diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 8b8be2bb265..72b40252361 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -2062,9 +2062,15 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) { var seq = []; if(restyleFlags.fullReplot && relayoutFlags.layoutReplot) { - var layout = gd.layout; + var data = gd.data, + layout = gd.layout; + + // clear existing data/layout on gd + // so that Plotly.plot doesn't try to extend them + gd.data = undefined; gd.layout = undefined; - seq.push(function() { return Plotly.plot(gd, gd.data, layout); }); + + seq.push(function() { return Plotly.plot(gd, data, layout); }); } else if(restyleFlags.fullReplot) { seq.push(Plotly.plot); diff --git a/test/jasmine/tests/plot_api_test.js b/test/jasmine/tests/plot_api_test.js index 748ec779278..06078004c2a 100644 --- a/test/jasmine/tests/plot_api_test.js +++ b/test/jasmine/tests/plot_api_test.js @@ -934,7 +934,7 @@ describe('Test plot api', function() { }); describe('Plotly.update should', function() { - var gd, calcdata; + var gd, data, layout, calcdata; beforeAll(function() { Object.keys(subroutines).forEach(function(k) { @@ -945,6 +945,8 @@ describe('Test plot api', function() { beforeEach(function(done) { gd = createGraphDiv(); Plotly.plot(gd, [{ y: [2, 1, 2] }]).then(function() { + data = gd.data; + layout = gd.layout; calcdata = gd.calcdata; done(); }); @@ -964,11 +966,33 @@ describe('Test plot api', function() { it('clear calcdata on data updates', function(done) { Plotly.update(gd, { x: [[3, 1, 3]] }).then(function() { + expect(data).toBe(gd.data); + expect(layout).toBe(gd.layout); expect(calcdata).not.toBe(gd.calcdata); done(); }); }); + it('clear calcdata on data + axis updates w/o extending current gd.data', function(done) { + var traceUpdate = { + x: [[3, 1, 3]] + }; + + var layoutUpdate = { + xaxis: {title: 'A', type: '-'} + }; + + Plotly.update(gd, traceUpdate, layoutUpdate).then(function() { + expect(data).toBe(gd.data); + expect(layout).toBe(gd.layout); + expect(calcdata).not.toBe(gd.calcdata); + + expect(gd.data.length).toEqual(1); + + done(); + }); + }); + it('call doLegend on legend updates', function(done) { expect(subroutines.doLegend).not.toHaveBeenCalled();