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

The protocol every scale module implements (spec/03 §1.3).

`Visualize.Scale` dispatches each of these operations to the module named by the scale
struct (`scale.__struct__`). A module that declares this behaviour and omits a callback
fails to compile under `--warnings-as-errors`, which is what keeps the facade total: no
scale reaches `Visualize.Scale.apply/2` without an `apply/2` of its own.

Operations that do not apply to a scale kind are still defined and behave as identity
(`nice/1`, `padding/2`, `clamp/2`), return `nil` (`invert/2`), or return `0`
(`bandwidth/1`). The discretizing scales (`Quantile`, `Quantize`, `Threshold`) return their
thresholds from `ticks/2`.

# `scale`

```elixir
@type scale() :: struct()
```

Any scale struct.

# `apply`

```elixir
@callback apply(scale(), term()) :: term()
```

Maps a domain value to a range value.

# `bandwidth`

```elixir
@callback bandwidth(scale()) :: number()
```

The band width; `0` for every scale but `Band`.

# `clamp`

```elixir
@callback clamp(scale(), boolean()) :: scale()
```

Enables or disables clamping; identity where the scale never extrapolates.

# `domain`

```elixir
@callback domain(scale(), term()) :: scale()
```

Sets the input domain; the argument shape is the module's own.

# `invert`

```elixir
@callback invert(scale(), term()) :: term() | nil
```

Maps a range value back to the domain; `nil` where the scale is not invertible.

# `nice`

```elixir
@callback nice(scale()) :: scale()
```

Extends the domain outward to round values; identity where that has no meaning.

# `padding`

```elixir
@callback padding(scale(), number()) :: scale()
```

Sets band padding; identity for every scale but `Band`.

# `range`

```elixir
@callback range(scale(), term()) :: scale()
```

Sets the output range; the argument shape is the module's own.

# `ticks`

```elixir
@callback ticks(scale(), integer()) :: [term()]
```

Representative domain values; `count` is a hint, never a guarantee.

# `normalize`

```elixir
@spec normalize(number(), number(), number()) :: float()
```

The position of `value` between `a` and `b` as a fraction, `0.5` when `a == b`.

d3-scale's `normalize`: a collapsed domain maps every value to the middle of the range and
a collapsed range inverts to the middle of the domain, instead of dividing by zero (D-49).
Every continuous scale's `apply/2` and `invert/2` go through it.

---

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