@@ -182,4 +182,173 @@ describe('groupby', function() {
182
182
183
183
} ) ;
184
184
185
+ // these tests can be shortened, once the meaning of edge cases gets clarified
186
+ describe ( 'symmetry/degeneracy testing of one-to-many transforms on arbitrary arrays where there is no grouping (implicit 1):' , function ( ) {
187
+ 'use strict' ;
188
+
189
+ var mockData = [ {
190
+ mode : 'markers' ,
191
+ x : [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ,
192
+ y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ,
193
+
194
+ // everything is present:
195
+ transforms : [ {
196
+ type : 'groupby' ,
197
+ groups : [ 'a' , 'a' , 'b' , 'a' , 'b' , 'b' , 'a' ] ,
198
+ style : { a : { marker : { color : 'red' } } , b : { marker : { color : 'blue' } } }
199
+ } ]
200
+ } ] ;
201
+
202
+ var mockData0 = [ {
203
+ mode : 'markers' ,
204
+ x : [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ,
205
+ y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ,
206
+
207
+ // groups, styles not present
208
+ transforms : [ {
209
+ type : 'groupby'
210
+ // groups not present
211
+ // styles not present
212
+ } ]
213
+ } ] ;
214
+
215
+ // transform attribute with empty list
216
+ var mockData1 = [ {
217
+ mode : 'markers' ,
218
+ x : [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ,
219
+ y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ,
220
+
221
+ // transforms is present but there are no items in it
222
+ transforms : [ /* list is empty */ ]
223
+ } ] ;
224
+
225
+ // transform attribute with null value
226
+ var mockData2 = [ {
227
+ mode : 'markers' ,
228
+ x : [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ,
229
+ y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ,
230
+ transforms : null
231
+ } ] ;
232
+
233
+ // no transform is present at all
234
+ var mockData3 = [ {
235
+ mode : 'markers' ,
236
+ x : [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ,
237
+ y : [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ]
238
+ } ] ;
239
+
240
+ afterEach ( destroyGraphDiv ) ;
241
+
242
+ it ( 'Plotly.plot should plot the transform traces' , function ( done ) {
243
+ var data = Lib . extendDeep ( [ ] , mockData ) ;
244
+
245
+ var gd = createGraphDiv ( ) ;
246
+
247
+ Plotly . plot ( gd , data ) . then ( function ( ) {
248
+ expect ( gd . data . length ) . toEqual ( 1 ) ;
249
+ expect ( gd . data [ 0 ] . x ) . toEqual ( [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
250
+ expect ( gd . data [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
251
+
252
+ expect ( gd . _fullData . length ) . toEqual ( 2 ) ; // two groups
253
+ expect ( gd . _fullData [ 0 ] . x ) . toEqual ( [ 1 , - 1 , 0 , 3 ] ) ;
254
+ expect ( gd . _fullData [ 0 ] . y ) . toEqual ( [ 1 , 2 , 1 , 1 ] ) ;
255
+ expect ( gd . _fullData [ 1 ] . x ) . toEqual ( [ - 2 , 1 , 2 ] ) ;
256
+ expect ( gd . _fullData [ 1 ] . y ) . toEqual ( [ 3 , 2 , 3 ] ) ;
257
+
258
+ assertDims ( [ 4 , 3 ] ) ;
259
+
260
+ done ( ) ;
261
+ } ) ;
262
+ } ) ;
263
+
264
+ // passes; maybe not for the good reasons (see fixme comments)
265
+ it ( 'Plotly.plot should plot the transform traces' , function ( done ) {
266
+ var data = Lib . extendDeep ( [ ] , mockData0 ) ;
267
+
268
+ var gd = createGraphDiv ( ) ;
269
+
270
+ Plotly . plot ( gd , data ) . then ( function ( ) {
271
+ expect ( gd . data . length ) . toEqual ( 1 ) ;
272
+ expect ( gd . data [ 0 ] . x ) . toEqual ( [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
273
+ expect ( gd . data [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
274
+
275
+ expect ( gd . _fullData . length ) . toEqual ( 0 ) ; // fixme: it passes with 0; shouldn't it be 1? (one implied group)
276
+
277
+ /* since the array is of zero length, the below items are obv. meaningless to test
278
+ expect(gd._fullData[0].x).toEqual([1, -1, -2, 0, 1, 2, 3]);
279
+ expect(gd._fullData[0].y).toEqual([1, 2, 3, 1, 2, 3, 1]);
280
+ */
281
+
282
+ assertDims ( [ ] ) ; // fixme: same thing, looks like zero dimensionality
283
+
284
+ done ( ) ;
285
+ } ) ;
286
+ } ) ;
287
+
288
+ // passes; looks OK
289
+ it ( 'Plotly.plot should plot the transform traces' , function ( done ) {
290
+ var data = Lib . extendDeep ( [ ] , mockData1 ) ;
291
+
292
+ var gd = createGraphDiv ( ) ;
293
+
294
+ Plotly . plot ( gd , data ) . then ( function ( ) {
295
+ expect ( gd . data . length ) . toEqual ( 1 ) ;
296
+ expect ( gd . data [ 0 ] . x ) . toEqual ( [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
297
+ expect ( gd . data [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
298
+
299
+ expect ( gd . _fullData . length ) . toEqual ( 1 ) ; // fixme not: good, okay it's 1 here (one implied group / thing)
300
+ expect ( gd . _fullData [ 0 ] . x ) . toEqual ( [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
301
+ expect ( gd . _fullData [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
302
+
303
+ assertDims ( [ 7 ] ) ;
304
+
305
+ done ( ) ;
306
+ } ) ;
307
+ } ) ;
308
+
309
+ // passes OK; see todo comments
310
+ it ( 'Plotly.plot should plot the transform traces' , function ( done ) {
311
+ var data = Lib . extendDeep ( [ ] , mockData2 ) ;
312
+
313
+ var gd = createGraphDiv ( ) ;
314
+
315
+ Plotly . plot ( gd , data ) . then ( function ( ) {
316
+ expect ( gd . data . length ) . toEqual ( 1 ) ;
317
+ expect ( gd . data [ 0 ] . x ) . toEqual ( [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
318
+ expect ( gd . data [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
319
+
320
+ expect ( gd . _fullData . length ) . toEqual ( 1 ) ; // todo: confirm this result is OK
321
+
322
+ expect ( gd . _fullData [ 0 ] . x ) . toEqual ( [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
323
+ expect ( gd . _fullData [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
324
+
325
+ assertDims ( [ 7 ] ) ; // todo: confirm this result is OK
326
+
327
+ done ( ) ;
328
+ } ) ;
329
+ } ) ;
330
+
331
+ // passes OK; see todo comments
332
+ it ( 'Plotly.plot should plot the transform traces' , function ( done ) {
333
+ var data = Lib . extendDeep ( [ ] , mockData3 ) ;
334
+
335
+ var gd = createGraphDiv ( ) ;
336
+
337
+ Plotly . plot ( gd , data ) . then ( function ( ) {
338
+ expect ( gd . data . length ) . toEqual ( 1 ) ;
339
+ expect ( gd . data [ 0 ] . x ) . toEqual ( [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
340
+ expect ( gd . data [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
341
+
342
+ expect ( gd . _fullData . length ) . toEqual ( 1 ) ; // todo: confirm this result is OK
343
+
344
+ expect ( gd . _fullData [ 0 ] . x ) . toEqual ( [ 1 , - 1 , - 2 , 0 , 1 , 2 , 3 ] ) ;
345
+ expect ( gd . _fullData [ 0 ] . y ) . toEqual ( [ 1 , 2 , 3 , 1 , 2 , 3 , 1 ] ) ;
346
+
347
+ assertDims ( [ 7 ] ) ; // todo: confirm this result is OK
348
+
349
+ done ( ) ;
350
+ } ) ;
351
+ } ) ;
352
+ } ) ;
353
+
185
354
} ) ;
0 commit comments