Skip to content

Commit 3b1dd0f

Browse files
committed
fixups and add polar tests
1 parent c4224f4 commit 3b1dd0f

File tree

6 files changed

+67
-11
lines changed

6 files changed

+67
-11
lines changed

src/plots/cartesian/axis_autotype.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = function autoType(array, calendar, opts) {
1818
var convertNumeric = opts.convertNumeric;
1919

2020
if(!opts.noMultiCategory && multiCategory(array)) return 'multicategory';
21-
if(moreDates(array, calendar, convertNumeric)) return 'date';
21+
if(convertNumeric && moreDates(array, calendar)) return 'date';
2222
if(category(array)) return 'category';
2323
if(linearOK(array, convertNumeric)) return 'linear';
2424
else return convertNumeric ? '-' : 'category';
@@ -46,7 +46,7 @@ function linearOK(array, convertNumeric) {
4646
// dates as non-dates, to exclude cases with mostly 2 & 4 digit
4747
// numbers and a few dates
4848
// as with categories, consider DISTINCT values only.
49-
function moreDates(a, calendar, convertNumeric) {
49+
function moreDates(a, calendar) {
5050
// test at most 1000 points, evenly spaced
5151
var inc = Math.max(1, (a.length - 1) / 1000);
5252
var dcnt = 0;
@@ -60,7 +60,7 @@ function moreDates(a, calendar, convertNumeric) {
6060
seen[stri] = 1;
6161

6262
if(Lib.isDateTime(ai, calendar)) dcnt += 1;
63-
if(hasTypeNumber(ai, convertNumeric)) ncnt += 1;
63+
if(isNumeric(ai)) ncnt += 1;
6464
}
6565

6666
return (dcnt > ncnt * 2);

src/plots/polar/layout_attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ var angularAxisAttrs = {
180180
'If *category, use `period` to set the number of integer coordinates around polar axis.'
181181
].join(' ')
182182
},
183+
convertnumeric: axesAttrs.convertnumeric,
183184

184185
categoryorder: axesAttrs.categoryorder,
185186
categoryarray: axesAttrs.categoryarray,

src/plots/polar/layout_defaults.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
5757
axOut._traceIndices = subplotData.map(function(t) { return t._expandedIndex; });
5858

5959
var dataAttr = constants.axisName2dataArray[axName];
60-
var axType = handleAxisTypeDefaults(axIn, axOut, coerceAxis, subplotData, dataAttr, opts.convertnumericDflt);
60+
var axType = handleAxisTypeDefaults(axIn, axOut, coerceAxis, subplotData, dataAttr, opts);
6161

6262
handleCategoryOrderDefaults(axIn, axOut, coerceAxis, {
6363
axData: subplotData,
@@ -188,7 +188,7 @@ function handleDefaults(contIn, contOut, coerce, opts) {
188188
}
189189

190190
function handleAxisTypeDefaults(axIn, axOut, coerce, subplotData, dataAttr, options) {
191-
var convertnumeric = dataAttr.convertnumeric ? coerce('convertnumeric', options.convertnumericDflt) : false;
191+
var convertnumeric = coerce('convertnumeric', options.convertnumericDflt);
192192
var axType = coerce('type');
193193

194194
if(axType === '-') {
@@ -203,7 +203,7 @@ function handleAxisTypeDefaults(axIn, axOut, coerce, subplotData, dataAttr, opti
203203

204204
if(trace && trace[dataAttr]) {
205205
axOut.type = autoType(trace[dataAttr], 'gregorian', {
206-
convertNumeric: !convertnumeric
206+
convertNumeric: convertnumeric
207207
});
208208
}
209209

src/traces/box/defaults.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function handleSampleDefaults(traceIn, traceOut, coerce, layout) {
109109
var yLen = yDims && Lib.minRowLength(y);
110110
var xLen = xDims && Lib.minRowLength(x);
111111

112-
var calendar = null; // TODO: should we use ax.calendar here?
112+
var calendar = 'gregorian'; // TODO: should we use ax.calendar here?
113113
var opts = {
114114
convertNumeric: true // TODO: should we use ax.convertnumeric here?
115115
};

test/jasmine/tests/axes_test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,12 @@ describe('Test axes', function() {
347347
type: 'scatter',
348348
xaxis: 'x',
349349
yaxis: 'y',
350-
x: ['0', '1'],
351-
y: ['0', '1']
350+
x: ['0', '1', '1970', '2000'],
351+
y: ['0', '1', '1970', '2000']
352352
}]);
353353

354+
expect(layoutOut.xaxis.convertnumeric).toBe(true);
355+
expect(layoutOut.yaxis.convertnumeric).toBe(false);
354356
expect(layoutOut.xaxis.type).toBe('linear');
355357
expect(layoutOut.yaxis.type).toBe('category');
356358
});
@@ -367,10 +369,12 @@ describe('Test axes', function() {
367369
type: 'scatter',
368370
xaxis: 'x',
369371
yaxis: 'y',
370-
x: ['0', '1'],
371-
y: ['0', '1']
372+
x: ['0', '1', '1970', '2000'],
373+
y: ['0', '1', '1970', '2000']
372374
}]);
373375

376+
expect(layoutOut.xaxis.convertnumeric).toBe(true);
377+
expect(layoutOut.yaxis.convertnumeric).toBe(false);
374378
expect(layoutOut.xaxis.type).toBe('linear');
375379
expect(layoutOut.yaxis.type).toBe('category');
376380
});

test/jasmine/tests/polar_test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('Test polar plots defaults:', function() {
7474
}];
7575

7676
layoutOut = {
77+
axesconvertnumeric: true,
7778
font: {color: 'red'},
7879
_subplots: {polar: ['polar']}
7980
};
@@ -209,6 +210,56 @@ describe('Test polar plots defaults:', function() {
209210
expect(layoutOut.polar.radialaxis.hoverformat).toBe('g');
210211
expect(layoutOut.polar.angularaxis.hoverformat).toBe('g');
211212
});
213+
214+
it('should disable converting numeric strings using axis.convertnumeric', function() {
215+
_supply({
216+
polar: {
217+
radialaxis: {
218+
convertnumeric: false
219+
},
220+
angularaxis: {
221+
convertnumeric: false
222+
}
223+
}
224+
}, [{
225+
visible: true,
226+
type: 'scatterpolar',
227+
r: ['0', '1', '1970', '2000'],
228+
theta: ['0', '1', '1970', '2000'],
229+
subplot: 'polar'
230+
}]);
231+
232+
expect(layoutOut.polar.angularaxis.convertnumeric).toBe(false);
233+
expect(layoutOut.polar.radialaxis.convertnumeric).toBe(false);
234+
expect(layoutOut.polar.radialaxis.type).toBe('category');
235+
expect(layoutOut.polar.angularaxis.type).toBe('category');
236+
});
237+
238+
it('should enable converting numeric strings using axis.convertnumeric and inherit defaults from layout.axesconvertnumeric', function() {
239+
layoutOut.axesconvertnumeric = false;
240+
241+
_supply({
242+
polar: {
243+
radialaxis: {
244+
convertnumeric: true
245+
},
246+
angularaxis: {
247+
convertnumeric: true
248+
}
249+
}
250+
}, [{
251+
visible: true,
252+
type: 'scatterpolar',
253+
r: ['0', '1', '1970', '2000'],
254+
theta: ['0', '1', '1970', '2000'],
255+
subplot: 'polar'
256+
}]);
257+
258+
expect(layoutOut.polar.angularaxis.convertnumeric).toBe(true);
259+
expect(layoutOut.polar.radialaxis.convertnumeric).toBe(true);
260+
expect(layoutOut.polar.radialaxis.type).toBe('linear');
261+
expect(layoutOut.polar.angularaxis.type).toBe('linear');
262+
});
212263
});
213264

214265
describe('Test relayout on polar subplots:', function() {

0 commit comments

Comments
 (0)