Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 45c2f35

Browse filesBrowse files
committed
[PoC] bypass ax.d2c for typedArray during ax.makeCalcdata
... and use typed array 'subarray' to slice coordinate arrays to series length
1 parent a25ff13 commit 45c2f35
Copy full SHA for 45c2f35

File tree

Expand file treeCollapse file tree

4 files changed

+54
-4
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+54
-4
lines changed

‎src/lib/index.js

Copy file name to clipboardExpand all lines: src/lib/index.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ lib.relinkPrivateKeys = require('./relink_private');
2828
lib.ensureArray = require('./ensure_array');
2929

3030
var isArrayModule = require('./is_array');
31-
lib.isArrayOrTypedArray = isArrayModule.isArrayOrTypedArray
31+
lib.isTypedArray = isArrayModule.isTypedArray;
32+
lib.isArrayOrTypedArray = isArrayModule.isArrayOrTypedArray;
3233

3334
var coerceModule = require('./coerce');
3435
lib.valObjectMeta = coerceModule.valObjectMeta;

‎src/lib/is_array.js

Copy file name to clipboardExpand all lines: src/lib/is_array.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var ab = (typeof ArrayBuffer === 'undefined' || !ArrayBuffer.isView) ?
1313
{isView: function() { return false; }} :
1414
ArrayBuffer;
1515

16+
exports.isTypedArray = ab.isView;
17+
1618
exports.isArrayOrTypedArray = function(a) {
1719
return Array.isArray(a) || ab.isView(a);
1820
};

‎src/plots/cartesian/set_convert.js

Copy file name to clipboardExpand all lines: src/plots/cartesian/set_convert.js
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,15 @@ module.exports = function setConvert(ax, fullLayout) {
405405
if(axLetter in trace) {
406406
arrayIn = trace[axLetter];
407407
len = trace._length || arrayIn.length;
408-
arrayOut = new Array(len);
409408

410-
for(i = 0; i < len; i++) {
411-
arrayOut[i] = ax.d2c(arrayIn[i], 0, cal);
409+
if(ax.type === 'linear' && Lib.isTypedArray(arrayIn) && arrayIn.subarray) {
410+
arrayOut = arrayIn.subarray(0, len);
411+
} else {
412+
arrayOut = new Array(len);
413+
414+
for(i = 0; i < len; i++) {
415+
arrayOut[i] = ax.d2c(arrayIn[i], 0, cal);
416+
}
412417
}
413418
}
414419
else {

‎test/jasmine/tests/is_array_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/is_array_test.js
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,45 @@ describe('isArrayOrTypedArray', function() {
4141
});
4242
});
4343
});
44+
45+
describe('isTypedArray', function() {
46+
function A() {}
47+
48+
var shouldPass = [
49+
new Float32Array(1),
50+
new Int32Array([1, 2, 3])
51+
];
52+
53+
var shouldFail = [
54+
new Array(10),
55+
[],
56+
A,
57+
new A(),
58+
document,
59+
window,
60+
null,
61+
undefined,
62+
'string',
63+
true,
64+
false,
65+
NaN,
66+
Infinity,
67+
/foo/,
68+
'\n',
69+
new Date(),
70+
new RegExp('foo'),
71+
new String('string')
72+
];
73+
74+
shouldPass.forEach(function(obj) {
75+
it('treats ' + JSON.stringify(obj) + ' as an array', function() {
76+
expect(Lib.isTypedArray(obj)).toBe(true);
77+
});
78+
});
79+
80+
shouldFail.forEach(function(obj) {
81+
it('treats ' + JSON.stringify(obj !== window ? obj : 'window') + ' as NOT an array', function() {
82+
expect(Lib.isTypedArray(obj)).toBe(false);
83+
});
84+
});
85+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.