-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathsurface_test.js
256 lines (222 loc) · 8.66 KB
/
surface_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
253
254
255
256
var Plotly = require('../../../lib/index');
var Lib = require('../../../src/lib');
var supplyDefaults = require('../../../src/traces/surface').supplyDefaults;
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
describe('Test surface', function() {
'use strict';
describe('supplyDefaults', function() {
var defaultColor = '#444';
var layout = {_dfltTitle: {colorbar: 'cb'}, font: {color: '#444'}};
var traceIn, traceOut;
beforeEach(function() {
traceOut = {};
});
it('should set \'visible\' to false if \'z\' isn\'t provided', function() {
traceIn = {};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.visible).toBe(false);
});
it('should NOT fill \'x\' and \'y\' if not provided', function() {
// this happens later on now
traceIn = {
z: [[1, 2, 3], [2, 1, 2]]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.x).toBeUndefined();
expect(traceOut.y).toBeUndefined();
});
it('should coerce \'project\' if contours or highlight lines are enabled', function() {
traceIn = {
z: [[1, 2, 3], [2, 1, 2]],
contours: {
x: {},
y: { show: true },
z: { show: false, highlight: false }
}
};
var fullOpts = {
show: false,
highlight: true,
project: { x: false, y: false, z: false },
highlightcolor: '#444',
highlightwidth: 2
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.contours.x).toEqual(fullOpts);
expect(traceOut.contours.y).toEqual(Lib.extendDeep({}, fullOpts, {
show: true,
color: '#444',
width: 2,
usecolormap: false
}));
expect(traceOut.contours.z).toEqual({ show: false, highlight: false });
});
it('should coerce contour style attributes if contours lines are enabled', function() {
traceIn = {
z: [[1, 2, 3], [2, 1, 2]],
contours: {
x: { show: true }
}
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.contours.x.color).toEqual('#444');
expect(traceOut.contours.x.width).toEqual(2);
expect(traceOut.contours.x.usecolormap).toEqual(false);
['y', 'z'].forEach(function(ax) {
expect(traceOut.contours[ax].color).toBeUndefined();
expect(traceOut.contours[ax].width).toBeUndefined();
expect(traceOut.contours[ax].usecolormap).toBeUndefined();
});
});
it('should coerce colorscale and colorbar attributes', function() {
traceIn = {
z: [[1, 2, 3], [2, 1, 2]]
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.cauto).toBe(true);
expect(traceOut.cmin).toBeUndefined();
expect(traceOut.cmax).toBeUndefined();
expect(traceOut.colorscale).toEqual([
[0, 'rgb(5,10,172)'],
[0.35, 'rgb(106,137,247)'],
[0.5, 'rgb(190,190,190)'],
[0.6, 'rgb(220,170,132)'],
[0.7, 'rgb(230,145,90)'],
[1, 'rgb(178,10,28)']
]);
expect(traceOut.reversescale).toBe(false);
expect(traceOut.showscale).toBe(true);
expect(traceOut.colorbar).toBeDefined();
});
it('should default \'c\' attributes with if \'surfacecolor\' is present', function() {
traceIn = {
z: [[1, 2, 3], [2, 1, 2]],
surfacecolor: [[2, 1, 2], [1, 2, 3]],
zauto: false,
zmin: 0,
zmax: 10
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.cauto).toEqual(true);
expect(traceOut.cmin).toBeUndefined();
expect(traceOut.cmax).toBeUndefined();
});
it('should inherit layout.calendar', function() {
traceIn = {
z: [[1, 2, 3], [2, 1, 2]]
};
supplyDefaults(traceIn, traceOut, defaultColor, Lib.extendFlat({calendar: 'islamic'}, layout));
// we always fill calendar attributes, because it's hard to tell if
// we're on a date axis at this point.
expect(traceOut.xcalendar).toBe('islamic');
expect(traceOut.ycalendar).toBe('islamic');
expect(traceOut.zcalendar).toBe('islamic');
});
it('should take its own calendars', function() {
var traceIn = {
z: [[1, 2, 3], [2, 1, 2]],
xcalendar: 'coptic',
ycalendar: 'ethiopian',
zcalendar: 'mayan'
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.xcalendar).toBe('coptic');
expect(traceOut.ycalendar).toBe('ethiopian');
expect(traceOut.zcalendar).toBe('mayan');
});
});
describe('Test dimension and expected visibility tests', function() {
var gd;
beforeEach(function() {
gd = createGraphDiv();
});
afterEach(function() {
Plotly.purge(gd);
destroyGraphDiv();
});
function assertVisibility(exp, msg) {
expect(gd._fullData[0]).not.toBe(undefined, 'no visibility!');
expect(gd._fullData[0].visible).toBe(exp, msg);
}
it('@gl surface should be invisible when the z array is empty', function(done) {
Plotly.newPlot(gd, [{
type: 'surface',
z: []
}])
.then(function() {
assertVisibility(false, 'not to be visible');
})
.then(done, done.fail);
});
it('@gl surface should be invisible when the x array is defined but is empty', function(done) {
Plotly.newPlot(gd, [{
type: 'surface',
x: [],
y: [0, 1],
z: []
}])
.then(function() {
assertVisibility(false, 'not to be visible');
})
.then(done, done.fail);
});
it('@gl surface should be invisible when the y array is defined but is empty', function(done) {
Plotly.newPlot(gd, [{
type: 'surface',
x: [0, 1],
y: [],
z: []
}])
.then(function() {
assertVisibility(false, 'not to be visible');
})
.then(done, done.fail);
});
it('@gl surface should be invisible when the x array is defined and has at least one item', function(done) {
Plotly.newPlot(gd, [{
type: 'surface',
x: [0],
y: [0, 1],
z: [[1], [2]]
}])
.then(function() {
assertVisibility(true, 'to be visible');
})
.then(done, done.fail);
});
it('@gl surface should be invisible when the y array is defined and has at least one item', function(done) {
Plotly.newPlot(gd, [{
type: 'surface',
x: [0, 1],
y: [0],
z: [[1, 2]]
}])
.then(function() {
assertVisibility(true, 'to be visible');
})
.then(done, done.fail);
});
it('@gl surface should be visible when the x and y are not provided; but z array is provided', function(done) {
Plotly.newPlot(gd, [{
type: 'surface',
z: [[1, 2], [3, 4]]
}])
.then(function() {
assertVisibility(true, 'to be visible');
})
.then(done, done.fail);
});
it('@gl surface should be invisible when the x and y are provided; but z array is not provided', function(done) {
Plotly.newPlot(gd, [{
type: 'surface',
x: [0, 1],
y: [0, 1]
}])
.then(function() {
assertVisibility(false, 'to be invisible');
})
.then(done, done.fail);
});
});
});