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
textset at font sizesize, 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
labelwith a trailing ellipsis (“…”) until it (plus the ellipsis) fits withinmax_widthpx at fontsize(#159: a vertical multi-column legend grid that still overflows after exhausting column reduction falls back to truncating its labels).Nonemeanslabelalready fits — no truncation needed, so the caller keeps the byte-identical untruncated path. Amax_widthtoo narrow for even a bare “…” still returnsSome("…")— the best any truncation can do — rather than an empty string.