-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Handle invalid values and zero totals for pie and funnelarea #4416
Conversation
src/traces/pie/calc.js
Outdated
|
||
var i, pt; | ||
|
||
if(trace.dlabel) { | ||
labels = new Array(vals.length); | ||
for(i = 0; i < vals.length; i++) { | ||
labels = []; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/traces/pie/defaults.js
Outdated
if(v < 0) { | ||
sum = 0; | ||
break; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Nicely done - 💃 ! |
Fixes #4414
Before
After
@plotly/plotly_js