Skip to main content

Module text

Module text 

Source
Expand description

Text-metric helpers for axis-label fit (B3-1): ggplot-rs owns the outer-label-overflow and check.overlap logic centrally, instead of a downstream consumer post-processing rendered SVG (the old approach had to re-parse <text> elements out of the markup).

Ported verbatim from the consumer’s ticks.rs em table and TickLabel::bbox, which is the only reason the measurements match what callers previously saw.

Functions§

text_width
Estimated width (px) of text set at font size size, in the house sans (Hanken Grotesk, or the system UI font it falls back to). This is a heuristic per-character average-width table, not real font metrics — good enough for layout decisions (fit, overlap, auto-wrap), not for pixel-perfect text extents.
truncate_to_width
Shorten label with a trailing ellipsis (“…”) until it (plus the ellipsis) fits within max_width px at font size (#159: a vertical multi-column legend grid that still overflows after exhausting column reduction falls back to truncating its labels). None means label already fits — no truncation needed, so the caller keeps the byte-identical untruncated path. A max_width too narrow for even a bare “…” still returns Some("…") — the best any truncation can do — rather than an empty string.