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
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.
copy_with_domain/3, answering the scale or raising Macaw.Draw.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/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
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
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.
copy_with_domain/3, answering the scale or raising Macaw.Draw.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/2, answering the scale or raising Macaw.Draw.Error.
nil: a threshold scale maps many values to one bucket.
@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.
@spec new() :: t()
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.