Skip to content

Commit 7176e7a

Browse files
committed
autotype booleans as categories
1 parent b02221f commit 7176e7a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Diff for: src/plots/cartesian/axis_autotype.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ function category(a) {
6565

6666
for(var i = 0; i < a.length; i += inc) {
6767
ai = a[Math.round(i)];
68-
if(Lib.cleanNumber(ai) !== BADNUM) curvenums++;
68+
if(typeof ai === 'boolean') curvecats++;
69+
else if(Lib.cleanNumber(ai) !== BADNUM) curvenums++;
6970
else if(typeof ai === 'string' && ai !== '' && ai !== 'None') curvecats++;
7071
}
7172

Diff for: test/jasmine/tests/axes_test.js

+16
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,22 @@ describe('Test axes', function() {
189189
fullData = [];
190190
});
191191

192+
describe('autotype', function() {
193+
function fullTrace(mods) {
194+
return Lib.extendDeep(
195+
{type: 'scatter', xaxis: 'x', yaxis: 'y'},
196+
mods
197+
);
198+
}
199+
it('treats booleans as categories', function() {
200+
fullData = [fullTrace({x: [0, 1, 2], y: [true, false, true]})];
201+
layoutIn = {xaxis: {}, yaxis: {}};
202+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
203+
expect(layoutOut.xaxis.type).toBe('linear');
204+
expect(layoutOut.yaxis.type).toBe('category');
205+
});
206+
});
207+
192208
it('should set undefined linewidth/linecolor if linewidth, linecolor or showline is not supplied', function() {
193209
layoutIn = {
194210
xaxis: {},

0 commit comments

Comments
 (0)