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
8 changes: 3 additions & 5 deletions src/components/colorscale/has_colorscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');

var isValidScale = require('./is_valid_scale');


module.exports = function hasColorscale(trace, containerStr) {
var container = containerStr ?
Lib.nestedProperty(trace, containerStr).get() || {} :
trace,
color = container.color,
isArrayWithOneNumber = false;

if(Array.isArray(color)) {
if(Lib.isTypedArray(color)) {
isArrayWithOneNumber = true;
} else if(Array.isArray(color)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

again to my question about missing data in typed arrays... here can't we just let these typed arrays drop into the for loop as well?

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 306986d

for(var i = 0; i < color.length; i++) {
if(isNumeric(color[i])) {
isArrayWithOneNumber = true;
Expand Down
6 changes: 3 additions & 3 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ function singlePointStyle(d, sel, trace, markerScale, lineScale, marker, markerL

if('mlc' in d) lineColor = d.mlcc = lineScale(d.mlc);
// weird case: array wasn't long enough to apply to every point
else if(Array.isArray(markerLine.color)) lineColor = Color.defaultLine;
else if(Lib.isArrayOrTypedArray(markerLine.color)) lineColor = Color.defaultLine;
else lineColor = markerLine.color;

if(Array.isArray(marker.color)) {
if(Lib.isArrayOrTypedArray(marker.color)) {
fillColor = Color.defaultLine;
perPointGradient = true;
}
Expand Down Expand Up @@ -542,7 +542,7 @@ drawing.tryColorscale = function(marker, prefix) {
scl = cont.colorscale,
colorArray = cont.color;

if(scl && Array.isArray(colorArray)) {
if(scl && Lib.isArrayOrTypedArray(colorArray)) {
return Colorscale.makeColorScaleFunc(
Colorscale.extractScale(scl, cont.cmin, cont.cmax)
);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ lib.castOption = function(trace, ptNumber, astr, fn) {
var val = lib.nestedProperty(trace, astr).get();

if(lib.isArrayOrTypedArray(val)) {
// TODO what to do with 2d arrays?
if(Array.isArray(ptNumber) && Array.isArray(val[ptNumber[0]])) {
if(Array.isArray(ptNumber) && lib.isArrayOrTypedArray(val[ptNumber[0]])) {
return fn(val[ptNumber[0]][ptNumber[1]]);
} else {
return fn(val[ptNumber]);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

var isNumeric = require('fast-isnumeric');

var isArrayOrTypedArray = require('./is_array').isArrayOrTypedArray;

/**
* aggNums() returns the result of an aggregate function applied to an array of
Expand All @@ -30,7 +30,7 @@ exports.aggNums = function(f, v, a, len) {
b;
if(!len) len = a.length;
if(!isNumeric(v)) v = false;
if(Array.isArray(a[0])) {
if(isArrayOrTypedArray(a[0])) {
b = new Array(len);
for(i = 0; i < len; i++) b[i] = exports.aggNums(f, v, a[i]);
a = b;
Expand Down
5 changes: 3 additions & 2 deletions src/traces/heatmap/has_columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var Lib = require('../../lib');

module.exports = function(trace) {
return !Array.isArray(trace.z[0]);
return !Lib.isArrayOrTypedArray(trace.z[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it work to provide a 2D array as an array of typed arrays? Not that I want to encourage this, far better for us to provide a solution based on a single typed array...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it work to provide a 2D array as an array of typed arrays?

Should have looked at the next commit before commenting 🏆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, arrays of typed arrays for should work after this PR.

};
5 changes: 3 additions & 2 deletions src/traces/heatmap/make_bound_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

'use strict';

var Lib = require('../../lib');
var Registry = require('../../registry');

module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) {
Expand All @@ -19,7 +20,7 @@ module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks,
dv,
i;

var isArrayOfTwoItemsOrMore = Array.isArray(arrayIn) && arrayIn.length > 1;
var isArrayOfTwoItemsOrMore = Lib.isArrayOrTypedArray(arrayIn) && arrayIn.length > 1;

if(isArrayOfTwoItemsOrMore && !isHist && (ax.type !== 'category')) {
var len = arrayIn.length;
Expand Down Expand Up @@ -67,7 +68,7 @@ module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks,
var calendar = trace[ax._id.charAt(0) + 'calendar'];

if(isHist || ax.type === 'category') v0 = ax.r2c(v0In, 0, calendar) || 0;
else if(Array.isArray(arrayIn) && arrayIn.length === 1) v0 = arrayIn[0];
else if(Lib.isArrayOrTypedArray(arrayIn) && arrayIn.length === 1) v0 = arrayIn[0];
else if(v0In === undefined) v0 = 0;
else v0 = ax.d2c(v0In, 0, calendar);

Expand Down
4 changes: 2 additions & 2 deletions src/traces/heatmap/xyz_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
var Registry = require('../../registry');
var hasColumns = require('./has_columns');


module.exports = function handleXYZDefaults(traceIn, traceOut, coerce, layout, xName, yName) {
var z = coerce('z');
xName = xName || 'x';
Expand Down Expand Up @@ -76,7 +76,7 @@ function isValidZ(z) {

for(var i = 0; i < z.length; i++) {
zi = z[i];
if(!Array.isArray(zi)) {
if(!Lib.isArrayOrTypedArray(zi)) {
allRowsAreArrays = false;
break;
}
Expand Down
17 changes: 9 additions & 8 deletions src/traces/surface/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var fill = require('ndarray-fill');
var ops = require('ndarray-ops');
var tinycolor = require('tinycolor2');

var Lib = require('../../lib');
var str2RgbaArray = require('../../lib/str2rgbarray');

var MIN_RESOLUTION = 128;
Expand Down Expand Up @@ -45,17 +46,17 @@ proto.handlePick = function(selection) {
];
var traceCoordinate = [0, 0, 0];

if(!Array.isArray(this.data.x)) {
if(!Lib.isArrayOrTypedArray(this.data.x)) {
traceCoordinate[0] = selectIndex[0];
} else if(Array.isArray(this.data.x[0])) {
} else if(Lib.isArrayOrTypedArray(this.data.x[0])) {
traceCoordinate[0] = this.data.x[selectIndex[1]][selectIndex[0]];
} else {
traceCoordinate[0] = this.data.x[selectIndex[0]];
}

if(!Array.isArray(this.data.y)) {
if(!Lib.isArrayOrTypedArray(this.data.y)) {
traceCoordinate[1] = selectIndex[1];
} else if(Array.isArray(this.data.y[0])) {
} else if(Lib.isArrayOrTypedArray(this.data.y[0])) {
traceCoordinate[1] = this.data.y[selectIndex[1]][selectIndex[0]];
} else {
traceCoordinate[1] = this.data.y[selectIndex[1]];
Expand Down Expand Up @@ -231,11 +232,11 @@ proto.update = function(data) {
});

// coords x
if(!Array.isArray(x)) {
if(!Lib.isArrayOrTypedArray(x)) {
fill(xc, function(row) {
return xaxis.d2l(row, 0, xcalendar) * scaleFactor[0];
});
} else if(Array.isArray(x[0])) {
} else if(Lib.isArrayOrTypedArray(x[0])) {
fill(xc, function(row, col) {
return xaxis.d2l(x[col][row], 0, xcalendar) * scaleFactor[0];
});
Expand All @@ -247,11 +248,11 @@ proto.update = function(data) {
}

// coords y
if(!Array.isArray(x)) {
if(!Lib.isArrayOrTypedArray(x)) {
fill(yc, function(row, col) {
return yaxis.d2l(col, 0, xcalendar) * scaleFactor[1];
});
} else if(Array.isArray(y[0])) {
} else if(Lib.isArrayOrTypedArray(y[0])) {
fill(yc, function(row, col) {
return yaxis.d2l(y[col][row], 0, ycalendar) * scaleFactor[1];
});
Expand Down
3 changes: 1 addition & 2 deletions src/traces/surface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
var x = coerce('x');
coerce('y');

// TODO
traceOut._xlength = (Array.isArray(x) && Array.isArray(x[0])) ? z.length : z[0].length;
traceOut._xlength = (Array.isArray(x) && Lib.isArrayOrTypedArray(x[0])) ? z.length : z[0].length;
traceOut._ylength = z.length;

var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
Expand Down