@@ -194,7 +194,9 @@ exports.loneHover = function loneHover(hoverItems, opts) {
194194 d . offset -= anchor ;
195195 } ) ;
196196
197- alignHoverText ( hoverLabel , fullOpts . rotateLabels ) ;
197+ var scaleX = opts . gd . _fullLayout . _inverseScaleX ;
198+ var scaleY = opts . gd . _fullLayout . _inverseScaleY ;
199+ alignHoverText ( hoverLabel , fullOpts . rotateLabels , scaleX , scaleY ) ;
198200
199201 return multiHover ? hoverLabel : hoverLabel . node ( ) ;
200202} ;
@@ -338,6 +340,11 @@ function _hover(gd, evt, subplot, noHoverEvent) {
338340 xpx = evt . clientX - dbb . left ;
339341 ypx = evt . clientY - dbb . top ;
340342
343+ var transformedCoords = Lib . apply3DTransform ( fullLayout . _inverseTransform ) ( xpx , ypx ) ;
344+
345+ xpx = transformedCoords [ 0 ] ;
346+ ypx = transformedCoords [ 1 ] ;
347+
341348 // in case hover was called from mouseout into hovertext,
342349 // it's possible you're not actually over the plot anymore
343350 if ( xpx < 0 || xpx > xaArray [ 0 ] . _length || ypx < 0 || ypx > yaArray [ 0 ] . _length ) {
@@ -718,10 +725,8 @@ function _hover(gd, evt, subplot, noHoverEvent) {
718725
719726 if ( ! helpers . isUnifiedHover ( hovermode ) ) {
720727 hoverAvoidOverlaps ( hoverLabels , rotateLabels ? 'xa' : 'ya' , fullLayout ) ;
721- alignHoverText ( hoverLabels , rotateLabels ) ;
722- }
723-
724- // TODO: tagName hack is needed to appease geo.js's hack of using evt.target=true
728+ alignHoverText ( hoverLabels , rotateLabels , fullLayout . _inverseScaleX , fullLayout . _inverseScaleY ) ;
729+ } // TODO: tagName hack is needed to appease geo.js's hack of using evt.target=true
725730 // we should improve the "fx" API so other plots can use it without these hack.
726731 if ( evt . target && evt . target . tagName ) {
727732 var hasClickToShow = Registry . getComponentMethod ( 'annotations' , 'hasClickToShow' ) ( gd , newhoverdata ) ;
@@ -1479,7 +1484,10 @@ function hoverAvoidOverlaps(hoverLabels, axKey, fullLayout) {
14791484 }
14801485}
14811486
1482- function alignHoverText ( hoverLabels , rotateLabels ) {
1487+ function alignHoverText ( hoverLabels , rotateLabels , scaleX , scaleY ) {
1488+ var pX = function ( x ) { return x * scaleX ; } ;
1489+ var pY = function ( y ) { return y * scaleY ; } ;
1490+
14831491 // finally set the text positioning relative to the data and draw the
14841492 // box around it
14851493 hoverLabels . each ( function ( d ) {
@@ -1495,7 +1503,8 @@ function alignHoverText(hoverLabels, rotateLabels) {
14951503 var offsetX = 0 ;
14961504 var offsetY = d . offset ;
14971505
1498- if ( anchor === 'middle' ) {
1506+ var isMiddle = anchor === 'middle' ;
1507+ if ( isMiddle ) {
14991508 txx -= d . tx2width / 2 ;
15001509 tx2x += d . txwidth / 2 + HOVERTEXTPAD ;
15011510 }
@@ -1504,49 +1513,50 @@ function alignHoverText(hoverLabels, rotateLabels) {
15041513 offsetX = d . offset * YSHIFTX ;
15051514 }
15061515
1507- g . select ( 'path' ) . attr ( 'd' , anchor === 'middle' ?
1516+ g . select ( 'path' )
1517+ . attr ( 'd' , isMiddle ?
15081518 // middle aligned: rect centered on data
1509- ( 'M-' + ( d . bx / 2 + d . tx2width / 2 ) + ',' + ( offsetY - d . by / 2 ) +
1510- 'h' + d . bx + 'v' + d . by + 'h-' + d . bx + 'Z' ) :
1519+ ( 'M-' + pX ( d . bx / 2 + d . tx2width / 2 ) + ',' + pY ( offsetY - d . by / 2 ) +
1520+ 'h' + pX ( d . bx ) + 'v' + pY ( d . by ) + 'h-' + pX ( d . bx ) + 'Z' ) :
15111521 // left or right aligned: side rect with arrow to data
1512- ( 'M0,0L' + ( horzSign * HOVERARROWSIZE + offsetX ) + ',' + ( HOVERARROWSIZE + offsetY ) +
1513- 'v' + ( d . by / 2 - HOVERARROWSIZE ) +
1514- 'h' + ( horzSign * d . bx ) +
1515- 'v-' + d . by +
1516- 'H' + ( horzSign * HOVERARROWSIZE + offsetX ) +
1517- 'V' + ( offsetY - HOVERARROWSIZE ) +
1522+ ( 'M0,0L' + pX ( horzSign * HOVERARROWSIZE + offsetX ) + ',' + pY ( HOVERARROWSIZE + offsetY ) +
1523+ 'v' + pY ( d . by / 2 - HOVERARROWSIZE ) +
1524+ 'h' + pX ( horzSign * d . bx ) +
1525+ 'v-' + pY ( d . by ) +
1526+ 'H' + pX ( horzSign * HOVERARROWSIZE + offsetX ) +
1527+ 'V' + pY ( offsetY - HOVERARROWSIZE ) +
15181528 'Z' ) ) ;
15191529
1520- var posX = txx + offsetX ;
1530+ var posX = offsetX + txx ;
15211531 var posY = offsetY + d . ty0 - d . by / 2 + HOVERTEXTPAD ;
15221532 var textAlign = d . textAlign || 'auto' ;
15231533
15241534 if ( textAlign !== 'auto' ) {
15251535 if ( textAlign === 'left' && anchor !== 'start' ) {
15261536 tx . attr ( 'text-anchor' , 'start' ) ;
1527- posX = anchor === 'middle' ?
1537+ posX = isMiddle ?
15281538 - d . bx / 2 - d . tx2width / 2 + HOVERTEXTPAD :
15291539 - d . bx - HOVERTEXTPAD ;
15301540 } else if ( textAlign === 'right' && anchor !== 'end' ) {
15311541 tx . attr ( 'text-anchor' , 'end' ) ;
1532- posX = anchor === 'middle' ?
1542+ posX = isMiddle ?
15331543 d . bx / 2 - d . tx2width / 2 - HOVERTEXTPAD :
15341544 d . bx + HOVERTEXTPAD ;
15351545 }
15361546 }
15371547
1538- tx . call ( svgTextUtils . positionText , posX , posY ) ;
1548+ tx . call ( svgTextUtils . positionText , pX ( posX ) , pY ( posY ) ) ;
15391549
15401550 if ( d . tx2width ) {
15411551 g . select ( 'text.name' )
15421552 . call ( svgTextUtils . positionText ,
1543- tx2x + alignShift * HOVERTEXTPAD + offsetX ,
1544- offsetY + d . ty0 - d . by / 2 + HOVERTEXTPAD ) ;
1553+ pX ( tx2x + alignShift * HOVERTEXTPAD + offsetX ) ,
1554+ pY ( offsetY + d . ty0 - d . by / 2 + HOVERTEXTPAD ) ) ;
15451555 g . select ( 'rect' )
15461556 . call ( Drawing . setRect ,
1547- tx2x + ( alignShift - 1 ) * d . tx2width / 2 + offsetX ,
1548- offsetY - d . by / 2 - 1 ,
1549- d . tx2width , d . by + 2 ) ;
1557+ pX ( tx2x + ( alignShift - 1 ) * d . tx2width / 2 + offsetX ) ,
1558+ pY ( offsetY - d . by / 2 - 1 ) ,
1559+ pX ( d . tx2width ) , pY ( d . by + 2 ) ) ;
15501560 }
15511561 } ) ;
15521562}
0 commit comments