it('should leave categoryorder on "array" if it is supplied', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {type: 'category', categoryorder: 'array', categoryarray: ['b','a','d','e','c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('array'); expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b','a','d','e','c']); });
it('should not switch categoryorder on "array" if categoryarray is supplied but empty', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {type: 'category', categoryarray: []} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categoryarray).toEqual(undefined); });
it('should switch categoryorder to default if list is not supplied', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {type: 'category', categoryorder: 'array', categoryarray: []} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categoryarray).toEqual([]); });
it('should switch categoryorder to "trace" if mode is supplied but invalid', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {type: 'category', categoryorder: 'invalid value'} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categoryarray).toBe(undefined); });
it('should use specified categoryorder if it is supplied even if categoryarray exists', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {type: 'category', categoryorder: 'category descending', categoryarray: ['b','a','d','e','c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('category descending'); expect(gd._fullLayout.xaxis.categoryarray).toBe(undefined); });
it('should switch categoryorder to "array" if mode is supplied but invalid and list is supplied', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {type: 'category', categoryorder: 'invalid value', categoryarray: ['b','a','d','e','c']} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('array'); expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b','a','d','e','c']); });
it('should revert categoryorder to "trace" if "array" is supplied but there is no list', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {type: 'category', categoryorder: 'array'} }); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categorarray).toBe(undefined); });
it('should set categoryorder to default if type is overridden to be category', function() { PlotlyInternal.plot(gd, [{x: [1,2,3,4,5], y: [15,11,12,13,14]}], {yaxis: {type: 'category'}}); expect(gd._fullLayout.xaxis.categoryorder).toBe(undefined); expect(gd._fullLayout.yaxis.categorarray).toBe(undefined); expect(gd._fullLayout.yaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.yaxis.categorarray).toBe(undefined); });
beforeEach(function (done) { var data = [{ x: [1,2,3], y: [4,5,6] }], promise = Plotly.plot(createGraphDiv(), data, {}); promise.then(function(gd){ promiseGd = gd; done(); }); });
beforeEach(function (done) { var data = [{ x: [1,2,3], y: [4,5,6] }], initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); promise = Plotly.extendTraces(initialDiv, { y: [[2]] }, [0], 3); promise.then(function(gd){ promiseGd = gd; done(); }); });
beforeEach(function (done) { var data = [{ x: [1,2,3], y: [4,5,6] }], initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); promise = Plotly.redraw(initialDiv); promise.then(function(gd){ promiseGd = gd; done(); }); });
beforeEach(function (done) { var data = [{ x: [1,2,3], y: [4,5,6] }], initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); promise = Plotly.restyle(initialDiv, 'marker.color', 'rgb(255,0,0)'); promise.then(function(gd){ promiseGd = gd; done(); }); });
it('should conditionally coerce based on showticklabels', function() { var layout = { yaxis: { showticklabels: false, tickangle: -90 } }; PlotlyInternal.plot(gd, data, layout); var yaxis = gd._fullLayout.yaxis; expect(yaxis.tickangle).toBeUndefined(); });
it('should use the non-fancy gl-vis/gl-scatter2d with string dates', function() { PlotlyInternal.plot(gd, [{ type: 'scattergl', mode: 'markers', // important, as otherwise lines are assumed (which needs fancy) x: ['2016-10-10', '2016-10-11'], y: [15, 16] }]); expect(gd._fullLayout.xaxis.type).toBe('date'); expect(gd._fullLayout.yaxis.type).toBe('linear'); expect(gd._fullData[0].type).toBe('scattergl'); expect(gd._fullData[0]._module.basePlotModule.name).toBe('gl2d'); expect(gd._fullLayout._plots.xy._scene2d.glplot.objects[3].pointCount).toBe(2); });
beforeEach(function (done) { var data = [ { x: [1,2,3], y: [4,5,6] }, { x: [1,2,3], y: [6,5,4] } ], initialDiv = createGraphDiv(); Plotly.plot(initialDiv, data, {}); promise = Plotly.moveTraces(initialDiv, 0, 1); promise.then(function(gd){ promiseGd = gd; done(); }); });
it('should use the fancy gl-vis/gl-scatter2d once again', function() { PlotlyInternal.plot(gd, [{ type: 'scattergl', 'marker': { 'color': 'rgb(31, 119, 180)', 'size': 36, 'symbol': [ 'circle', 'cross' ] }, x: [new Date('2016-10-10'), new Date('2016-10-11')], y: [15, 16] }]); expect(gd._fullLayout.xaxis.type).toBe('date'); expect(gd._fullLayout.yaxis.type).toBe('linear'); expect(gd._fullData[0].type).toBe('scattergl'); expect(gd._fullData[0]._module.basePlotModule.name).toBe('gl2d'); // one way of check which renderer - fancy vs not - we're using expect(gd._fullLayout._plots.xy._scene2d.glplot.objects[3].pointCount).toBe(0); });
it('should use valid inputs', function() { var layout = { yaxis: { ticklen: 10, tickwidth: 5, tickcolor: '#F00', showticklabels: true, tickfont: { family: 'Garamond', size: 72, color: '#0FF' }, tickangle: -20 } }; PlotlyInternal.plot(gd, data, layout); var yaxis = gd._fullLayout.yaxis; expect(yaxis.ticklen).toBe(10); expect(yaxis.tickwidth).toBe(5); expect(yaxis.tickcolor).toBe('#F00'); expect(yaxis.ticks).toBe('outside'); expect(yaxis.showticklabels).toBe(true); expect(yaxis.tickfont).toEqual({ family: 'Garamond', size: 72, color: '#0FF' }); expect(yaxis.tickangle).toBe(-20); });
it('should set defaults on bad inputs', function() { var layout = { yaxis: { ticklen: 'invalid', tickwidth: 'invalid', tickcolor: 'invalid', showticklabels: 'invalid', tickfont: 'invalid', tickangle: 'invalid' } }; PlotlyInternal.plot(gd, data, layout); var yaxis = gd._fullLayout.yaxis; expect(yaxis.ticklen).toBe(5); expect(yaxis.tickwidth).toBe(1); expect(yaxis.tickcolor).toBe('#444'); expect(yaxis.ticks).toBe('outside'); expect(yaxis.showticklabels).toBe(true); expect(yaxis.tickfont).toEqual({ family: '"Open Sans", verdana, arial, sans-serif', size: 12, color: '#444' }); expect(yaxis.tickangle).toBe('auto'); });
it('should set categoryorder to default if categoryorder and categoryarray are not supplied', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], {xaxis: {type: 'category'}}); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categorarray).toBe(undefined); });
it('should set categoryorder to default even if type is not set to category explicitly', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}]); expect(gd._fullLayout.xaxis.categoryorder).toBe('trace'); expect(gd._fullLayout.xaxis.categorarray).toBe(undefined); });
it('should NOT set categoryorder to default if type is not category', function() { PlotlyInternal.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}]); expect(gd._fullLayout.yaxis.categoryorder).toBe(undefined); expect(gd._fullLayout.xaxis.categorarray).toBe(undefined); });