Skip to content

Commit 57d669d

Browse files
author
John Soklaski
committed
Add unit tests for stacked subplots with both shared x and y axes
1 parent cddba4e commit 57d669d

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"data": [
3+
{
4+
"x": [
5+
1,
6+
2,
7+
3
8+
]
9+
},
10+
{
11+
"x": [
12+
2.1,
13+
2
14+
],
15+
"xaxis": "x2"
16+
},
17+
{
18+
"x": [
19+
3,
20+
2,
21+
1
22+
],
23+
"xaxis": "x3"
24+
}
25+
],
26+
"layout": {
27+
"xaxis": {
28+
"domain": [
29+
0,
30+
0.3
31+
]
32+
},
33+
"xaxis2": {
34+
"domain": [
35+
0.35,
36+
0.65
37+
]
38+
},
39+
"xaxis3": {
40+
"domain": [
41+
0.7,
42+
1
43+
]
44+
},
45+
"hovermode": "y"
46+
}
47+
}

test/jasmine/tests/hover_label_test.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,107 @@ describe('hover info', function() {
282282
});
283283
});
284284
});
285+
286+
describe('hover info on stacked subplots', function() {
287+
'use strict';
288+
289+
afterEach(destroyGraphDiv);
290+
291+
describe('hover info on stacked subplots with shared x-axis', function() {
292+
var mock = require('@mocks/stacked_coupled_subplots.json');
293+
294+
beforeEach(function(done) {
295+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
296+
});
297+
298+
it('responds to hover', function() {
299+
var gd = document.getElementById('graph');
300+
Plotly.Fx.hover(gd, {xval: 3}, ['xy','xy2','xy3']);
301+
302+
expect(gd._hoverdata.length).toEqual(2);
303+
304+
expect(gd._hoverdata[0]).toEqual(jasmine.objectContaining(
305+
{
306+
curveNumber: 1,
307+
pointNumber: 1,
308+
x: 3,
309+
y: 110
310+
}));
311+
312+
expect(gd._hoverdata[1]).toEqual(jasmine.objectContaining(
313+
{
314+
curveNumber: 2,
315+
pointNumber: 0,
316+
x: 3,
317+
y: 1000
318+
}));
319+
320+
//There should be a single label on the x-axis with the shared x value, 3.
321+
expect(d3.selectAll('g.axistext').size()).toEqual(1);
322+
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('3');
323+
324+
//There should be two points being hovered over, in two different traces, one in each plot.
325+
expect(d3.selectAll('g.hovertext').size()).toEqual(2);
326+
var textNodes = d3.selectAll('g.hovertext').selectAll('text');
327+
328+
expect(textNodes[0][0].innerHTML).toEqual('trace 1');
329+
expect(textNodes[0][1].innerHTML).toEqual('110');
330+
expect(textNodes[1][0].innerHTML).toEqual('trace 2');
331+
expect(textNodes[1][1].innerHTML).toEqual('1000');
332+
});
333+
});
334+
335+
describe('hover info on stacked subplots with shared y-axis', function() {
336+
var mock = require('@mocks/stacked_subplots_shared_yaxis.json');
337+
338+
beforeEach(function(done) {
339+
Plotly.plot(createGraphDiv(), mock.data, mock.layout).then(done);
340+
});
341+
342+
it('responds to hover', function() {
343+
var gd = document.getElementById('graph');
344+
Plotly.Fx.hover(gd, {yval: 0}, ['xy', 'x2y', 'x3y']);
345+
346+
expect(gd._hoverdata.length).toEqual(3);
347+
348+
expect(gd._hoverdata[0]).toEqual(jasmine.objectContaining(
349+
{
350+
curveNumber: 0,
351+
pointNumber: 0,
352+
x: 1,
353+
y: 0
354+
}));
355+
356+
expect(gd._hoverdata[1]).toEqual(jasmine.objectContaining(
357+
{
358+
curveNumber: 1,
359+
pointNumber: 0,
360+
x: 2.1,
361+
y: 0
362+
}));
363+
364+
expect(gd._hoverdata[2]).toEqual(jasmine.objectContaining(
365+
{
366+
curveNumber: 2,
367+
pointNumber: 0,
368+
x: 3,
369+
y: 0
370+
}));
371+
372+
//There should be a single label on the y-axis with the shared y value, 0.
373+
expect(d3.selectAll('g.axistext').size()).toEqual(1);
374+
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0');
375+
376+
//There should be three points being hovered over, in three different traces, one in each plot.
377+
expect(d3.selectAll('g.hovertext').size()).toEqual(3);
378+
var textNodes = d3.selectAll('g.hovertext').selectAll('text');
379+
380+
expect(textNodes[0][0].innerHTML).toEqual('trace 0');
381+
expect(textNodes[0][1].innerHTML).toEqual('1');
382+
expect(textNodes[1][0].innerHTML).toEqual('trace 1');
383+
expect(textNodes[1][1].innerHTML).toEqual('2.1');
384+
expect(textNodes[2][0].innerHTML).toEqual('trace 2');
385+
expect(textNodes[2][1].innerHTML).toEqual('3');
386+
});
387+
});
388+
});

0 commit comments

Comments
 (0)