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

The design schema as data (spec/14 §14.2).

Every node kind of the design map (spec/14 §1.2) is a list of key specs, each with a
type (§1.4), a facet (§1.3), a default, whether it is required and a merge rule (§1.5).
The validator, the JSON codec and the introspection a builder needs all derive from
these specs, so a key added here reaches every consumer at once (D-58). Which keys are
style is `keys(:style)`, never a hand-kept list.

The design-level node kinds live here; the frame's and the marks' tables are in two
hidden submodules reached only through this one.

## Examples

    iex> Visualize.Chart.Schema.key(:mark, :style).facet
    :style
    iex> Visualize.Chart.Schema.default(:frame, :margin)
    %{top: 20, right: 20, bottom: 30, left: 40}
    iex> Visualize.Chart.Schema.channels(:line)
    %{required: [:x, :y], optional: [:series]}

# `facet`

```elixir
@type facet() :: :binding | :channel | :geometry | :style | :content
```

What a key is about (spec/14 §1.3).

# `key_spec`

```elixir
@type key_spec() :: %{
  key: atom(),
  type: type(),
  facet: facet(),
  default: term(),
  required: boolean(),
  merge: merge(),
  range: {number(), number(), number()} | nil
}
```

One key of a node kind.

# `kind`

```elixir
@type kind() :: atom()
```

A node kind of the design map (spec/14 §1.2).

# `merge`

```elixir
@type merge() :: :concat | :union | :deep | :override
```

How two fragments combine under a key (spec/14 §1.5).

# `type`

```elixir
@type type() :: atom() | tuple()
```

A type term of spec/14 §1.4.

# `builtin_styles`

```elixir
@spec builtin_styles() :: [atom(), ...]
```

The style names every design declares (spec/14 §3.3).

# `channels`

```elixir
@spec channels(atom()) :: %{required: [atom()], optional: [atom()]}
```

The required and optional channels of a mark type (spec/14 §5.2).

# `column_types`

```elixir
@spec column_types() :: [atom(), ...]
```

The five column types a source's `types` may name (spec/14 §2.3, #369, D-233).

# `default`

```elixir
@spec default(kind(), atom()) :: term()
```

The default of a key, `nil` when it has none or is required.

# `describe`

```elixir
@spec describe(kind()) :: [key_spec(), ...]
```

The key specs of a node kind, in the order of its table in spec/14.

# `key`

```elixir
@spec key(kind(), atom()) :: key_spec() | nil
```

The spec of one key of a node kind, or `nil` when the node has no such key.

# `keys`

```elixir
@spec keys(facet()) :: [{kind(), atom()}]
```

Every `{kind, key}` pair carrying the facet, over every node kind (spec/14 §1.3).

# `keys`

```elixir
@spec keys(kind(), facet()) :: [atom()]
```

The keys of one node kind carrying the facet, in table order.

# `kinds`

```elixir
@spec kinds() :: [kind(), ...]
```

Every node kind of spec/14 §1.2, the design first.

# `mark_types`

```elixir
@spec mark_types() :: [atom(), ...]
```

The mark types of spec/14 §5.2, in table order.

# `options`

```elixir
@spec options(atom()) :: [atom()]
```

The option keys a mark type reads (spec/14 §5.3).

# `scale_kinds`

```elixir
@spec scale_kinds() :: [atom(), ...]
```

The scale kinds of spec/14 §4.3.

# `style_sites`

```elixir
@spec style_sites() :: [{kind(), atom()}, ...]
```

Every style site: each `{kind, key}` whose type is the style stack (spec/14 §3.6), in
`kinds/0` order, derived from the tables (D-196).

    iex> Visualize.Chart.Schema.style_sites()
    [label: :style, axis: :style, legend: :style, mark: :style, mark_label: :style, choice: :style]

# `style_stack`

```elixir
@spec style_stack() :: type()
```

The type a style site takes (spec/14 §3.6): a reference, an inline node, a field binding
`{:field, f}` whose value per datum names a style (#644), a generator call
`{:generate, name, args}` whose result is a style (§3.13, #654), or a list of those.

Written once because five keys share it — `mark.style`, `label.style`, `mark_label.style`,
`axis.style` and `legend.style` — and a sixth would otherwise be a sixth copy.

    iex> {:one_of, alts} = Visualize.Chart.Schema.style_stack()
    iex> {:ref, :style} in alts
    true

# `transform_keys`

```elixir
@spec transform_keys(atom()) :: %{required: [atom()], optional: [atom()]}
```

The required and optional keys of a transform op (spec/14 §5.4).

# `transform_ops`

```elixir
@spec transform_ops() :: [atom(), ...]
```

The transform ops of spec/14 §5.4.

---

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