Sunburst Chart

A series in two rings: its rows' groups inside, each their total, and the rows around them in their group's color. Names and colors come from the chart's config; the keyboard moves through the rows, and the tooltip says their values.

ChartsExperimental

Installation

It has its own entry point, @semantic-components/ui/charts, built on d3-scale d3-shape — an optional peer of ui: install it where you use the component.

ts
import { ScChart, ScChartPlot, ScChartSunburst } from '@semantic-components/ui/charts';

Usage

import { DecimalPipe } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScChart,  type ScChartConfig,  ScChartLegend,  ScChartLegendIndicator,  ScChartLegendItem,  ScChartPlot,  ScChartSunburst,  ScChartTooltip,  ScChartTooltipIndicator,  ScChartTooltipItem,  ScChartTooltipLabel,  ScChartTooltipName,  ScChartTooltipPortal,  ScChartTooltipProvider,  ScChartTooltipValue,} from '@semantic-components/ui/charts';
@Component({  selector: 'app-sunburst-chart-usage-demo',  imports: [    ScChart,    ScChartPlot,    ScChartSunburst,    ScChartTooltip,    ScChartTooltipPortal,    ScChartTooltipProvider,    ScChartLegend,    DecimalPipe,    ScChartTooltipLabel,    ScChartTooltipIndicator,    ScChartTooltipItem,    ScChartTooltipName,    ScChartTooltipValue,    ScChartLegendItem,    ScChartLegendIndicator,  ],  template: `    <div      scChart      class="mx-auto aspect-square max-h-72"      [config]="config"      [data]="data"    >      <svg        scChartPlot        categoryKey="country"        aria-label="Sales by region and country"      >        <g scChartSunburst key="sales" groupKey="region" />      </svg>      <div scChartTooltipProvider>        <ng-template scChartTooltipPortal>          <div scChartTooltip #tooltip="scChartTooltip">            <div scChartTooltipLabel>{{ tooltip.label() }}</div>            @for (item of tooltip.payload(); track item.dataKey) {              <div scChartTooltipItem [item]="item">                <span scChartTooltipIndicator></span>                <span scChartTooltipName>{{ item.name }}</span>                <span scChartTooltipValue>{{ item.value | number }}</span>              </div>            }          </div>        </ng-template>      </div>      <div scChartLegend #legend="scChartLegend">        @for (item of legend.payload(); track item.dataKey) {          <div scChartLegendItem [item]="item">            <span scChartLegendIndicator></span>            {{ item.name }}          </div>        }      </div>    </div>  `,  host: { class: 'block w-full max-w-xl' },  encapsulation: ViewEncapsulation.None,})export class SunburstChartUsageDemo {  private readonly data = [    { region: 'europe', country: 'France', sales: 240 },    { region: 'europe', country: 'Germany', sales: 190 },    { region: 'europe', country: 'Spain', sales: 110 },    { region: 'americas', country: 'USA', sales: 320 },    { region: 'americas', country: 'Brazil', sales: 130 },    { region: 'asia', country: 'Japan', sales: 210 },    { region: 'asia', country: 'India', sales: 150 },  ];  private readonly config: ScChartConfig = {    sales: { label: 'Sales' },    europe: { label: 'Europe', color: 'var(--chart-1)' },    americas: { label: 'Americas', color: 'var(--chart-2)' },    asia: { label: 'Asia', color: 'var(--chart-3)' },  };}

Anatomy

A chart (its rows and config), its plot with the series, and the tooltip and legend you write from their state.

import { ScChart, ScChartPlot, ScChartSunburst, ScChartTooltip, ScChartTooltipIndicator, ScChartTooltipItem, ScChartTooltipName, ScChartTooltipPortal, ScChartTooltipProvider, ScChartTooltipValue, ScChartLegend, ScChartLegendIndicator, ScChartLegendItem } from '@semantic-components/ui/charts';
<div scChart [config]="…" [data]="…">  <svg scChartPlot categoryKey="…" aria-label="…">    <g scChartSunburst key="…" groupKey="…" />  </svg>  <div scChartTooltipProvider>    <ng-template scChartTooltipPortal>      <div scChartTooltip #tooltip="scChartTooltip">        <div scChartTooltipItem [item]="…">          <span scChartTooltipIndicator></span>          <span scChartTooltipName>…</span>          <span scChartTooltipValue>…</span>        </div>      </div>    </ng-template>  </div>  <div scChartLegend #legend="scChartLegend">    <div scChartLegendItem [item]="…">      <span scChartLegendIndicator></span>    </div>  </div></div>

Accessibility

  • The plot is one tab stop, a group named by its aria-label: the arrow keys, Home and End move through its rows; Escape closes the tooltip.
  • As the keyboard moves, screen readers hear what the tooltip says, through the CDK's LiveAnnouncer (politely).
  • Right to left, with the app following the direction (charts.followDirection), it is mirrored — from 9 o’clock, clockwise — and ← goes to the next.
  • It draws whole at once: Recharts' has no animation.

Examples

Labels

import { DecimalPipe } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScChart,  type ScChartConfig,  ScChartLabels,  ScChartPlot,  ScChartSunburst,  ScChartTooltip,  ScChartTooltipIndicator,

RTL

أوروبا
الأمريكتان
آسيا
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScChart,  type ScChartConfig,  ScChartLegend,  ScChartLegendIndicator,  ScChartLegendItem,  ScChartPlot,  ScChartSunburst,

API reference

The series' inputs. The chart, its plot, axes, tooltip and legend are on the Chart page.

InputTypeDefaultDescription
keystring (required)— each row's value
groupKeystring (required)— each row's group, the inner ring
innerRadiusnumber0.3 its hole, a share of the radius
splitRadiusnumber0.65 where the groups' ring ends, a share of the radius
strokeWidthnumber2 the line between slices (0: none)
cornerRadiusnumber— Its arcs' corners' rounding, in px — unset, the style's (--sc-chart-bar-radius, as the bars'; square in Lyra and Sera).
classstring'' Merged over its own classes.