Quantity display: a domain shown in the unit that fits it, its ticks on round numbers of that unit, and the tick format that labels them (spec/06 §19, visualize D-138, D-156).
The vocabulary is macaw_units' and macaw_format's: a measure
%{unit: code | nil, quantity: atom | nil} completed by Macaw.Units.Quantity.resolve/1,
its family under a unit system by Macaw.Format.Quantity.family/3, conversions by
Macaw.Units.Unit.convert/3 and symbols by Macaw.Units.Unit.symbol/2. This module only
draws: which member of the family an axis is drawn in (display_unit/3), the ticks it
places (ticks/3) and the Macaw.Draw.Format that labels them (formatter/3). One
value's label is macaw_format's measure default (Macaw.Format.for_measure/2), and a
title's word Macaw.Format.Quantity.label/1.
{:ok, scale} = Macaw.Draw.Scale.new(:linear, domain: [0, 100])
Macaw.Draw.Quantity.ticks(scale, %{unit: "s"}, count: 5)
#=> {:ok, [0.0, 12.0, 24.0, 36.0, 48.0, 60.0, 72.0, 84.0, 96.0]}A measure resolve/1 refuses is {:error, [{[:measure], reason}]}, and a system none of
Macaw.Format.Quantity.systems/0 is {[:system], {:unknown_system, system}}.
Summary
Types
A refusal: faults with their paths.
A measure: a unit code and a quantity, either or both absent.
Functions
display_unit(domain, measure, []).
The member of the system's family that fits a domain (spec/06 §19.1): the largest in
which the domain's magnitude is at least 1, else the smallest. A unit no family holds
under the system, a measure with no quantity, and a unit with no factor (Cel) keep the
unit; at a zero magnitude a member unit is kept, else the member nearest it by factor is
taken. A measure with no unit is nil. Option :system, :as_posted by default.
display_unit/3, answering the unit or raising Macaw.Draw.Error.
formatter(scale, measure, []).
The tick format of a realized scale in a measure (spec/06 §19.3): every tick in the
display unit by one notation and the unit's suffix on Linear, Power and Radial;
each tick in its own unit by per-value SI on Log and Symlog; money for a currency;
Macaw.Draw.Format.for_scale/2 on any other scale. A placed tick of ticks/3 at the
same scale, measure, count and system is labeled with its round number. Options
:count, :locale and :system.
formatter/3, answering the format or raising Macaw.Draw.Error.
What follows a number written in a unit: its symbol after a space, %, ° and a symbol
beginning with / directly, and "" for nil or an empty symbol; {:error, reason}
of Macaw.Units.Unit.symbol/2 for a code that does not read.
suffix/1, answering the suffix or raising Macaw.Draw.Error.
ticks(scale, measure, []).
The ticks of a realized scale in a measure whose display unit is not its unit (spec/06
§19.2): Scale.ticks/2 at count: (default 10) over the domain converted into the
display unit, each converted back to be placed. {:ok, nil}, the scale's own ticks, when
the display unit is the unit, with no unit or quantity, for a currency, and on any scale
but Linear, Power and Radial.
ticks/3, answering the ticks or raising Macaw.Draw.Error.
Types
@type error() :: {:error, [Macaw.Base.Fault.t()]}
A refusal: faults with their paths.
A measure: a unit code and a quantity, either or both absent.
Functions
display_unit(domain, measure, []).
The member of the system's family that fits a domain (spec/06 §19.1): the largest in
which the domain's magnitude is at least 1, else the smallest. A unit no family holds
under the system, a measure with no quantity, and a unit with no factor (Cel) keep the
unit; at a zero magnitude a member unit is kept, else the member nearest it by factor is
taken. A measure with no unit is nil. Option :system, :as_posted by default.
display_unit/3, answering the unit or raising Macaw.Draw.Error.
@spec formatter(struct(), measure()) :: {:ok, Macaw.Draw.Format.t() | nil} | error()
formatter(scale, measure, []).
@spec formatter(struct(), measure(), keyword()) :: {:ok, Macaw.Draw.Format.t() | nil} | error()
The tick format of a realized scale in a measure (spec/06 §19.3): every tick in the
display unit by one notation and the unit's suffix on Linear, Power and Radial;
each tick in its own unit by per-value SI on Log and Symlog; money for a currency;
Macaw.Draw.Format.for_scale/2 on any other scale. A placed tick of ticks/3 at the
same scale, measure, count and system is labeled with its round number. Options
:count, :locale and :system.
@spec formatter!(struct(), measure(), keyword()) :: Macaw.Draw.Format.t() | nil
formatter/3, answering the format or raising Macaw.Draw.Error.
What follows a number written in a unit: its symbol after a space, %, ° and a symbol
beginning with / directly, and "" for nil or an empty symbol; {:error, reason}
of Macaw.Units.Unit.symbol/2 for a code that does not read.
iex> Macaw.Draw.Quantity.suffix("Cel")
" °C"
iex> Macaw.Draw.Quantity.suffix("{request}/s")
"/s"
suffix/1, answering the suffix or raising Macaw.Draw.Error.
ticks(scale, measure, []).
The ticks of a realized scale in a measure whose display unit is not its unit (spec/06
§19.2): Scale.ticks/2 at count: (default 10) over the domain converted into the
display unit, each converted back to be placed. {:ok, nil}, the scale's own ticks, when
the display unit is the unit, with no unit or quantity, for a currency, and on any scale
but Linear, Power and Radial.
ticks/3, answering the ticks or raising Macaw.Draw.Error.