Skip to content

Commit 78faa3f

Browse files
committed
plots: add a cartesian subplot purge step
1 parent 937c54b commit 78faa3f

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/plots/cartesian/index.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
'use strict';
1111

1212
var d3 = require('d3');
13+
var Lib = require('../../lib');
1314
var Plots = require('../plots');
1415
var Axes = require('./axes');
15-
1616
var constants = require('./constants');
1717

1818
exports.name = 'cartesian';
@@ -147,20 +147,33 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
147147
}
148148
}
149149
}
150+
151+
var hadCartesian = (oldFullLayout._has && oldFullLayout._has('cartesian'));
152+
var hasCartesian = (newFullLayout._has && newFullLayout._has('cartesian'));
153+
154+
if(hadCartesian && !hasCartesian) {
155+
var subplotLayers = oldFullLayout._cartesianlayer.selectAll('.subplot');
156+
157+
subplotLayers.call(purgeSubplotLayers, oldFullLayout);
158+
oldFullLayout._defs.selectAll('.axesclip').remove();
159+
}
150160
};
151161

152162
exports.drawFramework = function(gd) {
153163
var fullLayout = gd._fullLayout,
154164
subplotData = makeSubplotData(gd);
155165

156166
var subplotLayers = fullLayout._cartesianlayer.selectAll('.subplot')
157-
.data(subplotData, String);
167+
.data(subplotData, Lib.identity);
158168

159169
subplotLayers.enter().append('g')
160170
.classed('subplot', true);
161171

162172
subplotLayers.order();
163173

174+
subplotLayers.exit()
175+
.call(purgeSubplotLayers, fullLayout);
176+
164177
subplotLayers.each(function(subplot) {
165178
var plotgroup = d3.select(this),
166179
plotinfo = fullLayout._plots[subplot];
@@ -316,6 +329,23 @@ function makeSubplotLayer(plotgroup, gd, subplot) {
316329
.classed('crisp', true);
317330
}
318331

332+
function purgeSubplotLayers(layers, fullLayout) {
333+
if(!layers) return;
334+
335+
layers.each(function(subplot) {
336+
var plotgroup = d3.select(this),
337+
clipId = 'clip' + fullLayout._uid + subplot + 'plot';
338+
339+
plotgroup.remove();
340+
fullLayout._draggers.selectAll('g.' + subplot).remove();
341+
fullLayout._defs.select('#' + clipId).remove();
342+
343+
// do not remove individual axis <clipPath>s here
344+
// as other subplots may need them
345+
});
346+
}
347+
348+
319349
function joinLayer(parent, nodeType, className) {
320350
var layer = parent.selectAll('.' + className)
321351
.data([0]);

0 commit comments

Comments
 (0)