@@ -306,6 +306,17 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
306306 purgeSubplotLayers ( oldFullLayout . _cartesianlayer . selectAll ( '.subplot' ) , oldFullLayout ) ;
307307 oldFullLayout . _defs . selectAll ( '.axesclip' ) . remove ( ) ;
308308 }
309+ // otherwise look for subplots we need to remove
310+ else if ( oldSubplotList . cartesian ) {
311+ for ( i = 0 ; i < oldSubplotList . cartesian . length ; i ++ ) {
312+ var oldSubplotId = oldSubplotList . cartesian [ i ] ;
313+ if ( newSubplotList . cartesian . indexOf ( oldSubplotId ) === - 1 ) {
314+ var selector = '.' + oldSubplotId + ',.' + oldSubplotId + '-x,.' + oldSubplotId + '-y' ;
315+ oldFullLayout . _cartesianlayer . selectAll ( selector ) . remove ( ) ;
316+ removeSubplotExtras ( oldSubplotId , oldFullLayout ) ;
317+ }
318+ }
319+ }
309320} ;
310321
311322exports . drawFramework = function ( gd ) {
@@ -484,11 +495,9 @@ function purgeSubplotLayers(layers, fullLayout) {
484495
485496 layers . each ( function ( subplotId ) {
486497 var plotgroup = d3 . select ( this ) ;
487- var clipId = 'clip' + fullLayout . _uid + subplotId + 'plot' ;
488498
489499 plotgroup . remove ( ) ;
490- fullLayout . _draggers . selectAll ( 'g.' + subplotId ) . remove ( ) ;
491- fullLayout . _defs . select ( '#' + clipId ) . remove ( ) ;
500+ removeSubplotExtras ( subplotId , fullLayout ) ;
492501
493502 overlayIdsToRemove [ subplotId ] = true ;
494503
@@ -515,6 +524,11 @@ function purgeSubplotLayers(layers, fullLayout) {
515524 }
516525}
517526
527+ function removeSubplotExtras ( subplotId , fullLayout ) {
528+ fullLayout . _draggers . selectAll ( 'g.' + subplotId ) . remove ( ) ;
529+ fullLayout . _defs . select ( '#clip' + fullLayout . _uid + subplotId + 'plot' ) . remove ( ) ;
530+ }
531+
518532function joinLayer ( parent , nodeType , className , dataVal ) {
519533 var layer = parent . selectAll ( '.' + className )
520534 . data ( [ dataVal || 0 ] ) ;
0 commit comments