Visualize.Chart.Refs (Visualize v0.2.25)

Copy Markdown View Source

Reference resolution as one rule (spec/14 §19.6, D-103): every library id at a reference site of a flat design is resolved through a store, so that what leaves Visualize.Chart.flatten/2 carries no ids and what the frame draws needs no store.

A {:style, n} at a style site — a mark's, an axis's, a label's style, alone or in a stack (§3.6) — becomes the entry's body inline, since a style site already takes a node. A {:scale, n} or {:source, n} at a single-valued site — an axis's scale, a mark's data, a mark's scales.x — is declared in the design's namespace for the kind under a synthesised key, :"scale:4", the word the DOM already uses for the id, and the site is rewritten to that key. A body that is itself a composite is flattened first.

An id the store no longer holds is a mask at the site (§19.2, D-100): a style entry becomes nothing, a single-valued site is removed so the kind's default or the validator's fault applies, and the id is reported. Rendering never fails on a stale reference and never draws less than it says.

Summary

Types

The ids no store could find, each with the path of the site that named it.

Functions

A flat design with every id at a reference site resolved through fetch, and the ids that were missing.

Types

missing()

@type missing() :: [{[atom() | non_neg_integer()], Visualize.Chart.Fragment.id()}]

The ids no store could find, each with the path of the site that named it.

Functions

resolve(design, fetch)

@spec resolve(map(), (Visualize.Chart.Fragment.id() -> {:ok, map()} | :error)) ::
  {map(), missing()}

A flat design with every id at a reference site resolved through fetch, and the ids that were missing.

iex> lib = %{{:style, 1} => %{style: %{stroke_width: 5}}, {:scale, 4} => %{scale: %{kind: :linear}}}
iex> design = %{frames: %{main: %{axes: [%{scale: {:scale, 4}, side: :left}]}}, marks: [%{id: :m, style: [{:style, 1}, %{opacity: 0.5}], scales: %{x: {:scale, 9}}}]}
iex> {resolved, missing} = Visualize.Chart.Refs.resolve(design, &Map.fetch(lib, &1))
iex> hd(resolved.frames.main.axes).scale
:"scale:4"
iex> resolved.frames.main.scales
%{"scale:4": %{kind: :linear}}
iex> hd(resolved.marks).style
[%{stroke_width: 5}, %{opacity: 0.5}]
iex> {Map.has_key?(hd(resolved.marks).scales, :x), missing}
{false, [{[:marks, 0, :scales, :x], {:scale, 9}}]}