The scale facade: constructors, the validating builder new/2, and dispatch of the
common operations to the module the scale struct names (spec/06 §2, §3).
Scales map values from a data domain to a visual range. The kinds (spec/06 §2.1):
- continuous:
:linear,:log,:power,:sqrt,:symlog,:time,:radial; - discrete:
:ordinal,:band; - discretizing:
:quantile,:quantize,:threshold; - color:
:sequential,:diverging.
Every operation is total over every scale this module constructs (spec/06 §1.2): a
refusable one answers {:ok, scale} or {:error, faults} and has a ! twin raising
Macaw.Draw.Error; apply/2 answers nil for a value it cannot place; an argument of
the wrong type is {:error, faults}. A kind, and an option's key, is an atom or its
string, read by spelling and never made into an atom (spec/06 §1.3).
{:ok, scale} = Macaw.Draw.Scale.new("linear", domain: [0, 100], range: [0, 500])
Macaw.Draw.Scale.apply(scale, 50)
#=> 250.0
Summary
Functions
The range value of a domain value; total, nil for a value the scale cannot place.
A packed column mapped through the scale in one pass, to a pixel binary (spec/06
§3.3): float64 little-endian, one slot for each of the column's, each slot exactly
apply/2 of that slot's value as a float, and NaN where apply/2 answers no number or
the value is missing. No list is built and no term made a row on a linear or time scale.
A band scale with no categories over [0, 1] (spec/06 §10).
A band's width; 0 on every other scale.
Sets clamping; identity where it does not apply.
A diverging color scale: Macaw.Draw.Scale.Color.diverging/1 (spec/06 §14).
diverging/1, answering the scale or raising Macaw.Draw.Error.
Sets the domain: the module's domain/2, refusable as the module's is.
domain/2, answering the scale or raising Macaw.Draw.Error.
The domain value of a range value: continuous scales only, nil on the rest.
The kind of a scale struct, an atom of kinds/0: :sqrt for a power scale of exponent
0.5.
The kinds, in the order of spec/06 §2.1.
A linear scale: domain [0, 1], range [0, 1] (spec/06 §4).
A log scale of base 10 (spec/06 §5).
A log scale of base: {:ok, scale} or {:error, [{[], {:log_base, base}}]}.
log/1, answering the scale or raising Macaw.Draw.Error.
A scale of kind built from options, every option checked at once (spec/06 §3.2):
{:ok, scale}, or {:error, faults} with every fault at its key, ordered by path.
new/2, answering the scale or raising Macaw.Draw.Error.
The domain extended to round values; identity where that does not apply.
An ordinal scale with no domain and no range (spec/06 §9).
Sets band padding: the module's padding/2, identity on every scale but a band.
padding/2, answering the scale or raising Macaw.Draw.Error.
A power scale of exponent 1 (spec/06 §6).
A quantile scale with no samples (spec/06 §11).
A quantize scale over [0, 1] with no range (spec/06 §12).
A radial scale: domain [0, 1], range [0, 2π] (spec/06 §15).
Sets the range: the module's range/2, refusable as the module's is.
range/2, answering the scale or raising Macaw.Draw.Error.
A sequential color scale: Macaw.Draw.Scale.Color.sequential/1 (spec/06 §14).
sequential/1, answering the scale or raising Macaw.Draw.Error.
A square-root scale, a power scale of exponent 0.5 (spec/06 §6).
A symmetric-log scale (spec/06 §7).
A threshold scale with no thresholds (spec/06 §13).
ticks(scale, 10).
Representative domain values; count is a hint (spec/06 §1.4).
A time scale with no domain (spec/06 §8).
Sets a time scale's display zone: Macaw.Draw.Scale.Time.zone/2 (spec/06 §8.4). Not part
of the protocol: any other scale is {:error, [{[], {:not_time_scale, kind}}]}.
zone/2, answering the scale or raising Macaw.Draw.Error.
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
A kind, kinds/0's, or its string.
@type t() :: struct()
A scale struct of any kind.
Functions
The range value of a domain value; total, nil for a value the scale cannot place.
A packed column mapped through the scale in one pass, to a pixel binary (spec/06
§3.3): float64 little-endian, one slot for each of the column's, each slot exactly
apply/2 of that slot's value as a float, and NaN where apply/2 answers no number or
the value is missing. No list is built and no term made a row on a linear or time scale.
The column is a buffer of macaw_data's encoding table (its spec/01 §1.1.6): {form, data} with every slot present, {form, data, validity} with its bitmap (least
significant bit first, a set bit present), or a piece {{form, data, validity}, offset, count} as Macaw.Data.Table.packed/2 and window/4 answer, its run the slots offset
to offset + count - 1. form is :int64 or :float64; a time scale reads int64
slots as integer microseconds, and places no float. Anything else is {:error, [{[1], {:type, :column}}]}.
iex> scale = Macaw.Draw.Scale.new!(:linear, domain: [0, 10], range: [0, 100])
iex> pixels = Macaw.Draw.Scale.apply_column(scale, {:int64, <<5::signed-little-64, 10::signed-little-64>>})
iex> for <<x::float-little-64 <- pixels>>, do: x
[50.0, 100.0]
@spec band() :: Macaw.Draw.Scale.Band.t()
A band scale with no categories over [0, 1] (spec/06 §10).
A band's width; 0 on every other scale.
Sets clamping; identity where it does not apply.
@spec diverging(term()) :: {:ok, Macaw.Draw.Scale.Color.t()} | error()
A diverging color scale: Macaw.Draw.Scale.Color.diverging/1 (spec/06 §14).
@spec diverging!(term()) :: Macaw.Draw.Scale.Color.t()
diverging/1, answering the scale or raising Macaw.Draw.Error.
Sets the domain: the module's domain/2, refusable as the module's is.
domain/2, answering the scale or raising Macaw.Draw.Error.
The domain value of a range value: continuous scales only, nil on the rest.
The kind of a scale struct, an atom of kinds/0: :sqrt for a power scale of exponent
0.5.
@spec kinds() :: [atom()]
The kinds, in the order of spec/06 §2.1.
@spec linear() :: Macaw.Draw.Scale.Linear.t()
A linear scale: domain [0, 1], range [0, 1] (spec/06 §4).
@spec log() :: Macaw.Draw.Scale.Log.t()
A log scale of base 10 (spec/06 §5).
@spec log(term()) :: {:ok, Macaw.Draw.Scale.Log.t()} | error()
A log scale of base: {:ok, scale} or {:error, [{[], {:log_base, base}}]}.
@spec log!(term()) :: Macaw.Draw.Scale.Log.t()
log/1, answering the scale or raising Macaw.Draw.Error.
A scale of kind built from options, every option checked at once (spec/06 §3.2):
{:ok, scale}, or {:error, faults} with every fault at its key, ordered by path.
kind is an atom of kinds/0 or its string; opts a keyword list or a map whose keys
are atoms or strings. An option the kind does not take is {[key], :unknown_key}; an
unknown kind {[], {:unknown, :kind, spelling}}; options that are no keyword list or
map {[], {:type, :options}}.
new/2, answering the scale or raising Macaw.Draw.Error.
The domain extended to round values; identity where that does not apply.
@spec ordinal() :: Macaw.Draw.Scale.Ordinal.t()
An ordinal scale with no domain and no range (spec/06 §9).
Sets band padding: the module's padding/2, identity on every scale but a band.
padding/2, answering the scale or raising Macaw.Draw.Error.
@spec power() :: Macaw.Draw.Scale.Power.t()
A power scale of exponent 1 (spec/06 §6).
@spec quantile() :: Macaw.Draw.Scale.Quantile.t()
A quantile scale with no samples (spec/06 §11).
@spec quantize() :: Macaw.Draw.Scale.Quantize.t()
A quantize scale over [0, 1] with no range (spec/06 §12).
@spec radial() :: Macaw.Draw.Scale.Radial.t()
A radial scale: domain [0, 1], range [0, 2π] (spec/06 §15).
Sets the range: the module's range/2, refusable as the module's is.
range/2, answering the scale or raising Macaw.Draw.Error.
@spec sequential(term()) :: {:ok, Macaw.Draw.Scale.Color.t()} | error()
A sequential color scale: Macaw.Draw.Scale.Color.sequential/1 (spec/06 §14).
@spec sequential!(term()) :: Macaw.Draw.Scale.Color.t()
sequential/1, answering the scale or raising Macaw.Draw.Error.
@spec sqrt() :: Macaw.Draw.Scale.Power.t()
A square-root scale, a power scale of exponent 0.5 (spec/06 §6).
@spec symlog() :: Macaw.Draw.Scale.Symlog.t()
A symmetric-log scale (spec/06 §7).
@spec threshold() :: Macaw.Draw.Scale.Threshold.t()
A threshold scale with no thresholds (spec/06 §13).
ticks(scale, 10).
Representative domain values; count is a hint (spec/06 §1.4).
@spec time() :: Macaw.Draw.Scale.Time.t()
A time scale with no domain (spec/06 §8).
@spec zone(t(), term()) :: {:ok, Macaw.Draw.Scale.Time.t()} | error()
Sets a time scale's display zone: Macaw.Draw.Scale.Time.zone/2 (spec/06 §8.4). Not part
of the protocol: any other scale is {:error, [{[], {:not_time_scale, kind}}]}.
@spec zone!(t(), term()) :: Macaw.Draw.Scale.Time.t()
zone/2, answering the scale or raising Macaw.Draw.Error.