@@ -126,13 +126,70 @@ exports.loneHover = function loneHover(hoverItems, opts) {
126126 hoverItems = [ hoverItems ] ;
127127 }
128128
129+ var gd = opts . gd ;
130+ var gTop = getTopOffset ( gd ) ;
131+ var gLeft = getLeftOffset ( gd ) ;
132+
129133 var pointsData = hoverItems . map ( function ( hoverItem ) {
134+ var _x0 = 0 ;
135+ if ( hoverItem . x0 !== undefined ) _x0 = hoverItem . x0 ;
136+ else if ( hoverItem . x !== undefined ) _x0 = hoverItem . x ;
137+
138+ var _x1 = 0 ;
139+ if ( hoverItem . x1 !== undefined ) _x1 = hoverItem . x1 ;
140+ else if ( hoverItem . x !== undefined ) _x1 = hoverItem . x ;
141+
142+ var _y0 = 0 ;
143+ if ( hoverItem . y0 !== undefined ) _y0 = hoverItem . y0 ;
144+ else if ( hoverItem . y !== undefined ) _y0 = hoverItem . y ;
145+
146+ var _y1 = 0 ;
147+ if ( hoverItem . y1 !== undefined ) _y1 = hoverItem . y1 ;
148+ else if ( hoverItem . y !== undefined ) _y1 = hoverItem . y ;
149+
150+ var eventData = hoverItem . eventData ;
151+ if ( eventData ) {
152+ var x0 = Math . min ( _x0 , _x1 ) ;
153+ var x1 = Math . max ( _x0 , _x1 ) ;
154+ var y0 = Math . min ( _y0 , _y1 ) ;
155+ var y1 = Math . max ( _y0 , _y1 ) ;
156+
157+ var trace = hoverItem . trace ;
158+ if ( Registry . traceIs ( trace , 'gl3d' ) ) {
159+ var container = gd . _fullLayout [ trace . scene ] . _scene . container ;
160+ var dx = container . offsetLeft ;
161+ var dy = container . offsetTop ;
162+ x0 += dx ;
163+ x1 += dx ;
164+ y0 += dy ;
165+ y1 += dy ;
166+ } // TODO: handle heatmapgl
167+
168+ eventData . bbox = {
169+ x0 : x0 + gLeft ,
170+ x1 : x1 + gLeft ,
171+ y0 : y0 + gTop ,
172+ y1 : y1 + gTop
173+ } ;
174+
175+ d3 . select ( '.hover-bbox' )
176+ . attr ( 'x' , x0 )
177+ . attr ( 'y' , y0 )
178+ . attr ( 'width' , Math . max ( 4 , x1 - x0 ) )
179+ . attr ( 'height' , Math . max ( 4 , y1 - y0 ) )
180+ . attr ( 'stroke' , 'black' )
181+ . attr ( 'fill' , 'lightgray' )
182+ . attr ( 'opacity' , '0.5' ) ;
183+ } else {
184+ eventData = false ;
185+ }
186+
130187 return {
131188 color : hoverItem . color || Color . defaultLine ,
132- x0 : hoverItem . x0 || hoverItem . x || 0 ,
133- x1 : hoverItem . x1 || hoverItem . x || 0 ,
134- y0 : hoverItem . y0 || hoverItem . y || 0 ,
135- y1 : hoverItem . y1 || hoverItem . y || 0 ,
189+ x0 : _x0 ,
190+ x1 : _x1 ,
191+ y0 : _y0 ,
192+ y1 : _y1 ,
136193 xLabel : hoverItem . xLabel ,
137194 yLabel : hoverItem . yLabel ,
138195 zLabel : hoverItem . zLabel ,
@@ -158,8 +215,9 @@ exports.loneHover = function loneHover(hoverItems, opts) {
158215 index : 0 ,
159216
160217 hovertemplate : hoverItem . hovertemplate || false ,
161- eventData : hoverItem . eventData || false ,
162218 hovertemplateLabels : hoverItem . hovertemplateLabels || false ,
219+
220+ eventData : eventData
163221 } ;
164222 } ) ;
165223
@@ -174,7 +232,7 @@ exports.loneHover = function loneHover(hoverItems, opts) {
174232 outerContainer : outerContainer3
175233 } ;
176234
177- var hoverLabel = createHoverText ( pointsData , fullOpts , opts . gd ) ;
235+ var hoverLabel = createHoverText ( pointsData , fullOpts , gd ) ;
178236
179237 // Fix vertical overlap
180238 var tooltipSpacing = 5 ;
@@ -199,8 +257,8 @@ exports.loneHover = function loneHover(hoverItems, opts) {
199257 d . offset -= anchor ;
200258 } ) ;
201259
202- var scaleX = opts . gd . _fullLayout . _invScaleX ;
203- var scaleY = opts . gd . _fullLayout . _invScaleY ;
260+ var scaleX = gd . _fullLayout . _invScaleX ;
261+ var scaleY = gd . _fullLayout . _invScaleY ;
204262 alignHoverText ( hoverLabel , fullOpts . rotateLabels , scaleX , scaleY ) ;
205263
206264 return multiHover ? hoverLabel : hoverLabel . node ( ) ;
@@ -732,11 +790,8 @@ function _hover(gd, evt, subplot, noHoverEvent) {
732790 var oldhoverdata = gd . _hoverdata ;
733791 var newhoverdata = [ ] ;
734792
735- // Top/left hover offsets relative to graph div. As long as hover content is
736- // a sibling of the graph div, it will be positioned correctly relative to
737- // the offset parent, whatever that may be.
738- var gTop = gd . offsetTop + gd . clientTop ;
739- var gLeft = gd . offsetLeft + gd . clientLeft ;
793+ var gTop = getTopOffset ( gd ) ;
794+ var gLeft = getLeftOffset ( gd ) ;
740795
741796 // pull out just the data that's useful to
742797 // other people and send it to the event
@@ -2067,3 +2122,9 @@ function getCoord(axLetter, winningPoint, fullLayout) {
20672122
20682123 return val ;
20692124}
2125+
2126+ // Top/left hover offsets relative to graph div. As long as hover content is
2127+ // a sibling of the graph div, it will be positioned correctly relative to
2128+ // the offset parent, whatever that may be.
2129+ function getTopOffset ( gd ) { return gd . offsetTop + gd . clientTop ; }
2130+ function getLeftOffset ( gd ) { return gd . offsetLeft + gd . clientLeft ; }
0 commit comments