@@ -52,18 +52,26 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
5252 }
5353
5454 var period = trace [ posLetter + 'period' ] ;
55+ var isClosestOrPeriod = isClosest || period ;
5556
5657 function thisBarMinPos ( di ) { return thisBarExtPos ( di , - 1 ) ; }
5758 function thisBarMaxPos ( di ) { return thisBarExtPos ( di , 1 ) ; }
5859
5960 function thisBarExtPos ( di , sgn ) {
60- var w = ( period ) ? di . wPeriod : di . w ;
61+ var w = di . w ;
6162
6263 return di [ posLetter ] + sgn * w / 2 ;
6364 }
6465
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+ } :
6775 function ( di ) {
6876 /*
6977 * 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) {
8088 return Math . min ( thisBarMinPos ( di ) , di . p - t . bardelta / 2 ) ;
8189 } ;
8290
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+ } :
8596 function ( di ) {
8697 return Math . max ( thisBarMaxPos ( di ) , di . p + t . bardelta / 2 ) ;
8798 } ;
@@ -156,7 +167,7 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
156167 // if we get here and we're not in 'closest' mode, push min/max pos back
157168 // onto the group - even though that means occasionally the mouse will be
158169 // over the hover label.
159- if ( ! isClosest ) {
170+ if ( ! isClosestOrPeriod ) {
160171 minPos = function ( di ) {
161172 return Math . min ( thisBarMinPos ( di ) , di . p - t . bargroupwidth / 2 ) ;
162173 } ;
@@ -179,9 +190,6 @@ function hoverOnBars(pointData, xval, yval, hovermode, opts) {
179190
180191 var hasPeriod = di . orig_p !== undefined ;
181192 pointData [ posLetter + 'LabelVal' ] = hasPeriod ? di . orig_p : di . p ;
182- if ( hasPeriod ) {
183- pointData [ posLetter + 'Period' ] = di . p ;
184- }
185193
186194 pointData . labelLabel = hoverLabelText ( pa , pointData [ posLetter + 'LabelVal' ] , trace [ posLetter + 'hoverformat' ] ) ;
187195 pointData . valueLabel = hoverLabelText ( sa , pointData [ sizeLetter + 'LabelVal' ] , trace [ sizeLetter + 'hoverformat' ] ) ;
0 commit comments