@@ -879,6 +879,8 @@ function createHoverText(hoverData, opts) {
879
879
var container = opts . container ;
880
880
var outerContainer = opts . outerContainer ;
881
881
var commonLabelOpts = opts . commonLabelOpts || { } ;
882
+ // Early exit if no labels are drawn
883
+ if ( hoverData . length === 0 ) return [ [ ] ] ;
882
884
883
885
// opts.fontFamily/Size are used for the common label
884
886
// and as defaults for each hover label, though the individual labels
@@ -1085,9 +1087,9 @@ function createHoverText(hoverData, opts) {
1085
1087
if ( helpers . isUnifiedHover ( hovermode ) ) {
1086
1088
// Delete leftover hover labels from other hovermodes
1087
1089
container . selectAll ( 'g.hovertext' ) . remove ( ) ;
1088
-
1090
+ var groupedHoverData = hoverData . filter ( function ( data ) { return data . hoverinfo !== 'none' ; } ) ;
1089
1091
// Return early if nothing is hovered on
1090
- if ( hoverData . length === 0 ) return ;
1092
+ if ( groupedHoverData . length === 0 ) return ;
1091
1093
1092
1094
// mock legend
1093
1095
var hoverlabel = fullLayout . hoverlabel ;
@@ -1111,11 +1113,14 @@ function createHoverText(hoverData, opts) {
1111
1113
1112
1114
// prepare items for the legend
1113
1115
mockLegend . entries = [ ] ;
1114
- for ( var j = 0 ; j < hoverData . length ; j ++ ) {
1115
- var texts = getHoverLabelText ( hoverData [ j ] , true , hovermode , fullLayout , t0 ) ;
1116
+ for ( var j = 0 ; j < groupedHoverData . length ; j ++ ) {
1117
+ var pt = groupedHoverData [ j ] ;
1118
+ if ( pt . hoverinfo === 'none' ) continue ;
1119
+
1120
+ var texts = getHoverLabelText ( pt , true , hovermode , fullLayout , t0 ) ;
1116
1121
var text = texts [ 0 ] ;
1117
1122
var name = texts [ 1 ] ;
1118
- var pt = hoverData [ j ] ;
1123
+
1119
1124
pt . name = name ;
1120
1125
if ( name !== '' ) {
1121
1126
pt . text = name + ' : ' + text ;
@@ -1151,7 +1156,7 @@ function createHoverText(hoverData, opts) {
1151
1156
var tbb = getBoundingClientRect ( gd , legendContainer . node ( ) ) ;
1152
1157
var tWidth = tbb . width + 2 * HOVERTEXTPAD ;
1153
1158
var tHeight = tbb . height + 2 * HOVERTEXTPAD ;
1154
- var winningPoint = hoverData [ 0 ] ;
1159
+ var winningPoint = groupedHoverData [ 0 ] ;
1155
1160
var avgX = ( winningPoint . x0 + winningPoint . x1 ) / 2 ;
1156
1161
var avgY = ( winningPoint . y0 + winningPoint . y1 ) / 2 ;
1157
1162
// When a scatter (or e.g. heatmap) point wins, it's OK for the hovelabel to occlude the bar and other points.
@@ -1166,11 +1171,11 @@ function createHoverText(hoverData, opts) {
1166
1171
lyTop = avgY - HOVERTEXTPAD ;
1167
1172
lyBottom = avgY + HOVERTEXTPAD ;
1168
1173
} else {
1169
- lyTop = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . y0 , c . y1 ) ; } ) ) ;
1170
- lyBottom = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . y0 , c . y1 ) ; } ) ) ;
1174
+ lyTop = Math . min . apply ( null , groupedHoverData . map ( function ( c ) { return Math . min ( c . y0 , c . y1 ) ; } ) ) ;
1175
+ lyBottom = Math . max . apply ( null , groupedHoverData . map ( function ( c ) { return Math . max ( c . y0 , c . y1 ) ; } ) ) ;
1171
1176
}
1172
1177
} else {
1173
- lyTop = lyBottom = Lib . mean ( hoverData . map ( function ( c ) { return ( c . y0 + c . y1 ) / 2 ; } ) ) - tHeight / 2 ;
1178
+ lyTop = lyBottom = Lib . mean ( groupedHoverData . map ( function ( c ) { return ( c . y0 + c . y1 ) / 2 ; } ) ) - tHeight / 2 ;
1174
1179
}
1175
1180
1176
1181
var lxRight , lxLeft ;
@@ -1179,11 +1184,11 @@ function createHoverText(hoverData, opts) {
1179
1184
lxRight = avgX + HOVERTEXTPAD ;
1180
1185
lxLeft = avgX - HOVERTEXTPAD ;
1181
1186
} else {
1182
- lxRight = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . x0 , c . x1 ) ; } ) ) ;
1183
- lxLeft = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . x0 , c . x1 ) ; } ) ) ;
1187
+ lxRight = Math . max . apply ( null , groupedHoverData . map ( function ( c ) { return Math . max ( c . x0 , c . x1 ) ; } ) ) ;
1188
+ lxLeft = Math . min . apply ( null , groupedHoverData . map ( function ( c ) { return Math . min ( c . x0 , c . x1 ) ; } ) ) ;
1184
1189
}
1185
1190
} else {
1186
- lxRight = lxLeft = Lib . mean ( hoverData . map ( function ( c ) { return ( c . x0 + c . x1 ) / 2 ; } ) ) - tWidth / 2 ;
1191
+ lxRight = lxLeft = Lib . mean ( groupedHoverData . map ( function ( c ) { return ( c . x0 + c . x1 ) / 2 ; } ) ) - tWidth / 2 ;
1187
1192
}
1188
1193
1189
1194
var xOffset = xa . _offset ;
0 commit comments