Macaw.Frame.Slots (macaw_frame v0.1.0)

Copy Markdown View Source

The slots a frame document declares and each slot's roles and their requirements, from its layers' channels (spec/05 §1). Copied from visualize's Visualize.Board.required_sources/3 (a slot per source a design reads, one design in two cells two sets of slots) and Visualize.Chart.contract/1 and check_types/2 (what each field a layer reads through a scale needs of its type, visualize spec/14 §7.4, D-153); binding a slot and checking the binding are the host's, Macaw.Component.Slot.check/3 (§1.3).

A role is a field a layer reads from the slot's own rows (§1.2): through a channel, or through a step's field option before any step derives a column (Macaw.Frame.Layer.Channel.roles/4). Its requirement follows the table of §1.2:

The readingThe requirement
a channel through a :time scaletype: [:time]
through a numeric scale, or a number with no scale betweentype: [:number]
through :band or :ordinaltype: [:category, :text]
a series channeltype: [:category, :text], optional when the channel is
the frame's x over the slot's window field (requires :window)type: [:time, :number], window: true
a hierarchy's id, a graph's nodes' ididentity: true
a role the document declares many (bound to several fields)many: true
a field a step's list option names (a fold's columns)a role of its own, of one field
a field only steps readevery type a column may hold
  • A document's own types and requires narrow it further: a declared type is the role's type, requires :identity and :window set the flags (spec/02 §2.4).
  • Two layers reading one role agree or the document is refused (§1.2): readings whose types share none are {:role_type, slot, role, a, b} at the second layer's channel, so a slot's requirements are one per role.
  • Graph-shaped data is slots (§1.4): a hierarchy step's id is an identity role and its parent field (by) an optional one; a graph's fields are its links' source and target, its field an optional :number value, and the slot its nodes option names carries the id role, an identity.
  • What a step makes is not a role: a bin's x0, a stack's y1, a layout's x.

of/2 answers {:ok, %{slot => %{roles: %{role => requirement}}}} in the shape Macaw.Frame.Declarations hands macaw_component (type, window, identity, many, optional), or {:error, faults}.

Summary

Types

A role's requirement, macaw_component's slot requirement (spec/01 §1.3).

Functions

A design with each many role a step's list option names read as the fields a surface binds it to (spec/02 §2.3, spec/13 §4.3): in a layer's steps over a slot, a list option's element that names one of the slot's many roles is replaced by that role's bound fields, in order. A role bound to no list, a design with no binding, and anything that is no design answer the design as given.

The slot whose declared identity names a layer's rows (§1.4): the nodes slot of a graph step answering nodes (its output not :links), the layer's own slot otherwise.

The slots of a compiled document (§1.1, §1.2): each slot the document declares, with every role its layers read and that role's requirement; {:role_type, slot, role, a, b} at the second layer's channel where two readings of one role share no type. Anything but a compiled document is a type fault.

The slots a layer reads (§1.1): its own, and the slots its steps name (a graph's nodes), by spelling.

Types

requirement()

@type requirement() :: %{
  type: [atom(), ...],
  window: boolean(),
  identity: boolean(),
  many: boolean(),
  optional: boolean()
}

A role's requirement, macaw_component's slot requirement (spec/01 §1.3).

Functions

expand(design, bindings)

@spec expand(term(), term()) :: term()

A design with each many role a step's list option names read as the fields a surface binds it to (spec/02 §2.3, spec/13 §4.3): in a layer's steps over a slot, a list option's element that names one of the slot's many roles is replaced by that role's bound fields, in order. A role bound to no list, a design with no binding, and anything that is no design answer the design as given.

iex> design = %{slots: %{"d" => %{fields: ["x", "vs"], many: ["vs"]}},
...>   frames: %{"main" => %{kind: "cartesian"}},
...>   layers: [%{kind: "area", data: %{slot: "d", steps: [%{"op" => "stack", "fields" => ["vs"]}]}}]}
iex> [layer] = Macaw.Frame.Slots.expand(design, %{"d" => %{"vs" => ["a", "b"]}}).layers
iex> layer.data.steps
[%{"op" => "stack", "fields" => ["a", "b"]}]

identity_slot(arg1)

@spec identity_slot(map()) :: String.t() | nil

The slot whose declared identity names a layer's rows (§1.4): the nodes slot of a graph step answering nodes (its output not :links), the layer's own slot otherwise.

of(compiled, registry)

@spec of(term(), term()) ::
  {:ok,
   %{required(String.t()) => %{roles: %{required(String.t()) => requirement()}}}}
  | {:error, [{list(), term()}, ...]}

The slots of a compiled document (§1.1, §1.2): each slot the document declares, with every role its layers read and that role's requirement; {:role_type, slot, role, a, b} at the second layer's channel where two readings of one role share no type. Anything but a compiled document is a type fault.

read_by(arg1)

@spec read_by(map()) :: [String.t()]

The slots a layer reads (§1.1): its own, and the slots its steps name (a graph's nodes), by spelling.