# `Visualize.Shape.PercentileBand`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/shape/percentile_band.ex#L1)

Percentile-band generator: a median line with an inner and an outer band around it
(spec/04 §14, D-28).

A composition of `Visualize.Shape.Area` and `Visualize.Shape.Line` with a fixed output
shape: `generate/2` returns `%{outer: d, inner: d, median: d}`, each path exactly what the
standalone generator would produce, or `nil` for a band that is not set.

## Examples

    band =
      Visualize.Shape.PercentileBand.new()
      |> Visualize.Shape.PercentileBand.x(fn d -> Visualize.Scale.apply(x_scale, d.t) end)
      |> Visualize.Shape.PercentileBand.median(fn d -> Visualize.Scale.apply(y_scale, d.p50) end)
      |> Visualize.Shape.PercentileBand.inner({&y.(&1.p25), &y.(&1.p75)})
      |> Visualize.Shape.PercentileBand.outer({&y.(&1.p5), &y.(&1.p95)})
      |> Visualize.Shape.PercentileBand.curve(:monotone_x)

    %{outer: outer, inner: inner, median: median} =
      Visualize.Shape.PercentileBand.generate(band, samples)

# `accessor`

```elixir
@type accessor() :: Visualize.Shape.Line.accessor()
```

# `output`

```elixir
@type output(path) :: %{outer: path | nil, inner: path | nil, median: path | nil}
```

The output: one entry per path, `nil` where the band or median is unset.

# `pair`

```elixir
@type pair() :: {accessor(), accessor()}
```

The lower and upper percentile of a band.

# `t`

```elixir
@type t() :: %Visualize.Shape.PercentileBand{
  curve: Visualize.Shape.Curve.curve_type(),
  curve_opts: keyword(),
  defined: (any() -&gt; boolean()) | nil,
  inner: {(any() -&gt; number()), (any() -&gt; number())} | nil,
  median: (any() -&gt; number()) | nil,
  outer: {(any() -&gt; number()), (any() -&gt; number())} | nil,
  x: accessor() | nil
}
```

# `curve`

```elixir
@spec curve(t(), Visualize.Shape.Curve.curve_type(), keyword()) :: t()
```

Sets the curve type and options, applied to every path

# `defined`

```elixir
@spec defined(t(), (any() -&gt; boolean())) :: t()
```

Sets the defined predicate, applied to every path (spec/04 §1.2)

# `generate`

```elixir
@spec generate(t(), Visualize.Data.Table.source()) :: output(String.t())
```

Returns `%{outer:, inner:, median:}` of SVG path-data strings, `nil` where unset

# `generate_path`

```elixir
@spec generate_path(t(), Visualize.Data.Table.source()) ::
  output(Visualize.IR.Path.t())
```

Returns `%{outer:, inner:, median:}` of `IR.Path`, `nil` where unset

# `inner`

```elixir
@spec inner(t(), pair() | nil) :: t()
```

Sets the inner band as a `{lo, hi}` pair of accessors; `nil` clears it

# `median`

```elixir
@spec median(t(), accessor() | nil) :: t()
```

Sets the median accessor; `nil` clears it

# `new`

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

Creates a generator reading tuple element 0 as `x`, with no median and no bands

# `outer`

```elixir
@spec outer(t(), pair() | nil) :: t()
```

Sets the outer band as a `{lo, hi}` pair of accessors; `nil` clears it

# `x`

```elixir
@spec x(t(), accessor()) :: t()
```

Sets the x accessor: 1-arity function, atom field, or numeric constant

---

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