Skip to content

Commit 6ae0349

Browse files
authored
Merge pull request #3825 from plotly/modebar-after-update-fix
Plotly.update replot fixes
2 parents 09b4972 + 34f81d5 commit 6ae0349

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
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

+31-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var Legend = require('@src/components/legend');
99
var Axes = require('@src/plots/cartesian/axes');
1010
var pkg = require('../../../package.json');
1111
var subroutines = require('@src/plot_api/subroutines');
12+
var manageArrays = require('@src/plot_api/manage_arrays');
1213
var helpers = require('@src/plot_api/helpers');
1314
var editTypes = require('@src/plot_api/edit_types');
1415

@@ -2649,16 +2650,29 @@ describe('Test plot api', function() {
26492650
it('should only have one modebar-container', function(done) {
26502651
var data = [{y: [1, 2]}];
26512652

2652-
Plotly.plot(gd, data).then(function() {
2653-
var modebars = document.getElementsByClassName('modebar-container');
2654-
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+
}
26552661

2656-
return Plotly.newPlot(gd, data);
2657-
})
2658-
.then(function() {
2659-
var modebars = document.getElementsByClassName('modebar-container');
2660-
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+
});
26612674
})
2675+
.then(_assert('after update()'))
26622676
.catch(failTest)
26632677
.then(done);
26642678
});
@@ -2674,6 +2688,10 @@ describe('Test plot api', function() {
26742688
});
26752689

26762690
beforeEach(function(done) {
2691+
Object.keys(subroutines).forEach(function(k) {
2692+
subroutines[k].calls.reset();
2693+
});
2694+
26772695
gd = createGraphDiv();
26782696
Plotly.plot(gd, [{ y: [2, 1, 2] }]).then(function() {
26792697
data = gd.data;
@@ -2687,8 +2705,6 @@ describe('Test plot api', function() {
26872705
afterEach(destroyGraphDiv);
26882706

26892707
it('call doTraceStyle on trace style updates', function(done) {
2690-
expect(subroutines.doTraceStyle).not.toHaveBeenCalled();
2691-
26922708
Plotly.update(gd, { 'marker.color': 'blue' }).then(function() {
26932709
expect(subroutines.doTraceStyle).toHaveBeenCalledTimes(1);
26942710
expect(calcdata).toBe(gd.calcdata);
@@ -2720,16 +2736,14 @@ describe('Test plot api', function() {
27202736
expect(data).toBe(gd.data);
27212737
expect(layout).toBe(gd.layout);
27222738
expect(calcdata).not.toBe(gd.calcdata);
2723-
27242739
expect(gd.data.length).toEqual(1);
2740+
expect(subroutines.layoutReplot).toHaveBeenCalledTimes(1);
27252741
})
27262742
.catch(failTest)
27272743
.then(done);
27282744
});
27292745

27302746
it('call doLegend on legend updates', function(done) {
2731-
expect(subroutines.doLegend).not.toHaveBeenCalled();
2732-
27332747
Plotly.update(gd, {}, { 'showlegend': true }).then(function() {
27342748
expect(subroutines.doLegend).toHaveBeenCalledTimes(1);
27352749
expect(calcdata).toBe(gd.calcdata);
@@ -2738,8 +2752,8 @@ describe('Test plot api', function() {
27382752
.then(done);
27392753
});
27402754

2741-
it('call layoutReplot when adding update menu', function(done) {
2742-
expect(subroutines.layoutReplot).not.toHaveBeenCalled();
2755+
it('call array manager when adding update menu', function(done) {
2756+
spyOn(manageArrays, 'applyContainerArrayChanges').and.callThrough();
27432757

27442758
var layoutUpdate = {
27452759
updatemenus: [{
@@ -2751,16 +2765,15 @@ describe('Test plot api', function() {
27512765
};
27522766

27532767
Plotly.update(gd, {}, layoutUpdate).then(function() {
2754-
expect(subroutines.doLegend).toHaveBeenCalledTimes(1);
2768+
expect(manageArrays.applyContainerArrayChanges).toHaveBeenCalledTimes(1);
2769+
expect(subroutines.layoutReplot).toHaveBeenCalledTimes(0);
27552770
expect(calcdata).toBe(gd.calcdata);
27562771
})
27572772
.catch(failTest)
27582773
.then(done);
27592774
});
27602775

27612776
it('call doModeBar when updating \'dragmode\'', function(done) {
2762-
expect(subroutines.doModeBar).not.toHaveBeenCalled();
2763-
27642777
Plotly.update(gd, {}, { 'dragmode': 'pan' }).then(function() {
27652778
expect(subroutines.doModeBar).toHaveBeenCalledTimes(1);
27662779
expect(calcdata).toBe(gd.calcdata);

0 commit comments

Comments
 (0)