@@ -772,12 +772,9 @@ function _hover(gd, evt, subplot, noHoverEvent) {
772
772
hoverdistance : fullLayout . hoverdistance
773
773
} ;
774
774
775
- var actualHoverData = hoverData . filter ( function ( d ) {
776
- return d . hoverinfo !== 'none' ;
777
- } ) ;
778
- var hoverLabels = actualHoverData . length && createHoverText ( actualHoverData , labelOpts , gd ) ;
775
+ var hoverLabels = createHoverText ( hoverData , labelOpts , gd ) ;
779
776
780
- if ( hoverLabels && ! helpers . isUnifiedHover ( hovermode ) ) {
777
+ if ( ! helpers . isUnifiedHover ( hovermode ) ) {
781
778
hoverAvoidOverlaps ( hoverLabels , rotateLabels ? 'xa' : 'ya' , fullLayout ) ;
782
779
alignHoverText ( hoverLabels , rotateLabels , fullLayout . _invScaleX , fullLayout . _invScaleY ) ;
783
780
} // TODO: tagName hack is needed to appease geo.js's hack of using evt.target=true
@@ -1025,14 +1022,11 @@ function createHoverText(hoverData, opts, gd) {
1025
1022
1026
1023
// Show a single hover label
1027
1024
if ( helpers . isUnifiedHover ( hovermode ) ) {
1028
- var unifiedHoverData = hoverData . filter ( function ( d ) {
1029
- return d . hoverinfo !== 'none' ;
1030
- } ) ;
1031
1025
// Delete leftover hover labels from other hovermodes
1032
1026
container . selectAll ( 'g.hovertext' ) . remove ( ) ;
1033
1027
1034
1028
// Return early if nothing is hovered on
1035
- if ( unifiedHoverData . length === 0 ) return ;
1029
+ if ( hoverData . length === 0 ) return ;
1036
1030
1037
1031
// mock legend
1038
1032
var mockLayoutIn = {
@@ -1054,11 +1048,14 @@ function createHoverText(hoverData, opts, gd) {
1054
1048
1055
1049
// prepare items for the legend
1056
1050
mockLegend . entries = [ ] ;
1057
- for ( var j = 0 ; j < unifiedHoverData . length ; j ++ ) {
1058
- var texts = getHoverLabelText ( unifiedHoverData [ j ] , true , hovermode , fullLayout , t0 ) ;
1051
+ for ( var j = 0 ; j < hoverData . length ; j ++ ) {
1052
+ var pt = hoverData [ j ] ;
1053
+ if ( pt . hoverinfo === 'none' ) continue ;
1054
+
1055
+ var texts = getHoverLabelText ( pt , true , hovermode , fullLayout , t0 ) ;
1059
1056
var text = texts [ 0 ] ;
1060
1057
var name = texts [ 1 ] ;
1061
- var pt = unifiedHoverData [ j ] ;
1058
+
1062
1059
pt . name = name ;
1063
1060
if ( name !== '' ) {
1064
1061
pt . text = name + ' : ' + text ;
@@ -1093,7 +1090,7 @@ function createHoverText(hoverData, opts, gd) {
1093
1090
var tbb = legendContainer . node ( ) . getBoundingClientRect ( ) ;
1094
1091
var tWidth = tbb . width + 2 * HOVERTEXTPAD ;
1095
1092
var tHeight = tbb . height + 2 * HOVERTEXTPAD ;
1096
- var winningPoint = unifiedHoverData [ 0 ] ;
1093
+ var winningPoint = hoverData [ 0 ] ;
1097
1094
var avgX = ( winningPoint . x0 + winningPoint . x1 ) / 2 ;
1098
1095
var avgY = ( winningPoint . y0 + winningPoint . y1 ) / 2 ;
1099
1096
// When a scatter (or e.g. heatmap) point wins, it's OK for the hovelabel to occlude the bar and other points.
@@ -1108,11 +1105,11 @@ function createHoverText(hoverData, opts, gd) {
1108
1105
lyTop = avgY - HOVERTEXTPAD ;
1109
1106
lyBottom = avgY + HOVERTEXTPAD ;
1110
1107
} else {
1111
- lyTop = Math . min . apply ( null , unifiedHoverData . map ( function ( c ) { return Math . min ( c . y0 , c . y1 ) ; } ) ) ;
1112
- lyBottom = Math . max . apply ( null , unifiedHoverData . map ( function ( c ) { return Math . max ( c . y0 , c . y1 ) ; } ) ) ;
1108
+ lyTop = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . y0 , c . y1 ) ; } ) ) ;
1109
+ lyBottom = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . y0 , c . y1 ) ; } ) ) ;
1113
1110
}
1114
1111
} else {
1115
- lyTop = lyBottom = Lib . mean ( unifiedHoverData . map ( function ( c ) { return ( c . y0 + c . y1 ) / 2 ; } ) ) - tHeight / 2 ;
1112
+ lyTop = lyBottom = Lib . mean ( hoverData . map ( function ( c ) { return ( c . y0 + c . y1 ) / 2 ; } ) ) - tHeight / 2 ;
1116
1113
}
1117
1114
1118
1115
var lxRight , lxLeft ;
@@ -1121,11 +1118,11 @@ function createHoverText(hoverData, opts, gd) {
1121
1118
lxRight = avgX + HOVERTEXTPAD ;
1122
1119
lxLeft = avgX - HOVERTEXTPAD ;
1123
1120
} else {
1124
- lxRight = Math . max . apply ( null , unifiedHoverData . map ( function ( c ) { return Math . max ( c . x0 , c . x1 ) ; } ) ) ;
1125
- lxLeft = Math . min . apply ( null , unifiedHoverData . map ( function ( c ) { return Math . min ( c . x0 , c . x1 ) ; } ) ) ;
1121
+ lxRight = Math . max . apply ( null , hoverData . map ( function ( c ) { return Math . max ( c . x0 , c . x1 ) ; } ) ) ;
1122
+ lxLeft = Math . min . apply ( null , hoverData . map ( function ( c ) { return Math . min ( c . x0 , c . x1 ) ; } ) ) ;
1126
1123
}
1127
1124
} else {
1128
- lxRight = lxLeft = Lib . mean ( unifiedHoverData . map ( function ( c ) { return ( c . x0 + c . x1 ) / 2 ; } ) ) - tWidth / 2 ;
1125
+ lxRight = lxLeft = Lib . mean ( hoverData . map ( function ( c ) { return ( c . x0 + c . x1 ) / 2 ; } ) ) - tWidth / 2 ;
1129
1126
}
1130
1127
1131
1128
var xOffset = xa . _offset ;
0 commit comments