# `Macaw.Frame.Layer.Draw`
[🔗](https://github.com/dcoai/macaw_frame/blob/v0.1.0/lib/macaw/frame/layer/draw.ex#L1)

The drawing rules every layer kind shares (spec/04 §1.7), copied from visualize's
`Visualize.Chart.Mark` (the group), `Visualize.Chart.Mark.Series`, `.Strokes`,
`.Styled` and `.Identity`.

A kind's `draw/3` builds its **children**, one per element it draws, each a map:

  * `element` - the generator's own `Macaw.Draw.IR.Element`, so a layer is byte for
    byte the direct call with the same numbers;
  * `row` - the row's index in the layer's rows, or `nil` for an element no row draws;
  * `series` - the series value the element draws, or `nil`;
  * `anchor` - its inline label's anchor point `{x, y}` (§1.8.1), `nil` for none;
  * `bounds` - `{x, y, w, h}` of a rectangular element, for the edge anchors and the
    fit; `extent` the width a label fits into, `:none` for any; `radii` an arc's radii;
  * `tail` - `true` for the provisional part of a cut path (§1.12).

and hands them to `group/4`, which applies every shared rule in one pass:

1. **Series** (§1.7.2): each element of a series carries `data-series` (`to_string/1`
   of the value) and is painted the series' color: the frame's `color` scale's value
   for it when the frame declares the scale (a value outside its domain takes the
   scale's `unknown`), else the theme's series role for the series' position among the
   layer's series values; anything more specific wins. A `nil` series names none.
2. **Paint and parts** (§1.7.3): the group carries the resolved style's keys of the
   parts the kind declares, and its paint key: the style's, else the theme's series role
   for the layer's position among the document's layers; a stroked kind takes `fill:
   none`. A `{:field, f}` binding is read per element from its row; one reading `nil`
   is `none`. Every color is a theme role or a value bound from data, which carries its
   cue (`data-mw-cue`).
3. **Keys and identity** (§1.7.5): every element drawn from a row carries `data-row`;
   the group carries `data-frame` and `data-layer`; a moving layer's elements carry
   `data-mw-id`, `<frame>.<layer>.<identity>`.
4. **Tooltip** (§1.9): the datum attributes of each element's row, and the group's.
5. **Stroke placement** (§1.7.4): `inside`, `outside` and `double`, drawn by the kind.
6. **The polar bend**: a kind that `bend?/0` is bent by the model.
7. **The group** (§1.7.1): one group `class="mw-layer mw-layer-<kind>"`, or the
   wrapper of an elements group and a labels group when the layer has a label
   (`Macaw.Frame.Layer.Label`); a centered kind outside a polar frame translates its
   group to the plot's center.

Pixels are columns (§1.12): a kind zips the columns of `Macaw.Frame.Layer.Read` into
its children in one pass, and only an edge that names a row reads it, by index.

# `child`

```elixir
@type child() :: %{
  :element =&gt; Macaw.Draw.IR.Element.t(),
  optional(:row) =&gt; non_neg_integer() | nil,
  optional(:series) =&gt; term(),
  optional(:anchor) =&gt; tuple() | nil,
  optional(:bounds) =&gt; {number(), number(), number(), number()} | nil,
  optional(:extent) =&gt; number() | :none | nil,
  optional(:radii) =&gt; {number(), number()} | nil,
  optional(:tail) =&gt; boolean()
}
```

One element a kind draws, with what the shared rules read of it.

# `class`

```elixir
@spec class(map()) :: String.t()
```

The group's class: `mw-layer mw-layer-<kind>`, then the style's own class.

# `context`

```elixir
@spec context(map(), Macaw.Data.Table.t(), Macaw.Frame.Coordinates.Model.t()) :: map()
```

The drawing context of a checked layer over its table in its model: the theme and mode,
the static style (its kind's parts), its bindings, its paint `{key, color}`, its series
values by position, the color scale and the label. A kind reads it to build its
children; `group/4` reads it to apply the shared rules.

# `data_color`

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

A color read from data, as drawn (spec/11 §8.2): the literal where it reaches 3:1
against the theme's background (`Macaw.Layers.Theme.data_color/2`), else the theme's
neutral, in the layer's mode.

# `data_color_faults`

```elixir
@spec data_color_faults(
  map(),
  Macaw.Data.Table.t(),
  Macaw.Frame.Coordinates.Model.t()
) :: [
  {list(), term()}
]
```

The faults of the data colors a checked layer draws over `table` in `model` (spec/11
§8.2): each field bound to a fill or a stroke with no color scale between, whose first
value under the theme's 3:1 guard is `{:data_color, field, reason}` at the layer's
`style`. The column is read once, each distinct value judged once.

# `group`

```elixir
@spec group(map(), [child()], keyword()) :: {:ok, Macaw.Draw.IR.Element.t()}
```

The layer's group of children (§1.7): every shared rule applied, in one pass over the
children, the labels of `Macaw.Frame.Layer.Label` beside them when the layer has a
label. `{:ok, group}`. Options: `labels:` text elements the kind lifts into the labels
group itself (a rule's and an x band's generator labels), `paint: false` for a kind
whose paint sits on its elements (a rule's line), `center: true` for a centered kind.

# `moves?`

```elixir
@spec moves?(map()) :: boolean()
```

Whether a layer moves: its style carries motion, or it has a transition (§1.7.5).

# `provisional`

```elixir
@spec provisional(map()) :: map()
```

What a provisional element draws in over its layer's style (§1.12, D-274): the style
named `provisional`, the design's entry over the theme's palette entry, laid at the
data-style layer; a dashed stroke and a half-opaque fill where neither names one. The
keys it changes, resolved in the layer's mode.

# `role_cue`

```elixir
@spec role_cue(map(), term()) ::
  {:ok, %{glyph: atom(), dash: String.t() | nil}} | :none
```

The cue of the role a reading has through the layer's color scale (spec/11 §8.1):
`{:ok, %{glyph, dash}}` where the scale maps the reading to one of the theme's roles
(`Macaw.Layers.Theme.cue/1`), `:none` otherwise.

# `series_color`

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

A series value's color (§1.7.2): the color scale's value for it, or the theme's series
role for its position among the layer's series values.

---

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