it('should work when duplicating the existing data', function() { Plotly.addTraces(gd, gd.data); expect(gd.data.length).toEqual(4); expect(gd.data[0]).not.toBe(gd.data[2]); expect(gd.data[1]).not.toBe(gd.data[3]); });
Plotly.newPlot(gd, mock).then(function() { _assert(12); return Plotly.addTraces(gd, { y: [1, 2, 1] }); })
.then(function() { expect(document.querySelectorAll('.parcoords-line-layers').length).toEqual(1); expect(gd.data.length).toEqual(1); return Plotly.addTraces(gd, [mockCopy2.data[0]]); })
it('should work when newIndices is an integer', function() { Plotly.addTraces(gd, {'name': 'c'}, 0); expect(gd.data[2].name).toBeDefined(); expect(gd.data[2].uid).toBeDefined(); expect(PlotlyInternal.redraw).not.toHaveBeenCalled(); expect(PlotlyInternal.moveTraces).toHaveBeenCalledWith(gd, [-1], [0]); });
.then(function() { expect(countOHLCTraces()).toEqual(0); expect(countBoxTraces()).toEqual(1); var trace = Lib.extendDeep({}, mock0, { type: 'ohlc' }); return Plotly.addTraces(gd, [trace]); })
.then(function() { expect(countScatterTraces()).toEqual(0); expect(countBoxTraces()).toEqual(0); var trace = Lib.extendDeep({}, mock0, { type: 'candlestick' }); return Plotly.addTraces(gd, [trace]); })
it('should work when newIndices has negative indices', function() { Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}], [-3, -1]); expect(gd.data[2].name).toBeDefined(); expect(gd.data[2].uid).toBeDefined(); expect(gd.data[3].name).toBeDefined(); expect(gd.data[3].uid).toBeDefined(); expect(PlotlyInternal.redraw).not.toHaveBeenCalled(); expect(PlotlyInternal.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [-3, -1]); });
it('should work when newIndices is undefined', function() { Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}]); expect(gd.data[2].name).toBeDefined(); expect(gd.data[2].uid).toBeDefined(); expect(gd.data[3].name).toBeDefined(); expect(gd.data[3].uid).toBeDefined(); expect(PlotlyInternal.redraw).toHaveBeenCalled(); expect(PlotlyInternal.moveTraces).not.toHaveBeenCalled(); });
.then(function() { expect(count('g.scatterlayer > g.trace')).toEqual(0); expect(count('g.barlayer > g.trace')).toEqual(0); return Plotly.addTraces(gd, [{ type: 'heatmap', z: [[1, 2, 3], [2, 1, 3]] }]); })
Plotly.plot(gd, data).then(function() { expect(gd._fullLayout.xaxis._categories).toEqual(['a', 'f']); expect(gd._fullLayout.yaxis._categories).toEqual([]); return Plotly.addTraces(gd, [{ type: 'bar', x: ['h', 'i'], y: [2, 1], transforms: [{ type: 'filter', operation: '=', value: 'i' }] }]); })
it('should resize when traces added', function(done) { var origLegend = document.getElementsByClassName('legend')[0]; var origLegendHeight = getBBox(origLegend).height; Plotly.addTraces(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() { var legend = document.getElementsByClassName('legend')[0]; var legendHeight = getBBox(legend).height; // clippath resized to show new trace expect(+legendHeight).toBeCloseTo(+origLegendHeight + 19, 0); done(); }); });
it('should resize when traces added', function(done) { legend = document.getElementsByClassName('legend')[0]; bg = document.getElementsByClassName('bg')[0]; var origLegendHeight = getLegendHeight(); Plotly.addTraces(gd, { x: [1,2,3], y: [4,3,2], name: 'Test2' }).then(function() { legend = document.getElementsByClassName('legend')[0]; bg = document.getElementsByClassName('bg')[0]; var legendHeight = getLegendHeight(); expect(+legendHeight).toBeCloseTo(+origLegendHeight + 19, 0); done(); }); });
.then(function() { var scene = gd._fullLayout._plots.xy._scene; expect(scene.count).toBe(1); expect(scene.selectBatch).toEqual([[0]]); expect(scene.unselectBatch).toEqual([[]]); spyOn(scene.scatter2d, 'draw'); var trace = { x: [2], y: [1], type: 'scattergl', mode: 'markers', marker: {color: 'red'} }; return Plotly.addTraces(gd, trace); })
expect(function() { Plotly.addTraces(gd, [{}, {}], [0, 10]); }).toThrow(new Error('newIndices must be valid indices for gd.data.'));
expect(function() { Plotly.addTraces(gd, [{}, {}], 2); }).toThrowError(Error, 'if indices is specified, traces.length must equal indices.length');
expect(function() { Plotly.addTraces(gd, [{}, []], 2); }).toThrowError(Error, 'all values in traces array must be non-array objects');
.then(function() { assertBoxPosFields([0]); return Plotly.addTraces(gd, [Lib.extendDeep({}, trace0)]); })
it('should work when adding an existing trace', function() { Plotly.addTraces(gd, gd.data[0]); expect(gd.data.length).toEqual(3); expect(gd.data[0]).not.toBe(gd.data[2]); });
.then(function() { expect(countCarpets()).toEqual(1); expect(countContourTraces()).toEqual(2); return Plotly.addTraces(gd, trace1); })
.then(function() { assertRange([-0.32, 5.32], [-1, 11]); return Plotly.addTraces(gd, { x: [0, 10], y: [2, 1] }); })
Plotly.plot(gd, [trace0]).then(function() { assertBoxPosFields([0.5, undefined]); return Plotly.addTraces(gd, {}); })
.then(function() { expect(gd.data.length).toEqual(1); expect(d3.selectAll('.sankey').size()).toEqual(1); return Plotly.addTraces(gd, mockCopy2.data[0]); })