Skip to content

Commit 89794c6

Browse files
committed
plotly#189 adding test cases for combinations of category ordering and stacking (aggregated y value correspondence check)
1 parent 616121b commit 89794c6

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

test/jasmine/tests/calcdata_test.js

+70
Original file line numberDiff line numberDiff line change
@@ -788,5 +788,75 @@ describe('calculated data and points', function() {
788788
expect(gd.calcdata[2][2]).toEqual(jasmine.objectContaining({x: 1, y: 32}));
789789
});
790790
});
791+
792+
describe('ordering and stacking combined', function() {
793+
794+
it('partially overlapping category order follows categorylist and stacking produces expected results', function() {
795+
796+
var x1 = ['Gear', 'Bearing', 'Motor'];
797+
var x2 = ['Switch', 'Plug', 'Cord', 'Fuse', 'Bulb'];
798+
var x3 = ['Pump', 'Leak', 'Bearing', 'Seals'];
799+
800+
Plotly.plot(gd, [
801+
{x: x1, y: x1.map(function(d, i) {return i + 10;}), type: 'bar'},
802+
{x: x2, y: x2.map(function(d, i) {return i + 20;}), type: 'bar'},
803+
{x: x3, y: x3.map(function(d, i) {return i + 30;}), type: 'bar'}
804+
], {
805+
barmode: 'stack',
806+
xaxis: {
807+
// type: 'category', // commented out to rely on autotyping for added realism
808+
categorymode: 'array',
809+
categorylist: ['Switch','Bearing','Motor','Seals','Pump','Cord','Plug','Bulb','Fuse','Gear','Leak']
810+
}
811+
});
812+
813+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 9, y: 10}));
814+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 1, y: 11}));
815+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 2, y: 12}));
816+
817+
expect(gd.calcdata[1][0]).toEqual(jasmine.objectContaining({x: 0, y: 20}));
818+
expect(gd.calcdata[1][1]).toEqual(jasmine.objectContaining({x: 6, y: 21}));
819+
expect(gd.calcdata[1][2]).toEqual(jasmine.objectContaining({x: 5, y: 22}));
820+
expect(gd.calcdata[1][3]).toEqual(jasmine.objectContaining({x: 8, y: 23}));
821+
expect(gd.calcdata[1][4]).toEqual(jasmine.objectContaining({x: 7, y: 24}));
822+
823+
expect(gd.calcdata[2][0]).toEqual(jasmine.objectContaining({x: 4, y: 30}));
824+
expect(gd.calcdata[2][1]).toEqual(jasmine.objectContaining({x: 10, y: 31}));
825+
expect(gd.calcdata[2][2]).toEqual(jasmine.objectContaining({x: 1, y: 11 + 32}));
826+
expect(gd.calcdata[2][3]).toEqual(jasmine.objectContaining({x: 3, y: 33}));
827+
})
828+
829+
it('fully overlapping - category order follows categorylist and stacking produces expected results', function() {
830+
831+
var x1 = ['Gear', 'Bearing', 'Motor'];
832+
var x2 = ['Bearing', 'Gear', 'Motor'];
833+
var x3 = ['Motor', 'Gear', 'Bearing'];
834+
835+
Plotly.plot(gd, [
836+
{x: x1, y: x1.map(function(d, i) {return i + 10;}), type: 'bar'},
837+
{x: x2, y: x2.map(function(d, i) {return i + 20;}), type: 'bar'},
838+
{x: x3, y: x3.map(function(d, i) {return i + 30;}), type: 'bar'}
839+
], {
840+
barmode: 'stack',
841+
xaxis: {
842+
// type: 'category', // commented out to rely on autotyping for added realism
843+
categorymode: 'array',
844+
categorylist: ['Bearing','Motor','Gear']
845+
}
846+
});
847+
848+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 2, y: 10}));
849+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 0, y: 11}));
850+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 1, y: 12}));
851+
852+
expect(gd.calcdata[1][0]).toEqual(jasmine.objectContaining({x: 0, y: 11 + 20}));
853+
expect(gd.calcdata[1][1]).toEqual(jasmine.objectContaining({x: 2, y: 10 + 21}));
854+
expect(gd.calcdata[1][2]).toEqual(jasmine.objectContaining({x: 1, y: 12 + 22}));
855+
856+
expect(gd.calcdata[2][0]).toEqual(jasmine.objectContaining({x: 1, y: 12 + 22 + 30}));
857+
expect(gd.calcdata[2][1]).toEqual(jasmine.objectContaining({x: 2, y: 10 + 21 + 31}));
858+
expect(gd.calcdata[2][2]).toEqual(jasmine.objectContaining({x: 0, y: 11 + 20 + 32}));
859+
});
860+
});
791861
});
792862
});

0 commit comments

Comments
 (0)