@@ -942,7 +942,6 @@ describe('hover info', function() {
942
942
describe ( 'histogram hover info' , function ( ) {
943
943
it ( 'shows the data range when bins have multiple values' , function ( done ) {
944
944
var gd = createGraphDiv ( ) ;
945
- var pts ;
946
945
947
946
Plotly . plot ( gd , [ {
948
947
x : [ 0 , 2 , 3 , 4 , 5 , 6 , 7 ] ,
@@ -954,18 +953,15 @@ describe('hover info', function() {
954
953
margin : { l : 0 , t : 0 , r : 0 , b : 0 }
955
954
} )
956
955
. then ( function ( ) {
957
- gd . on ( 'plotly_hover' , function ( e ) { pts = e . points ; } ) ;
956
+ var pts = null ;
957
+ gd . once ( 'plotly_hover' , function ( e ) { pts = e . points ; } ) ;
958
958
959
959
_hoverNatural ( gd , 250 , 200 ) ;
960
- assertHoverLabelContent ( {
961
- nums : '3' ,
962
- axis : '3 - 5'
963
- } ) ;
964
- } )
965
- . then ( function ( ) {
960
+ assertHoverLabelContent ( { nums : '3' , axis : '3 - 5' } ) ;
961
+ if ( pts === null ) fail ( 'no hover evt triggered' ) ;
966
962
expect ( pts . length ) . toBe ( 1 ) ;
967
- var pt = pts [ 0 ] ;
968
963
964
+ var pt = pts [ 0 ] ;
969
965
expect ( pt . curveNumber ) . toBe ( 0 ) ;
970
966
expect ( pt . binNumber ) . toBe ( 1 ) ;
971
967
expect ( pt . pointNumbers ) . toEqual ( [ 2 , 3 , 4 ] ) ;
@@ -976,6 +972,32 @@ describe('hover info', function() {
976
972
expect ( pt . xaxis ) . toBe ( gd . _fullLayout . xaxis ) ;
977
973
expect ( pt . yaxis ) . toBe ( gd . _fullLayout . yaxis ) ;
978
974
} )
975
+ . then ( function ( ) {
976
+ var pts = null ;
977
+ gd . once ( 'plotly_hover' , function ( e ) { pts = e . points ; } ) ;
978
+
979
+ _hoverNatural ( gd , 250 , 200 ) ;
980
+ expect ( pts ) . toBe ( null , 'should not emit hover event on same pt' ) ;
981
+ } )
982
+ . then ( function ( ) {
983
+ var pts = null ;
984
+ gd . once ( 'plotly_hover' , function ( e ) { pts = e . points ; } ) ;
985
+
986
+ _hoverNatural ( gd , 350 , 200 ) ;
987
+ assertHoverLabelContent ( { nums : '2' , axis : '6 - 8' } ) ;
988
+ expect ( pts . length ) . toBe ( 1 ) ;
989
+
990
+ var pt = pts [ 0 ] ;
991
+ expect ( pt . curveNumber ) . toBe ( 0 ) ;
992
+ expect ( pt . binNumber ) . toBe ( 2 ) ;
993
+ expect ( pt . pointNumbers ) . toEqual ( [ 5 , 6 ] ) ;
994
+ expect ( pt . x ) . toBe ( 7 ) ;
995
+ expect ( pt . y ) . toBe ( 2 ) ;
996
+ expect ( pt . data ) . toBe ( gd . data [ 0 ] ) ;
997
+ expect ( pt . fullData ) . toBe ( gd . _fullData [ 0 ] ) ;
998
+ expect ( pt . xaxis ) . toBe ( gd . _fullLayout . xaxis ) ;
999
+ expect ( pt . yaxis ) . toBe ( gd . _fullLayout . yaxis ) ;
1000
+ } )
979
1001
. catch ( failTest )
980
1002
. then ( done ) ;
981
1003
} ) ;
0 commit comments