@@ -358,7 +358,7 @@ 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' )
364364 . attr ( 'class' , function ( name ) { return 'subplot ' + name ; } ) ;
@@ -371,19 +371,9 @@ exports.drawFramework = function(gd) {
371371 subplotLayers . each ( function ( name ) {
372372 var plotinfo = fullLayout . _plots [ name ] ;
373373
374- // keep ref to plot group
375374 plotinfo . plotgroup = d3 . select ( this ) ;
376-
377- // initialize list of overlay subplots
378- plotinfo . overlays = [ ] ;
379-
380375 makeSubplotLayer ( gd , plotinfo ) ;
381376
382- // fill in list of overlay subplots
383- if ( plotinfo . mainplot ) {
384- var mainplot = fullLayout . _plots [ plotinfo . mainplot ] ;
385- mainplot . overlays . push ( plotinfo ) ;
386- }
387377
388378 // make separate drag layers for each subplot,
389379 // but append them to paper rather than the plot groups,
@@ -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}
0 commit comments