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

Copy Markdown View Source

A discretizing scale by explicit thresholds (spec/06 §13): n thresholds divide the numbers into n + 1 buckets, one per range element.

scale = Macaw.Draw.Scale.Threshold.new() |> Macaw.Draw.Scale.Threshold.domain!([60, 70, 80, 90])
scale = Macaw.Draw.Scale.Threshold.range(scale, ["F", "D", "C", "B", "A"])
Macaw.Draw.Scale.Threshold.apply(scale, 75)
#=> "C"

A value equal to a threshold falls in the upper bucket. A range shorter than the thresholds plus one answers nil for the highest buckets.

Summary

Types

A refusal: faults with their paths.

t()

Functions

The range element at k, the number of thresholds at or below the value, found by binary search; nil for an empty range, a value that is no number, or a bucket past the range's end.

0: a threshold scale has no bandwidth.

Identity: a threshold scale always maps into its range.

The scale with n thresholds taken from data (spec/06 §13.2): the de-duplicated sorted values at indices ⌊i · len / (n + 1)⌋, capped at len − 1, for i in 1 … n; [] for empty data. n at or below zero is read as 1; the range is untouched. {:ok, scale}, or {:error, faults} with {[i], {:type, :number}} for a datum that is no number.

Sets the thresholds, 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 threshold scale maps many values to one bucket.

The bounds of the bucket a range element stands for: {:neg_infinity, t_0} for the first ({:neg_infinity, :infinity} with no thresholds), {t_last, :infinity} for the last, {t_(k−1), t_k} between; nil for an empty range or an element not in it.

A threshold scale with no thresholds and no range.

Identity.

Identity: a threshold scale has no padding.

Sets the range, a list, unchecked; answers the struct.

The thresholds, the domain.

The thresholds; 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.Threshold{domain: [number()], range: [term()]}

Functions

apply(arg1, value)

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

The range element at k, the number of thresholds at or below the value, found by binary search; nil for an empty range, a value that is no number, or a bucket past the range's end.

bandwidth(arg1)

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

0: a threshold scale has no bandwidth.

clamp(scale, clamp?)

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

Identity: a threshold scale always maps into its range.

copy_with_domain(scale, data, n)

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

The scale with n thresholds taken from data (spec/06 §13.2): the de-duplicated sorted values at indices ⌊i · len / (n + 1)⌋, capped at len − 1, for i in 1 … n; [] for empty data. n at or below zero is read as 1; the range is untouched. {:ok, scale}, or {:error, faults} with {[i], {:type, :number}} for a datum that is no number.

copy_with_domain!(scale, data, n)

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

copy_with_domain/3, answering the scale or raising Macaw.Draw.Error.

domain(scale, thresholds)

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

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

domain!(scale, thresholds)

@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 threshold scale maps many values to one bucket.

invert_extent(arg1, value)

@spec invert_extent(t(), term()) ::
  {number() | :neg_infinity, number() | :infinity} | nil | error()

The bounds of the bucket a range element stands for: {:neg_infinity, t_0} for the first ({:neg_infinity, :infinity} with no thresholds), {t_last, :infinity} for the last, {t_(k−1), t_k} between; nil for an empty range or an element not in it.

new()

@spec new() :: t()

A threshold scale with no thresholds and no range.

nice(scale)

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

Identity.

padding(scale, padding)

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

Identity: a threshold scale has no padding.

range(scale, values)

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

Sets the range, a list, unchecked; answers the struct.

thresholds(arg1)

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

The thresholds, the domain.

ticks(scale, count)

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

The thresholds; the count is ignored.