forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgl2d_click_test.js
146 lines (92 loc) · 4.3 KB
/
gl2d_click_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
var Plotly = require('@lib/index');
var Lib = require('@src/lib');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var customMatchers = require('../assets/custom_matchers');
// cartesian click events events use the hover data
// from the mousemove events and then simulate
// a click event on mouseup
// var click = require('../assets/click');
var hover = require('../assets/hover');
describe('Test click interactions:', function() {
var mock = require('@mocks/gl2d_14.json');
var mockCopy, gd;
beforeAll(function() {
jasmine.addMatchers(customMatchers);
});
beforeEach(function() {
gd = createGraphDiv();
mockCopy = Lib.extendDeep({}, mock);
});
afterEach(destroyGraphDiv);
describe('hover event is fired on hover', function() {
var futureData;
it('in general', function(done) {
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
.then(new Promise(function() {
gd.on('plotly_hover', function(data) {
futureData = data;
});
hover(654.7712871743302, 316.97670766680994);
window.setTimeout(function() {
expect(futureData.points.length).toEqual(1);
var pt = futureData.points[0];
expect(Object.keys(pt)).toEqual([
'trace', 'dataCoord', 'traceCoord', 'textLabel', 'color',
'name', 'hoverinfo', 'screenCoord'
]);
expect(pt.traceCoord).toEqual([15.772, 0.387]);
done();
}, 250);
}));
});
it('even when hoverinfo (== plotly tooltip) is set to none', function(done) {
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
modifiedMockCopy.data[0].hoverinfo = 'none';
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
.then(new Promise(function() {
gd.on('plotly_hover', function(data) {
futureData = data;
});
hover(654.7712871743302, 316.97670766680994);
window.setTimeout(function() {
expect(futureData.points.length).toEqual(1);
var pt = futureData.points[0];
expect(Object.keys(pt)).toEqual([
'trace', 'dataCoord', 'traceCoord', 'textLabel', 'color',
'name', 'hoverinfo', 'screenCoord'
]);
expect(pt.traceCoord).toEqual([15.772, 0.387]);
done();
}, 250);
}));
});
it('unhover happens', function(done) {
var modifiedMockCopy = Lib.extendDeep({}, mockCopy);
modifiedMockCopy.data[0].hoverinfo = 'none';
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)
.then(new Promise(function() {
futureData = undefined;
gd.on('plotly_unhover', function() {
futureData = 'emitted plotly_unhover';
});
hover(654.7712871743302, 316.97670766680994);
// fairly realistic simulation of moving with the cursor
window.setTimeout(function() {
var x = 654, y = 316; // we start here
var canceler = window.setInterval(function() {
hover(x--, y++); // move the cursor
}, 10);
window.setTimeout(function() {
window.clearInterval(canceler); // stop the mouse at some point
}, 250);
window.setTimeout(function() {
expect(futureData).toEqual('emitted plotly_unhover');
done();
}, 250);
}, 250);
}));
});
});
});