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

Copy Markdown View Source

A continuous linear scale, a numeric domain to a numeric range (spec/06 §4).

{:ok, scale} = Macaw.Draw.Scale.Linear.new() |> Macaw.Draw.Scale.Linear.domain([0, 100])
{:ok, scale} = Macaw.Draw.Scale.Linear.range(scale, [0, 500])
Macaw.Draw.Scale.Linear.apply(scale, 50)
#=> 250.0

apply/2 is total: a value that is not a number answers nil. ticks/2 and nice/1 are the one tick rule's, Macaw.Draw.Ticks (spec/06 §16).

Summary

Types

A refusal: faults with their paths.

t()

Functions

The range value of value: r0 + t · (r1 − r0), t the value's position in the domain, 0.5 in a collapsed one, clamped to [0, 1] when the scale clamps. Always a float; a value that is not a number answers nil.

0: a linear scale has no bandwidth.

Sets clamping; answers the struct.

Sets the domain, two numbers: {:ok, scale} or {:error, faults} (spec/06 §2.2).

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

The domain value of a range value, d0 + t · (d1 − d0); never clamps, nil for a non-number.

The default scale: domain [0, 1], range [0, 1], no clamping.

The domain widened to nice values at count 10, keeping its orientation (spec/06 §16).

Identity: a linear scale has no padding.

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

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

About count nice ticks over the domain: Macaw.Draw.Ticks.ticks/3 (spec/06 §16).

Types

error()

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

A refusal: faults with their paths.

t()

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

Functions

apply(arg1, v)

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

The range value of value: r0 + t · (r1 − r0), t the value's position in the domain, 0.5 in a collapsed one, clamped to [0, 1] when the scale clamps. Always a float; a value that is not a number answers nil.

bandwidth(arg1)

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

0: a linear scale has no bandwidth.

clamp(scale, clamp?)

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

Sets clamping; answers the struct.

domain(scale, domain)

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

Sets the domain, two numbers: {:ok, scale} or {:error, faults} (spec/06 §2.2).

domain!(scale, domain)

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

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

invert(arg1, value)

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

The domain value of a range value, d0 + t · (d1 − d0); never clamps, nil for a non-number.

new()

@spec new() :: t()

The default scale: domain [0, 1], range [0, 1], no clamping.

nice(scale)

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

The domain widened to nice values at count 10, keeping its orientation (spec/06 §16).

padding(scale, padding)

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

Identity: a linear scale has no padding.

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.

ticks(scale, count)

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

About count nice ticks over the domain: Macaw.Draw.Ticks.ticks/3 (spec/06 §16).