Visualize.Scale.Band (Visualize v0.2.35)

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.

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()],
  padding_inner: number(),
  padding_outer: number(),
  range: [number()],
  round?: boolean()
}

Functions

align(scale, a)

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

Sets alignment (0 to 1) for distributing outer space

apply(scale, value)

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

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

bandwidth(scale)

@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(scale)

@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