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. - wrap_
text - Word-wraps
textto lines no wider thanmax_widthpx at fontsize, measured withtext_width(ggtext /str_wrapbehaviour: break at whitespace; a single word wider thanmax_widthon its own is hard-split so it never overflows the box). Returnsvec![String::new()]for empty input and otherwise always at least one line, so a caller can takelines.len()as the wrapped block’s line count without a special case. - wrapped_
block_ width - The widest wrapped line’s width (px) at font
size— the natural width of a wrapped text block, e.g. for aGeomLabelbackground box sized to fit its wrapped text.