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

feat: add band area chart #157

Merged
merged 11 commits into from
Apr 11, 2019
Merged

feat: add band area chart #157

merged 11 commits into from
Apr 11, 2019

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Apr 8, 2019

Summary

close #144

This PR adds a y0Accessors prop for each SeriesSpec: this property can be used to describe a dataset with bands ( with a min and max value for each data point).
It's mainly used for with AreaSeries to descibe a bounded area chart, bounded on the y axis. The y0 value, is usually a lower value than the y1, it will be rendered perpendicularly to the y1 point. On a standard area chart, the y0 value usually correspond to 0 or to the previous value in the stack. In a band-area chart, the y0 can be any value below the y1 value.

It can also be applied to bar charts, with some limitations as described below. On a barchart, the y0 value is the bottom edge of the bar.

On a stacked bar/area chart a series with a y0Accessor will be stacked on top of the below series stacking the below series y1 value with the band series y0 value. This means that if the below series at a point X has an height of 10, and the bound series has the following values: y0: 2, y1: 5 the resulting chart will push the bound series to the top starting using the following values: y0:12, y1: 15

Screenshot 2019-04-09 at 23 52 35

The IndexedGeometry object is also refactored. To limit amount of redundant code/memory object we used the same Geometry elements used on the highlight/hover process.
The structure of IndexedGeometry is slightly changed, to avoid duplicate values and to simplify tooltip formatting when rendering either y1 and y0 values.

A candlestick-like barchart can be also configured, but the y0 value is not currently displayed on the tooltip.

Screenshot 2019-04-10 at 00 27 24

After few investigation on tests, I've currently removed from the indexedGeometries map all geometry with null values on y1. This leads to a minor problem: we are not showing any tooltip on that interval, the tooltip of the crosshair is never shown.

To Dos:

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

  • This was checked for cross-browser compatibility, including a check against IE11
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios
  • Each commit follows the convention

@markov00 markov00 force-pushed the feat-band-area branch 2 times, most recently from bcb04db to 81812fa Compare April 9, 2019 20:49
@markov00 markov00 marked this pull request as ready for review April 9, 2019 21:52
@markov00 markov00 added wip work in progress :chart Chart element related issue enhancement New feature or request labels Apr 9, 2019
@markov00 markov00 mentioned this pull request Apr 9, 2019
93 tasks
@codecov-io
Copy link

codecov-io commented Apr 10, 2019

Codecov Report

Merging #157 into master will increase coverage by 0.59%.
The diff coverage is 97.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #157      +/-   ##
==========================================
+ Coverage   95.66%   96.26%   +0.59%     
==========================================
  Files          34       36       +2     
  Lines        1801     1848      +47     
  Branches      228      239      +11     
==========================================
+ Hits         1723     1779      +56     
+ Misses         65       60       -5     
+ Partials       13        9       -4
Impacted Files Coverage Δ
src/state/utils.ts 91.22% <ø> (ø) ⬆️
...onents/react_canvas/utils/rendering_props_utils.ts 100% <ø> (ø) ⬆️
src/lib/series/specs.ts 100% <ø> (ø) ⬆️
src/lib/series/rendering.ts 89.58% <100%> (+2.91%) ⬆️
src/lib/series/tooltip.ts 100% <100%> (+24.13%) ⬆️
src/lib/series/domains/y_domain.ts 100% <100%> (ø) ⬆️
src/lib/utils/interactions.ts 100% <100%> (ø) ⬆️
src/lib/series/nonstacked_series_utils.ts 100% <100%> (ø)
src/state/chart_state.ts 96.21% <87.5%> (ø) ⬆️
src/lib/series/stacked_series_utils.ts 94.73% <94.73%> (ø)
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21316d1...c2156d9. Read the comment docs.

Add a `y0Accessor` prop for each series to enable the possibility to add a lower limit to area and
bars.

close elastic#144
refactoring of the indexed geometries: removed the extra duplicated values in favour of a better
rendering geometry.
This commit also remove the wrongly conceived seriesKey with an undefined element in there. It's now a clean empty array if you wrongly specified a wrong split accessor
The logic of data structure in stacked charts is changed a bit to reflect correctly what are the initial values of the datum and what are the current stacked data
Copy link
Contributor

@emmacunningham emmacunningham left a comment

Choose a reason for hiding this comment

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

one tiny comment but overall code lgtm & tested locally on firefox. there are some places where we might be able to refactor to help with test coverage also, but since we are going to take care of this in a separate PR already anyways, i think that can be handled there.

a couple of things that can be addressed in separate PRs but just mentioning them here:

when we go back to improve the test coverage, maybe we can also add data with only negative values & mixed negative/positive. i checked the stories with data like this and the bands look fine still but might still be nice to have those in the tests to check in the future.

the other thing is that right now only one of the band values appears next to the legend element as you're hovering, which is especially noticeable when you're hovering over the top part of the band and the value next to the legend element is the value is for the bottom part of the band:

area_band

y1: number | null;
/** the optional y0 metric, used for bars or area with a lower bound */
y0?: number | null;
/** the datum */
datum?: any;
}

export interface DataSeriesDatum {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could DataSeriesDatum extend RawDataSeriesDatum? Seems like there is a lot of overlap and since they are related, might make it clearer for others in the codebase to draw this connection.

Copy link
Member Author

Choose a reason for hiding this comment

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

They are similar but they have only few things in common. The raw, is more or less the initialY part of the DataSeriesDatum. I can check and rewrite a bit those

@markov00
Copy link
Member Author

@emmacunningham thanks for the review. I will address those problems in 3 separated PRs: one for testing negative/mixed values, one for cleaning the DataSeriesDatum types and one to add either values of the band to the legend.

@markov00 markov00 merged commit a9307ef into elastic:master Apr 11, 2019
markov00 pushed a commit that referenced this pull request Apr 11, 2019
# [3.10.0](v3.9.0...v3.10.0) (2019-04-11)

### Features

* add band area chart ([#157](#157)) ([a9307ef](a9307ef)), closes [#144](#144)
@markov00
Copy link
Member Author

🎉 This PR is included in version 3.10.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Apr 11, 2019
@markov00 markov00 deleted the feat-band-area branch April 16, 2019 12:03
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:chart Chart element related issue enhancement New feature or request released Issue released publicly wip work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Band area chart
3 participants