Visualize.Chart.Presets (Visualize v0.2.25)

Copy Markdown View Source

The ten LiveView components as stored designs (spec/14 §15, D-64).

Each preset is a function from a component's assigns — the keys of its table in spec/10, an absent one taking defaults/1 — to a design map of spec/14: no function reaches the map, because the accessor assigns are applied once by sources/2, the assign mapping, into the rows the design's one source (data) binds to. Visualize.Components and Visualize.Components.Tree render these designs through Visualize.Chart.Frame; a design is also a value of its own, storable and bindable to any source with the same columns.

Examples

iex> design =
...>   Visualize.Chart.Presets.bar_chart(%{
...>     data: [%{name: "a", value: 3}, %{name: "b", value: 5}],
...>     x: & &1.name,
...>     y: & &1.value
...>   })
iex> design.frames.main.scales
%{x: %{kind: :band, padding: 0.1}, y: %{kind: :linear, domain: [0, :auto]}}
iex> hd(design.marks).channels
%{x0: :x, x1: :x, y0: 0, y1: :y}
iex> {:ok, _chart} = Visualize.Chart.from_map(design)
iex> Visualize.Chart.Presets.sources(
...>   :bar_chart,
...>   %{data: [%{name: "a", value: 3}], x: & &1.name, y: & &1.value}
...> )
%{data: [%{x: "a", y: 3}]}

Summary

Types

A component's assigns: the keys of its table in spec/10.

A preset name: one of names/0.

Functions

The area_chart design (spec/14 §15.3, spec/10 §2.7).

The bar_chart design (spec/14 §15.3, spec/10 §2.3).

The assigns a component's table defaults (spec/10 §2–3), as a map: the one place the numbers live, which the components' attr/3 declarations read.

The design of the named preset: the function of that name over assigns.

The horizontal_bar_chart design (spec/14 §15.3, spec/10 §2.4).

The line_chart design (spec/14 §15.3, spec/10 §2.2).

The ten preset names in the order of spec/10 §2.1 and §3.1.

The pie_chart design (spec/14 §15.3, spec/10 §2.5).

The scatter_plot design (spec/14 §15.3, spec/10 §2.6).

The assign mapping (spec/14 §15.2): %{data: rows}, the rows the design's source binds to — the accessor assigns applied to each row of data, or the nested map flattened to one row per node for a hierarchy preset.

The stacked_bar_chart design (spec/14 §15.3, spec/10 §2.8).

The sunburst_chart design (spec/14 §15.4, spec/10 §3.4).

The tree_diagram design (spec/14 §15.4, spec/10 §3.2).

The treemap_chart design (spec/14 §15.4, spec/10 §3.3).

Types

assigns()

@type assigns() :: %{optional(atom()) => term()}

A component's assigns: the keys of its table in spec/10.

name()

@type name() ::
  :line_chart
  | :bar_chart
  | :horizontal_bar_chart
  | :pie_chart
  | :scatter_plot
  | :area_chart
  | :stacked_bar_chart
  | :tree_diagram
  | :treemap_chart
  | :sunburst_chart

A preset name: one of names/0.

Functions

area_chart(assigns)

@spec area_chart(assigns()) :: map()

The area_chart design (spec/14 §15.3, spec/10 §2.7).

bar_chart(assigns)

@spec bar_chart(assigns()) :: map()

The bar_chart design (spec/14 §15.3, spec/10 §2.3).

defaults(name)

@spec defaults(name()) :: assigns()

The assigns a component's table defaults (spec/10 §2–3), as a map: the one place the numbers live, which the components' attr/3 declarations read.

design(name, assigns)

@spec design(name(), assigns()) :: map()

The design of the named preset: the function of that name over assigns.

horizontal_bar_chart(assigns)

@spec horizontal_bar_chart(assigns()) :: map()

The horizontal_bar_chart design (spec/14 §15.3, spec/10 §2.4).

line_chart(assigns)

@spec line_chart(assigns()) :: map()

The line_chart design (spec/14 §15.3, spec/10 §2.2).

names()

@spec names() :: [name()]

The ten preset names in the order of spec/10 §2.1 and §3.1.

pie_chart(assigns)

@spec pie_chart(assigns()) :: map()

The pie_chart design (spec/14 §15.3, spec/10 §2.5).

scatter_plot(assigns)

@spec scatter_plot(assigns()) :: map()

The scatter_plot design (spec/14 §15.3, spec/10 §2.6).

sources(name, assigns)

@spec sources(name(), assigns()) :: %{data: [map()]}

The assign mapping (spec/14 §15.2): %{data: rows}, the rows the design's source binds to — the accessor assigns applied to each row of data, or the nested map flattened to one row per node for a hierarchy preset.

stacked_bar_chart(assigns)

@spec stacked_bar_chart(assigns()) :: map()

The stacked_bar_chart design (spec/14 §15.3, spec/10 §2.8).

sunburst_chart(assigns)

@spec sunburst_chart(assigns()) :: map()

The sunburst_chart design (spec/14 §15.4, spec/10 §3.4).

tree_diagram(assigns)

@spec tree_diagram(assigns()) :: map()

The tree_diagram design (spec/14 §15.4, spec/10 §3.2).

treemap_chart(assigns)

@spec treemap_chart(assigns()) :: map()

The treemap_chart design (spec/14 §15.4, spec/10 §3.3).