@@ -704,7 +704,7 @@ function _hover(gd, evt, subplot, noHoverEvent) {
704
704
705
705
var hoverLabels = createHoverText ( hoverData , labelOpts , gd ) ;
706
706
707
- hoverAvoidOverlaps ( hoverData , rotateLabels ? 'xa' : 'ya' , fullLayout ) ;
707
+ hoverAvoidOverlaps ( hoverLabels , rotateLabels ? 'xa' : 'ya' , fullLayout ) ;
708
708
709
709
alignHoverText ( hoverLabels , rotateLabels ) ;
710
710
@@ -879,6 +879,7 @@ function createHoverText(hoverData, opts, gd) {
879
879
880
880
// show all the individual labels
881
881
882
+
882
883
// first create the objects
883
884
var hoverLabels = container . selectAll ( 'g.hovertext' )
884
885
. data ( hoverData , function ( d ) {
@@ -1091,17 +1092,21 @@ function createHoverText(hoverData, opts, gd) {
1091
1092
// know what happens if the group spans all the way from one edge to
1092
1093
// the other, though it hardly matters - there's just too much
1093
1094
// information then.
1094
- function hoverAvoidOverlaps ( hoverData , ax , fullLayout ) {
1095
+ function hoverAvoidOverlaps ( hoverLabels , ax , fullLayout ) {
1095
1096
var nummoves = 0 ;
1096
1097
var axSign = 1 ;
1098
+ var nLabels = hoverLabels . size ( ) ;
1097
1099
1098
1100
// make groups of touching points
1099
- var pointgroups = hoverData . map ( function ( d , i ) {
1101
+ var pointgroups = new Array ( nLabels ) ;
1102
+
1103
+ hoverLabels . each ( function ( d , i ) {
1100
1104
var axis = d [ ax ] ;
1101
1105
var axIsX = axis . _id . charAt ( 0 ) === 'x' ;
1102
1106
var rng = axis . range ;
1103
1107
if ( ! i && rng && ( ( rng [ 0 ] > rng [ 1 ] ) !== axIsX ) ) axSign = - 1 ;
1104
- return [ {
1108
+ pointgroups [ i ] = [ {
1109
+ datum : d ,
1105
1110
i : i ,
1106
1111
traceIndex : d . trace . index ,
1107
1112
dp : 0 ,
@@ -1111,8 +1116,9 @@ function hoverAvoidOverlaps(hoverData, ax, fullLayout) {
1111
1116
pmin : 0 ,
1112
1117
pmax : ( axIsX ? fullLayout . width : fullLayout . height )
1113
1118
} ] ;
1114
- } )
1115
- . sort ( function ( a , b ) {
1119
+ } ) ;
1120
+
1121
+ pointgroups . sort ( function ( a , b ) {
1116
1122
return ( a [ 0 ] . posref - b [ 0 ] . posref ) ||
1117
1123
// for equal positions, sort trace indices increasing or decreasing
1118
1124
// depending on whether the axis is reversed or not... so stacked
@@ -1198,7 +1204,7 @@ function hoverAvoidOverlaps(hoverData, ax, fullLayout) {
1198
1204
1199
1205
// loop through groups, combining them if they overlap,
1200
1206
// until nothing moves
1201
- while ( ! donepositioning && nummoves <= hoverData . length ) {
1207
+ while ( ! donepositioning && nummoves <= nLabels ) {
1202
1208
// to avoid infinite loops, don't move more times
1203
1209
// than there are traces
1204
1210
nummoves ++ ;
@@ -1246,7 +1252,7 @@ function hoverAvoidOverlaps(hoverData, ax, fullLayout) {
1246
1252
var grp = pointgroups [ i ] ;
1247
1253
for ( j = grp . length - 1 ; j >= 0 ; j -- ) {
1248
1254
var pt = grp [ j ] ;
1249
- var hoverPt = hoverData [ pt . i ] ;
1255
+ var hoverPt = pt . datum ;
1250
1256
hoverPt . offset = pt . dp ;
1251
1257
hoverPt . del = pt . del ;
1252
1258
}
0 commit comments