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

Pie layout generator that computes angles for pie and donut charts.

This doesn't generate paths directly - it computes start and end angles
that can be passed to the Arc generator.

## Examples

    data = [
      %{name: "A", value: 30},
      %{name: "B", value: 50},
      %{name: "C", value: 20}
    ]

    pie = Visualize.Shape.Pie.new()
      |> Visualize.Shape.Pie.value(fn d -> d.value end)

    arcs = Visualize.Shape.Pie.generate(pie, data)
    # Returns list of maps with :data, :value, :index, :start_angle, :end_angle, :pad_angle

# `accessor`

```elixir
@type accessor() :: (any() -&gt; number()) | atom()
```

# `arc_data`

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

# `comparator`

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

# `t`

```elixir
@type t() :: %Visualize.Shape.Pie{
  end_angle: number() | (any() -&gt; number()),
  pad_angle: number() | (any() -&gt; number()),
  sort: comparator() | nil,
  sort_values: comparator() | nil,
  start_angle: number() | (any() -&gt; number()),
  value: accessor() | nil
}
```

# `end_angle`

```elixir
@spec end_angle(t(), number()) :: t()
```

Sets the end angle (in radians)

# `generate`

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

Generates arc data from the input data.

Returns a list of maps, each containing:
- `:data` - the original data element
- `:value` - the computed value
- `:index` - the original index
- `:start_angle` - start angle in radians
- `:end_angle` - end angle in radians
- `:pad_angle` - padding angle in radians

# `new`

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

Creates a new pie generator

# `pad_angle`

```elixir
@spec pad_angle(t(), number()) :: t()
```

Sets the pad angle between arcs (in radians)

# `sort`

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

Sets a comparator to sort the data before computing angles.

Takes a function that receives two data elements and returns true
if the first should come before the second.

# `sort_values`

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

Sets a comparator to sort by computed values.

Takes a function that receives two values and returns true
if the first should come before the second.

# `start_angle`

```elixir
@spec start_angle(t(), number()) :: t()
```

Sets the start angle (in radians)

# `value`

```elixir
@spec value(t(), accessor()) :: t()
```

Sets the value accessor

---

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