@@ -26,8 +26,63 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
26
26
ypx = ya . c2p ( yval ) ,
27
27
pt = [ xpx , ypx ] ;
28
28
29
+ // look for points to hover on first, then take fills only if we
30
+ // didn't find a point
31
+ if ( trace . hoveron . indexOf ( 'points' ) !== - 1 ) {
32
+ var dx = function ( di ) {
33
+ // scatter points: d.mrc is the calculated marker radius
34
+ // adjust the distance so if you're inside the marker it
35
+ // always will show up regardless of point size, but
36
+ // prioritize smaller points
37
+ var rad = Math . max ( 3 , di . mrc || 0 ) ;
38
+ return Math . max ( Math . abs ( xa . c2p ( di . x ) - xpx ) - rad , 1 - 3 / rad ) ;
39
+ } ,
40
+ dy = function ( di ) {
41
+ var rad = Math . max ( 3 , di . mrc || 0 ) ;
42
+ return Math . max ( Math . abs ( ya . c2p ( di . y ) - ypx ) - rad , 1 - 3 / rad ) ;
43
+ } ,
44
+ dxy = function ( di ) {
45
+ var rad = Math . max ( 3 , di . mrc || 0 ) ,
46
+ dx = xa . c2p ( di . x ) - xpx ,
47
+ dy = ya . c2p ( di . y ) - ypx ;
48
+ return Math . max ( Math . sqrt ( dx * dx + dy * dy ) - rad , 1 - 3 / rad ) ;
49
+ } ,
50
+ distfn = Fx . getDistanceFunction ( hovermode , dx , dy , dxy ) ;
51
+
52
+ Fx . getClosest ( cd , distfn , pointData ) ;
53
+
54
+ // skip the rest (for this trace) if we didn't find a close point
55
+ if ( pointData . index !== false ) {
56
+
57
+ // the closest data point
58
+ var di = cd [ pointData . index ] ,
59
+ xc = xa . c2p ( di . x , true ) ,
60
+ yc = ya . c2p ( di . y , true ) ,
61
+ rad = di . mrc || 1 ;
62
+
63
+ Lib . extendFlat ( pointData , {
64
+ color : getTraceColor ( trace , di ) ,
65
+
66
+ x0 : xc - rad ,
67
+ x1 : xc + rad ,
68
+ xLabelVal : di . x ,
69
+
70
+ y0 : yc - rad ,
71
+ y1 : yc + rad ,
72
+ yLabelVal : di . y
73
+ } ) ;
74
+
75
+ if ( di . tx ) pointData . text = di . tx ;
76
+ else if ( trace . text ) pointData . text = trace . text ;
77
+
78
+ ErrorBars . hoverInfo ( di , trace , pointData ) ;
79
+
80
+ return [ pointData ] ;
81
+ }
82
+ }
83
+
29
84
// even if hoveron is 'fills', only use it if we have polygons too
30
- if ( trace . hoveron === 'fills' && trace . _polygons ) {
85
+ if ( trace . hoveron . indexOf ( 'fills' ) !== - 1 && trace . _polygons ) {
31
86
var polygons = trace . _polygons ,
32
87
polygonsIn = [ ] ,
33
88
inside = false ,
@@ -100,55 +155,4 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
100
155
return [ pointData ] ;
101
156
}
102
157
}
103
- else {
104
- var dx = function ( di ) {
105
- // scatter points: d.mrc is the calculated marker radius
106
- // adjust the distance so if you're inside the marker it
107
- // always will show up regardless of point size, but
108
- // prioritize smaller points
109
- var rad = Math . max ( 3 , di . mrc || 0 ) ;
110
- return Math . max ( Math . abs ( xa . c2p ( di . x ) - xpx ) - rad , 1 - 3 / rad ) ;
111
- } ,
112
- dy = function ( di ) {
113
- var rad = Math . max ( 3 , di . mrc || 0 ) ;
114
- return Math . max ( Math . abs ( ya . c2p ( di . y ) - ypx ) - rad , 1 - 3 / rad ) ;
115
- } ,
116
- dxy = function ( di ) {
117
- var rad = Math . max ( 3 , di . mrc || 0 ) ,
118
- dx = xa . c2p ( di . x ) - xpx ,
119
- dy = ya . c2p ( di . y ) - ypx ;
120
- return Math . max ( Math . sqrt ( dx * dx + dy * dy ) - rad , 1 - 3 / rad ) ;
121
- } ,
122
- distfn = Fx . getDistanceFunction ( hovermode , dx , dy , dxy ) ;
123
-
124
- Fx . getClosest ( cd , distfn , pointData ) ;
125
-
126
- // skip the rest (for this trace) if we didn't find a close point
127
- if ( pointData . index === false ) return ;
128
-
129
- // the closest data point
130
- var di = cd [ pointData . index ] ,
131
- xc = xa . c2p ( di . x , true ) ,
132
- yc = ya . c2p ( di . y , true ) ,
133
- rad = di . mrc || 1 ;
134
-
135
- Lib . extendFlat ( pointData , {
136
- color : getTraceColor ( trace , di ) ,
137
-
138
- x0 : xc - rad ,
139
- x1 : xc + rad ,
140
- xLabelVal : di . x ,
141
-
142
- y0 : yc - rad ,
143
- y1 : yc + rad ,
144
- yLabelVal : di . y
145
- } ) ;
146
-
147
- if ( di . tx ) pointData . text = di . tx ;
148
- else if ( trace . text ) pointData . text = trace . text ;
149
-
150
- ErrorBars . hoverInfo ( di , trace , pointData ) ;
151
-
152
- return [ pointData ] ;
153
- }
154
158
} ;
0 commit comments