@@ -253,19 +253,29 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
253253 . remove ( ) ;
254254 }
255255
256+ var oldSubplotList = oldFullLayout . _subplots || { } ;
257+ var newSubplotList = newFullLayout . _subplots || { xaxis : [ ] , yaxis : [ ] } ;
258+
259+ // delete any titles we don't need anymore
260+ // check if axis list has changed, and if so clear old titles
261+ if ( oldSubplotList . xaxis && oldSubplotList . yaxis ) {
262+ var oldAxIDs = oldSubplotList . xaxis . concat ( oldSubplotList . yaxis ) ;
263+ var newAxIDs = newSubplotList . xaxis . concat ( newSubplotList . yaxis ) ;
264+
265+ for ( i = 0 ; i < oldAxIDs . length ; i ++ ) {
266+ if ( newAxIDs . indexOf ( oldAxIDs [ i ] ) === - 1 ) {
267+ oldFullLayout . _infolayer . selectAll ( '.g-' + oldAxIDs [ i ] + 'title' ) . remove ( ) ;
268+ }
269+ }
270+ }
271+
272+ // if we've gotten rid of all cartesian traces, remove all the subplot svg items
256273 var hadCartesian = ( oldFullLayout . _has && oldFullLayout . _has ( 'cartesian' ) ) ;
257274 var hasCartesian = ( newFullLayout . _has && newFullLayout . _has ( 'cartesian' ) ) ;
258275
259276 if ( hadCartesian && ! hasCartesian ) {
260- var subplotLayers = oldFullLayout . _cartesianlayer . selectAll ( '.subplot' ) ;
261- var axIds = axisIds . listIds ( { _fullLayout : oldFullLayout } ) ;
262-
263- subplotLayers . call ( purgeSubplotLayers , oldFullLayout ) ;
277+ purgeSubplotLayers ( oldFullLayout . _cartesianlayer . selectAll ( '.subplot' ) , oldFullLayout ) ;
264278 oldFullLayout . _defs . selectAll ( '.axesclip' ) . remove ( ) ;
265-
266- for ( i = 0 ; i < axIds . length ; i ++ ) {
267- oldFullLayout . _infolayer . select ( '.' + axIds [ i ] + 'title' ) . remove ( ) ;
268- }
269279 }
270280} ;
271281
0 commit comments