@@ -208,8 +208,8 @@ function _hover(gd, evt, subplot, noHoverEvent) {
208
208
return dragElement . unhoverRaw ( gd , evt ) ;
209
209
}
210
210
211
- var hoverdistance = fullLayout . hoverdistance === 0 ? Infinity : fullLayout . hoverdistance ;
212
- var spikedistance = fullLayout . spikedistance === 0 ? Infinity : fullLayout . spikedistance ;
211
+ var hoverdistance = fullLayout . hoverdistance === - 1 ? Infinity : fullLayout . hoverdistance ;
212
+ var spikedistance = fullLayout . spikedistance === - 1 ? Infinity : fullLayout . spikedistance ;
213
213
214
214
// hoverData: the set of candidate points we've found to highlight
215
215
var hoverData = [ ] ,
@@ -268,17 +268,18 @@ function _hover(gd, evt, subplot, noHoverEvent) {
268
268
269
269
// [x|y]px: the pixels (from top left) of the mouse location
270
270
// on the currently selected plot area
271
+ // add pointerX|Y property for drawing the spikes in spikesnap 'cursor' situation
271
272
var hasUserCalledHover = ! evt . target ,
272
273
xpx , ypx ;
273
274
274
275
if ( hasUserCalledHover ) {
275
276
if ( 'xpx' in evt ) xpx = evt . xpx ;
276
277
else xpx = xaArray [ 0 ] . _length / 2 ;
277
- if ( ! ( 'offsetX' in evt ) ) evt . offsetX = xpx + xaArray [ 0 ] . _offset ;
278
+ evt . pointerX = xpx + xaArray [ 0 ] . _offset ;
278
279
279
280
if ( 'ypx' in evt ) ypx = evt . ypx ;
280
281
else ypx = yaArray [ 0 ] . _length / 2 ;
281
- if ( ! ( 'offsetY' in evt ) ) evt . offsetY = ypx + yaArray [ 0 ] . _offset ;
282
+ evt . pointerY = ypx + yaArray [ 0 ] . _offset ;
282
283
}
283
284
else {
284
285
// fire the beforehover event and quit if it returns false
@@ -298,6 +299,8 @@ function _hover(gd, evt, subplot, noHoverEvent) {
298
299
if ( xpx < 0 || xpx > dbb . width || ypx < 0 || ypx > dbb . height ) {
299
300
return dragElement . unhoverRaw ( gd , evt ) ;
300
301
}
302
+ evt . pointerX = evt . offsetX ;
303
+ evt . pointerY = evt . offsetY ;
301
304
}
302
305
303
306
if ( 'xval' in evt ) xvalArray = helpers . flat ( subplots , evt . xval ) ;
@@ -391,21 +394,23 @@ function _hover(gd, evt, subplot, noHoverEvent) {
391
394
yval = yvalArray [ subploti ] ;
392
395
}
393
396
394
- // Now find the points.
395
- if ( trace . _module && trace . _module . hoverPoints ) {
396
- var newPoints = trace . _module . hoverPoints ( pointData , xval , yval , mode , fullLayout . _hoverlayer ) ;
397
- if ( newPoints ) {
398
- var newPoint ;
399
- for ( var newPointNum = 0 ; newPointNum < newPoints . length ; newPointNum ++ ) {
400
- newPoint = newPoints [ newPointNum ] ;
401
- if ( isNumeric ( newPoint . x0 ) && isNumeric ( newPoint . y0 ) ) {
402
- hoverData . push ( cleanPoint ( newPoint , hovermode ) ) ;
397
+ // Now if there is range to look in, find the points to hover.
398
+ if ( hoverdistance !== 0 ) {
399
+ if ( trace . _module && trace . _module . hoverPoints ) {
400
+ var newPoints = trace . _module . hoverPoints ( pointData , xval , yval , mode , fullLayout . _hoverlayer ) ;
401
+ if ( newPoints ) {
402
+ var newPoint ;
403
+ for ( var newPointNum = 0 ; newPointNum < newPoints . length ; newPointNum ++ ) {
404
+ newPoint = newPoints [ newPointNum ] ;
405
+ if ( isNumeric ( newPoint . x0 ) && isNumeric ( newPoint . y0 ) ) {
406
+ hoverData . push ( cleanPoint ( newPoint , hovermode ) ) ;
407
+ }
403
408
}
404
409
}
405
410
}
406
- }
407
- else {
408
- Lib . log ( 'Unrecognized trace type in hover:' , trace ) ;
411
+ else {
412
+ Lib . log ( 'Unrecognized trace type in hover:' , trace ) ;
413
+ }
409
414
}
410
415
411
416
// in closest mode, remove any existing (farther) points
@@ -415,9 +420,9 @@ function _hover(gd, evt, subplot, noHoverEvent) {
415
420
distance = hoverData [ 0 ] . distance ;
416
421
}
417
422
418
- // Now look for the points to draw the spikelines
423
+ // Now if there is range to look in, find the points to draw the spikelines
419
424
// Do it only if there is no hoverData
420
- if ( fullLayout . _has ( 'cartesian' ) ) {
425
+ if ( fullLayout . _has ( 'cartesian' ) && ( spikedistance !== 0 ) ) {
421
426
if ( hoverData . length === 0 ) {
422
427
pointData . distance = spikedistance ;
423
428
pointData . index = false ;
@@ -430,7 +435,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
430
435
if ( closestVPoints . length ) {
431
436
var closestVPt = closestVPoints [ 0 ] ;
432
437
if ( isNumeric ( closestVPt . x0 ) && isNumeric ( closestVPt . y0 ) ) {
433
- tmpPoint = clearClosestPoint ( closestVPt ) ;
438
+ tmpPoint = fillClosestPoint ( closestVPt ) ;
434
439
if ( ! spikePoints . vLinePoint || ( spikePoints . vLinePoint . distance > tmpPoint . distance ) ) {
435
440
spikePoints . vLinePoint = tmpPoint ;
436
441
}
@@ -443,7 +448,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
443
448
if ( closestHPoints . length ) {
444
449
var closestHPt = closestHPoints [ 0 ] ;
445
450
if ( isNumeric ( closestHPt . x0 ) && isNumeric ( closestHPt . y0 ) ) {
446
- tmpPoint = clearClosestPoint ( closestHPt ) ;
451
+ tmpPoint = fillClosestPoint ( closestHPt ) ;
447
452
if ( ! spikePoints . hLinePoint || ( spikePoints . hLinePoint . distance > tmpPoint . distance ) ) {
448
453
spikePoints . hLinePoint = tmpPoint ;
449
454
}
@@ -463,7 +468,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
463
468
xpx = xa . c2p ( xval ) ,
464
469
ypx = ya . c2p ( yval ) ,
465
470
dxy = function ( point ) {
466
- var rad = Math . max ( 3 , point . mrc || 0 ) ,
471
+ var rad = point . kink ,
467
472
dx = ( point . x1 + point . x0 ) / 2 - xpx ,
468
473
dy = ( point . y1 + point . y0 ) / 2 - ypx ;
469
474
return Math . max ( Math . sqrt ( dx * dx + dy * dy ) - rad , 1 - 3 / rad ) ;
@@ -486,7 +491,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
486
491
return resultPoint ;
487
492
}
488
493
489
- function clearClosestPoint ( point ) {
494
+ function fillClosestPoint ( point ) {
490
495
if ( ! point ) return null ;
491
496
return {
492
497
xa : point . xa ,
@@ -502,7 +507,6 @@ function _hover(gd, evt, subplot, noHoverEvent) {
502
507
} ;
503
508
}
504
509
505
- // if hoverData is empty check for the spikes to draw and quit if there are none
506
510
var spikelineOpts = {
507
511
fullLayout : fullLayout ,
508
512
container : fullLayout . _hoverlayer ,
@@ -516,22 +520,24 @@ function _hover(gd, evt, subplot, noHoverEvent) {
516
520
} ;
517
521
gd . _spikepoints = newspikepoints ;
518
522
519
- if ( fullLayout . _has ( 'cartesian' ) ) {
523
+ // Now if it is not restricted by spikedistance option, set the points to draw the spikelines
524
+ if ( fullLayout . _has ( 'cartesian' ) && ( spikedistance !== 0 ) ) {
520
525
if ( hoverData . length !== 0 ) {
521
526
var tmpHPointData = hoverData . filter ( function ( point ) {
522
527
return point . ya . showspikes ;
523
528
} ) ;
524
529
var tmpHPoint = selectClosestPoint ( tmpHPointData , spikedistance ) ;
525
- spikePoints . hLinePoint = clearClosestPoint ( tmpHPoint ) ;
530
+ spikePoints . hLinePoint = fillClosestPoint ( tmpHPoint ) ;
526
531
527
532
var tmpVPointData = hoverData . filter ( function ( point ) {
528
533
return point . xa . showspikes ;
529
534
} ) ;
530
535
var tmpVPoint = selectClosestPoint ( tmpVPointData , spikedistance ) ;
531
- spikePoints . vLinePoint = clearClosestPoint ( tmpVPoint ) ;
536
+ spikePoints . vLinePoint = fillClosestPoint ( tmpVPoint ) ;
532
537
}
533
538
}
534
539
540
+ // if hoverData is empty check for the spikes to draw and quit if there are none
535
541
if ( hoverData . length === 0 ) {
536
542
var result = dragElement . unhoverRaw ( gd , evt ) ;
537
543
if ( fullLayout . _has ( 'cartesian' ) && ( ( spikePoints . hLinePoint !== null ) || ( spikePoints . vLinePoint !== null ) ) ) {
@@ -1228,8 +1234,8 @@ function createSpikelines(closestPoints, opts) {
1228
1234
var xa ,
1229
1235
ya ;
1230
1236
1231
- var showY = closestPoints . hLinePoint ? true : false ;
1232
- var showX = closestPoints . vLinePoint ? true : false ;
1237
+ var showY = ! ! closestPoints . hLinePoint ;
1238
+ var showX = ! ! closestPoints . vLinePoint ;
1233
1239
1234
1240
// Remove old spikeline items
1235
1241
container . selectAll ( '.spikeline' ) . remove ( ) ;
@@ -1248,11 +1254,11 @@ function createSpikelines(closestPoints, opts) {
1248
1254
var ySnap = ya . spikesnap ;
1249
1255
1250
1256
if ( ySnap === 'cursor' ) {
1251
- hLinePointY = evt . offsetY ;
1252
- hLinePointX = evt . offsetX ;
1257
+ hLinePointX = evt . pointerX ;
1258
+ hLinePointY = evt . pointerY ;
1253
1259
} else {
1254
- hLinePointY = ya . _offset + ( hLinePoint . y0 + hLinePoint . y1 ) / 2 ;
1255
1260
hLinePointX = xa . _offset + ( hLinePoint . x0 + hLinePoint . x1 ) / 2 ;
1261
+ hLinePointY = ya . _offset + ( hLinePoint . y0 + hLinePoint . y1 ) / 2 ;
1256
1262
}
1257
1263
var dfltHLineColor = tinycolor . readability ( hLinePoint . color , contrastColor ) < 1.5 ?
1258
1264
Color . contrast ( contrastColor ) : hLinePoint . color ;
@@ -1324,8 +1330,8 @@ function createSpikelines(closestPoints, opts) {
1324
1330
var xSnap = xa . spikesnap ;
1325
1331
1326
1332
if ( xSnap === 'cursor' ) {
1327
- vLinePointX = evt . offsetX ;
1328
- vLinePointY = evt . offsetY ;
1333
+ vLinePointX = evt . pointerX ;
1334
+ vLinePointY = evt . pointerY ;
1329
1335
} else {
1330
1336
vLinePointX = xa . _offset + ( vLinePoint . x0 + vLinePoint . x1 ) / 2 ;
1331
1337
vLinePointY = ya . _offset + ( vLinePoint . y0 + vLinePoint . y1 ) / 2 ;
@@ -1408,7 +1414,7 @@ function hoverChanged(gd, evt, oldhoverdata) {
1408
1414
}
1409
1415
1410
1416
function spikesChanged ( gd , oldspikepoints ) {
1411
- // don't emit any events if nothing changed
1417
+ // don't relayout the plot because of new spikelines if spikelines points didn't change
1412
1418
if ( ! oldspikepoints ) return true ;
1413
1419
if ( oldspikepoints . vLinePoint !== gd . _spikepoints . vLinePoint ||
1414
1420
oldspikepoints . hLinePoint !== gd . _spikepoints . hLinePoint
0 commit comments