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

A gauge's or compass's pointer (spec/07 §16), copied from visualize's
`Visualize.Shape.Needle`: one filled pointer per datum from the hub to its angle.

`angle/2` is in the radial scale's domain units, radians without one; `length/2`,
`inner_radius/2`, `width/2` and `tail/2` are pixel accessors; `hub/2` is the hub
circle's radius, the width when `nil`; `cap/2` is `:point`, `:round` or `:flat`, read by
spelling, another `{[], {:unknown, :cap, spelling}}`.

    iex> alias Macaw.Draw.Shape.Needle
    iex> Needle.generate(Needle.new(), [{0, 100}])
    ["M3,0L-3,0L0,-100Z"]

With `a` the angle clockwise from 12 o'clock, `u = (sin a, −cos a)` the ray and
`p = (cos a, sin a)` across it, each path runs from the base corner
`(inner_radius − tail)·u + (width/2)·p`, to the other corner, then to the tip by its cap,
and closes. A datum with a coordinate that is no number draws the empty path, so the
list stays one path a datum.

# `accessor`

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

# `cap`

```elixir
@type cap() :: :point | :round | :flat
```

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Shape.Needle{
  angle: (term() -&gt; term()) | nil,
  cap: cap(),
  hub: (term() -&gt; term()) | nil,
  inner_radius: (term() -&gt; term()) | number(),
  length: (term() -&gt; term()) | nil,
  scale: struct() | nil,
  tail: (term() -&gt; term()) | number(),
  width: (term() -&gt; term()) | number()
}
```

# `angle`

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

Sets the angle, in the scale's domain units (radians without one), accessor: a function, a field, or a number.

# `cap`

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

Sets the tip, `:point`, `:round` or `:flat` by spelling: `{:ok, needle}` or `{:error, faults}`.

# `cap!`

```elixir
@spec cap!(t(), term()) :: t()
```

As `cap/2`, the needle itself, raising `Macaw.Draw.Error` with its faults.

# `generate`

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

The pointers as SVG path data, one per datum.

# `generate_path`

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

One `Macaw.Draw.IR.Path` pointer per datum, in data order.

# `hub`

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

Sets the hub circle's radius accessor; `nil` means the width.

# `hub_path`

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

The hub circle about the origin for a datum, radius `hub` (the width when `nil`).

# `inner_radius`

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

Sets the pointer's start, in pixels (default `0`), accessor: a function, a field, or a number.

# `length`

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

Sets the tip's radius, in pixels, accessor: a function, a field, or a number.

# `new`

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

A needle reading tuple elements 0 and 1 as angle and length.

# `scale`

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

Sets the radial scale the angles map through; `nil` means radians.

# `tail`

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

Sets the length behind the hub, in pixels (default `0`), accessor: a function, a field, or a number.

# `width`

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

Sets the base width, in pixels (default `6`), accessor: a function, a field, or a number.

---

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