Skip to content

Commit 69fe83b

Browse files
authored
Merge pull request #947 from plotly/on-par-redraw
Clean data & layout on Plotly.redraw
2 parents de6a183 + 1e6616c commit 69fe83b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/plot_api/plot_api.js

+3
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,9 @@ Plotly.redraw = function(gd) {
473473
throw new Error('This element is not a Plotly plot: ' + gd);
474474
}
475475

476+
helpers.cleanData(gd.data, gd.data);
477+
helpers.cleanLayout(gd.layout);
478+
476479
gd.calcdata = undefined;
477480
return Plotly.plot(gd).then(function() {
478481
gd.emit('plotly_redraw');

test/jasmine/tests/plot_api_test.js

+38
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var Legend = require('@src/components/legend');
88
var pkg = require('../../../package.json');
99
var subroutines = require('@src/plot_api/subroutines');
1010

11+
var d3 = require('d3');
1112
var createGraphDiv = require('../assets/create_graph_div');
1213
var destroyGraphDiv = require('../assets/destroy_graph_div');
1314

@@ -779,6 +780,43 @@ describe('Test plot api', function() {
779780
});
780781
});
781782

783+
describe('Plotly.redraw', function() {
784+
785+
afterEach(destroyGraphDiv);
786+
787+
it('', function(done) {
788+
var gd = createGraphDiv(),
789+
initialData = [],
790+
layout = { title: 'Redraw' };
791+
792+
Plotly.newPlot(gd, initialData, layout);
793+
794+
var trace1 = {
795+
x: [1, 2, 3, 4],
796+
y: [4, 1, 5, 3],
797+
name: 'First Trace'
798+
};
799+
var trace2 = {
800+
x: [1, 2, 3, 4],
801+
y: [14, 11, 15, 13],
802+
name: 'Second Trace'
803+
};
804+
var trace3 = {
805+
x: [1, 2, 3, 4],
806+
y: [5, 3, 7, 1],
807+
name: 'Third Trace'
808+
};
809+
810+
var newData = [trace1, trace2, trace3];
811+
gd.data = newData;
812+
813+
Plotly.redraw(gd).then(function() {
814+
expect(d3.selectAll('g.trace.scatter').size()).toEqual(3);
815+
})
816+
.then(done);
817+
});
818+
});
819+
782820
describe('cleanData', function() {
783821
var gd;
784822

0 commit comments

Comments
 (0)