Skip to content

Commit 34f81d5

Browse files
committed
don't clear gd.data when both fullReplot & layoutReplot are true
... during Plotly.update. Clearing gd.data lead to an erroneous makePlotFramework call which lead to modebar buttons not displaying (and potentially other bugs)
1 parent e6fb492 commit 34f81d5

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/plot_api/plot_api.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -2362,20 +2362,12 @@ function update(gd, traceUpdate, layoutUpdate, _traces) {
23622362
// fill in redraw sequence
23632363
var seq = [];
23642364

2365-
if(restyleFlags.fullReplot && relayoutFlags.layoutReplot) {
2366-
var data = gd.data;
2367-
var layout = gd.layout;
2368-
2369-
// clear existing data/layout on gd
2370-
// so that Plotly.plot doesn't try to extend them
2371-
gd.data = undefined;
2372-
gd.layout = undefined;
2373-
2374-
seq.push(function() { return exports.plot(gd, data, layout); });
2365+
if(relayoutFlags.layoutReplot) {
2366+
// N.B. works fine when both
2367+
// relayoutFlags.layoutReplot and restyleFlags.fullReplot are true
2368+
seq.push(subroutines.layoutReplot);
23752369
} else if(restyleFlags.fullReplot) {
23762370
seq.push(exports.plot);
2377-
} else if(relayoutFlags.layoutReplot) {
2378-
seq.push(subroutines.layoutReplot);
23792371
} else {
23802372
seq.push(Plots.previousPromises);
23812373
axRangeSupplyDefaultsByPass(gd, relayoutFlags, relayoutSpecs) || Plots.supplyDefaults(gd);

test/jasmine/tests/plot_api_test.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -2650,16 +2650,29 @@ describe('Test plot api', function() {
26502650
it('should only have one modebar-container', function(done) {
26512651
var data = [{y: [1, 2]}];
26522652

2653-
Plotly.plot(gd, data).then(function() {
2654-
var modebars = document.getElementsByClassName('modebar-container');
2655-
expect(modebars.length).toBe(1);
2653+
function _assert(msg) {
2654+
return function() {
2655+
var modebars = document.getElementsByClassName('modebar-container');
2656+
expect(modebars.length).toBe(1, msg + ' # of modebar container');
2657+
var groups = document.getElementsByClassName('modebar-group');
2658+
expect(groups.length).toBe(5, msg + ' # of modebar button groups');
2659+
};
2660+
}
26562661

2657-
return Plotly.newPlot(gd, data);
2658-
})
2659-
.then(function() {
2660-
var modebars = document.getElementsByClassName('modebar-container');
2661-
expect(modebars.length).toBe(1);
2662+
Plotly.plot(gd, data)
2663+
.then(_assert('base'))
2664+
.then(function() { return Plotly.newPlot(gd, data); })
2665+
.then(_assert('after newPlot()'))
2666+
.then(function() {
2667+
// funky combinations of update flags found in
2668+
// https://github.com/plotly/plotly.js/issues/3824
2669+
return Plotly.update(gd, {
2670+
visible: false
2671+
}, {
2672+
annotations: [{text: 'a'}]
2673+
});
26622674
})
2675+
.then(_assert('after update()'))
26632676
.catch(failTest)
26642677
.then(done);
26652678
});

0 commit comments

Comments
 (0)