Skip to content

Commit 462b2f0

Browse files
committed
test heterogeneous attributes, deep nesting and overridden attributes
1 parent 55f9e0c commit 462b2f0

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

test/jasmine/tests/transform_groupby_test.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,119 @@ describe('groupby', function() {
351351
});
352352
});
353353

354+
describe('grouping with basic, heterogenous and overridden attributes', function() {
355+
'use strict';
356+
357+
afterEach(destroyGraphDiv);
358+
359+
function test(mockData) {
360+
361+
return function(done) {
362+
var data = Lib.extendDeep([], mockData);
363+
364+
var gd = createGraphDiv();
365+
366+
Plotly.plot(gd, data).then(function() {
367+
368+
expect(gd.data.length).toEqual(1);
369+
expect(gd.data[0].x).toEqual([1, -1, -2, 0, 1, 2, 3]);
370+
expect(gd.data[0].y).toEqual([0, 1, 2, 3, 5, 4, 6]);
371+
372+
expect(gd._fullData.length).toEqual(2);
373+
expect(gd._fullData[0].x).toEqual([1, -1, 0, 3]);
374+
expect(gd._fullData[0].y).toEqual([0, 1, 3, 6]);
375+
expect(gd._fullData[1].x).toEqual([-2, 1, 2]);
376+
expect(gd._fullData[1].y).toEqual([2, 5, 4]);
377+
378+
assertDims([4, 3]);
379+
380+
done();
381+
});
382+
};
383+
}
384+
385+
// basic test
386+
var mockData1 = [{
387+
mode: 'markers',
388+
x: [1, -1, -2, 0, 1, 2, 3],
389+
y: [0, 1, 2, 3, 5, 4, 6],
390+
transforms: [{
391+
type: 'groupby',
392+
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'],
393+
style: { a: {marker: {color: 'red'}}, b: {marker: {color: 'blue'}} }
394+
}]
395+
}];
396+
397+
// heterogenously present attributes
398+
var mockData2 = [{
399+
mode: 'markers',
400+
x: [1, -1, -2, 0, 1, 2, 3],
401+
y: [0, 1, 2, 3, 5, 4, 6],
402+
transforms: [{
403+
type: 'groupby',
404+
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'],
405+
style: {
406+
a: {
407+
marker: {
408+
color: 'orange',
409+
size: 20,
410+
line: {
411+
color: 'red',
412+
width: 1
413+
}
414+
}
415+
},
416+
b: {
417+
mode: 'markers+lines', // heterogeonos attributes are OK: group "a" doesn't need to define this
418+
marker: {
419+
color: 'cyan',
420+
size: 15,
421+
line: {
422+
color: 'purple',
423+
width: 4
424+
},
425+
opacity: 0.5,
426+
symbol: 'triangle-up'
427+
},
428+
line: {
429+
width: 1,
430+
color: 'purple'
431+
}
432+
}
433+
}
434+
}]
435+
}];
436+
437+
// attributes set at top level and partially overridden in the group item level
438+
var mockData3 = [{
439+
mode: 'markers+lines',
440+
x: [1, -1, -2, 0, 1, 2, 3],
441+
y: [0, 1, 2, 3, 5, 4, 6],
442+
marker: {
443+
color: 'darkred', // general "default" color
444+
line: {
445+
width: 8,
446+
// a general, not overridden array will be interpreted per group
447+
color: ['orange', 'red', 'green', 'cyan']
448+
}
449+
},
450+
line: {color: 'red'},
451+
transforms: [{
452+
type: 'groupby',
453+
groups: ['a', 'a', 'b', 'a', 'b', 'b', 'a'],
454+
style: {
455+
a: {marker: {size: 30}},
456+
// override general color:
457+
b: {marker: {size: 15, color: 'lightblue'}, line: {color: 'purple'}}
458+
}
459+
}]
460+
}];
461+
462+
// this passes OK as expected
463+
it('`data` preserves user supplied input but `gd._fullData` reflects the grouping', test(mockData1));
464+
it('passes with lots of attributes and heterogenous attrib presence', test(mockData2));
465+
it('passes with group styles partially overriding top level aesthetics', test(mockData3));
466+
467+
});
468+
354469
});

0 commit comments

Comments
 (0)