Macaw.Draw.Scale.Quantile (macaw_draw v0.1.0)

Copy Markdown View Source

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.

Summary

Types

A refusal: faults with their paths.

t()

Functions

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.

0: a quantile scale has no bandwidth.

Identity: a quantile scale always maps into its range.

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

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

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

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.

A quantile scale with no samples and no range.

Identity.

Identity: a quantile scale has no padding.

The n โˆ’ 1 interior quantiles, the thresholds.

Sets the range, a list; answers the struct.

quantiles/1; the count is ignored.

Types

error()

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

A refusal: faults with their paths.

t()

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

Functions

apply(arg1, value)

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

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

0: a quantile scale has no bandwidth.

clamp(scale, clamp?)

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

Identity: a quantile scale always maps into its range.

domain(scale, samples)

@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!(scale, samples)

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

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

invert(arg1, value)

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

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

invert_extent(arg1, value)

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

@spec new() :: t()

A quantile scale with no samples and no range.

nice(scale)

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

Identity.

padding(scale, padding)

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

Identity: a quantile scale has no padding.

quantiles(arg1)

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

The n โˆ’ 1 interior quantiles, the thresholds.

range(scale, values)

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

Sets the range, a list; answers the struct.

ticks(scale, count)

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

quantiles/1; the count is ignored.