@@ -1071,20 +1071,35 @@ function createHoverText(hoverData, opts, gd) {
1071
1071
legendDraw ( gd , mockLegend ) ;
1072
1072
1073
1073
// Position the hover
1074
+ var winningPoint = hoverData [ 0 ] ;
1075
+
1076
+ // When the scatter point wins, it's OK for the hovelabel to occlude the bar and other points.
1077
+ var scatterWon = winningPoint . trace . type === 'scatter' ;
1078
+
1074
1079
var lyBottom , lyTop ;
1075
1080
if ( axLetter === 'y' ) {
1076
- lyTop = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . y0 , c . y1 ) ; } ) ) ;
1077
- lyBottom = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . y0 , c . y1 ) ; } ) ) ;
1081
+ if ( scatterWon ) {
1082
+ lyTop = Math . min ( winningPoint . y0 , winningPoint . y1 ) ;
1083
+ lyBottom = Math . max ( winningPoint . y0 , winningPoint . y1 ) ;
1084
+ } else {
1085
+ lyTop = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . y0 , c . y1 ) ; } ) ) ;
1086
+ lyBottom = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . y0 , c . y1 ) ; } ) ) ;
1087
+ }
1078
1088
} else {
1079
- lyTop = lyBottom = Lib . mean ( hoverData . map ( function ( c ) { return ( c . y0 + c . y1 ) / 2 ; } ) ) ;
1089
+ lyTop = lyBottom = Lib . mean ( hoverData . map ( function ( c ) { return ( c . y0 + c . y1 ) / 2 ; } ) ) ;
1080
1090
}
1081
1091
1082
1092
var lxRight , lxLeft ;
1083
1093
if ( axLetter === 'x' ) {
1084
- lxRight = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . x0 , c . x1 ) ; } ) ) ;
1085
- lxLeft = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . x0 , c . x1 ) ; } ) ) ;
1094
+ if ( scatterWon ) {
1095
+ lxRight = Math . max ( winningPoint . x0 , winningPoint . x1 ) ;
1096
+ lxLeft = Math . min ( winningPoint . x0 , winningPoint . x1 ) ;
1097
+ } else {
1098
+ lxRight = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . x0 , c . x1 ) ; } ) ) ;
1099
+ lxLeft = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . x0 , c . x1 ) ; } ) ) ;
1100
+ }
1086
1101
} else {
1087
- lxRight = lxLeft = Lib . mean ( hoverData . map ( function ( c ) { return ( c . x0 + c . x1 ) / 2 ; } ) ) ;
1102
+ lxRight = lxLeft = Lib . mean ( hoverData . map ( function ( c ) { return ( c . x0 + c . x1 ) / 2 ; } ) ) ;
1088
1103
}
1089
1104
1090
1105
var legendContainer = container . select ( 'g.legend' ) ;
0 commit comments