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

fix(partition): rtl text label support #1433

Merged
merged 22 commits into from
Nov 15, 2021
Merged

Conversation

nickofthyme
Copy link
Collaborator

@nickofthyme nickofthyme commented Oct 18, 2021

Summary

Better support RTL text value in partition and xy charts. Current support is automatically applied given the label text characters.

Screen.Recording.2021-10-21.at.04.10.52.PM.mp4

Details

Partition charts parse the words individually by performing .split(' ') on the string to obtain the words. Thus the global canvas dir attribute alone will not fix the issue.

  • Add support for horizontal alignment of fill labels in partition charts, namely sunburst and treemap. Currently hardcoded as treemap && RTL->'right', treemap && not RTL->'left', sunburst->'center'. We could expose this to the user later.
  • Add RTL support for link labels in partition charts, namely sunburst and treemap.
  • Provide better styling support for RTL, specifically related to legend and tooltip.

Styles for DOM elements, not canvas, are mostly handled by default by just setting the dir or direction on an element, with a few exceptions. These exceptions are handled with css overrides for [dir=rtl].

The only visual change in this PR is that the formatted value string in fill labels used to be split to allow for better fitting. This caused issues related to RTL strings so I removed this and now the value strings act as a single string.

This PR adds pretty good support for rtl text in partition and xy charts and applies the global dir setting on the canvas element for both based on .

Missing support

  • RTL support for other charts (i.e. heatmap, goal, etc.)
  • RTL support for annotation tooltips
  • Consider using DOM elements to better render directional text labels.
  • Missing support for rotations of fill and link labels. I don't see any usage of this in kibana, or out own stories just yet.
  • Tick values should force direction when formatted. Now if using rtl strings formatted values will show in reverse.
  • Consensus on how to support value interpolation. Now just forcing all value string labels to ltr.

Issues

fix #1432

Checklist

  • The proper chart type label has been added (e.g. :xy, :partition)
  • All related issues have been linked (i.e. closes #123, fixes #123)
  • Unit tests have been added or updated to match the most common scenarios
  • The proper documentation and/or storybook story has been added or updated
  • The code has been checked for cross-browser compatibility (Chrome, Firefox, Safari, Edge)

@nickofthyme nickofthyme added bug Something isn't working :partition Partition/PieChart/Donut/Sunburst/Treemap chart related labels Oct 18, 2021
@nickofthyme nickofthyme marked this pull request as ready for review October 18, 2021 22:05
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.

It looks good, but I can't understand the language used here and I can't say if that is correct or not.
@ghudgins do you know someone that knows an RTL language to confirm our tests are valid?
The only think I see is that the RTL text in the pie starts at the bottom, I'm not sure but RTL text is not automatically a bottom to top language.

Screenshot 2021-10-19 at 11 54 59

packages/charts/src/utils/common.ts Outdated Show resolved Hide resolved
@nickofthyme
Copy link
Collaborator Author

nickofthyme commented Oct 19, 2021

@markov00 what are your thought about adding a way to set the dir attribute on the canvas? Should we attempt to set this from the data using isRTL?

UPDATE

Per zoom chat, we assign global canvas dir based on majority of strings.

- Add better alignment support for partition fill and link labels
- Better support for mixed text with force ctx.direction
- Improve legend and tooltip styles for rtl strings and mixed
Copy link
Collaborator Author

@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.

I still need to update the unit and VRT's with latest changes.

@nickofthyme nickofthyme added the :xy Bar/Line/Area chart related label Oct 25, 2021
@markov00 markov00 mentioned this pull request Nov 1, 2021
5 tasks
@markov00 markov00 requested a review from rshen91 November 1, 2021 15:59
@nickofthyme
Copy link
Collaborator Author

@elasticmachine merge upstream

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.

Changes looks good to me, tested locally and works great!

@nickofthyme nickofthyme requested a review from monfera November 5, 2021 21:25
@nickofthyme nickofthyme requested review from monfera and removed request for monfera and rshen91 November 6, 2021 17:49
Copy link
Contributor

@monfera monfera left a comment

Choose a reason for hiding this comment

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

LGTM, great addition! Thanks for adopting the small code suggestions and the addition of more RTL languages 👍

@elastic elastic deleted a comment from elasticmachine Nov 9, 2021
@nickofthyme
Copy link
Collaborator Author

Added logic to xy_chart tick labels to treat all non-ordinal labels as ltr text and ordinal tick depending on the label characters. Now formatted numerical values with pre/postfixes are correctly rendered.

Screen Recording 2021-11-09 at 09 38 22 AM

@nickofthyme nickofthyme merged commit 01bbe3a into elastic:master Nov 15, 2021
@nickofthyme nickofthyme deleted the rtl-text branch November 15, 2021 15:29
@nickofthyme nickofthyme changed the title fix(partition): rtl text labels fix(partition): rtl text label support Nov 15, 2021
nickofthyme pushed a commit that referenced this pull request Nov 15, 2021
## [39.0.1](v39.0.0...v39.0.1) (2021-11-15)

### Bug Fixes

* **partition:** rtl text label support ([#1433](#1433)) ([01bbe3a](01bbe3a))
nickofthyme added a commit to nickofthyme/elastic-charts that referenced this pull request Nov 15, 2021
support rtl text labels in xy and partition charts, including mixed ltr/rtl.
# Conflicts:
#	packages/charts/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts
#	packages/charts/src/chart_types/xy_chart/renderer/canvas/axes/tick_label.ts
#	packages/charts/src/chart_types/xy_chart/state/selectors/visible_ticks.ts
#	packages/charts/src/chart_types/xy_chart/utils/axis_utils.test.ts
#	packages/charts/src/chart_types/xy_chart/utils/axis_utils.ts
nickofthyme pushed a commit that referenced this pull request Nov 15, 2021
## [38.0.4](v38.0.3...v38.0.4) (2021-11-15)

### Bug Fixes

* **partition:** rtl text label support ([#1433](#1433)) ([#1478](#1478)) ([5d5c186](5d5c186))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working :partition Partition/PieChart/Donut/Sunburst/Treemap chart related :xy Bar/Line/Area chart related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for RTL text
6 participants