Skip to content
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

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

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

function handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce) {
var lineColor = coerce('line.color', defaultColor);

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.

Expand Down Expand Up @@ -49,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
8 changes: 5 additions & 3 deletions test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('parcoords initialization tests', function() {
});
});

it('\'line.color\' should convert typed arrays to normal arrays', function() {
it('\'dimensions.values\' and \'line.color\' should convert typed arrays to normal arrays', function() {
var fullTrace = _supply({
dimensions: [{
range: [1, 5],
Expand All @@ -154,17 +154,19 @@ describe('parcoords initialization tests', function() {
}, {
range: [1, 5],
label: 'B',
values: [3, 1.5, 2],
values: new Float64Array([3, 1.5, 2]),
}, {
range: [1, 5],
label: 'C',
values: [2, 4, 1],
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() {
Expand Down