Skip to main content

Module legend

Module legend 

Source
Expand description

Legend model — the whole legend is one rich inline document (Legend::content).

Design points:

  • Symbols are fixed-width rich segments. A line sample is a drawn horizontal rule whose em dash text is only a fallback, while a scatter sample is a geometric-shape glyph (●, ■, …) centered in its field. Each symbol form occupies the same 2 em total advance and carries a per-segment RichSegment.color override, so marks line up and use the same layout path on screen and in PNG export.
  • Everything is explicit in the SSoT. Line breaks are '\n' segments, and symbols remain inline segment sequences, so a one-line legend, mid-text symbols, and any custom arrangement are all explicit.
  • Font and font size are live. content.font / content.font_size (and per-segment overrides) are consumed at draw time, so SSoT edits after composition still apply.

Composition helpers cover the common cases: symbol_segments / series_symbol_segments build a colored symbol, append_legend_entry appends “fixed-width symbol + space + tab + label” as a new line. Fully custom layouts edit content.segments directly.

Structs§

Legend
Legend box rendered in one corner of the chart’s data area.

Enums§

LegendCorner
LegendEntryKind
Sample kinds for the convenience builders (mirrors what a series draws).

Constants§

SYMBOL_FIELD_EM
Every symbol form spans exactly this many em (× legend font size), so marks line up regardless of shape: a lone line, a lone glyph, and a line-through-glyph all advance the pen by the same fixed field.

Functions§

append_legend_entry
Append one “entry” to the legend document: a '\n' segment when content already exists, then the symbol segments, one space, a '\t' column separator, then the label (sub/superscript unicode and '\n' are interpreted by the segment mapper).
append_legend_entry_rich
Append one legend entry using already-styled label segments.
legend_entry_count
Number of auto-format legend entries recognized in a rich legend document.
remove_legend_entry
Remove one recognized auto-format legend entry. Returns false when the document does not expose that entry shape.
scatter_shape_char
The compact legend character for a ScatterShape. Exact geometric glyphs are used only when the bundled Liberation Sans face covers them; pentagon/hexagon/octagon fall back to familiar marker-code letters.
series_symbol_segments
Symbol segments matching a series declaration: line / scatter / combined, shape and color taken from the render type’s sub-styles.
set_legend_entry_label
Set one recognized legend entry label while preserving the surrounding document. If the entry does not exist, append a new auto-format entry.
symbol_segments
Symbol segments for the convenience-builder LegendEntryKind: each segment carries color: Some(color) so the mark keeps the series color independent of the document-level text color.
update_legend_symbols_preserving_text
Replace recognized entry symbols in order and keep every user text segment untouched. Custom layouts that do not expose the auto symbol+tab shape are left unchanged.