@@ -385,6 +385,19 @@ function _hover(gd, evt, subplot, noHoverEvent) {
385385 yval = yvalArray [ subploti ] ;
386386 }
387387
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+
388401 // Now find the points.
389402 if ( trace . _module && trace . _module . hoverPoints ) {
390403 var newPoints = trace . _module . hoverPoints ( pointData , xval , yval , mode , fullLayout . _hoverlayer ) ;
@@ -408,22 +421,11 @@ function _hover(gd, evt, subplot, noHoverEvent) {
408421 hoverData . splice ( 0 , closedataPreviousLength ) ;
409422 distance = hoverData [ 0 ] . distance ;
410423 }
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- }
424424 }
425425
426426 function findCrosslinePoint ( pointData , xval , yval , mode , endPoint ) {
427+ var tmpDistance = pointData . distance ;
428+ var tmpIndex = pointData . index ;
427429 var resultPoint = endPoint ;
428430 pointData . distance = Infinity ;
429431 pointData . index = false ;
@@ -447,6 +449,8 @@ function _hover(gd, evt, subplot, noHoverEvent) {
447449 }
448450 }
449451 }
452+ pointData . index = tmpIndex ;
453+ pointData . distance = tmpDistance ;
450454 return resultPoint ;
451455 }
452456
@@ -1145,7 +1149,7 @@ function cleanPoint(d, hovermode) {
11451149 return d ;
11461150}
11471151
1148- function createCrosslines ( hoverData , fullLayout ) {
1152+ function createCrosslines ( closestPoints , fullLayout ) {
11491153 var showXSpikeline = fullLayout . xaxis && fullLayout . xaxis . showspikes ;
11501154 var showYSpikeline = fullLayout . yaxis && fullLayout . yaxis . showspikes ;
11511155 var showH = fullLayout . yaxis && fullLayout . yaxis . showcrossline ;
@@ -1168,7 +1172,7 @@ function createCrosslines(hoverData, fullLayout) {
11681172
11691173 // do not draw a crossline if there is a spikeline
11701174 if ( showV && ! ( showXSpikeline && hovermode === 'closest' ) ) {
1171- vLinePoint = hoverData . vLinePoint ;
1175+ vLinePoint = closestPoints . vLinePoint ;
11721176 xa = vLinePoint . xa ;
11731177 vLinePointX = xa . _offset + ( vLinePoint . x0 + vLinePoint . x1 ) / 2 ;
11741178
@@ -1192,7 +1196,7 @@ function createCrosslines(hoverData, fullLayout) {
11921196 }
11931197
11941198 if ( showH && ! ( showYSpikeline && hovermode === 'closest' ) ) {
1195- hLinePoint = hoverData . hLinePoint ;
1199+ hLinePoint = closestPoints . hLinePoint ;
11961200 ya = hLinePoint . ya ;
11971201 hLinePointY = ya . _offset + ( hLinePoint . y0 + hLinePoint . y1 ) / 2 ;
11981202
0 commit comments