Visualize.Shape.PercentileBand (Visualize v0.2.25)

Copy Markdown View Source

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)

Summary

Types

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

The lower and upper percentile of a band.

t()

Functions

Sets the curve type and options, applied to every path

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

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

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

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

Sets the median accessor; nil clears it

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

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

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

Types

accessor()

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

output(path)

@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()

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

The lower and upper percentile of a band.

t()

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

Functions

curve(band, curve_type, opts \\ [])

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

Sets the curve type and options, applied to every path

defined(band, predicate)

@spec defined(t(), (any() -> boolean())) :: t()

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

generate(band, data)

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

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

generate_path(band, data)

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

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

inner(band, arg2)

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

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

median(band, accessor)

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

Sets the median accessor; nil clears it

new()

@spec new() :: t()

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

outer(band, arg2)

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

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

x(band, accessor)

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

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