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

Copy Markdown View Source

A discretizing scale by uniform buckets: the domain divided into as many equal segments as the range has elements (spec/06 §12).

scale = Macaw.Draw.Scale.Quantize.new() |> Macaw.Draw.Scale.Quantize.domain!([0, 100])
scale = Macaw.Draw.Scale.Quantize.range(scale, [:low, :mid, :high, :top])
Macaw.Draw.Scale.Quantize.apply(scale, 60)
#=> :high

apply/2 always clamps: a value outside the domain maps to the first or last element.

Summary

Types

A refusal: faults with their paths.

t()

Functions

The range element of the value's bucket, min(⌊t · n⌋, n − 1) for t its clamped position in the domain (0 in a collapsed one); nil for an empty range or a value that is no number.

0: a quantize scale has no bandwidth.

The number of buckets, the range's length.

Identity: a quantize scale always clamps.

Sets the domain, two numbers as a list or a tuple, stored as a list.

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

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

The sub-interval of the domain a range element stands for, {d0 + k·step, d0 + (k+1)·step}; nil for an empty range or an element not in it.

A quantize scale over [0, 1] with no range.

Identity.

Identity: a quantize scale has no padding.

Sets the range, a list; answers the struct.

The n − 1 interior boundaries; [] for fewer than two range elements.

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

Functions

apply(arg1, value)

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

The range element of the value's bucket, min(⌊t · n⌋, n − 1) for t its clamped position in the domain (0 in a collapsed one); nil for an empty range or a value that is no number.

bandwidth(arg1)

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

0: a quantize scale has no bandwidth.

bucket_count(arg1)

@spec bucket_count(t()) :: non_neg_integer() | error()

The number of buckets, the range's length.

clamp(scale, clamp?)

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

Identity: a quantize scale always clamps.

domain(scale, domain)

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

Sets the domain, two numbers as a list or a tuple, stored as a list.

domain!(scale, domain)

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

invert_extent(arg1, value)

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

The sub-interval of the domain a range element stands for, {d0 + k·step, d0 + (k+1)·step}; nil for an empty range or an element not in it.

new()

@spec new() :: t()

A quantize scale over [0, 1] with no range.

nice(scale)

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

Identity.

padding(scale, padding)

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

Identity: a quantize scale has no padding.

range(scale, values)

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

Sets the range, a list; answers the struct.

thresholds(arg1)

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

The n − 1 interior boundaries; [] for fewer than two range elements.

ticks(scale, count)

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

thresholds/1; the count is ignored.