# `Visualize.Axis`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/axis.ex#L1)

Axis generator for creating reference marks and labels.

Creates element groups containing tick marks, labels, and axis lines. Colors, font and
size come from a `Visualize.Theme` (`theme/2`, default `Visualize.Theme.default/0`),
resolved as CSS references for SVG and as literals for a canvas (spec/05 §1.4, D-55).

## Examples

    x_scale = Visualize.Scale.linear()
      |> Visualize.Scale.domain([0, 100])
      |> Visualize.Scale.range([0, 500])

    x_axis = Visualize.Axis.bottom(x_scale)
      |> Visualize.Axis.ticks(5)
      |> Visualize.Axis.tick_format(fn v -> "#{v}%" end)

    element = Visualize.Axis.generate(x_axis)

# `orientation`

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

# `t`

```elixir
@type t() :: %Visualize.Axis{
  offset: number(),
  orient: orientation(),
  scale: struct(),
  theme: Visualize.Theme.t() | nil,
  tick_format: (any() -&gt; String.t()) | nil,
  tick_padding: number(),
  tick_size_inner: number(),
  tick_size_outer: number(),
  tick_values: [any()] | nil,
  ticks: integer() | nil
}
```

# `bottom`

```elixir
@spec bottom(struct()) :: t()
```

Creates a bottom-oriented axis

# `generate`

```elixir
@spec generate(t(), keyword()) :: Visualize.IR.Element.t()
```

Generates the axis as an IR Element tree.

Returns a group element containing the domain line and tick groups.

## Options

  * `:resolve` - how the theme's slots render: `:css` (default) for references a
    stylesheet can override, `:literal` for the plain values a canvas needs

# `left`

```elixir
@spec left(struct()) :: t()
```

Creates a left-oriented axis

# `offset`

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

Sets the pixel offset for crisp edges

# `render`

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

Renders the axis to a string using the specified backend.

## Options

  * `:backend` - The backend to use (`:svg`, `:canvas`, or a module). Defaults to `:svg`.
  * `:resolve` - the theme mode of `generate/2`; defaults to `Visualize.Theme.mode/1` of
    the backend, so an SVG axis carries CSS references and a canvas axis literals

# `right`

```elixir
@spec right(struct()) :: t()
```

Creates a right-oriented axis

# `theme`

```elixir
@spec theme(t(), Visualize.Theme.t()) :: t()
```

Sets the theme the axis's colors, font and size resolve from

# `tick_count`

```elixir
@spec tick_count(number(), orientation()) :: pos_integer()
```

The tick-count hint an axis `length` pixels long asks for on a side (spec/05 §1.5):
one tick per 80 px across a `:top` or `:bottom` axis, per 35 px down a `:left` or
`:right` one (Observable Plot's spacing), at least 2 and at most 10.

A pure function rather than a default: `ticks/2` stays d3's ten unless given this.

    iex> Visualize.Axis.tick_count(600, :bottom)
    7

    iex> Visualize.Axis.tick_count(300, :left)
    8

# `tick_format`

```elixir
@spec tick_format(t(), (any() -&gt; String.t())) :: t()
```

Sets the tick format function

# `tick_padding`

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

Sets the padding between tick and label

# `tick_size`

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

Sets both inner and outer tick sizes

# `tick_size_inner`

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

Sets the inner tick size (length of tick lines)

# `tick_size_outer`

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

Sets the outer tick size (length of domain line extensions)

# `tick_values`

```elixir
@spec tick_values(t(), [any()]) :: t()
```

Sets explicit tick values

# `ticks`

```elixir
@spec ticks(t(), integer()) :: t()
```

Sets the approximate number of ticks

# `top`

```elixir
@spec top(struct()) :: t()
```

Creates a top-oriented axis

---

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