# `Macaw.Frame.Labels`
[🔗](https://github.com/dcoai/macaw_frame/blob/v0.1.0/lib/macaw/frame/labels.ex#L1)

The frame's labels (spec/03 §3.4): one text at its anchor, placed by the model.

| Anchor | Position | `text-anchor` | Default style |
|---|---|---|---|
| `:title` | `(w / 2, −m.top / 2)`, `dy 0.32em` | `middle` | `title` |
| `:subtitle` | `(w / 2, −4)` | `middle` | `label` |
| `:caption` | `(0, h + m.bottom − 4)` | `start` | `label` |
| `{:axis, s}` | the title of the first axis naming `s`, by its side | `middle` | `label` |
| `{:frame, corner}` | 4 in from the corner (`dy 0.71em` at the top) | `start`, `end` | `label` |
| `{:frame, :center}` | the plot's middle, the polar origin in a polar frame | `middle` | `label` |
| `{:data, point}` | the model's `place/2` of the point; nothing when it cannot place it | `start` | `label` |

A label's style may set `vertical_align`, `margin_x`, `margin_y` and `text_angle`,
applied along the anchor's **outward direction** (`position/4`); `rotate` turns the text
about its point, `:tangent` and `:radial` about the model's center with the upright flip
(`rotation/4`). Copied from visualize's `Visualize.Chart.Frame.Labels`,
`Visualize.Chart.Frame.Position` and `Visualize.Chart.Label.Polar`.

A text's rotation is its node's `Macaw.Draw.IR.Transform` (spec/10 §1.3): the anchor's
turn, then the label's own `rotate` about its point, then the style's `text_angle`.

# `placement`

```elixir
@type placement() :: %{
  :x =&gt; number(),
  :y =&gt; number(),
  :anchor =&gt; :start | :middle | :end,
  optional(:dy) =&gt; String.t(),
  optional(:rotate) =&gt; number()
}
```

Where a label's text goes: its point, `dy`, text anchor and rotation.

# `axis_title`

```elixir
@spec axis_title(Macaw.Frame.Coordinates.Model.t(), atom(), String.t(), keyword()) ::
  [
    Macaw.Draw.IR.Element.t()
  ]
```

An axis's title (§3.2): the text placed as a label anchored at the axis's side is.

# `center`

```elixir
@spec center(Macaw.Frame.Coordinates.Model.t()) :: {number(), number()}
```

The center a frame's labels turn about and its `center` anchor sits at: the plot's
middle, which is the polar origin in a polar frame.

# `generate`

```elixir
@spec generate(term(), term()) :: [Macaw.Draw.IR.Element.t()]
```

One text per label of `opts[:labels]` (the frame's label nodes) that has a place (§3.4),
in its style resolved through `opts[:styles]` and the theme.

# `outward`

```elixir
@spec outward(term(), term()) :: {-1 | 0 | 1, -1 | 0 | 1} | nil
```

The outward direction of an anchor (§3.4): away from the plot for titles and captions,
into the plot for corners, none for the center and data points.

# `place`

```elixir
@spec place(term(), term()) :: placement() | nil
```

Where an anchor puts a label in the model (§3.4), `nil` for a point it cannot place.

# `position`

```elixir
@spec position(Macaw.Draw.IR.Element.t(), map(), term(), {number(), number()}) ::
  Macaw.Draw.IR.Element.t()
```

A placed text with its style node's position keys applied (§3.4; spec/02 §6.3): the
`text` part's `baseline` (or `vertical_align`) sets its `dy`; its `offset` `[x, y]` (or
`margin_x` and `margin_y`) moves it along `outward`; its `angle` (or `text_angle`) turns
it about its own point. `box` is `{width, height}` an offset in `pct` is of.

# `rotation`

```elixir
@spec rotation(term(), {number(), number()}, {number(), number()}, atom()) ::
  {number() | nil, atom()}
```

The rotation of a text at `point` about `center` and the text anchor it leaves
(visualize `Visualize.Chart.Label.Polar`): `nil` none; a number as it is; `:radial` the
ray's angle anchored `:start`, flipped a half turn on the left and anchored `:end`;
`:tangent` a quarter turn from the ray, flipped on the lower half, anchored `:middle`.

    iex> Macaw.Frame.Labels.rotation(:radial, {-10, 0}, {0, 0}, :start)
    {0.0, :end}
    iex> Macaw.Frame.Labels.rotation(:tangent, {0, 10}, {0, 0}, :start)
    {0.0, :middle}

# `shown`

```elixir
@spec shown(term()) :: [map()]
```

The labels a design draws (spec/02 §6.1): every label node but one whose `show` is
`false`, in order; anything that is no list of labels draws none.

    iex> Macaw.Frame.Labels.shown([%{text: "a", show: false}, %{text: "b"}])
    [%{text: "b"}]

---

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