# `Visualize.Shape.Rule`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/shape/rule.ex#L1)

Rule generator: a vertical line at a domain x value, with an optional label
(spec/04 §12, D-27).

The x accessor yields a *domain* value that `scale/2` maps, so the rule stays aligned
with the axis whatever the margins. Without a scale the value is a pixel coordinate.
Each datum is one annotation; by default the datum is the value itself.

## Examples

    rule =
      Visualize.Shape.Rule.new()
      |> Visualize.Shape.Rule.scale(x_scale)
      |> Visualize.Shape.Rule.y1(height)
      |> Visualize.Shape.Rule.label("deploy")

    [group] = Visualize.Shape.Rule.generate(rule, [~U[2024-01-01 12:00:00Z]])

# `t`

```elixir
@type t() :: %Visualize.Shape.Rule{
  label: (any() -&gt; String.t() | nil) | nil,
  scale: struct() | nil,
  x: Visualize.Shape.Line.accessor() | nil,
  y0: Visualize.Shape.Line.accessor(),
  y1: Visualize.Shape.Line.accessor()
}
```

# `text_accessor`

```elixir
@type text_accessor() :: (any() -&gt; String.t() | nil) | atom() | String.t()
```

An accessor whose value is text: a 1-arity function, an atom field, or a string.

# `generate`

```elixir
@spec generate(t(), Visualize.Data.Table.source()) :: [Visualize.IR.Element.t()]
```

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

# `label`

```elixir
@spec label(t(), text_accessor() | nil) :: t()
```

Sets the label accessor: function, atom field, or string constant; `nil` clears it

# `new`

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

Creates a rule generator reading each datum as its x value, with extent 0 to 100

# `scale`

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

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

# `x`

```elixir
@spec x(t(), Visualize.Shape.Line.accessor()) :: t()
```

Sets the domain-value accessor

# `y0`

```elixir
@spec y0(t(), Visualize.Shape.Line.accessor()) :: t()
```

Sets the first vertical-extent accessor, in pixels

# `y1`

```elixir
@spec y1(t(), Visualize.Shape.Line.accessor()) :: t()
```

Sets the second vertical-extent accessor, in pixels

---

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