@@ -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,7 +1326,7 @@ function createHoverText(hoverData, opts) {
1326
1326
stroke : contrastColor
1327
1327
} ) ;
1328
1328
1329
- var tbb = tx . node ( ) . getBoundingClientRect ( ) ;
1329
+ var tbb = getBoundingClientRect ( gd , tx . node ( ) ) ;
1330
1330
var htx = d . xa . _offset + ( d . x0 + d . x1 ) / 2 ;
1331
1331
var hty = d . ya . _offset + ( d . y0 + d . y1 ) / 2 ;
1332
1332
var dx = Math . abs ( d . x1 - d . x0 ) ;
@@ -2100,3 +2100,33 @@ function getCoord(axLetter, winningPoint, fullLayout) {
2100
2100
// the offset parent, whatever that may be.
2101
2101
function getTopOffset ( gd ) { return gd . offsetTop + gd . clientTop ; }
2102
2102
function getLeftOffset ( gd ) { return gd . offsetLeft + gd . clientLeft ; }
2103
+
2104
+ function getBoundingClientRect ( gd , node ) {
2105
+ var fullLayout = gd . _fullLayout ;
2106
+
2107
+ var rect = node . getBoundingClientRect ( ) ;
2108
+
2109
+ var x0 = rect . x ;
2110
+ var y0 = rect . y ;
2111
+ var x1 = x0 + rect . width ;
2112
+ var y1 = y0 + rect . height ;
2113
+
2114
+ var A = Lib . apply3DTransform ( fullLayout . _invTransform ) ( x0 , y0 ) ;
2115
+ var B = Lib . apply3DTransform ( fullLayout . _invTransform ) ( x1 , y1 ) ;
2116
+
2117
+ var Ax = A [ 0 ] ;
2118
+ var Ay = A [ 1 ] ;
2119
+ var Bx = B [ 0 ] ;
2120
+ var By = B [ 1 ] ;
2121
+
2122
+ return {
2123
+ x : Ax ,
2124
+ y : Ay ,
2125
+ width : Bx - Ax ,
2126
+ height : By - Ay ,
2127
+ top : Math . min ( Ay , By ) ,
2128
+ left : Math . min ( Ax , Bx ) ,
2129
+ right : Math . max ( Ax , Bx ) ,
2130
+ bottom : Math . max ( Ay , By ) ,
2131
+ } ;
2132
+ }
0 commit comments