Skip to content

Fix parcoords dimensions values & line coloring error with integer TypedArray #3598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions src/traces/parcoords/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ var maxDimensionCount = require('./constants').maxDimensionCount;
var mergeLength = require('./merge_length');

function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {

var lineColor = coerce('line.color', defaultColor);
if(!Array.isArray(lineColor) && Lib.isArrayOrTypedArray(lineColor)) {
// should convert typed arrays e.g. integers to real numbers
lineColor = traceOut.line.color = Array.prototype.slice.call(lineColor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

}

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

var values = coerce('values');
if(!Array.isArray(values) && Lib.isArrayOrTypedArray(values)) {
// should convert typed arrays e.g. integers to real numbers
values = dimensionOut.values = Array.prototype.slice.call(values);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop. Let's not do this during defaults to remain consistent with other typed-array-to-array blocks.

Move this to parcoords/calc.js.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can keep typed arrays as typed array and handle them correct downstream, then we shouldn't convert them.

That makes perfect sense!

}

var visible = coerce('visible');
if(!(values && values.length)) {
visible = dimensionOut.visible = false;
Expand Down
24 changes: 24 additions & 0 deletions test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,30 @@ describe('parcoords initialization tests', function() {
});
});

it('\'dimensions.values\' and \'line.color\' should convert typed arrays to normal arrays', function() {
var fullTrace = _supply({
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);
});

it('\'domain\' specification should have a default', function() {
var fullTrace = _supply({});
expect(fullTrace.domain).toEqual({x: [0, 1], y: [0, 1]});
Expand Down