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

A discrete scale dividing a numeric range into uniform bands, one per category
(spec/06 §10): what a bar chart places its bars by.

The band math is d3-scale's `rescale`: a descending range lays the bands out in reverse
with a positive `step` and `bandwidth`, and `round/2` floors the step and rounds the
start and bandwidth so every position is a whole number. Every setter lays the bands out
again and keeps the layout and each category's slot in the struct, so `apply/2`,
`bandwidth/1` and `step/1` cost the same over a thousand categories as over ten.
`inspect/1` leaves the derived `slots` and `layout` out; a struct built by hand rather
than by the setters has no slots and places nothing.

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Scale.Band{
  align: number(),
  domain: [term()],
  layout: {number(), number(), number(), boolean()},
  padding_inner: number(),
  padding_outer: number(),
  range: [number()],
  round?: boolean(),
  slots: %{optional(term()) =&gt; non_neg_integer()}
}
```

# `align`

```elixir
@spec align(t(), term()) :: {:ok, t()} | error()
```

Sets how the outer space is shared, `0 ≤ a ≤ 1`, `0.5` centering the bands:
`{:ok, scale}` or `{:error, [{[], {:range, :align, a}}]}`.

# `align!`

```elixir
@spec align!(t(), term()) :: t()
```

`align/2`, answering the scale or raising `Macaw.Draw.Error`.

# `apply`

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

The start of a category's band, or `nil` for a value not in the domain.

# `bandwidth`

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

The width of each band.

# `clamp`

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

Identity: a band scale never extrapolates.

# `domain`

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

Sets the categories, any list; answers the struct.

# `invert`

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

`nil`: a band scale is not invertible.

# `new`

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

A band scale with no categories over `[0, 1]`.

# `nice`

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

Identity.

# `padding`

```elixir
@spec padding(t(), term()) :: {:ok, t()} | error()
```

Sets the inner and outer padding together, `0 ≤ p < 1`: `{:ok, scale}`, or
`{:error, [{[], {:range, :padding, p}}]}`.

# `padding!`

```elixir
@spec padding!(t(), term()) :: t()
```

`padding/2`, answering the scale or raising `Macaw.Draw.Error`.

# `padding_inner`

```elixir
@spec padding_inner(t(), term()) :: {:ok, t()} | error()
```

Sets the padding between bands, `0 ≤ p < 1`: `{:ok, scale}` or `{:error, faults}`.

# `padding_inner!`

```elixir
@spec padding_inner!(t(), term()) :: t()
```

`padding_inner/2`, answering the scale or raising `Macaw.Draw.Error`.

# `padding_outer`

```elixir
@spec padding_outer(t(), term()) :: {:ok, t()} | error()
```

Sets the padding at the range's ends, `p ≥ 0`: `{:ok, scale}` or `{:error, faults}`.

# `padding_outer!`

```elixir
@spec padding_outer!(t(), term()) :: t()
```

`padding_outer/2`, answering the scale or raising `Macaw.Draw.Error`.

# `range`

```elixir
@spec range(t(), term()) :: {:ok, t()} | error()
```

Sets the range, two numbers: `{:ok, scale}` or `{:error, faults}`.

# `range!`

```elixir
@spec range!(t(), term()) :: t()
```

`range/2`, answering the scale or raising `Macaw.Draw.Error`.

# `round`

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

Sets rounding: the step floored, the start and bandwidth rounded; answers the struct.

# `step`

```elixir
@spec step(t()) :: number() | error()
```

The distance between adjacent band starts; floored when the scale rounds.

# `ticks`

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

The domain; the count is ignored.

---

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