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

[Elastic Charts] Added value labels styles for bar charts #4845

Merged
merged 22 commits into from
Sep 16, 2021

Conversation

elizabetdev
Copy link
Contributor

@elizabetdev elizabetdev commented Jun 1, 2021

Summary

Closes #4267.

This PR adds better value labels default styles for bar charts.

By default the value labels once enabled are going to:

  • Be vertical and horizontal centered. The ideal positions would be based on the rotation of the bars. But this can't be achieved because we can't pass to the theme object what is the current rotation. So vertical and horizontal centered labels seem a good compromise.
  • The color will adapt to black or white according to the background (textInvertible)

Frame 5@2x

The following demo #/elastic-charts/categorical was updated and a "Show value labels" switch was added. The value labels adapt the position according to the configuration. They are positioned close to the edge of the bars.

Screenshot 2021-09-09 at 17 01 38

When it's multi-series and stacked the value labels are positioned vertically and horizontally in the center.

Screenshot 2021-09-09 at 17 01 54

Checklist

  • Check against all themes for compatibility in both light and dark modes
  • [ ] Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • [ ] Props have proper autodocs and playground toggles
  • [ ] Added documentation
  • [ ] Checked Code Sandbox works for the any docs examples
  • [ ] Added or updated jest tests
  • [ ] Checked for breaking changes and labeled appropriately
  • [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

1 similar comment
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

@elizabetdev elizabetdev changed the title [Elastic Charts] Adding new theme value labels styling [Elastic Charts] Added value labels styles for bar charts Jul 27, 2021
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

@elizabetdev elizabetdev marked this pull request as ready for review July 27, 2021 17:12
@elizabetdev elizabetdev requested review from markov00 and cchaos July 27, 2021 17:13
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

👍 💯 Much better defaults for sure!

I have mainly suggestions around documentation and giving more to the consumer than just a toggle.

CHANGELOG.md Outdated Show resolved Hide resolved
src-docs/src/views/elastic_charts/category_chart.js Outdated Show resolved Hide resolved
Co-authored-by: Caroline Horn <[email protected]>
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

@elizabetdev elizabetdev requested a review from cchaos July 28, 2021 17:48
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

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 only one comment:
when rendering stacked bars, I agree with the choice of having the labels centered in the bars, the value corresponds to the size of the bar and is not directly connected with the Y-axis.
Instead, when you only have a single series, the label could be placed near the top edge of the bar. In that way, you link the label to its corresponding position on the Y-axis. This also limits the eye movements when reading the bar, reducing the gap between the top edge and the value label.
Using your screenshot as an example, I'm noticing that my eyes are focused or on the value labels (centered) or on the bars' shape/trend. Moving the label closer to the edge makes the readability easier
image

@markov00 markov00 requested a review from monfera July 29, 2021 12:53
@monfera
Copy link

monfera commented Jul 29, 2021

I agree it'd be better for the numbers in the non-stacked case to be at the top. Also, the custom is that if there's room past the single bar (in the positive or negative direction, wherever the bar extends toward) then the label would be outside the bar. There's more text contrast there. Example elastic/elastic-charts#1277

This may not be the place to raise this issue, but our bar charts, and charts in general are configured with a suboptimal balance of font size and data glyph (bar rectangle, etc.) shape. The fonts are small and the data shapes are large. It looks like a functional prototype not the final product. It's also an issue from an accessibility viewpoint: the user gets a huge piece of help in determining the screenspace size of the data shapes, but it's at the expense of font size. Also, even if there's ample room and the user has something like 3 bars, it shouldn't take up all that space. There ought to be a ratio of font size to bar width. For example, on the above images, the bar thickness is easily 3x that of the category labels, and the slightly taller value label inside the bar is also barely over 1/3rd of the height. 1.618x (golden ratio) to around 2x ratio would work but 3x is visually and accessibility wise unbalanced. Eg. this uses around 2x, despite few bars (if there are many bars, it's OK for the text to be about as tall as the bar is thick). This page has a couple of bad examples or unsupported advice, but most charts have a good font/shape balance. Big bars, small fonts is the main way to recognize Kibana visualizations in the wild
elastic/elastic-charts#1276

@elizabetdev
Copy link
Contributor Author

Instead, when you only have a single series, the label could be placed near the top edge of the bar. In that way, you link the label to its corresponding position on the Y-axis. This also limits the eye movements when reading the bar, reducing the gap between the top edge and the value label.

@markov00 I agree. But how can I get this as default in the theme? The theme is static and doesn't know what is the current rotation state. Inside the theme object, we don't know if the chart is rotated or if it is stacked. That's why I had to pick one default alignment that would make more sense to most use cases.

Then in the demo, we're showing that you don't need to use the defaults but implement an alignment that makes sense:
Frame 1@2x

The first time a value label is enabled it is aligned at the end of the bar chart. But then you have the option to center align. The idea is that users can play around with the toggles and copy the configuration that makes sense for their use case. We even recommend just use value labels when it's strictly necessary.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

@elizabetdev
Copy link
Contributor Author

Default theme

@markov00 as we agreed, the default theme keeps the value labels vertically/horizontally centered.

Demo (https://eui.elastic.co/pr_4845/#/elastic-charts/categorical)

@cchaos and @markov00 for the demo in our docs, I removed the center value labels switch option. Now according to the configuration, the value labels adapt.

when rendering stacked bars, I agree with the choice of having the labels centered in the bars

✔️ When stacked the labels get centered

Screenshot 2021-09-09 at 17 01 54

Instead, when you only have a single series, the label could be placed near the top edge of the bar.

✔️ They are now positioned near the edge of the bar

Screenshot 2021-09-09 at 17 15 55

Generated configuration

I also improved the data of the "Copy code of current configuration" and removed the orderBy (lodash) that was included in the generated code.

Frame 3

Next

Also, the custom is that if there's room past the single bar (in the positive or negative direction, wherever the bar extends toward) then the label would be outside the bar. There's more text contrast there. Example elastic/elastic-charts#1277

@monfera I'm looking forward to elastic/elastic-charts#1277. Render bar labels outside of the bar is going to be a great enhancement. 👍🏽

@markov00 and @cchaos can you both do another review?

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

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.

Looks good to me, tested locally, and works great.

<EuiFlexItem>
<ChartCard
title="Value labels"
description="Value labels can add too much detail and make categorical charts more difficult to interpret. Consider showing them only when the values are of extreme importance."
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: usually the reason why you want to show numbers on a chart is that you want to clearly present the exact number (all digits/decimal digits are important). If that is the case, a suggestion could be to include, on the side, a small table that definitely shows clearly all the numbers and allow the user to sort them by value or categories.

Comment on lines 86 to 87
offsetX: rotated ? 2 : 0,
offsetY: rotated ? 0 : -2,
Copy link
Member

Choose a reason for hiding this comment

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

From what I see, this is used as padding on the text. We can probably introduce a default or custom padding and we can get rid of this part

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree 👍🏽

Copy link
Contributor

Choose a reason for hiding this comment

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

Optional, but I'd love to see even more separation.

Suggested change
offsetX: rotated ? 2 : 0,
offsetY: rotated ? 0 : -2,
offsetX: rotated ? 4 : 0,
offsetY: rotated ? 0 : -4,

@@ -100,9 +100,17 @@ function createTheme(colors: any): EuiChartThemeType {
},
barSeriesStyle: {
displayValue: {
fontSize: 8,
fontSize: 10,
Copy link
Member

Choose a reason for hiding this comment

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

You can also set a min and max font size, the code automatically uses the right size depending on the available space.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Overall the new toggle and theme settings LGTM. Had a couple questions and suggestions, but ok to merge in as-is.

CHANGELOG.md Outdated Show resolved Hide resolved
<Axis
id="left-axis"
position={${rotated ? '"bottom"' : '"left"'}}
${formatted ? 'tickFormat={d => `${round(Number(d) / 1000, 2)}k`}' : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

@markov00 The one thing I noticed is that when we format the tick labels on a particular axis, it does also get applied to the showValueLabel setting, except when the chart gets rotated. Is this a known issue in elastic-charts?

Screen Shot 2021-09-14 at 11 45 57 AM

Copy link
Member

Choose a reason for hiding this comment

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

thank you @cchaos you are right, this is an issue in our code. I will check and fix the bug soon.

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 86 to 87
offsetX: rotated ? 2 : 0,
offsetY: rotated ? 0 : -2,
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional, but I'd love to see even more separation.

Suggested change
offsetX: rotated ? 2 : 0,
offsetY: rotated ? 0 : -2,
offsetX: rotated ? 4 : 0,
offsetY: rotated ? 0 : -4,

src-docs/src/views/elastic_charts/category_chart.js Outdated Show resolved Hide resolved
src-docs/src/views/elastic_charts/category_chart.js Outdated Show resolved Hide resolved
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4845/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate new XY Chart theme value labels styling
5 participants