Macaw.Draw.Scale.Band (macaw_draw v0.1.0)

Copy Markdown View Source

A discrete scale dividing a numeric range into uniform bands, one per category (spec/06 §10): what a bar chart places its bars by.

The band math is d3-scale's rescale: a descending range lays the bands out in reverse with a positive step and bandwidth, and round/2 floors the step and rounds the start and bandwidth so every position is a whole number. Every setter lays the bands out again 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 thousand categories as over ten. inspect/1 leaves the derived slots and layout out; a struct built by hand rather than by the setters has no slots and places nothing.

Summary

Types

A refusal: faults with their paths.

t()

Functions

Sets how the outer space is shared, 0 ≤ a ≤ 1, 0.5 centering the bands: {:ok, scale} or {:error, [{[], {:range, :align, a}}]}.

align/2, answering the scale or raising Macaw.Draw.Error.

The start of a category's band, or nil for a value not in the domain.

The width of each band.

Identity: a band scale never extrapolates.

Sets the categories, any list; answers the struct.

nil: a band scale is not invertible.

A band scale with no categories over [0, 1].

Identity.

Sets the inner and outer padding together, 0 ≤ p < 1: {:ok, scale}, or {:error, [{[], {:range, :padding, p}}]}.

padding/2, answering the scale or raising Macaw.Draw.Error.

Sets the padding between bands, 0 ≤ p < 1: {:ok, scale} or {:error, faults}.

padding_inner/2, answering the scale or raising Macaw.Draw.Error.

Sets the padding at the range's ends, p ≥ 0: {:ok, scale} or {:error, faults}.

padding_outer/2, answering the scale or raising Macaw.Draw.Error.

Sets the range, two numbers: {:ok, scale} or {:error, faults}.

range/2, answering the scale or raising Macaw.Draw.Error.

Sets rounding: the step floored, the start and bandwidth rounded; answers the struct.

The distance between adjacent band starts; floored when the scale rounds.

The domain; the count is ignored.

Types

error()

@type error() :: {:error, [Macaw.Base.Fault.t()]}

A refusal: faults with their paths.

t()

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

Functions

align(scale, a)

@spec align(t(), term()) :: {:ok, t()} | error()

Sets how the outer space is shared, 0 ≤ a ≤ 1, 0.5 centering the bands: {:ok, scale} or {:error, [{[], {:range, :align, a}}]}.

align!(scale, a)

@spec align!(t(), term()) :: t()

align/2, answering the scale or raising Macaw.Draw.Error.

apply(arg1, value)

@spec apply(t(), term()) :: number() | nil | error()

The start of a category's band, or nil for a value not in the domain.

bandwidth(arg1)

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

The width of each band.

clamp(scale, clamp?)

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

Identity: a band scale never extrapolates.

domain(scale, categories)

@spec domain(t(), [term()]) :: t() | error()

Sets the categories, any list; answers the struct.

invert(arg1, value)

@spec invert(t(), term()) :: nil | error()

nil: a band scale is not invertible.

new()

@spec new() :: t()

A band scale with no categories over [0, 1].

nice(scale)

@spec nice(t()) :: t() | error()

Identity.

padding(scale, p)

@spec padding(t(), term()) :: {:ok, t()} | error()

Sets the inner and outer padding together, 0 ≤ p < 1: {:ok, scale}, or {:error, [{[], {:range, :padding, p}}]}.

padding!(scale, p)

@spec padding!(t(), term()) :: t()

padding/2, answering the scale or raising Macaw.Draw.Error.

padding_inner(scale, p)

@spec padding_inner(t(), term()) :: {:ok, t()} | error()

Sets the padding between bands, 0 ≤ p < 1: {:ok, scale} or {:error, faults}.

padding_inner!(scale, p)

@spec padding_inner!(t(), term()) :: t()

padding_inner/2, answering the scale or raising Macaw.Draw.Error.

padding_outer(scale, p)

@spec padding_outer(t(), term()) :: {:ok, t()} | error()

Sets the padding at the range's ends, p ≥ 0: {:ok, scale} or {:error, faults}.

padding_outer!(scale, p)

@spec padding_outer!(t(), term()) :: t()

padding_outer/2, answering the scale or raising Macaw.Draw.Error.

range(scale, range)

@spec range(t(), term()) :: {:ok, t()} | error()

Sets the range, two numbers: {:ok, scale} or {:error, faults}.

range!(scale, range)

@spec range!(t(), term()) :: t()

range/2, answering the scale or raising Macaw.Draw.Error.

round(scale, round?)

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

Sets rounding: the step floored, the start and bandwidth rounded; answers the struct.

step(arg1)

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

The distance between adjacent band starts; floored when the scale rounds.

ticks(scale, count)

@spec ticks(t(), number()) :: [term()] | error()

The domain; the count is ignored.