Macaw.Draw.Shape.PercentileBand (macaw_draw v0.1.0)

Copy Markdown View Source

A median line with an inner and an outer band about it (spec/07 §14), copied from visualize's Visualize.Shape.PercentileBand: the standard reading of a distribution over time, Macaw.Draw.Shape.Area and Macaw.Draw.Shape.Line composed with a fixed output shape (visualize D-28).

x/2 and median/2 are pixel accessors; inner/2 and outer/2 each take a {lo, hi} pair of pixel accessors, nil clearing the band. The quantiles come in as accessors over the data: none is computed here. curve/2,3 and defined/2 apply to all three paths.

iex> alias Macaw.Draw.Shape.PercentileBand
iex> PercentileBand.generate(PercentileBand.new(), [{0, 1}])
%{outer: nil, inner: nil, median: nil}

generate_path/2 answers %{outer:, inner:, median:}: each band the area of its pair (y0 = lo, y1 = hi) and the median the line, under one curve and predicate, or nil when unset. generate/2 writes each as path data. They are drawn outer, inner, median.

Summary

Types

A refusal: faults with their paths.

One entry per path, nil where the band or the median is unset.

t()

Functions

curve(band, type, []).

Sets the curve of every path: {:ok, band} or {:error, faults} (§5.1).

As curve/3, the band itself, raising Macaw.Draw.Error with its faults.

Sets the defined predicate of every path (§1.2); nil clears it.

%{outer:, inner:, median:} of SVG path data, nil where unset.

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

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

Sets the median accessor; nil clears it.

A percentile band with x from tuple element 0, nothing else set.

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

Sets the x accessor: a function, a field, or a number.

Types

accessor()

@type accessor() :: (term() -> term()) | atom() | String.t() | number()

error()

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

A refusal: faults with their paths.

output(path)

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

One entry per path, nil where the band or the median is unset.

t()

@type t() :: %Macaw.Draw.Shape.PercentileBand{
  curve: Macaw.Draw.Shape.Curve.curve_type(),
  curve_opts: keyword(),
  defined: (term() -> term()) | nil,
  inner: {(term() -> term()), (term() -> term())} | nil,
  median: (term() -> term()) | nil,
  outer: {(term() -> term()), (term() -> term())} | nil,
  x: (term() -> term()) | nil
}

Functions

curve(band, type)

@spec curve(t(), term()) :: {:ok, t()} | error()

curve(band, type, []).

curve(band, type, opts)

@spec curve(t(), term(), keyword()) :: {:ok, t()} | error()

Sets the curve of every path: {:ok, band} or {:error, faults} (§5.1).

curve!(band, type, opts \\ [])

@spec curve!(t(), term(), keyword()) :: t()

As curve/3, the band itself, raising Macaw.Draw.Error with its faults.

defined(band, predicate)

@spec defined(t(), (term() -> term()) | nil) :: t() | error()

Sets the defined predicate of every path (§1.2); nil clears it.

generate(band, data)

@spec generate(t(), [term()]) :: output(String.t()) | error()

%{outer:, inner:, median:} of SVG path data, nil where unset.

generate_path(band, data)

@spec generate_path(t(), [term()]) :: output(Macaw.Draw.IR.Path.t()) | error()

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

inner(band, pair)

@spec inner(t(), {accessor(), accessor()} | nil) :: t() | error()

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

median(band, accessor)

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

Sets the median accessor; nil clears it.

new()

@spec new() :: t()

A percentile band with x from tuple element 0, nothing else set.

outer(band, pair)

@spec outer(t(), {accessor(), accessor()} | nil) :: t() | error()

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

x(band, accessor)

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

Sets the x accessor: a function, a field, or a number.