@@ -450,25 +450,67 @@ describe('subplot creation / deletion:', function() {
450450 . then ( done ) ;
451451 } ) ;
452452
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 ) ;
457459
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+ }
460470
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' ] ) ;
463483
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
468488 } ) ;
469- expect ( gd . querySelectorAll ( '.bg' ) . length ) . toBe ( behindCount + x2y2Count ) ;
470- }
489+ } )
490+ . then ( function ( ) {
491+ checkBGLayers ( 2 , 0 , [ 'xy' , 'x2y2' ] ) ;
471492
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 ) {
472514 Plotly . plot ( gd , [
473515 { y : [ 1 , 2 , 3 ] } ,
474516 { y : [ 2 , 3 , 1 ] , xaxis : 'x2' , yaxis : 'y2' } ,
@@ -484,19 +526,19 @@ describe('subplot creation / deletion:', function() {
484526 } )
485527 . then ( function ( ) {
486528 // touching but not overlapping: all backgrounds are in back
487- checkBGLayers ( 2 , 0 ) ;
529+ checkBGLayers ( 2 , 0 , [ 'xy' , 'x2y2' , 'xy3' ] ) ;
488530
489531 // now add a slight overlap: that's enough to put x2y2 in front
490532 return Plotly . relayout ( gd , { 'xaxis2.domain' : [ 0.49 , 1 ] } ) ;
491533 } )
492534 . then ( function ( ) {
493- checkBGLayers ( 1 , 1 ) ;
535+ checkBGLayers ( 1 , 1 , [ 'xy' , 'x2y2' , 'xy3' ] ) ;
494536
495537 // x ranges overlap, but now y ranges are disjoint
496538 return Plotly . relayout ( gd , { 'xaxis2.domain' : [ 0 , 1 ] , 'yaxis.domain' : [ 0 , 0.5 ] } ) ;
497539 } )
498540 . then ( function ( ) {
499- checkBGLayers ( 2 , 0 ) ;
541+ checkBGLayers ( 2 , 0 , [ 'xy' , 'x2y2' , 'xy3' ] ) ;
500542
501543 // regular inset
502544 return Plotly . relayout ( gd , {
@@ -507,7 +549,7 @@ describe('subplot creation / deletion:', function() {
507549 } ) ;
508550 } )
509551 . then ( function ( ) {
510- checkBGLayers ( 1 , 1 ) ;
552+ checkBGLayers ( 1 , 1 , [ 'xy' , 'x2y2' , 'xy3' ] ) ;
511553 } )
512554 . catch ( failTest )
513555 . then ( done ) ;
0 commit comments