@@ -66,7 +66,7 @@ describe('contour defaults', function() {
66
66
67
67
it ( 'should default connectgaps to false if `z` is not a one dimensional array' , function ( ) {
68
68
traceIn = {
69
- type : 'heatmap ' ,
69
+ type : 'contour ' ,
70
70
z : [ [ 0 , null ] , [ 1 , 2 ] ]
71
71
} ;
72
72
@@ -76,7 +76,7 @@ describe('contour defaults', function() {
76
76
77
77
it ( 'should default connectgaps to true if `z` is a one dimensional array' , function ( ) {
78
78
traceIn = {
79
- type : 'heatmap ' ,
79
+ type : 'contour ' ,
80
80
x : [ 0 , 1 , 0 , 1 ] ,
81
81
y : [ 0 , 0 , 1 , 1 ] ,
82
82
z : [ 0 , null , 1 , 2 ]
@@ -591,3 +591,63 @@ describe('contour plotting and editing', function() {
591
591
. then ( done ) ;
592
592
} ) ;
593
593
} ) ;
594
+
595
+ describe ( 'contour hover' , function ( ) {
596
+ 'use strict' ;
597
+
598
+ var gd ;
599
+
600
+ function _hover ( gd , xval , yval ) {
601
+ var fullLayout = gd . _fullLayout ;
602
+ var calcData = gd . calcdata ;
603
+ var hoverData = [ ] ;
604
+
605
+ for ( var i = 0 ; i < calcData . length ; i ++ ) {
606
+ var pointData = {
607
+ index : false ,
608
+ distance : 20 ,
609
+ cd : calcData [ i ] ,
610
+ trace : calcData [ i ] [ 0 ] . trace ,
611
+ xa : fullLayout . xaxis ,
612
+ ya : fullLayout . yaxis
613
+ } ;
614
+
615
+ var hoverPoint = Contour . hoverPoints ( pointData , xval , yval ) ;
616
+ if ( hoverPoint ) hoverData . push ( hoverPoint [ 0 ] ) ;
617
+ }
618
+
619
+ return hoverData ;
620
+ }
621
+
622
+ function assertLabels ( hoverPoint , xLabel , yLabel , zLabel , text ) {
623
+ expect ( hoverPoint . xLabelVal ) . toBe ( xLabel , 'have correct x label' ) ;
624
+ expect ( hoverPoint . yLabelVal ) . toBe ( yLabel , 'have correct y label' ) ;
625
+ expect ( hoverPoint . zLabelVal ) . toBe ( zLabel , 'have correct z label' ) ;
626
+ expect ( hoverPoint . text ) . toBe ( text , 'have correct text label' ) ;
627
+ }
628
+
629
+ describe ( 'missing data' , function ( ) {
630
+ beforeAll ( function ( done ) {
631
+ gd = createGraphDiv ( ) ;
632
+
633
+ Plotly . plot ( gd , {
634
+ data : [ {
635
+ type : 'contour' ,
636
+ x : [ 10 , 11 , 10 , 11 ] ,
637
+ y : [ 100 , 100 , 101 , 101 ] ,
638
+ z : [ null , 1 , 2 , 3 ] ,
639
+ connectgaps : false ,
640
+ hovergaps : false
641
+ } ]
642
+ } ) . then ( done ) ;
643
+ } ) ;
644
+ afterAll ( destroyGraphDiv ) ;
645
+
646
+ it ( 'should not create zLabels when hovering on missing data and hovergaps is disabled' , function ( ) {
647
+ var pt = _hover ( gd , 10 , 100 ) [ 0 ] ;
648
+
649
+ expect ( pt . index ) . toEqual ( [ 0 , 0 ] , 'have correct index' ) ;
650
+ assertLabels ( pt , 10 , 100 , undefined ) ;
651
+ } ) ;
652
+ } ) ;
653
+ } ) ;
0 commit comments