@@ -52,18 +52,26 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
52
52
}
53
53
54
54
var period = trace [ posLetter + 'period' ] ;
55
+ var isClosestOrPeriod = isClosest || period ;
55
56
56
57
function thisBarMinPos ( di ) { return thisBarExtPos ( di , - 1 ) ; }
57
58
function thisBarMaxPos ( di ) { return thisBarExtPos ( di , 1 ) ; }
58
59
59
60
function thisBarExtPos ( di , sgn ) {
60
- var w = ( period ) ? di . wPeriod : di . w ;
61
+ var w = di . w ;
61
62
62
63
return di [ posLetter ] + sgn * w / 2 ;
63
64
}
64
65
65
- var minPos = isClosest || period ?
66
- thisBarMinPos :
66
+ function periodLength ( di ) {
67
+ return di [ posLetter + 'End' ] - di [ posLetter + 'Start' ] ;
68
+ }
69
+
70
+ var minPos = isClosest ?
71
+ thisBarMinPos : period ?
72
+ function ( di ) {
73
+ return di . p - periodLength ( di ) / 2 ;
74
+ } :
67
75
function ( di ) {
68
76
/*
69
77
* In compare mode, accept a bar if you're on it *or* its group.
@@ -80,8 +88,11 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
80
88
return Math . min ( thisBarMinPos ( di ) , di . p - t . bardelta / 2 ) ;
81
89
} ;
82
90
83
- var maxPos = isClosest || period ?
84
- thisBarMaxPos :
91
+ var maxPos = isClosest ?
92
+ thisBarMaxPos : period ?
93
+ function ( di ) {
94
+ return di . p + periodLength ( di ) / 2 ;
95
+ } :
85
96
function ( di ) {
86
97
return Math . max ( thisBarMaxPos ( di ) , di . p + t . bardelta / 2 ) ;
87
98
} ;
@@ -156,7 +167,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
156
167
// if we get here and we're not in 'closest' mode, push min/max pos back
157
168
// onto the group - even though that means occasionally the mouse will be
158
169
// over the hover label.
159
- if ( ! isClosest ) {
170
+ if ( ! isClosestOrPeriod ) {
160
171
minPos = function ( di ) {
161
172
return Math . min ( thisBarMinPos ( di ) , di . p - t . bargroupwidth / 2 ) ;
162
173
} ;
@@ -179,9 +190,6 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
179
190
180
191
var hasPeriod = di . orig_p !== undefined ;
181
192
pointData [ posLetter + 'LabelVal' ] = hasPeriod ? di . orig_p : di . p ;
182
- if ( hasPeriod ) {
183
- pointData [ posLetter + 'Period' ] = di . p ;
184
- }
185
193
186
194
pointData . labelLabel = hoverLabelText ( pa , pointData [ posLetter + 'LabelVal' ] , trace [ posLetter + 'hoverformat' ] ) ;
187
195
pointData . valueLabel = hoverLabelText ( sa , pointData [ sizeLetter + 'LabelVal' ] , trace [ sizeLetter + 'hoverformat' ] ) ;
0 commit comments