@@ -7,6 +7,7 @@ var Drawing = require('@src/components/drawing');
77var createGraphDiv = require ( '../assets/create_graph_div' ) ;
88var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
99var mouseEvent = require ( '../assets/mouse_event' ) ;
10+ var failTest = require ( '../assets/fail_test' ) ;
1011
1112
1213describe ( 'zoom box element' , function ( ) {
@@ -111,7 +112,9 @@ describe('restyle', function() {
111112 } ) . then ( function ( ) {
112113 expect ( d3 . selectAll ( 'g.trace.scatter' ) . size ( ) ) . toEqual ( 0 ) ;
113114
114- } ) . then ( done ) ;
115+ } )
116+ . catch ( failTest )
117+ . then ( done ) ;
115118 } ) ;
116119
117120 it ( 'reuses SVG lines' , function ( done ) {
@@ -149,7 +152,9 @@ describe('restyle', function() {
149152
150153 // Second line was persisted:
151154 expect ( firstLine2 ) . toBe ( secondLine2 ) ;
152- } ) . then ( done ) ;
155+ } )
156+ . catch ( failTest )
157+ . then ( done ) ;
153158 } ) ;
154159
155160 it ( 'can change scatter mode' , function ( done ) {
@@ -194,6 +199,7 @@ describe('restyle', function() {
194199 . then ( function ( ) {
195200 assertScatterModeSizes ( 3 , 9 , 9 ) ;
196201 } )
202+ . catch ( failTest )
197203 . then ( done ) ;
198204
199205 } ) ;
@@ -246,9 +252,9 @@ describe('relayout', function() {
246252 expect ( gd . _fullLayout . xaxis . categoryarray ) . toEqual ( list ) ;
247253 expect ( gd . _fullLayout . xaxis . _initialCategories ) . toEqual ( list ) ;
248254 assertCategories ( list ) ;
249-
250- done ( ) ;
251- } ) ;
255+ } )
256+ . catch ( failTest )
257+ . then ( done ) ;
252258 } ) ;
253259
254260 } ) ;
@@ -300,6 +306,7 @@ describe('relayout', function() {
300306 . then ( function ( ) {
301307 assertPointTranslate ( [ - 540 , 135 ] , [ - 540 , 135 ] ) ;
302308 } )
309+ . catch ( failTest )
303310 . then ( done ) ;
304311 } ) ;
305312
@@ -308,6 +315,11 @@ describe('relayout', function() {
308315} ) ;
309316
310317describe ( 'subplot creation / deletion:' , function ( ) {
318+ var gd ;
319+
320+ beforeEach ( function ( ) {
321+ gd = createGraphDiv ( ) ;
322+ } ) ;
311323
312324 afterEach ( destroyGraphDiv ) ;
313325
@@ -322,13 +334,13 @@ describe('subplot creation / deletion:', function() {
322334 expect ( d3 . select ( '.ytitle' ) . size ( ) ) . toEqual ( len ) ;
323335 }
324336
325- Plotly . plot ( createGraphDiv ( ) , [ ] , {
337+ Plotly . plot ( gd , [ ] , {
326338 xaxis : { title : 'X' } ,
327339 yaxis : { title : 'Y' } ,
328340 xaxis2 : { title : 'X2' , anchor : 'y2' } ,
329341 yaxis2 : { title : 'Y2' , anchor : 'x2' }
330342 } )
331- . then ( function ( gd ) {
343+ . then ( function ( ) {
332344 assertCartesianSubplot ( 1 ) ;
333345
334346 return Plotly . addTraces ( gd , [ {
@@ -340,6 +352,70 @@ describe('subplot creation / deletion:', function() {
340352 . then ( function ( ) {
341353 assertCartesianSubplot ( 0 ) ;
342354 } )
355+ . catch ( failTest )
356+ . then ( done ) ;
357+ } ) ;
358+
359+ it ( 'puts plot backgrounds behind everything except if they overlap' , function ( done ) {
360+ function checkBGLayers ( behindCount , x2y2Count ) {
361+ expect ( gd . querySelectorAll ( '.bglayer rect.bg' ) . length ) . toBe ( behindCount ) ;
362+ expect ( gd . querySelectorAll ( '.subplot.x2y2 rect.bg' ) . length ) . toBe ( x2y2Count ) ;
363+
364+ // xy is the first subplot, so it never gets put in front of others
365+ expect ( gd . querySelectorAll ( '.subplot.xy rect.bg' ) . length ) . toBe ( 0 ) ;
366+
367+ // xy3 is an overlay, so never gets its own bg
368+ expect ( gd . querySelectorAll ( '.subplot.xy3 rect.bg' ) . length ) . toBe ( 0 ) ;
369+
370+ // verify that these are *all* the subplots and backgrounds we have
371+ expect ( gd . querySelectorAll ( '.subplot' ) . length ) . toBe ( 3 ) ;
372+ [ 'xy' , 'x2y2' , 'xy3' ] . forEach ( function ( subplot ) {
373+ expect ( gd . querySelectorAll ( '.subplot.' + subplot ) . length ) . toBe ( 1 ) ;
374+ } ) ;
375+ expect ( gd . querySelectorAll ( '.bg' ) . length ) . toBe ( behindCount + x2y2Count ) ;
376+ }
377+
378+ Plotly . plot ( gd , [
379+ { y : [ 1 , 2 , 3 ] } ,
380+ { y : [ 2 , 3 , 1 ] , xaxis : 'x2' , yaxis : 'y2' } ,
381+ { y : [ 3 , 1 , 2 ] , yaxis : 'y3' }
382+ ] , {
383+ xaxis : { domain : [ 0 , 0.5 ] } ,
384+ xaxis2 : { domain : [ 0.5 , 1 ] , anchor : 'y2' } ,
385+ yaxis : { domain : [ 0 , 1 ] } ,
386+ yaxis2 : { domain : [ 0.5 , 1 ] , anchor : 'x2' } ,
387+ yaxis3 : { overlaying : 'y' } ,
388+ // legend makes its own .bg rect - delete so we can ignore that here
389+ showlegend : false
390+ } )
391+ . then ( function ( ) {
392+ // touching but not overlapping: all backgrounds are in back
393+ checkBGLayers ( 2 , 0 ) ;
394+
395+ // now add a slight overlap: that's enough to put x2y2 in front
396+ return Plotly . relayout ( gd , { 'xaxis2.domain' : [ 0.49 , 1 ] } ) ;
397+ } )
398+ . then ( function ( ) {
399+ checkBGLayers ( 1 , 1 ) ;
400+
401+ // x ranges overlap, but now y ranges are disjoint
402+ return Plotly . relayout ( gd , { 'xaxis2.domain' : [ 0 , 1 ] , 'yaxis.domain' : [ 0 , 0.5 ] } ) ;
403+ } )
404+ . then ( function ( ) {
405+ checkBGLayers ( 2 , 0 ) ;
406+
407+ // regular inset
408+ return Plotly . relayout ( gd , {
409+ 'xaxis.domain' : [ 0 , 1 ] ,
410+ 'yaxis.domain' : [ 0 , 1 ] ,
411+ 'xaxis2.domain' : [ 0.6 , 0.9 ] ,
412+ 'yaxis2.domain' : [ 0.6 , 0.9 ]
413+ } ) ;
414+ } )
415+ . then ( function ( ) {
416+ checkBGLayers ( 1 , 1 ) ;
417+ } )
418+ . catch ( failTest )
343419 . then ( done ) ;
344420 } ) ;
345421} ) ;
0 commit comments