Visualize.Scale.Band (Visualize v0.8.0)

Copy Markdown View Source

A discrete scale that divides the range into uniform bands.

Essential for bar charts where each category gets an equal-width band. The band maths is d3-scale's: a descending range lays the bands out in reverse with positive step and bandwidth, and round/2 floors the step and rounds the start and bandwidth so every position is an integer.

Every setter lays the bands out again, as d3-scale's rescale does, and keeps the layout and each category's slot in the struct, so apply/2, bandwidth/1 and step/1 cost the same over a domain of a thousand categories as over ten (spec/03 §9.3).

Summary

Functions

Sets alignment (0 to 1) for distributing outer space

Returns the start position for a category, or nil when it is not in the domain

Returns the width of each band

Identity: a band scale never extrapolates

Sets the domain (list of categories)

Returns nil: a band scale is not invertible

Creates a new band scale

Identity

Sets both inner and outer padding (0 to 1)

Sets inner padding between bands

Sets outer padding at range edges

Sets the range

Enables rounding: the step is floored, the start and bandwidth rounded

Returns the step (band + padding); floored when round?

Returns the domain as ticks

Types

t()

@type t() :: %Visualize.Scale.Band{
  align: number(),
  domain: [any()],
  layout: {number(), number(), number(), boolean()},
  padding_inner: number(),
  padding_outer: number(),
  range: [number()],
  round?: boolean(),
  slots: %{optional(any()) => non_neg_integer()}
}

Functions

align(scale, a)

@spec align(t(), number()) :: t()

Sets alignment (0 to 1) for distributing outer space

apply(band, value)

@spec apply(t(), any()) :: number() | nil

Returns the start position for a category, or nil when it is not in the domain

bandwidth(band)

@spec bandwidth(t()) :: number()

Returns the width of each band

clamp(scale, clamp?)

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

Identity: a band scale never extrapolates

domain(scale, categories)

@spec domain(t(), [any()]) :: t()

Sets the domain (list of categories)

invert(band, value)

@spec invert(t(), number()) :: nil

Returns nil: a band scale is not invertible

new()

@spec new() :: t()

Creates a new band scale

nice(scale)

@spec nice(t()) :: t()

Identity

padding(scale, p)

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

Sets both inner and outer padding (0 to 1)

padding_inner(scale, p)

@spec padding_inner(t(), number()) :: t()

Sets inner padding between bands

padding_outer(scale, p)

@spec padding_outer(t(), number()) :: t()

Sets outer padding at range edges

range(scale, list)

@spec range(t(), [number()]) :: t()

Sets the range

round(scale, round?)

@spec round(t(), boolean()) :: t()

Enables rounding: the step is floored, the start and bandwidth rounded

step(band)

@spec step(t()) :: number()

Returns the step (band + padding); floored when round?

ticks(band, count)

@spec ticks(t(), integer()) :: [any()]

Returns the domain as ticks