# `Visualize.Chart.Transform`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/chart/transform.ex#L1)

The data pipeline of a mark (spec/14 §5.4, D-62): filtering, binning, stacking,
aggregation, the layouts of `Visualize.Layout` and the geo algorithms as `%{op: …}`
steps over rows.

`apply/3` runs the steps of a mark's `data.transforms` in order over its source's rows,
each a pure function of the rows before it and its node, and yields the rows the mark
draws. Its only context is the plot area (`size:`, the extent every layout defaults
to), the point a centered mark is about (`center:`), in a `:geo` frame the projection
(`projection:`), the instant a `:window` step measures back from (`now:`), the schema
of the rows' slot, whose declared identity a `:window` step's `latest` groups by
(`schema:`, D-168), and the realization's laid-out `:force` steps (`forces:`, spec/14
§5.4.3, D-132) — never a
scale, which is what lets `Visualize.Chart.Frame.new/2` run the pipeline before its
scales exist and infer their domains from the transformed columns. A layout's rows carry
their shape as a `Visualize.IR.Path` under `path`, which the `:path` mark draws as it is.

## Examples

    iex> rows = [%{v: 1}, %{v: 2}, %{v: 2}, %{v: 9}]
    iex> Visualize.Chart.Transform.apply([%{op: :bin, field: :v, thresholds: [5]}], rows)
    [%{x0: 1, x1: 5, y0: 0, count: 3, values: [1, 2, 2]}, %{x0: 5, x1: 9, y0: 0, count: 1, values: [9]}]

# `context`

```elixir
@type context() :: %{
  size: [number()],
  center: [number()],
  projection: Visualize.Geo.Projection.t() | nil,
  sources: map(),
  now: term() | nil,
  schema: Visualize.Data.Schema.t() | nil,
  forces: map()
}
```

What a step sees of the frame: the plot area, in a `:geo` frame its projection, the bound sources for a graph's node table, the instant a `:window` measures back from, the rows' slot's schema, and the realization's force layouts.

# `apply`

```elixir
@spec apply([map()], Visualize.Data.Table.source(), keyword()) :: [map()]
```

The rows after every transform node, in order (spec/14 §5.4).

## Options

  * `:size` - the `[width, height]` the layouts and the geo algorithms default to, and
    whose width an `:lttb` step's `n: :plot` and an `:m4` step's `width: :plot` read
    (default `[1, 1]`)
  * `:center` - the `[x, y]` a `:chord` step's paths are about: the point an `:arc`
    mark is about, which the frame passes (spec/14 §5.4.3, #488); `size` sets the
    chord's radius, never its center (default the middle of `:size`)
  * `:projection` - the `%Visualize.Geo.Projection{}` a `:projection` step maps through
    (default `nil`)
  * `:sources` - the bound sources by name, for a graph step's `nodes` (default `%{}`)
  * `:now` - the instant a `:window` step measures its durations back from (spec/14
    §5.4.1); without it each such step takes the newest reading of its own column
  * `:schema` - the `%Visualize.Data.Schema{}` of the rows' slot, whose declared
    identity a `:window` step's `latest` groups by (spec/14 §5.4.1, D-168); a `latest`
    step without one, or over a schema that declares none, raises
  * `:forces` - the `:force` steps a realization has laid out, by run (spec/14 §5.4.3,
    D-132): what `Visualize.Chart.Frame.new/2` passes, so the marks of one graph read
    one layout; a step not among them runs cold (default `%{}`)

Raises `ArgumentError` for an op that is not one of spec/14 §5.4, a key an op requires
and the node lacks, or a `:projection` step without a projection.

# `step`

```elixir
@spec step(map(), Visualize.Data.Table.source(), keyword()) :: [map()]
```

One step of `apply/3`: the rows after the transform node.

---

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