# `Macaw.Frame.Furniture.Legend`
[🔗](https://github.com/dcoai/macaw_frame/blob/v0.1.0/lib/macaw/frame/furniture/legend.ex#L1)

The frame's legend (spec/03 §3.3): its entries, its placement, and whether it is drawn,
all from **one layout**, so the drawing, the extent, the margin it takes and its fit
cannot disagree.

- **Entries** (§3.3.1): one per `Macaw.Draw.Scale.ticks/2` value of the scale (five of
  a continuous one), or one per declared value with `values`; a 12 × 12 swatch and, 16
  to its right, its label as the axis prints it with `prefix` and `unit`. A value with a
  declared name in its slot's schema is labeled by the name. Each entry's group carries
  `data-series`, the value's string.
- **Placement** (§3.3.2): a corner or a side, inside the plot 8 from its edges or in a
  margin 8 out from it; a top or bottom row wraps to the plot's width and in a margin
  grows that margin, `(rows − 1) × 16 + 12 + 8`. `max_label` cuts a label to
  `max_label − 1` characters and `…`, the full label kept as its `<title>` and
  `aria-label`. Text widths are the Frame's measurer's (`Macaw.Draw.Text.width/3`,
  macaw_layers#59), the estimate by default.
- **Omission** (§3.3.3): a legend that cannot be laid out is omitted, not a fault: no
  group, no margin, extent zero; the reason the first of `:min_entries`, `:cell`,
  `:row`, `:height`, `:width` that holds.
- **Fit** (§3.3.4): `status/2` is the model's `legend_fit`, `extent/2` its box less the 8.

The options: `:theme`, `:mode`, `:styles` (the design's styles), `:schemas` (each
slot's schema, for declared names) and `:bindings` (the cell's binding of each slot's
roles to the schema's fields). Copied from visualize's `Visualize.Chart.Frame.Legend`.

# `omission`

```elixir
@type omission() :: :min_entries | :cell | :row | :height | :width
```

Why a legend is omitted (§3.3.3).

# `extent`

```elixir
@spec extent(term(), term()) :: %{width: number(), height: number()}
```

The box the legend is laid out in, `%{width, height}`, not counting the 8 between it
and the plot (§3.3.4); zero with no legend or an omitted one.

# `fit`

```elixir
@spec fit(term(), term()) :: map()
```

The margin the frame takes for its legend (§3.3.2): its own, with a top or bottom margin
of a legend `inside: false` grown to the legend's rows. An omitted legend takes none.

# `generate`

```elixir
@spec generate(term(), term()) :: [Macaw.Draw.IR.Element.t()]
```

The legend group, `[]` when the frame has no legend or its legend is omitted (§3.3).

# `paint`

```elixir
@spec paint(term(), term(), term(), term()) ::
  Macaw.Layers.Color.t()
  | String.t()
  | :none
  | {:error, [{list(), term()}, ...]}
```

The paint an entry's swatch is filled with (§3.3.1): a literal color as itself, a color
value (a role, a series, a ramp position) resolved against `theme` in `mode` (`:css` or
`:literal`), and anything else, or a color value that resolves to nothing, the theme's
series role at the entry's one-based `position`. The shared Legend paints its entries
with it (spec/01 §7), so both legends show a value in one color. A wrong-typed
`position`, `theme` or `mode` is a type fault at its argument.

# `status`

```elixir
@spec status(term(), term()) :: map() | nil
```

Whether the legend is drawn (§3.3.4): `nil` with no legend, `%{status: :drawn,
entries: n}`, or `%{status: :omitted, reason: r, entries: n}`.

# `swatch`

```elixir
@spec swatch(term(), term()) ::
  Macaw.Draw.IR.Element.t() | {:error, [{list(), term()}, ...]}
```

An entry's swatch (§3.3.1): the 12 × 12 square filled with `paint` (`paint/4`'s answer),
its left edge at `x`. Every entry of the frame's legend is drawn with it, and every entry
of the shared Legend (spec/01 §7). A non-numeric `x` is a type fault at `[1]`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
