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

Handle invalid values and zero totals for pie and funnelarea #4416

Merged
merged 3 commits into from
Jan 7, 2020

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Dec 7, 2019

Fixes #4414

Before
After

@plotly/plotly_js

@archmoj archmoj added bug something broken status: reviewable labels Dec 7, 2019

var i, pt;

if(trace.dlabel) {
labels = new Array(vals.length);
for(i = 0; i < vals.length; i++) {
labels = [];
Copy link
Contributor

@etpinard etpinard Dec 9, 2019

Choose a reason for hiding this comment

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

What's wrong with labels = new Array(len);? I'm not a fan an implicit array-pushing e.g.

var arr = [];
for(var i = 0; i < N; i++) {
  arr[i] = i;
}

like you have here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done in 1967fd4.

Comment on lines 30 to 32
if(v < 0) {
sum = 0;
break;
Copy link
Contributor

@etpinard etpinard Dec 9, 2019

Choose a reason for hiding this comment

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

Hmm. Don't you mean continue; here instead of break; ?

If I understand correctly, this makes any trace with one (or more) negative values have _length=0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done in 1967fd4.

sum += v;
}
if(!sum) len = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Moreover, you're potentially looping here over all the values items. This is something we usually defer to the calc step to keep supplyDefaults performance scaling as the number of attributes NOT the number of data array items.

As pie-like trace usually don't have that many data array items, this is not a big deal, but still could you move some of this logic to the calc step?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done in 1967fd4.

- apply isNumeric test
- should skip Infinity
- no need to compuet sum
- declare known size of Array
@etpinard
Copy link
Contributor

etpinard commented Jan 7, 2020

Nicely done - 💃 !

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.

pie should handle case of zero total values
2 participants