Visualize.Chart.Builder.Themes (Visualize v0.4.1)

Copy Markdown View Source

The theme mode's editor (spec/14 §20, D-139): the theme a chart holds, as a node the builder writes and as the %Visualize.Theme{} it draws as, and the panel that edits it.

The mode is the builder's shape while the open chart is a theme. Its writes are the theme node of one site — the selected site, or the first of the chart that carries a theme — and every one goes through change/3, a pure reading of one control's value, so the panel and the tests agree on what a control means. The theme is drawn unchecked — its fields over the default theme, no contract checked — so a theme that breaks a contract still draws while a person fixes it, and the validity section says what breaks.

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

Summary

Functions

The node with the ramp resampled at one more evenly spaced anchor, each the colour the ramp had at its position (spec/14 §20.4): the ramp changes as little as the even spacing allows, and the new anchor is there to be moved.

The node without the ramp's anchor at i; a ramp keeps two anchors (spec/14 §20.4).

The node with one control's value written (spec/14 §20.2), or :error for a value that does not read — a blank, a colour Visualize.Color.parse/1 cannot read, a size that is not a positive number — so the node is left as it was.

The node with every value of theme and the node's own name (spec/14 §20.2): a variant starts from what it varies. A node with no name takes none, so a new theme does not take a built-in theme's name by deriving from it.

The theme a site holds as the node the editor writes (spec/14 §20.1): a name as the whole node of the theme it names — built-in, else the store's — so an edit changes one value of the theme a person was looking at; a map as it is; anything else an empty node.

The %Visualize.Theme{} a design's theme value draws as (spec/14 §20.3): a built-in name, the store's theme of that name, or a map over the default theme — built unchecked, so a theme that breaks a contract still draws. Anything else is the default theme.

Renders the theme editor (spec/14 §20.2, §20.4, §20.5): derive from and the vision select, then <form class="vis-builder-theme"> of sections — the theme's name, the series, the chrome, the fonts, the ramps and the roles — then the theme's validity.

The node with one more series colour: the default palette's colour at the next position, cycling, so a new series is distinct from its neighbours.

The node without the series colour at i; the last colour stays (spec/08 §7.2).

Functions

anchor_added(node, ramp)

@spec anchor_added(map(), Visualize.Theme.ramp_name()) :: map()

The node with the ramp resampled at one more evenly spaced anchor, each the colour the ramp had at its position (spec/14 §20.4): the ramp changes as little as the even spacing allows, and the new anchor is there to be moved.

iex> node = Visualize.Chart.Builder.Themes.anchor_added(%{}, :thermal)
iex> node.ramps.thermal
["#0e68ad", "#acbbd5", "#e3aea6", "#c02e31"]

anchor_removed(node, ramp, i)

@spec anchor_removed(map(), Visualize.Theme.ramp_name(), non_neg_integer()) :: map()

The node without the ramp's anchor at i; a ramp keeps two anchors (spec/14 §20.4).

change(node, field, value)

@spec change(map(), String.t(), String.t()) :: {:ok, map()} | :error

The node with one control's value written (spec/14 §20.2), or :error for a value that does not read — a blank, a colour Visualize.Color.parse/1 cannot read, a size that is not a positive number — so the node is left as it was.

iex> Visualize.Chart.Builder.Themes.change(%{}, "axis", "#555555")
{:ok, %{axis: "#555555"}}

iex> Visualize.Chart.Builder.Themes.change(%{series: ["#111111", "#222222"]}, "series.1", "#333333")
{:ok, %{series: ["#111111", "#333333"]}}

iex> Visualize.Chart.Builder.Themes.change(%{}, "font_size", "eleven")
:error

derived(node, theme)

@spec derived(map(), Visualize.Theme.t()) :: map()

The node with every value of theme and the node's own name (spec/14 §20.2): a variant starts from what it varies. A node with no name takes none, so a new theme does not take a built-in theme's name by deriving from it.

iex> node = Visualize.Chart.Builder.Themes.derived(%{name: :house}, Visualize.Theme.dark())
iex> {node.name, node.background}
{:house, "#1b1e24"}

editable(value, store)

@spec editable(term(), Visualize.Chart.Builder.Store.store() | nil) :: map()

The theme a site holds as the node the editor writes (spec/14 §20.1): a name as the whole node of the theme it names — built-in, else the store's — so an edit changes one value of the theme a person was looking at; a map as it is; anything else an empty node.

effective(name, store)

The %Visualize.Theme{} a design's theme value draws as (spec/14 §20.3): a built-in name, the store's theme of that name, or a map over the default theme — built unchecked, so a theme that breaks a contract still draws. Anything else is the default theme.

panel(assigns)

Renders the theme editor (spec/14 §20.2, §20.4, §20.5): derive from and the vision select, then <form class="vis-builder-theme"> of sections — the theme's name, the series, the chrome, the fonts, the ramps and the roles — then the theme's validity.

Attributes

  • id (:string) (required) - the panel's id.
  • node (:map) (required) - the theme node being edited, as editable/2 gives it.
  • theme (:any) (required) - the %Visualize.Theme{} the node draws as.
  • faults (:list) - the theme's faults, each a line a person reads. Defaults to [].
  • derive (:list) - the themes to derive from, {label, value} each. Defaults to [].
  • vision (:atom) - the deficiency the ramps and the sheet are seen under. Defaults to :none.
  • target (:any) - the phx-target of the panel's events. Defaults to nil.

series_added(node)

@spec series_added(map()) :: map()

The node with one more series colour: the default palette's colour at the next position, cycling, so a new series is distinct from its neighbours.

series_removed(node, i)

@spec series_removed(map(), non_neg_integer()) :: map()

The node without the series colour at i; the last colour stays (spec/08 §7.2).