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

Copy Markdown View Source

A discrete scale, a category to a range element (spec/06 §9).

apply/2 finds the first domain element equal (==) to the value, else the first of the same spelling (Macaw.Base.Names.same?/2: :ok and "ok" are one category), and answers the range element at its index, the range cycling when the domain is longer. A value the domain lacks answers unknown, nil by default; the domain is never extended implicitly.

The lookup is a map built once by domain/2: each category's first index keyed by the category (an integral float keyed as its integer, as == equates them), and a second keyed by its spelling, so apply/2 costs two map reads at most whatever the domain's length. inspect/1 leaves the derived maps out.

Summary

Types

A refusal: faults with their paths.

t()

Functions

The range element of a category, the range cycling; unknown for a category the domain lacks or an empty range.

0: an ordinal scale has no bandwidth.

Identity: an ordinal scale never extrapolates.

Sets the domain, a list of any terms; answers the struct.

nil: an ordinal scale is not invertible.

An ordinal scale with no domain and no range.

Identity.

Identity: an ordinal scale has no padding.

Sets the range, a list; answers the struct.

The domain; the count is ignored.

Sets the value for a category the domain lacks (default nil); answers the struct.

Types

error()

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

A refusal: faults with their paths.

t()

@type t() :: %Macaw.Draw.Scale.Ordinal{
  domain: [term()],
  index: %{optional(term()) => non_neg_integer()},
  range: [term()],
  spelled: %{optional(term()) => non_neg_integer()},
  unknown: term(),
  values: tuple()
}

Functions

apply(arg1, value)

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

The range element of a category, the range cycling; unknown for a category the domain lacks or an empty range.

bandwidth(arg1)

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

0: an ordinal scale has no bandwidth.

clamp(scale, clamp?)

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

Identity: an ordinal scale never extrapolates.

domain(scale, categories)

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

Sets the domain, a list of any terms; answers the struct.

invert(arg1, value)

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

nil: an ordinal scale is not invertible.

new()

@spec new() :: t()

An ordinal scale with no domain and no range.

nice(scale)

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

Identity.

padding(scale, padding)

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

Identity: an ordinal scale has no padding.

range(scale, values)

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

Sets the range, a list; answers the struct.

ticks(scale, count)

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

The domain; the count is ignored.

unknown(scale, value)

@spec unknown(t(), term()) :: t() | error()

Sets the value for a category the domain lacks (default nil); answers the struct.