Macaw.Frame.Document.Types (macaw_frame v0.1.0)

Copy Markdown View Source

The type check of a design's bindings against its slots' schemas (spec/02 §7.3).

A field read through a scale has the type its scale needs: a :time scale needs :time, a numeric scale :number, a band or ordinal scale :category or :text; a position channel read with no scale between needs :number; a :term field, which a column of colors is (data holds no color type), satisfies no need. A field whose schema type does not satisfy its need is {:invalid_for, type} at the channel that reads it, type the field's schema type: the one fault name for a scale and a type that do not pair. A layer's position channels (x, x0, x1, y, y0, y1) read the frame's x and y scales, renamed by its scales.

check_types/2 is pure and total over any map: what it cannot read it does not judge.

iex> schema = Macaw.Data.Schema.new!(%{"t" => %{type: :category}, "v" => %{type: :number}})
iex> design = %{frames: %{"main" => %{kind: "cartesian", scales: %{"x" => %{kind: :linear}}}},
...>   layers: [%{kind: "line", data: "s", channels: %{"x" => "t", "y" => "v"}}]}
iex> Macaw.Frame.Document.Types.check_types(design, %{"s" => schema})
{:error, [{[:layers, 0, :channels, "x"], {:invalid_for, :category}}]}

Summary

Functions

:ok, or every channel whose field's schema type its scale cannot take, by path. A slot's schema is a Macaw.Data.Schema or a map of field to its type.

Functions

check_types(design, schemas)

@spec check_types(term(), term()) :: :ok | {:error, [Macaw.Base.Fault.t(), ...]}

:ok, or every channel whose field's schema type its scale cannot take, by path. A slot's schema is a Macaw.Data.Schema or a map of field to its type.