\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: legend-spec.js

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

    var chart, args;

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

    describe('legend when multiple charts rendered', function () {

        beforeAll(function () {
            args = {
                data: {
                    columns: [
                        ['data1', 30],
                        ['data2', 50],
                        ['data3', 100]
                    ]
                }
            };
        });

        describe('long data names', function () {
            beforeAll(function(){
                args = {
                    data: {
                        columns: [
                            ['long data name 1', 30],
                            ['long data name 2', 50],
                            ['long data name 3', 50],
                        ]
                    }
                };
            });

            it('should have properly computed legend width', function () {
                var expectedLeft = [148, 226, 384],
                    expectedWidth = [118, 118, 108];
                d3.selectAll('.c3-legend-item').each(function (d, i) {
                    var rect = d3.select(this).node().getBoundingClientRect();
                    expect(rect.left).toBeCloseTo(expectedLeft[i], -2);
                    expect(rect.width).toBeCloseTo(expectedWidth[i], -2);
                });
            });
        });
    });

    describe('legend position', function () {

        beforeAll(function () {
            args = {
                data: {
                    columns: [
                        ['data1', 30, 200, 100, 400, 150, 250],
                        ['data2', 50, 20, 10, 40, 15, 25]
                    ]
                }
            };
        });

        it('should be located on the center of chart', function () {
            var box = chart.internal.legend.node().getBoundingClientRect();
            expect(box.left + box.right).toBe(638);
        });

    });

    describe('legend as inset', function () {

        describe('should change the legend to "inset" successfully', function () {
            beforeAll(function(){
                args = {
                    data: {
                        columns: [
                            ['data1', 30, 200, 100, 400, 150, 250],
                            ['data2', 50, 20, 10, 40, 15, 25]
                        ]
                    },
                    legend: {
                        position: 'inset',
                        inset: {
                            step: null
                        }
                    }
                };
            });

            it('should be positioned properly', function () {
                var box = d3.select('.c3-legend-background').node().getBoundingClientRect();
                expect(box.top).toBe(5.5);
                expect(box.left).toBeGreaterThan(30);
            });

            it('should have automatically calculated height', function () {
                var box = d3.select('.c3-legend-background').node().getBoundingClientRect();
                expect(box.height).toBe(48);
            });
        });

        describe('should change the legend step to 1 successfully', function () {
            beforeAll(function(){
                args.legend.inset.step = 1;
            });

            it('should have automatically calculated height', function () {
                var box = d3.select('.c3-legend-background').node().getBoundingClientRect();
                expect(box.height).toBe(28);
            });
        });

        describe('should change the legend step to 2 successfully', function () {
            beforeAll(function(){
                args.legend.inset.step = 2;
            });

            it('should have automatically calculated height', function () {
                var box = d3.select('.c3-legend-background').node().getBoundingClientRect();
                expect(box.height).toBe(48);
            });
        });

        describe('with only one series', function () {
            beforeAll(function(){
                args = {
                    data: {
                        columns: [
                            ['data1', 30, 200, 100, 400, 150, 250],
                        ]
                    },
                    legend: {
                        position: 'inset'
                    }
                };
            });

            it('should locate legend properly', function () {
                var box = d3.select('.c3-legend-background').node().getBoundingClientRect();
                expect(box.height).toBe(28);
                expect(box.width).toBeGreaterThan(64);
            });
        });
    });

    describe('legend.hide', function () {

        beforeAll(function () {
            args = {
                data: {
                    columns: [
                        ['data1', 30, 200, 100, 400, 150, 250],
                        ['data2', 130, 100, 200, 100, 250, 150]
                    ]
                },
                legend: {
                    hide: true
                }
            };
        });

        it('should not show legends', function () {
            d3.selectAll('.c3-legend-item').each(function () {
                expect(d3.select(this).style('visibility')).toBe('hidden');
            });
        });

        describe('hidden legend', function () {
            beforeAll(function(){
                args = {
                    data: {
                        columns: [
                            ['data1', 30, 200, 100, 400, 150, 250],
                            ['data2', 130, 100, 200, 100, 250, 150]
                        ]
                    },
                    legend: {
                        hide: 'data2'
                    }
                };
            });

            it('should not show legends', function () {
                expect(d3.select('.c3-legend-item-data1').style('visibility')).toBe('visible');
                expect(d3.select('.c3-legend-item-data2').style('visibility')).toBe('hidden');
            });
        });

    });

    describe('legend.show', function () {

        beforeAll(function () {
            args = {
                data: {
                    columns: [
                        ['data1', 30, 200, 100, 400, 150, 250],
                        ['data2', 130, 100, 200, 100, 250, 150]
                    ]
                },
                legend: {
                    show: false
                }
            };
        });

        it('should not initially have rendered any legend items', function () {
            expect(d3.selectAll('.c3-legend-item').empty()).toBe(true);
        });

        it('allows us to show the legend on showLegend call', function () {
            chart.legend.show();
            d3.selectAll('.c3-legend-item').each(function () {
                expect(d3.select(this).style('visibility')).toBe('visible');
                // This selects all the children, but we expect it to be empty
                expect(d3.select(this).selectAll("*").length).not.toEqual(0);
            });
        });

    });

    describe('custom legend size', function() {
        beforeAll(function () {
            args = {
                data: {
                    columns: [
                        ['data1', 30, 200, 100, 400, 150, 250],
                        ['data2', 130, 100, 200, 100, 250, 150]
                    ]
                },
                legend: {
                    item: {
                        tile: {
                            width: 15,
                            height: 2
                        }
                    }
                }
            };
        });

        it('renders the legend item with the correct width and height', function () {
            d3.selectAll('.c3-legend-item-tile').each(function () {
                expect(d3.select(this).style('stroke-width')).toBe(args.legend.item.tile.height + 'px');
                var tileWidth = d3.select(this).attr('x2') - d3.select(this).attr('x1');
                expect(tileWidth).toBe(args.legend.item.tile.width);
            });
        });
    });

    describe('custom legend padding', function() {
        beforeAll(function () {
            args = {
                data: {
                    columns: [
                        ['padded1', 30, 200, 100, 400, 150, 250],
                        ['padded2', 130, 100, 200, 100, 250, 150]
                    ]
                },
                legend: {
                    padding: 10
                }
            };
        });

        it('renders the correct amount of padding on the legend element', function () {
            d3.selectAll('.c3-legend-item-padded1 .c3-legend-item-tile, .c3-legend-item-padded2 .c3-legend-item-tile').each(function (el, index) {
                var itemWidth = d3.select(this).node().parentNode.getBBox().width,
                    textBoxWidth = d3.select(d3.select(this).node().parentNode).select('text').node().getBBox().width,
                    tileWidth = 17, // default value is 10, plus 7 more for padding @TODO verify this, seems PhantomJS@^2 adds another 1px to each side
                    expectedWidth = textBoxWidth + tileWidth + (index ? 0 : 10) + args.legend.padding;

                expect(itemWidth).toBe(expectedWidth);
            });
        });
    });

});