The coordinate-model behavior and the model registry (spec/03 §1).
A frame places its layers through one coordinate model: the module that owns its
scales (Macaw.Frame.Scales), its furniture, its clip, how it answers a pointer, and
what it may write to the page's state. The Frame asks the model, never a case over
model names. A model is a registered module implementing this behavior; the five of
spec/03 are macaw_frame's (Macaw.Frame.Package): Cartesian, Polar,
Geographic, Layout and Facet under this namespace.
Every callback is pure and answers every input: a refusal is {:error, faults},
each fault a Macaw.Base.Fault with its path in the frame document; none raises.
What a model realizes from
realize/3 takes the frame node (canonical, as Macaw.Frame.Document holds it), the
inputs and options. The inputs are what the Frame has after the layers' data steps:
:layers- the frame's layers in design order, each a map::index(its position among the frame's layers),:kind(the layer kind's name),:channels(channel to its reading:{:field, f}, a field's name, a number,{:scale, :min | :max}),:scales(the layer's renames),:offset,:colors(the fields its style binds to color),:slot(the slot it reads) or:output(a layout output it reads),:table(its rows after its data steps, aMacaw.Data.Table),:label(its inline label node) and:order;:slots- each slot by name::table(the delivery's rows before any step),:schema(itsMacaw.Data.Schema) and:served(the delivery's served facts);:design- the whole design, for scales adopted from other frames (§2.5) and the design's interaction.
The options: :name (the frame's name), :size ({width, height} of the Frame
component, {600, 400} by default), :layout (the design's grid), :theme, :units
and :zone (the viewer's preferences), :domains (extents given in place of
inference), :sync (the cell's group), :operations (the operations registry a layout
runs through) and :warm (a layout's carried state).
The registry
Models are members of packages (§1.3): a package's __members__/0 lists modules, and
each one implementing this behavior is a model, named by name/0's spelling.
registry/1 builds the registry of a list of packages, macaw_frame's own always in;
fetch/2 reads it by spelling. The registry is the Frame module's, never the
component context's.
Summary
Types
A clip: a rectangle in the plot group's own coordinates.
A refusal: faults with their paths.
A frame node of the frame document, canonical.
What a model realizes from (see the module doc).
A registry of models by name.
Callbacks
The range of a scale whose range is :auto (§2.4), :none for no default.
A layer's scene element in the model's layout space, turned into plot pixels.
The scale family a layer's channel reads through (§2.2), :pixels for none.
The plot's clip rectangle in the plot group's coordinates; a facet's, one a panel.
The spatial context the frame's spatial transforms run under.
The grid, the axes, the legend and the labels as scene elements, placed (§3).
A finished gesture as the event the Frame emits (§5.3), :none for one not taken.
A plot pixel back to a domain point, where the position scales invert (§4.3).
The frame keys the model reads beyond every frame's, each declared as an option.
The :local keys it shares under the cell's sync group (§5.2).
The model's name, unique in a registry: :cartesian, :polar, … (§1.1).
A domain point to plot pixels, nil for one the model cannot place.
The realized model (§1.2).
The model's part of the text summary: its kind word and its axes' descriptions.
The model's own checks of a frame node: every fault at once, [] for a good one.
The standard state sources the realized model can write (§5.1).
Functions
A frame's box as fractions of the Frame component's size (§1.4): its box, or the
share of the document's layout grid its cell and span take, the weights
normalized over their sum and the gap (pixels) taken out of the cells, never the
grid's outer edges. The one place a cell becomes a box. size is {width, height}.
The behavior's callbacks, [{name, arity}].
The size a frame is realized at when none is given: {600, 400}.
The model a registry holds by name, read by spelling: {:ok, module} or :error.
Whether a module implements every callback of the behavior.
The registry's model names, sorted.
The frames of a document in drawing order (§1.4): by z, ties by name.
The frame realized by the model its kind names in the registry: the model's
realize/3, or {:unknown, :coordinates, name} at the frame's kind (§1.1).
Every frame of a design realized, with its adopted scales shared (§2.5): {:ok, %{name => model}}, or every fault at once. inputs are each frame's by name (the design is
added to each). Two passes: every frame realizes over its own layers, then each
adoption group's domains are united (Macaw.Frame.Scales.unite/1) and its frames
realize again with the union under domains, each keeping its own range. Adoption is
within one design: two Frame components never share a scale.
The model after a change (§1.2): :init and :size always realize; {:delivery, slot}
realizes only when a scale the model infers reads the slot, its fit reads it or its
layout does, and otherwise answers the model unchanged; :render never realizes. A
realization reuses every fixed scale the model already holds.
The registry of the models the packages hold, macaw_frame's own (Macaw.Frame.Package)
always in: {:ok, %{name => module}}, or every fault at once. Two members naming one
model are {[:coordinates, name], {:named_twice, module, other}}; a module that is not a
package {[module], :not_a_package}. A member that implements no model is skipped: it
is another registry's (a layer kind, an operation).
Types
A clip: a rectangle in the plot group's own coordinates.
@type error() :: {:error, [Macaw.Base.Fault.t(), ...]}
A refusal: faults with their paths.
@type frame() :: map()
A frame node of the frame document, canonical.
@type inputs() :: map()
What a model realizes from (see the module doc).
A registry of models by name.
Callbacks
The range of a scale whose range is :auto (§2.4), :none for no default.
@callback bend(Macaw.Frame.Coordinates.Model.t(), Macaw.Draw.IR.Element.t()) :: Macaw.Draw.IR.Element.t()
A layer's scene element in the model's layout space, turned into plot pixels.
The scale family a layer's channel reads through (§2.2), :pixels for none.
@callback clip(Macaw.Frame.Coordinates.Model.t()) :: clip() | [clip()]
The plot's clip rectangle in the plot group's coordinates; a facet's, one a panel.
@callback context(Macaw.Frame.Coordinates.Model.t()) :: map()
The spatial context the frame's spatial transforms run under.
@callback furniture(Macaw.Frame.Coordinates.Model.t(), keyword()) :: {:ok, [Macaw.Draw.IR.Element.t()]} | error()
The grid, the axes, the legend and the labels as scene elements, placed (§3).
@callback gesture(Macaw.Frame.Coordinates.Model.t(), map()) :: {:ok, Macaw.Frame.Writes.event()} | :none
A finished gesture as the event the Frame emits (§5.3), :none for one not taken.
@callback invert(Macaw.Frame.Coordinates.Model.t(), {number(), number()}) :: {:ok, term()} | :none
A plot pixel back to a domain point, where the position scales invert (§4.3).
@callback keys() :: [{String.t(), Macaw.Data.Operations.Option.t()}]
The frame keys the model reads beyond every frame's, each declared as an option.
@callback local(Macaw.Frame.Coordinates.Model.t()) :: %{required(String.t()) => atom()}
The :local keys it shares under the cell's sync group (§5.2).
@callback name() :: atom()
The model's name, unique in a registry: :cartesian, :polar, … (§1.1).
@callback place(Macaw.Frame.Coordinates.Model.t(), term()) :: {number(), number()} | nil
A domain point to plot pixels, nil for one the model cannot place.
@callback realize(frame(), inputs(), keyword()) :: {:ok, Macaw.Frame.Coordinates.Model.t()} | error()
The realized model (§1.2).
@callback summary(Macaw.Frame.Coordinates.Model.t()) :: map()
The model's part of the text summary: its kind word and its axes' descriptions.
@callback validate(frame(), map()) :: [Macaw.Base.Fault.t()]
The model's own checks of a frame node: every fault at once, [] for a good one.
@callback writes(Macaw.Frame.Coordinates.Model.t()) :: %{ required(String.t()) => :identity | :window }
The standard state sources the realized model can write (§5.1).
Functions
A frame's box as fractions of the Frame component's size (§1.4): its box, or the
share of the document's layout grid its cell and span take, the weights
normalized over their sum and the gap (pixels) taken out of the cells, never the
grid's outer edges. The one place a cell becomes a box. size is {width, height}.
iex> Macaw.Frame.Coordinates.box_of(%{box: [0.5, 0, 0.5, 1]}, nil, {600, 400})
{:ok, [0.5, 0, 0.5, 1]}
iex> Macaw.Frame.Coordinates.box_of(%{cell: [1, 0]}, %{columns: [3, 1]}, {600, 400})
{:ok, [0.75, 0.0, 0.25, 1.0]}
@spec callbacks() :: keyword(non_neg_integer())
The behavior's callbacks, [{name, arity}].
@spec default_size() :: {600, 400}
The size a frame is realized at when none is given: {600, 400}.
The model a registry holds by name, read by spelling: {:ok, module} or :error.
iex> {:ok, registry} = Macaw.Frame.Coordinates.registry([])
iex> Macaw.Frame.Coordinates.fetch(registry, :polar)
{:ok, Macaw.Frame.Coordinates.Polar}
iex> Macaw.Frame.Coordinates.fetch(registry, "geo")
:error
Whether a module implements every callback of the behavior.
The registry's model names, sorted.
The frames of a document in drawing order (§1.4): by z, ties by name.
iex> Macaw.Frame.Coordinates.order(%{"b" => %{z: 1}, "a" => %{z: 1}, "c" => %{}})
["c", "a", "b"]
The frame realized by the model its kind names in the registry: the model's
realize/3, or {:unknown, :coordinates, name} at the frame's kind (§1.1).
@spec realize_all(term(), term(), term(), term()) :: {:ok, %{required(String.t()) => Macaw.Frame.Coordinates.Model.t()}} | error()
Every frame of a design realized, with its adopted scales shared (§2.5): {:ok, %{name => model}}, or every fault at once. inputs are each frame's by name (the design is
added to each). Two passes: every frame realizes over its own layers, then each
adoption group's domains are united (Macaw.Frame.Scales.unite/1) and its frames
realize again with the union under domains, each keeping its own range. Adoption is
within one design: two Frame components never share a scale.
@spec refresh(term(), term(), term(), term(), term()) :: {:ok, Macaw.Frame.Coordinates.Model.t()} | error()
The model after a change (§1.2): :init and :size always realize; {:delivery, slot}
realizes only when a scale the model infers reads the slot, its fit reads it or its
layout does, and otherwise answers the model unchanged; :render never realizes. A
realization reuses every fixed scale the model already holds.
The registry of the models the packages hold, macaw_frame's own (Macaw.Frame.Package)
always in: {:ok, %{name => module}}, or every fault at once. Two members naming one
model are {[:coordinates, name], {:named_twice, module, other}}; a module that is not a
package {[module], :not_a_package}. A member that implements no model is skipped: it
is another registry's (a layer kind, an operation).
iex> {:ok, registry} = Macaw.Frame.Coordinates.registry([])
iex> Macaw.Frame.Coordinates.names(registry)
["cartesian", "facet", "geographic", "layout", "polar"]