Skip to content

Accept objects for encoded typedarrays in data_array valType #5230

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

Merged
merged 142 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
dc9f4e5
accept objects for encoded typedarrays in data_array valType
archmoj Aug 5, 2020
67ccac9
Revert trace changes
jonmmease Nov 28, 2020
712a124
WIP of decoding in calc.
jonmmease Nov 28, 2020
4d5b382
Back to decoding in coerce
jonmmease Nov 28, 2020
7233f34
Cache base64 decoded ArrayBuffers and keep decoding in coerce / suppl…
jonmmease Nov 28, 2020
5079fc7
bvals -> buffer
jonmmease Nov 28, 2020
38e10bb
remove big for consistency
jonmmease Nov 28, 2020
1043827
Revert "bvals -> buffer"
jonmmease Nov 28, 2020
8d84f3e
Run isArray1D on decoded array not spec
jonmmease Nov 28, 2020
2381deb
Plotly.js doesn't currently handle BigInt64/BigUint64 arrays.
jonmmease Nov 29, 2020
a0d980e
Merge pull request #5308 from plotly/jonmmease_typed_array_encoding
archmoj Nov 29, 2020
7a37d62
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Nov 29, 2020
599bc2f
no longer support IE9
archmoj Nov 29, 2020
a83b11f
Remove Big(U)?IntArray from eslint
jonmmease Nov 29, 2020
aba0d4b
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Jun 26, 2021
fbb3f21
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Jul 7, 2021
f3c43f7
reflect schema changes
archmoj Jul 7, 2021
960cea3
provide draft log for PR 5230
archmoj Jul 7, 2021
9aea69d
Update src/lib/coerce.js
archmoj Jul 9, 2021
18caf3f
reflect description change in the schema
archmoj Jul 9, 2021
707b98e
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Jul 12, 2021
adc3efe
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Jul 17, 2021
57141b8
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Jul 20, 2021
53bad2a
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Jul 23, 2021
dc576a4
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Jul 30, 2021
0759432
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Oct 8, 2021
8af44ab
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj May 13, 2022
bbc5848
uninstall base64-arraybuffer using npm 6
archmoj Feb 3, 2023
d150941
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Feb 3, 2023
bdc1f7b
install latest base64-arraybuffer - new major
archmoj Feb 3, 2023
b94d994
revisit key access
archmoj Feb 6, 2023
114deab
declare isInteger
archmoj Feb 6, 2023
145c457
add TODO comments
archmoj Feb 6, 2023
fa229d0
faster access to BYTES_PER_ELEMENT
archmoj Feb 6, 2023
8536fe4
refactor
archmoj Feb 6, 2023
d2b03ac
refactor type detection
archmoj Feb 6, 2023
d956405
refactor decode bvals
archmoj Feb 6, 2023
dbb717e
revisit handling integer shapes - do not add ndims and length
archmoj Feb 6, 2023
323bf4d
remove module based cache
archmoj Feb 6, 2023
4f3c0d3
rewrite coerce logic
archmoj Feb 7, 2023
014cbe3
faster b64 decode calls
archmoj Feb 7, 2023
1f260e0
no need to extra call coerceTypedArraySpec
archmoj Feb 7, 2023
5919634
attach spec to array for json export
archmoj Feb 7, 2023
4fbefeb
export spec in json
archmoj Feb 8, 2023
21ec1fe
add test
archmoj Feb 8, 2023
af5abc5
add test
archmoj Feb 9, 2023
dde03df
export converted _vals in full-json
archmoj Feb 9, 2023
6e7706e
improve test
archmoj Feb 9, 2023
470b3b7
improve test
archmoj Feb 9, 2023
61fa9b0
rewrite to simplify handling 2d arrays
archmoj Feb 9, 2023
3d41e45
fix logic & test
archmoj Feb 9, 2023
68d7541
refactor bvals export
archmoj Feb 9, 2023
2cc98fb
convert ArrayBuffer to b64 in json export
archmoj Feb 9, 2023
64e6988
improve test
archmoj Feb 10, 2023
fe5cc08
add test for buffer
archmoj Feb 10, 2023
9f724b2
simplify decode logic for 2d & 3d - skip 3d for now
archmoj Feb 10, 2023
a35c3fc
use short forms of types
archmoj Feb 10, 2023
f391e76
simplify API for typed array spec - avoid shape array
archmoj Feb 10, 2023
ebd9d79
bvals > vals
archmoj Feb 10, 2023
acc8792
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Feb 16, 2023
1853b6a
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Feb 24, 2023
23902dc
add shape and revise dtype naming to match numpy
archmoj Feb 24, 2023
819d420
make shape optional
archmoj Feb 25, 2023
1230ba8
fix comment for big ints
archmoj Feb 27, 2023
8215c9f
inline detect supported types
archmoj Feb 27, 2023
9ecaf5d
refactor
archmoj Feb 27, 2023
938bb77
correct var name rowBytes
archmoj Feb 27, 2023
d260168
simplify 1d length detection
archmoj Feb 27, 2023
78438fa
rename vals to bdata
archmoj Feb 27, 2023
c1c54e8
handle buffer for arrayOk attributes
archmoj Feb 28, 2023
2df73c4
add b64 image test
archmoj Feb 28, 2023
78abdf1
reverse order of shape dimensions to match numpy API
archmoj Mar 1, 2023
3af205d
handle typed arrays in smith chart tickvals
archmoj Mar 1, 2023
bbb2c0f
handle typed arrays in box
archmoj Mar 1, 2023
bd4d2eb
handle typed arrays in contour
archmoj Mar 1, 2023
60dd1d5
handle typed arrays for tickvals
archmoj Mar 2, 2023
8309136
handle typed arrays in bar text
archmoj Mar 2, 2023
25d3b4f
handle typed arrays in pie
archmoj Mar 2, 2023
2059d2a
handle typed arrays in axes ticktext, hoverlabel & getDataConversions
archmoj Mar 2, 2023
f660105
handle typed arrays for bubble charts
archmoj Mar 2, 2023
ca07e89
handle typed arrays in pie
archmoj Mar 2, 2023
0f2ef23
handle typed arrays in parcats
archmoj Mar 2, 2023
832af54
allow 3d arrays used e.g. by image trace
archmoj Mar 2, 2023
142e353
handle typed arrays in scattergeo
archmoj Mar 2, 2023
1b58c43
handle typed arrays in heatmap hover
archmoj Mar 3, 2023
ff305fc
handle typed arrays in contour
archmoj Mar 3, 2023
d44d2d2
handle typed arrays in scattergl convert
archmoj Mar 3, 2023
14fed21
handle typed array fix rendering of contour_transposed-irregular
archmoj Mar 3, 2023
5902656
handle typed arrays in table
archmoj Mar 6, 2023
590ce4f
do not convert to in32 when not in bounds
archmoj Mar 6, 2023
c7f0e10
handle typed arrays in parcoords
archmoj Mar 6, 2023
ae04cad
handle typed arrays for polar
archmoj Mar 6, 2023
e691a4f
handle typed arrays for smith charts
archmoj Mar 7, 2023
a9d21c9
no need to support in transforms which is deprecated
archmoj Mar 7, 2023
41c1140
handle typed arrays in image trace
archmoj Mar 7, 2023
4b50e16
handle typed arrays various traces
archmoj Mar 7, 2023
8c4202b
handle typed array in scattergl text
archmoj Mar 7, 2023
59557c1
revise dtypes
archmoj Mar 8, 2023
fe9b404
add TODO comments to avoid casting to Array in supply defaults
archmoj Mar 8, 2023
662294e
handle typed arrays in categoryarray
archmoj Mar 8, 2023
281220a
fix polar set_convert
archmoj Mar 8, 2023
1300c2a
handle typed arrays in barpolar
archmoj Mar 8, 2023
0fe1414
handle typed arrays in transform - fix rendering of point-selection case
archmoj Mar 8, 2023
d9dc593
handle typed arrays in scatter3d text
archmoj Mar 9, 2023
7365093
short dtype is now optional - both i1 & int8 are supported
archmoj Mar 9, 2023
e92352b
remove unused import
archmoj Mar 9, 2023
db62bb1
allow transforms
archmoj Mar 9, 2023
ed8cea1
handle typed arrays in transform target
archmoj Mar 9, 2023
5860886
allow groups
archmoj Mar 9, 2023
560fadf
handle typed arrays & b64 in info_array e.g. sankey.groups
archmoj Mar 9, 2023
ea98440
allow values
archmoj Mar 9, 2023
0fc0d70
handle typed arrays in table values
archmoj Mar 9, 2023
a414715
allow args and args2
archmoj Mar 9, 2023
6852b4d
allow more keys
archmoj Mar 9, 2023
bd381f5
allow dtickrange, constraintrange and bounds
archmoj Mar 9, 2023
2d4d47f
allow subplots, xaxes, yaxes & domain
archmoj Mar 9, 2023
d33dc30
allow opacityscale
archmoj Mar 9, 2023
60697dc
handle typed arrays in opacityscale
archmoj Mar 9, 2023
11e0bf0
allow selectedpoints
archmoj Mar 9, 2023
4810585
handle typed arrays in selectedpoints
archmoj Mar 9, 2023
8bba7f8
allow range
archmoj Mar 9, 2023
74f8ee2
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Mar 13, 2023
bb53b1e
handle array spec in type any
archmoj Mar 13, 2023
1a38f37
fix handling direct typedarrays in selectedpoints
archmoj Mar 13, 2023
5347774
Revert "handle typed arrays in contour"
archmoj Mar 13, 2023
5dfe2c9
Revert "handle typed arrays in parcats"
archmoj Mar 13, 2023
9767454
Revert "handle typed arrays in scattergeo"
archmoj Mar 13, 2023
dfa65db
Revert "handle typed arrays in opacityscale"
archmoj Mar 13, 2023
43d0780
improve packing integers in b64 image test
archmoj Mar 13, 2023
b93033f
handle typed arrays in transform filter value
archmoj Mar 13, 2023
6e3f987
improve b64 test coverage include 2 item arrays too
archmoj Mar 13, 2023
4bab8de
handle typed arrays in parcats categoryarray
archmoj Mar 13, 2023
9b0be90
handle typed arrays in scattergeo locations
archmoj Mar 13, 2023
509f7df
test b64 on arrays with only 1 item as well
archmoj Mar 13, 2023
25e8678
add b64 test dashboard - add script to convert mocks to b64
archmoj Mar 14, 2023
e8d82f4
place b64 mocks in the same folder so that devtools.js finds them
archmoj Mar 15, 2023
e9e221e
lint env_image script
archmoj Mar 15, 2023
c7ec94f
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Mar 21, 2023
cef2785
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Sep 11, 2023
02557e5
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Oct 16, 2023
3314377
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Oct 26, 2023
cae76aa
Merge remote-tracking branch 'origin/master' into handle-coded-typed-…
archmoj Dec 14, 2023
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
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
"Float32Array": true,
"Float64Array": true,
"Uint8Array": true,
"Int8Array": true,
"Uint8ClampedArray": true,
"Int16Array": true,
"Uint16Array": true,
"Int32Array": true,
"Uint32Array": true,
"BigInt64Array": true,
"BigUint64Array": true,
"ArrayBuffer": true,
"DataView": true,
"SVGElement": false
Expand Down
21 changes: 17 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@turf/bbox": "^6.0.1",
"@turf/centroid": "^6.0.2",
"alpha-shape": "^1.0.0",
"base64-arraybuffer": "^0.2.0",
"canvas-fit": "^1.5.0",
"color-alpha": "1.0.4",
"color-normalize": "1.5.0",
Expand Down
37 changes: 32 additions & 5 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,49 @@ var DESELECTDIM = require('../constants/interactions').DESELECTDIM;
var nestedProperty = require('./nested_property');
var counterRegex = require('./regex').counter;
var modHalf = require('./mod').modHalf;
var isPlainObject = require('./is_plain_object');
var isArrayOrTypedArray = require('./array').isArrayOrTypedArray;

