-
Notifications
You must be signed in to change notification settings - Fork 121
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
feat: expose computeRatioByGroups fn #1495
feat: expose computeRatioByGroups fn #1495
Conversation
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.
LGTM 🎉
Some comment changes suggested.
Also, this makes me wonder if there'd be utility to a sign-aware version, such that, with the same setup as in the example,
- Product A contributes (which I think is an OK word here) -200% of the results
- Product B contributes 300% of the results
The two together contribute 100% of the results. So what's in the PR is a net version, and the above is a gross version
* The ratio is computed using absolute values. | ||
* Product A made a profit of $200, and product B has a loss of $300. In total, the company lost $100 ($200 – $300). | ||
* Product A contributed: abs(200) / ( abs(200) + abs(-300) ) * 100% = 40% | ||
* Product B contributed: abs(-300) / ( abs(200) + abs(-300) ) * 100% = 60% | ||
* Product A and product B contributed 40% and 60% respectively on a total loss of $100. |
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.
Nice docs! Though as we discussed, I think few people would say that "Product A contributed 40% of the losses" when product A is profitable, while it's fairer to say, "Product A has a weight of 40% in the formation of the overall results"
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.
You are right, I've updated it here 9e63025
@monfera you are right, we can probably add that version in a subsequent PR, in the meantime I've created this issue to track it #1500 |
This commit exposes the function to compute the participation ratio of a value in the total sum of its membership group. It can be used to compute non-stacked percentage bar charts.
Backports the following commits to 38.0.x: - feat: expose computeRatioByGroups fn (#1495)
# [40.1.0](v40.0.0...v40.1.0) (2021-12-01) ### Bug Fixes * **deps:** update dependency @elastic/eui to ^41.3.0 ([#1506](#1506)) ([d364cc0](d364cc0)) * remove pointer for onElementOver ([#1493](#1493)) ([bf95dbc](bf95dbc)) * **deps:** update dependency @elastic/eui to ^41.2.1 ([#1494](#1494)) ([1c32f82](1c32f82)) ### Features * expose computeRatioByGroups fn ([#1495](#1495)) ([65f4886](65f4886))
Summary
This PR exposes the function to compute the participation ratio of a value in the total sum of its membership group.
It can be used to compute non-stacked percentage bar charts.
Right now, we only compute such data only for stacked bar charts, but exposing that utility function can also help creating non stacked bar chart.
The story was also updated to nicely match the categories used with all the edge cases considered.
Details
As described in the tsdocs: The ratio is computed using absolute values, for example:
Product A made a profit of $200, and product B has a loss of $300. In total, the company lost $100 ($200 – $300).
Product A contributed: abs(200) / ( abs(200) + abs(-300) ) * 100% = 40%
Product B contributed: abs(-300) / ( abs(200) + abs(-300) ) * 100% = 60%
Product A and product B contributed 40% and 60% respectively on a total loss of $100.
We don't compute the ratio for non-finite values. In this case, the original non-finite value is returned.
If the sum of the group values is 0, each ratio is considered 0.
Issues
It enabled the non-stacked percentage bar charts in Kibana elastic/kibana#118525
Checklist
:xy
,:partition
):interactions
,:axis
)closes #123
,fixes #123
)packages/charts/src/index.ts