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 4 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
16 changes: 15 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,11 @@ function constHalf(len) {
}
return out;
}

function isTypedArray(a) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need for this. Lib.isTypedArray is a thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@etpinard Thanks for the note.
Done in e577e49.

return !Array.isArray(a) && Lib.isArrayOrTypedArray(a);
}

function convertTypedArray(a) {
return (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