@@ -479,15 +479,20 @@ describe('heatmap calc', function() {
479
479
describe ( 'heatmap plot' , function ( ) {
480
480
'use strict' ;
481
481
482
+ var gd ;
483
+
484
+ beforeEach ( function ( ) {
485
+ gd = createGraphDiv ( ) ;
486
+ } ) ;
487
+
482
488
afterEach ( destroyGraphDiv ) ;
483
489
484
490
it ( 'should not draw traces that are off-screen' , function ( done ) {
485
- var mock = require ( '@mocks/heatmap_multi-trace.json' ) ,
486
- mockCopy = Lib . extendDeep ( { } , mock ) ,
487
- gd = createGraphDiv ( ) ;
491
+ var mock = require ( '@mocks/heatmap_multi-trace.json' ) ;
492
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
488
493
489
494
function assertImageCnt ( cnt ) {
490
- var images = d3 . selectAll ( '.hm' ) . select ( ' image') ;
495
+ var images = d3 . selectAll ( '.hm image' ) ;
491
496
492
497
expect ( images . size ( ) ) . toEqual ( cnt ) ;
493
498
}
@@ -502,15 +507,44 @@ describe('heatmap plot', function() {
502
507
return Plotly . relayout ( gd , 'xaxis.autorange' , true ) ;
503
508
} ) . then ( function ( ) {
504
509
assertImageCnt ( 5 ) ;
510
+ } )
511
+ . catch ( failTest )
512
+ . then ( done ) ;
513
+ } ) ;
505
514
506
- done ( ) ;
507
- } ) ;
515
+ it ( 'keeps the correct ordering after hide and show' , function ( done ) {
516
+ function getIndices ( ) {
517
+ var out = [ ] ;
518
+ d3 . selectAll ( '.hm image' ) . each ( function ( d ) { out . push ( d . trace . index ) ; } ) ;
519
+ return out ;
520
+ }
521
+
522
+ Plotly . newPlot ( gd , [ {
523
+ type : 'heatmap' ,
524
+ z : [ [ 1 , 2 ] , [ 3 , 4 ] ]
525
+ } , {
526
+ type : 'heatmap' ,
527
+ z : [ [ 2 , 1 ] , [ 4 , 3 ] ] ,
528
+ contours : { coloring : 'lines' }
529
+ } ] )
530
+ . then ( function ( ) {
531
+ expect ( getIndices ( ) ) . toEqual ( [ 0 , 1 ] ) ;
532
+ return Plotly . restyle ( gd , 'visible' , false , [ 0 ] ) ;
533
+ } )
534
+ . then ( function ( ) {
535
+ expect ( getIndices ( ) ) . toEqual ( [ 1 ] ) ;
536
+ return Plotly . restyle ( gd , 'visible' , true , [ 0 ] ) ;
537
+ } )
538
+ . then ( function ( ) {
539
+ expect ( getIndices ( ) ) . toEqual ( [ 0 , 1 ] ) ;
540
+ } )
541
+ . catch ( failTest )
542
+ . then ( done ) ;
508
543
} ) ;
509
544
510
545
it ( 'should be able to restyle' , function ( done ) {
511
- var mock = require ( '@mocks/13.json' ) ,
512
- mockCopy = Lib . extendDeep ( { } , mock ) ,
513
- gd = createGraphDiv ( ) ;
546
+ var mock = require ( '@mocks/13.json' ) ;
547
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
514
548
515
549
function getImageURL ( ) {
516
550
return d3 . select ( '.hm > image' ) . attr ( 'href' ) ;
@@ -538,19 +572,18 @@ describe('heatmap plot', function() {
538
572
imageURLs . push ( getImageURL ( ) ) ;
539
573
540
574
expect ( imageURLs [ 1 ] ) . toEqual ( imageURLs [ 3 ] ) ;
541
-
542
- done ( ) ;
543
- } ) ;
575
+ } )
576
+ . catch ( failTest )
577
+ . then ( done ) ;
544
578
} ) ;
545
579
546
580
it ( 'draws canvas with correct margins' , function ( done ) {
547
- var mockWithPadding = require ( '@mocks/heatmap_brick_padding.json' ) ,
548
- mockWithoutPadding = Lib . extendDeep ( { } , mockWithPadding ) ,
549
- gd = createGraphDiv ( ) ,
550
- getContextStub = {
551
- fillRect : jasmine . createSpy ( )
552
- } ,
553
- originalCreateElement = document . createElement ;
581
+ var mockWithPadding = require ( '@mocks/heatmap_brick_padding.json' ) ;
582
+ var mockWithoutPadding = Lib . extendDeep ( { } , mockWithPadding ) ;
583
+ var getContextStub = {
584
+ fillRect : jasmine . createSpy ( )
585
+ } ;
586
+ var originalCreateElement = document . createElement ;
554
587
555
588
mockWithoutPadding . data [ 0 ] . xgap = 0 ;
556
589
mockWithoutPadding . data [ 0 ] . ygap = 0 ;
@@ -591,7 +624,6 @@ describe('heatmap plot', function() {
591
624
} ) ;
592
625
593
626
it ( 'can change z values with connected gaps' , function ( done ) {
594
- var gd = createGraphDiv ( ) ;
595
627
Plotly . newPlot ( gd , [ {
596
628
type : 'heatmap' , connectgaps : true ,
597
629
z : [ [ 1 , 2 ] , [ null , 4 ] , [ 1 , 2 ] ]
@@ -615,7 +647,7 @@ describe('heatmap plot', function() {
615
647
. then ( function ( ) {
616
648
expect ( gd . calcdata [ 0 ] [ 0 ] . z ) . toEqual ( [ [ 1 , 2 ] , [ 2 , 4 ] , [ 1 , 2 ] ] ) ;
617
649
} )
618
- . catch ( fail )
650
+ . catch ( failTest )
619
651
. then ( done ) ;
620
652
} ) ;
621
653
} ) ;
0 commit comments