Skip to content

Commit 6fb2871

Browse files
committed
plotly#189 adding test cases for trace lines with mutually exclusive category sets
1 parent 82076f2 commit 6fb2871

File tree

1 file changed

+132
-11
lines changed

1 file changed

+132
-11
lines changed

test/jasmine/tests/calcdata_test.js

+132-11
Original file line numberDiff line numberDiff line change
@@ -291,24 +291,19 @@ describe('calculated data and points', function() {
291291
});
292292
});
293293

294-
describe('ordering tests in the presence of multiple traces', function() {
294+
describe('ordering tests in the presence of multiple traces - mutually exclusive', function() {
295295

296296
it('baseline testing for the unordered, disjunct case', function() {
297297

298298
var x1 = ['Gear', 'Bearing', 'Motor'];
299299
var x2 = ['Switch', 'Plug', 'Cord', 'Fuse', 'Bulb'];
300300
var x3 = ['Pump', 'Leak', 'Seals'];
301301

302-
Plotly.plot(gd, [{
303-
x: x1,
304-
y: x1.map(function(d, i) {return i + 10;})
305-
}, {
306-
x: x2,
307-
y: x2.map(function(d, i) {return i + 20;})
308-
}, {
309-
x: x3,
310-
y: x3.map(function(d, i) {return i + 30;})
311-
}]);
302+
Plotly.plot(gd, [
303+
{x: x1, y: x1.map(function(d, i) {return i + 10;})},
304+
{x: x2, y: x2.map(function(d, i) {return i + 20;})},
305+
{x: x3, y: x3.map(function(d, i) {return i + 30;})}
306+
]);
312307

313308
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 0, y: 10}));
314309
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 1, y: 11}));
@@ -325,6 +320,132 @@ describe('calculated data and points', function() {
325320
expect(gd.calcdata[2][2]).toEqual(jasmine.objectContaining({x: 10, y: 32}));
326321
});
327322

