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

A reference axis as scene elements: its domain line, tick marks and labels (spec/06
§17), d3-axis's geometry (visualize `Visualize.Axis`, D-23, D-55, D-56).

    {:ok, scale} = Macaw.Draw.Scale.new(:linear, domain: [0, 100], range: [0, 200])
    {:ok, axis} = Macaw.Draw.Axis.bottom(scale)
    {:ok, svg} = axis |> Macaw.Draw.Axis.ticks(5) |> Macaw.Draw.Axis.render()

An axis takes only a position scale: a continuous one, a `Band`, or an `Ordinal` whose
range is all numbers; any other is `{:not_positional, kind}`. Its colors and font are the
theme's slots `"axis"`, `"text"`, `"font_size"` and `"font_family"`, written as CSS
references (`var(--mw-axis, #666666)`) or, with `resolve: :literal`, as plain values;
nothing is `currentColor`, and the group is `aria-hidden`. An axis built by hand is d3's:
ten ticks and the default label. Every setter answers the struct, and an argument of the
wrong type its fault.

# `error`

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

A refusal: faults with their paths.

# `orient`

```elixir
@type orient() :: :top | :right | :bottom | :left
```

An axis's side.

# `t`

```elixir
@type t() :: %Macaw.Draw.Axis{
  offset: number(),
  orient: orient(),
  scale: struct() | nil,
  theme: Macaw.Layers.Theme.t() | nil,
  tick_format: tick_format(),
  tick_padding: number(),
  tick_size_inner: number(),
  tick_size_outer: number(),
  tick_values: [term()] | nil,
  ticks: number() | nil
}
```

# `tick_format`

```elixir
@type tick_format() ::
  Macaw.Draw.Format.t()
  | Macaw.Format.t()
  | Macaw.Format.Time.t()
  | Macaw.Format.Measure.t()
  | (term() -&gt; String.t())
  | nil
```

How a tick value becomes its label.

# `bottom`

```elixir
@spec bottom(struct()) :: {:ok, t()} | error()
```

An axis below the plot: `new(scale, :bottom)`.

# `bottom!`

```elixir
@spec bottom!(term()) :: t()
```

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

# `default_label`

```elixir
@spec default_label(term()) :: String.t()
```

The default label (spec/06 §17.5): a float rounded to six decimals in plain notation,
trailing zeros and point removed, never an exponent and never `-0`; any other value
`to_string/1`, or inspected where it has none.

    iex> Enum.map([2.0, 0.1 + 0.2, 1000.0, 0.00001, -0.0], &Macaw.Draw.Axis.default_label/1)
    ["2", "0.3", "1000", "0.00001", "0"]

# `generate`

```elixir
@spec generate(t()) :: {:ok, Macaw.Draw.IR.Element.t()} | error()
```

`generate(axis, resolve: :css)`.

# `generate`

```elixir
@spec generate(t(), keyword()) :: {:ok, Macaw.Draw.IR.Element.t()} | error()
```

The axis as a scene group (spec/06 §17.4): `{:ok, group}`, or the faults of resolving its
theme's slots at `[:theme, slot]`. `:resolve` is `:css` (the default) or `:literal`.

# `generate!`

```elixir
@spec generate!(t(), keyword()) :: Macaw.Draw.IR.Element.t()
```

`generate/2`, answering the group or raising `Macaw.Draw.Error`.

# `left`

```elixir
@spec left(struct()) :: {:ok, t()} | error()
```

An axis left of the plot: `new(scale, :left)`.

# `left!`

```elixir
@spec left!(term()) :: t()
```

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

# `new`

```elixir
@spec new(struct(), orient() | String.t()) :: {:ok, t()} | error()
```

An axis of a position scale on a side, the orientation an atom or its string:
`{:ok, axis}`, or `{:error, [{[], {:not_positional, kind}}]}` for a scale that maps to
range elements rather than positions.

# `new!`

```elixir
@spec new!(term(), term()) :: t()
```

`new/2`, answering the axis or raising `Macaw.Draw.Error`.

# `offset`

```elixir
@spec offset(t(), number()) :: t() | error()
```

An offset added to every tick position (crisp half-pixel alignment).

# `render`

```elixir
@spec render(t()) :: {:ok, String.t()} | error()
```

`render(axis, [])`.

# `render`

```elixir
@spec render(t(), keyword()) :: {:ok, String.t()} | error()
```

The axis written by a target (spec/06 §17.6): `generate/2` then
`Macaw.Draw.Render.to_string/2` with the same options, `:resolve` defaulting to the
target's theme mode. `{:ok, string}` or the faults of either.

# `render!`

```elixir
@spec render!(t(), keyword()) :: String.t()
```

`render/2`, answering the string or raising `Macaw.Draw.Error`.

# `right`

```elixir
@spec right(struct()) :: {:ok, t()} | error()
```

An axis right of the plot: `new(scale, :right)`.

# `right!`

```elixir
@spec right!(term()) :: t()
```

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

# `theme`

```elixir
@spec theme(t(), Macaw.Layers.Theme.t() | nil) :: t() | error()
```

The theme the colors, font and size resolve from, or `nil` for the default theme.

# `tick_format`

```elixir
@spec tick_format(t(), tick_format()) :: t() | error()
```

How a tick value becomes its label: a `Macaw.Draw.Format`, a `Macaw.Format`, a
`Macaw.Format.Time`, a `Macaw.Format.Measure`, a 1-arity function, or `nil`
for the default label.

# `tick_padding`

```elixir
@spec tick_padding(t(), number()) :: t() | error()
```

The gap between a tick line's end and its label.

# `tick_position`

```elixir
@spec tick_position(t(), term()) :: number() | nil | error()
```

The position of a tick value (spec/06 §17.3): `Scale.apply/2` plus the offset and d3's
band centering, `max(0, bandwidth − 2·offset) / 2`, rounded when the band scale rounds;
`nil` for a value the scale places nowhere. A frame's grid lines are drawn here too.

# `tick_size`

```elixir
@spec tick_size(t(), number()) :: t() | error()
```

The inner and outer tick sizes together.

# `tick_size_inner`

```elixir
@spec tick_size_inner(t(), number()) :: t() | error()
```

The length of each tick line.

# `tick_size_outer`

```elixir
@spec tick_size_outer(t(), number()) :: t() | error()
```

The length of the domain line's end caps.

# `tick_values`

```elixir
@spec tick_values(t(), [term()] | nil) :: t() | error()
```

Explicit tick values, bypassing the scale's ticks, or `nil`.

# `ticks`

```elixir
@spec ticks(t(), number()) :: t() | error()
```

The tick count hint given to the scale's `ticks/2`; ignored when `tick_values` is set.

# `top`

```elixir
@spec top(struct()) :: {:ok, t()} | error()
```

An axis above the plot: `new(scale, :top)`.

# `top!`

```elixir
@spec top!(term()) :: t()
```

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

---

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