Visualize.Chart.Transform (Visualize v0.2.25)

Copy Markdown View Source

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 centred mark is about (centre:), in a :geo frame the projection (projection:), the instant a :window step measures back from (now:), and the realisation'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]}]

Summary

Types

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, and the realisation's force layouts.

Functions

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

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

Types

context()

@type context() :: %{
  size: [number()],
  centre: [number()],
  projection: Visualize.Geo.Projection.t() | nil,
  sources: map(),
  now: term() | 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, and the realisation's force layouts.

Functions

apply(transforms, rows, opts \\ [])

@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])
  • :centre - 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 centre (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
  • :forces - the :force steps a realisation 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(transform, rows, opts)

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

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