Components

DonutChart

SVG donut chart implemented in pure React without dependencies

Overview

DonutChart is a pure SVG-based donut chart. It renders using arc-path calculations without any external chart libraries.

  • No dependency — No need for D3, Chart.js, or other external libraries
  • Interactive — Supports segment click events
  • Customizable — Size, inner ratio, start angle, and colors are all customizable
  • Accessiblerole="img" and aria-label applied by default

Basic Usage

import { DonutChart } from '@illog/ui'
 
<DonutChart
  segments={[
    { value: 40, fill: 'var(--background-brand-default)' },
    { value: 30, fill: 'var(--background-success-default)' },
    { value: 20, fill: 'var(--background-warning-default)' },
    { value: 10, fill: 'var(--background-danger-default)' },
  ]}
/>

Interaction

<DonutChart
  segments={categories.map(cat => ({
    id: cat.id,
    value: cat.hours,
    fill: cat.color,
    ariaLabel: `${cat.name}: ${cat.hours} hours`,
  }))}
  onSegmentClick={(segment, index) => {
    setSelectedCategory(segment.id)
  }}
/>

Customization

// Small chart, thin ring
<DonutChart segments={segments} size={120} innerRatio={0.75} />
 
// Large chart, thick ring
<DonutChart segments={segments} size={240} innerRatio={0.3} />

Props

PropTypeDefaultDescription
segmentsDonutChartSegment[]requiredArray of segment data
sizenumber180Chart size (px)
innerRationumber0.55Inner hole ratio (0–0.95)
startAnglenumber0Start angle (12 o'clock = 0)
defaultStrokeWidthnumber0.75Default segment stroke width
emptyFillstringvar(--background-default-tertiary)Empty state fill color
emptyStrokestringvar(--border-default-default)Empty state stroke color
onSegmentClick(segment, index) => voidSegment click handler
segmentKey(segment, index) => stringReact key generator function

DonutChartSegment

PropTypeDescription
valuenumberSegment value (values ≤ 0 are excluded)
fillstringCSS color
strokestringSegment stroke color
strokeWidthnumberIndividual stroke width
ariaLabelstringAccessibility label
idstringIdentifier

Guidelines

  • When all segment values are 0, an empty gray ring is displayed
  • For data visualization, consider using TimeDistribution instead of DonutChart alone