# `Visualize.Board.State`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/board/state.ex#L1)

A cell's state, decided and drawn (spec/15 §8.4, D-146).

A cell is always in one state, and every state is drawn deliberately: never a blank
chart, a crash or a host's spinner. `of/3` decides the state of a cell's slots at the
board's now; `render/3` draws it as the whole cell, where there is no chart, and
`banner/3` as one line across the top of a chart, where the last data stays readable.
Each state has a **role** (spec/08 §7.5, D-135): its color is the drawing's accent and
its cue's glyph (spec/14 §21.7, D-142) stands beside the words, so a state reads in
grayscale as well. Both drawings are in `:css` mode, so a stylesheet themes them as it
themes the charts.

| State | Role | Words |
|---|---|---|
| `{:crashed, reason}` | `:bad` | Crashed, restarting |
| `{:down, reason}` | `:bad` | Feed down and the reason |
| `{:invalid, errors}` | `:bad` | Wrong binding and the first fault |
| `{:over_budget, rows, ceiling}` | `:bad` | Over budget, the rows and the ceiling |
| `:loading` | `:info` | Loading… |
| `:no_data` | `:neutral` | No data yet |
| `{:stale, age}` | `:warning` | Stale and the age |
| `:capped` | `:info` | Capped: part of the window |
| `:live` | — | — |

## Examples

    iex> Visualize.Board.State.words({:stale, 330})
    "Stale: 5m30s old"
    iex> Visualize.Board.State.role(:no_data)
    :neutral
    iex> Visualize.Board.State.banner(:live, Visualize.Theme.default(), 300)
    nil

# `slot`

```elixir
@type slot() :: %{
  delivery: Visualize.Data.Delivery.t() | nil,
  schema: Visualize.Data.Schema.t() | nil,
  status:
    Visualize.Feed.Monitor.status()
    | {:over_budget, pos_integer(), pos_integer()}
}
```

What a cell knows of one slot: its delivery, the delivery's schema and the feed's status,
or `{:over_budget, rows, ceiling}` with no delivery for a slot the board did not hand its
rows (spec/15 §8.2, D-227).

# `t`

```elixir
@type t() ::
  :loading
  | :no_data
  | :live
  | :capped
  | {:stale, number() | nil}
  | {:down, term()}
  | {:invalid, [Visualize.Chart.Validator.error(), ...]}
  | {:over_budget, pos_integer(), pos_integer()}
  | {:crashed, term()}
```

# `banner`

```elixir
@spec banner(t(), Visualize.Theme.t(), number(), keyword()) :: String.t() | nil
```

A state drawn as a banner across the top of a chart `width` wide (spec/15 §8.4): an SVG
root one line high, the role's color behind the role's glyph and the words in the
contrast ink of `Visualize.Theme.ink/2`. `nil` for `:live`, which needs none. `id:` as
`render/4` takes it; a board passes `<cell root id>-banner` (#722).

# `name`

```elixir
@spec name(t()) :: String.t()
```

A state's name, the `data-vis-state` its drawings carry: `"stale"`, `"down"`, …

# `of`

```elixir
@spec of(%{required(atom()) =&gt; slot()}, DateTime.t() | nil, number() | nil) :: t()
```

The state of a cell's slots at `now` (spec/15 §8.4), the first that holds of: down (a
slot's feed is down), over budget (a slot the board did not hand its rows, more than
its ceiling, D-227), loading (a slot has no delivery yet), no data (every delivery
empty), stale (a feed the monitor calls stale, or a newest `DateTime` reading older than
`stale_after` seconds at `now`), capped (a delivery is `capped`), and live. A cell with
no slots is live. Crashed is the board's, which draws it for a cell that cannot.

# `render`

```elixir
@spec render(t(), Visualize.Theme.t(), {number(), number()}, keyword()) :: String.t()
```

A state drawn as the whole cell (spec/15 §8.4): an accessible SVG root of `{w, h}`
titled with the words, the theme's `surface` filling it inside a frame of the role's
color, and the role's glyph and the words centered in the theme's `text`. `:live` is
drawn as the empty surface.

`id:` is the root's id and its title's id stem (spec/14 §4.7, D-188): a board passes the
cell's root id, so two cells in one state never share one (#722). Without it the id is
derived from the title.

# `role`

```elixir
@spec role(t()) :: Visualize.Theme.slot() | nil
```

A state's role (spec/08 §7.5), whose color and glyph draw it; `nil` for `:live`.

# `words`

```elixir
@spec words(t()) :: String.t()
```

A state's words, as the drawings print them; `""` for `:live`.

---

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