Skip to content

Commit e481f14

Browse files
committed
Linting/formatting
1 parent 2ab7e84 commit e481f14

1 file changed

Lines changed: 152 additions & 117 deletions

File tree

test/jasmine/tests/hover_click_anywhere_test.js

Lines changed: 152 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,168 +6,203 @@ var createGraphDiv = require('../assets/create_graph_div');
66
var destroyGraphDiv = require('../assets/destroy_graph_div');
77
var click = require('../assets/click');
88

9-
109
function makePlot(gd, layoutExtras) {
11-
return Plotly.newPlot(gd, [{
12-
x: [1, 2, 3],
13-
y: [1, 3, 2],
14-
type: 'scatter',
15-
mode: 'markers'
16-
}], Lib.extendFlat({
17-
width: 400, height: 400,
18-
margin: {l: 50, t: 50, r: 50, b: 50},
19-
xaxis: {range: [0, 10]},
20-
yaxis: {range: [0, 10]},
21-
hovermode: 'closest'
22-
}, layoutExtras || {}));
10+
return Plotly.newPlot(
11+
gd,
12+
[
13+
{
14+
x: [1, 2, 3],
15+
y: [1, 3, 2],
16+
type: 'scatter',
17+
mode: 'markers'
18+
}
19+
],
20+
Lib.extendFlat(
21+
{
22+
width: 400,
23+
height: 400,
24+
margin: { l: 50, t: 50, r: 50, b: 50 },
25+
xaxis: { range: [0, 10] },
26+
yaxis: { range: [0, 10] },
27+
hovermode: 'closest'
28+
},
29+
layoutExtras || {}
30+
)
31+
);
2332
}
2433

