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-segmentRichSegment.coloroverride, 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§
- Legend
Corner - Legend
Entry Kind - 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 carriescolor: 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.