# pieSlices

Import `pieSlices` from `@pibbl/core/viz`. Call `pieSlices(data, { value, keyBy? })`.
`value` is a numeric property key or `(datum, index, data)` accessor; `keyBy`
uses the same property/function convention as `PlotSeries`.

Returns a frozen array of frozen `PieSliceGeometry` records with `datum`, source `index`,
string `key`, `value`, `fraction`, `startAngle`, and `endAngle`. Datum references
are preserved, not frozen or copied. No sorting or input mutation occurs.

Values must be finite and nonnegative. Null and undefined become zero; other
invalid values and an overflowing total throw. Zero/missing rows remain in the
result with zero fraction and equal angles. Empty input returns an empty array;
an all-zero dataset has no painted sectors. A zero fraction does not mean an
equal share.

Angles use Canvas radians, clockwise from −π/2 (12 o'clock), covering one full
turn. Feed them directly to core `Wedge` style. Its exact filled-sector and
optional stroke geometry supplies normal Pibbl events, transforms, and clipping.
Decorative labels should set `pointerEvents="none"`. Shared edges use ordinary
source paint order; there is no nearest-slice or chart-wide target.

Keys default to stringified source indices. Supply unique stable category IDs
for mutable data and use `slice.key` as the Pibbl element key. String and finite
number keys are accepted; duplicates after string conversion throw. Reordering
changes angles while preserving explicit keys; record objects are fresh on each
call.

The helper owns no rendering or reactive resources. Read data signals inside a
component or core computed and pass the resulting plain array. Compose `Wedge`,
custom labels, legends, and `HoverCard` with ordinary elements and handlers.
Angles are radius-independent, so custom annular `Path` geometry can reuse them;
core Wedge has no inner radius. Donut rendering, padding, sorting, and arbitrary
sweeps are outside this first slice.

## API details from source

<span id="api-pieSlices"></span>

### pieSlices

Pure source-ordered full-circle layout. Angles use Canvas radians, clockwise from the top.

```ts
pieSlices: <D>(data: readonly D[], { value: input, keyBy }: PieOptions<D>) => readonly PieSliceGeometry<D>[]
```

Related API: [pieSlices](/reference/functions/pie-slices/), [PieOptions](/reference/functions/pie-slices/), [PieSliceGeometry](/reference/functions/pie-slices/).

#### Parameters

- **`data`** — Records whose values determine slice proportions.

- **`options`** — Value accessor and optional stable key accessor. See [PieOptions](/reference/functions/pie-slices/).

#### Returns

Ordered slice geometry associated with the input records. See [PieSliceGeometry](/reference/functions/pie-slices/).

#### See also

[PieOptions](/reference/functions/pie-slices/)

[PieSliceGeometry](/reference/functions/pie-slices/)

[View source — packages/core/src/features/viz/lib/pie-slices.ts:55](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L55)

<span id="api-PieOptions"></span>

### PieOptions

Value and stable-key accessors used to derive pie-slice geometry.

```ts
interface PieOptions<D>
```

Related API: [PieOptions](/reference/functions/pie-slices/).

#### See also

[LineAccessor](/reference/components/line-series/)

[PlotKeyAccessor](/reference/components/plot-series/)

[pieSlices](/reference/functions/pie-slices/)

[PieLayoutProps](/reference/components/pie-layout/)

[View source — packages/core/src/features/viz/lib/pie-slices.ts:14](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L14)

#### Properties and methods

<span id="api-PieOptions-value"></span>
<details>
<summary>value</summary>


```ts
readonly value: LineAccessor<D>
```

Related API: [LineAccessor](/reference/components/line-series/).

Value associated with this sample, input, or result. See LineAccessor.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:16](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L16)

</details>

<span id="api-PieOptions-keyBy"></span>
<details>
<summary>keyBy (optional)</summary>


```ts
readonly keyBy?: PlotKeyAccessor<D> | undefined
```

Related API: [PlotKeyAccessor](/reference/components/plot-series/).

Property or callback supplying stable identity for each datum. See PlotKeyAccessor.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:18](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L18)

</details>

<span id="api-PieSliceGeometry"></span>

### PieSliceGeometry

A datum's key, value, fraction, and angular interval in a pie layout.

```ts
interface PieSliceGeometry<D>
```

Related API: [PieSliceGeometry](/reference/functions/pie-slices/).

#### See also

[pieSlices](/reference/functions/pie-slices/)

[PieLayoutProps](/reference/components/pie-layout/)

[PieLayoutSlice](/reference/components/pie-layout/)

[View source — packages/core/src/features/viz/lib/pie-slices.ts:28](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L28)

#### Properties and methods

<span id="api-PieSliceGeometry-datum"></span>
<details>
<summary>datum</summary>


```ts
readonly datum: D
```

The original data item selected by this result. See PieSliceGeometry.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:30](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L30)

</details>

<span id="api-PieSliceGeometry-index"></span>
<details>
<summary>index</summary>


```ts
readonly index: number
```

Index of the selected datum in its source data. See PieSliceGeometry.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:32](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L32)

</details>

<span id="api-PieSliceGeometry-key"></span>
<details>
<summary>key</summary>


```ts
readonly key: string
```

Stable identity used by the containing protocol. See PieSliceGeometry.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:34](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L34)

</details>

<span id="api-PieSliceGeometry-value"></span>
<details>
<summary>value</summary>


```ts
readonly value: number
```

Value associated with this sample, input, or result. See PieSliceGeometry.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:36](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L36)

</details>

<span id="api-PieSliceGeometry-fraction"></span>
<details>
<summary>fraction</summary>


```ts
readonly fraction: number
```

Normalized share or position represented by this value. See PieSliceGeometry.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:38](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L38)

</details>

<span id="api-PieSliceGeometry-startAngle"></span>
<details>
<summary>startAngle</summary>


```ts
readonly startAngle: number
```

Angle at which the arc or slice begins. See PieSliceGeometry.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:40](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L40)

</details>

<span id="api-PieSliceGeometry-endAngle"></span>
<details>
<summary>endAngle</summary>


```ts
readonly endAngle: number
```

Angle at which the arc or slice ends. See PieSliceGeometry.

[View source — packages/core/src/features/viz/lib/pie-slices.ts:42](/source/packages/core/src/features/viz/lib/pie-slices-ts/#L42)

</details>

## Implementation guidance for agents

Read the [Data visualization companion](/agents/topics/visualization/) for ownership, adaptation, failure modes, and verification. [Agent start](/agents/) provides the version-selection workflow.

## Complete minimal examples

- [Pie chart composition](/minimal-examples/viz/pie/): Compute pie geometry and render labeled donut slices. [Plain source](/minimal/viz/pie.tsx)
## Documentation version

Documentation built with @pibbl/core 0.0.2, revision 272a94a. ALPHA — NOT FOR PRODUCTION USE.
