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(bar_chart): add Alignment offset to value labels #784

Merged
merged 6 commits into from
Oct 13, 2020

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Aug 19, 2020

Make it possible to position value labels based on bar relative geometry

Summary

This is a draft proposal for value label positioning within the bar chart with relative alignment.

value-positioning

There are still some open questions, such:

  • what should the default value be? Each chart rotation configuration has its own default alignment, so, for the moment, I've just extended the TextAlignment in this scenario to handle undefined values
  • Should explicit positioning have a different behaviour from similar "default" positioning?
    • for instance when there are short bars the default configuration may propose an "overlapping" solution, but what about explicit alignment?

Checklist

  • This was checked for cross-browser compatibility
  • 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

Make it possible to position value labels based on bar relative geometry
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

I've put a small comment on how to refactor the long list of switch/if
I'm ok with the approach and the proposed API for that

@dej611 dej611 self-assigned this Sep 18, 2020
Sync new labels alignment feature API with the doc
@dej611 dej611 marked this pull request as ready for review September 28, 2020 08:28
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Everything seems to work fine except for a 180 degree rotation where: the vertical alignment is not working well
Screenshot 2020-09-29 at 10 52 06
Screenshot 2020-09-29 at 10 51 59

Screenshot 2020-09-29 at 10 52 12

Also please note that the debug rectangle doesn't reflect the alignment: try to flag the debug check on the label story and you will see the issue when changing the alignment.

One more thing to add:
it will be great to have VRTs for every situation: all rotation + all configuration of alignment.
Please take a look at integration/tests/interactions.test.ts and a new set of tests for the various situations (you can run the VRTs for a specific file and/or a subset of tests with yarn test:integration:local your_test_file_name.test.ts --testNamePattern "your test name"

Comment on lines 38 to 43
const CHART_ROTATION: Record<string, Rotation> = {
BottomUp: 0,
TopToBottom: 180,
LeftToRight: 90,
RightToLeft: -90,
};
Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% sure what are you referring to with these directions. All these terms resemble a mirror/flip action more than a rotation.
If you are using these to simplify the understanding of the rotation, please add a comment on the code where you are using them (like in each case of the switch few lines below

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I don't think this is necessary, we could just make a comment on each of the switch cases below. Unless you are planning to expose this constant to the consumer for simplicity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the original idea was to export them as they may be more readable than numbers.
Not really in the scope of this PR, but they helped to code the solution giving some more semantic.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If that's the case I think we should rename the enum from CHART_ROTATION to something more descriptive.

Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

Tested locally and works great, just left a few comments.

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM, adding some functional test will be great to avoid regressions:
please take a look at: integration/tests/interactions.test.ts on how to create VRTs with different knob options

@codecov-io
Copy link

codecov-io commented Oct 12, 2020

Codecov Report

Merging #784 into master will decrease coverage by 2.39%.
The diff coverage is 3.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #784      +/-   ##
==========================================
- Coverage   74.29%   71.90%   -2.40%     
==========================================
  Files         270      337      +67     
  Lines        9274    11929    +2655     
  Branches     1991     2589     +598     
==========================================
+ Hits         6890     8577    +1687     
- Misses       2377     3327     +950     
- Partials        7       25      +18     
Flag Coverage Δ
#unittests 69.64% <3.65%> (-4.65%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/utils/themes/theme.ts 100.00% <ø> (ø)
...chart_types/xy_chart/renderer/canvas/values/bar.ts 8.63% <3.65%> (-2.48%) ⬇️
src/utils/events.ts 83.33% <0.00%> (-16.67%) ⬇️
src/components/tooltip/tooltip.tsx 63.84% <0.00%> (-6.95%) ⬇️
.../chart_types/goal_chart/state/selectors/tooltip.ts 33.33% <0.00%> (-5.13%) ⬇️
src/chart_types/xy_chart/utils/series.ts 91.54% <0.00%> (-4.00%) ⬇️
.../chart_types/partition_chart/state/chart_state.tsx 71.42% <0.00%> (-3.58%) ⬇️
...t_types/partition_chart/state/selectors/tooltip.ts 28.00% <0.00%> (-2.44%) ⬇️
src/chart_types/xy_chart/utils/fill_series.ts 97.82% <0.00%> (-2.18%) ⬇️
src/state/chart_state.ts 90.90% <0.00%> (-1.60%) ⬇️
... and 102 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 e7a8a30...c2ed230. Read the comment docs.

Copy link

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Works well!

@dej611 dej611 merged commit 363aeb4 into elastic:master Oct 13, 2020
@dej611 dej611 deleted the feature/value-label-alignment branch October 13, 2020 13:11
markov00 pushed a commit that referenced this pull request Oct 19, 2020
# [24.0.0](v23.2.1...v24.0.0) (2020-10-19)

### Bug Fixes

* **annotation:** annotation rendering with no yDomain or groupId ([#842](#842)) ([f173b49](f173b49)), closes [#438](#438) [#798](#798)

### Features

* **bar_chart:** add Alignment offset to value labels ([#784](#784)) ([363aeb4](363aeb4))
* **bar_chart:** add shadow prop for value labels ([#785](#785)) ([9b29392](9b29392))
* **bar_chart:** scaled font size for value labels ([#789](#789)) ([3bdd1ee](3bdd1ee)), closes [#788](#788)
* **heatmap:** allow fixed right margin ([#873](#873)) ([16cf73c](16cf73c))

### BREAKING CHANGES

* **bar_chart:** The `DisplayValueStyle` `fontSize` property can now express an upper and lower bound as size, used for the automatic scaling.
* **bar_chart:** The `DisplayValueStyle` `fill` property can now express a border color and width, or let the library pick the best match based on contrast using the textInvertible parameter.
@markov00
Copy link
Member

🎉 This PR is included in version 24.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Oct 19, 2020
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [24.0.0](elastic/elastic-charts@v23.2.1...v24.0.0) (2020-10-19)

### Bug Fixes

* **annotation:** annotation rendering with no yDomain or groupId ([opensearch-project#842](elastic/elastic-charts#842)) ([6bad0d7](elastic/elastic-charts@6bad0d7)), closes [opensearch-project#438](elastic/elastic-charts#438) [opensearch-project#798](elastic/elastic-charts#798)

### Features

* **bar_chart:** add Alignment offset to value labels ([opensearch-project#784](elastic/elastic-charts#784)) ([106d924](elastic/elastic-charts@106d924))
* **bar_chart:** add shadow prop for value labels ([opensearch-project#785](elastic/elastic-charts#785)) ([de95b44](elastic/elastic-charts@de95b44))
* **bar_chart:** scaled font size for value labels ([opensearch-project#789](elastic/elastic-charts#789)) ([8b74a9d](elastic/elastic-charts@8b74a9d)), closes [opensearch-project#788](elastic/elastic-charts#788)
* **heatmap:** allow fixed right margin ([opensearch-project#873](elastic/elastic-charts#873)) ([dd34574](elastic/elastic-charts@dd34574))

### BREAKING CHANGES

* **bar_chart:** The `DisplayValueStyle` `fontSize` property can now express an upper and lower bound as size, used for the automatic scaling.
* **bar_chart:** The `DisplayValueStyle` `fill` property can now express a border color and width, or let the library pick the best match based on contrast using the textInvertible parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants