# `Visualize.Chart.Presets`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/chart/presets.ex#L1)

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}]}

# `assigns`

```elixir
@type assigns() :: %{optional(atom()) =&gt; term()}
```

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

# `name`

```elixir
@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`.

# `area_chart`

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

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

# `bar_chart`

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

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

# `defaults`

```elixir
@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`

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

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

# `horizontal_bar_chart`

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

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

# `line_chart`

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

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

# `names`

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

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

# `pie_chart`

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

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

# `scatter_plot`

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

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

# `sources`

```elixir
@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`

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

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

# `sunburst_chart`

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

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

# `tree_diagram`

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

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

# `treemap_chart`

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

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
