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

A line through points (spec/07 §3), copied from visualize's `Visualize.Shape.Line`.

`new/0` reads tuple elements 0 and 1 as `x` and `y`, so `{x, y}` tuples need no
configuration:

    iex> alias Macaw.Draw.Shape.Line
    iex> Line.new() |> Line.generate([{0, 0}, {10, 5}, {20, 2}])
    "M0,0L10,5L20,2"

`generate_path/2` splits the data into defined runs (§1.2: a falsy `defined` and a
coordinate that is no number each break the line), draws each run through the curve as
its own subpath, and concatenates them in data order; no run of two points is the empty
path. A layer whose pixels are columns hands `runs_path/2` its runs of `{x, y}` points
instead, and reads no accessor (§1.4).

An accessor is a 1-arity function, a field name read from a map datum by spelling (`:v`
finds `"v"` and the other way round, as `Macaw.Data.Table.get/2` reads it), or a
numeric constant (§1.1). A generator takes a list of data; any other term is
`{:error, [{[], {:type, :list}}]}`.

# `accessor`

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

An accessor: a 1-arity function, a field name, or a numeric constant (§1.1).

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Shape.Line{
  curve: Macaw.Draw.Shape.Curve.curve_type(),
  curve_opts: keyword(),
  defined: (term() -&gt; term()) | nil,
  x: (term() -&gt; term()) | nil,
  y: (term() -&gt; term()) | nil
}
```

# `curve`

```elixir
@spec curve(t(), term()) :: {:ok, t()} | error()
```

`curve(line, type, [])`.

# `curve`

```elixir
@spec curve(t(), term(), keyword()) :: {:ok, t()} | error()
```

Sets the curve type (§5) and its options: `{:ok, line}`, or `{:error, faults}` for an
unknown type (`{[], {:unknown, :curve, spelling}}`) or an option of the wrong type.

# `curve!`

```elixir
@spec curve!(t(), term(), keyword()) :: t()
```

As `curve/3`, the line itself, raising `Macaw.Draw.Error` with its faults.

# `defined`

```elixir
@spec defined(t(), (term() -&gt; term()) | nil) :: t() | error()
```

Sets the `defined` predicate (§1.2), a 1-arity function; `nil` clears it.

# `generate`

```elixir
@spec generate(t(), [term()]) :: String.t() | error()
```

The SVG path data of `generate_path/2`.

# `generate_path`

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

The line's `Macaw.Draw.IR.Path`: one subpath per defined run of two or more points, each
through the curve, in data order (§3).

# `new`

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

A line reading tuple elements 0 and 1.

# `runs_path`

```elixir
@spec runs_path(t(), [[{number(), number()}]]) :: Macaw.Draw.IR.Path.t() | error()
```

The path of runs already read (§1.4): each run a list of `{x, y}` points drawn through
the curve as its own subpath, in order, as `generate_path/2` draws a run of defined data.
A point that is no pair of numbers is `{[1, run, i], {:type, :point}}`.

# `x`

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

Sets the x accessor: a function, a field, or a number.

# `y`

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

Sets the y accessor: a function, a field, or a number.

---

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