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

Copy Markdown View Source

A continuous power scale: d3's signed power, sqrt its exponent 0.5 (spec/06 §6).

The transform is T(x) = sign(x) · |x|^e, applied to the domain's bounds and the value alike, so a domain that includes negatives maps symmetrically and invert/2 answers negative domain values. ticks/2 and nice/1 are Macaw.Draw.Scale.Linear's over the domain: linear in the domain, not in the transformed space. When it clamps, the scale clamps its output to the range's bounds.

scale = Macaw.Draw.Scale.Power.sqrt() |> Macaw.Draw.Scale.Power.domain!([0, 100])
Macaw.Draw.Scale.Power.apply(Macaw.Draw.Scale.Power.range!(scale, [0, 10]), 25)
#=> 5.0

Summary

Types

A refusal: faults with their paths.

t()

Functions

The range value of value by the signed power, 0.5 of the range in a collapsed transformed domain, clamped to the range's bounds when the scale clamps; nil for a value that is not a number.

0: a power scale has no bandwidth.

Sets clamping of the output to the range; answers the struct.

Sets the domain, a two-element list or tuple of numbers, stored as a list.

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

Sets the exponent, a number; answers the struct.

The domain value of a range value, T⁻¹(T(d0) + t · (T(d1) − T(d0))); never clamps.

A power scale of exponent 1.

Identity: a power scale has no padding.

Sets the range, a two-element list or tuple of numbers, stored as a list.

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

A square-root scale: exponent 0.5, kind :sqrt.

Types

error()

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

A refusal: faults with their paths.

t()

@type t() :: %Macaw.Draw.Scale.Power{
  clamp?: boolean(),
  domain: [number()],
  exponent: number(),
  range: [number()]
}

Functions

apply(s, v)

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

The range value of value by the signed power, 0.5 of the range in a collapsed transformed domain, clamped to the range's bounds when the scale clamps; nil for a value that is not a number.

bandwidth(arg1)

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

0: a power scale has no bandwidth.

clamp(scale, clamp?)

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

Sets clamping of the output to the range; answers the struct.

domain(scale, domain)

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

Sets the domain, a two-element list or tuple of numbers, stored as a list.

domain!(scale, domain)

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

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

exponent(scale, e)

@spec exponent(t(), number()) :: t() | error()

Sets the exponent, a number; answers the struct.

invert(s, value)

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

The domain value of a range value, T⁻¹(T(d0) + t · (T(d1) − T(d0))); never clamps.

new()

@spec new() :: t()

A power scale of exponent 1.

nice(scale)

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

Macaw.Draw.Scale.Linear.nice/1's domain.

padding(scale, padding)

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

Identity: a power scale has no padding.

range(scale, range)

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

Sets the range, a two-element list or tuple of numbers, stored as a list.

range!(scale, range)

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

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

sqrt()

@spec sqrt() :: t()

A square-root scale: exponent 0.5, kind :sqrt.

ticks(scale, count)

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

Macaw.Draw.Scale.Linear.ticks/2 over the domain.