Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed arrays support #2388

Merged
merged 28 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
91b03ff
rename Lib.isArray -> Lib.isArrayOrTypedArray
etpinard Feb 20, 2018
a25ff13
accept typed array when coercing 'data_array' attributes
etpinard Feb 20, 2018
45c2f35
[PoC] bypass ax.d2c for typedArray during ax.makeCalcdata
etpinard Feb 20, 2018
2d81bdc
replace Array.isArray -> Lib.isArrayOrTypedArray in various places
etpinard Feb 20, 2018
bcf59d7
replace Lib.isArray -> Array.isArray in tests w/o typed arrays
etpinard Feb 20, 2018
bc32981
[wip] a few todos
etpinard Feb 20, 2018
2372629
Merge branch 'master' into typed-arrays-support
etpinard Feb 22, 2018
909120e
make scattergl dragmode relayout replot not recalc
etpinard Feb 26, 2018
5316c47
large lint commit in scattergl/index.js
etpinard Feb 26, 2018
0aa0f5e
improvements to Scattergl.calc
etpinard Feb 26, 2018
39ef5a9
update baselines
etpinard Feb 26, 2018
36b4e25
update jasmine tests for new scattergl auto-ranges
etpinard Feb 26, 2018
40f93f7
add svg vs gl scatter autorange :lock:s
etpinard Feb 26, 2018
d98dcc0
improve makeCalcdata typed array handling + some tests + some linting
etpinard Feb 26, 2018
c0e2f73
a few more Array.isArray -> Lib.isArrayOrTypedArray
etpinard Feb 26, 2018
09d37b6
some typed array tests
etpinard Feb 26, 2018
a7ed2c2
:lock: Plotly.restyle support for typed arrays
etpinard Feb 28, 2018
b95e462
add and :lock: typed array support for extendTraces and prependTraces
etpinard Feb 28, 2018
53ea0ec
Merge branch 'master' into typed-arrays-support
etpinard Feb 28, 2018
98d2407
use c2l instead of d2l
etpinard Feb 28, 2018
01a8443
:hocho: TODOs
etpinard Feb 28, 2018
c15722f
add mock :lock:ing down cleanNumber for scattergl
etpinard Feb 28, 2018
a2fb88b
Merge pull request #2404 from plotly/scattergl-autorange
etpinard Feb 28, 2018
f0395b5
improve isTypedArray
etpinard Feb 28, 2018
9b83826
don't require all of Lib when only isArrayOrTypedArray is needed
etpinard Feb 28, 2018
6dd2f69
turn coord typed arrays into plain array for 'date' and 'category axes
etpinard Feb 28, 2018
306986d
check that typed arrays items aren't all NaNs in hasColorscale
etpinard Feb 28, 2018
d4cb0c4
no need to check for typed array in outer array of a 2d array
etpinard Feb 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/plots/cartesian/set_convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,29 +406,33 @@ module.exports = function setConvert(ax, fullLayout) {
arrayIn = trace[axLetter];
len = trace._length || arrayIn.length;

if(ax.type === 'linear' && Lib.isTypedArray(arrayIn) && arrayIn.subarray) {
arrayOut = arrayIn.subarray(0, len);
} else {
arrayOut = new Array(len);

for(i = 0; i < len; i++) {
arrayOut[i] = ax.d2c(arrayIn[i], 0, cal);
if(Lib.isTypedArray(arrayIn)) {
if(len === arrayIn.length) {
return arrayIn;
} else if(arrayIn.subarray) {
return arrayIn.subarray(0, len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work for linear and log axes, but what happens if you feed numeric data to a non-numeric (date or category) axis? Both of those could be real use cases, but both also alter the input numbers, so I think they need to bail out to the d2c block below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and 🔒 in 6dd2f69

}
}

arrayOut = new Array(len);
for(i = 0; i < len; i++) {
arrayOut[i] = ax.d2c(arrayIn[i], 0, cal);
}
}
else {
var v0 = ((axLetter + '0') in trace) ?
ax.d2c(trace[axLetter + '0'], 0, cal) : 0,
dv = (trace['d' + axLetter]) ?
Number(trace['d' + axLetter]) : 1;
var v0 = ((axLetter + '0') in trace) ? ax.d2c(trace[axLetter + '0'], 0, cal) : 0;
var dv = (trace['d' + axLetter]) ? Number(trace['d' + axLetter]) : 1;

// the opposing data, for size if we have x and dx etc
arrayIn = trace[{x: 'y', y: 'x'}[axLetter]];
len = trace._length || arrayIn.length;
arrayOut = new Array(len);

for(i = 0; i < len; i++) arrayOut[i] = v0 + i * dv;
for(i = 0; i < len; i++) {
arrayOut[i] = v0 + i * dv;
}
}

return arrayOut;
};

Expand Down
85 changes: 84 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ var Cartesian = require('@src/plots/cartesian');
var Axes = require('@src/plots/cartesian/axes');
var Fx = require('@src/components/fx');
var supplyLayoutDefaults = require('@src/plots/cartesian/layout_defaults');
var BADNUM = require('@src/constants/numerical').BADNUM;

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var selectButton = require('../assets/modebar_button');
var supplyDefaults = require('../assets/supply_defaults');


describe('Test axes', function() {
'use strict';

Expand Down Expand Up @@ -2447,6 +2447,89 @@ describe('Test axes', function() {
});
});
});

describe('makeCalcdata', function() {
function _makeCalcdata(trace, axLetter, axType) {
var ax = {type: axType};
Axes.setConvert(ax);
ax._categories = [];
return ax.makeCalcdata(trace, axLetter);
}

describe('should convert items', function() {
it('- linear case', function() {
var out = _makeCalcdata({
x: ['1', NaN, null, 2],
}, 'x', 'linear');
expect(out).toEqual([1, BADNUM, BADNUM, 2]);
});

it('- date case', function() {
var out = _makeCalcdata({
x: ['2000-01-01', NaN, null, new Date(2000, 0, 1).getTime()],
}, 'x', 'date');
expect(out).toEqual([946684800000, BADNUM, BADNUM, 946684800000]);
});

it('- category case', function() {
var out = _makeCalcdata({
x: ['a', 'b', null, 4],
}, 'x', 'category');

expect(out).toEqual([0, 1, BADNUM, 2]);
});
});

describe('should fill item to other coordinate length if not present', function() {
it('- base case', function() {
var out = _makeCalcdata({
y: [1, 2, 1],
}, 'x', 'linear');
expect(out).toEqual([0, 1, 2]);
});

it('- x0/dx case', function() {
var out = _makeCalcdata({
y: [1, 2, 1],
x0: 2,
dx: 10,
_length: 3
}, 'x', 'linear');
expect(out).toEqual([2, 12, 22]);
});

it('- other length case', function() {
var out = _makeCalcdata({
_length: 5,
y: [1, 2, 1],
}, 'x', 'linear');
expect(out).toEqual([0, 1, 2, 3, 4]);
});
});

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

it('- subarray case', function() {
var x = new Float32Array([1, 2, 3]);
var out = _makeCalcdata({
_length: 2,
x: x
}, 'x', 'linear');
expect(out).toEqual(new Float32Array([1, 2]));
// check that in and out are linked to same buffer
expect(out.buffer).toBeDefined();
expect(out.buffer).toEqual(x.buffer);
});
});
});
});

function getZoomInButton(gd) {
Expand Down