|
| 1 | +--- |
| 2 | +description: Marking component which positions text labels on pie and arc chart segments, including along the arc path, at the centroid (horizontal, tangent-rotated, or radially-rotated), outside the arc, and with callout leader lines. |
| 3 | +category: marks |
| 4 | +layers: [svg] |
| 5 | +related: [Arc, Pie, PieChart, ArcChart, Labels] |
| 6 | +--- |
| 7 | + |
| 8 | +## Usage |
| 9 | + |
| 10 | +`ArcLabel` positions a text label (and optional leader line) relative to an arc. It's used by `PieChart` and `ArcChart` internally when the `labels` prop is set, but can also be used directly inside an `Arc` children snippet for full control. |
| 11 | + |
| 12 | +:example{ component="PieChart" name="labels" showCode } |
| 13 | + |
| 14 | +### Placements |
| 15 | + |
| 16 | +- `centroid` — at the arc centroid (horizontal text, default). |
| 17 | +- `centroid-rotated` — at the centroid, rotated to follow the arc tangent. The rotation is flipped where needed so text stays upright. |
| 18 | +- `centroid-radial` — at the centroid, rotated to read along the radial direction (center → outer edge). Useful for sunburst-style labels. |
| 19 | +- `inner` — along the inner arc path. |
| 20 | +- `middle` — along the medial arc path (midway between inner and outer). |
| 21 | +- `outer` — along the outer arc path. |
| 22 | +- `callout` — outside the arc with a polyline leader line that bends horizontally toward the label. |
| 23 | + |
| 24 | +### Offsets |
| 25 | + |
| 26 | +Depending on the placement, different offset props apply: |
| 27 | + |
| 28 | +- `outerPadding` — adds padding to the outer radius used for `inner` / `middle` / `outer` arc text paths. |
| 29 | +- `startOffset` — percentage along the arc path where the text starts. Defaults to `'50%'` (centered). |
| 30 | +- `calloutLineLength` — length of the radial portion of the `callout` leader line. |
| 31 | +- `calloutLabelOffset` — length of the horizontal portion of the `callout` leader line after the bend. |
| 32 | +- `calloutPadding` — gap between the end of the leader line and the label text. |
| 33 | + |
| 34 | +### Callout leader lines |
| 35 | + |
| 36 | +`placement="callout"` draws a line from the outer arc edge to the label with a single bend. The line is rendered via the [`Path`](/docs/components/Path) component so it works in both SVG and Canvas chart layers. |
| 37 | + |
| 38 | +Three props control the geometry: |
| 39 | + |
| 40 | +- `calloutLineLength` — length of the radial (first) segment, from the outer arc edge out to the bend. |
| 41 | +- `calloutLabelOffset` — length of the horizontal (second) segment, from the bend to the label. |
| 42 | +- `calloutPadding` — gap between the end of the line and the label text. |
| 43 | + |
| 44 | +:example{ component="PieChart" name="labels-callout" } |
| 45 | + |
| 46 | +Customize the line itself via the `line` prop, which forwards props to `<Path>`: |
| 47 | + |
| 48 | +```svelte |
| 49 | +<PieChart |
| 50 | + {data} |
| 51 | + labels={{ |
| 52 | + placement: 'callout', |
| 53 | + value: 'fruit', |
| 54 | + line: { stroke: 'currentColor', strokeWidth: 1.5, class: 'opacity-50' } |
| 55 | + }} |
| 56 | +/> |
| 57 | +``` |
| 58 | + |
| 59 | +### Using `ArcLabel` directly |
| 60 | + |
| 61 | +When using `Arc` directly (outside of `PieChart`/`ArcChart`), render `ArcLabel` inside the `Arc` children snippet. The snippet exposes `centroid`, `startAngle`, `endAngle`, `innerRadius`, `outerRadius`, and `getArcTextProps` — all of which `ArcLabel` accepts. |
| 62 | + |
| 63 | +```svelte |
| 64 | +<Arc {...arcProps}> |
| 65 | + {#snippet children({ centroid, startAngle, endAngle, innerRadius, outerRadius, getArcTextProps })} |
| 66 | + <ArcLabel |
| 67 | + {centroid} |
| 68 | + {startAngle} |
| 69 | + {endAngle} |
| 70 | + {innerRadius} |
| 71 | + {outerRadius} |
| 72 | + {getArcTextProps} |
| 73 | + placement="centroid-radial" |
| 74 | + value="Label text" |
| 75 | + /> |
| 76 | + {/snippet} |
| 77 | +</Arc> |
| 78 | +``` |
0 commit comments