@@ -313,9 +313,14 @@ function hover(gd, evt, subplot) {
313313
314314 var fullLayout = gd . _fullLayout ,
315315 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+
319324 xaArray = subplots . map ( function ( spId ) {
320325 return Plotly . Axes . getFromId ( gd , spId , 'x' ) ;
321326 } ) ,
@@ -533,7 +538,7 @@ function hover(gd, evt, subplot) {
533538 } ;
534539 var hoverLabels = createHoverText ( hoverData , labelOpts ) ;
535540
536- hoverAvoidOverlaps ( hoverData , rotateLabels ? xaArray [ 0 ] : yaArray [ 0 ] ) ;
541+ hoverAvoidOverlaps ( hoverData , rotateLabels ? 'xa' : 'ya' ) ;
537542
538543 alignHoverText ( hoverLabels , rotateLabels ) ;
539544
@@ -872,7 +877,7 @@ function createHoverText(hoverData, opts) {
872877 // first create the objects
873878 var hoverLabels = container . selectAll ( 'g.hovertext' )
874879 . 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 ( ',' ) ;
876881 } ) ;
877882 hoverLabels . enter ( ) . append ( 'g' )
878883 . classed ( 'hovertext' , true )
@@ -978,8 +983,8 @@ function createHoverText(hoverData, opts) {
978983 stroke : contrastColor
979984 } ) ;
980985 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 ,
983988 dx = Math . abs ( d . x1 - d . x0 ) ,
984989 dy = Math . abs ( d . y1 - d . y0 ) ,
985990 txTotalWidth = tbb . width + HOVERARROWSIZE + HOVERTEXTPAD + tx2width ,
@@ -1042,18 +1047,19 @@ function createHoverText(hoverData, opts) {
10421047// information then.
10431048function hoverAvoidOverlaps ( hoverData , ax ) {
10441049 var nummoves = 0 ,
1045- pmin = ax . _offset ,
1046- pmax = ax . _offset + ax . _length ,
10471050
10481051 // make groups of touching points
10491052 pointgroups = hoverData
10501053 . map ( function ( d , i ) {
1054+ var axis = d [ ax ] ;
10511055 return [ {
10521056 i : i ,
10531057 dp : 0 ,
10541058 pos : d . pos ,
10551059 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
10571063 } ] ;
10581064 } )
10591065 . sort ( function ( a , b ) { return a [ 0 ] . posref - b [ 0 ] . posref ; } ) ,
@@ -1069,10 +1075,10 @@ function hoverAvoidOverlaps(hoverData, ax) {
10691075 maxPt = grp [ grp . length - 1 ] ;
10701076
10711077 // 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 ;
10731079
10741080 // 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 ;
10761082
10771083 // check for min overlap first, so that we always
10781084 // see the largest labels
@@ -1096,7 +1102,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
10961102 var deleteCount = 0 ;
10971103 for ( i = 0 ; i < grp . length ; i ++ ) {
10981104 pti = grp [ i ] ;
1099- if ( pti . pos + pti . dp + pti . size > pmax ) deleteCount ++ ;
1105+ if ( pti . pos + pti . dp + pti . size > minPt . pmax ) deleteCount ++ ;
11001106 }
11011107
11021108 // start by deleting points whose data is off screen
@@ -1106,7 +1112,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
11061112
11071113 // pos has already been constrained to [pmin,pmax]
11081114 // so look for points close to that to delete
1109- if ( pti . pos > pmax - 1 ) {
1115+ if ( pti . pos > minPt . pmax - 1 ) {
11101116 pti . del = true ;
11111117 deleteCount -- ;
11121118 }
@@ -1117,7 +1123,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
11171123
11181124 // pos has already been constrained to [pmin,pmax]
11191125 // so look for points close to that to delete
1120- if ( pti . pos < pmin + 1 ) {
1126+ if ( pti . pos < minPt . pmin + 1 ) {
11211127 pti . del = true ;
11221128 deleteCount -- ;
11231129
@@ -1130,7 +1136,7 @@ function hoverAvoidOverlaps(hoverData, ax) {
11301136 for ( i = grp . length - 1 ; i >= 0 ; i -- ) {
11311137 if ( deleteCount <= 0 ) break ;
11321138 pti = grp [ i ] ;
1133- if ( pti . pos + pti . dp + pti . size > pmax ) {
1139+ if ( pti . pos + pti . dp + pti . size > minPt . pmax ) {
11341140 pti . del = true ;
11351141 deleteCount -- ;
11361142 }
@@ -1158,7 +1164,9 @@ function hoverAvoidOverlaps(hoverData, ax) {
11581164 p0 = g0 [ g0 . length - 1 ] ,
11591165 p1 = g1 [ 0 ] ;
11601166 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 ) ) {
11621170 // push the new point(s) added to this group out of the way
11631171 for ( j = g1 . length - 1 ; j >= 0 ; j -- ) g1 [ j ] . dp += topOverlap ;
11641172
0 commit comments