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

A vertical rule at a domain value, with an optional label (spec/07 §12), copied from
visualize's `Visualize.Shape.Rule`: an instant (a deploy, an incident) inside the same
scale and plot as the data.

`x/2` yields a **domain** value that `scale/2` maps, any scale
`Macaw.Draw.Scale.apply/2` takes; with no scale the value is a pixel. `new/0` reads
each datum as its own value, so a list of bare values is valid data:

    iex> alias Macaw.Draw.Shape.Rule
    iex> [group] = Rule.generate(Rule.new(), [33])
    iex> [line] = group.children
    iex> {group.style, line.attrs}
    {%{class: "rule"}, %{x1: 33, y1: 0, x2: 33, y2: 100}}

`generate/2` answers one `:group` per datum, `style: %{class: "rule"}`: a `:line` from
`(px, y0)` to `(px, y1)` and, with a label, a `:text` right of the rule's upper end. A
value the scale places nowhere draws nothing for its datum. The label is a function, an
atom field, or a string; `nil` clears it.

# `accessor`

```elixir
@type accessor() :: (term() -&gt; term()) | atom() | String.t() | number()
```

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Shape.Rule{
  label: (term() -&gt; term()) | nil,
  scale: struct() | nil,
  x: (term() -&gt; term()) | nil,
  y0: (term() -&gt; term()) | number(),
  y1: (term() -&gt; term()) | number()
}
```

# `generate`

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

One `:group` element per drawn datum: the line, then the label when there is one.

# `label`

```elixir
@spec label(t(), term()) :: t() | error()
```

Sets the label: a function, an atom field, or a string; `nil` clears it.

# `new`

```elixir
@spec new() :: t()
```

A rule reading each datum as its own x value, with extent `0` to `100`.

# `scale`

```elixir
@spec scale(t(), struct() | nil) :: t() | error()
```

Sets the x scale the values map through; `nil` means the values are pixels.

# `x`

```elixir
@spec x(t(), accessor()) :: t() | error()
```

Sets the domain value accessor: a function, a field, or a number.

# `y0`

```elixir
@spec y0(t(), accessor()) :: t() | error()
```

Sets the first vertical extent accessor: a function, a field, or a number.

# `y1`

```elixir
@spec y1(t(), accessor()) :: t() | error()
```

Sets the second vertical extent accessor: a function, a field, or a number.

---

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