Skip to content

Commit 6dd2f69

Browse files
committed
turn coord typed arrays into plain array for 'date' and 'category axes
... for now.
1 parent 9b83826 commit 6dd2f69

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/plots/cartesian/set_convert.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,14 @@ module.exports = function setConvert(ax, fullLayout) {
400400
ax.makeCalcdata = function(trace, axLetter) {
401401
var arrayIn, arrayOut, i, len;
402402

403-
var cal = ax.type === 'date' && trace[axLetter + 'calendar'];
403+
var axType = ax.type;
404+
var cal = axType === 'date' && trace[axLetter + 'calendar'];
404405

405406
if(axLetter in trace) {
406407
arrayIn = trace[axLetter];
407408
len = trace._length || arrayIn.length;
408409

409-
if(Lib.isTypedArray(arrayIn)) {
410+
if(Lib.isTypedArray(arrayIn) && (axType === 'linear' || axType === 'log')) {
410411
if(len === arrayIn.length) {
411412
return arrayIn;
412413
} else if(arrayIn.subarray) {

test/jasmine/tests/axes_test.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -2449,8 +2449,10 @@ describe('Test axes', function() {
24492449
});
24502450

24512451
describe('makeCalcdata', function() {
2452+
var ax;
2453+
24522454
function _makeCalcdata(trace, axLetter, axType) {
2453-
var ax = {type: axType};
2455+
ax = {type: axType};
24542456
Axes.setConvert(ax);
24552457
ax._categories = [];
24562458
return ax.makeCalcdata(trace, axLetter);
@@ -2508,7 +2510,7 @@ describe('Test axes', function() {
25082510
});
25092511

25102512
describe('should subarray typed arrays', function() {
2511-
it('- same length case', function() {
2513+
it('- same length linear case', function() {
25122514
var x = new Float32Array([1, 2, 3]);
25132515
var out = _makeCalcdata({
25142516
_length: 3,
@@ -2517,6 +2519,15 @@ describe('Test axes', function() {
25172519
expect(out).toBe(x);
25182520
});
25192521

2522+
it('- same length log case', function() {
2523+
var x = new Float32Array([1, 2, 3]);
2524+
var out = _makeCalcdata({
2525+
_length: 3,
2526+
x: x
2527+
}, 'x', 'log');
2528+
expect(out).toBe(x);
2529+
});
2530+
25202531
it('- subarray case', function() {
25212532
var x = new Float32Array([1, 2, 3]);
25222533
var out = _makeCalcdata({
@@ -2529,6 +2540,29 @@ describe('Test axes', function() {
25292540
expect(out.buffer).toEqual(x.buffer);
25302541
});
25312542
});
2543+
2544+
describe('should convert typed arrays to plain array', function() {
2545+
it('- on a category axis', function() {
2546+
var out = _makeCalcdata({
2547+
x: new Float32Array([3, 1, 2]),
2548+
}, 'x', 'category');
2549+
expect(out).toEqual([0, 1, 2]);
2550+
expect(ax._categories).toEqual([3, 1, 2]);
2551+
});
2552+
2553+
it('- on a date axis', function() {
2554+
var dates = [[2000, 0, 1], [2001, 0, 1], [2002, 0, 1]]
2555+
.map(function(d) { return new Date(d[0], d[1], d[2]).getTime(); });
2556+
2557+
// We could make this work down the road (in v2),
2558+
// when address our timezone problems.
2559+
var out = _makeCalcdata({
2560+
x: new Float64Array(dates)
2561+
}, 'x', 'date');
2562+
2563+
expect(out).toEqual([946684800000, 978307200000, 1009843200000]);
2564+
});
2565+
});
25322566
});
25332567
});
25342568

0 commit comments

Comments
 (0)