• Stars
    star
    273
  • Rank 147,615 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A sunburst interactive chart web component for visualizing hierarchical data

Sunburst Chart

NPM package Build Size NPM Downloads

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.

See also the Icicle, Circle Pack and Treemap charts.

Quick start

import Sunburst from 'sunburst-chart';

or using a script tag

<script src="//unpkg.com/sunburst-chart"></script>

then

const myChart = Sunburst();
myChart
  .data(<myData>)
  (<myDOMElement>);

API reference

Method Description Default
data([object]) Getter/setter for chart data (see below for syntax details).
width([number]) Getter/setter for the chart width in px. <window width>
height([number]) Getter/setter for the chart height in px. <window height>
children([string or fn]) Getter/setter for a 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. children
label([string or fn]) Getter/setter for a node object label accessor, used to display labels on the arcs and their tooltips. name
size([string or fn]) Getter/setter for a node object size accessor, used to compute the angles of the arcs. value
color([string or fn]) Getter/setter for a node object color accessor, used to color fill the arcs. grey
strokeColor([string or fn]) Getter/setter for a node object stroke color accessor, used to color the contour of the arcs. white
nodeClassName([string or fn]) Getter/setter for a node object classname accessor. Determines the CSS class(es) to apply to each slice node. -
minSliceAngle([number]) Getter/setter for the minimum angle of an arc (in degrees) required for it to be rendered in the DOM. 0.2
maxLevels([number]) Getter/setter for the maximum number of layers to show at any given time. -
excludeRoot([boolean]) Getter/setter for whether to exclude the root node from the top level representation, to maximize the available radial space. false
centerRadius([number]) Getter/setter for the relative radius of the center circle. The value should be proportional to the whole chart radius. Only values between <0, 1> are permitted. 0.1
radiusScaleExponent([number]) Getter/setter for the 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. 0.5
sort([fn]) Getter/setter for the 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. <existing order>
showLabels([boolean]) Getter/setter for whether to show labels in the arcs. Regardless of this setting, labels too large to fit within an arc's boundaries are automatically hidden. true
labelOrientation([angular, radial or auto]) Getter/setter for the 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. auto
handleNonFittingLabel([fn(label, availablePx, node)]) Getter/setter for 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([fn]) Getter/setter to 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. () => true
tooltipTitle([fn]) Getter/setter for a 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([fn]) Getter/setter for a 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.
focusOnNode([object]) Getter/setter for 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.
onHover([fn]) 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([fn]) 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 myChart.onClick(myChart.focusOnNode).
transitionDuration([number]) Getter/setter for the animation duration of transitions between states (opening, zoom in/out) in milliseconds. Enter 0 to disable animations. 750

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 ☕!

More Repositories

1

3d-force-graph

3D force-directed graph component using ThreeJS/WebGL
HTML
4,252
star
2

react-force-graph

React component for 2D, 3D, VR and AR force directed graphs
HTML
1,861
star
3

globe.gl

UI component for Globe Data Visualization using ThreeJS/WebGL
HTML
1,809
star
4

force-graph

Force-directed graph rendered on HTML5 canvas
JavaScript
1,409
star
5

three-globe

WebGL Globe Data Visualization as a ThreeJS reusable 3D object
JavaScript
1,071
star
6

react-globe.gl

React component for Globe Data Visualization using ThreeJS/WebGL
HTML
775
star
7

timelines-chart

Timelines Chart
JavaScript
527
star
8

three-spritetext

A sprite based text component for ThreeJS
JavaScript
306
star
9

three-forcegraph

Force-directed graph as a ThreeJS 3d object
JavaScript
219
star
10

3d-force-graph-vr

3D force-directed graph component in VR
HTML
208
star
11

d3-force-registry

A curated compilation of plugins and all-things related to d3-force
133
star
12

3d-force-graph-ar

3D force-directed graph component in AR
HTML
87
star
13

aframe-forcegraph-component

Force-directed graph component for A-Frame
JavaScript
77
star
14

three-fatline

A ThreeJS Line object with variable width
JavaScript
68
star
15

circlepack-chart

A circle packing interactive chart web component for visualizing hierarchical data
JavaScript
55
star
16

kapsule

Kapsule - A closure based Web Component library
JavaScript
54
star
17

treemap-chart

A treemap interactive chart web component for visualizing hierarchical data
JavaScript
54
star
18

three-geojson-geometry

