Skip to content

Commit b1892ce

Browse files
committed
make 'categoryorder' / 'categoryarray' relayouts recompute calcdata:
- part two in fixing the category relayout bug. - update the axis categories require a re-computation of the graphs calcdata.
1 parent 460e53a commit b1892ce

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/plot_api/plot_api.js

+6
Original file line numberDiff line numberDiff line change
@@ -2211,6 +2211,12 @@ Plotly.relayout = function relayout(gd, astr, val) {
22112211
else if(/[xy]axis[0-9]*?$/.test(pleaf) && !Object.keys(vi || {}).length) {
22122212
docalc = true;
22132213
}
2214+
else if(/[xy]axis[0-9]*\.categoryorder$/.test(pleafPlus)) {
2215+
docalc = true;
2216+
}
2217+
else if(/[xy]axis[0-9]*\.categoryarray/.test(pleafPlus)) {
2218+
docalc = true;
2219+
}
22142220

22152221
if(pleafPlus.indexOf('rangeslider') !== -1) {
22162222
docalc = true;

test/jasmine/tests/cartesian_test.js

+54
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,57 @@ describe('zoom box element', function() {
4949
.toEqual(0);
5050
});
5151
});
52+
53+
describe('relayout', function() {
54+
55+
describe('axis category attributes', function() {
56+
var mock = require('@mocks/basic_bar.json');
57+
58+
var gd, mockCopy;
59+
60+
beforeEach(function() {
61+
mockCopy = Lib.extendDeep({}, mock);
62+
gd = createGraphDiv();
63+
});
64+
65+
afterEach(destroyGraphDiv);
66+
67+
it('should response to \'categoryarray\' and \'categoryorder\' updates', function(done) {
68+
function assertCategories(list) {
69+
d3.selectAll('g.xtick').each(function(_, i) {
70+
var tick = d3.select(this).select('text');
71+
expect(tick.html()).toEqual(list[i]);
72+
});
73+
}
74+
75+
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(function() {
76+
assertCategories(['giraffes', 'orangutans', 'monkeys']);
77+
78+
return Plotly.relayout(gd, 'xaxis.categoryorder', 'category descending');
79+
}).then(function() {
80+
var list = ['orangutans', 'monkeys', 'giraffes'];
81+
82+
expect(gd._fullLayout.xaxis._initialCategories).toEqual(list);
83+
assertCategories(list);
84+
85+
return Plotly.relayout(gd, 'xaxis.categoryorder', null);
86+
}).then(function() {
87+
assertCategories(['giraffes', 'orangutans', 'monkeys']);
88+
89+
return Plotly.relayout(gd, {
90+
'xaxis.categoryarray': ['monkeys', 'giraffes', 'orangutans']
91+
});
92+
}).then(function() {
93+
var list = ['monkeys', 'giraffes', 'orangutans'];
94+
95+
expect(gd.layout.xaxis.categoryarray).toEqual(list);
96+
expect(gd._fullLayout.xaxis.categoryarray).toEqual(list);
97+
expect(gd._fullLayout.xaxis._initialCategories).toEqual(list);
98+
assertCategories(list);
99+
100+
done();
101+
});
102+
});
103+
});
104+
105+
});

0 commit comments

Comments
 (0)