Skip to content

Commit 30e2c25

Browse files
committed
moved convert typedArray logic from defaults to calc step
1 parent e8cc760 commit 30e2c25

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

src/traces/parcoords/calc.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ var Lib = require('../../lib');
1414
var wrap = require('../../lib/gup').wrap;
1515

1616
module.exports = function calc(gd, trace) {
17-
var cs = !!trace.line.colorscale && Lib.isArrayOrTypedArray(trace.line.color);
17+
18+
for(var i = 0; i < trace.dimensions.length; i++) {
19+
trace.dimensions[i].values = convertTypedArray(trace.dimensions[i].values);
20+
}
21+
trace.line.color = convertTypedArray(trace.line.color);
22+
23+
var cs = !!trace.line.colorscale && Array.isArray(trace.line.color);
1824
var color = cs ? trace.line.color : constHalf(trace._length);
1925
var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];
2026

@@ -39,3 +45,11 @@ function constHalf(len) {
3945
}
4046
return out;
4147
}
48+
49+
function isTypedArray(a) {
50+
return !Array.isArray(a) && Lib.isArrayOrTypedArray(a);
51+
}
52+
53+
function convertTypedArray(a) {
54+
return (isTypedArray(a)) ? Array.prototype.slice.call(a) : a;
55+
}

src/traces/parcoords/defaults.js

-10
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ var maxDimensionCount = require('./constants').maxDimensionCount;
2020
var mergeLength = require('./merge_length');
2121

2222
function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
23-
2423
var lineColor = coerce('line.color', defaultColor);
25-
if(!Array.isArray(lineColor) && Lib.isArrayOrTypedArray(lineColor)) {
26-
// should convert typed arrays e.g. integers to real numbers
27-
lineColor = traceOut.line.color = Array.prototype.slice.call(lineColor);
28-
}
2924

3025
if(hasColorscale(traceIn, 'line') && Lib.isArrayOrTypedArray(lineColor)) {
3126
if(lineColor.length) {
@@ -49,11 +44,6 @@ function dimensionDefaults(dimensionIn, dimensionOut) {
4944
}
5045

5146
var values = coerce('values');
52-
if(!Array.isArray(values) && Lib.isArrayOrTypedArray(values)) {
53-
// should convert typed arrays e.g. integers to real numbers
54-
values = dimensionOut.values = Array.prototype.slice.call(values);
55-
}
56-
5747
var visible = coerce('visible');
5848
if(!(values && values.length)) {
5949
visible = dimensionOut.visible = false;

test/jasmine/tests/parcoords_test.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -145,30 +145,6 @@ describe('parcoords initialization tests', function() {
145145
});
146146
});
147147

148-
it('\'dimensions.values\' and \'line.color\' should convert typed arrays to normal arrays', function() {
149-
var fullTrace = _supply({
150-
dimensions: [{
151-
range: [1, 5],
152-
label: 'A',
153-
values: [1, 4, 3]
154-
}, {
155-
range: [1, 5],
156-
label: 'B',
157-
values: new Float64Array([3, 1.5, 2]),
158-
}, {
159-
range: [1, 5],
160-
label: 'C',
161-
values: new Int32Array([2, 4, 1]),
162-
}],
163-
line: {
164-
color: new Int32Array([0, 1, 2])
165-
}
166-
});
167-
expect(Array.isArray(fullTrace.line.color) === true).toEqual(true);
168-
expect(Array.isArray(fullTrace.dimensions[1].values) === true).toEqual(true);
169-
expect(Array.isArray(fullTrace.dimensions[2].values) === true).toEqual(true);
170-
});
171-
172148
it('\'domain\' specification should have a default', function() {
173149
var fullTrace = _supply({});
174150
expect(fullTrace.domain).toEqual({x: [0, 1], y: [0, 1]});
@@ -350,6 +326,30 @@ describe('parcoords initialization tests', function() {
350326
color: '#444'
351327
});
352328
});
329+
330+
it('\'dimensions.values\' and \'line.color\' should convert typed arrays to normal arrays', function() {
331+
var fullTrace = _calc(Lib.extendDeep({}, base, {
332+
dimensions: [{
333+
range: [1, 5],
334+
label: 'A',
335+
values: [1, 4, 3]
336+
}, {
337+
range: [1, 5],
338+
label: 'B',
339+
values: new Float64Array([3, 1.5, 2]),
340+
}, {
341+
range: [1, 5],
342+
label: 'C',
343+
values: new Int32Array([2, 4, 1]),
344+
}],
345+
line: {
346+
color: new Int32Array([0, 1, 2])
347+
}
348+
}));
349+
expect(Array.isArray(fullTrace.line.color) === true).toEqual(true);
350+
expect(Array.isArray(fullTrace.dimensions[1].values) === true).toEqual(true);
351+
expect(Array.isArray(fullTrace.dimensions[2].values) === true).toEqual(true);
352+
});
353353
});
354354
});
355355

0 commit comments

Comments
 (0)