path-rite

pieLayout

Compute pie slice angles from an array of values.

pieLayout(values: number[]): PieSlice[]

values — Array of numeric values. Negative and zero values produce slices with zero angular span.

Returns — Array of PieSlice objects, one per input value:

  • startAngle: number — Start angle in radians (0 = 12 o'clock, clockwise).
  • endAngle: number — End angle in radians.
  • value: number — The original input value.
  • index: number — The index of this slice in the input array.

Angles span a full circle (0 to 2*PI), proportional to each value's share of the total. Feed the output into arcPath or arcPathRounded to generate SVG paths.

// Compute angles for three categories
const slices = pathRite.pieLayout([25, 25, 50]);
// slices[0]: { startAngle: 0, endAngle: PI/2, value: 25, index: 0 }
// slices[1]: { startAngle: PI/2, endAngle: PI, value: 25, index: 1 }
// slices[2]: { startAngle: PI, endAngle: 2*PI, value: 50, index: 2 }

// Combine with arcPath for a pie chart
const paths = slices.map(s =>
  pathRite.arcPath(100, 100, 0, 80, s.startAngle, s.endAngle)
);