The shared Legend (spec/01 §7, spec/13 §7.4): one legend for several Frames, for a page
whose charts share a color mapping, so each of them can drop its own (legend: "none").
| Component | Name | Kind | Isolation |
|---|---|---|---|
| Legend | "macaw.legend" | :content | :pure |
| Parameter | Type | Default | Bindable | Meaning |
|---|---|---|---|---|
label | :text | nil | yes | the list's accessible name; without one, the value field's label from the schema |
hidden | :category | nil | yes | the value hidden, bound to the page's state of hidden values, its entry drawn not pressed |
- The mapping is data, not a Frame's internals. The one slot,
"entries", has the rolesvalue(:category),label(:text, optional) andcolor(:term, a column of colors, optional; data holds no color type). Bound to the field the Frames color by, whose schema declares itsvalues, the entries are the declared values in order, each labeled by its declared name and painted its declared color (the page's, in the context'scolors, else itsstatusrole's, asMacaw.Frame.Fact's:colorsreads it), else the theme's series color at its declared position: exactly what a Frame's ordinal color scale over the same field draws (Macaw.Frame.Scales, macaw_draw spec/06 §2.3). Bound to a derived source answering one row per entry, they are its rows' distinct values in order, labeled and painted by thelabelandcolorroles, a data color under the theme's 3:1 guard (spec/11 §8.2). - Entries are drawn as the frame's legend draws them: each swatch is
Macaw.Frame.Furniture.Legend.swatch/2filled withpaint/4's answer, rendered byMacaw.Draw.Render.SVG, and a label as the axis prints a value (Macaw.Draw.Axis.default_label/1) where no name is declared. - Hiding is state. A click or Enter on an entry emits
"toggle", itsvaluethe entry's value and no identity (Macaw.Component.Client.event/3); a placement maps it to a state source of the hidden values, which each Frame and this Legend'shiddenbind. Until multi-valued state (macaw#164) the Legend toggles one value. - It renders
<div class="mw-legend-box" id="<instance>-legend">holding a<ul class="mw-legend">of entries, each a<button aria-pressed>(pressed while its value is shown) holding its swatch, which carries its cue (data-mw-cue="label", the label beside it), never a color alone, and its label. It declares no hook. - Its drawn states are the contract's notices (
Macaw.Frame.Drawn.notice/3), written before the list.
Decision: the visual check set's :image, :table and :tab_stop checks do not apply
to the Legend. The visual set (macaw_component spec/04 §4) asks a component that draws
data for a named image, a <table> beside it and exactly one tab stop. The Legend draws
no data: it is a list of controls whose every entry is already text, so an image would
name nothing the list does not, a table would repeat the list, and §7's entries are
buttons, one tab stop each, since moving among them by arrow keys would need a hook,
which the Legend declares none of (§1). It runs every core check and the visual set's
:token and :svg checks.
Summary
Functions
The entries the Legend draws for context over deliveries (spec/01 §7), in order: the
declared values of the field bound to value, where its schema declares them, else the
delivered rows' distinct values. Each is %{value, label, paint}, paint resolved
against the context's theme in mode (:css by default, :literal) as the frame's
legend paints a swatch. A context or deliveries of the wrong type is a type fault at
its argument.
Types
Functions
The entries the Legend draws for context over deliveries (spec/01 §7), in order: the
declared values of the field bound to value, where its schema declares them, else the
delivered rows' distinct values. Each is %{value, label, paint}, paint resolved
against the context's theme in mode (:css by default, :literal) as the frame's
legend paints a swatch. A context or deliveries of the wrong type is a type fault at
its argument.