Quantize scale for mapping continuous values to discrete buckets.
Divides the continuous domain into uniform segments, each mapped to a discrete value from the range. Useful for choropleth maps and heat maps where you want to bin continuous data into categories.
Examples
# Map values 0-100 to colors
scale = Visualize.Scale.Quantize.new()
|> Visualize.Scale.Quantize.domain([0, 100])
|> Visualize.Scale.Quantize.range(["#f7fbff", "#c6dbef", "#6baed6", "#2171b5", "#084594"])
Visualize.Scale.Quantize.apply(scale, 10) # => "#f7fbff"
Visualize.Scale.Quantize.apply(scale, 50) # => "#6baed6"
Visualize.Scale.Quantize.apply(scale, 90) # => "#084594"
# Get the thresholds
Visualize.Scale.Quantize.thresholds(scale) # => [20, 40, 60, 80]
Summary
Functions
Maps a continuous value to a discrete range value
Returns 0: a quantize scale has no bandwidth
Returns the number of buckets
Identity: a quantize scale always clamps
Sets the domain from a two-element list; a two-tuple is accepted and stored as a list
Returns nil: a quantize scale maps many values to one bucket
Returns the extent of values in the domain that map to a given range value.
Creates a new quantize scale
Identity
Identity: a quantize scale has no padding
Sets the discrete output range
Alias of apply/2, kept for one release (spec/03 §1.3)
Returns the threshold values that separate the buckets
Returns the bucket thresholds (thresholds/1); the count is ignored
Types
Functions
Maps a continuous value to a discrete range value
@spec bandwidth(t()) :: 0
Returns 0: a quantize scale has no bandwidth
@spec bucket_count(t()) :: non_neg_integer()
Returns the number of buckets
Identity: a quantize scale always clamps
Sets the domain from a two-element list; a two-tuple is accepted and stored as a list
Returns nil: a quantize scale maps many values to one bucket
Returns the extent of values in the domain that map to a given range value.
Returns {min, max} for the continuous values that map to the specified discrete value.
@spec new() :: t()
Creates a new quantize scale
Identity
Identity: a quantize scale has no padding
Sets the discrete output range
Alias of apply/2, kept for one release (spec/03 §1.3)
Returns the threshold values that separate the buckets
Returns the bucket thresholds (thresholds/1); the count is ignored