-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathsurface_test.js
182 lines (153 loc) · 6.24 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
var Surface = require('@src/traces/surface');
var Lib = require('@src/lib');
describe('Test surface', function() {
'use strict';
describe('supplyDefaults', function() {
var supplyDefaults = Surface.supplyDefaults;
var defaultColor = '#444',
layout = {_dfltTitle: {colorbar: 'cb'}};
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.showscale).toBe(true);
expect(traceOut.colorbar).toBeDefined();
});
it('should coerce \'c\' attributes with \'z\' if \'c\' isn\'t present', function() {
traceIn = {
z: [[1, 2, 3], [2, 1, 2]],
zauto: false,
zmin: 0,
zmax: 10
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.cauto).toEqual(false);
expect(traceOut.cmin).toEqual(0);
expect(traceOut.cmax).toEqual(10);
});
it('should coerce \'c\' attributes with \'c\' values regardless of `\'z\' if \'c\' is present', function() {
traceIn = {
z: [[1, 2, 3], [2, 1, 2]],
zauto: false,
zmin: 0,
zmax: 10,
cauto: true,
cmin: -10,
cmax: 20
};
supplyDefaults(traceIn, traceOut, defaultColor, layout);
expect(traceOut.cauto).toEqual(true);
expect(traceOut.cmin).toEqual(-10);
expect(traceOut.cmax).toEqual(20);
});
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');
});
});
});