@@ -891,7 +891,7 @@ function createHoverText(hoverData, opts) {
891
891
var ya = c0 . ya ;
892
892
var axLetter = hovermode . charAt ( 0 ) ;
893
893
var t0 = c0 [ axLetter + 'Label' ] ;
894
- var outerContainerBB = outerContainer . getBoundingClientRect ( ) ;
894
+ var outerContainerBB = getBoundingClientRect ( gd , outerContainer ) ;
895
895
var outerTop = outerContainerBB . top ;
896
896
var outerWidth = outerContainerBB . width ;
897
897
var outerHeight = outerContainerBB . height ;
@@ -966,7 +966,7 @@ function createHoverText(hoverData, opts) {
966
966
967
967
label . attr ( 'transform' , '' ) ;
968
968
969
- var tbb = ltext . node ( ) . getBoundingClientRect ( ) ;
969
+ var tbb = getBoundingClientRect ( gd , ltext . node ( ) ) ;
970
970
var lx , ly ;
971
971
972
972
if ( hovermode === 'x' ) {
@@ -1059,7 +1059,7 @@ function createHoverText(hoverData, opts) {
1059
1059
var dummy = Drawing . tester . append ( 'text' )
1060
1060
. text ( s . text ( ) )
1061
1061
. call ( Drawing . font , commonLabelFont ) ;
1062
- var dummyBB = dummy . node ( ) . getBoundingClientRect ( ) ;
1062
+ var dummyBB = getBoundingClientRect ( gd , dummy . node ( ) ) ;
1063
1063
if ( Math . round ( dummyBB . width ) < Math . round ( tbb . width ) ) {
1064
1064
s . attr ( 'x' , ltx - dummyBB . width ) ;
1065
1065
}
@@ -1148,7 +1148,7 @@ function createHoverText(hoverData, opts) {
1148
1148
1149
1149
// Position the hover
1150
1150
var legendContainer = container . select ( 'g.legend' ) ;
1151
- var tbb = legendContainer . node ( ) . getBoundingClientRect ( ) ;
1151
+ var tbb = getBoundingClientRect ( gd , legendContainer . node ( ) ) ;
1152
1152
var tWidth = tbb . width + 2 * HOVERTEXTPAD ;
1153
1153
var tHeight = tbb . height + 2 * HOVERTEXTPAD ;
1154
1154
var winningPoint = hoverData [ 0 ] ;
@@ -1313,7 +1313,7 @@ function createHoverText(hoverData, opts) {
1313
1313
. call ( svgTextUtils . positionText , 0 , 0 )
1314
1314
. call ( svgTextUtils . convertToTspans , gd ) ;
1315
1315
1316
- var t2bb = tx2 . node ( ) . getBoundingClientRect ( ) ;
1316
+ var t2bb = getBoundingClientRect ( gd , tx2 . node ( ) ) ;
1317
1317
tx2width = t2bb . width + 2 * HOVERTEXTPAD ;
1318
1318
tx2height = t2bb . height + 2 * HOVERTEXTPAD ;
1319
1319
} else {
@@ -1326,22 +1326,26 @@ function createHoverText(hoverData, opts) {
1326
1326
stroke : contrastColor
1327
1327
} ) ;
1328
1328
1329
- var tbb = tx . node ( ) . getBoundingClientRect ( ) ;
1330
1329
var htx = d . xa . _offset + ( d . x0 + d . x1 ) / 2 ;
1331
1330
var hty = d . ya . _offset + ( d . y0 + d . y1 ) / 2 ;
1332
1331
var dx = Math . abs ( d . x1 - d . x0 ) ;
1333
1332
var dy = Math . abs ( d . y1 - d . y0 ) ;
1334
- var txTotalWidth = tbb . width + HOVERARROWSIZE + HOVERTEXTPAD + tx2width ;
1335
- var anchorStartOK , anchorEndOK ;
1336
1333
1337
- d . ty0 = outerTop - tbb . top ;
1338
- d . bx = tbb . width + 2 * HOVERTEXTPAD ;
1339
- d . by = Math . max ( tbb . height + 2 * HOVERTEXTPAD , tx2height ) ;
1334
+ var tbb = getBoundingClientRect ( gd , tx . node ( ) ) ;
1335
+ var tbbWidth = tbb . width / fullLayout . _invScaleX ;
1336
+ var tbbHeight = tbb . height / fullLayout . _invScaleY ;
1337
+
1338
+ d . ty0 = ( outerTop - tbb . top ) / fullLayout . _invScaleY ;
1339
+ d . bx = tbbWidth + 2 * HOVERTEXTPAD ;
1340
+ d . by = Math . max ( tbbHeight + 2 * HOVERTEXTPAD , tx2height ) ;
1340
1341
d . anchor = 'start' ;
1341
- d . txwidth = tbb . width ;
1342
+ d . txwidth = tbbWidth ;
1342
1343
d . tx2width = tx2width ;
1343
1344
d . offset = 0 ;
1344
1345
1346
+ var txTotalWidth = ( tbbWidth + HOVERARROWSIZE + HOVERTEXTPAD + tx2width ) * fullLayout . _invScaleX ;
1347
+ var anchorStartOK , anchorEndOK ;
1348
+
1345
1349
if ( rotateLabels ) {
1346
1350
d . pos = htx ;
1347
1351
anchorStartOK = hty + dy / 2 + txTotalWidth <= outerHeight ;
@@ -2100,3 +2104,33 @@ function getCoord(axLetter, winningPoint, fullLayout) {
2100
2104
// the offset parent, whatever that may be.
2101
2105
function getTopOffset ( gd ) { return gd . offsetTop + gd . clientTop ; }
2102
2106
function getLeftOffset ( gd ) { return gd . offsetLeft + gd . clientLeft ; }
2107
+
2108
+ function getBoundingClientRect ( gd , node ) {
2109
+ var fullLayout = gd . _fullLayout ;
2110
+
2111
+ var rect = node . getBoundingClientRect ( ) ;
2112
+
2113
+ var x0 = rect . x ;
2114
+ var y0 = rect . y ;
2115
+ var x1 = x0 + rect . width ;
2116
+ var y1 = y0 + rect . height ;
2117
+
2118
+ var A = Lib . apply3DTransform ( fullLayout . _invTransform ) ( x0 , y0 ) ;
2119
+ var B = Lib . apply3DTransform ( fullLayout . _invTransform ) ( x1 , y1 ) ;
2120
+
2121
+ var Ax = A [ 0 ] ;
2122
+ var Ay = A [ 1 ] ;
2123
+ var Bx = B [ 0 ] ;
2124
+ var By = B [ 1 ] ;
2125
+
2126
+ return {
2127
+ x : Ax ,
2128
+ y : Ay ,
2129
+ width : Bx - Ax ,
2130
+ height : By - Ay ,
2131
+ top : Math . min ( Ay , By ) ,
2132
+ left : Math . min ( Ax , Bx ) ,
2133
+ right : Math . max ( Ax , Bx ) ,
2134
+ bottom : Math . max ( Ay , By ) ,
2135
+ } ;
2136
+ }
0 commit comments