-
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(series): stack series in percentage mode #250
Conversation
This commit will add a new props that allows stacking bars, areas and lines using the percentage mode. For each stacked x value, we scale their value to the percentage on that bucket. fix elastic#222
Codecov Report
@@ Coverage Diff @@
## master #250 +/- ##
==========================================
+ Coverage 97.76% 97.97% +0.21%
==========================================
Files 36 36
Lines 2641 2920 +279
Branches 590 702 +112
==========================================
+ Hits 2582 2861 +279
+ Misses 52 50 -2
- Partials 7 9 +2
Continue to review full report at Codecov.
|
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.
Left a few inline code comments, some other things that I've noticed:
last bucket value in legend is not visible in legend when bars are clustered
The current hover value is visible, but not the default last value.
multiple series
We should be careful to document this for the consuming users so that they understand that for stackAsPercentage
to work correctly, the need to define stackAccessors
for each series or else the chart will look quite strange. Below is what the chart looks like if you enable stackAsPercentage
on one series but only define stackAccessors
for one series:
Can we also add a story for the area series?
Also, should stackAsPercentage
be unavailable as a prop on a line series? It seems to me that without the context that is provided by the area series, this prop with a line series could present very misleading data to the point that we shouldn't expose it as a possibility for consumer users because it would lead to a very bad practice.
} else if (customDomain && isUpperBound(customDomain)) { | ||
if (computedDomainMin > customDomain.max) { | ||
throw new Error(`custom yDomain for ${groupId} is invalid, computed min is greater than custom max`); | ||
let domain: number[]; |
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.
Should we use the Domain
type 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.
Yes and no. On the Y Axis we, currently can handle only numeric values, so the domain here is number[]
, or better: it should be [number, number]
. What do you think?
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.
ahhh yes, of course. Yes I agree [number, number]
; maybe in the future we can consider how to tighten the Domain
type so that we can between distinguish between types of domains so it is clearer.
src/lib/series/specs.ts
Outdated
/** | ||
* Stack each series in percentage for each point. | ||
*/ | ||
stackAsPercentage?: boolean; |
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.
It is possible to define a series with empty/undefined stackAccessors
and stackAsPercentage=true
. While functionally it ends up rendering ok, it seems we may want to consider how to constrain these "impossible states" in a way that makes it easy for the user to understand what options are available to them given certain other prop configurations.
I don't think this needs to be addressed in this PR because we also have a few other "impossible states" that can be configured currently, but wanted to start the discussion in case that is something we want to explore. This is a talk about how to achieve such a semantics in Elm, but certainly not unique to Elm and something that we could do using Typescript/React.
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.
Sure, that should be addressed here: #85
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, verified locally.
@emmacunningham this is addressed on 3093ec9:
|
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.
Changes LGTM!
Add the `stackAsPercentage` prop to allow stacking bars and areas computing the percentage of each data point on each bucket/x value. fix elastic#222
# [7.2.0](elastic/elastic-charts@v7.1.0...v7.2.0) (2019-07-05) ### Bug Fixes * **ticks:** fill in additional ticks for histogram ([opensearch-project#251](elastic/elastic-charts#251)) ([8045531](elastic/elastic-charts@8045531)) ### Features * **series:** stack series in percentage mode ([opensearch-project#250](elastic/elastic-charts#250)) ([892a826](elastic/elastic-charts@892a826)), closes [opensearch-project#222](elastic/elastic-charts#222)
Summary
This PR will add a new props that allows stacking bars, areas and lines using the percentage
mode. For each stacked x value, we scale their value to the percentage on that bucket.
That option mode is applied by groups of series (specified by
groupId
) so you need to specify only one prop on one of the group series the property:stackAsPercentage={true}
100% stacked bars:
100% stacked areas:
100% stacked areas with
y0accessors
on a single area:100% stacked areas with
y0accessors
on multiple areas:fix #222
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.src/index.ts
(and stories only import from../src
except for test data & storybook)