@@ -358,7 +358,7 @@ exports.drawFramework = function(gd) {
358
358
var subplotData = makeSubplotData ( gd ) ;
359
359
360
360
var subplotLayers = fullLayout . _cartesianlayer . selectAll ( '.subplot' )
361
- . data ( subplotData , Lib . identity ) ;
361
+ . data ( subplotData , String ) ;
362
362
363
363
subplotLayers . enter ( ) . append ( 'g' )
364
364
. attr ( 'class' , function ( name ) { return 'subplot ' + name ; } ) ;
@@ -371,19 +371,9 @@ exports.drawFramework = function(gd) {
371
371
subplotLayers . each ( function ( name ) {
372
372
var plotinfo = fullLayout . _plots [ name ] ;
373
373
374
- // keep ref to plot group
375
374
plotinfo . plotgroup = d3 . select ( this ) ;
376
-
377
- // initialize list of overlay subplots
378
- plotinfo . overlays = [ ] ;
379
-
380
375
makeSubplotLayer ( gd , plotinfo ) ;
381
376
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
377
388
378
// make separate drag layers for each subplot,
389
379
// but append them to paper rather than the plot groups,
@@ -400,27 +390,49 @@ exports.rangePlot = function(gd, plotinfo, cdSubplot) {
400
390
401
391
function makeSubplotData ( gd ) {
402
392
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 ;
410
406
var mainplot = xa2 . _id + ya2 . _id ;
407
+ var mainplotinfo = fullLayout . _plots [ mainplot ] ;
408
+ plotinfo . overlays = [ ] ;
411
409
412
- if ( mainplot !== k && fullLayout . _plots [ mainplot ] ) {
410
+ if ( mainplot !== id && mainplotinfo ) {
411
+ // link 'main plot' ref in overlaying plotinfo
413
412
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 ) ;
416
416
} else {
417
- subplotData . push ( k ) ;
418
417
plotinfo . mainplot = undefined ;
418
+ plotinfo . mainPlotinfo = undefined ;
419
419
}
420
420
}
421
421
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
+ }
424
436
425
437
return subplotData ;
426
438
}
0 commit comments