@@ -1083,8 +1083,11 @@ function createHoverText(hoverData, opts, gd) {
10831083 legendDraw ( gd , mockLegend ) ;
10841084
10851085 // 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 ;
10861090 var winningPoint = hoverData [ 0 ] ;
1087-
10881091 // When the scatter point wins, it's OK for the hovelabel to occlude the bar and other points.
10891092 var scatterWon = cartesianScatterPoints [ winningPoint . trace . type ] ;
10901093
@@ -1098,7 +1101,7 @@ function createHoverText(hoverData, opts, gd) {
10981101 lyBottom = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . y0 , c . y1 ) ; } ) ) ;
10991102 }
11001103 } 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 ;
11021105 }
11031106
11041107 var lxRight , lxLeft ;
@@ -1111,14 +1114,9 @@ function createHoverText(hoverData, opts, gd) {
11111114 lxLeft = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . x0 , c . x1 ) ; } ) ) ;
11121115 }
11131116 } 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 ;
11151118 }
11161119
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-
11221120 var xOffset = xa . _offset ;
11231121 var yOffset = ya . _offset ;
11241122 lyBottom += yOffset ;
0 commit comments