Skip to content

Commit 907b90e

Browse files
authored
Merge pull request #971 from plotly/plotly-update-args
Fix Plotly.update for full data + layout replot
2 parents 4845978 + 9bad608 commit 907b90e

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
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

+25-1
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ describe('Test plot api', function() {
934934
});
935935

936936
describe('Plotly.update should', function() {
937-
var gd, calcdata;
937+
var gd, data, layout, calcdata;
938938

939939
beforeAll(function() {
940940
Object.keys(subroutines).forEach(function(k) {
@@ -945,6 +945,8 @@ describe('Test plot api', function() {
945945
beforeEach(function(done) {
946946
gd = createGraphDiv();
947947
Plotly.plot(gd, [{ y: [2, 1, 2] }]).then(function() {
948+
data = gd.data;
949+
layout = gd.layout;
948950
calcdata = gd.calcdata;
949951
done();
950952
});
@@ -964,11 +966,33 @@ describe('Test plot api', function() {
964966

965967
it('clear calcdata on data updates', function(done) {
966968
Plotly.update(gd, { x: [[3, 1, 3]] }).then(function() {
969+
expect(data).toBe(gd.data);
970+
expect(layout).toBe(gd.layout);
967971
expect(calcdata).not.toBe(gd.calcdata);
968972
done();
969973
});
970974
});
971975

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+
972996
it('call doLegend on legend updates', function(done) {
973997
expect(subroutines.doLegend).not.toHaveBeenCalled();
974998

0 commit comments

Comments
 (0)