@@ -385,6 +385,19 @@ function _hover(gd, evt, subplot, noHoverEvent) {
385
385
yval = yvalArray [ subploti ] ;
386
386
}
387
387
388
+ var showSpikes = fullLayout . xaxis && fullLayout . xaxis . showspikes && fullLayout . yaxis && fullLayout . yaxis . showspikes ;
389
+ var showCrosslines = fullLayout . xaxis && fullLayout . xaxis . showcrossline || fullLayout . yaxis && fullLayout . yaxis . showcrossline ;
390
+
391
+ // Find the points for the crosslines first to avoid overwriting the hoverLabels data.
392
+ if ( fullLayout . _has ( 'cartesian' ) && showCrosslines && ! ( showSpikes && hovermode === 'closest' ) ) {
393
+ if ( fullLayout . yaxis . showcrossline ) {
394
+ crosslinePoints . hLinePoint = findCrosslinePoint ( pointData , xval , yval , 'y' , crosslinePoints . hLinePoint ) ;
395
+ }
396
+ if ( fullLayout . xaxis . showcrossline ) {
397
+ crosslinePoints . vLinePoint = findCrosslinePoint ( pointData , xval , yval , 'x' , crosslinePoints . vLinePoint ) ;
398
+ }
399
+ }
400
+
388
401
// Now find the points.
389
402
if ( trace . _module && trace . _module . hoverPoints ) {
390
403
var newPoints = trace . _module . hoverPoints ( pointData , xval , yval , mode , fullLayout . _hoverlayer ) ;
@@ -408,22 +421,11 @@ function _hover(gd, evt, subplot, noHoverEvent) {
408
421
hoverData . splice ( 0 , closedataPreviousLength ) ;
409
422
distance = hoverData [ 0 ] . distance ;
410
423
}
411
-
412
- var showSpikes = fullLayout . xaxis && fullLayout . xaxis . showspikes && fullLayout . yaxis && fullLayout . yaxis . showspikes ;
413
- var showCrosslines = fullLayout . xaxis && fullLayout . xaxis . showcrossline || fullLayout . yaxis && fullLayout . yaxis . showcrossline ;
414
-
415
- if ( fullLayout . _has ( 'cartesian' ) && showCrosslines && ! ( showSpikes && hovermode === 'closest' ) ) {
416
- // Now find the points for the crosslines.
417
- if ( fullLayout . yaxis . showcrossline ) {
418
- crosslinePoints . hLinePoint = findCrosslinePoint ( pointData , xval , yval , 'y' , crosslinePoints . hLinePoint ) ;
419
- }
420
- if ( fullLayout . xaxis . showcrossline ) {
421
- crosslinePoints . vLinePoint = findCrosslinePoint ( pointData , xval , yval , 'x' , crosslinePoints . vLinePoint ) ;
422
- }
423
- }
424
424
}
425
425
426
426
function findCrosslinePoint ( pointData , xval , yval , mode , endPoint ) {
427
+ var tmpDistance = pointData . distance ;
428
+ var tmpIndex = pointData . index ;
427
429
var resultPoint = endPoint ;
428
430
pointData . distance = Infinity ;
429
431
pointData . index = false ;
@@ -447,6 +449,8 @@ function _hover(gd, evt, subplot, noHoverEvent) {
447
449
}
448
450
}
449
451
}
452
+ pointData . index = tmpIndex ;
453
+ pointData . distance = tmpDistance ;
450
454
return resultPoint ;
451
455
}
452
456
@@ -1145,7 +1149,7 @@ function cleanPoint(d, hovermode) {
1145
1149
return d ;
1146
1150
}
1147
1151
1148
- function createCrosslines ( hoverData , fullLayout ) {
1152
+ function createCrosslines ( closestPoints , fullLayout ) {
1149
1153
var showXSpikeline = fullLayout . xaxis && fullLayout . xaxis . showspikes ;
1150
1154
var showYSpikeline = fullLayout . yaxis && fullLayout . yaxis . showspikes ;
1151
1155
var showH = fullLayout . yaxis && fullLayout . yaxis . showcrossline ;
@@ -1168,7 +1172,7 @@ function createCrosslines(hoverData, fullLayout) {
1168
1172
1169
1173
// do not draw a crossline if there is a spikeline
1170
1174
if ( showV && ! ( showXSpikeline && hovermode === 'closest' ) ) {
1171
- vLinePoint = hoverData . vLinePoint ;
1175
+ vLinePoint = closestPoints . vLinePoint ;
1172
1176
xa = vLinePoint . xa ;
1173
1177
vLinePointX = xa . _offset + ( vLinePoint . x0 + vLinePoint . x1 ) / 2 ;
1174
1178
@@ -1192,7 +1196,7 @@ function createCrosslines(hoverData, fullLayout) {
1192
1196
}
1193
1197
1194
1198
if ( showH && ! ( showYSpikeline && hovermode === 'closest' ) ) {
1195
- hLinePoint = hoverData . hLinePoint ;
1199
+ hLinePoint = closestPoints . hLinePoint ;
1196
1200
ya = hLinePoint . ya ;
1197
1201
hLinePointY = ya . _offset + ( hLinePoint . y0 + hLinePoint . y1 ) / 2 ;
1198
1202
0 commit comments