Skip to content

Arc

An Arc draws a circular or annular (donut) arc segment. It supports inner radius for donut shapes, pad angles for spacing between segments, and provides a getCentroid() method useful for positioning labels.

Example

Usage

ts
import {
    createArc,
} from '@ripl/core';

const arc = createArc({
    fillStyle: '#3a86ff',
    cx: 200,
    cy: 200,
    radius: 100,
    startAngle: 0,
    endAngle: Math.PI,
});

Properties

PropertyTypeRequiredDescription
cxnumberYesCenter X coordinate
cynumberYesCenter Y coordinate
radiusnumberYesOuter radius
startAnglenumberYesStart angle in radians
endAnglenumberYesEnd angle in radians
innerRadiusnumberNoInner radius (creates a donut/annular arc)
padAnglenumberNoPadding angle in radians between segments
borderRadiusnumberNoCorner rounding radius

Plus all Element style properties and Shape options.

Methods

getCentroid(alterations?)

Returns the centroid point [x, y] of the arc segment. Useful for positioning labels at the visual center of a pie/donut slice:

ts
const [labelX, labelY] = arc.getCentroid();

You can pass partial state alterations to compute the centroid at a different radius:

ts
const [x, y] = arc.getCentroid({ radius: arc.radius * 1.2 });