@@ -7,6 +7,7 @@ var Drawing = require('@src/components/drawing');
7
7
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
8
var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
9
9
var mouseEvent = require ( '../assets/mouse_event' ) ;
10
+ var failTest = require ( '../assets/fail_test' ) ;
10
11
11
12
12
13
describe ( 'zoom box element' , function ( ) {
@@ -111,7 +112,9 @@ describe('restyle', function() {
111
112
} ) . then ( function ( ) {
112
113
expect ( d3 . selectAll ( 'g.trace.scatter' ) . size ( ) ) . toEqual ( 0 ) ;
113
114
114
- } ) . then ( done ) ;
115
+ } )
116
+ . catch ( failTest )
117
+ . then ( done ) ;
115
118
} ) ;
116
119
117
120
it ( 'reuses SVG lines' , function ( done ) {
@@ -149,7 +152,9 @@ describe('restyle', function() {
149
152
150
153
// Second line was persisted:
151
154
expect ( firstLine2 ) . toBe ( secondLine2 ) ;
152
- } ) . then ( done ) ;
155
+ } )
156
+ . catch ( failTest )
157
+ . then ( done ) ;
153
158
} ) ;
154
159
155
160
it ( 'can change scatter mode' , function ( done ) {
@@ -194,6 +199,7 @@ describe('restyle', function() {
194
199
. then ( function ( ) {
195
200
assertScatterModeSizes ( 3 , 9 , 9 ) ;
196
201
} )
202
+ . catch ( failTest )
197
203
. then ( done ) ;
198
204
199
205
} ) ;
@@ -246,9 +252,9 @@ describe('relayout', function() {
246
252
expect ( gd . _fullLayout . xaxis . categoryarray ) . toEqual ( list ) ;
247
253
expect ( gd . _fullLayout . xaxis . _initialCategories ) . toEqual ( list ) ;
248
254
assertCategories ( list ) ;
249
-
250
- done ( ) ;
251
- } ) ;
255
+ } )
256
+ . catch ( failTest )
257
+ . then ( done ) ;
252
258
} ) ;
253
259
254
260
} ) ;
@@ -300,6 +306,7 @@ describe('relayout', function() {
300
306
. then ( function ( ) {
301
307
assertPointTranslate ( [ - 540 , 135 ] , [ - 540 , 135 ] ) ;
302
308
} )
309
+ . catch ( failTest )
303
310
. then ( done ) ;
304
311
} ) ;
305
312
@@ -308,6 +315,11 @@ describe('relayout', function() {
308
315
} ) ;
309
316
310
317
describe ( 'subplot creation / deletion:' , function ( ) {
318
+ var gd ;
319
+
320
+ beforeEach ( function ( ) {
321
+ gd = createGraphDiv ( ) ;
322
+ } ) ;
311
323
312
324
afterEach ( destroyGraphDiv ) ;
313
325
@@ -322,13 +334,13 @@ describe('subplot creation / deletion:', function() {
322
334
expect ( d3 . select ( '.ytitle' ) . size ( ) ) . toEqual ( len ) ;
323
335
}
324
336
325
- Plotly . plot ( createGraphDiv ( ) , [ ] , {
337
+ Plotly . plot ( gd , [ ] , {
326
338
xaxis : { title : 'X' } ,
327
339
yaxis : { title : 'Y' } ,
328
340
xaxis2 : { title : 'X2' , anchor : 'y2' } ,
329
341
yaxis2 : { title : 'Y2' , anchor : 'x2' }
330
342
} )
331
- . then ( function ( gd ) {
343
+ . then ( function ( ) {
332
344
assertCartesianSubplot ( 1 ) ;
333
345
334
346
return Plotly . addTraces ( gd , [ {
@@ -340,6 +352,70 @@ describe('subplot creation / deletion:', function() {
340
352
. then ( function ( ) {
341
353
assertCartesianSubplot ( 0 ) ;
342
354
} )
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 )
343
419
. then ( done ) ;
344
420
} ) ;
345
421
} ) ;
0 commit comments