Sequential and diverging color scales, and the d3 schemes (spec/06 §14).
A scale maps a number to a literal %Macaw.Layers.Color{}, never a string (macaw_layers
spec/04 §1.1): its interpolator is a scheme's stops, a list of literal colors, or a
1-arity function of t ∈ [0, 1] answering one. A sequential scale's domain is
[d0, d1]; a diverging one's [d0, d1, d2], d1 the pivot at t = 0.5. Clamping is
on by default.
{:ok, scale} = Macaw.Draw.Scale.Color.sequential("blues")
scale |> Macaw.Draw.Scale.Color.apply(1) |> Macaw.Layers.Color.to_hex()
#=> "#084594"Stops interpolate per channel to an 8-bit color, opacity included, the answer equal to
visualize's for the same stops and t. A categorical scheme is a stop list like any
other: to pick its colors discretely, give scheme/1 as an Ordinal scale's range.
Summary
Types
A refusal: faults with their paths.
An interpolator as a scale holds it: literal stops, or a function of t.
Functions
The literal color of a number (spec/06 §14.3): sequential t = normalize(v, d0, d1), the
interpolator's middle in a collapsed domain; diverging by the half the value lies in,
a value beyond a collapsed half at that half's end; t clamped when the scale clamps.
nil for a value that is no number, and for a function interpolator's answer that is
no literal color.
0: a color scale has no bandwidth.
Sets clamping of t to [0, 1] (on by default); answers the struct.
A diverging scale over [0, 0.5, 1] from an interpolator, as sequential/1 takes.
diverging/1, answering the scale or raising Macaw.Draw.Error.
Sets the domain, two numbers for a sequential scale and three for a diverging one:
{:ok, scale}, or {:error, faults}, another length {[], {:type, :domain, type}}.
domain/2, answering the scale or raising Macaw.Draw.Error.
nil: a color scale is not invertible.
Identity.
Identity: a color scale has no padding.
Replaces the interpolator, as sequential/1 takes one: {:ok, scale} or {:error, faults}.
range/2, answering the scale or raising Macaw.Draw.Error.
A scheme's stops as literal colors, by its name, an atom or its string; nil for a
name no scheme has.
The 25 scheme names, in the order of spec/06 §14.4.
A sequential scale over [0, 1] from an interpolator: a scheme's name (atom or
string), a list of literal colors, or a 1-arity function. {:ok, scale} or
{:error, faults} (spec/06 §14.2).
sequential/1, answering the scale or raising Macaw.Draw.Error.
Macaw.Draw.Scale.Linear.ticks/2 over the domain's extent, [d0, d1] or [d0, d2].
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
@type interpolator() :: [Macaw.Layers.Color.t()] | (number() -> Macaw.Layers.Color.t())
An interpolator as a scale holds it: literal stops, or a function of t.
@type t() :: %Macaw.Draw.Scale.Color{ clamp?: boolean(), domain: [number()], interpolator: interpolator(), type: :sequential | :diverging }
Functions
@spec apply(t(), term()) :: Macaw.Layers.Color.t() | nil | error()
The literal color of a number (spec/06 §14.3): sequential t = normalize(v, d0, d1), the
interpolator's middle in a collapsed domain; diverging by the half the value lies in,
a value beyond a collapsed half at that half's end; t clamped when the scale clamps.
nil for a value that is no number, and for a function interpolator's answer that is
no literal color.
0: a color scale has no bandwidth.
Sets clamping of t to [0, 1] (on by default); answers the struct.
A diverging scale over [0, 0.5, 1] from an interpolator, as sequential/1 takes.
diverging/1, answering the scale or raising Macaw.Draw.Error.
Sets the domain, two numbers for a sequential scale and three for a diverging one:
{:ok, scale}, or {:error, faults}, another length {[], {:type, :domain, type}}.
domain/2, answering the scale or raising Macaw.Draw.Error.
nil: a color scale is not invertible.
Identity.
Identity: a color scale has no padding.
Replaces the interpolator, as sequential/1 takes one: {:ok, scale} or {:error, faults}.
range/2, answering the scale or raising Macaw.Draw.Error.
@spec scheme(term()) :: [Macaw.Layers.Color.t()] | nil
A scheme's stops as literal colors, by its name, an atom or its string; nil for a
name no scheme has.
@spec schemes() :: [atom()]
The 25 scheme names, in the order of spec/06 §14.4.
A sequential scale over [0, 1] from an interpolator: a scheme's name (atom or
string), a list of literal colors, or a 1-arity function. {:ok, scale} or
{:error, faults} (spec/06 §14.2).
sequential/1, answering the scale or raising Macaw.Draw.Error.
Macaw.Draw.Scale.Linear.ticks/2 over the domain's extent, [d0, d1] or [d0, d2].