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

Gap breaking over packed columns (spec/04 §6), copied from visualize's
`Visualize.Board.Rows` without the board's state and named for the frame.

A series is **placed by its window field and broken at every gap longer than the
source's continuity, or the delivery's resolution if that is larger**. This is a property
of the `line`, `area` and `percentile_band` kinds, read from the delivery and the slot's
schema:

1. **The axis**: the field the layer's `x` reads, when it is the slot's window field; for a
   line over a `projection` step's pixels (a route), the slot's window field, its value
   fields the projected longitude and latitude. Any other layer whose `x` is not the
   window field is not gap-broken.
2. **Order**: rows in window-field order; a delivery whose window column is already
   non-decreasing is used as it is, otherwise a stable sort permutation of the column.
   The delivery is never rewritten.
3. **Series**: gaps are measured within a series: the layer's `series` field, else the
   slot's declared identity, else the whole delivery.
4. **The threshold**, per value field: `max(continuity, resolution)`, the field's schema
   `continuity` and the delivery's `served.resolution` (a number as it is, a name as its
   seconds, an unknown name or `nil` as `0`). A field with no `continuity` never breaks.
5. **The measure**: an instant in seconds, a number as itself (`Macaw.Frame.Layer.Device
   .measure/1`).
6. **The break** is a mask (`gap`): `true` at a row a gap precedes in its series, where
   its window reading and the previous placed row's differ by more than any of its value
   fields' thresholds. No row is inserted.

`of/3` is one pass over the window column per series, linear in the rows; the Frame keeps
its answer per delivery.

# `t`

```elixir
@type t() :: %Macaw.Frame.Gaps{
  gap: tuple() | MapSet.t(non_neg_integer()) | nil,
  order: [non_neg_integer()] | nil,
  window: String.t() | nil
}
```

# `breaks`

```elixir
@spec breaks(t()) :: [non_neg_integer()]
```

The rows a gap precedes, ascending (§6): `[]` where nothing breaks. What a layer drawing
from its pixel binaries splits its runs at.

# `gap?`

```elixir
@spec gap?(t(), non_neg_integer()) :: boolean()
```

Whether a row's gap mask says a gap precedes it.

# `of`

```elixir
@spec of(map(), Macaw.Data.Table.t(), [String.t()]) :: t()
```

A layer's window order and gaps over its table (§6). `values` are the value channels the
layer reads (`["y"]` for a line). `order` is the rows' indices in window order, `nil` when
the layer is not placed by a window field (its rows as they are); `gap` a tuple with one
boolean per row, `true` where a gap precedes it, `nil` where nothing breaks.

    iex> {:ok, schema} = Macaw.Data.Schema.new(%{"t" => %{type: :number, window: true},
    ...>   "v" => %{type: :number, continuity: 5}})
    iex> {:ok, table} = Macaw.Data.Table.from([%{"t" => 12, "v" => 3}, %{"t" => 0, "v" => 1}, %{"t" => 2, "v" => 2}])
    iex> layer = %{"channels" => %{"x" => {:field, "t"}, "y" => {:field, "v"}}, "context" => %{schema: schema}}
    iex> gaps = Macaw.Frame.Gaps.of(layer, table, ["y"])
    iex> {gaps.order, gaps.gap}
    {[1, 2, 0], {true, false, false}}

# `order`

```elixir
@spec order(t(), non_neg_integer()) :: [non_neg_integer()]
```

The rows' indices in drawing order: the window order, else the delivery's.

# `resolution`

```elixir
@spec resolution(term()) :: number()
```

A delivery's resolution in the window field's units (§6.4): a number as it is, a name as
its seconds, an unknown name or `nil` as `0`.

    iex> {Macaw.Frame.Gaps.resolution("hour"), Macaw.Frame.Gaps.resolution(15), Macaw.Frame.Gaps.resolution(nil)}
    {3600, 15, 0}

---

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