@@ -358,37 +358,27 @@ 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
- . attr ( 'class' , function ( name ) { return 'subplot ' + name ; } ) ;
364
+ . attr ( 'class' , function ( d ) { return 'subplot ' + d [ 0 ] ; } ) ;
365
365
366
366
subplotLayers . order ( ) ;
367
367
368
368
subplotLayers . exit ( )
369
369
. call ( purgeSubplotLayers , fullLayout ) ;
370
370
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 ] ;
373
374
374
- // keep ref to plot group
375
375
plotinfo . plotgroup = d3 . select ( this ) ;
376
-
377
- // initialize list of overlay subplots
378
- plotinfo . overlays = [ ] ;
379
-
380
376
makeSubplotLayer ( gd , plotinfo ) ;
381
377
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
-
388
378
// make separate drag layers for each subplot,
389
379
// but append them to paper rather than the plot groups,
390
380
// 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 ) ;
392
382
} ) ;
393
383
} ;
394
384
@@ -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
}
@@ -517,7 +529,9 @@ function makeSubplotLayer(gd, plotinfo) {
517
529
if ( ! hasOnlyLargeSploms ) {
518
530
ensureSingleAndAddDatum ( plotinfo . gridlayer , 'g' , plotinfo . xaxis . _id ) ;
519
531
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 ) ;
521
535
}
522
536
523
537
plotinfo . xlines
@@ -534,13 +548,13 @@ function purgeSubplotLayers(layers, fullLayout) {
534
548
535
549
var overlayIdsToRemove = { } ;
536
550
537
- layers . each ( function ( subplotId ) {
551
+ layers . each ( function ( d ) {
552
+ var id = d [ 0 ] ;
538
553
var plotgroup = d3 . select ( this ) ;
539
554
540
555
plotgroup . remove ( ) ;
541
- removeSubplotExtras ( subplotId , fullLayout ) ;
542
-
543
- overlayIdsToRemove [ subplotId ] = true ;
556
+ removeSubplotExtras ( id , fullLayout ) ;
557
+ overlayIdsToRemove [ id ] = true ;
544
558
545
559
// do not remove individual axis <clipPath>s here
546
560
// as other subplots may need them
0 commit comments