Skip to content

Commit dab105c

Browse files
authored
Merge pull request #3598 from plotly/parcoords-line-color-integer
Fix parcoords dimensions values & line coloring error with integer TypedArray
2 parents ecfa45a + e577e49 commit dab105c

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/traces/parcoords/calc.js

+11-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,7 @@ function constHalf(len) {
3945
}
4046
return out;
4147
}
48+
49+
function convertTypedArray(a) {
50+
return (Lib.isTypedArray(a)) ? Array.prototype.slice.call(a) : a;
51+
}

test/jasmine/tests/parcoords_test.js

+24
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,30 @@ describe('parcoords initialization tests', function() {
326326
color: '#444'
327327
});
328328
});
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+
});
329353
});
330354
});
331355

0 commit comments

Comments
 (0)