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

The budget picks each layer's renderer (spec/10 §2.7), copied from visualize's
`Visualize.Chart.Compiled` targets (its spec/14 §12.3) and `.Compiled.Regions`.

`choose(layer, frame, mode)` picks a layer's target **when the frame compiles** (a
document, binding, budget or size change), never per delivery, so a layer's DOM is
stable through a stream (visualize D-66). It reads what compilation knows, never a
delivered row:

1. **Outside live mode every layer is `:svg`** (macaw_component 02 §3): socketless,
   neutral and print draw no canvas.
2. **A text layer, a tile layer and a facet's layer are `:svg`**, whatever they say: the
   binary stream carries no text, tiles are the backdrop, a facet's panels are SVG. A
   layer is a text or tile layer when its kind draws on `:svg` alone (its `targets/0`).
3. **A layer's own `render:`** (`:svg`, `:canvas`, `:binary`) is taken as given in live
   mode, the document's override.
4. **A scrolling plot is `:incremental`**: a frame whose viewport is a relative window
   (`%{scale: s, span: n}`, spec/03 §6.3) over a `:linear` or `:time` x scale, every
   other scale its layers read fixed. Any other moving scale makes every tick a full
   redraw, so the layer is `:binary` instead.
5. **Otherwise the budget decides.** A layer whose slot's budget (`Macaw.Frame.Budget`,
   the rows its pixel extent allows) exceeds the **ceiling** (1,000 drawn points by
   default, the Frame's `ceiling:` option) is `:binary`, one at or under it `:svg`; and
   **a high-rate layer is `:binary` whatever its budget**, one whose slot's schema
   declares a field's continuity under 1 second (macaw_data 01).

Choosing from the budget, not the delivered count, is the change from visualize: the
first live render already draws on the target the stream keeps, and a page never flips
a layer from SVG to canvas when its data fills. `targets(value)` reports
`[{layer, target, budget}]` in layer order.

# `frame`

```elixir
@type frame() :: %{
  optional(:facet) =&gt; boolean(),
  optional(:scrolls) =&gt; :incremental | :binary | nil,
  optional(:budget) =&gt; pos_integer() | nil,
  optional(:ceiling) =&gt; pos_integer(),
  optional(:high_rate) =&gt; boolean()
}
```

What compilation knows of a layer's frame and slot: whether it is a `facet`, whether
it `scrolls` (`:incremental` for a relative window over a linear or time x with every
other scale fixed, `:binary` for one with another moving scale, `nil` for none), the
slot's `budget`, the `ceiling`, and whether its source is `high_rate`.

# `target`

```elixir
@type target() :: :svg | :canvas | :binary | :incremental
```

A layer's target.

# `choose`

```elixir
@spec choose(map(), frame(), atom()) :: target()
```

The target of `layer` (a compiled layer: its `render` and its kind's `module`) in
`frame` (`t:frame/0`) and `mode`, by the five rules above. A term of another shape is
`:svg`, the target every mode draws.

    iex> layer = %{render: :auto, module: nil}
    iex> Macaw.Frame.Render.Target.choose(layer, %{budget: 5_000}, :live)
    :binary
    iex> Macaw.Frame.Render.Target.choose(layer, %{budget: 5_000}, :print)
    :svg

# `frame`

```elixir
@spec frame(Macaw.Frame.Compiled.t(), map(), map(), map()) :: frame()
```

What compilation knows of `layer`'s frame (`t:frame/0`), its slot's budget read from
`budgets` (`%{slot => rows}`) and its schema from the context.

# `targets`

```elixir
@spec targets(Macaw.Frame.Value.t()) :: [
  {non_neg_integer(), target(), pos_integer() | nil}
]
```

Each layer's target and the budget it was chosen from, in layer order: `[{index,
target, budget}]`. A value with no compiled document reports none.

---

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