@@ -358,37 +358,27 @@ exports.drawFramework = function(gd) {
358358 var subplotData = makeSubplotData ( gd ) ;
359359
360360 var subplotLayers = fullLayout . _cartesianlayer . selectAll ( '.subplot' )
361- . data ( subplotData , Lib . identity ) ;
361+ . data ( subplotData , String ) ;
362362
363363 subplotLayers . enter ( ) . append ( 'g' )
364- . attr ( 'class' , function ( name ) { return 'subplot ' + name ; } ) ;
364+ . attr ( 'class' , function ( d ) { return 'subplot ' + d [ 0 ] ; } ) ;
365365
366366 subplotLayers . order ( ) ;
367367
368368 subplotLayers . exit ( )
369369 . call ( purgeSubplotLayers , fullLayout ) ;
370370
371- subplotLayers . each ( function ( name ) {
372- var plotinfo = fullLayout . _plots [ name ] ;
371+ subplotLayers . each ( function ( d ) {
372+ var id = d [ 0 ] ;
373+ var plotinfo = fullLayout . _plots [ id ] ;
373374
374- // keep ref to plot group
375375 plotinfo . plotgroup = d3 . select ( this ) ;
376-
377- // initialize list of overlay subplots
378- plotinfo . overlays = [ ] ;
379-
380376 makeSubplotLayer ( gd , plotinfo ) ;
381377
382- // fill in list of overlay subplots
383- if ( plotinfo . mainplot ) {
384- var mainplot = fullLayout . _plots [ plotinfo . mainplot ] ;
385- mainplot . overlays . push ( plotinfo ) ;
386- }
387-
388378 // make separate drag layers for each subplot,
389379 // but append them to paper rather than the plot groups,
390380 // so they end up on top of the rest
391- plotinfo . draglayer = ensureSingle ( fullLayout . _draggers , 'g' , name ) ;
381+ plotinfo . draglayer = ensureSingle ( fullLayout . _draggers , 'g' , id ) ;
392382 } ) ;
393383} ;
394384
@@ -400,27 +390,49 @@ exports.rangePlot = function(gd, plotinfo, cdSubplot) {
400390
401391function makeSubplotData ( gd ) {
402392 var fullLayout = gd . _fullLayout ;
403- var subplotData = [ ] ;
404- var overlays = [ ] ;
405-
406- for ( var k in fullLayout . _plots ) {
407- var plotinfo = fullLayout . _plots [ k ] ;
408- var xa2 = plotinfo . xaxis . _mainAxis ;
409- var ya2 = plotinfo . yaxis . _mainAxis ;
393+ var ids = fullLayout . _subplots . cartesian ;
394+ var len = ids . length ;
395+ var subplotData = new Array ( len ) ;
396+ var i , j , id , plotinfo , xa , ya ;
397+
398+ for ( i = 0 ; i < len ; i ++ ) {
399+ id = ids [ i ] ;
400+ plotinfo = fullLayout . _plots [ id ] ;
401+ xa = plotinfo . xaxis ;
402+ ya = plotinfo . yaxis ;
403+
404+ var xa2 = xa . _mainAxis ;
405+ var ya2 = ya . _mainAxis ;
410406 var mainplot = xa2 . _id + ya2 . _id ;
407+ var mainplotinfo = fullLayout . _plots [ mainplot ] ;
408+ plotinfo . overlays = [ ] ;
411409
412- if ( mainplot !== k && fullLayout . _plots [ mainplot ] ) {
410+ if ( mainplot !== id && mainplotinfo ) {
411+ // link 'main plot' ref in overlaying plotinfo
413412 plotinfo . mainplot = mainplot ;
414- plotinfo . mainplotinfo = fullLayout . _plots [ mainplot ] ;
415- overlays . push ( k ) ;
413+ plotinfo . mainplotinfo = mainplotinfo ;
414+ // fill in list of overlaying subplots in 'main plot'
415+ mainplotinfo . overlays . push ( plotinfo ) ;
416416 } else {
417- subplotData . push ( k ) ;
418417 plotinfo . mainplot = undefined ;
418+ plotinfo . mainPlotinfo = undefined ;
419419 }
420420 }
421421
422- // main subplots before overlays
423- subplotData = subplotData . concat ( overlays ) ;
422+ // use info about axis layer and overlaying pattern
423+ // to clean what need to be cleaned up in exit selection
424+ for ( i = 0 ; i < len ; i ++ ) {
425+ id = ids [ i ] ;
426+ plotinfo = fullLayout . _plots [ id ] ;
427+ xa = plotinfo . xaxis ;
428+ ya = plotinfo . yaxis ;
429+
430+ var d = [ id , xa . layer , ya . layer , xa . overlaying || '' , ya . overlaying || '' ] ;
431+ for ( j = 0 ; j < plotinfo . overlays . length ; j ++ ) {
432+ d . push ( plotinfo . overlays [ j ] . id ) ;
433+ }
434+ subplotData [ i ] = d ;
435+ }
424436
425437 return subplotData ;
426438}
@@ -517,7 +529,9 @@ function makeSubplotLayer(gd, plotinfo) {
517529 if ( ! hasOnlyLargeSploms ) {
518530 ensureSingleAndAddDatum ( plotinfo . gridlayer , 'g' , plotinfo . xaxis . _id ) ;
519531 ensureSingleAndAddDatum ( plotinfo . gridlayer , 'g' , plotinfo . yaxis . _id ) ;
520- plotinfo . gridlayer . selectAll ( 'g' ) . sort ( axisIds . idSort ) ;
532+ plotinfo . gridlayer . selectAll ( 'g' )
533+ . map ( function ( d ) { return d [ 0 ] ; } )
534+ . sort ( axisIds . idSort ) ;
521535 }
522536
523537 plotinfo . xlines
@@ -534,13 +548,13 @@ function purgeSubplotLayers(layers, fullLayout) {
534548
535549 var overlayIdsToRemove = { } ;
536550
537- layers . each ( function ( subplotId ) {
551+ layers . each ( function ( d ) {
552+ var id = d [ 0 ] ;
538553 var plotgroup = d3 . select ( this ) ;
539554
540555 plotgroup . remove ( ) ;
541- removeSubplotExtras ( subplotId , fullLayout ) ;
542-
543- overlayIdsToRemove [ subplotId ] = true ;
556+ removeSubplotExtras ( id , fullLayout ) ;
557+ overlayIdsToRemove [ id ] = true ;
544558
545559 // do not remove individual axis <clipPath>s here
546560 // as other subplots may need them
0 commit comments