@@ -1089,35 +1089,41 @@ function createHoverText(hoverData, opts, gd) {
1089
1089
1090
1090
var legendContainer = container . select ( 'g.legend' ) ;
1091
1091
var tbb = legendContainer . node ( ) . getBoundingClientRect ( ) ;
1092
- var tWidth = tbb . width ;
1093
- var tHeight = tbb . height ;
1092
+ var tWidth = tbb . width + 2 * HOVERTEXTPAD ;
1093
+ var tHeight = tbb . height + 2 * HOVERTEXTPAD ;
1094
1094
1095
1095
var xOffset = xa . _offset ;
1096
1096
var yOffset = ya . _offset ;
1097
- lyBottom += yOffset + HOVERTEXTPAD ;
1098
- lxRight += xOffset + HOVERTEXTPAD ;
1099
- lxLeft += xOffset - tWidth - HOVERTEXTPAD ;
1100
- lyTop += yOffset - tHeight - HOVERTEXTPAD ;
1097
+ lyBottom += yOffset ;
1098
+ lxRight += xOffset ;
1099
+ lxLeft += xOffset - tWidth ;
1100
+ lyTop += yOffset - tHeight ;
1101
1101
1102
- var lx , ly ;
1102
+ var lx , ly ; // top and left positions of the hover box
1103
1103
1104
1104
// horizontal alignment to end up on screen
1105
- if ( lxRight + tWidth + HOVERTEXTPAD <= outerWidth && lxRight - HOVERTEXTPAD >= 0 ) {
1105
+ if ( lxRight + tWidth <= outerWidth && lxRight >= 0 ) {
1106
1106
lx = lxRight ;
1107
- } else if ( lxLeft + HOVERTEXTPAD <= outerWidth && lxLeft - HOVERTEXTPAD >= 0 ) {
1107
+ } else if ( lxLeft + tWidth <= outerWidth && lxLeft >= 0 ) {
1108
1108
lx = lxLeft ;
1109
+ } else if ( xOffset + tWidth <= outerWidth ) {
1110
+ lx = xOffset ; // subplot left corner
1109
1111
} else {
1110
- lx = xOffset ;
1112
+ lx = 0 ; // paper left corner
1111
1113
}
1114
+ lx += HOVERTEXTPAD ;
1112
1115
1113
1116
// vertical alignement to end up on screen
1114
- if ( lyBottom + tHeight + HOVERTEXTPAD <= outerHeight && lyBottom - HOVERTEXTPAD >= 0 ) {
1117
+ if ( lyBottom + tHeight <= outerHeight && lyBottom >= 0 ) {
1115
1118
ly = lyBottom ;
1116
- } else if ( lyTop + HOVERTEXTPAD <= outerHeight && lyTop - HOVERTEXTPAD >= 0 ) {
1119
+ } else if ( lyTop + tHeight <= outerHeight && lyTop >= 0 ) {
1117
1120
ly = lyTop ;
1121
+ } else if ( yOffset + tHeight <= outerHeight ) {
1122
+ ly = yOffset ; // subplot top corner
1118
1123
} else {
1119
- ly = yOffset ;
1124
+ ly = 0 ; // paper top corner
1120
1125
}
1126
+ ly += HOVERTEXTPAD ;
1121
1127
1122
1128
legendContainer . attr ( 'transform' , strTranslate ( lx , ly ) ) ;
1123
1129
return legendContainer ;
0 commit comments