@@ -833,7 +833,7 @@ function _hover(gd, evt, subplot, noHoverEvent, eventTarget) {
833
833
var hoverLabels = hoverText . hoverLabels ;
834
834
835
835
if ( ! helpers . isUnifiedHover ( hovermode ) ) {
836
- hoverAvoidOverlaps ( hoverLabels , rotateLabels , fullLayout , hoverText . commonLabel ) ;
836
+ hoverAvoidOverlaps ( hoverLabels , rotateLabels , fullLayout , hoverText . commonLabelBoundingBox ) ;
837
837
alignHoverText ( hoverLabels , rotateLabels , fullLayout . _invScaleX , fullLayout . _invScaleY ) ;
838
838
} // TODO: tagName hack is needed to appease geo.js's hack of using eventTarget=true
839
839
// we should improve the "fx" API so other plots can use it without these hack.
@@ -944,7 +944,13 @@ function createHoverText(hoverData, opts) {
944
944
. classed ( 'axistext' , true ) ;
945
945
commonLabel . exit ( ) . remove ( ) ;
946
946
947
- var commonLabelLx , commonLabelLy ;
947
+ // set rect (without arrow) behind label below for later collision detection
948
+ var commonLabelRect = {
949
+ minX : 0 ,
950
+ maxX : 0 ,
951
+ minY : 0 ,
952
+ maxY : 0
953
+ } ;
948
954
commonLabel . each ( function ( ) {
949
955
var label = d3 . select ( this ) ;
950
956
var lpath = Lib . ensureSingle ( label , 'path' , '' , function ( s ) {
@@ -998,7 +1004,7 @@ function createHoverText(hoverData, opts) {
998
1004
999
1005
lpath . attr ( 'd' , 'M-' + ( halfWidth - HOVERARROWSIZE ) + ',0' +
1000
1006
'L-' + ( halfWidth - HOVERARROWSIZE * 2 ) + ',' + topsign + HOVERARROWSIZE +
1001
- 'H' + ( HOVERTEXTPAD + tbb . width / 2 ) +
1007
+ 'H' + ( halfWidth ) +
1002
1008
'v' + topsign + ( HOVERTEXTPAD * 2 + tbb . height ) +
1003
1009
'H-' + halfWidth +
1004
1010
'V' + topsign + HOVERARROWSIZE +
@@ -1015,12 +1021,23 @@ function createHoverText(hoverData, opts) {
1015
1021
} else {
1016
1022
lpath . attr ( 'd' , 'M0,0' +
1017
1023
'L' + HOVERARROWSIZE + ',' + topsign + HOVERARROWSIZE +
1018
- 'H' + ( HOVERTEXTPAD + tbb . width / 2 ) +
1024
+ 'H' + ( halfWidth ) +
1019
1025
'v' + topsign + ( HOVERTEXTPAD * 2 + tbb . height ) +
1020
- 'H-' + ( HOVERTEXTPAD + tbb . width / 2 ) +
1026
+ 'H-' + ( halfWidth ) +
1021
1027
'V' + topsign + HOVERARROWSIZE +
1022
1028
'H-' + HOVERARROWSIZE + 'Z' ) ;
1023
1029
}
1030
+
1031
+ commonLabelRect . minX = lx - halfWidth ;
1032
+ commonLabelRect . maxX = lx + halfWidth ;
1033
+ if ( xa . side === 'top' ) {
1034
+ // label on negative y side
1035
+ commonLabelRect . minY = ly - ( HOVERTEXTPAD * 2 + tbb . height ) ;
1036
+ commonLabelRect . maxY = ly - HOVERTEXTPAD ;
1037
+ } else {
1038
+ commonLabelRect . minY = ly + HOVERTEXTPAD ;
1039
+ commonLabelRect . maxY = ly + ( HOVERTEXTPAD * 2 + tbb . height ) ;
1040
+ }
1024
1041
} else {
1025
1042
var anchor ;
1026
1043
var sgn ;
@@ -1048,6 +1065,17 @@ function createHoverText(hoverData, opts) {
1048
1065
'V-' + ( HOVERTEXTPAD + tbb . height / 2 ) +
1049
1066
'H' + leftsign + HOVERARROWSIZE + 'V-' + HOVERARROWSIZE + 'Z' ) ;
1050
1067
1068
+ commonLabelRect . minY = ly - ( HOVERTEXTPAD + tbb . height / 2 ) ;
1069
+ commonLabelRect . maxY = ly + ( HOVERTEXTPAD + tbb . height / 2 ) ;
1070
+ if ( ya . side === 'right' ) {
1071
+ commonLabelRect . minX = lx + HOVERARROWSIZE ;
1072
+ commonLabelRect . maxX = lx + HOVERARROWSIZE + ( HOVERTEXTPAD * 2 + tbb . width ) ;
1073
+ } else {
1074
+ // label on negative x side
1075
+ commonLabelRect . minX = lx - HOVERARROWSIZE - ( HOVERTEXTPAD * 2 + tbb . width ) ;
1076
+ commonLabelRect . maxX = lx - HOVERARROWSIZE ;
1077
+ }
1078
+
1051
1079
var halfHeight = tbb . height / 2 ;
1052
1080
var lty = outerTop - tbb . top - halfHeight ;
1053
1081
var clipId = 'clip' + fullLayout . _uid + 'commonlabel' + ya . _id ;
@@ -1090,9 +1118,6 @@ function createHoverText(hoverData, opts) {
1090
1118
}
1091
1119
1092
1120
label . attr ( 'transform' , strTranslate ( lx , ly ) ) ;
1093
-
1094
- commonLabelLx = lx ;
1095
- commonLabelLy = ly ;
1096
1121
} ) ;
1097
1122
1098
1123
// Show a single hover label
@@ -1411,11 +1436,7 @@ function createHoverText(hoverData, opts) {
1411
1436
1412
1437
return {
1413
1438
hoverLabels : hoverLabels ,
1414
- commonLabel : {
1415
- lx : commonLabelLx ,
1416
- ly : commonLabelLy ,
1417
- label : commonLabel
1418
- }
1439
+ commonLabelBoundingBox : commonLabelRect
1419
1440
} ;
1420
1441
}
1421
1442
@@ -1510,7 +1531,7 @@ function getHoverLabelText(d, showCommonLabel, hovermode, fullLayout, t0, g) {
1510
1531
// know what happens if the group spans all the way from one edge to
1511
1532
// the other, though it hardly matters - there's just too much
1512
1533
// information then.
1513
- function hoverAvoidOverlaps ( hoverLabels , rotateLabels , fullLayout , commonLabel ) {
1534
+ function hoverAvoidOverlaps ( hoverLabels , rotateLabels , fullLayout , commonLabelBoundingBox ) {
1514
1535
var axKey = rotateLabels ? 'xa' : 'ya' ;
1515
1536
var crossAxKey = rotateLabels ? 'ya' : 'xa' ;
1516
1537
var nummoves = 0 ;
@@ -1522,21 +1543,10 @@ function hoverAvoidOverlaps(hoverLabels, rotateLabels, fullLayout, commonLabel)
1522
1543
var k = 0 ;
1523
1544
1524
1545
// get extent of axis hover label
1525
- var axisLabelMinX , axisLabelMaxX , axisLabelMinY , axisLabelMaxY ;
1526
- if ( commonLabel ) {
1527
- commonLabel . label . each ( function ( ) {
1528
- var selection = d3 . select ( this ) ;
1529
- if ( selection && selection . length && selection [ 0 ] && selection [ 0 ] . length && selection [ 0 ] [ 0 ] ) {
1530
- var bbox = selection [ 0 ] [ 0 ] . getBBox ( ) ;
1531
- if ( bbox ) {
1532
- axisLabelMinX = commonLabel . lx ;
1533
- axisLabelMaxX = commonLabel . lx + bbox . width ;
1534
- axisLabelMinY = commonLabel . ly ;
1535
- axisLabelMaxY = commonLabel . ly + bbox . height ;
1536
- }
1537
- }
1538
- } ) ;
1539
- }
1546
+ var axisLabelMinX = commonLabelBoundingBox . minX ;
1547
+ var axisLabelMaxX = commonLabelBoundingBox . maxX ;
1548
+ var axisLabelMinY = commonLabelBoundingBox . minY ;
1549
+ var axisLabelMaxY = commonLabelBoundingBox . maxY ;
1540
1550
1541
1551
var pX = function ( x ) { return x * fullLayout . _invScaleX ; } ;
1542
1552
var pY = function ( y ) { return y * fullLayout . _invScaleY ; } ;
0 commit comments