Skip to content

[Lens][XY] Truncate long axis tick labels in horizontal bar charts#268106

Merged
biamalveiro merged 11 commits into
elastic:mainfrom
biamalveiro:feat/axis-tick-label-truncation
May 25, 2026
Merged

[Lens][XY] Truncate long axis tick labels in horizontal bar charts#268106
biamalveiro merged 11 commits into
elastic:mainfrom
biamalveiro:feat/axis-tick-label-truncation

Conversation

@biamalveiro
Copy link
Copy Markdown
Contributor

@biamalveiro biamalveiro commented May 7, 2026

Summary

Wires axis tick label truncation to @elastic/charts through the new tickLabel.truncation style option, replacing previous character based truncating happening inside the formatter. We now interpret axis.truncate as pixels instead of characters now.

To fix #265517, for horizontal charts with bars and no explicit truncate, we apply a default truncation of 40% relative to the chart container's width.

Before:
Screenshot 2026-05-11 at 17 42 06

After:
Screenshot 2026-05-11 at 17 42 15

Legacy compatibility

Agg-based XY charts truncated axis tick labels by character count, and the renderer sliced tick strings to that length in the formatter. We now use elastic-charts's tickLabelMaxLength which expects a value in pixels. Without converting, a saved value like 100 would be treated as 100px instead of ~100 characters, so labels would truncate much more aggressively than before. charsToPixels used in vis_types/xy/public/to_ast.ts approximates character count to pixels so existing legacy charts and editor keep a similar behavior.

To test:

  1. Go to Machine Learning / Data Visualizer and upload file sample-k8s.csv, name index "test-h-data".
  2. Go to Saved Objects and import horizontal-bars-truncate.ndjson.zip
  3. Go to visualisation "truncate-horizontal-bar-labels", set time frame to last year.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

@biamalveiro biamalveiro changed the title [Lens][XY] Truncate long labels in horizontal bar charts [Lens][XY] Truncate long axis tick labels in horizontal bar charts May 7, 2026
@biamalveiro biamalveiro force-pushed the feat/axis-tick-label-truncation branch from a40d380 to 3758756 Compare May 11, 2026 16:23
@biamalveiro biamalveiro force-pushed the feat/axis-tick-label-truncation branch from 3758756 to 81f105c Compare May 11, 2026 19:00
@biamalveiro biamalveiro force-pushed the feat/axis-tick-label-truncation branch from 8dbca9d to 2455b6d Compare May 22, 2026 10:13
@biamalveiro biamalveiro added release_note:skip Skip the PR/issue when compiling release notes Feature:Lens backport:skip This PR does not require backporting labels May 22, 2026
return {
truncate: data.labels.truncate,
// axis expressions expect pixels, we approximate pixels from character count
truncate: charsToPixels(data.labels.truncate),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Legacy xy charts truncated axis tick labels by character count, and then in expression_xy, the formatter sliced tick strings to that length:

tickFormat={(d) => {
let value = axis.formatter?.convert(d) || '';
if (axis.truncate && value.length > axis.truncate) {
value = `${value.slice(0, axis.truncate)}...`;
}
return value;
}}

We now use elastic-charts's tickLabelMaxLength which expects a value in pixels.

Without converting, a saved value like 100 would be treated as 100px instead of 100 characters, so labels would truncate much more aggressively than before.

@biamalveiro biamalveiro marked this pull request as ready for review May 25, 2026 07:05
@biamalveiro biamalveiro requested a review from a team as a code owner May 25, 2026 07:05
Copy link
Copy Markdown
Contributor

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

Thanks, works pretty well locally!

@kibanamachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Scout Lane #33 - serverless-observability_complete / default / local-serverless-observability_complete - Hosts Page - Empty State - should show onboarding page when no data is present
  • [job] [logs] Scout Lane #9 - stateful-classic / default / local-stateful-classic - Profiling is setup and data is loaded - Admin user

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
visTypeXy 196 197 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
expressionXY 101.8KB 101.8KB +51.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
expressionXY 41.7KB 41.7KB +13.0B
visTypeXy 29.1KB 29.2KB +73.0B
total +86.0B

History

@biamalveiro biamalveiro merged commit d42ed00 into elastic:main May 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Lens release_note:skip Skip the PR/issue when compiling release notes v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Lens] Max width + middle truncation for horizontal bar labels

3 participants