Skip to content

Commit 871402b

Browse files
committed
Add tests
1 parent f269b7a commit 871402b

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎test/jasmine/tests/hover_test.js‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5617,6 +5617,44 @@ describe('hover working with zorder', function () {
56175617
});
56185618
});
56195619

5620+
describe('hover on points at the same position', () => {
5621+
afterEach(destroyGraphDiv);
5622+
5623+
['scatter', 'scattergl', 'splom'].forEach((type) => {
5624+
const makeTrace = (x, y) =>
5625+
type === 'splom' ? { type, dimensions: [{ values: x }, { values: y }] } : { type, x, y };
5626+
// splom plots dimension 0 against dimension 1 on subplot xy2
5627+
const subplot = type === 'splom' ? 'xy2' : 'xy';
5628+
5629+
it(`picks the trace drawn last for ${type} in closest hovermode`, async () => {
5630+
const gd = createGraphDiv();
5631+
await Plotly.newPlot(gd, {
5632+
data: [makeTrace([0, 1, 2], [1, 0, 1]), makeTrace([0, 1, 2], [2, 0, 2])],
5633+
layout: { width: 400, height: 400, hovermode: 'closest' }
5634+
});
5635+
5636+
Fx.hover(gd, { xval: 1, yval: 0 }, subplot);
5637+
5638+
expect(gd._hoverdata.length).toEqual(1);
5639+
expect(gd._hoverdata[0].curveNumber).toEqual(1);
5640+
expect(gd._hoverdata[0].pointNumber).toEqual(1);
5641+
});
5642+
5643+
it(`picks the point drawn last for ${type} in x hovermode`, async () => {
5644+
const gd = createGraphDiv();
5645+
await Plotly.newPlot(gd, {
5646+
data: [makeTrace([0, 1, 1, 2], [1, 0, 0, 1])],
5647+
layout: { width: 400, height: 400, hovermode: 'x' }
5648+
});
5649+
5650+
Fx.hover(gd, { xval: 1, yval: 0 }, subplot);
5651+
5652+
expect(gd._hoverdata.length).toEqual(1);
5653+
expect(gd._hoverdata[0].pointNumber).toEqual(2);
5654+
});
5655+
});
5656+
});
5657+
56205658
describe('hover label rotation:', function () {
56215659
var gd;
56225660

0 commit comments

Comments
 (0)