feat(axis): add option to truncate axis tick labels#2829
Conversation
f68416b to
b1ce36e
Compare
|
buildkite update vrt |
nickofthyme
left a comment
There was a problem hiding this comment.
Sorry for the delay, I wanted to really understand the logic and test it out.
I left a few things to check out and resolve before merging but nothing real major.
Really nice PR! 🚀
99aac32 to
647d820
Compare
|
buildkite test this |
|
buildkite update vrt |
|
buildkite update vrt |
nickofthyme
left a comment
There was a problem hiding this comment.
I added a few more comments. I'm a little more doubtful about applying this to both axes instead of just the vertical axis, at least for this first pass to close the kibana issue. Also think it may be better to split the setting to control horizontal and vertical truncation separately.
058c5a0 to
907e944
Compare
907e944 to
2792327
Compare
2f05ea9 to
5bd1830
Compare
nickofthyme
left a comment
There was a problem hiding this comment.
This looks great! Sorry for all the back and forth. In the end, I think it ended up in a good spot.
|
Thanks @nickofthyme for having a thorough look at this + helping think through and improve the solution! |
# [71.7.0](v71.6.1...v71.7.0) (2026-05-20) ### Features * **axis:** add option to truncate axis tick labels ([#2829](#2829)) ([e0c8e72](e0c8e72))
## Summary This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@elastic/charts](https://togithub.com/elastic/elastic-charts) | dependencies | minor | [`71.6.1` -> `71.7.0`](elastic/elastic-charts@v71.6.1...v71.7.0) | ### Release Notes #### [71.7.0](elastic/elastic-charts@v71.6.1...v71.7.0) (2026-05-20) Features • axis: add option to truncate axis tick labels ([#2829](elastic/elastic-charts#2829)) ([e0c8e72](elastic/elastic-charts@e0c8e72))
## Summary This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@elastic/charts](https://togithub.com/elastic/elastic-charts) | dependencies | minor | [`71.6.1` -> `71.7.0`](elastic/elastic-charts@v71.6.1...v71.7.0) | ### Release Notes #### [71.7.0](elastic/elastic-charts@v71.6.1...v71.7.0) (2026-05-20) Features • axis: add option to truncate axis tick labels ([elastic#2829](elastic/elastic-charts#2829)) ([e0c8e72](elastic/elastic-charts@e0c8e72))
## Summary This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@elastic/charts](https://togithub.com/elastic/elastic-charts) | dependencies | minor | [`71.6.1` -> `71.7.0`](elastic/elastic-charts@v71.6.1...v71.7.0) | ### Release Notes #### [71.7.0](elastic/elastic-charts@v71.6.1...v71.7.0) (2026-05-20) Features • axis: add option to truncate axis tick labels ([#2829](elastic/elastic-charts#2829)) ([e0c8e72](elastic/elastic-charts@e0c8e72))
Summary
Adds ability to set a maximum length for axis tick labels, and truncate in case of overflow. Truncation can be configured to happen at start, middle or end of the string.
Details
AxisStyle.tickLabelconfig has two new optional properties:maxLength(Pixels, or a string such as80%, in relation to the container's width) andtruncate(end,start, ormiddle). Formatters are wrapped withwithTickLabelTruncation, so they are truncated if they overflow.Additionally, this PR extends
fitTextto support truncation at start or middle of string, not only trailing ellipsis (end). This updated implementation searches for fit based on what is drawn (including the...when text is clipped), while the previous used the length of the prefix before swapping last character with an ellipsis. This led to ~1 character differences in snapshots that used text truncation, (whenwidth(slice(0, v))is different fromwidth(slice(0, v−1) + …)). Updated VRT to fix these misses.Added a story where this behavior can be tested.
Scope / follow-ups
This is intentionally a first pass: truncation is applied at the formatter using a max length in pixels (and optional ellipsis position), not a full label-box sizing model.
An idea of having
minSize/size/maxSizeon axis labels for more control was discussed but needs more thought, as it goes intolabelBoxcalculations and we need to consider rotated labels and vertical/horizontal axis. Scoped out for this change, but to be revisited later.Issues
Related to elastic/kibana#265517
Checklist
:interactions,:axis)closes #123,fixes #123)packages/charts/src/index.ts