@@ -66,7 +66,7 @@ describe('contour defaults', function() {
6666
6767 it ( 'should default connectgaps to false if `z` is not a one dimensional array' , function ( ) {
6868 traceIn = {
69- type : 'heatmap ' ,
69+ type : 'contour ' ,
7070 z : [ [ 0 , null ] , [ 1 , 2 ] ]
7171 } ;
7272
@@ -76,7 +76,7 @@ describe('contour defaults', function() {
7676
7777 it ( 'should default connectgaps to true if `z` is a one dimensional array' , function ( ) {
7878 traceIn = {
79- type : 'heatmap ' ,
79+ type : 'contour ' ,
8080 x : [ 0 , 1 , 0 , 1 ] ,
8181 y : [ 0 , 0 , 1 , 1 ] ,
8282 z : [ 0 , null , 1 , 2 ]
@@ -591,3 +591,63 @@ describe('contour plotting and editing', function() {
591591 . then ( done ) ;
592592 } ) ;
593593} ) ;
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