Skip to content

Commit b45886f

Browse files
committed
edit interact tests and add hover label tests
1 parent 69997b1 commit b45886f

File tree

3 files changed

+102
-26
lines changed

3 files changed

+102
-26
lines changed

src/plots/cartesian/graph_interact.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,9 @@ function createHoverText(hoverData, opts) {
778778
var i, traceHoverinfo;
779779
for (i = 0; i < hoverData.length; i++) {
780780
traceHoverinfo = hoverData[i].trace.hoverinfo;
781-
if (traceHoverinfo.indexOf('all')===-1 ||
782-
traceHoverinfo.indexOf(hovermode)===-1) {
781+
var parts = traceHoverinfo.split('+');
782+
if (parts.indexOf('all') === -1 &&
783+
parts.indexOf(hovermode) === -1) {
783784
showCommonLabel = false;
784785
break;
785786
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
var d3 = require('d3');
2+
3+
var Plotly = require('@src/index');
4+
var Fx = require('@src/plots/cartesian/graph_interact');
5+
var Lib = require('@src/lib');
6+
7+
var createGraphDiv = require('../assets/create_graph_div');
8+
var destroyGraphDiv = require('../assets/destroy_graph_div');
9+
10+
describe('hover info', function() {
11+
'use strict';
12+
13+
var mock = require('@mocks/14.json'),
14+
evt = {
15+
clientX: mock.layout.width/ 2,
16+
clientY: mock.layout.height / 2
17+
};
18+
19+
afterEach(destroyGraphDiv);
20+
21+
describe('hover info', function() {
22+
var mockCopy = Lib.extendDeep({}, mock);
23+
24+
beforeEach(function(done) {
25+
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
26+
});
27+
28+
it('responds to hover', function() {
29+
var gd = document.getElementById('graph');
30+
Fx.hover('graph', evt, 'xy');
31+
32+
var hoverTrace = gd._hoverdata[0];
33+
34+
expect(hoverTrace.curveNumber).toEqual(0);
35+
expect(hoverTrace.pointNumber).toEqual(17);
36+
expect(hoverTrace.x).toEqual(0.388);
37+
expect(hoverTrace.y).toEqual(1);
38+
39+
expect(d3.selectAll('g.axistext').size()).toEqual(1);
40+
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
41+
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388');
42+
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('1');
43+
});
44+
});
45+
46+
describe('hover info x', function() {
47+
var mockCopy = Lib.extendDeep({}, mock);
48+
49+
mockCopy.data[0].hoverinfo = 'x';
50+
51+
beforeEach(function(done) {
52+
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
53+
});
54+
55+
it('responds to hover x', function() {
56+
var gd = document.getElementById('graph');
57+
Fx.hover('graph', evt, 'xy');
58+
59+
var hoverTrace = gd._hoverdata[0];
60+
61+
expect(hoverTrace.curveNumber).toEqual(0);
62+
expect(hoverTrace.pointNumber).toEqual(17);
63+
expect(hoverTrace.x).toEqual(0.388);
64+
expect(hoverTrace.y).toEqual(1);
65+
66+
expect(d3.selectAll('g.axistext').size()).toEqual(1);
67+
expect(d3.selectAll('g.hovertext').size()).toEqual(0);
68+
expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388');
69+
});
70+
});
71+
72+
describe('hover info y', function() {
73+
var mockCopy = Lib.extendDeep({}, mock);
74+
75+
mockCopy.data[0].hoverinfo = 'y';
76+
77+
beforeEach(function(done) {
78+
Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done);
79+
});
80+
81+
it('responds to hover y', function() {
82+
var gd = document.getElementById('graph');
83+
Fx.hover('graph', evt, 'xy');
84+
85+
var hoverTrace = gd._hoverdata[0];
86+
87+
expect(hoverTrace.curveNumber).toEqual(0);
88+
expect(hoverTrace.pointNumber).toEqual(17);
89+
expect(hoverTrace.x).toEqual(0.388);
90+
expect(hoverTrace.y).toEqual(1);
91+
92+
expect(d3.selectAll('g.axistext').size()).toEqual(0);
93+
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
94+
expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('1');
95+
});
96+
});
97+
});

test/jasmine/tests/plot_interact_test.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('Test plot structure', function () {
1212

1313
afterEach(destroyGraphDiv);
1414

15-
describe('cartesian plots', function() {
15+
describe('cartesian plots', function() {
1616
describe('scatter traces', function() {
1717
var mock = require('@mocks/14.json');
1818

@@ -45,29 +45,8 @@ describe('Test plot structure', function () {
4545

4646
expect(nodes[0].length).toEqual(Npts);
4747
});
48-
49-
it('responds to hover', function() {
50-
var gd = document.getElementById('graph');
51-
52-
var evt = {
53-
clientX: gd.layout.width/ 2,
54-
clientY: gd.layout.height / 2
55-
};
56-
57-
Fx.hover('graph', evt, 'xy');
58-
59-
var hoverTrace = gd._hoverdata[0];
60-
61-
expect(hoverTrace.curveNumber).toEqual(0);
62-
expect(hoverTrace.pointNumber).toEqual(17);
63-
expect(hoverTrace.x).toEqual(0.388);
64-
expect(hoverTrace.y).toEqual(1);
65-
66-
expect(d3.selectAll('g.axistext')[0].length).toEqual(1);
67-
expect(d3.selectAll('g.hovertext')[0].length).toEqual(1);
68-
});
6948
});
70-
49+
7150
describe('pie traces', function() {
7251
var mock = require('@mocks/pie_simple.json');
7352

@@ -86,7 +65,6 @@ describe('Test plot structure', function () {
8665
expect(nodes[0].length).toEqual(Npts);
8766
});
8867
});
89-
9068
});
9169

9270
describe('geo plots', function() {

0 commit comments

Comments
 (0)