@@ -479,15 +479,20 @@ describe('heatmap calc', function() {
479479describe ( 'heatmap plot' , function ( ) {
480480 'use strict' ;
481481
482+ var gd ;
483+
484+ beforeEach ( function ( ) {
485+ gd = createGraphDiv ( ) ;
486+ } ) ;
487+
482488 afterEach ( destroyGraphDiv ) ;
483489
484490 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 ) ;
488493
489494 function assertImageCnt ( cnt ) {
490- var images = d3 . selectAll ( '.hm' ) . select ( ' image') ;
495+ var images = d3 . selectAll ( '.hm image' ) ;
491496
492497 expect ( images . size ( ) ) . toEqual ( cnt ) ;
493498 }
@@ -502,15 +507,44 @@ describe('heatmap plot', function() {
502507 return Plotly . relayout ( gd , 'xaxis.autorange' , true ) ;
503508 } ) . then ( function ( ) {
504509 assertImageCnt ( 5 ) ;
510+ } )
511+ . catch ( failTest )
512+ . then ( done ) ;
513+ } ) ;
505514
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 ) ;
508543 } ) ;
509544
510545 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 ) ;
514548
515549 function getImageURL ( ) {
516550 return d3 . select ( '.hm > image' ) . attr ( 'href' ) ;
@@ -538,19 +572,18 @@ describe('heatmap plot', function() {
538572 imageURLs . push ( getImageURL ( ) ) ;
539573
540574 expect ( imageURLs [ 1 ] ) . toEqual ( imageURLs [ 3 ] ) ;
541-
542- done ( ) ;
543- } ) ;
575+ } )
576+ . catch ( failTest )
577+ . then ( done ) ;
544578 } ) ;
545579
546580 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 ;
554587
555588 mockWithoutPadding . data [ 0 ] . xgap = 0 ;
556589 mockWithoutPadding . data [ 0 ] . ygap = 0 ;
@@ -591,7 +624,6 @@ describe('heatmap plot', function() {
591624 } ) ;
592625
593626 it ( 'can change z values with connected gaps' , function ( done ) {
594- var gd = createGraphDiv ( ) ;
595627 Plotly . newPlot ( gd , [ {
596628 type : 'heatmap' , connectgaps : true ,
597629 z : [ [ 1 , 2 ] , [ null , 4 ] , [ 1 , 2 ] ]
@@ -615,7 +647,7 @@ describe('heatmap plot', function() {
615647 . then ( function ( ) {
616648 expect ( gd . calcdata [ 0 ] [ 0 ] . z ) . toEqual ( [ [ 1 , 2 ] , [ 2 , 4 ] , [ 1 , 2 ] ] ) ;
617649 } )
618- . catch ( fail )
650+ . catch ( failTest )
619651 . then ( done ) ;
620652 } ) ;
621653} ) ;
0 commit comments