npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-sunburst-chart

v1.0.1

Published

A sunburst interactive chart React component for visualizing hierarchical data

Readme

React Sunburst Chart

NPM package Build Size NPM Downloads

React bindings for the sunburst-chart UI component.

A React component of an interactive sunburst chart for representing hierarchical data, where each data node of a tree is represented by an annular segment within multi-layered rings.

Clicking on an arc focuses the view on the associated sub-tree, enabling a gradual exploration of the data. Clicking in the chart's center zooms out one level, while clicking on the canvas resets the zoom level to the root view. The chart also responds to data changes by animating the arcs of each of the nodes into their new positions.

By default the arcs areas are linearly proportional to their data values, resulting in a decrease of the thickness of the outer layers in a quadratic fashion. This can however be customized using the radiusScaleExponent method.

For improved performance, arcs smaller than a given threshold (minSliceAngle) are excluded from the DOM, allowing for representation of large data sets while maintaining a smooth interaction. See here for an example of a randomly generated large data structure.

Quick start

import Sunburst from 'react-sunburst-chart';

or using a script tag

<script src="//cdn.jsdelivr.net/npm/react-sunburst-chart"></script>

then

ReactDOM.render(
  <Sunburst
    data={myData}
  />, 
  myDOMElement
);

API reference

Props

| Prop | Type | Default | Description | | --- | :--: | :--: | --- | | data | object | - | Chart data (see below for syntax details). | | width | number | <window width> | Chart width in px. | | height | number | <window height> | Chart height in px. | | children | string or func | children | Data node's children accessor, used to establish the hierarchical relationship between nodes. Supports either a string indicating the object's property name, or a function(node) which should return an array of nodes. | | label | string or func | name | Node object label accessor, used to display labels on the arcs and their tooltips. | | size | string or func | value | Node object size accessor, used to compute the angles of the arcs. | | color | string or func | grey | Node object color accessor, used to color fill the arcs. | | strokeColor | string or func | white | Node object stroke color accessor, used to color the contour of the arcs. | | nodeClassName | string or func | - | Node object classname accessor. Determines the CSS class(es) to apply to each slice node. | | minSliceAngle | number | 0.2 | Minimum angle of an arc (in degrees) required for it to be rendered in the DOM. | | maxLevels | number | - | Maximum number of layers to show at any given time. | | excludeRoot | bool | false | Whether to exclude the root node from the top level representation, to maximize the available radial space. | | centerRadius | number | 0.1 | Relative radius of the center circle. The value should be proportional to the whole chart radius. Only values between <0, 1> are permitted. | | radiusScaleExponent | number | 0.5 | Exponent of the power scale used to calculate the thickness of the multi-layered rings. The default is 0.5 (square-root) which ensures the area of every segment remains proportional to their value, by decreasing the radius outwards in a quadratic fashion. For a linear scale, use 1. Negatives values are not permitted. | | sort | func | <existing order> | Compare method used to sort sibling arcs. A value of null (default) maintains the existing order found in the input data structure. This method is equivalent to d3-hierarchy's sort, it receives two arguments representing two sibling arcs and expects a numeric return value (-1, 0 or 1) indicating the order. Each element is an instance of d3-hierarchy node and has several useful properties to specify order: data (the corresponding data object), value (summed value of node and all its descendants) and depth (layer degree). For example, to order arcs by angular size, use: (a, b) => b.value - a.value. | | showLabels | bool | true | Whether to show labels in the arcs. Regardless of this setting, labels too large to fit within an arc's boundaries are automatically hidden. | | labelOrientation | angular, radial or auto | auto | Orientation of the labels. angular positions curved labels along the arc perimeter. radial will orient labels along the radial axis, centered on the arc's centroid. The auto mode will pick whichever of the two methods that allows the label to fit inside the arc's boundaries. If both modes fit, the method that keeps the text most horizontal is selected. | | handleNonFittingLabel | fn(label, availablePx, node) | - | How to handle labels that are too large to fit in their designated space. Expects a function that receives as arguments the label, the available space (in px) and the corresponding node object. This function should return a string to be rendered instead, or a falsy value indicating the label should be hidden (default). See here for a label truncation example. | | showTooltip | func | () => true | Specify a node object tooltip's visibility. If this function returns false for a particular node, that node's tooltip will not display at all. If unspecified, all nodes' tooltips will display. | | tooltipTitle | func | | Node object tooltip title. The function should return a string to be displayed in bold in the first line of the tooltip. If unspecified, the full hierarchical name will be displayed. | | tooltipContent | func | | Node object tooltip content. Use this to specify extra content in each of the arc's tooltips in addition to the title set in tooltipTitle. | | onHover | func | | Callback function for mouse hover events. The data node object (or null if hovering on background) and the event object are included as arguments onHover(node, event). | | onClick | func | | Callback function for click events. The data node object (or null if clicking on background) and the event object are included as arguments onClick(node, event). A falsy value (default) automatically focuses on clicked nodes, equivalent to onClick={chartRef.current.focusOnNode}. | | onRightClick | func | | Callback function for right-click events. The data node object (or null if right-clicking on background) and the event object are included as arguments onRightClick(node, event). A falsy value (default) will fallback to the default browser behaviour, which is to open the context menu. | | transitionDuration | number | 750 | Animation duration of transitions between states (opening, zoom in/out) in milliseconds. Enter 0 to disable animations. |

Component Methods

| Method | Arguments | Description | | --- | :--: | --- | | focusOnNode | [object] | The data node to focus the chart on. Use this method to retrieve the current node in focus, or to programmatically zoom the chart to a particular node. |

Data syntax

{
  name: "root",
  children: [
    {
      name: "leafA",
      value: 3
    },
    {
      name: "nodeB",
      children: [
        {
          name: "leafBA",
          value: 5
        },
        {
          name: "leafBB",
          value: 1
        }
      ]
    }
  ]
}

Giving Back

paypal If this project has helped you and you'd like to contribute back, you can always buy me a ☕!