Skip to content

Commit

Permalink
Merge pull request #3598 from plotly/parcoords-line-color-integer
Browse files Browse the repository at this point in the history
Fix parcoords dimensions values & line coloring error with integer TypedArray
  • Loading branch information
archmoj committed Mar 4, 2019
2 parents ecfa45a + e577e49 commit dab105c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
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

0 comments on commit dab105c

Please sign in to comment.