Skip to content

Commit

Permalink
turn coord typed arrays into plain array for 'date' and 'category axes
Browse files Browse the repository at this point in the history
... for now.
  • Loading branch information
etpinard committed Feb 28, 2018
1 parent 9b83826 commit 6dd2f69
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,14 @@ module.exports = function setConvert(ax, fullLayout) {
ax.makeCalcdata = function(trace, axLetter) {
var arrayIn, arrayOut, i, len;

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

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

if(Lib.isTypedArray(arrayIn)) {
if(Lib.isTypedArray(arrayIn) && (axType === 'linear' || axType === 'log')) {
if(len === arrayIn.length) {
return arrayIn;
} else if(arrayIn.subarray) {
Expand Down
38 changes: 36 additions & 2 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2449,8 +2449,10 @@ describe('Test axes', function() {
});

describe('makeCalcdata', function() {
var ax;

function _makeCalcdata(trace, axLetter, axType) {
var ax = {type: axType};
ax = {type: axType};
Axes.setConvert(ax);
ax._categories = [];
return ax.makeCalcdata(trace, axLetter);
Expand Down Expand Up @@ -2508,7 +2510,7 @@ describe('Test axes', function() {
});

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

it('- same length log case', function() {
var x = new Float32Array([1, 2, 3]);
var out = _makeCalcdata({
_length: 3,
x: x
}, 'x', 'log');
expect(out).toBe(x);
});

it('- subarray case', function() {
var x = new Float32Array([1, 2, 3]);
var out = _makeCalcdata({
Expand All @@ -2529,6 +2540,29 @@ describe('Test axes', function() {
expect(out.buffer).toEqual(x.buffer);
});
});

describe('should convert typed arrays to plain array', function() {
it('- on a category axis', function() {
var out = _makeCalcdata({
x: new Float32Array([3, 1, 2]),
}, 'x', 'category');
expect(out).toEqual([0, 1, 2]);
expect(ax._categories).toEqual([3, 1, 2]);
});

it('- on a date axis', function() {
var dates = [[2000, 0, 1], [2001, 0, 1], [2002, 0, 1]]
.map(function(d) { return new Date(d[0], d[1], d[2]).getTime(); });

// We could make this work down the road (in v2),
// when address our timezone problems.
var out = _makeCalcdata({
x: new Float64Array(dates)
}, 'x', 'date');

expect(out).toEqual([946684800000, 978307200000, 1009843200000]);
});
});
});
});

Expand Down

0 comments on commit 6dd2f69

Please sign in to comment.