@@ -11,7 +11,7 @@ describe('aggregate', function() {
11
11
12
12
afterEach ( destroyGraphDiv ) ;
13
13
14
- it ( 'handles all funcs for numeric data' , function ( ) {
14
+ it ( 'handles all funcs for numeric data' , function ( done ) {
15
15
// throw in some non-numbers, they should get discarded except first/last
16
16
Plotly . newPlot ( gd , [ {
17
17
x : [ 1 , 2 , 3 , 4 , 'fail' ] ,
@@ -51,25 +51,28 @@ describe('aggregate', function() {
51
51
} ] , {
52
52
// log axis doesn't change how sum (or avg but not tested) works
53
53
xaxis : { type : 'log' }
54
- } ) ;
55
-
56
- var traceOut = gd . _fullData [ 0 ] ;
57
-
58
- expect ( traceOut . x ) . toEqual ( [ 8 , 2 ] ) ;
59
- expect ( traceOut . y ) . toBeCloseToArray ( [ 3.3 , 2.2 ] , 5 ) ;
60
- expect ( traceOut . customdata ) . toEqual ( [ - 3 , undefined ] ) ;
61
- expect ( traceOut . marker . size ) . toEqual ( [ 0.1 , 0.2 ] ) ;
62
- expect ( traceOut . marker . color ) . toEqual ( [ 10 , 4 ] ) ;
63
- expect ( traceOut . marker . opacity ) . toEqual ( [ 0.6 , 'boo' ] ) ;
64
- expect ( traceOut . marker . line . color ) . toEqual ( [ 'the end' , 3.3 ] ) ;
65
- expect ( traceOut . marker . line . width ) . toEqual ( [ 4 , 1 ] ) ;
66
-
67
- var transform = traceOut . transforms [ 0 ] ;
68
- var inverseMapping = transform . _indexToPoints ;
69
- expect ( inverseMapping ) . toEqual ( { 0 : [ 0 , 2 , 3 , 4 ] , 1 : [ 1 ] } ) ;
54
+ } )
55
+ . then ( function ( ) {
56
+ var traceOut = gd . _fullData [ 0 ] ;
57
+
58
+ expect ( traceOut . x ) . toEqual ( [ 8 , 2 ] ) ;
59
+ expect ( traceOut . y ) . toBeCloseToArray ( [ 3.3 , 2.2 ] , 5 ) ;
60
+ expect ( traceOut . customdata ) . toEqual ( [ - 3 , undefined ] ) ;
61
+ expect ( traceOut . marker . size ) . toEqual ( [ 0.1 , 0.2 ] ) ;
62
+ expect ( traceOut . marker . color ) . toEqual ( [ 10 , 4 ] ) ;
63
+ expect ( traceOut . marker . opacity ) . toEqual ( [ 0.6 , 'boo' ] ) ;
64
+ expect ( traceOut . marker . line . color ) . toEqual ( [ 'the end' , 3.3 ] ) ;
65
+ expect ( traceOut . marker . line . width ) . toEqual ( [ 4 , 1 ] ) ;
66
+
67
+ var transform = traceOut . transforms [ 0 ] ;
68
+ var inverseMapping = transform . _indexToPoints ;
69
+ expect ( inverseMapping ) . toEqual ( { 0 : [ 0 , 2 , 3 , 4 ] , 1 : [ 1 ] } ) ;
70
+ } )
71
+ . catch ( failTest )
72
+ . then ( done ) ;
70
73
} ) ;
71
74
72
- it ( 'handles all funcs except sum for date data' , function ( ) {
75
+ it ( 'handles all funcs except sum for date data' , function ( done ) {
73
76
// weird cases handled in another test
74
77
Plotly . newPlot ( gd , [ {
75
78
x : [ '2001-01-01' , '' , '2001-01-03' , '2001-01-05' , '2001-01-07' ] ,
@@ -95,19 +98,22 @@ describe('aggregate', function() {
95
98
{ target : 'x' , func : 'min' }
96
99
]
97
100
} ]
98
- } ] ) ;
99
-
100
- var traceOut = gd . _fullData [ 0 ] ;
101
+ } ] )
102
+ . then ( function ( ) {
103
+ var traceOut = gd . _fullData [ 0 ] ;
101
104
102
- expect ( traceOut . x ) . toEqual ( [ '2001-01-04' , undefined ] ) ;
103
- expect ( traceOut . y ) . toEqual ( [ '1990-12-23' , '2005-03-15' ] ) ;
104
- expect ( traceOut . text ) . toEqual ( [ '2001-01-01 12:37' , '2001-01-01 12:35' ] ) ;
105
- expect ( traceOut . hovertext ) . toEqual ( [ 'a' , '2001-01-02' ] ) ;
106
- expect ( traceOut . customdata ) . toEqual ( [ '2001-05' , 'b' ] ) ;
107
- expect ( traceOut . marker . line . width ) . toEqual ( [ 4 , 1 ] ) ;
105
+ expect ( traceOut . x ) . toEqual ( [ '2001-01-04' , undefined ] ) ;
106
+ expect ( traceOut . y ) . toEqual ( [ '1990-12-23' , '2005-03-15' ] ) ;
107
+ expect ( traceOut . text ) . toEqual ( [ '2001-01-01 12:37' , '2001-01-01 12:35' ] ) ;
108
+ expect ( traceOut . hovertext ) . toEqual ( [ 'a' , '2001-01-02' ] ) ;
109
+ expect ( traceOut . customdata ) . toEqual ( [ '2001-05' , 'b' ] ) ;
110
+ expect ( traceOut . marker . line . width ) . toEqual ( [ 4 , 1 ] ) ;
111
+ } )
112
+ . catch ( failTest )
113
+ . then ( done ) ;
108
114
} ) ;
109
115
110
- it ( 'handles all funcs except sum and avg for category data' , function ( ) {
116
+ it ( 'handles all funcs except sum and avg for category data' , function ( done ) {
111
117
// weird cases handled in another test
112
118
Plotly . newPlot ( gd , [ {
113
119
x : [ 'a' , 'b' , 'c' , 'aa' , 'd' ] ,
@@ -130,20 +136,23 @@ describe('aggregate', function() {
130
136
} ]
131
137
} ] , {
132
138
xaxis : { categoryarray : [ 'aaa' , 'aa' , 'a' , 'b' , 'c' ] }
133
- } ) ;
134
-
135
- var traceOut = gd . _fullData [ 0 ] ;
139
+ } )
140
+ . then ( function ( ) {
141
+ var traceOut = gd . _fullData [ 0 ] ;
136
142
137
- // explicit order (only possible for axis data)
138
- expect ( traceOut . x ) . toEqual ( [ 'aa' , 'b' ] ) ;
139
- // implied order from data
140
- expect ( traceOut . y ) . toEqual ( [ 't' , 'w' ] ) ;
141
- expect ( traceOut . text ) . toEqual ( [ 'a' , 'b' ] ) ;
142
- expect ( traceOut . hovertext ) . toEqual ( [ 'c' , 'b' ] ) ;
143
- expect ( traceOut . marker . line . width ) . toEqual ( [ 4 , 1 ] ) ;
143
+ // explicit order (only possible for axis data)
144
+ expect ( traceOut . x ) . toEqual ( [ 'aa' , 'b' ] ) ;
145
+ // implied order from data
146
+ expect ( traceOut . y ) . toEqual ( [ 't' , 'w' ] ) ;
147
+ expect ( traceOut . text ) . toEqual ( [ 'a' , 'b' ] ) ;
148
+ expect ( traceOut . hovertext ) . toEqual ( [ 'c' , 'b' ] ) ;
149
+ expect ( traceOut . marker . line . width ) . toEqual ( [ 4 , 1 ] ) ;
150
+ } )
151
+ . catch ( failTest )
152
+ . then ( done ) ;
144
153
} ) ;
145
154
146
- it ( 'allows date and category sums, and category avg, with weird output' , function ( ) {
155
+ it ( 'allows date and category sums, and category avg, with weird output' , function ( done ) {
147
156
// this test is more of an FYI than anything else - it doesn't break but
148
157
// these results are usually meaningless.
149
158
@@ -160,24 +169,27 @@ describe('aggregate', function() {
160
169
{ target : 'text' , func : 'avg' }
161
170
]
162
171
} ]
163
- } ] ) ;
164
-
165
- var traceOut = gd . _fullData [ 0 ] ;
166
-
167
- // date sums: 1970-01-01 is "zero", there are shifts due to # of leap years
168
- // without that shift these would be 2032-01-02 and 2032-01-06
169
- expect ( traceOut . x ) . toEqual ( [ '2032-01-03' , '2032-01-07' ] ) ;
170
- // category sums: can go off the end of the category array -> gives undefined
171
- expect ( traceOut . y ) . toEqual ( [ 'b' , undefined ] ) ;
172
- // category average: can result in fractional categories -> rounds (0.5 rounds to 1)
173
- expect ( traceOut . text ) . toEqual ( [ 'b' , 'b' ] ) ;
172
+ } ] )
173
+ . then ( function ( ) {
174
+ var traceOut = gd . _fullData [ 0 ] ;
174
175
175
- var transform = traceOut . transforms [ 0 ] ;
176
- var inverseMapping = transform . _indexToPoints ;
177
- expect ( inverseMapping ) . toEqual ( { 0 : [ 0 , 1 ] , 1 : [ 2 , 3 ] } ) ;
176
+ // date sums: 1970-01-01 is "zero", there are shifts due to # of leap years
177
+ // without that shift these would be 2032-01-02 and 2032-01-06
178
+ expect ( traceOut . x ) . toEqual ( [ '2032-01-03' , '2032-01-07' ] ) ;
179
+ // category sums: can go off the end of the category array -> gives undefined
180
+ expect ( traceOut . y ) . toEqual ( [ 'b' , undefined ] ) ;
181
+ // category average: can result in fractional categories -> rounds (0.5 rounds to 1)
182
+ expect ( traceOut . text ) . toEqual ( [ 'b' , 'b' ] ) ;
183
+
184
+ var transform = traceOut . transforms [ 0 ] ;
185
+ var inverseMapping = transform . _indexToPoints ;
186
+ expect ( inverseMapping ) . toEqual ( { 0 : [ 0 , 1 ] , 1 : [ 2 , 3 ] } ) ;
187
+ } )
188
+ . catch ( failTest )
189
+ . then ( done ) ;
178
190
} ) ;
179
191
180
- it ( 'can aggregate on an existing data array' , function ( ) {
192
+ it ( 'can aggregate on an existing data array' , function ( done ) {
181
193
Plotly . newPlot ( gd , [ {
182
194
x : [ 1 , 2 , 3 , 4 , 5 ] ,
183
195
y : [ 2 , 4 , 6 , 8 , 10 ] ,
@@ -190,20 +202,23 @@ describe('aggregate', function() {
190
202
{ target : 'y' , func : 'avg' }
191
203
]
192
204
} ]
193
- } ] ) ;
194
-
195
- var traceOut = gd . _fullData [ 0 ] ;
205
+ } ] )
206
+ . then ( function ( ) {
207
+ var traceOut = gd . _fullData [ 0 ] ;
196
208
197
- expect ( traceOut . x ) . toEqual ( [ 8 , 7 ] ) ;
198
- expect ( traceOut . y ) . toBeCloseToArray ( [ 16 / 3 , 7 ] , 5 ) ;
199
- expect ( traceOut . marker . size ) . toEqual ( [ 10 , 20 ] ) ;
209
+ expect ( traceOut . x ) . toEqual ( [ 8 , 7 ] ) ;
210
+ expect ( traceOut . y ) . toBeCloseToArray ( [ 16 / 3 , 7 ] , 5 ) ;
211
+ expect ( traceOut . marker . size ) . toEqual ( [ 10 , 20 ] ) ;
200
212
201
- var transform = traceOut . transforms [ 0 ] ;
202
- var inverseMapping = transform . _indexToPoints ;
203
- expect ( inverseMapping ) . toEqual ( { 0 : [ 0 , 1 , 4 ] , 1 : [ 2 , 3 ] } ) ;
213
+ var transform = traceOut . transforms [ 0 ] ;
214
+ var inverseMapping = transform . _indexToPoints ;
215
+ expect ( inverseMapping ) . toEqual ( { 0 : [ 0 , 1 , 4 ] , 1 : [ 2 , 3 ] } ) ;
216
+ } )
217
+ . catch ( failTest )
218
+ . then ( done ) ;
204
219
} ) ;
205
220
206
- it ( 'can handle case where aggregation array is missing' , function ( ) {
221
+ it ( 'can handle case where aggregation array is missing' , function ( done ) {
207
222
Plotly . newPlot ( gd , [ {
208
223
x : [ 1 , 2 , 3 , 4 , 5 ] ,
209
224
y : [ 2 , 4 , 6 , 8 , 10 ] ,
@@ -212,20 +227,23 @@ describe('aggregate', function() {
212
227
type : 'aggregate' ,
213
228
groups : 'marker.size'
214
229
} ]
215
- } ] ) ;
216
-
217
- var traceOut = gd . _fullData [ 0 ] ;
230
+ } ] )
231
+ . then ( function ( ) {
232
+ var traceOut = gd . _fullData [ 0 ] ;
218
233
219
- expect ( traceOut . x ) . toEqual ( [ 1 , 3 ] ) ;
220
- expect ( traceOut . y ) . toEqual ( [ 2 , 6 ] ) ;
221
- expect ( traceOut . marker . size ) . toEqual ( [ 10 , 20 ] ) ;
234
+ expect ( traceOut . x ) . toEqual ( [ 1 , 3 ] ) ;
235
+ expect ( traceOut . y ) . toEqual ( [ 2 , 6 ] ) ;
236
+ expect ( traceOut . marker . size ) . toEqual ( [ 10 , 20 ] ) ;
222
237
223
- var transform = traceOut . transforms [ 0 ] ;
224
- var inverseMapping = transform . _indexToPoints ;
225
- expect ( inverseMapping ) . toEqual ( { 0 : [ 0 , 1 , 4 ] , 1 : [ 2 , 3 ] } ) ;
238
+ var transform = traceOut . transforms [ 0 ] ;
239
+ var inverseMapping = transform . _indexToPoints ;
240
+ expect ( inverseMapping ) . toEqual ( { 0 : [ 0 , 1 , 4 ] , 1 : [ 2 , 3 ] } ) ;
241
+ } )
242
+ . catch ( failTest )
243
+ . then ( done ) ;
226
244
} ) ;
227
245
228
- it ( 'handles median, mode, rms, stddev, change & range for numeric data' , function ( ) {
246
+ it ( 'handles median, mode, rms, stddev, change & range for numeric data' , function ( done ) {
229
247
// again, nothing is going to barf with non-numeric data, but sometimes it
230
248
// won't make much sense.
231
249
@@ -252,22 +270,25 @@ describe('aggregate', function() {
252
270
{ target : 'marker.color' , func : 'stddev' }
253
271
]
254
272
} ]
255
- } ] ) ;
256
-
257
- var traceOut = gd . _fullData [ 0 ] ;
258
-
259
- // 1 and 2 both have count of 2 in the first group,
260
- // but 2 gets to that count first
261
- expect ( traceOut . x ) . toEqual ( [ 2 , 1 ] ) ;
262
- expect ( traceOut . y ) . toBeCloseToArray ( [ 3.5 , 2 ] , 5 ) ;
263
- expect ( traceOut . customdata ) . toEqual ( [ - 4 , 0 ] ) ;
264
- expect ( traceOut . marker . size ) . toBeCloseToArray ( [ Math . sqrt ( 51 / 4 ) , 2 ] , 5 ) ;
265
- expect ( traceOut . marker . opacity ) . toEqual ( [ 0.8 , 0 ] ) ;
266
- expect ( traceOut . marker . line . width ) . toBeCloseToArray ( [ 0.5 , 0 ] , 5 ) ;
267
- expect ( traceOut . marker . color ) . toBeCloseToArray ( [ Math . sqrt ( 1 / 3 ) , 0 ] , 5 ) ;
273
+ } ] )
274
+ . then ( function ( ) {
275
+ var traceOut = gd . _fullData [ 0 ] ;
276
+
277
+ // 1 and 2 both have count of 2 in the first group,
278
+ // but 2 gets to that count first
279
+ expect ( traceOut . x ) . toEqual ( [ 2 , 1 ] ) ;
280
+ expect ( traceOut . y ) . toBeCloseToArray ( [ 3.5 , 2 ] , 5 ) ;
281
+ expect ( traceOut . customdata ) . toEqual ( [ - 4 , 0 ] ) ;
282
+ expect ( traceOut . marker . size ) . toBeCloseToArray ( [ Math . sqrt ( 51 / 4 ) , 2 ] , 5 ) ;
283
+ expect ( traceOut . marker . opacity ) . toEqual ( [ 0.8 , 0 ] ) ;
284
+ expect ( traceOut . marker . line . width ) . toBeCloseToArray ( [ 0.5 , 0 ] , 5 ) ;
285
+ expect ( traceOut . marker . color ) . toBeCloseToArray ( [ Math . sqrt ( 1 / 3 ) , 0 ] , 5 ) ;
286
+ } )
287
+ . catch ( failTest )
288
+ . then ( done ) ;
268
289
} ) ;
269
290
270
- it ( 'handles ragged data - extra groups are ignored' , function ( ) {
291
+ it ( 'handles ragged data - extra groups are ignored' , function ( done ) {
271
292
Plotly . newPlot ( gd , [ {
272
293
x : [ 1 , 1 , 2 , 2 , 1 , 3 , 4 ] ,
273
294
y : [ 1 , 2 , 3 , 4 , 5 ] , // shortest array controls all
@@ -279,15 +300,18 @@ describe('aggregate', function() {
279
300
{ target : 'y' , func : 'median' } ,
280
301
]
281
302
} ]
282
- } ] ) ;
283
-
284
- var traceOut = gd . _fullData [ 0 ] ;
303
+ } ] )
304
+ . then ( function ( ) {
305
+ var traceOut = gd . _fullData [ 0 ] ;
285
306
286
- expect ( traceOut . x ) . toEqual ( [ 2 , 1 ] ) ;
287
- expect ( traceOut . y ) . toBeCloseToArray ( [ 3.5 , 2 ] , 5 ) ;
307
+ expect ( traceOut . x ) . toEqual ( [ 2 , 1 ] ) ;
308
+ expect ( traceOut . y ) . toBeCloseToArray ( [ 3.5 , 2 ] , 5 ) ;
309
+ } )
310
+ . catch ( failTest )
311
+ . then ( done ) ;
288
312
} ) ;
289
313
290
- it ( 'handles ragged data - groups is the shortest, others are ignored' , function ( ) {
314
+ it ( 'handles ragged data - groups is the shortest, others are ignored' , function ( done ) {
291
315
Plotly . newPlot ( gd , [ {
292
316
x : [ 1 , 1 , 2 , 2 , 1 , 3 , 4 ] ,
293
317
y : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ,
@@ -299,15 +323,18 @@ describe('aggregate', function() {
299
323
{ target : 'y' , func : 'median' } ,
300
324
]
301
325
} ]
302
- } ] ) ;
303
-
304
- var traceOut = gd . _fullData [ 0 ] ;
326
+ } ] )
327
+ . then ( function ( ) {
328
+ var traceOut = gd . _fullData [ 0 ] ;
305
329
306
- expect ( traceOut . x ) . toEqual ( [ 2 , 1 ] ) ;
307
- expect ( traceOut . y ) . toBeCloseToArray ( [ 3.5 , 2 ] , 5 ) ;
330
+ expect ( traceOut . x ) . toEqual ( [ 2 , 1 ] ) ;
331
+ expect ( traceOut . y ) . toBeCloseToArray ( [ 3.5 , 2 ] , 5 ) ;
332
+ } )
333
+ . catch ( failTest )
334
+ . then ( done ) ;
308
335
} ) ;
309
336
310
- it ( 'links fullData aggregations to userData via _index' , function ( ) {
337
+ it ( 'links fullData aggregations to userData via _index' , function ( done ) {
311
338
Plotly . newPlot ( gd , [ {
312
339
x : [ 1 , 2 , 3 , 4 , 5 ] ,
313
340
y : [ 2 , 4 , 6 , 8 , 10 ] ,
@@ -324,23 +351,26 @@ describe('aggregate', function() {
324
351
{ target : 'y' , func : 'avg' }
325
352
]
326
353
} ]
327
- } ] ) ;
328
-
329
- var traceOut = gd . _fullData [ 0 ] ;
330
- var fullAggregation = traceOut . transforms [ 0 ] ;
331
- var fullAggregations = fullAggregation . aggregations ;
332
- var enabledAggregations = fullAggregations . filter ( function ( agg ) {
333
- return agg . enabled ;
334
- } ) ;
354
+ } ] )
355
+ . then ( function ( ) {
356
+ var traceOut = gd . _fullData [ 0 ] ;
357
+ var fullAggregation = traceOut . transforms [ 0 ] ;
358
+ var fullAggregations = fullAggregation . aggregations ;
359
+ var enabledAggregations = fullAggregations . filter ( function ( agg ) {
360
+ return agg . enabled ;
361
+ } ) ;
335
362
336
- expect ( enabledAggregations [ 0 ] . target ) . toEqual ( 'x' ) ;
337
- expect ( enabledAggregations [ 0 ] . _index ) . toEqual ( 0 ) ;
363
+ expect ( enabledAggregations [ 0 ] . target ) . toEqual ( 'x' ) ;
364
+ expect ( enabledAggregations [ 0 ] . _index ) . toEqual ( 0 ) ;
338
365
339
- expect ( enabledAggregations [ 1 ] . target ) . toEqual ( 'y' ) ;
340
- expect ( enabledAggregations [ 1 ] . _index ) . toEqual ( 2 ) ;
366
+ expect ( enabledAggregations [ 1 ] . target ) . toEqual ( 'y' ) ;
367
+ expect ( enabledAggregations [ 1 ] . _index ) . toEqual ( 2 ) ;
341
368
342
- expect ( enabledAggregations [ 2 ] . target ) . toEqual ( 'marker.color' ) ;
343
- expect ( enabledAggregations [ 2 ] . _index ) . toEqual ( - 1 ) ;
369
+ expect ( enabledAggregations [ 2 ] . target ) . toEqual ( 'marker.color' ) ;
370
+ expect ( enabledAggregations [ 2 ] . _index ) . toEqual ( - 1 ) ;
371
+ } )
372
+ . catch ( failTest )
373
+ . then ( done ) ;
344
374
} ) ;
345
375
346
376
it ( 'does not error out on bad *group* value' , function ( done ) {
@@ -361,7 +391,7 @@ describe('aggregate', function() {
361
391
. then ( done ) ;
362
392
} ) ;
363
393
364
- it ( 'use numeric sort function for median' , function ( ) {
394
+ it ( 'use numeric sort function for median' , function ( done ) {
365
395
var subject = [ 'M' , 'M' , 'M' ] ;
366
396
var score = [ 2 , 10 , 11 ] ;
367
397
@@ -383,6 +413,8 @@ describe('aggregate', function() {
383
413
. then ( function ( ) {
384
414
var traceOut = gd . _fullData [ 0 ] ;
385
415
expect ( traceOut . y [ 0 ] ) . toBe ( 10 ) ;
386
- } ) ;
416
+ } )
417
+ . catch ( failTest )
418
+ . then ( done ) ;
387
419
} ) ;
388
420
} ) ;
0 commit comments