Skip to content

Commit 9c4157b

Browse files
committed
rm <g .trace> in overlaid subplots when removing exit() subplots
1 parent 3bf58db commit 9c4157b

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/plots/cartesian/index.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,39 @@ function makeSubplotLayer(plotinfo) {
368368
function purgeSubplotLayers(layers, fullLayout) {
369369
if(!layers) return;
370370

371-
layers.each(function(subplot) {
372-
var plotgroup = d3.select(this),
373-
clipId = 'clip' + fullLayout._uid + subplot + 'plot';
371+
var overlayIdsToRemove = {};
372+
373+
layers.each(function(subplotId) {
374+
var plotgroup = d3.select(this);
375+
var clipId = 'clip' + fullLayout._uid + subplotId + 'plot';
374376

375377
plotgroup.remove();
376-
fullLayout._draggers.selectAll('g.' + subplot).remove();
378+
fullLayout._draggers.selectAll('g.' + subplotId).remove();
377379
fullLayout._defs.select('#' + clipId).remove();
378380

381+
overlayIdsToRemove[subplotId] = true;
382+
379383
// do not remove individual axis <clipPath>s here
380384
// as other subplots may need them
381385
});
386+
387+
// must remove overlaid subplot trace layers 'manually'
388+
389+
var subplots = fullLayout._plots;
390+
var subplotIds = Object.keys(subplots);
391+
392+
for(var i = 0; i < subplotIds.length; i++) {
393+
var subplotInfo = subplots[subplotIds[i]];
394+
var overlays = subplotInfo.overlays || [];
395+
396+
for(var j = 0; j < overlays.length; j++) {
397+
var overlayInfo = overlays[j];
398+
399+
if(overlayIdsToRemove[overlayInfo.id]) {
400+
overlayInfo.plot.selectAll('.trace').remove();
401+
}
402+
}
403+
}
382404
}
383405

384406
function joinLayer(parent, nodeType, className) {

test/jasmine/tests/cartesian_test.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ var createGraphDiv = require('../assets/create_graph_div');
88
var destroyGraphDiv = require('../assets/destroy_graph_div');
99
var failTest = require('../assets/fail_test');
1010

11-
1211
describe('restyle', function() {
1312
describe('scatter traces', function() {
1413
var gd;
@@ -375,4 +374,33 @@ describe('subplot creation / deletion:', function() {
375374
.catch(failTest)
376375
.then(done);
377376
});
377+
378+
it('should clear overlaid subplot trace layers on restyle', function(done) {
379+
var fig = Lib.extendDeep({}, require('@mocks/overlaying-axis-lines.json'));
380+
381+
function _assert(xyCnt, x2y2Cnt) {
382+
expect(d3.select('.subplot.xy').select('.plot').selectAll('.trace').size())
383+
.toBe(xyCnt, 'has correct xy subplot trace count');
384+
expect(d3.select('.overplot').select('.x2y2').selectAll('.trace').size())
385+
.toBe(x2y2Cnt, 'has correct x2y2 oveylaid subplot trace count');
386+
}
387+
388+
Plotly.plot(gd, fig).then(function() {
389+
_assert(1, 1);
390+
return Plotly.restyle(gd, 'visible', false, [1]);
391+
})
392+
.then(function() {
393+
_assert(1, 0);
394+
return Plotly.restyle(gd, 'visible', true);
395+
})
396+
.then(function() {
397+
_assert(1, 1);
398+
return Plotly.restyle(gd, 'visible', false);
399+
})
400+
.then(function() {
401+
_assert(0, 0);
402+
})
403+
.catch(failTest)
404+
.then(done);
405+
});
378406
});

0 commit comments

Comments
 (0)