@@ -450,25 +450,67 @@ describe('subplot creation / deletion:', function() {
450
450
. then ( done ) ;
451
451
} ) ;
452
452
453
- it ( 'puts plot backgrounds behind everything except if they overlap' , function ( done ) {
454
- function checkBGLayers ( behindCount , x2y2Count ) {
455
- expect ( gd . querySelectorAll ( '.bglayer rect.bg' ) . length ) . toBe ( behindCount ) ;
456
- expect ( gd . querySelectorAll ( '.subplot.x2y2 rect.bg' ) . length ) . toBe ( x2y2Count ) ;
453
+ function checkBGLayers ( behindCount , x2y2Count , subplots ) {
454
+ expect ( gd . querySelectorAll ( '.bglayer rect.bg' ) . length ) . toBe ( behindCount ) ;
455
+ expect ( gd . querySelectorAll ( '.subplot.x2y2 rect.bg' ) . length ) . toBe ( x2y2Count ) ;
456
+
457
+ // xy is the first subplot, so it never gets put in front of others
458
+ expect ( gd . querySelectorAll ( '.subplot.xy rect.bg' ) . length ) . toBe ( 0 ) ;
457
459
458
- // xy is the first subplot, so it never gets put in front of others
459
- expect ( gd . querySelectorAll ( '.subplot.xy rect.bg' ) . length ) . toBe ( 0 ) ;
460
+ // xy3 is an overlay, so never gets its own bg
461
+ expect ( gd . querySelectorAll ( '.subplot.xy3 rect.bg' ) . length ) . toBe ( 0 ) ;
462
+
463
+ // verify that these are *all* the subplots and backgrounds we have
464
+ expect ( gd . querySelectorAll ( '.subplot' ) . length ) . toBe ( subplots . length ) ;
465
+ subplots . forEach ( function ( subplot ) {
466
+ expect ( gd . querySelectorAll ( '.subplot.' + subplot ) . length ) . toBe ( 1 ) ;
467
+ } ) ;
468
+ expect ( gd . querySelectorAll ( '.bg' ) . length ) . toBe ( behindCount + x2y2Count ) ;
469
+ }
460
470
461
- // xy3 is an overlay, so never gets its own bg
462
- expect ( gd . querySelectorAll ( '.subplot.xy3 rect.bg' ) . length ) . toBe ( 0 ) ;
471
+ it ( 'makes new backgrounds when switching between overlaying and separate subplots' , function ( done ) {
472
+ Plotly . newPlot ( gd , [
473
+ { x : [ 1 ] , y : [ 2 ] } ,
474
+ { x : [ 3 ] , y : [ 4 ] , xaxis : 'x2' , yaxis : 'y2' }
475
+ ] , {
476
+ xaxis2 : { overlaying : 'x' } ,
477
+ yaxis2 : { overlaying : 'y' } ,
478
+ plot_bgcolor : 'red' ,
479
+ showlegend : false
480
+ } )
481
+ . then ( function ( ) {
482
+ checkBGLayers ( 1 , 0 , [ 'xy' , 'x2y2' ] ) ;
463
483
464
- // verify that these are *all* the subplots and backgrounds we have
465
- expect ( gd . querySelectorAll ( '.subplot' ) . length ) . toBe ( 3 ) ;
466
- [ 'xy' , 'x2y2' , 'xy3' ] . forEach ( function ( subplot ) {
467
- expect ( gd . querySelectorAll ( '.subplot.' + subplot ) . length ) . toBe ( 1 ) ;
484
+ return Plotly . relayout ( gd , {
485
+ 'xaxis.domain' : [ 0 , 0.4 ] ,
486
+ 'xaxis2.domain' : [ 0.6 , 1 ] ,
487
+ 'xaxis2.overlaying' : null
468
488
} ) ;
469
- expect ( gd . querySelectorAll ( '.bg' ) . length ) . toBe ( behindCount + x2y2Count ) ;
470
- }
489
+ } )
490
+ . then ( function ( ) {
491
+ checkBGLayers ( 2 , 0 , [ 'xy' , 'x2y2' ] ) ;
471
492
493
+ return Plotly . relayout ( gd , {
494
+ 'xaxis2.overlaying' : 'x'
495
+ } ) ;
496
+ } )
497
+ . then ( function ( ) {
498
+ checkBGLayers ( 1 , 0 , [ 'xy' , 'x2y2' ] ) ;
499
+
500
+ return Plotly . relayout ( gd , {
501
+ 'xaxis.domain' : [ 0 , 0.6 ] ,
502
+ 'xaxis2.domain' : [ 0.4 , 1 ] ,
503
+ 'xaxis2.overlaying' : null
504
+ } ) ;
505
+ } )
506
+ . then ( function ( ) {
507
+ checkBGLayers ( 1 , 1 , [ 'xy' , 'x2y2' ] ) ;
508
+ } )
509
+ . catch ( failTest )
510
+ . then ( done ) ;
511
+ } ) ;
512
+
513
+ it ( 'puts plot backgrounds behind everything except if they overlap' , function ( done ) {
472
514
Plotly . plot ( gd , [
473
515
{ y : [ 1 , 2 , 3 ] } ,
474
516
{ y : [ 2 , 3 , 1 ] , xaxis : 'x2' , yaxis : 'y2' } ,
@@ -484,19 +526,19 @@ describe('subplot creation / deletion:', function() {
484
526
} )
485
527
. then ( function ( ) {
486
528
// touching but not overlapping: all backgrounds are in back
487
- checkBGLayers ( 2 , 0 ) ;
529
+ checkBGLayers ( 2 , 0 , [ 'xy' , 'x2y2' , 'xy3' ] ) ;
488
530
489
531
// now add a slight overlap: that's enough to put x2y2 in front
490
532
return Plotly . relayout ( gd , { 'xaxis2.domain' : [ 0.49 , 1 ] } ) ;
491
533
} )
492
534
. then ( function ( ) {
493
- checkBGLayers ( 1 , 1 ) ;
535
+ checkBGLayers ( 1 , 1 , [ 'xy' , 'x2y2' , 'xy3' ] ) ;
494
536
495
537
// x ranges overlap, but now y ranges are disjoint
496
538
return Plotly . relayout ( gd , { 'xaxis2.domain' : [ 0 , 1 ] , 'yaxis.domain' : [ 0 , 0.5 ] } ) ;
497
539
} )
498
540
. then ( function ( ) {
499
- checkBGLayers ( 2 , 0 ) ;
541
+ checkBGLayers ( 2 , 0 , [ 'xy' , 'x2y2' , 'xy3' ] ) ;
500
542
501
543
// regular inset
502
544
return Plotly . relayout ( gd , {
@@ -507,7 +549,7 @@ describe('subplot creation / deletion:', function() {
507
549
} ) ;
508
550
} )
509
551
. then ( function ( ) {
510
- checkBGLayers ( 1 , 1 ) ;
552
+ checkBGLayers ( 1 , 1 , [ 'xy' , 'x2y2' , 'xy3' ] ) ;
511
553
} )
512
554
. catch ( failTest )
513
555
. then ( done ) ;
0 commit comments