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

The angles of a pie, as data (spec/07 §7), copied from visualize's
`Visualize.Shape.Pie`. It draws nothing: `generate/2` answers one arc datum per datum,
in data order, that `Macaw.Draw.Shape.Arc` consumes directly.

    iex> alias Macaw.Draw.Shape.Pie
    iex> [a, b] = Pie.generate(Pie.new(), [1, 3])
    iex> {a.end_angle, b.start_angle, b.value}
    {1.5707963267948966, 1.5707963267948966, 3}

An arc datum is `%{data: d, value: v, index: i, start_angle: a, end_angle: b,
pad_angle: p}`: `v = max(0, value.(d))` (a value that is not a number read as `0`), the
span `da = clamp(end − start, −2π, 2π)` shared out as `k = (da − n·pad) / Σv` per unit
(`0` when the total is not positive), the pad after each positive value only. Sorting
(`sort/2` on the data, `sort_values/2` on the values) changes the angles, never the
order of the answer.

`start_angle`, `end_angle` and `pad_angle` are numbers or 1-arity functions of the whole
data list, evaluated once per `generate/2`; one answering no number is
`{[key], {:type, :number}}`.

# `angle`

```elixir
@type angle() :: number() | ([term()] -&gt; number())
```

# `arc_datum`

```elixir
@type arc_datum() :: %{
  data: term(),
  value: number(),
  index: non_neg_integer(),
  start_angle: number(),
  end_angle: number(),
  pad_angle: number()
}
```

# `comparator`

```elixir
@type comparator() :: (term(), term() -&gt; boolean())
```

# `error`

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

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Draw.Shape.Pie{
  end_angle: angle(),
  pad_angle: angle(),
  sort: comparator() | nil,
  sort_values: comparator() | nil,
  start_angle: angle(),
  value: (term() -&gt; term()) | nil
}
```

# `end_angle`

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

Sets `end_angle`: radians, or a 1-arity function of the whole data list.

# `generate`

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

The arc data (§7): `[]` for empty data, else one map per datum in data order.

# `new`

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

A pie whose value is the datum itself when a number, its `:value` field (by spelling)
when a map, `0` when that is absent or `nil`, and `0` otherwise.

# `pad_angle`

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

Sets `pad_angle`: radians, or a 1-arity function of the whole data list.

# `sort`

```elixir
@spec sort(t(), comparator() | nil) :: t() | error()
```

Sets the comparator on data, a 2-arity function, and clears `sort_values`; `nil` unsets.

# `sort_values`

```elixir
@spec sort_values(t(), comparator() | nil) :: t() | error()
```

Sets the comparator on values, a 2-arity function, and clears `sort`; `nil` unsets.

# `start_angle`

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

Sets `start_angle`: radians, or a 1-arity function of the whole data list.

# `value`

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

Sets the value accessor: a function, a field (`0` when absent), or a number.

---

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