323+
it('category order follows the trace order (even if categorylist is specified)', function() {
324+
325+
var x1 = ['Gear', 'Bearing', 'Motor'];
326+
var x2 = ['Switch', 'Plug', 'Cord', 'Fuse', 'Bulb'];
327+
var x3 = ['Pump', 'Leak', 'Seals'];
328+
329+
Plotly.plot(gd, [
330+
{x: x1, y: x1.map(function(d, i) {return i + 10;})},
331+
{x: x2, y: x2.map(function(d, i) {return i + 20;})},
332+
{x: x3, y: x3.map(function(d, i) {return i + 30;})}
333+
], { xaxis: {
334+
// type: 'category', // commented out to rely on autotyping for added realism
335+
categorymode: 'trace',
336+
categorylist: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak']
337+
}});
338+
339+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 0, y: 10}));
340+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 1, y: 11}));
341+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 2, y: 12}));
342+
343+
expect(gd.calcdata[1][0]).toEqual(jasmine.objectContaining({x: 3, y: 20}));
344+
expect(gd.calcdata[1][1]).toEqual(jasmine.objectContaining({x: 4, y: 21}));
345+
expect(gd.calcdata[1][2]).toEqual(jasmine.objectContaining({x: 5, y: 22}));
346+
expect(gd.calcdata[1][3]).toEqual(jasmine.objectContaining({x: 6, y: 23}));
347+
expect(gd.calcdata[1][4]).toEqual(jasmine.objectContaining({x: 7, y: 24}));
348+
349+
expect(gd.calcdata[2][0]).toEqual(jasmine.objectContaining({x: 8, y: 30}));
350+
expect(gd.calcdata[2][1]).toEqual(jasmine.objectContaining({x: 9, y: 31}));
351+
expect(gd.calcdata[2][2]).toEqual(jasmine.objectContaining({x: 10, y: 32}));
352+
});
353+
354+
it('category order is category ascending (even if categorylist is specified)', function() {
355+
356+
var x1 = ['Gear', 'Bearing', 'Motor'];
357+
var x2 = ['Switch', 'Plug', 'Cord', 'Fuse', 'Bulb'];
358+
var x3 = ['Pump', 'Leak', 'Seals'];
359+
360+
Plotly.plot(gd, [
361+
{x: x1, y: x1.map(function(d, i) {return i + 10;})},
362+
{x: x2, y: x2.map(function(d, i) {return i + 20;})},
363+
{x: x3, y: x3.map(function(d, i) {return i + 30;})}
364+
], { xaxis: {
365+
// type: 'category', // commented out to rely on autotyping for added realism
366+
categorymode: 'category ascending',
367+
categorylist: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak']
368+
// this is the expected sorted outcome: ['Bearing','Bulb','Cord','Fuse','Gear','Leak','Motor','Plug','Pump','Seals','Switch']
369+
}});
370+
371+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 4, y: 10}));
372+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 0, y: 11}));
373+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 6, y: 12}));
374+
375+
expect(gd.calcdata[1][0]).toEqual(jasmine.objectContaining({x: 10, y: 20}));
376+
expect(gd.calcdata[1][1]).toEqual(jasmine.objectContaining({x: 7, y: 21}));
377+
expect(gd.calcdata[1][2]).toEqual(jasmine.objectContaining({x: 2, y: 22}));
378+
expect(gd.calcdata[1][3]).toEqual(jasmine.objectContaining({x: 3, y: 23}));
379+
expect(gd.calcdata[1][4]).toEqual(jasmine.objectContaining({x: 1, y: 24}));
380+
381+
expect(gd.calcdata[2][0]).toEqual(jasmine.objectContaining({x: 8, y: 30}));
382+
expect(gd.calcdata[2][1]).toEqual(jasmine.objectContaining({x: 5, y: 31}));
383+
expect(gd.calcdata[2][2]).toEqual(jasmine.objectContaining({x: 9, y: 32}));
384+
});
385+
386+
it('category order is category descending (even if categorylist is specified)', function() {
387+
388+
var x1 = ['Gear', 'Bearing', 'Motor'];
389+
var x2 = ['Switch', 'Plug', 'Cord', 'Fuse', 'Bulb'];
390+
var x3 = ['Pump', 'Leak', 'Seals'];
391+
392+
Plotly.plot(gd, [
393+
{x: x1, y: x1.map(function(d, i) {return i + 10;})},
394+
{x: x2, y: x2.map(function(d, i) {return i + 20;})},
395+
{x: x3, y: x3.map(function(d, i) {return i + 30;})}
396+
], { xaxis: {
397+
// type: 'category', // commented out to rely on autotyping for added realism
398+
categorymode: 'category descending',
399+
categorylist: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak']
400+
// this is the expected sorted outcome: ["Switch", "Seals", "Pump", "Plug", "Motor", "Leak", "Gear", "Fuse", "Cord", "Bulb", "Bearing"]
401+
}});
402+
403+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 6, y: 10}));
404+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 10, y: 11}));
405+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 4, y: 12}));
406+
407+
expect(gd.calcdata[1][0]).toEqual(jasmine.objectContaining({x: 0, y: 20}));
408+
expect(gd.calcdata[1][1]).toEqual(jasmine.objectContaining({x: 3, y: 21}));
409+
expect(gd.calcdata[1][2]).toEqual(jasmine.objectContaining({x: 8, y: 22}));
410+
expect(gd.calcdata[1][3]).toEqual(jasmine.objectContaining({x: 7, y: 23}));
411+
expect(gd.calcdata[1][4]).toEqual(jasmine.objectContaining({x: 9, y: 24}));
412+
413+
expect(gd.calcdata[2][0]).toEqual(jasmine.objectContaining({x: 2, y: 30}));
414+
expect(gd.calcdata[2][1]).toEqual(jasmine.objectContaining({x: 5, y: 31}));
415+
expect(gd.calcdata[2][2]).toEqual(jasmine.objectContaining({x: 1, y: 32}));
416+
});
417+
418+
it('category order follows categorylist', function() {
419+
420+
var x1 = ['Gear', 'Bearing', 'Motor'];
421+
var x2 = ['Switch', 'Plug', 'Cord', 'Fuse', 'Bulb'];
422+
var x3 = ['Pump', 'Leak', 'Seals'];
423+
424+
Plotly.plot(gd, [
425+
{x: x1, y: x1.map(function(d, i) {return i + 10;})},
426+
{x: x2, y: x2.map(function(d, i) {return i + 20;})},
427+
{x: x3, y: x3.map(function(d, i) {return i + 30;})}
428+
], { xaxis: {
429+
// type: 'category', // commented out to rely on autotyping for added realism
430+
categorymode: 'array',
431+
categorylist: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak']
432+
}});
433+
434+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 9, y: 10}));
435+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 1, y: 11}));
436+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 2, y: 12}));
437+
438+
expect(gd.calcdata[1][0]).toEqual(jasmine.objectContaining({x: 0, y: 20}));
439+
expect(gd.calcdata[1][1]).toEqual(jasmine.objectContaining({x: 6, y: 21}));
440+
expect(gd.calcdata[1][2]).toEqual(jasmine.objectContaining({x: 5, y: 22}));
441+
expect(gd.calcdata[1][3]).toEqual(jasmine.objectContaining({x: 8, y: 23}));
442+
expect(gd.calcdata[1][4]).toEqual(jasmine.objectContaining({x: 7, y: 24}));
443+
444+
expect(gd.calcdata[2][0]).toEqual(jasmine.objectContaining({x: 4, y: 30}));
445+
expect(gd.calcdata[2][1]).toEqual(jasmine.objectContaining({x: 10, y: 31}));
446+
expect(gd.calcdata[2][2]).toEqual(jasmine.objectContaining({x: 3, y: 32}));
447+
});
328448
});
449+
329450
});
330451
});

0 commit comments

Comments
 (0)