Skip to content

Commit 4434fad

Browse files
committed
add test case 🔒 axis categories in x/y/z column heatmaps
1 parent 071249f commit 4434fad

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

test/jasmine/tests/heatmap_test.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ describe('heatmap convertColumnXYZ', function() {
168168
};
169169
}
170170

171-
var xa = makeMockAxis(),
172-
ya = makeMockAxis();
171+
var xa = makeMockAxis();
172+
var ya = makeMockAxis();
173173

174174
it('should convert x/y/z columns to z(x,y)', function() {
175175
trace = {
@@ -305,8 +305,13 @@ describe('heatmap calc', function() {
305305

306306
Plots.supplyDefaults(gd);
307307
var fullTrace = gd._fullData[0];
308+
var fullLayout = gd._fullLayout;
308309

309-
return Heatmap.calc(gd, fullTrace)[0];
310+
var out = Heatmap.calc(gd, fullTrace)[0];
311+
out._xcategories = fullLayout.xaxis._categories;
312+
out._ycategories = fullLayout.yaxis._categories;
313+
314+
return out;
310315
}
311316

312317
it('should fill in bricks if x/y not given', function() {
@@ -404,6 +409,25 @@ describe('heatmap calc', function() {
404409
expect(out.y).toBeCloseToArray([-0.5, 0.5]);
405410
expect(out.z).toBeCloseTo2DArray([[17, 18, 19]]);
406411
});
412+
413+
it('should handle the category x/y/z/ column case', function() {
414+
var out = _calc({
415+
x: ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c'],
416+
y: ['A', 'B', 'C', 'A', 'B', 'C', 'A', 'B', 'C'],
417+
z: [0, 50, 100, 50, 0, 255, 100, 510, 1010]
418+
});
419+
420+
expect(out.x).toBeCloseToArray([-0.5, 0.5, 1.5, 2.5]);
421+
expect(out.y).toBeCloseToArray([-0.5, 0.5, 1.5, 2.5]);
422+
expect(out.z).toBeCloseTo2DArray([
423+
[0, 50, 100],
424+
[50, 0, 510],
425+
[100, 255, 1010]
426+
]);
427+
428+
expect(out._xcategories).toEqual(['a', 'b', 'c']);
429+
expect(out._ycategories).toEqual(['A', 'B', 'C']);
430+
});
407431
});
408432

409433
describe('heatmap plot', function() {

0 commit comments

Comments
 (0)