var typedArrays = {
int8: typeof Int8Array !== 'undefined' ? 1 : 0,
uint8: typeof Uint8Array !== 'undefined' ? 1 : 0,
uint8clamped: typeof Uint8ClampedArray !== 'undefined' ? 1 : 0,
int16: typeof Int16Array !== 'undefined' ? 1 : 0,
uint16: typeof Uint16Array !== 'undefined' ? 1 : 0,
int32: typeof Int32Array !== 'undefined' ? 1 : 0,
uint32: typeof Uint32Array !== 'undefined' ? 1 : 0,
float32: typeof Float32Array !== 'undefined' ? 1 : 0,
float64: typeof Float64Array !== 'undefined' ? 1 : 0,
bigint64: typeof BigInt64Array !== 'undefined' ? 1 : 0,
biguint64: typeof BigUint64Array !== 'undefined' ? 1 : 0
};

exports.valObjectMeta = {
data_array: {
// You can use *dflt=[] to force said array to exist though.
description: [
'An {array} of data.',
'The value MUST be an {array}, or we ignore it.',
'Note that typed arrays (e.g. Float32Array) are supported.'
'The value could be an {array}',
'noting that typed arrays (e.g. Float32Array) are also supported.',
'It could also be an object in the form of',
'v: {, dtype: \'float32\', bvals: [/* ... */]}, shape: [dim0 (, dim1, (dim3))]',
'otherwise, it would be ignored.'
].join(' '),
requiredOpts: [],
otherOpts: ['dflt'],
coerceFunction: function(v, propOut, dflt) {
// TODO maybe `v: {type: 'float32', vals: [/* ... */]}` also
if(isArrayOrTypedArray(v)) propOut.set(v);
else if(dflt !== undefined) propOut.set(dflt);
var wasSet;
if(isArrayOrTypedArray(v)) {
propOut.set(v);
wasSet = true;
} else if(isPlainObject(v)) {
var T = typedArrays[v.dtype];
if(T) {
propOut.set(v);
wasSet = true;
}
}
if(!wasSet && dflt !== undefined) propOut.set(dflt);
}
},
enumerated: {
Expand Down
44 changes: 44 additions & 0 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var d3 = require('d3');
var timeFormatLocale = require('d3-time-format').timeFormatLocale;
var isNumeric = require('fast-isnumeric');
var b64 = require('base64-arraybuffer');

var Registry = require('../registry');
var PlotSchema = require('../plot_api/plot_schema');
Expand Down Expand Up @@ -2848,7 +2849,50 @@ function _transition(gd, transitionOpts, opts) {
return transitionStarting.then(function() { return gd; });
}

var typedArrays = {
int8: typeof Int8Array !== 'undefined' ? Int8Array : null,
uint8: typeof Uint8Array !== 'undefined' ? Uint8Array : null,
uint8clamped: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : null,
int16: typeof Int16Array !== 'undefined' ? Int16Array : null,
uint16: typeof Uint16Array !== 'undefined' ? Uint16Array : null,
int32: typeof Int32Array !== 'undefined' ? Int32Array : null,
uint32: typeof Uint32Array !== 'undefined' ? Uint32Array : null,
float32: typeof Float32Array !== 'undefined' ? Float32Array : null,
float64: typeof Float64Array !== 'undefined' ? Float64Array : null,
bigint64: typeof BigInt64Array !== 'undefined' ? BigInt64Array : null,
biguint64: typeof BigUint64Array !== 'undefined' ? BigUint64Array : null
};

function _decode(cont) {
if(cont.dtype && cont.bvals) {
var T = typedArrays[cont.dtype];
if(T) {
return new T(b64.decode(cont.bvals));
}
}

for(var prop in cont) {
if(prop[0] !== '_' && cont.hasOwnProperty(prop)) {
var item = cont[prop];
if(Lib.isPlainObject(item)) {
var r = _decode(item);
if(r !== undefined) cont[prop] = r;
}
}
}
}

function decodeB64Arrays(gd) {
for(var i = 0; i < gd._fullData.length; i++) {
_decode(gd._fullData[i]);
}

_decode(gd._fullLayout);
}

plots.doCalcdata = function(gd, traces) {
decodeB64Arrays(gd);

var axList = axisIDs.list(gd);
var fullData = gd._fullData;
var fullLayout = gd._fullLayout;
Expand Down
16 changes: 11 additions & 5 deletions src/traces/heatmap/xyz_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ module.exports = function handleXYZDefaults(traceIn, traceOut, coerce, layout, x
yName = yName || 'y';
var x, y;

if(z === undefined || !z.length) return 0;
var shapeX = x ? (x.shape ? x.shape[0] : x.length) || 0 : 0;
var shapeY = y ? (y.shape ? y.shape[0] : y.length) || 0 : 0;
var shapeZ = z ? (z.shape ? z.shape[0] : z.length) || 0 : 0;

if(Lib.isArray1D(traceIn.z)) {
var zlen = shapeZ || (z && z.length) || 0;

if(z === undefined || !zlen) return 0;

if(Lib.isArray1D(traceIn.z) || (z && z.shape && z.shape.length === 1)) {
x = coerce(xName);
y = coerce(yName);

var xlen = Lib.minRowLength(x);
var ylen = Lib.minRowLength(y);
var xlen = shapeX || Lib.minRowLength(x);
var ylen = shapeY || Lib.minRowLength(y);

// column z must be accompanied by xName and yName arrays
if(xlen === 0 || ylen === 0) return 0;

traceOut._length = Math.min(xlen, ylen, z.length);
traceOut._length = Math.min(xlen, ylen, zlen);
} else {
x = coordDefaults(xName, coerce);
y = coordDefaults(yName, coerce);
Expand Down
18 changes: 12 additions & 6 deletions src/traces/isosurface/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ function supplyIsoDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var z = coerce('z');
var value = coerce('value');

if(
!x || !x.length ||
!y || !y.length ||
!z || !z.length ||
!value || !value.length
) {
var len = 0;

if(x && y && z && value) {
len = Math.min(
(x.shape ? x.shape[0] : x.length) || 0,
(y.shape ? y.shape[0] : y.length) || 0,
(z.shape ? z.shape[0] : z.length) || 0,
(value.shape ? value.shape[0] : value.length) || 0
);
}

if(!len) {
traceOut.visible = false;
return;
}
Expand Down
11 changes: 7 additions & 4 deletions src/traces/scatter/xy_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ module.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);

var shapeX = x && x.shape ? x.shape[0] : 0;
var shapeY = y && y.shape ? y.shape[0] : 0;

if(x) {
var xlen = Lib.minRowLength(x);
var xlen = shapeX || Lib.minRowLength(x);
if(y) {
len = Math.min(xlen, Lib.minRowLength(y));
len = shapeY || Math.min(xlen, Lib.minRowLength(y));
} else {
len = xlen;
len = shapeX || xlen;
coerce('y0');
coerce('dy');
}
} else {
if(!y) return 0;

len = Lib.minRowLength(y);
len = shapeY || Lib.minRowLength(y);
coerce('x0');
coerce('dx');
}
Expand Down
6 changes: 5 additions & 1 deletion src/traces/scatter3d/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ function handleXYZDefaults(traceIn, traceOut, coerce, layout) {
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);

if(x && y && z) {
var shapeX = (x.shape ? x.shape[0] : x.length) || 0;
var shapeY = (y.shape ? y.shape[0] : y.length) || 0;
var shapeZ = (z.shape ? z.shape[0] : z.length) || 0;

// TODO: what happens if one is missing?
len = Math.min(x.length, y.length, z.length);
len = Math.min(shapeX, shapeY, shapeZ);
traceOut._length = traceOut._xlength = traceOut._ylength = traceOut._zlength = len;
}

Expand Down