Visualize.Chart.Builder.Variables (Visualize v0.2.35)

Copy Markdown View Source

The variable panel (spec/14 §19.10): the composition's variables as chips, and what a person does with them.

Every variable the stack declares or uses is listed alphabetically as a chip — the thing dragged onto a control to bind it (§19.9). A chip expands to its details: the type it took from its first use (§17.2), every use as a link to the node, its declared default, the value the preview binds it to, and the per-site rows of §19.4. A find box filters the list and names the variable whose fields the form highlights; a create form declares a new one as a var site of the stack.

This module compiles only when Phoenix.Component is loaded (spec/10 §1.1, D-45, D-85).

Summary

Functions

Every variable of the composition, alphabetically: what the stack still needs (Visualize.Chart.free_vars/1) and what it declares, each with the type its first use expects, or nil for one used nowhere.

Renders the variable panel: the chips, the find box, the create form, and each expanded chip's details.

The type a variable took from its first use (spec/14 §17.2), or nil for none.

The variables the composition still needs a value for (spec/14 §18.13, #363): those of list/2 with neither a default in their declaration nor a binding among bindings, alphabetically — the count the variables tab wears as its badge.

Functions

list(layers, design)

@spec list([{term(), map()}], map()) :: [map()]

Every variable of the composition, alphabetically: what the stack still needs (Visualize.Chart.free_vars/1) and what it declares, each with the type its first use expects, or nil for one used nowhere.

iex> layers = [{"a", %{vars: %{unit: %{default: "%"}}, labels: [%{anchor: :title, text: ["u ", Visualize.Chart.var(:unit)]}]}}]
iex> [unit] = Visualize.Chart.Builder.Variables.list(layers, Visualize.Chart.stack(layers))
iex> {unit.name, unit.type, unit.default, length(unit.uses)}
{:unit, :text, "%", 1}

panel(assigns)

Renders the variable panel: the chips, the find box, the create form, and each expanded chip's details.

Attributes

  • id (:string) (required) - the panel's id.
  • layers (:list) (required) - the resolved layers, {label, fragment} in stack order.
  • design (:map) (required) - the stacked design, for what is declared.
  • bindings (:map) - the values the preview binds variables to. Defaults to %{}.
  • sites (:list) - the per-site rows, as Stack.sites/3 gives them. Defaults to [].
  • expanded (:any) - the names expanded, a MapSet. Defaults to nil.
  • find (:string) - the find box's text. Defaults to "".
  • target (:any) - the phx-target of the panel's events. Defaults to nil.

type_of(arg)

@spec type_of([map()]) :: term() | nil

The type a variable took from its first use (spec/14 §17.2), or nil for none.

unbound(layers, design, bindings)

@spec unbound([{term(), map()}], map(), map()) :: [map()]

The variables the composition still needs a value for (spec/14 §18.13, #363): those of list/2 with neither a default in their declaration nor a binding among bindings, alphabetically — the count the variables tab wears as its badge.

iex> layers = [{"a", %{labels: [%{anchor: :title, text: ["u ", Visualize.Chart.var(:unit)]}]}}]
iex> design = Visualize.Chart.stack(layers)
iex> Visualize.Chart.Builder.Variables.unbound(layers, design, %{}) |> Enum.map(& &1.name)
[:unit]
iex> Visualize.Chart.Builder.Variables.unbound(layers, design, %{unit: "%"})
[]