ThreeJS geometry to stroke GeoJSON objects on a sphere
JavaScript
52
star
19

globe-ar

3D Globe data visualization component in AR
HTML
51
star
20

three-render-objects

Easy way to render ThreeJS objects with built-in interaction defaults
JavaScript
45
star
21

horizon-timeseries-chart

A chart to represent time-series data using multiple vertically layered horizon area plots
JavaScript
44
star
22

three-conic-polygon-geometry

ThreeJS geometry for drawing polygons on a sphere
JavaScript
36
star
23

canvas-color-tracker

A utility to track objects on a canvas by unique px color
HTML
34
star
24

icicle-chart

A partition / icicle interactive chart web component for visualizing hierarchical data
JavaScript
33
star
25

d3-geo-zoom

Zoom and pan D3 geo projections
JavaScript
30
star
26

aframe-globe-component

3D Globe data visualization component for A-Frame
JavaScript
30
star
27

d3-force-magnetic

A natural attraction/repulsion force type for the d3-force simulation engine
JavaScript
27
star
28

hilbert-chart

Hilbert space-filling curve chart
JavaScript
27
star
29

d3-radial-axis

A radial implementation of the D3 axis component
JavaScript
25
star
30

ip.js

A JS library for manipulating IP addresses, prefixes and ranges
JavaScript
23
star
31

d3-hilbert

D3 layout to visualize distance variables using a continuous Hilbert space-filling curve.
JavaScript
22
star
32

d3-force-surface

A multi-surface elastic collision force type for the d3-force simulation engine
JavaScript
21
star
33

cartogram-chart

A cartogram chart web component for visualizing geographical data by distorting a TopoJson topology
JavaScript
19
star
34

d3-force-bounce

An elastic collision force type for the d3-force simulation engine
JavaScript
16
star
35

d3-morton-order

D3 layout to visualize distance variables using a continuous Morton (Z-order) space-filling curve.
JavaScript
11
star
36

d3-force-cluster-3d

A clustering force type for the d3-force-3d simulation engine
JavaScript
10
star
37

d3-binarytree

One-dimensional recursive spatial subdivision.
JavaScript
9
star
38

d3-horizon

Horizon area chart D3 component
JavaScript
8
star
39

proportions-chart

A one-dimensional proportional chart web component for visualizing categorical data
JavaScript
8
star
40

d3-force-limit

A positioning hard limit force type for the d3-force simulation engine
JavaScript
8
star
41

index-array-by

A utility function to index arrays by any criteria
JavaScript
8
star
42

react-kapsule

React wrapper for kapsule-style web components
JavaScript
8
star
43

multilateration

Locate points according to distributed beacon signals with consistent propagation speeds
JavaScript
6
star
44

data-joint

Perform data joins with any type of JS objects
JavaScript
6
star
45

Intermap

Internet Interactive Map
JavaScript
6
star
46

d3-zoomable

Easy way to apply d3-zoom functionality to DOM elements
JavaScript
6
star
47

d3-force-pod

Component to automatically draw nodes/links in a D3 force simulation according to a set of forces
JavaScript
5
star
48

accessor-fn

A wrapper function for object accessor properties
JavaScript
5
star
49

d3-color-legend

SVG color legends for continuous or discrete D3 scales
JavaScript
3
star
50

d3-force-constant

A constant acceleration force type for the d3-force simulation engine
JavaScript
3
star
51

svg-text-fit

SVG utility for fitting text inside a box by resizing or ellipsis
JavaScript
3
star
52

jerrypick

Pluck and omit properties from a JS object
JavaScript
3
star
53

ui-module

Template repo for UI modules
JavaScript
2
star
54

three-trackballcontrols-web

A browser friendly wrapper of https://github.com/JonLim/three-trackballcontrols
JavaScript
2
star
55

svg-utils

Miscellaneous utility components for manipulating SVG
JavaScript
2
star
56

forcelayout3d-web

A browser friendly wrapper of https://github.com/anvaka/ngraph.forcelayout3d
JavaScript
1
star
57

js-module

Template repo for JS modules
JavaScript
1
star
58

ris-live-viz

A quick RIS live viz prototype
JavaScript
1
star
59

flatten

Recursively flatten nested arrays with arbitrary levels
JavaScript
1
star
60

scroll-zoom-clamp

Prevent page scrolling interference by zooming components
JavaScript
1
star