@@ -10,6 +10,7 @@ var Axes = PlotlyInternal.Axes;
1010var createGraphDiv = require ( '../assets/create_graph_div' ) ;
1111var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
1212var customMatchers = require ( '../assets/custom_matchers' ) ;
13+ var failTest = require ( '../assets/fail_test' ) ;
1314
1415describe ( 'Bar.supplyDefaults' , function ( ) {
1516 'use strict' ;
@@ -1209,7 +1210,10 @@ describe('bar hover', function() {
12091210
12101211 function _hover ( gd , xval , yval , hovermode ) {
12111212 var pointData = getPointData ( gd ) ;
1212- var pt = Bar . hoverPoints ( pointData , xval , yval , hovermode ) [ 0 ] ;
1213+ var pts = Bar . hoverPoints ( pointData , xval , yval , hovermode ) ;
1214+ if ( ! pts ) return false ;
1215+
1216+ var pt = pts [ 0 ] ;
12131217
12141218 return {
12151219 style : [ pt . index , pt . color , pt . xLabelVal , pt . yLabelVal ] ,
@@ -1296,7 +1300,7 @@ describe('bar hover', function() {
12961300 gd = createGraphDiv ( ) ;
12971301 } ) ;
12981302
1299- it ( 'should return correct \'closest\' hover data (single bar, trace width)' , function ( done ) {
1303+ it ( 'should return correct hover data (single bar, trace width)' , function ( done ) {
13001304 Plotly . plot ( gd , [ {
13011305 type : 'bar' ,
13021306 x : [ 1 ] ,
@@ -1307,15 +1311,39 @@ describe('bar hover', function() {
13071311 xaxis : { range : [ - 200 , 200 ] }
13081312 } )
13091313 . then ( function ( ) {
1310- var out = _hover ( gd , 0 , 0 , 'closest' ) ;
1311-
1312- expect ( out . style ) . toEqual ( [ 0 , 'red' , 1 , 2 ] ) ;
1313- assertPos ( out . pos , [ 264 , 278 , 14 , 14 ] ) ;
1314+ // all these x, y, hovermode should give the same (the only!) hover label
1315+ [
1316+ [ 0 , 0 , 'closest' ] ,
1317+ [ - 3.9 , 1 , 'closest' ] ,
1318+ [ 5.9 , 1.9 , 'closest' ] ,
1319+ [ - 3.9 , - 10 , 'x' ] ,
1320+ [ 5.9 , 19 , 'x' ]
1321+ ] . forEach ( function ( hoverSpec ) {
1322+ var out = _hover ( gd , hoverSpec [ 0 ] , hoverSpec [ 1 ] , hoverSpec [ 2 ] ) ;
1323+
1324+ expect ( out . style ) . toEqual ( [ 0 , 'red' , 1 , 2 ] , hoverSpec ) ;
1325+ assertPos ( out . pos , [ 264 , 278 , 14 , 14 ] , hoverSpec ) ;
1326+ } ) ;
1327+
1328+ // then a few that are off the edge so yield nothing
1329+ [
1330+ [ 1 , - 0.1 , 'closest' ] ,
1331+ [ 1 , 2.1 , 'closest' ] ,
1332+ [ - 4.1 , 1 , 'closest' ] ,
1333+ [ 6.1 , 1 , 'closest' ] ,
1334+ [ - 4.1 , 1 , 'x' ] ,
1335+ [ 6.1 , 1 , 'x' ]
1336+ ] . forEach ( function ( hoverSpec ) {
1337+ var out = _hover ( gd , hoverSpec [ 0 ] , hoverSpec [ 1 ] , hoverSpec [ 2 ] ) ;
1338+
1339+ expect ( out ) . toBe ( false , hoverSpec ) ;
1340+ } ) ;
13141341 } )
1342+ . catch ( failTest )
13151343 . then ( done ) ;
13161344 } ) ;
13171345
1318- it ( 'should return correct \'closest\' hover data (two bars, array width)' , function ( done ) {
1346+ it ( 'should return correct hover data (two bars, array width)' , function ( done ) {
13191347 Plotly . plot ( gd , [ {
13201348 type : 'bar' ,
13211349 x : [ 1 , 200 ] ,
@@ -1338,13 +1366,18 @@ describe('bar hover', function() {
13381366
13391367 expect ( out . style ) . toEqual ( [ 0 , 'red' , 1 , 2 ] ) ;
13401368 assertPos ( out . pos , [ 99 , 106 , 13 , 13 ] ) ;
1341- } )
1342- . then ( function ( ) {
1343- var out = _hover ( gd , 164 , 0.8 , 'closest' ) ;
1369+
1370+ out = _hover ( gd , 164 , 0.8 , 'closest' ) ;
13441371
13451372 expect ( out . style ) . toEqual ( [ 1 , 'red' , 200 , 1 ] ) ;
13461373 assertPos ( out . pos , [ 222 , 235 , 168 , 168 ] ) ;
1374+
1375+ out = _hover ( gd , 125 , 0.8 , 'x' ) ;
1376+
1377+ expect ( out . style ) . toEqual ( [ 1 , 'red' , 200 , 1 ] ) ;
1378+ assertPos ( out . pos , [ 201 , 301 , 168 , 168 ] ) ;
13471379 } )
1380+ . catch ( failTest )
13481381 . then ( done ) ;
13491382 } ) ;
13501383
0 commit comments