-
Notifications
You must be signed in to change notification settings - Fork 120
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): scaled font size for value labels #789
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.
Thank you @wylieconlon for the PR.
I've added a suggestion to make this work to compute that target font size in a more precise way than the current proposed solution.
If you need the chart rotation parameter, unfortunately is not available at that level, but you can pass it down from computeSeriesGeometries
==> renderGeometries
==> renderBars
I've also a doubt about the readability of the text using this varying-font-size approach:
longer text (due to more decimal points or higher value) can results in smaller font sizes (see the image as an extreme example).
On a data visualization, these font changes can be interpreted in different ways from the users, assuming more importance to bigger texts rather than the smaller ones. Uniform font sizes are preferable if we don't need to communicate any exceptional significance to that value. @monfera @nickofthyme thoughts on that?
@markov00 Thanks for the feedback! I agree that uniform font sizes would look much better. To implement your suggestion, I think we would need to calculate the formatted values for all bars, and then scale the font size based on the highest character count of the formatted values. What do you think about that approach? |
I think we should compute the bounding box of all the formatted values and then scale the font size based on the maximum width of these boundingboxes. |
@markov00 Do you think it makes sense to change from |
@wylieconlon we can have that change without introducing a breaking change if we use a union type that covers two cases: fixed font size or scaled font size. Something like this could work: export interface TextStyle {
fontSize: number | { min: number; max: number };
...
} With that, we can handle both use cases: users that want a specific fixed font size + users that look at a scalable font size |
Introduce a range size format for bar chart labels to auto scale and improve readability Address elastic#788
Reworked the PR to address the various feedback:
|
displayValueSettings, | ||
); | ||
|
||
const isHorizontalRotation = chartRotation == null || [0, 180].includes(chartRotation); |
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.
Either the logic or naming is wrong, the horizontal charts are 90 and 270: https://elastic.github.io/elastic-charts/?path=/story/rotations--rotations-90-deg-ordinal
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.
Eheh I had a chat with @markov00 about that the other day. He explained to me that their naming reference where the bars are located (for a vertical bar chart they are located on the x axis, therefore horizontal
).
I used isVertical
here before which makes more sense for me as well, then changed after the chat as consitency is best when maintain the codebase.
Always show labels if enabled but stick min/max values when auto scaling go beyond them
Sync API with the new fontsize format changes for bar charts
Codecov Report
@@ Coverage Diff @@
## master #789 +/- ##
==========================================
- Coverage 70.01% 69.98% -0.03%
==========================================
Files 321 336 +15
Lines 10508 10189 -319
Branches 2221 2031 -190
==========================================
- Hits 7357 7131 -226
+ Misses 3142 2991 -151
- Partials 9 67 +58
Flags with carried forward coverage won't be shown. Click here to find out more.
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.
Looks good to me, I've checked the code and tested locally seems to work fine and scales correctly all the values. I've check also the scale with very different value lengths and seems to scale correctly per bar.
I've left a few comments to address (division by zero checks) and some other nit picks
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, that's related to this bug: #786 . |
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.
Tested locally and it looks very good!
Just a small typo on the story title
Co-authored-by: Marco Vettorello <[email protected]>
💚 CLA has been signed |
338fd5d
to
0d4e56f
Compare
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.
Looking good @dej611! I can't approve since this is technically my own PR, but left some small comments.
fill: color('value color', '#000'), | ||
offsetX: number('offsetX', 0), | ||
offsetY: number('offsetY', 0), | ||
alignment: { |
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.
The alignment properties don't appear to do anything yet, maybe remove this?
h: frozenDataHighVolume, | ||
}; | ||
|
||
export const Example = () => { |
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've created a new storybook, but I noticed that you didn't update the existing storybook for value labels. I found it a little confusing not to have these options on the "value label" storybook. Would it be worth combining into a single story?
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.
I've left this in here as it will probably be merged with other stories in related PRs to make an Advanced value label
story.
Codecov Report
@@ Coverage Diff @@
## master #789 +/- ##
==========================================
+ Coverage 69.58% 69.64% +0.06%
==========================================
Files 321 336 +15
Lines 10605 10269 -336
Branches 2187 2066 -121
==========================================
- Hits 7379 7152 -227
+ Misses 3217 3050 -167
- Partials 9 67 +58
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
# [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.
🎉 This PR is included in version 24.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [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.
This is my first attempt at creating scaled font sizes for text in the bar charts, which has similarity to the scaling logic that is implemented in partition charts by @monfera. I've applied the simplest possible logic, which is to take the maximum font size that fits these restrictions:
It doesn't work correctly for horizontal charts because I don't know how to determine rotation.
Fixes #788
Checklist
Delete any items that are not applicable to this PR.
src/index.ts
(and stories only import from../src
except for test data & storybook)