Skip to content

Commit c4224f4

Browse files
committed
adjust autoType return when convertNumeric is disabled - add tests
1 parent cbac3ae commit c4224f4

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/plots/cartesian/axis_autotype.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function autoType(array, calendar, opts) {
2121
if(moreDates(array, calendar, convertNumeric)) return 'date';
2222
if(category(array)) return 'category';
2323
if(linearOK(array, convertNumeric)) return 'linear';
24-
else return '-';
24+
else return convertNumeric ? '-' : 'category';
2525
};
2626

2727
function hasTypeNumber(v, convertNumeric) {

test/jasmine/tests/axes_test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,46 @@ describe('Test axes', function() {
336336
});
337337
});
338338

339+
describe('autotype disable/enable converting numeric strings', function() {
340+
it('should disable converting numeric strings using axis.convertnumeric', function() {
341+
layoutIn = {
342+
xaxis: {},
343+
yaxis: { convertnumeric: false }
344+
};
345+
346+
supplyLayoutDefaults(layoutIn, layoutOut, [{
347+
type: 'scatter',
348+
xaxis: 'x',
349+
yaxis: 'y',
350+
x: ['0', '1'],
351+
y: ['0', '1']
352+
}]);
353+
354+
expect(layoutOut.xaxis.type).toBe('linear');
355+
expect(layoutOut.yaxis.type).toBe('category');
356+
});
357+
358+
it('should enable converting numeric strings using axis.convertnumeric and inherit defaults from layout.axesconvertnumeric', function() {
359+
layoutOut.axesconvertnumeric = false;
360+
361+
layoutIn = {
362+
xaxis: { convertnumeric: true },
363+
yaxis: {}
364+
};
365+
366+
supplyLayoutDefaults(layoutIn, layoutOut, [{
367+
type: 'scatter',
368+
xaxis: 'x',
369+
yaxis: 'y',
370+
x: ['0', '1'],
371+
y: ['0', '1']
372+
}]);
373+
374+
expect(layoutOut.xaxis.type).toBe('linear');
375+
expect(layoutOut.yaxis.type).toBe('category');
376+
});
377+
});
378+
339379
it('should set undefined linewidth/linecolor if linewidth, linecolor or showline is not supplied', function() {
340380
layoutIn = {
341381
xaxis: {},

0 commit comments

Comments
 (0)