Power scale for non-linear transformations.
Maps a continuous input domain to a continuous output range using a power function. The exponent determines the curve shape:
- exponent = 1: linear
- exponent = 0.5: square root (sqrt)
- exponent = 2: quadratic
- exponent = 3: cubic
The transform is D3's signed power T(x) = sign(x) · |x|^e, applied to the domain
bounds and the value alike, so domains that include negative values map symmetrically
and invert/2 returns negative domain values.
Examples
# Square root scale (good for area-based sizing)
scale = Visualize.Scale.Power.new()
|> Visualize.Scale.Power.exponent(0.5)
|> Visualize.Scale.Power.domain([0, 100])
|> Visualize.Scale.Power.range([0, 10])
Visualize.Scale.Power.apply(scale, 25) # => 5.0
Visualize.Scale.Power.apply(scale, 100) # => 10.0
# Quadratic scale
scale = Visualize.Scale.Power.new()
|> Visualize.Scale.Power.exponent(2)
|> Visualize.Scale.Power.domain([0, 10])
|> Visualize.Scale.Power.range([0, 100])
Visualize.Scale.Power.apply(scale, 5) # => 25.0
Summary
Functions
Maps a value from the domain to the range using the signed power transform
Returns 0: a power scale has no bandwidth
Enables or disables clamping of the output to the range
Sets the domain from a two-element list; a two-tuple is accepted and stored as a list
Sets the exponent for the power function
Maps a value from the range back to the domain (inverse)
Creates a new power scale with exponent 1 (linear)
Extends the domain to nice round values, as Linear.nice/1 does
Identity: a power scale has no padding
Sets the range from a two-element list; a two-tuple is accepted and stored as a list
Alias of apply/2, kept for one release (spec/03 §1.3)
Creates a square root scale (exponent 0.5)
Generates nice tick values, linearly spaced over the domain
Types
Functions
Maps a value from the domain to the range using the signed power transform
@spec bandwidth(t()) :: 0
Returns 0: a power scale has no bandwidth
Enables or disables clamping of the output to the range
Sets the domain from a two-element list; a two-tuple is accepted and stored as a list
Sets the exponent for the power function
Maps a value from the range back to the domain (inverse)
@spec new() :: t()
Creates a new power scale with exponent 1 (linear)
Extends the domain to nice round values, as Linear.nice/1 does
Identity: a power scale has no padding
Sets the range from a two-element list; a two-tuple is accepted and stored as a list
Alias of apply/2, kept for one release (spec/03 §1.3)
@spec sqrt() :: t()
Creates a square root scale (exponent 0.5)
Generates nice tick values, linearly spaced over the domain