@@ -1071,20 +1071,35 @@ function createHoverText(hoverData, opts, gd) {
10711071 legendDraw ( gd , mockLegend ) ;
10721072
10731073 // 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+
10741079 var lyBottom , lyTop ;
10751080 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+ }
10781088 } 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 ; } ) ) ;
10801090 }
10811091
10821092 var lxRight , lxLeft ;
10831093 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+ }
10861101 } 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 ; } ) ) ;
10881103 }
10891104
10901105 var legendContainer = container . select ( 'g.legend' ) ;
0 commit comments