-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathcone_test.js
252 lines (210 loc) · 7.34 KB
/
cone_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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
var Plotly = require('@lib');
var Lib = require('@src/lib');
var supplyAllDefaults = require('../assets/supply_defaults');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var delay = require('../assets/delay');
var mouseEvent = require('../assets/mouse_event');
var customAssertions = require('../assets/custom_assertions');
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
describe('Test cone defaults', function() {
var gd;
function makeGD() {
return {
data: [{
type: 'cone',
x: [1, 2],
y: [1, 2],
z: [1, 2],
u: [1, 2],
v: [1, 2],
w: [1, 2]
}],
layout: {}
};
}
it('should not set `visible: false` for traces with x,y,z,u,v,w arrays', function() {
gd = makeGD();
supplyAllDefaults(gd);
expect(gd._fullData[0].visible).toBe(true);
});
it('should set `visible: false` for traces missing x,y,z,u,v,w arrays', function() {
var keysToDelete = ['x', 'y', 'z', 'u', 'v', 'w'];
keysToDelete.forEach(function(k) {
gd = makeGD();
delete gd.data[0][k];
supplyAllDefaults(gd);
expect(gd._fullData[0].visible).toBe(!k, 'missing array ' + k);
});
});
it('should set `visible: false` for traces empty x,y,z,u,v,w arrays', function() {
var keysToEmpty = ['x', 'y', 'z', 'u', 'v', 'w'];
keysToEmpty.forEach(function(k) {
gd = makeGD();
gd.data[0][k] = [];
supplyAllDefaults(gd);
expect(gd._fullData[0].visible).toBe(!k, 'empty array ' + k);
});
});
});
describe('@gl Test cone autorange:', function() {
var gd;
beforeEach(function() {
gd = createGraphDiv();
});
afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});
function _assertAxisRanges(msg, xrng, yrng, zrng) {
var sceneLayout = gd._fullLayout.scene;
expect(sceneLayout.xaxis.range).toBeCloseToArray(xrng, 2, 'xaxis range -' + msg);
expect(sceneLayout.yaxis.range).toBeCloseToArray(yrng, 2, 'yaxis range -' + msg);
expect(sceneLayout.zaxis.range).toBeCloseToArray(zrng, 2, 'zaxis range -' + msg);
}
it('should add pad around cone position to make sure they fit on the scene', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/gl3d_cone-autorange.json'));
// the resulting image should be independent of what I multiply by here
function makeScaleFn(s) {
return function(v) { return v * s; };
}
Plotly.plot(gd, fig).then(function() {
_assertAxisRanges('base',
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
);
var trace = fig.data[0];
var m = makeScaleFn(10);
var u = trace.u.map(m);
var v = trace.v.map(m);
var w = trace.w.map(m);
return Plotly.restyle(gd, {u: [u], v: [v], w: [w]});
})
.then(function() {
_assertAxisRanges('scaled up',
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
);
var trace = fig.data[0];
var m = makeScaleFn(0.2);
var u = trace.u.map(m);
var v = trace.v.map(m);
var w = trace.w.map(m);
return Plotly.restyle(gd, {u: [u], v: [v], w: [w]});
})
.then(function() {
_assertAxisRanges('scaled down',
[-0.39, 4.39], [-0.39, 4.39], [-0.39, 4.39]
);
var trace = fig.data[0];
var x = trace.x.slice();
x.push(5);
var y = trace.y.slice();
y.push(5);
var z = trace.z.slice();
z.push(5);
var u = trace.u.slice();
u.push(0);
var v = trace.v.slice();
v.push(0);
var w = trace.w.slice();
w.push(0);
return Plotly.restyle(gd, {
x: [x], y: [y], z: [z],
u: [u], v: [v], w: [w]
});
})
.then(function() {
_assertAxisRanges('after adding one cone outside range but with norm-0',
[-0.45, 6.45], [-0.45, 6.45], [-0.45, 6.45]
);
return Plotly.restyle(gd, 'sizeref', 10);
})
.then(function() {
_assertAxisRanges('after increasing sizeref',
[-12.4, 18.4], [-12.4, 18.4], [-12.4, 18.4]
);
return Plotly.restyle(gd, 'sizeref', 0.1);
})
.then(function() {
_assertAxisRanges('after decreasing sizeref',
[0.74, 5.26], [0.74, 5.26], [0.74, 5.26]
);
return Plotly.restyle(gd, {
sizemode: 'absolute',
sizeref: 2
});
})
.then(function() {
_assertAxisRanges('with sizemode absolute',
[-1.25, 7.25], [-1.25, 7.25], [-1.25, 7.25]
);
})
.catch(failTest)
.then(done);
});
});
describe('@gl Test cone interactions', function() {
var gd;
beforeEach(function() {
gd = createGraphDiv();
});
afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});
it('should add/clear gl objects correctly', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/gl3d_cone-simple.json'));
// put traces on same subplot
delete fig.data[1].scene;
Plotly.plot(gd, fig).then(function() {
var scene = gd._fullLayout.scene._scene;
var objs = scene.glplot.objects;
expect(objs.length).toBe(4);
return Plotly.deleteTraces(gd, [0]);
})
.then(function() {
var scene = gd._fullLayout.scene._scene;
var objs = scene.glplot.objects;
expect(objs.length).toBe(2);
return Plotly.deleteTraces(gd, [0]);
})
.then(function() {
var scene = gd._fullLayout.scene;
expect(scene).toBeUndefined();
})
.catch(failTest)
.then(done);
});
it('should display hover labels', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/gl3d_cone-simple.json'));
// only one trace on one scene
fig.data = [fig.data[0]];
fig.data[0].showscale = false;
delete fig.layout.scene.domain;
fig.layout.margin = {l: 0, t: 0, r: 0, b: 0};
fig.layout.width = 400;
fig.layout.height = 400;
function _hover() {
mouseEvent('mouseover', 200, 200);
return delay(20)();
}
Plotly.plot(gd, fig)
.then(delay(20))
.then(_hover)
.then(function() {
assertHoverLabelContent({
nums: ['x: 3', 'y: 3', 'z: 3', 'norm: 2.00'].join('\n')
});
return Plotly.restyle(gd, 'hoverinfo', 'u+v+w');
})
.then(delay(20))
.then(_hover)
.then(function() {
assertHoverLabelContent({
nums: ['u: 0', 'v: 0', 'w: 2'].join('\n')
});
})
.catch(failTest)
.then(done);
});
});