# `Visualize.Scale.Band`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/scale/band.ex#L1)

A discrete scale that divides the range into uniform bands.

Essential for bar charts where each category gets an equal-width band. The band maths
is d3-scale's: a descending range lays the bands out in reverse with positive `step`
and `bandwidth`, and `round/2` floors the step and rounds the start and bandwidth so
every position is an integer.

Every setter lays the bands out again, as d3-scale's `rescale` does, 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 domain of a thousand categories as over ten (spec/03 §9.3).

# `t`

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

# `align`

```elixir
@spec align(t(), number()) :: t()
```

Sets alignment (0 to 1) for distributing outer space

# `apply`

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

Returns the start position for a category, or `nil` when it is not in the domain

# `bandwidth`

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

Returns the width of each band

# `clamp`

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

Identity: a band scale never extrapolates

# `domain`

```elixir
@spec domain(t(), [any()]) :: t()
```

Sets the domain (list of categories)

# `invert`

```elixir
@spec invert(t(), number()) :: nil
```

Returns `nil`: a band scale is not invertible

# `new`

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

Creates a new band scale

# `nice`

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

Identity

# `padding`

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

Sets both inner and outer padding (0 to 1)

# `padding_inner`

```elixir
@spec padding_inner(t(), number()) :: t()
```

Sets inner padding between bands

# `padding_outer`

```elixir
@spec padding_outer(t(), number()) :: t()
```

Sets outer padding at range edges

# `range`

```elixir
@spec range(t(), [number()]) :: t()
```

Sets the range

# `round`

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

Enables rounding: the step is floored, the start and bandwidth rounded

# `step`

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

Returns the step (band + padding); floored when `round?`

# `ticks`

```elixir
@spec ticks(t(), integer()) :: [any()]
```

Returns the domain as ticks

---

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