Bland.Scale (Elixir Technical Drawing v0.5.0)

Copy Markdown View Source

Coordinate scaling between data space and canvas space.

A Scale maps a closed interval in the data domain onto a pixel range on the output canvas. linear/2 and log/2 are the two supported scale families.

The plotting pipeline holds one scale per axis on each Bland.Figure, and series use project/2 to translate data tuples into pixel coordinates.

iex> s = Bland.Scale.linear({0.0, 10.0}, {40.0, 440.0})
iex> Bland.Scale.project(s, 5.0)
240.0

Summary

Functions

Derives a reasonable data-space domain from a list of numbers by padding padding * span on each end. Zero-span inputs get ±1 padding so the resulting scale never collapses to a point.

Inverse of project/2. Converts a canvas-space coordinate back to data-space.

Builds a linear scale mapping domain to range.

Builds a log-base scale. base defaults to 10. Both domain endpoints must be > 0.

Projects a data-space value into canvas-space.

Types

domain()

@type domain() :: {number(), number()}

range()

@type range() :: {number(), number()}

t()

@type t() :: %Bland.Scale{
  base: number(),
  domain: domain(),
  range: range(),
  type: :linear | :log
}

Functions

auto_domain(values, padding \\ 0.05)

@spec auto_domain([number()], float()) :: domain()

Derives a reasonable data-space domain from a list of numbers by padding padding * span on each end. Zero-span inputs get ±1 padding so the resulting scale never collapses to a point.

invert(scale, px)

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

Inverse of project/2. Converts a canvas-space coordinate back to data-space.

linear(arg1, arg2)

@spec linear(domain(), range()) :: t()

Builds a linear scale mapping domain to range.

log(arg1, arg2, base \\ 10)

@spec log(domain(), range(), number()) :: t()

Builds a log-base scale. base defaults to 10. Both domain endpoints must be > 0.

project(scale, v)

@spec project(t(), number()) :: float()

Projects a data-space value into canvas-space.