Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion src/traces/parcoords/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ var Lib = require('../../lib');
var wrap = require('../../lib/gup').wrap;

module.exports = function calc(gd, trace) {
var cs = !!trace.line.colorscale && Lib.isArrayOrTypedArray(trace.line.color);

for(var i = 0; i < trace.dimensions.length; i++) {
trace.dimensions[i].values = convertTypedArray(trace.dimensions[i].values);
}
trace.line.color = convertTypedArray(trace.line.color);

var cs = !!trace.line.colorscale && Array.isArray(trace.line.color);
var color = cs ? trace.line.color : constHalf(trace._length);
var cscale = cs ? trace.line.colorscale : [[0, trace.line.color], [1, trace.line.color]];

Expand All @@ -39,3 +45,7 @@ function constHalf(len) {
}
return out;
}

function convertTypedArray(a) {
return (Lib.isTypedArray(a)) ? Array.prototype.slice.call(a) : a;
}
24 changes: 24 additions & 0 deletions test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,30 @@ describe('parcoords initialization tests', function() {
color: '#444'
});
});

it('\'dimensions.values\' and \'line.color\' should convert typed arrays to normal arrays', function() {
var fullTrace = _calc(Lib.extendDeep({}, base, {
dimensions: [{
range: [1, 5],
label: 'A',
values: [1, 4, 3]
}, {
range: [1, 5],
label: 'B',
values: new Float64Array([3, 1.5, 2]),
}, {
range: [1, 5],
label: 'C',
values: new Int32Array([2, 4, 1]),
}],
line: {
color: new Int32Array([0, 1, 2])
}
}));
expect(Array.isArray(fullTrace.line.color) === true).toEqual(true);
expect(Array.isArray(fullTrace.dimensions[1].values) === true).toEqual(true);
expect(Array.isArray(fullTrace.dimensions[2].values) === true).toEqual(true);
});
});
});

Expand Down