# `Macaw.Draw.Scale.Ordinal`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/scale/ordinal.ex#L1)

A discrete scale, a category to a range element (spec/06 §9).

`apply/2` finds the first domain element equal (`==`) to the value, else the first of
the same spelling (`Macaw.Base.Names.same?/2`: `:ok` and `"ok"` are one category), and
answers the range element at its index, the range cycling when the domain is longer. A
value the domain lacks answers `unknown`, `nil` by default; the domain is never extended
implicitly.

The lookup is a map built once by `domain/2`: each category's first index keyed by the
category (an integral float keyed as its integer, as `==` equates them), and a second
keyed by its spelling, so `apply/2` costs two map reads at most whatever the domain's
length. `inspect/1` leaves the derived maps out.

# `error`

```elixir
@type error() :: {:error, [Macaw.Base.Fault.t()]}
```

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Scale.Ordinal{
  domain: [term()],
  index: %{optional(term()) =&gt; non_neg_integer()},
  range: [term()],
  spelled: %{optional(term()) =&gt; non_neg_integer()},
  unknown: term(),
  values: tuple()
}
```

# `apply`

```elixir
@spec apply(t(), term()) :: term() | error()
```

The range element of a category, the range cycling; `unknown` for a category the domain
lacks or an empty range.

# `bandwidth`

```elixir
@spec bandwidth(t()) :: 0 | error()
```

`0`: an ordinal scale has no bandwidth.

# `clamp`

```elixir
@spec clamp(t(), boolean()) :: t() | error()
```

Identity: an ordinal scale never extrapolates.

# `domain`

```elixir
@spec domain(t(), [term()]) :: t() | error()
```

Sets the domain, a list of any terms; answers the struct.

# `invert`

```elixir
@spec invert(t(), term()) :: nil | error()
```

`nil`: an ordinal scale is not invertible.

# `new`

```elixir
@spec new() :: t()
```

An ordinal scale with no domain and no range.

# `nice`

```elixir
@spec nice(t()) :: t() | error()
```

Identity.

# `padding`

```elixir
@spec padding(t(), number()) :: t() | error()
```

Identity: an ordinal scale has no padding.

# `range`

```elixir
@spec range(t(), [term()]) :: t() | error()
```

Sets the range, a list; answers the struct.

# `ticks`

```elixir
@spec ticks(t(), number()) :: [term()] | error()
```

The domain; the count is ignored.

# `unknown`

```elixir
@spec unknown(t(), term()) :: t() | error()
```

Sets the value for a category the domain lacks (default `nil`); answers the struct.

---

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