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

Scale ownership (spec/03 §2): a frame owns its scales, and this module realizes them.

- **Realization** (§2.1, `realize/5`): each scale node once, through
  `Macaw.Draw.Scale.new/2` with its kind's parameters, then the domain, the range,
  `nice` and `clamp`. A node the constructor refuses is a fault at the node's path,
  `{:range, reason}` for its range; nothing raises.
- **Which channel reads which scale** (§2.2, `reads/3`): the model's `channel_scale/3`
  maps a channel to a family, the layer's `scales` renames it, its `offset` adds the
  offset scale, and a `{:field, f}` color of its style reads `color`.
- **Inference** (§2.3): only inferring scales read data, and they read **columns**,
  `Macaw.Data.Table.column/2`, never rows.
- **Automatic ranges** (§2.4): the model's `auto_range/3`, the theme's series and ramps
  for colors, an offset's band, else the first axis naming the scale.
- **Adoption** (§2.5, `adoptions/1`, `unite/1`): a scale adopted from another frame is
  that frame's node, its domain shared, its range each frame's own.

Copied from visualize's `Visualize.Chart.Frame.Scales`, its raising sites made faults.

# `read`

```elixir
@type read() :: {String.t(), map(), String.t() | atom(), term()}
```

A read: the scale, the layer's input, the channel (or `:color`, `:offset`) and its reading.

# `realized`

```elixir
@type realized() :: %{
  scales: %{required(String.t()) =&gt; struct()},
  built: [String.t()],
  domains: map(),
  nodes: %{required(String.t()) =&gt; map()}
}
```

A realization: the scales by name, those built anew, the extents given, and the scale
nodes it realized from.

# `adoptions`

```elixir
@spec adoptions(term()) :: %{
  required({String.t(), String.t()}) =&gt; [{String.t(), String.t()}]
}
```

The adoption groups of a design (§2.5): the declared scale a chain ends at, `{frame,
name}`, and every `{frame, name}` reading it, the owner's own entry included. Only a
group whose node infers its domain is listed: a fixed domain is shared already.

# `carried`

```elixir
@spec carried(map(), map()) :: map()
```

The inputs with their compiled scale nodes held for `frame` (`resolved/3`), where the
frame they were compiled for declares the same scales: a model realizing a frame it
derives from its own (a facet's inner frame) reads the nodes compiled for it.

# `check`

```elixir
@spec check(term(), list()) :: [Macaw.Base.Fault.t()]
```

The faults a scale node alone decides (§2.1), found at validation: a ramp range on a
kind that takes none, a color map on a scale that is not ordinal, an empty range on a
scale that is not ordinal, each `{:range, reason}` at the node's `range`.

# `column`

```elixir
@spec column(term(), term()) :: [term()]
```

One column of a table, `nil` dropped, the column named by either spelling of `field`
(§2.3): read through `Macaw.Data.Table.column/2`, never row by row. `[]` for a table
without the column, or no table.

# `infers?`

```elixir
@spec infers?(term()) :: boolean()
```

Whether a domain is inferred: `:auto`, `:window` (a domain following the slot's served
window, inferred where no delivery gives one, spec/05 §3.2), or an extent with `:auto`
at an end (§2.3).

    iex> Macaw.Frame.Scales.infers?([0, :auto])
    true
    iex> Macaw.Frame.Scales.infers?([0, 1])
    false

# `model_nodes`

```elixir
@spec model_nodes(term()) ::
  {:ok, %{required(String.t()) =&gt; map()}} | {:error, list()}
```

A realized model's scale nodes: those it realized from, else `nodes/3` of its frame
node with no design.

# `nodes`

```elixir
@spec nodes(term(), term(), list()) ::
  {:ok, %{required(String.t()) =&gt; map()}} | {:error, list()}
```

The frame's scale nodes by name, each adopted entry `{:frame, f, s}` resolved to the node
its chain ends at in `design`: `{:ok, nodes}`, or a cycle `{:cycle, :scale, name}`, an
undeclared frame `{:undeclared, :frame, f}` or scale `{:undeclared, :scale, s}` at the
adopting scale's path.

# `reads`

```elixir
@spec reads(module(), map(), [map()], map()) :: [read()]
```

Every read of the frame's layers through `module`'s table (§2.2): `{scale, layer,
channel, reading}` per channel whose family is a declared scale, per `{:field, f}`
color of the layer's style (`:color`), and per offset field (`:offset`). A family the
frame does not declare reads pixels and is not listed. `nodes` are the frame's scale
nodes by name.

# `realize`

```elixir
@spec realize(module(), term(), term(), term(), term()) ::
  {:ok, realized()} | {:error, list()}
```

Every scale of `frame` realized for `module` over the plot (§2.1): `{:ok, %{scales,
built, domains}}`, or every fault at once.

`inputs` are the model's (`Macaw.Frame.Coordinates`). Options: `:path` (the frame's
path, `[:frames, name]`), `:theme`, `:domains` (an extent by name standing in for its
inference), `:reuse` (a previous realization's scales and plot, `%{scales, plot,
node}`: a fixed scale whose node and plot are unchanged is reused, not built), `:zone`
(the viewer's display zone, under a node's own).

# `renames`

```elixir
@spec renames(module(), map(), [map()], map()) :: [Macaw.Base.Fault.t()]
```

The undeclared renames of the frame's layers (§2.2): `{:undeclared, :scale, name}` at
the layer's `scales` path for a rename to a scale the frame does not declare.

# `resolved`

```elixir
@spec resolved(term(), term(), list()) ::
  {:ok, %{required(String.t()) =&gt; map()}} | {:error, list()}
```

The frame's scale nodes as compiled (spec/12 §2): the nodes the compilation resolved
for this frame, which a model's inputs hold as `scale_nodes: %{frame: frame, nodes:
nodes}`, else `nodes/3` of the frame in the inputs' design. A realization reads its
nodes so, and so constructs no scale setup from the frame's declarations per delivery.

# `unite`

```elixir
@spec unite(term()) :: term()
```

One domain over the domains of an adoption group (§2.5): the extent of continuous ones,
the categories of discrete ones in order of first appearance.

    iex> Macaw.Frame.Scales.unite([[0, 5], [-2, 3]])
    [-2, 5]
    iex> Macaw.Frame.Scales.unite([["a", "b"], ["c", "a"]])
    ["a", "b", "c"]

---

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