Skip to content

Commit 8d1a49e

Browse files
committed
fix: do not ovelap hoverlabels for different tracetypes
1 parent 482802b commit 8d1a49e

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/components/fx/hover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ function hoverAvoidOverlaps(hoverLabels, rotateLabels, fullLayout, commonLabelBo
17571757
topOverlap = p0.pos + p0.dp + p0.size - p1.pos - p1.dp + p1.size;
17581758

17591759
// Only group points that lie on the same axes
1760-
if(topOverlap > 0.01 && (p0.pmin === p1.pmin) && (p0.pmax === p1.pmax)) {
1760+
if(topOverlap > 0.01 && p0.crossAxKey === p1.crossAxKey) {
17611761
// push the new point(s) added to this group out of the way
17621762
for(j = g1.length - 1; j >= 0; j--) g1[j].dp += topOverlap;
17631763

test/jasmine/tests/hover_label_test.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,10 @@ describe('hover info', function() {
16681668
return Math.max(0, overlap);
16691669
}
16701670

1671+
function labelCount() {
1672+
return d3Select(gd).selectAll('g.hovertext').size();
1673+
}
1674+
16711675
it('centered-aligned, should render labels inside boxes', function(done) {
16721676
var trace1 = {
16731677
x: ['giraffes'],
@@ -1787,6 +1791,59 @@ describe('hover info', function() {
17871791
})
17881792
.then(done, done.fail);
17891793
});
1794+
1795+
it("does not overlap lebels for different trace types", function (done) {
1796+
function trace(name, type, delta) {
1797+
return {
1798+
name: name,
1799+
type: type,
1800+
y: [0 + delta, 1 + delta, 2 + delta],
1801+
x: ["CAT 1", "CAT 2", "CAT 3"],
1802+
};
1803+
}
1804+
1805+
var scatterName = "scatter_";
1806+
var barName = "bar_";
1807+
var data = [];
1808+
for(let i = 0; i<3; i++) {
1809+
data.push(trace(barName + i, "bar", 0.0));
1810+
data.push(trace(scatterName + i, "scatter", 0.1));
1811+
}
1812+
var layout = {
1813+
width: 600,
1814+
height: 400,
1815+
hovermode: "x",
1816+
};
1817+
1818+
Plotly.newPlot(gd, data, layout)
1819+
.then(function () {
1820+
_hoverNatural(gd, 200, 200);
1821+
})
1822+
.then(function () {
1823+
expect(labelCount()).toBe(6);
1824+
})
1825+
.then(function () {
1826+
1827+
var nodes = [];
1828+
for(let i = 0; i<3; i++) {
1829+
nodes.push(hoverInfoNodes(barName + i).secondaryBox.getBoundingClientRect());
1830+
nodes.push(hoverInfoNodes(scatterName + i).secondaryBox.getBoundingClientRect());
1831+
}
1832+
nodes.sort(function(a,b) { return a.top - b.top; } );
1833+
1834+
for(let i = 0; i<5; i++) {
1835+
expect(
1836+
calcLineOverlap(
1837+
nodes[i].top,
1838+
nodes[i].bottom,
1839+
nodes[i+1].top,
1840+
nodes[i+1].bottom,
1841+
)
1842+
).toBeWithin(2, 1);
1843+
}
1844+
})
1845+
.then(done, done.fail);
1846+
});
17901847
});
17911848

17921849
describe('constraints info graph viewport', function() {

0 commit comments

Comments
 (0)