\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /home/heznutpr/log.heznutprivate.com/dist/assets/node_modules/c3-master/spec/

Viewing File: arc-spec.js

describe('c3 chart arc', function () {
    'use strict';

    var chart, args;

    beforeEach(function (done) {
        chart = window.initChart(chart, args, done);
    });

    describe('show pie chart', function () {

        beforeAll(function () {
            args = {
                data: {
                    columns: [
                        ['data1', 30],
                        ['data2', 150],
                        ['data3', 120]
                    ],
                    type: 'pie'
                }
            };
        });

        it('should have correct classes', function () {
            var chartArc = d3.select('.c3-chart-arcs'),
            arcs = {
                data1: chartArc.select('.c3-chart-arc.c3-target.c3-target-data1')
                    .select('g.c3-shapes.c3-shapes-data1.c3-arcs.c3-arcs-data1')
                    .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data1'),
                data2: chartArc.select('.c3-chart-arc.c3-target.c3-target-data2')
                    .select('g.c3-shapes.c3-shapes-data2.c3-arcs.c3-arcs-data2')
                    .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data2'),
                data3: chartArc.select('.c3-chart-arc.c3-target.c3-target-data3')
                    .select('g.c3-shapes.c3-shapes-data3.c3-arcs.c3-arcs-data3')
                    .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data3')
            };
            expect(arcs.data1.size()).toBe(1);
            expect(arcs.data2.size()).toBe(1);
            expect(arcs.data3.size()).toBe(1);
        });

        it('should have correct d', function () {
            expect(d3.select('.c3-arc-data1').attr('d')).toMatch(/M-124\..+,-171\..+A211\..+,211\..+ 0 0,1 -3\..+,-211\..+L0,0Z/);
            expect(d3.select('.c3-arc-data2').attr('d')).toMatch(/M1\..+,-211\..+A211\..+,211\..+ 0 0,1 1\..+,211\..+L0,0Z/);
            expect(d3.select('.c3-arc-data3').attr('d')).toMatch(/M1\..+,211\..+A211\..+,211\..+ 0 0,1 -124\..+,-171\..+L0,0Z/);
        });

        describe('with data id that can be converted to a color', function () {
            beforeAll(function(){
                args.data.columns = [
                    ['black', 30],
                    ['data2', 150],
                    ['data3', 120]
                ];
            });

            it('should have correct d even if data id can be converted to a color', function (done) {
                setTimeout(function () {
                    expect(d3.select('.c3-arc-black').attr('d')).toMatch(/M-124\..+,-171\..+A211\..+,211\..+ 0 0,1 -3\..+,-211\..+L0,0Z/);
                    done();
                }, 500);
            });

            describe('with empty pie chart', function(){
                beforeAll(function () {
                    args = {
                        data: {
                            columns: [
                                ['data1', null],
                                ['data2', null],
                                ['data3', null]
                            ],
                            type: 'pie'
                        }
                    };
                });

                it('should have correct d attribute', function () {
                    var chartArc = d3.select('.c3-chart-arcs'),
                    arcs = {
                        data1: chartArc.select('.c3-chart-arc.c3-target.c3-target-data1')
                            .select('g.c3-shapes.c3-shapes-data1.c3-arcs.c3-arcs-data1')
                            .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data1'),
                        data2: chartArc.select('.c3-chart-arc.c3-target.c3-target-data2')
                            .select('g.c3-shapes.c3-shapes-data2.c3-arcs.c3-arcs-data2')
                            .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data2'),
                        data3: chartArc.select('.c3-chart-arc.c3-target.c3-target-data3')
                            .select('g.c3-shapes.c3-shapes-data3.c3-arcs.c3-arcs-data3')
                            .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data3')
                    };
                    expect(arcs.data1.attr('d').indexOf('NaN')).toBe(-1);
                    expect(arcs.data2.attr('d').indexOf('NaN')).toBe(-1);
                    expect(arcs.data3.attr('d').indexOf('NaN')).toBe(-1);
                });
            });
        });
    });

    describe('sort pie chart', function() {

        var createPie = function(order) {
            return {
                data: {
                    order: order,
                    columns: [
                        ['data1', 30],
                        ['data2', 150],
                        ['data3', 120]
                    ],
                    type: 'pie'
                }
            };
        };

        var collectArcs = function() {
            return d3.selectAll('.c3-arc')
                .data()
                .sort(function(a, b) {
                    return a.startAngle - b.startAngle;
                })
                .map(function(item) {
                    return item.data.id;
                });
        };

        it('should update data_order to desc', function () {
            args = createPie('desc');
            expect(true).toBeTruthy();
        });

        it('it should have descending ordering', function () {
            expect(collectArcs()).toEqual([ 'data2', 'data3', 'data1' ]);
        });

        it('should update data_order to asc', function () {
            args = createPie('asc');
            expect(true).toBeTruthy();
        });

        it('it should have ascending ordering', function () {
            expect(collectArcs()).toEqual([ 'data1', 'data3', 'data2' ]);
        });

        it('should update data_order to NULL', function () {
            args = createPie(null);
            expect(true).toBeTruthy();
        });

        it('it should have no ordering', function () {
            expect(collectArcs()).toEqual([ 'data1', 'data2', 'data3' ]);
        });

        it('should update data_order to Array', function () {
            args = createPie([ 'data3', 'data2', 'data1' ]);
            expect(true).toBeTruthy();
        });

        it('it should have array specified ordering', function () {
            expect(collectArcs()).toEqual([ 'data3', 'data2', 'data1' ]);
        });

        it('should update data_order to Function', function () {
            var names = [ 'data2', 'data1', 'data3' ];
            args = createPie(function(a, b) {
                return names.indexOf(a.id) - names.indexOf(b.id);
            });
            expect(true).toBeTruthy();
        });

        it('it should have array specified ordering', function () {
            expect(collectArcs()).toEqual([ 'data2', 'data1', 'data3' ]);
        });
    });

    describe('show gauge', function () {

        describe('with a 180 degree gauge', function(){
            beforeAll(function () {
                args = {
                    gauge: {
                        width: 10,
                        max: 10,
                        expand: true
                    },
                    data: {
                        columns: [
                            ['data', 8]
                        ],
                        type: 'gauge'
                    }
                };
            });

            it('should have correct d for Pi radian gauge', function () {
                var chartArc = d3.select('.c3-chart-arcs'),
                    data = chartArc.select('.c3-chart-arc.c3-target.c3-target-data')
                        .select('g.c3-shapes.c3-shapes-data.c3-arcs.c3-arcs-data')
                        .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data');

                expect(data.attr('d')).toMatch(/M-304,-3\..+A304,304 0 0,1 245\..+,-178\..+L237\..+,-172\..+A294,294 0 0,0 -294,-3\..+Z/);
            });
        });

        describe('with a 2 Pi radian gauge that starts at Pi/2', function() {
            beforeAll(function(){
                args = {
                    gauge: {
                        width: 10,
                        max: 10,
                        expand: true,
                        fullCircle: true
                    },
                    data: {
                        columns: [
                            ['data', 8]
                        ],
                        type: 'gauge',
                        fullCircle: true,
                        startingAngle: Math.PI/2
                    }
                };
            });

            it('should have correct d for 2 Pi radian gauge starting at Pi/2', function() {
                var chartArc = d3.select('.c3-chart-arcs'),
                    data = chartArc.select('.c3-chart-arc.c3-target.c3-target-data')
                        .select('g.c3-shapes.c3-shapes-data.c3-arcs.c3-arcs-data')
                        .select('path.c3-shape.c3-shape.c3-arc.c3-arc-data');

                // This test has bee updated to make tests pass. @TODO double-check this test is accurate.
                expect(data.attr('d')).toMatch(/M-221.*?,-2\..+A221.*?,221.*? 0 1,1 -68.*?,210.*?L-65.*?,201.*?A211.*?,211.*? 0 1,0 -211.*?,-2.*?Z/);
            });

            describe('with labels use custom text', function() {
                beforeAll(function(){
                    args = {
                        gauge: {
                            width: 10,
                            max: 100,
                            expand: true,
                            label: {
                                extents: function (value, isMax) {
                                    if (isMax) {
                                        return 'Max: ' + value + '%';
                                    }

                                    return 'Min: ' + value + '%';
                                }
                            }
                        },
                        data: {
                            columns: [
                                ['data', 8]
                            ],
                            type: 'gauge',
                            fullCircle: true,
                            startingAngle: Math.PI/2
                        }
                    };
                });
                it('should show custom min/max guage labels', function () {
                    var chartArc = d3.select('.c3-chart-arcs'),
                        min = chartArc.select('.c3-chart-arcs-gauge-min'),
                        max = chartArc.select('.c3-chart-arcs-gauge-max');

                    expect(min.text()).toMatch('Min: 0%');
                    expect(max.text()).toMatch('Max: 100%');
                });
            });
        });
    });

});