The layer-kind behavior (spec/04 §1.1) and the checked layer every callback is given (§1.6).
A frame composes layers. A layer is visualize's mark: it binds fields of its data
to the frame's scales and draws them with Macaw.Draw's generators in the frame's
coordinate model. A layer is never a component: it has no region, no budget of its
own on the page, no state and no failure isolation. What a layer can be is a layer
kind, a registered module implementing this behavior (Macaw.Frame.Layers).
visualize held its sixteen mark types in one schema module (Visualize.Chart.Schema .Mark); here each kind declares its own channels, options, scales, legend and summary
contributions, budget, validation and drawing, and every kind passes the layer kit
(Macaw.Frame.LayerKit).
Every callback is pure (no process, clock, randomness or ETS) and none raises on any
input. A refusal is a list of Macaw.Base.Faults, each at its path in the frame
document.
The checked layer (§1.6)
Every callback after validation is given a checked layer (checked/2): a map with
string keys, "kind" the kind's module and "name" its name, "channels" each in its
checked form ({:field, f}, a number, {:scale, :min | :max | :boundary}), "options"
every option present with its default, "style" the resolved element style,
"label" and "tooltip" their checked nodes ("label" with its resolved style under
"style"), "scales" its renames, "offset", "render", "transition", "id",
"frame", "data", its position among its frame's layers ("index") and its path
among the document's ("path"). Beside them, "context" holds what the delivery and
the Frame give the drawing: theme, mode, schema (the slot's), served (the
delivery's served facts), resolution (device pixels per pixel), position (the
one-based position among the document's layers) and styles (the design's named
styles). A kind never reads the unchecked document.
use Macaw.Frame.Layer
use Macaw.Frame.Layer declares the behavior and writes the callbacks most kinds share,
each overridable: scales/2 by the model's channel table and the layer's renames,
validate/2 answering [], legend/2 its series field with its paint's swatch,
closed?/0 false, bend?/0 true, order/0 :normal, targets/0 every renderer,
parts/0 from paint/0, assets/1 none, and budget/2 w.
Summary
Callbacks
The inline label's anchor point of one drawn element (§1.8).
Media and hooks the kind needs, folded into the Frame's declarations.
Whether a polar frame bends it.
Its budget hint: rows it needs at a plot width in pixels, nil for no rows (§1.10).
Every channel the kind reads, in order (§1.2).
Whether its elements are closed shapes, for stroke placement (§1.7.4).
Its draw into the scene: one group in the plot's coordinates, every element keyed.
The width a label fits into on an element at the label's point (§1.8.2).
Its legend contribution: the fields it shows by a scale and how its swatch reads.
The coordinate models the kind draws in, or :any.
The kind's name, unique in the registry; a document spells it as a string.
The kind's geometry scalars, each declared as a macaw_data option with its default.
:beneath draws before every :normal layer of its frame (the tiles).
Which key its series color and default color reach.
The style parts the kind draws (§1.7.3).
The scale each of the layer's channels reads, by the model's table and the renames.
Its text-summary contribution (§1.11).
The renderers it can draw on.
Its own checks of a layer node beyond the generic ones (§1.5).
Functions
The behavior's required callbacks, [{name, arity}].
The checked layer of a layer node (§1.6): {:ok, layer}, or the faults of what cannot
be checked. The node is the frame document's (atom or string keys); options
Whether a module implements every required callback of the behavior.
A channel's reading in its checked form (§1.3): a field's name (a string or an atom,
read by spelling) is {:field, name}; a number, {:field, f} and a scale end stand.
Types
Callbacks
The inline label's anchor point of one drawn element (§1.8).
Media and hooks the kind needs, folded into the Frame's declarations.
@callback bend?() :: boolean()
Whether a polar frame bends it.
@callback budget(t() | map(), non_neg_integer()) :: pos_integer() | nil
Its budget hint: rows it needs at a plot width in pixels, nil for no rows (§1.10).
@callback channels() :: [Macaw.Frame.Layer.Channel.t()]
Every channel the kind reads, in order (§1.2).
@callback closed?() :: boolean()
Whether its elements are closed shapes, for stroke placement (§1.7.4).
@callback draw(t(), Macaw.Data.Table.t(), Macaw.Frame.Coordinates.Model.t()) :: {:ok, Macaw.Draw.IR.Element.t()} | {:error, [Macaw.Base.Fault.t()]}
Its draw into the scene: one group in the plot's coordinates, every element keyed.
The width a label fits into on an element at the label's point (§1.8.2).
Its legend contribution: the fields it shows by a scale and how its swatch reads.
@callback models() :: [atom()] | :any
The coordinate models the kind draws in, or :any.
@callback name() :: atom()
The kind's name, unique in the registry; a document spells it as a string.
@callback options() :: [{String.t(), Macaw.Data.Operations.Option.t()}]
The kind's geometry scalars, each declared as a macaw_data option with its default.
@callback order() :: :beneath | :normal
:beneath draws before every :normal layer of its frame (the tiles).
@callback paint() :: :fill | :stroke | nil
Which key its series color and default color reach.
@callback parts() :: [part()]
The style parts the kind draws (§1.7.3).
@callback scales(t(), Macaw.Frame.Coordinates.Model.t()) :: %{ required(String.t()) => String.t() | :pixels }
The scale each of the layer's channels reads, by the model's table and the renames.
@callback summary(t(), Macaw.Data.Table.t(), Macaw.Frame.Coordinates.Model.t()) :: Macaw.Frame.Layer.Summary.t()
Its text-summary contribution (§1.11).
@callback targets() :: [:svg | :canvas | :binary]
The renderers it can draw on.
@callback validate(map(), map()) :: [Macaw.Base.Fault.t()]
Its own checks of a layer node beyond the generic ones (§1.5).
Functions
@spec callbacks() :: keyword(non_neg_integer())
The behavior's required callbacks, [{name, arity}].
@spec checked(term(), keyword()) :: {:ok, t()} | {:error, [Macaw.Base.Fault.t(), ...]}
The checked layer of a layer node (§1.6): {:ok, layer}, or the faults of what cannot
be checked. The node is the frame document's (atom or string keys); options:
kind:the kind's module (required);index:its position among its frame's layers (0),path:its path in the document ([:layers, index]),position:its one-based position among the document's layers (frompath);theme:(Macaw.Layers.Theme.default()),mode:(:css),styles:the design's named styles,defaults:the containers' defaults farthest first, orstyle:the already resolved element style, as compilation holds it (spec/02 §12.2);schema:,served:andresolution:from the delivery.
The layer's style stack is laid over its containers' defaults for its kind and resolved
in the theme; its label's over the label style and the containers' part defaults,
never the layer's style (§1.7.1).
Whether a module implements every required callback of the behavior.
iex> Macaw.Frame.Layer.kind?(Enum)
false
A channel's reading in its checked form (§1.3): a field's name (a string or an atom,
read by spelling) is {:field, name}; a number, {:field, f} and a scale end stand.