Skip to content

Hide axis labels clipped at the chart edge#1295

Merged
mstijak merged 1 commit into
masterfrom
feature/1291-axis-clipped-labels
May 19, 2026
Merged

Hide axis labels clipped at the chart edge#1295
mstijak merged 1 commit into
masterfrom
feature/1291-axis-clipped-labels

Conversation

@mstijak
Copy link
Copy Markdown
Member

@mstijak mstijak commented May 19, 2026

Summary

Fixes #1291 — on time axes the first/last label is anchored on a boundary tick and frequently gets clipped at the chart edge.

Adds a hideClippedLabels flag to Axis. When set, a boundary label that would overflow the chart edge is dropped — together with its tick.

How it decides

A label's reach toward an edge is estimated as a fraction of minLabelDistance (the minimum label spacing), scaled by the text anchor:

labelAnchor reach toward left edge reach toward right edge
start 0 80%
middle 40% 40%
end 80% 0

A label is dropped when s + rightReach > chartBounds.r or s - leftReach < chartBounds.l. This is pure geometry, so it handles first, last, and inverted axes automatically — no text measurement needed.

Details

  • The check uses instance.parentRect (the chart's bounds), not the axis bounds — correct for an axis inset within its chart, and per-chart when one Svg hosts several charts.
  • The reach values depend only on the anchor, so they're resolved once above the tick loops.
  • A clipped label is dropped with its major tick; minor ticks render via a separate path and are untouched.
  • Horizontal axes only (minLabelDistance ≈ label width is a horizontal heuristic).
  • Axis default false; TimeAxis default true — wide, start-anchored time labels make edge clipping the common case.

Testing

  • yarn test: 508 passing; yarn check-types: clean.
  • No axis rendering tests exist in the repo — this is a visual change, worth eyeballing in the gallery/docs.

Adds a `hideClippedLabels` flag to Axis. When set, a boundary (first/last)
label that would overflow the chart edge is dropped together with its tick.

A label's reach toward an edge is estimated as a fraction of minLabelDistance
based on its text anchor (start/end 80%, middle 40%). The check is made
against the chart bounds (parentRect), not the axis bounds, so it is correct
for inset axes and for multiple charts within one Svg. Minor ticks render via
a separate path and are unaffected.

Defaults to false on Axis and true on TimeAxis, where wide start-anchored
labels make edge clipping the common case.

Closes #1291
@netlify
Copy link
Copy Markdown

netlify Bot commented May 19, 2026

Deploy Preview for cxjs-docs ready!

Name Link
🔨 Latest commit 32baa79
🔍 Latest deploy log https://app.netlify.com/projects/cxjs-docs/deploys/6a0c32f6fc01300008a8ff5d
😎 Deploy Preview https://deploy-preview-1295--cxjs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mstijak mstijak merged commit 2f200ec into master May 19, 2026
6 checks passed
@mstijak mstijak deleted the feature/1291-axis-clipped-labels branch May 19, 2026 09:59
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.

Last label on time axes gets clipped at the chart edge

1 participant