Skip to content

pieSlices

Read as Markdown

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.

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

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

Related API: pieSlices, PieOptions, PieSliceGeometry.

  • data — Records whose values determine slice proportions.

  • options — Value accessor and optional stable key accessor. See PieOptions.

Ordered slice geometry associated with the input records. See PieSliceGeometry.

PieOptions

PieSliceGeometry

View source — packages/core/src/features/viz/lib/pie-slices.ts:55

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

interface PieOptions<D>

Related API: PieOptions.

LineAccessor

PlotKeyAccessor

pieSlices

PieLayoutProps

View source — packages/core/src/features/viz/lib/pie-slices.ts:14

value
readonly value: LineAccessor<D>

Related API: LineAccessor.

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

View source — packages/core/src/features/viz/lib/pie-slices.ts:16

keyBy (optional)
readonly keyBy?: PlotKeyAccessor<D> | undefined

Related API: PlotKeyAccessor.

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

View source — packages/core/src/features/viz/lib/pie-slices.ts:18

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

interface PieSliceGeometry<D>

Related API: PieSliceGeometry.

pieSlices

PieLayoutProps

PieLayoutSlice

View source — packages/core/src/features/viz/lib/pie-slices.ts:28

datum
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

index
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

key
readonly key: string

Stable identity used by the containing protocol. See PieSliceGeometry.

View source — packages/core/src/features/viz/lib/pie-slices.ts:34

value
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

fraction
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

startAngle
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

endAngle
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

Read the Data visualization companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

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