Menu

Change language

GitHub repo

Sunburst Chart

sunburst-chartui

React mirror of @uipkge/sunburst-chart — see the Vue registry item for the canonical description.

Installation

$npx shadcn@latest add https://uipkge.dev/r/lit/sunburst-chart.json
Manifest:https://uipkge.dev/r/lit/sunburst-chart.jsonInstalls to:src/uip/components/charts/

Examples

Loading interactive previews…

Props

NameType / ValuesDefaultRequired
dataSunNode[][]optional
radius[string, string]['12%', '90%']optional
optionany—optional

Schema

Type aliases from this item's source — use them to shape the data you pass in.

SunNode
interface SunNode {
  name: string
  value?: number
  children?: SunNode[]
}
HTMLElementTagNameMap
interface HTMLElementTagNameMap {
    'uip-sunburst-chart': UipSunburstChart
  }
}
ChartTheme
interface ChartTheme {
  colors: string[]
  textColor: string
  axisColor: string
  splitLineColor: string
  tooltipBg: string
  tooltipBorder: string
  tooltipText: string
  bgColor: string
  accentColor: string
  dangerColor: string
  /** `--card`: cell borders and inside-label text, so they read as gaps /
   *  contrast on light and dark surfaces (never '#fff'). */
  surfaceColor: string
  /** `--foreground`: primary numbers drawn on the canvas (gauge value). */
  foregroundColor: string
  /** Gauge stoplight from the status tokens, same rule as <uip-usage-bar>:
   *  < 70% success, 70-89% warning, >= 90% destructive. */
  semanticGaugeThresholds: [number, string][]
}

npm dependencies

Includes

Used by

Files installed (4)

  • src/uip/components/charts/sunburst-chart.ts2.1 kB
    import { ChartElement } from './lib/chart-element'
    
    export interface SunNode {
      name: string
      value?: number
      children?: SunNode[]
    }
    
    /**
     * <uip-sunburst-chart> — the registry SunburstChart (React `SunburstChart`)
     * as a web component. Builds the same ECharts option as React for the same
     * props.
     *
     * Properties (React props): `data` (hierarchical nodes; property or JSON
     * attribute), `height` (default 360), `radius` ([inner, outer] percentages;
     * property or JSON attribute; default ['12%', '90%']), `option` (ECharts
     * escape hatch, merged like React), `aria-label` (React `ariaLabel`).
     * React's `className` → host classes.
     */
    export class UipSunburstChart extends ChartElement {
      static properties = {
        data: { type: Array },
        radius: { type: Array },
        option: { type: Object },
      }
    
      data: SunNode[] = []
      radius: [string, string] = ['12%', '90%']
      option?: any
      protected readonly chartSlot = 'sunburst-chart'
    
      constructor() {
        super()
        this.height = 360
      }
    
      protected buildOption() {
        const theme = this.chartTheme
        const series = [
          {
            type: 'sunburst',
            radius: this.radius,
            data: this.data ?? [],
            label: { rotate: 'radial' as const, fontSize: 11 },
            itemStyle: { borderColor: '#fff', borderWidth: 1 },
            emphasis: { focus: 'ancestor' as const },
          },
        ]
    
        const userOption: any = this.option ?? {}
        const { series: userSeries, ...userRest } = userOption
        const mergedSeries = Array.isArray(userSeries) ? series.map((s, i) => ({ ...s, ...(userSeries[i] ?? {}) })) : series
    
        return {
          color: theme.colors,
          tooltip: {
            trigger: 'item',
            backgroundColor: theme.tooltipBg,
            borderColor: theme.tooltipBorder,
            textStyle: { color: theme.tooltipText, fontSize: 12 },
          },
          series: mergedSeries,
          ...userRest,
        }
      }
    }
    
    customElements.get('uip-sunburst-chart') || customElements.define('uip-sunburst-chart', UipSunburstChart)
    
    declare global {
      interface HTMLElementTagNameMap {
        'uip-sunburst-chart': UipSunburstChart
      }
    }
    
  • src/uip/components/charts/lib/chart-element.ts4.9 kB
  • src/uip/components/charts/lib/chart-theme.ts7.1 kB
  • src/uip/components/charts/lib/echarts.ts1.9 kB

Raw manifest:https://uipkge.dev/r/lit/sunburst-chart.json