Skip to content

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

Merged
archmoj merged 5 commits into
masterfrom
parcoords-line-color-integer
Mar 4, 2019
Merged

archmoj merged 5 commits into
masterfrom
parcoords-line-color-integer

Conversation

@archmoj

@archmoj archmoj commented Mar 3, 2019 •

Copy link
Copy Markdown
Contributor

Fixes two issues reported & discovered in #3595 resulted from integer rounding errors.

  • case of color.line typed arrays e.g. int32
  • case of dimensions.values typed arrays e.g. int32

@plotly_js
Codepen Before.
Codepen After.

@archmoj archmoj added bug something broken status: reviewable labels Mar 3, 2019
@antoinerg

Copy link
Copy Markdown
Contributor

Thanks for the fix @archmoj! It looks good to me 👍

I am wondering if we should add a parcoords mock with line.color as a typedArray to 🔒 this down.

@archmoj

archmoj commented Mar 3, 2019

Copy link
Copy Markdown
Contributor Author

@antoinerg thanks for the review & comment. I am not sure if we could make a JSON mock with typed arrays. So I may add a jasmine test.

@archmoj archmoj changed the title Fix parcoords line coloring error with integer TypedArray Fix parcoords dimensions values & line coloring error with integer TypedArray Mar 3, 2019
@archmoj

archmoj commented Mar 3, 2019

Copy link
Copy Markdown
Contributor Author

@antoinerg Please note that e8cc760 is also added concerning my comment here.

@antoinerg

Copy link
Copy Markdown
Contributor

I am not sure if we could make a JSON mock with typed arrays.

You're probably right 😄 Thanks for the jasmine tests!

I confirm this PR fix both issues in #3595 but I wonder why coerce isn't already doing the right thing and whether copying the TypedArray into an Array is avoidable. Therefore, I will leave it up to @etpinard to give you a dancer!

Nice work @archmoj

Comment thread src/traces/parcoords/defaults.js Outdated
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
Copy Markdown
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
Copy Markdown
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!

Comment thread src/traces/parcoords/defaults.js Outdated
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here.

@etpinard

etpinard commented Mar 4, 2019 •

Copy link
Copy Markdown
Contributor

but I wonder why coerce isn't already doing the right thing and whether copying the TypedArray into an Array is avoidable

because we don't want to do that in general. If we can keep typed arrays as typed array and handle them correctly downstream, then we shouldn't convert them. See for example ax.makeCalcdata which is called by most trace modules:

if(axLetter in trace) {
arrayIn = trace[axLetter];
len = trace._length || Lib.minRowLength(arrayIn);
if(Lib.isTypedArray(arrayIn) && (axType === 'linear' || axType === 'log')) {
if(len === arrayIn.length) {
return arrayIn;
} else if(arrayIn.subarray) {
return arrayIn.subarray(0, len);
}
}
if(axType === 'multicategory') {
return setMultiCategoryIndex(arrayIn, len);
}
arrayOut = new Array(len);
for(i = 0; i < len; i++) {
arrayOut[i] = ax.d2c(arrayIn[i], 0, cal);
}
}
else {

@etpinard

etpinard commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

I am not sure if we could make a JSON mock with typed arrays.

See #913

Comment thread src/traces/parcoords/calc.js Outdated
return out;
}

function isTypedArray(a) {

Copy link
Copy Markdown
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
Copy Markdown
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.

@etpinard

etpinard commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

Nicely done 💃

@archmoj
archmoj merged commit dab105c into master Mar 4, 2019
@archmoj
archmoj deleted the parcoords-line-color-integer branch March 4, 2019 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug something broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants