The Frame's contained value and its transitions as pure functions (spec/01 §3), copied
from visualize's Visualize.Visual, the runtime as a value with transitions, on
macaw_component's contract (macaw_component spec/02 §7). Its state/4, resolve/2,
drawing tokens resolving clicks and its two rescue sites are not carried over.
| Transition | Does |
|---|---|
init/3 | compiles the frame document once (§3.2), from nothing or carrying what the value it replaces built up |
delivery/3 | reads that one slot's data and draws (§3.3) |
size/2 | re-lays out at the new size and draws (§3.4) |
bound/3 | takes a changed bound parameter, design variable or the selection (§3.5) |
tick_interval/1, tick/2 | a running force simulation stepped on the host's ticks (§3.6) |
The value is pure (§3.1): a transition does no I/O, reads no clock, starts no
process and sends nothing, so equal inputs give equal values. A transition that
cannot draw is a fault the value holds, never a raise (§3.1): the drawing it holds is
kept and faults names what went wrong by path, which the Frame draws as invalid
(§4.3).
The fields of §3.1: settings, context, document (the canonical frame document),
compiled (Macaw.Frame.Compiled), compiled_for (the size, the document's digest and
the schemas' versions it was compiled for), slots (by slot, %{delivery, table, schema}), cache (the Macaw.Frame.Pipeline the layers' steps run through, holding
the per-chunk Macaw.Data.Operations.Cache), layouts (each force step's warm
simulation by graph, §3.6), selection, drawing, token and faults. Beside them
registry is the registry of the Frame module that built it (§2.3), and component its
name, the name its proxy routes are served under (spec/10 §8.1). keyboard is the
keyboard's armed reach and the point it stands on (Macaw.Frame.Keyboard, spec/11
§5.4), nil while unarmed; crosshair the crosshair's arrays while its hook is armed
(Macaw.Frame.Hooks.Crosshair, spec/10 §7, §7.4), nil otherwise; request/2 answers
the keyboard's and the crosshair's requests.
request/2 | answers a hook's "arm", "disarm" or "key" request (spec/11 §5.6) |
segments/1 | hands the runtime the drawing's binary segments, raw (spec/10 §6) |
Summary
Functions
The value after a changed bound input (§3.5): "title" and "description" are held
and re-rendered, nothing drawn; "vars.<name>" re-resolves a state-bound variable at
its paths (Macaw.Frame.Compiled.bound/3) and draws; "selection" is held and the data
layers draw again. An unknown name answers the value as given, and a value of the wrong
type is {:type, type} at ["settings", name], the drawing kept.
The value after one slot's delivery (§3.3): its rows held as the delivery's Macaw.Data.Table,
never decoded or copied, and the drawing drawn again, each role read through the cell's
binding (Macaw.Frame.Columns.bound/2). A delivery its slot cannot read
(no such slot, rows that build no table, {:rows, reason}) is a fault at
["sources", slot], and one
naming another version of the slot's schema than the value compiled for is
{:schema_version, slot, compiled, delivered} there; either keeps the drawing held. A
delivery whose table is Macaw.Data.Table.equal?/2 to the one held answers the value as
given, and so is one differing from it only in served facts that change no pixel
(stale, capped, reduced_by, spec/05 §4.3). The next readable delivery of the
compiled version clears the slot's fault.
The Frame's own drawn state (§4.3, Macaw.Frame.Drawn.own/1): :invalid while the
value holds faults, :capped when a layer drew fewer of its rows than it was handed,
:live otherwise.
The value of settings in context (§3.2): the document validated, its variables
resolved at the values the settings give, its layer kinds and coordinate models
resolved through the registry, and compiled at the context's size, theme and
preferences; no delivery is held, so nothing is drawn until the first.
A request of the Frame's keyboard hook (spec/11 §5.6, macaw_component spec/02 §7.3):
{answer, value}, Macaw.Frame.Keyboard.handle/2's.
The drawing's binary segments as the runtime carries them (spec/10 §6, macaw_live
spec/05 §9.1): {token, [{key, token, bytes}]}, the drawing's token and, in drawing
order, every binary canvas's pieces and every incremental canvas's records as raw
bytes, never Base64. A key is its canvas's prefix ("c<i>/", the canvas element's
data-mw-segments) and the segment's own key; a segment's token is that of the drawing
it last changed in, so an unchanged one is not sent again. The runtime chooses each
segment's carrier: Base64 in markup for a first render, a binary frame on a live
stream. A value with no drawing answers {"none", []}; a drawing on SVG or the canvas
commands alone, its token and no segment.
The value at a new size {width, height} (§3.4): the compiled document's size-dependent
part made again, carrying the warm layouts and the cache's parts, and the held
deliveries drawn at once. A size equal to the held one answers the value as given; one
that is no pair of positive numbers is a fault at ["size"].
The value one step on at the page's monotonic ms (§3.6): each running simulation steps
once and the graph is drawn again. ms is given, never read; a value with nothing
running answers itself.
The milliseconds to the value's next step (§3.6): 16 while a force simulation of its
drawing is still running, nil once every one has settled or there is none.
Types
@type t() :: %Macaw.Frame.Value{ cache: Macaw.Frame.Pipeline.t() | nil, compiled: Macaw.Frame.Compiled.t() | nil, compiled_for: map() | nil, component: String.t(), context: Macaw.Component.Context.t() | nil, crosshair: [{String.t(), String.t()}] | nil, document: map() | nil, drawing: map() | nil, faults: [{list(), term()}], keyboard: %{reach: Macaw.Frame.Reach.t(), at: term(), seq: integer()} | nil, layouts: map(), registry: map() | nil, selection: term(), settings: map(), slots: %{ required(String.t()) => %{ delivery: Macaw.Data.Delivery.t(), table: Macaw.Data.Table.t(), schema: term() } }, token: String.t() | nil }
Functions
The value after a changed bound input (§3.5): "title" and "description" are held
and re-rendered, nothing drawn; "vars.<name>" re-resolves a state-bound variable at
its paths (Macaw.Frame.Compiled.bound/3) and draws; "selection" is held and the data
layers draw again. An unknown name answers the value as given, and a value of the wrong
type is {:type, type} at ["settings", name], the drawing kept.
@spec delivery(t(), String.t(), Macaw.Data.Delivery.t()) :: t()
The value after one slot's delivery (§3.3): its rows held as the delivery's Macaw.Data.Table,
never decoded or copied, and the drawing drawn again, each role read through the cell's
binding (Macaw.Frame.Columns.bound/2). A delivery its slot cannot read
(no such slot, rows that build no table, {:rows, reason}) is a fault at
["sources", slot], and one
naming another version of the slot's schema than the value compiled for is
{:schema_version, slot, compiled, delivered} there; either keeps the drawing held. A
delivery whose table is Macaw.Data.Table.equal?/2 to the one held answers the value as
given, and so is one differing from it only in served facts that change no pixel
(stale, capped, reduced_by, spec/05 §4.3). The next readable delivery of the
compiled version clears the slot's fault.
@spec drawn(t()) :: :invalid | :capped | :live
The Frame's own drawn state (§4.3, Macaw.Frame.Drawn.own/1): :invalid while the
value holds faults, :capped when a layer drew fewer of its rows than it was handed,
:live otherwise.
@spec init(map(), Macaw.Component.Context.t(), keyword()) :: t()
The value of settings in context (§3.2): the document validated, its variables
resolved at the values the settings give, its layer kinds and coordinate models
resolved through the registry, and compiled at the context's size, theme and
preferences; no delivery is held, so nothing is drawn until the first.
Options: registry: the Frame module's registry (Macaw.Frame's by default),
component: the Frame module's name ("macaw.frame"), metrics: the text measurer
everything that lays text out measures with (a module implementing
Macaw.Layers.Text.Metrics, macaw_layers#59; Macaw.Layers.Text.Estimate without
one, and any other module the fault {:type, :metrics} at [:context, :metrics]
under "design"), and
from: the value this one replaces (macaw_component spec/02 §7.1), whose pipeline (its
cache and warm layouts) and drawing are carried, so a re-initialization keeps what still
holds and shows its last drawing until the first delivery. A from that is no value of
the same registry starts cold. A document the settings do not hold, or that does not
compile, is held in faults under ["design"].
A request of the Frame's keyboard hook (spec/11 §5.6, macaw_component spec/02 §7.3):
{answer, value}, Macaw.Frame.Keyboard.handle/2's.
The drawing's binary segments as the runtime carries them (spec/10 §6, macaw_live
spec/05 §9.1): {token, [{key, token, bytes}]}, the drawing's token and, in drawing
order, every binary canvas's pieces and every incremental canvas's records as raw
bytes, never Base64. A key is its canvas's prefix ("c<i>/", the canvas element's
data-mw-segments) and the segment's own key; a segment's token is that of the drawing
it last changed in, so an unchanged one is not sent again. The runtime chooses each
segment's carrier: Base64 in markup for a first render, a binary frame on a live
stream. A value with no drawing answers {"none", []}; a drawing on SVG or the canvas
commands alone, its token and no segment.
It is the Frame module's @impl of macaw_component's optional segments/1 callback
(macaw_component spec/02 §7.6), and a socketless render carries the same drawing in its
stream element (Macaw.Frame.Render).
The value at a new size {width, height} (§3.4): the compiled document's size-dependent
part made again, carrying the warm layouts and the cache's parts, and the held
deliveries drawn at once. A size equal to the held one answers the value as given; one
that is no pair of positive numbers is a fault at ["size"].
The value one step on at the page's monotonic ms (§3.6): each running simulation steps
once and the graph is drawn again. ms is given, never read; a value with nothing
running answers itself.
@spec tick_interval(t()) :: pos_integer() | nil
The milliseconds to the value's next step (§3.6): 16 while a force simulation of its
drawing is still running, nil once every one has settled or there is none.