25-
describe('hoveranywhere', function() {
34+
describe('hoveranywhere', function () {
2635
'use strict';
2736

2837
var gd;
2938

30-
beforeEach(function() { gd = createGraphDiv(); });
39+
beforeEach(function () {
40+
gd = createGraphDiv();
41+
});
3142
afterEach(destroyGraphDiv);
3243

3344
function _hover(xPixel, yPixel) {
3445
var bb = gd.getBoundingClientRect();
3546
var s = gd._fullLayout._size;
36-
Fx.hover(gd, {
37-
clientX: xPixel + bb.left + s.l,
38-
clientY: yPixel + bb.top + s.t,
39-
target: gd.querySelector('.nsewdrag')
40-
}, 'xy');
47+
Fx.hover(
48+
gd,
49+
{
50+
clientX: xPixel + bb.left + s.l,
51+
clientY: yPixel + bb.top + s.t,
52+
target: gd.querySelector('.nsewdrag')
53+
},
54+
'xy'
55+
);
4156
Lib.clearThrottle();
4257
}
4358

44-
it('emits plotly_hover with coordinate data on empty space', function(done) {
59+
it('emits plotly_hover with coordinate data on empty space', function (done) {
4560
var hoverData;
4661

47-
makePlot(gd, {hoveranywhere: true}).then(function() {
48-
gd.on('plotly_hover', function(d) { hoverData = d; });
49-
50-
// hover over empty area (no data points nearby)
51-
_hover(250, 50);
52-
53-
expect(hoverData).toBeDefined();
54-
expect(hoverData.points).toEqual([]);
55-
expect(hoverData.xaxes.length).toBe(1);
56-
expect(hoverData.yaxes.length).toBe(1);
57-
expect(hoverData.xaxes[0]._id).toBe('x');
58-
expect(hoverData.yaxes[0]._id).toBe('y');
59-
expect(hoverData.xvals.length).toBe(1);
60-
expect(hoverData.yvals.length).toBe(1);
61-
expect(hoverData.xvals[0]).toBeCloseTo(250 / 30, 2);
62-
expect(hoverData.yvals[0]).toBeCloseTo(10 - 50 / 30, 2);
63-
})
64-
.then(done, done.fail);
62+
makePlot(gd, { hoveranywhere: true })
63+
.then(function () {
64+
gd.on('plotly_hover', function (d) {
65+
hoverData = d;
66+
});
67+
68+
// hover over empty area (no data points nearby)
69+
_hover(250, 50);
70+
71+
expect(hoverData).toBeDefined();
72+
expect(hoverData.points).toEqual([]);
73+
expect(hoverData.xaxes.length).toBe(1);
74+
expect(hoverData.yaxes.length).toBe(1);
75+
expect(hoverData.xaxes[0]._id).toBe('x');
76+
expect(hoverData.yaxes[0]._id).toBe('y');
77+
expect(hoverData.xvals.length).toBe(1);
78+
expect(hoverData.yvals.length).toBe(1);
79+
expect(hoverData.xvals[0]).toBeCloseTo(250 / 30, 2);
80+
expect(hoverData.yvals[0]).toBeCloseTo(10 - 50 / 30, 2);
81+
})
82+
.then(done, done.fail);
6583
});
6684

67-
it('does not emit plotly_hover event on empty space when hoveranywhere is false', function(done) {
85+
it('does not emit plotly_hover event on empty space when hoveranywhere is false', function (done) {
6886
var hoverData;
6987

70-
makePlot(gd).then(function() {
71-
gd.on('plotly_hover', function(d) { hoverData = d; });
72-
_hover(250, 50);
73-
expect(hoverData).toBeUndefined();
74-
})
75-
.then(done, done.fail);
88+
makePlot(gd)
89+
.then(function () {
90+
gd.on('plotly_hover', function (d) {
91+
hoverData = d;
92+
});
93+
_hover(250, 50);
94+
expect(hoverData).toBeUndefined();
95+
})
96+
.then(done, done.fail);
7697
});
7798

78-
it('still returns normal point data on traces', function(done) {
99+
it('still returns normal point data on traces', function (done) {
79100
var hoverData;
80101

81-
makePlot(gd, {hoveranywhere: true}).then(function() {
82-
gd.on('plotly_hover', function(d) { hoverData = d; });
83-
84-
// hover near (2, 3)
85-
_hover(60, 210);
86-
87-
expect(hoverData.points.length).toBe(1);
88-
var pt = hoverData.points[0];
89-
expect(pt.x).toBe(2);
90-
expect(pt.y).toBe(3);
91-
expect(pt.curveNumber).toBe(0);
92-
expect(pt.pointNumber).toBe(1);
93-
// xPixel/yPixel: plot-area px + margin (60+50=110, 210+50=260)
94-
expect(pt.xPixel).toBeCloseTo(110, 1);
95-
expect(pt.yPixel).toBeCloseTo(260, 1);
96-
// bbox is page-relative (xPixel/yPixel + graph div page offset);
97-
// center of bbox should equal xPixel/yPixel + page offset
98-
var gLeft = gd.offsetLeft + gd.clientLeft;
99-
var gTop = gd.offsetTop + gd.clientTop;
100-
expect(pt.bbox).toBeDefined();
101-
expect((pt.bbox.x0 + pt.bbox.x1) / 2).toBeCloseTo(110 + gLeft, 1);
102-
expect((pt.bbox.y0 + pt.bbox.y1) / 2).toBeCloseTo(260 + gTop, 1);
103-
expect(pt.bbox.x0).toBeLessThan(pt.bbox.x1);
104-
expect(pt.bbox.y0).toBeLessThan(pt.bbox.y1);
105-
expect(hoverData.xaxes.length).toBe(1);
106-
expect(hoverData.yaxes.length).toBe(1);
107-
expect(hoverData.xvals.length).toBe(1);
108-
expect(hoverData.yvals.length).toBe(1);
109-
expect(hoverData.xvals[0]).toBeCloseTo(2, 2);
110-
expect(hoverData.yvals[0]).toBeCloseTo(3, 2);
111-
})
112-
.then(done, done.fail);
102+
makePlot(gd, { hoveranywhere: true })
103+
.then(function () {
104+
gd.on('plotly_hover', function (d) {
105+
hoverData = d;
106+
});
107+
108+
// hover near (2, 3)
109+
_hover(60, 210);
110+
111+
expect(hoverData.points.length).toBe(1);
112+
var pt = hoverData.points[0];
113+
expect(pt.x).toBe(2);
114+
expect(pt.y).toBe(3);
115+
expect(pt.curveNumber).toBe(0);
116+
expect(pt.pointNumber).toBe(1);
117+
// xPixel/yPixel: plot-area px + margin (60+50=110, 210+50=260)
118+
expect(pt.xPixel).toBeCloseTo(110, 1);
119+
expect(pt.yPixel).toBeCloseTo(260, 1);
120+
// bbox is page-relative (xPixel/yPixel + graph div page offset);
121+
// center of bbox should equal xPixel/yPixel + page offset
122+
var gLeft = gd.offsetLeft + gd.clientLeft;
123+
var gTop = gd.offsetTop + gd.clientTop;
124+
expect(pt.bbox).toBeDefined();
125+
expect((pt.bbox.x0 + pt.bbox.x1) / 2).toBeCloseTo(110 + gLeft, 1);
126+
expect((pt.bbox.y0 + pt.bbox.y1) / 2).toBeCloseTo(260 + gTop, 1);
127+
expect(pt.bbox.x0).toBeLessThan(pt.bbox.x1);
128+
expect(pt.bbox.y0).toBeLessThan(pt.bbox.y1);
129+
expect(hoverData.xaxes.length).toBe(1);
130+
expect(hoverData.yaxes.length).toBe(1);
131+
expect(hoverData.xvals.length).toBe(1);
132+
expect(hoverData.yvals.length).toBe(1);
133+
expect(hoverData.xvals[0]).toBeCloseTo(2, 2);
134+
expect(hoverData.yvals[0]).toBeCloseTo(3, 2);
135+
})
136+
.then(done, done.fail);
113137
});
114138

115-
it('respects hovermode:false', function(done) {
139+
it('respects hovermode:false', function (done) {
116140
var hoverData;
117141

118-
makePlot(gd, {hoveranywhere: true, hovermode: false}).then(function() {
119-
gd.on('plotly_hover', function(d) { hoverData = d; });
120-
_hover(250, 50);
121-
expect(hoverData).toBeUndefined();
122-
})
123-
.then(done, done.fail);
142+
makePlot(gd, { hoveranywhere: true, hovermode: false })
143+
.then(function () {
144+
gd.on('plotly_hover', function (d) {
145+
hoverData = d;
146+
});
147+
_hover(250, 50);
148+
expect(hoverData).toBeUndefined();
149+
})
150+
.then(done, done.fail);
124151
});
125152
});
126153

127-
describe('clickanywhere', function() {
154+
describe('clickanywhere', function () {
128155
'use strict';
129156

130157
var gd;
131158

132-
beforeEach(function() { gd = createGraphDiv(); });
159+
beforeEach(function () {
160+
gd = createGraphDiv();
161+
});
133162
afterEach(destroyGraphDiv);
134163

135-
it('emits plotly_click with empty points on empty space', function(done) {
164+
it('emits plotly_click with empty points on empty space', function (done) {
136165
var clickData;
137166

138-
makePlot(gd, {clickanywhere: true}).then(function() {
139-
gd.on('plotly_click', function(d) { clickData = d; });
140-
141-
var bb = gd.getBoundingClientRect();
142-
var s = gd._fullLayout._size;
143-
click(bb.left + s.l + 250, bb.top + s.t + 50);
144-
145-
expect(clickData).toBeDefined();
146-
expect(clickData.points).toEqual([]);
147-
expect(clickData.xaxes.length).toBe(1);
148-
expect(clickData.yaxes.length).toBe(1);
149-
expect(clickData.xvals.length).toBe(1);
150-
expect(clickData.yvals.length).toBe(1);
151-
// click at 250px into 300px plot area, xrange [0,10]: 250/300*10 = 8.33
152-
expect(clickData.xvals[0]).toBeCloseTo(250 / 30, 2);
153-
// click at 50px into 300px plot area, yrange [0,10]: 10 - 50/300*10 = 8.33
154-
expect(clickData.yvals[0]).toBeCloseTo(10 - 50 / 30, 2);
155-
})
156-
.then(done, done.fail);
167+
makePlot(gd, { clickanywhere: true })
168+
.then(function () {
169+
gd.on('plotly_click', function (d) {
170+
clickData = d;
171+
});
172+
173+
var bb = gd.getBoundingClientRect();
174+
var s = gd._fullLayout._size;
175+
click(bb.left + s.l + 250, bb.top + s.t + 50);
176+
177+
expect(clickData).toBeDefined();
178+
expect(clickData.points).toEqual([]);
179+
expect(clickData.xaxes.length).toBe(1);
180+
expect(clickData.yaxes.length).toBe(1);
181+
expect(clickData.xvals.length).toBe(1);
182+
expect(clickData.yvals.length).toBe(1);
183+
// click at 250px into 300px plot area, xrange [0,10]: 250/300*10 = 8.33
184+
expect(clickData.xvals[0]).toBeCloseTo(250 / 30, 2);
185+
// click at 50px into 300px plot area, yrange [0,10]: 10 - 50/300*10 = 8.33
186+
expect(clickData.yvals[0]).toBeCloseTo(10 - 50 / 30, 2);
187+
})
188+
.then(done, done.fail);
157189
});
158190

159-
it('does not emit plotly_click event on empty space when clickanywhere is false', function(done) {
191+
it('does not emit plotly_click event on empty space when clickanywhere is false', function (done) {
160192
var clickData;
161193

162-
makePlot(gd).then(function() {
163-
gd.on('plotly_click', function(d) { clickData = d; });
194+
makePlot(gd)
195+
.then(function () {
196+
gd.on('plotly_click', function (d) {
197+
clickData = d;
198+
});
164199

165-
var bb = gd.getBoundingClientRect();
166-
var s = gd._fullLayout._size;
167-
click(bb.left + s.l + 250, bb.top + s.t + 50);
200+
var bb = gd.getBoundingClientRect();
201+
var s = gd._fullLayout._size;
202+
click(bb.left + s.l + 250, bb.top + s.t + 50);
168203

169-
expect(clickData).toBeUndefined();
170-
})
171-
.then(done, done.fail);
204+
expect(clickData).toBeUndefined();
205+
})
206+
.then(done, done.fail);
172207
});
173208
});

0 commit comments

Comments
 (0)