Skip to content

Commit 9bad608

Browse files
committed
plot_api: clear gd.data on update calls -> full data + layout replot
- so that Plotly.plot doesn't try to extend them
1 parent 33698d8 commit 9bad608

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/plot_api/plot_api.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -2062,9 +2062,15 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) {
20622062
var seq = [];
20632063

20642064
if(restyleFlags.fullReplot && relayoutFlags.layoutReplot) {
2065-
var layout = gd.layout;
2065+
var data = gd.data,
2066+
layout = gd.layout;
2067+
2068+
// clear existing data/layout on gd
2069+
// so that Plotly.plot doesn't try to extend them
2070+
gd.data = undefined;
20662071
gd.layout = undefined;
2067-
seq.push(function() { return Plotly.plot(gd, gd.data, layout); });
2072+
2073+
seq.push(function() { return Plotly.plot(gd, data, layout); });
20682074
}
20692075
else if(restyleFlags.fullReplot) {
20702076
seq.push(Plotly.plot);

test/jasmine/tests/plot_api_test.js

+20
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,26 @@ describe('Test plot api', function() {
973973
});
974974
});
975975

976+
it('clear calcdata on data + axis updates w/o extending current gd.data', function(done) {
977+
var traceUpdate = {
978+
x: [[3, 1, 3]]
979+
};
980+
981+
var layoutUpdate = {
982+
xaxis: {title: 'A', type: '-'}
983+
};
984+
985+
Plotly.update(gd, traceUpdate, layoutUpdate).then(function() {
986+
expect(data).toBe(gd.data);
987+
expect(layout).toBe(gd.layout);
988+
expect(calcdata).not.toBe(gd.calcdata);
989+
990+
expect(gd.data.length).toEqual(1);
991+
992+
done();
993+
});
994+
});
995+
976996
it('call doLegend on legend updates', function(done) {
977997
expect(subroutines.doLegend).not.toHaveBeenCalled();
978998

0 commit comments

Comments
 (0)