# `Macaw.Draw.Quantity`
[🔗](https://github.com/dcoai/macaw_draw/blob/v0.1.0/lib/macaw/draw/quantity.ex#L1)

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}}`.

# `error`

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

A refusal: faults with their paths.

# `measure`

```elixir
@type measure() :: %{
  optional(:unit) =&gt; String.t() | nil,
  optional(:quantity) =&gt; atom() | nil
}
```

A measure: a unit code and a quantity, either or both absent.

# `display_unit`

```elixir
@spec display_unit([term()], measure()) :: {:ok, String.t() | nil} | error()
```

`display_unit(domain, measure, [])`.

# `display_unit`

```elixir
@spec display_unit([term()], measure(), keyword()) ::
  {:ok, String.t() | nil} | error()
```

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!`

```elixir
@spec display_unit!([term()], measure(), keyword()) :: String.t() | nil
```

`display_unit/3`, answering the unit or raising `Macaw.Draw.Error`.

# `formatter`

```elixir
@spec formatter(struct(), measure()) :: {:ok, Macaw.Draw.Format.t() | nil} | error()
```

`formatter(scale, measure, [])`.

# `formatter`

```elixir
@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`.

# `formatter!`

```elixir
@spec formatter!(struct(), measure(), keyword()) :: Macaw.Draw.Format.t() | nil
```

`formatter/3`, answering the format or raising `Macaw.Draw.Error`.

# `suffix`

```elixir
@spec suffix(String.t() | nil) :: String.t() | {:error, term()}
```

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!`

```elixir
@spec suffix!(String.t() | nil) :: String.t()
```

`suffix/1`, answering the suffix or raising `Macaw.Draw.Error`.

# `ticks`

```elixir
@spec ticks(struct(), measure()) :: {:ok, [number()] | nil} | error()
```

`ticks(scale, measure, [])`.

# `ticks`

```elixir
@spec ticks(struct(), measure(), keyword()) :: {:ok, [number()] | nil} | error()
```

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!`

```elixir
@spec ticks!(struct(), measure(), keyword()) :: [number()] | nil
```

`ticks/3`, answering the ticks or raising `Macaw.Draw.Error`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
