Visualize.Chart.Style (Visualize v0.2.25)

Copy Markdown View Source

Style resolution for the declarative layer (spec/14 §3.4, D-63): one style node, two outputs by the mode of the render target.

resolve/3 turns a :style node into the style map of a Visualize.IR.Element: the fourteen element keys, every theme slot resolved through Visualize.Theme.resolve/3 — a CSS custom-property reference in :css, the literal a canvas needs in :literal — a dash-array list joined, a literal passed through. A {:field, f} survives it, and bind/4 then reads it from a datum, a colour key's reading through the frame's color scale when the frame declares one. The frame's furniture and the marks share this resolver.

A style is looked up by name with its extends chain flattened first — the parent's keys, the child's over them (spec/14 §3.5, D-80) — so no consumer sees that key and a resolved node never carries it. A cycle raises ArgumentError; the validator reports it by path.

Examples

iex> theme = Visualize.Theme.default()
iex> Visualize.Chart.Style.resolve(%{stroke: :axis, stroke_width: 2, curve: :step}, theme, :css)
%{stroke: "var(--vis-axis, #666666)", stroke_width: 2}
iex> Visualize.Chart.Style.resolve(%{stroke: :axis, stroke_dasharray: [2, 2]}, theme, :literal)
%{stroke: "#666666", stroke_dasharray: "2 2"}

Summary

Functions

The map of resolve/3 with every {:field, f} read from the datum (spec/14 §3.4).

The element style map of a style node, every slot resolved in mode (spec/14 §3.4).

Functions

bind(style, datum, frame, mode)

@spec bind(map(), term(), map(), Visualize.Theme.mode()) :: map()

The map of resolve/3 with every {:field, f} read from the datum (spec/14 §3.4).

A colour key's reading passes through the frame's color scale when the frame declares one — a category outside its domain is the scale's unknown — and is resolved as a theme slot when it is one. A colour is never dropped: a nil reading, or a scale that yields nil, is :none, the explicit "no paint" SVG and canvas agree on, where an absent fill is black on one and nothing on the other (D-122). Any other key's nil reading drops the key.

resolve(node, theme, mode)

@spec resolve(map(), Visualize.Theme.t(), Visualize.Theme.mode()) :: map()

The element style map of a style node, every slot resolved in mode (spec/14 §3.4).

Only the keys an element renders are kept; curve, curve_opts, symbol and symbol_size reach the mark's generator instead. A {:field, f} is kept for bind/4. Raises ArgumentError for a variable: variables resolve at application (spec/14 §7.3).