forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcdata_test.js
243 lines (187 loc) · 10.5 KB
/
calcdata_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
var Plotly = require('@lib/index');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
describe('calculated data and points', function() {
var gd;
beforeEach(function() {
gd = createGraphDiv();
});
afterEach(destroyGraphDiv);
describe('connectGaps', function() {
it('should exclude null and undefined points when false', function() {
Plotly.plot(gd, [{ x: [1,2,3,undefined,5], y: [1,null,3,4,5]}], {});
expect(gd.calcdata[0][1]).toEqual({ x: false, y: false});
expect(gd.calcdata[0][3]).toEqual({ x: false, y: false});
});
it('should exclude null and undefined points as categories when false', function() {
Plotly.plot(gd, [{ x: [1,2,3,undefined,5], y: [1,null,3,4,5] }], { xaxis: { type: 'category' }});
expect(gd.calcdata[0][1]).toEqual({ x: false, y: false});
expect(gd.calcdata[0][3]).toEqual({ x: false, y: false});
});
});
xdescribe('category ordering', function() {
describe('default category ordering reified', function() {
it('should output categories in the given order by default', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category'
}});
expect(gd.calcdata[0][0].y).toEqual(15);
expect(gd.calcdata[0][1].y).toEqual(11);
expect(gd.calcdata[0][2].y).toEqual(12);
expect(gd.calcdata[0][3].y).toEqual(13);
expect(gd.calcdata[0][4].y).toEqual(14);
});
it('should output categories in the given order if `trace` order is explicitly specified', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'trace'
// Wouldn't it be preferred to supply a function and plotly would have several functions like this?
// E.g. it's easier for symbol completion (whereas there's no symbol completion on string config)
// See arguments from Mike Bostock, highlighted in medium green here:
// https://medium.com/@mbostock/what-makes-software-good-943557f8a488#eef9
// Plus if it's a function, then users can roll their own.
//
// Also, if axis tick order is made configurable, shouldn't we make trace order configurable?
// Trace order as in, if a line or curve is drawn through points, what's the trace sequence.
// These are two orthogonal concepts. In this round, I'm assuming that the trace order is implied
// by the order the {x,y} arrays are specified.
}});
expect(gd.calcdata[0][0].y).toEqual(15);
expect(gd.calcdata[0][1].y).toEqual(11);
expect(gd.calcdata[0][2].y).toEqual(12);
expect(gd.calcdata[0][3].y).toEqual(13);
expect(gd.calcdata[0][4].y).toEqual(14);
});
});
describe('domain alphanumerical category ordering', function() {
it('should output categories in ascending domain alphanumerical order', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'category ascending'
}});
expect(gd.calcdata[0][0].y).toEqual(11);
expect(gd.calcdata[0][1].y).toEqual(13);
expect(gd.calcdata[0][2].y).toEqual(15);
expect(gd.calcdata[0][3].y).toEqual(14);
expect(gd.calcdata[0][4].y).toEqual(12);
});
it('should output categories in descending domain alphanumerical order', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'category descending'
}});
expect(gd.calcdata[0][0].y).toEqual(12);
expect(gd.calcdata[0][1].y).toEqual(14);
expect(gd.calcdata[0][2].y).toEqual(15);
expect(gd.calcdata[0][3].y).toEqual(13);
expect(gd.calcdata[0][4].y).toEqual(11);
});
it('should output categories in categorymode order even if category array is defined', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'category ascending',
categorylist: ['b','a','d','e','c'] // These must be ignored. Alternative: error?
}});
expect(gd.calcdata[0][0].y).toEqual(11);
expect(gd.calcdata[0][1].y).toEqual(13);
expect(gd.calcdata[0][2].y).toEqual(15);
expect(gd.calcdata[0][3].y).toEqual(14);
expect(gd.calcdata[0][4].y).toEqual(12);
});
it('should output categories in ascending domain alphanumerical order, excluding undefined', function() {
Plotly.plot(gd, [{x: ['c',undefined,'e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'category ascending'
}});
expect(gd.calcdata[0][0].y).toEqual(11);
expect(gd.calcdata[0][1].y).toEqual(15);
expect(gd.calcdata[0][2].y).toEqual(14);
expect(gd.calcdata[0][3].y).toEqual(12);
});
});
describe('codomain numerical category ordering', function() {
it('should output categories in ascending codomain numerical order', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'value ascending'
}});
expect(gd.calcdata[0][0].y).toEqual(11);
expect(gd.calcdata[0][1].y).toEqual(12);
expect(gd.calcdata[0][2].y).toEqual(13);
expect(gd.calcdata[0][3].y).toEqual(14);
expect(gd.calcdata[0][4].y).toEqual(15);
});
it('should output categories in descending codomain numerical order', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'value descending'
}});
expect(gd.calcdata[0][0].y).toEqual(15);
expect(gd.calcdata[0][1].y).toEqual(14);
expect(gd.calcdata[0][2].y).toEqual(13);
expect(gd.calcdata[0][3].y).toEqual(12);
expect(gd.calcdata[0][4].y).toEqual(11);
});
it('should output categories in descending codomain numerical order, excluding nulls', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,null,13,14]}], { xaxis: {
type: 'category',
categorymode: 'value descending'
}});
expect(gd.calcdata[0][0].y).toEqual(15);
expect(gd.calcdata[0][1].y).toEqual(14);
expect(gd.calcdata[0][2].y).toEqual(12);
expect(gd.calcdata[0][3].y).toEqual(11);
});
});
describe('explicit category ordering', function() {
it('should output categories in explicitly supplied order, independent of trace order', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'array',
categorylist: ['b','a','d','e','c']
}});
expect(gd.calcdata[0][0].y).toEqual(13);
expect(gd.calcdata[0][1].y).toEqual(11);
expect(gd.calcdata[0][2].y).toEqual(14);
expect(gd.calcdata[0][3].y).toEqual(12);
expect(gd.calcdata[0][4].y).toEqual(15);
});
it('should output categories in explicitly supplied order, independent of trace order, pruned', function() {
Plotly.plot(gd, [{x: ['c',undefined,'e','b','d'], y: [15,11,12,null,14]}], { xaxis: {
type: 'category',
categorymode: 'array',
categorylist: ['b','a','d','e','c']
}});
expect(gd.calcdata[0][0].y).toEqual(13);
expect(gd.calcdata[0][1].y).toEqual(14);
expect(gd.calcdata[0][2].y).toEqual(15);
});
it('should output categories in explicitly supplied order even if not all categories are present', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'array',
categorylist: ['y','b','x','a','d','z','e','c']
}});
expect(gd.calcdata[0][0].y).toEqual(13);
expect(gd.calcdata[0][1].y).toEqual(11);
expect(gd.calcdata[0][2].y).toEqual(14);
expect(gd.calcdata[0][3].y).toEqual(12);
expect(gd.calcdata[0][4].y).toEqual(15);
});
it('should output categories in explicitly supplied order first, if not all categories are covered', function() {
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
type: 'category',
categorymode: 'array',
categorylist: ['b','a','x','c']
}});
expect(gd.calcdata[0][0].y).toEqual(13);
expect(gd.calcdata[0][1].y).toEqual(11);
expect(gd.calcdata[0][2].y).toEqual(15);
// The order of the rest is unspecified, no need to check. Alternative: make _both_ categorymode and
// categories effective; categories would take precedence and the remaining items would be sorted
// based on the categorymode. This of course means that the mere presence of categories triggers this
// behavior, rather than an explicit 'explicit' categorymode.
});
});
});
});