# `Macaw.Builtin.Reading`
[🔗](https://github.com/dcoai/macaw/blob/v0.6.0/lib/macaw/builtin/reading.ex#L1)

One number from a slot's rows, as the built-in stat and meter read it (spec/05 §6.3,
§6.4): the statistic a `reduce` setting names, over the field bound to the `value` role,
in the delivered rows.

`latest` and `delta` need the rows in time order, so a component using them asks its
source for them newest first by its `t` role (`order/1`), and `latest` needs only one
(`budget/1`). A slot with no time field has no latest: that is `:needs_time`, drawn
`invalid` rather than an arbitrary row called the newest. **Absence is never zero:** a
slot whose values are all gaps answers `nil`, whatever the statistic (`count` excepted,
which counts them as none).

# `budget`

```elixir
@spec budget(String.t()) :: pos_integer() | nil
```

The rows a `reduce` needs: one for `latest`, else every row up to the ceiling.

# `field`

```elixir
@spec field(Macaw.Component.Context.t()) :: String.t()
```

The field the `value` role of the `rows` slot reads: its binding, else `value`.

# `format`

```elixir
@spec format(map()) ::
  {:ok, Macaw.Format.Measure.t()} | {:error, [Macaw.Format.fault(), ...]}
```

The format a render writes its reading with: the one its placement prepared
(`prepare/2`), or built as `prepare/2` builds it when the render was handed none.

# `format_faults`

```elixir
@spec format_faults(map()) :: [{[String.t() | atom(), ...], term()}]
```

The faults of a design's `format`, at its name: none for `""`, else the faults
`Macaw.Format.parse/2` answers for it. A specifier that is no format is the design's
fault, found when its surface is validated, never by a render.

# `notice`

```elixir
@spec notice(
  Macaw.Component.Drawn.t(),
  Macaw.Data.Delivery.t(),
  Macaw.Component.Context.t(),
  String.t()
) :: Phoenix.HTML.Safe.t() | nil
```

The notice a capped or stale delivery draws above the number, or none for one that is
the whole answer to what was asked. `latest` asks for one row, so it is always reduced;
when those are the first rows in its order, nothing is missing. It keeps the notice when
the source cut its rows before they were ordered (`:sample`, which may not be the newest)
or says it stopped short (`capped`), and every other statistic keeps it, having read only
part of the data.

# `order`

```elixir
@spec order(String.t()) :: Macaw.Component.order()
```

The order a `reduce` asks of the slot: newest first by its `t` role, or none.

# `prepare`

```elixir
@spec prepare(map(), Macaw.Component.Context.t()) ::
  {:ok, {:ok, Macaw.Format.Measure.t()} | {:error, [Macaw.Format.fault(), ...]}}
```

What the stat and the meter prepare for their placement (macaw_component spec/02 §1.1,
#411): `writer/3`'s answer for the `value` role's field, the format built once from
what holds for the placement's life (the slot's schema and binding, the viewer's unit
system, `digits`, `format` and `reduce`), so no render builds it.

# `reduces`

```elixir
@spec reduces() :: [String.t(), ...]
```

The `reduce` parameter's legal values.

# `value`

```elixir
@spec value(Macaw.Data.Delivery.t(), Macaw.Component.Context.t(), String.t()) ::
  {:ok, number() | nil} | :needs_time | :no_rows
```

The number `reduce` answers over a live slot's rows: `{:ok, number}`, `{:ok, nil}` for
no readings, `:needs_time` for `latest` or `delta` with no time field, and `:no_rows` for
rows that don't pack.

# `write`

```elixir
@spec write(Macaw.Format.Measure.t(), number()) :: String.t()
```

A reading as `writer/3`'s format writes it, its unit's suffix included.

# `writer`

```elixir
@spec writer(Macaw.Component.Context.t(), String.t(), map()) ::
  {:ok, Macaw.Format.Measure.t()} | {:error, [Macaw.Format.fault(), ...]}
```

How the reading of `field` of the `rows` slot is written (macaw_data spec/05 §6): its
measure's default format, the unit and quantity from the slot's schema, under the
viewer's unit system, at the design's `digits` and `format`. A `count` counts rows, so
its measure is `:count` whatever the field's. The locale is English, macaw_data's
default, until a component's context carries the viewer's (macaw_component#64).
`{:ok, format}`, or the faults `Macaw.Format.for_measure/2` answers.

# `writing_parameters`

```elixir
@spec writing_parameters() :: %{required(String.t()) =&gt; map()}
```

The parameters that say how the reading is written, the stat's and the meter's alike:
`digits`, its decimals (`precision:` of `Macaw.Format.for_measure/2`), `""` for the
measure's own; and `format`, a d3-format specifier that overrides the number, `""` for
none.

---

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