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

A discretizing scale by sample quantiles: each range element stands for an equal share
of the samples (spec/06 §11).

    scale = Macaw.Draw.Scale.Quantile.new() |> Macaw.Draw.Scale.Quantile.domain!([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100])
    scale = Macaw.Draw.Scale.Quantile.range(scale, ["Q1", "Q2", "Q3", "Q4"])
    Macaw.Draw.Scale.Quantile.quantiles(scale)
    #=> [3.5, 6.0, 8.5]

The thresholds are derived, never set: the `i/n` quantiles of the sorted samples by
linear interpolation, for `n` the range's length. `apply/2` answers the range element at
the count of thresholds at or below the value, `nil` for a value that is no number.

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Scale.Quantile{
  domain: [number()],
  range: [term()],
  thresholds: [number()]
}
```

# `apply`

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

The range element of the value's bucket: the count of thresholds at or below it.
`nil` for an empty range or a value that is no number; the first element when there
are no thresholds.

# `bandwidth`

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

`0`: a quantile scale has no bandwidth.

# `clamp`

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

Identity: a quantile scale always maps into its range.

# `domain`

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

Sets the samples, numbers, sorted on entry: `{:ok, scale}`, or `{:error, faults}` with
`{[i], {:type, :number}}` for an element that is not one.

# `domain!`

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

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

# `invert`

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

`nil`: a quantile scale maps many values to one bucket.

# `invert_extent`

```elixir
@spec invert_extent(t(), term()) :: {number(), number()} | nil | error()
```

The samples' extent of the bucket a range element stands for, `{lo, hi}`: the first
sample or the threshold below, the last sample or the threshold above. `nil` for an
empty domain or range, or an element not in the range.

# `new`

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

A quantile scale with no samples and no range.

# `nice`

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

Identity.

# `padding`

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

Identity: a quantile scale has no padding.

# `quantiles`

```elixir
@spec quantiles(t()) :: [number()] | error()
```

The `n − 1` interior quantiles, the thresholds.

# `range`

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

Sets the range, a list; answers the struct.

# `ticks`

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

`quantiles/1`; the count is ignored.

---

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