@@ -1083,8 +1083,11 @@ function createHoverText(hoverData, opts, gd) {
1083
1083
legendDraw ( gd , mockLegend ) ;
1084
1084
1085
1085
// Position the hover
1086
+ var legendContainer = container . select ( 'g.legend' ) ;
1087
+ var tbb = legendContainer . node ( ) . getBoundingClientRect ( ) ;
1088
+ var tWidth = tbb . width + 2 * HOVERTEXTPAD ;
1089
+ var tHeight = tbb . height + 2 * HOVERTEXTPAD ;
1086
1090
var winningPoint = hoverData [ 0 ] ;
1087
-
1088
1091
// When the scatter point wins, it's OK for the hovelabel to occlude the bar and other points.
1089
1092
var scatterWon = cartesianScatterPoints [ winningPoint . trace . type ] ;
1090
1093
@@ -1098,7 +1101,7 @@ function createHoverText(hoverData, opts, gd) {
1098
1101
lyBottom = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . y0 , c . y1 ) ; } ) ) ;
1099
1102
}
1100
1103
} else {
1101
- lyTop = lyBottom = Lib . mean ( hoverData . map ( function ( c ) { return ( c . y0 + c . y1 ) / 2 ; } ) ) ;
1104
+ lyTop = lyBottom = Lib . mean ( hoverData . map ( function ( c ) { return ( c . y0 + c . y1 ) / 2 ; } ) ) - tHeight / 2 ;
1102
1105
}
1103
1106
1104
1107
var lxRight , lxLeft ;
@@ -1111,14 +1114,9 @@ function createHoverText(hoverData, opts, gd) {
1111
1114
lxLeft = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . x0 , c . x1 ) ; } ) ) ;
1112
1115
}
1113
1116
} else {
1114
- lxRight = lxLeft = Lib . mean ( hoverData . map ( function ( c ) { return ( c . x0 + c . x1 ) / 2 ; } ) ) ;
1117
+ lxRight = lxLeft = Lib . mean ( hoverData . map ( function ( c ) { return ( c . x0 + c . x1 ) / 2 ; } ) ) - tWidth / 2 ;
1115
1118
}
1116
1119
1117
- var legendContainer = container . select ( 'g.legend' ) ;
1118
- var tbb = legendContainer . node ( ) . getBoundingClientRect ( ) ;
1119
- var tWidth = tbb . width + 2 * HOVERTEXTPAD ;
1120
- var tHeight = tbb . height + 2 * HOVERTEXTPAD ;
1121
-
1122
1120
var xOffset = xa . _offset ;
1123
1121
var yOffset = ya . _offset ;
1124
1122
lyBottom += yOffset ;
0 commit comments