@@ -18,29 +18,54 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
1818 var hoveron = trace . hoveron || '' ;
1919 var minRad = ( trace . mode . indexOf ( 'markers' ) !== - 1 ) ? 3 : 0.5 ;
2020
21+ var xPeriod = ! ! trace . xperiodalignment ;
22+ var yPeriod = ! ! trace . yperiodalignment ;
23+
2124 // look for points to hover on first, then take fills only if we
2225 // didn't find a point
26+
2327 if ( hoveron . indexOf ( 'points' ) !== - 1 ) {
28+ // dx and dy are used in compare modes - here we want to always
29+ // prioritize the closest data point, at least as long as markers are
30+ // the same size or nonexistent, but still try to prioritize small markers too.
2431 var dx = function ( di ) {
25- // dx and dy are used in compare modes - here we want to always
26- // prioritize the closest data point, at least as long as markers are
27- // the same size or nonexistent, but still try to prioritize small markers too.
32+ if ( xPeriod ) {
33+ var x0 = xa . c2p ( di . xStart ) ;
34+ var x1 = xa . c2p ( di . xEnd ) ;
35+
36+ return (
37+ xpx >= Math . min ( x0 , x1 ) &&
38+ xpx <= Math . max ( x0 , x1 )
39+ ) ? 0 : Infinity ;
40+ }
41+
2842 var rad = Math . max ( 3 , di . mrc || 0 ) ;
2943 var kink = 1 - 1 / rad ;
3044 var dxRaw = Math . abs ( xa . c2p ( di . x ) - xpx ) ;
3145 return ( dxRaw < rad ) ? ( kink * dxRaw / rad ) : ( dxRaw - rad + kink ) ;
3246 } ;
3347 var dy = function ( di ) {
48+ if ( yPeriod ) {
49+ var y0 = ya . c2p ( di . yStart ) ;
50+ var y1 = ya . c2p ( di . yEnd ) ;
51+
52+ return (
53+ ypx >= Math . min ( y0 , y1 ) &&
54+ ypx <= Math . max ( y0 , y1 )
55+ ) ? 0 : Infinity ;
56+ }
57+
3458 var rad = Math . max ( 3 , di . mrc || 0 ) ;
3559 var kink = 1 - 1 / rad ;
3660 var dyRaw = Math . abs ( ya . c2p ( di . y ) - ypx ) ;
3761 return ( dyRaw < rad ) ? ( kink * dyRaw / rad ) : ( dyRaw - rad + kink ) ;
3862 } ;
63+
64+ // scatter points: d.mrc is the calculated marker radius
65+ // adjust the distance so if you're inside the marker it
66+ // always will show up regardless of point size, but
67+ // prioritize smaller points
3968 var dxy = function ( di ) {
40- // scatter points: d.mrc is the calculated marker radius
41- // adjust the distance so if you're inside the marker it
42- // always will show up regardless of point size, but
43- // prioritize smaller points
4469 var rad = Math . max ( minRad , di . mrc || 0 ) ;
4570 var dx = xa . c2p ( di . x ) - xpx ;
4671 var dy = ya . c2p ( di . y ) - ypx ;
@@ -87,9 +112,6 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
87112 hovertemplate : trace . hovertemplate
88113 } ) ;
89114
90- if ( di . orig_x !== undefined ) pointData . xPeriod = di . x ;
91- if ( di . orig_y !== undefined ) pointData . yPeriod = di . y ;
92-
93115 fillText ( di , trace , pointData ) ;
94116 Registry . getComponentMethod ( 'errorbars' , 'hoverInfo' ) ( di , trace , pointData ) ;
95117
0 commit comments