@@ -313,9 +313,14 @@ function hover(gd, evt, subplot) {
313
313
314
314
var fullLayout = gd . _fullLayout ,
315
315
plotinfo = fullLayout . _plots [ subplot ] ,
316
- // list of all overlaid subplots to look at
317
- subplots = [ subplot ] . concat ( plotinfo . overlays
318
- . map ( function ( pi ) { return pi . id ; } ) ) ,
316
+
317
+ //If the user passed in an array of subplots, use those instead of finding overlayed plots
318
+ subplots = Array . isArray ( subplot ) ?
319
+ subplot :
320
+ // list of all overlaid subplots to look at
321
+ [ subplot ] . concat ( plotinfo . overlays
322
+ . map ( function ( pi ) { return pi . id ; } ) ) ,
323
+
319
324
xaArray = subplots . map ( function ( spId ) {
320
325
return Plotly . Axes . getFromId ( gd , spId , 'x' ) ;
321
326
} ) ,
@@ -533,7 +538,7 @@ function hover(gd, evt, subplot) {
533
538
} ;
534
539
var hoverLabels = createHoverText ( hoverData , labelOpts ) ;
535
540
536
- hoverAvoidOverlaps ( hoverData , rotateLabels ? xaArray [ 0 ] : yaArray [ 0 ] ) ;
541
+ hoverAvoidOverlaps ( hoverData , rotateLabels ? 'xa' : 'ya' ) ;
537
542
538
543
alignHoverText ( hoverLabels , rotateLabels ) ;
539
544
@@ -872,7 +877,7 @@ function createHoverText(hoverData, opts) {
872
877
// first create the objects
873
878
var hoverLabels = container . selectAll ( 'g.hovertext' )
874
879
. data ( hoverData , function ( d ) {
875
- return [ d . trace . index , d . index , d . x0 , d . y0 , d . name , d . attr || '' ] . join ( ',' ) ;
880
+ return [ d . trace . index , d . index , d . x0 , d . y0 , d . name , d . attr , d . xa , d . ya || '' ] . join ( ',' ) ;
876
881
} ) ;
877
882
hoverLabels . enter ( ) . append ( 'g' )
878
883
. classed ( 'hovertext' , true )
@@ -978,8 +983,8 @@ function createHoverText(hoverData, opts) {
978
983
stroke : contrastColor
979
984
} ) ;
980
985
var tbb = tx . node ( ) . getBoundingClientRect ( ) ,
981
- htx = xa . _offset + ( d . x0 + d . x1 ) / 2 ,
982
- hty = ya . _offset + ( d . y0 + d . y1 ) / 2 ,
986
+ htx = d . xa . _offset + ( d . x0 + d . x1 ) / 2 ,
987
+ hty = d . ya . _offset + ( d . y0 + d . y1 ) / 2 ,
983
988
dx = Math . abs ( d . x1 - d . x0 ) ,
984
989
dy = Math . abs ( d . y1 - d . y0 ) ,
985
990
txTotalWidth = tbb . width + HOVERARROWSIZE + HOVERTEXTPAD + tx2width ,
@@ -1042,18 +1047,19 @@ function createHoverText(hoverData, opts) {
1042
1047
// information then.
1043
1048
function hoverAvoidOverlaps ( hoverData , ax ) {
1044
1049
var nummoves = 0 ,
1045
- pmin = ax . _offset ,
1046
- pmax = ax . _offset + ax . _length ,
1047
1050
1048
1051
// make groups of touching points
1049
1052
pointgroups = hoverData
1050
1053
. map ( function ( d , i ) {
1054
+ var axis = d [ ax ] ;
1051
1055
return [ {
1052
1056
i : i ,
1053
1057
dp : 0 ,
1054
1058
pos : d . pos ,
1055
1059
posref : d . posref ,
1056
- size : d . by * ( ax . _id . charAt ( 0 ) === 'x' ? YFACTOR : 1 ) / 2
1060
+ size : d . by * ( axis . _id . charAt ( 0 ) === 'x' ? YFACTOR : 1 ) / 2 ,
1061
+ pmin : axis . _offset ,
1062
+ pmax : axis . _offset + axis . _length
1057
1063
} ] ;
1058
1064
} )
1059
1065
. sort ( function ( a , b ) { return a [ 0 ] . posref - b [ 0 ] . posref ; } ) ,
@@ -1069,10 +1075,10 @@ function hoverAvoidOverlaps(hoverData, ax) {
1069
1075
maxPt = grp [ grp . length - 1 ] ;
1070
1076
1071
1077
// overlap with the top - positive vals are overlaps
1072
- topOverlap = pmin - minPt . pos - minPt . dp + minPt . size ;
1078
+ topOverlap = minPt . pmin - minPt . pos - minPt . dp + minPt . size ;
1073
1079
1074
1080
// overlap with the bottom - positive vals are overlaps
1075
- bottomOverlap = maxPt . pos + maxPt . dp + maxPt . size - pmax ;
1081
+ bottomOverlap = maxPt . pos + maxPt . dp + maxPt . size - minPt . pmax ;
1076
1082
1077
1083
// check for min overlap first, so that we always
1078
1084
// see the largest labels
@@ -1096,7 +1102,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
1096
1102
var deleteCount = 0 ;
1097
1103
for ( i = 0 ; i < grp . length ; i ++ ) {
1098
1104
pti = grp [ i ] ;
1099
- if ( pti . pos + pti . dp + pti . size > pmax ) deleteCount ++ ;
1105
+ if ( pti . pos + pti . dp + pti . size > minPt . pmax ) deleteCount ++ ;
1100
1106
}
1101
1107
1102
1108
// start by deleting points whose data is off screen
@@ -1106,7 +1112,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
1106
1112
1107
1113
// pos has already been constrained to [pmin,pmax]
1108
1114
// so look for points close to that to delete
1109
- if ( pti . pos > pmax - 1 ) {
1115
+ if ( pti . pos > minPt . pmax - 1 ) {
1110
1116
pti . del = true ;
1111
1117
deleteCount -- ;
1112
1118
}
@@ -1117,7 +1123,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
1117
1123
1118
1124
// pos has already been constrained to [pmin,pmax]
1119
1125
// so look for points close to that to delete
1120
- if ( pti . pos < pmin + 1 ) {
1126
+ if ( pti . pos < minPt . pmin + 1 ) {
1121
1127
pti . del = true ;
1122
1128
deleteCount -- ;
1123
1129
@@ -1130,7 +1136,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
1130
1136
for ( i = grp . length - 1 ; i >= 0 ; i -- ) {
1131
1137
if ( deleteCount <= 0 ) break ;
1132
1138
pti = grp [ i ] ;
1133
- if ( pti . pos + pti . dp + pti . size > pmax ) {
1139
+ if ( pti . pos + pti . dp + pti . size > minPt . pmax ) {
1134
1140
pti . del = true ;
1135
1141
deleteCount -- ;
1136
1142
}
@@ -1158,7 +1164,9 @@ function hoverAvoidOverlaps(hoverData, ax) {
1158
1164
p0 = g0 [ g0 . length - 1 ] ,
1159
1165
p1 = g1 [ 0 ] ;
1160
1166
topOverlap = p0 . pos + p0 . dp + p0 . size - p1 . pos - p1 . dp + p1 . size ;
1161
- if ( topOverlap > 0.01 ) {
1167
+
1168
+ //Only group points that lie on the same axes
1169
+ if ( topOverlap > 0.01 && ( p0 . pmin === p1 . pmin ) && ( p0 . pmax === p1 . pmax ) ) {
1162
1170
// push the new point(s) added to this group out of the way
1163
1171
for ( j = g1 . length - 1 ; j >= 0 ; j -- ) g1 [ j ] . dp += topOverlap ;
1164
1172
0 commit comments