|
10 | 10 | 'use strict'; |
11 | 11 |
|
12 | 12 | var d3 = require('d3'); |
| 13 | +var Lib = require('../../lib'); |
13 | 14 | var Plots = require('../plots'); |
14 | 15 | var Axes = require('./axes'); |
15 | | - |
16 | 16 | var constants = require('./constants'); |
17 | 17 |
|
18 | 18 | exports.name = 'cartesian'; |
@@ -147,20 +147,33 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) |
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
| 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 | + } |
150 | 160 | }; |
151 | 161 |
|
152 | 162 | exports.drawFramework = function(gd) { |
153 | 163 | var fullLayout = gd._fullLayout, |
154 | 164 | subplotData = makeSubplotData(gd); |
155 | 165 |
|
156 | 166 | var subplotLayers = fullLayout._cartesianlayer.selectAll('.subplot') |
157 | | - .data(subplotData, String); |
| 167 | + .data(subplotData, Lib.identity); |
158 | 168 |
|
159 | 169 | subplotLayers.enter().append('g') |
160 | 170 | .classed('subplot', true); |
161 | 171 |
|
162 | 172 | subplotLayers.order(); |
163 | 173 |
|
| 174 | + subplotLayers.exit() |
| 175 | + .call(purgeSubplotLayers, fullLayout); |
| 176 | + |
164 | 177 | subplotLayers.each(function(subplot) { |
165 | 178 | var plotgroup = d3.select(this), |
166 | 179 | plotinfo = fullLayout._plots[subplot]; |
@@ -316,6 +329,23 @@ function makeSubplotLayer(plotgroup, gd, subplot) { |
316 | 329 | .classed('crisp', true); |
317 | 330 | } |
318 | 331 |
|
| 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 | + |
319 | 349 | function joinLayer(parent, nodeType, className) { |
320 | 350 | var layer = parent.selectAll('.' + className) |
321 | 351 | .data([0]); |
|
0 commit comments