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

Copy Markdown View Source

A continuous logarithmic scale, for data spanning orders of magnitude (spec/06 §5).

Every logarithm is log(x) / log(base), exact for bases 10 and 2. The domain's bounds must be positive: one at or below zero is the fault {[i], {:not_positive, value}}. A value at or below zero has no position on a log axis and applies to nil, as does a value that is not a number. ticks/2 are d3-scale's log ticks.

Summary

Types

A refusal: faults with their paths.

t()

Functions

The range value of a positive value, by t = (log v − log d0) / (log d1 − log d0), clamped to [0, 1] when the scale clamps; nil for a value at or below zero or not a number.

0: a log scale has no bandwidth.

Sets clamping; answers the struct.

Sets the domain, both bounds positive: {:ok, scale} or {:error, faults}.

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

The domain value of a range value, base ^ (log d0 + t · (log d1 − log d0)); never clamps.

The default scale, base 10.

A log scale of base, a number above 0 and not 1: {:ok, scale}, or {:error, [{[], {:log_base, base}}]}.

new/1, answering the scale or raising Macaw.Draw.Error.

The domain extended to integer powers of the base.

Identity: a log 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 ticks, as d3-scale's log ticks are (spec/06 §5.2).

Types

error()

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

A refusal: faults with their paths.

t()

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

Functions

apply(scale, v)

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

The range value of a positive value, by t = (log v − log d0) / (log d1 − log d0), clamped to [0, 1] when the scale clamps; nil for a value at or below zero or not a number.

bandwidth(arg1)

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

0: a log 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, both bounds positive: {:ok, scale} or {:error, faults}.

domain!(scale, domain)

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

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

invert(scale, value)

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

The domain value of a range value, base ^ (log d0 + t · (log d1 − log d0)); never clamps.

new()

@spec new() :: t()

The default scale, base 10.

new(base)

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

A log scale of base, a number above 0 and not 1: {:ok, scale}, or {:error, [{[], {:log_base, base}}]}.

new!(base)

@spec new!(term()) :: t()

new/1, answering the scale or raising Macaw.Draw.Error.

nice(scale)

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

The domain extended to integer powers of the base.

padding(scale, padding)

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

Identity: a log 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 ticks, as d3-scale's log ticks are (spec/06 §5.2).

Within fewer decades than the count and with an integer base, every k · base^e (1 ≤ k < base) inside the domain, falling back to Macaw.Draw.Ticks.ticks/3 over the domain when those number under half the count; otherwise the exponents thinned by the tick rule at the real count min(j − i, count) and mapped back through the base. A count at or below zero is read as 1.