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 🙏

© 2026 – Pkg Stats / Ryan Hefner

d3-hierarchical-pie-chart

v1.0.4

Published

d3-hierarchical-pie-chart =========================

Readme

d3-hierarchical-pie-chart

d3 library for rendering hierarchical pie chart.

Demo

Usage

This library has no d3 dependencies, instead you have to install d3 dependencies directly via npm or include it in your HTML. The class assumes that d3 dependencies will be injected into the class via the constructor, i.e.:

import HierarchicalPieChart from 'd3-hierarchical-pie-chart'
import * as d3 from 'd3'

const chart = new HierarchicalPieChart(d3, data)
chart.render(document.querySelector("#chart"))

Sample data:

var data = {
  name: "All Orders",
  description: "10 orders",
  value: 10,
  children: [
    {
      name: "Pizza Orders",
      description: "4 orders",
      value: 4,
      children: [],
    },
    {
      name: "Burger Orders",
      description: "6 orders",
      value: 6,
      children: [],
    }
  ],
}

Data type definition:

interface NodeType {
  name: string,
  description: string,
  value: number,
  children: Array<NodeType>,
}

Note that NodeType are recursive, it can contains other NodeType as its children. You can think of NodeType as a tree data structure.

For more examples, see examples/ folder.

Supported d3 versions

This library supports d3 version 3 to version 6.

Advanced Usage

Custom width and height (default 400px x 400px)

const chart = new HierarchicalPieChart(d3, data, { plotWidth: 600, plotHeight: 600})

Custom legend

const legendFn = (d) => {
  const name = d.name || "&nbsp;"
  const description = d.description || "&nbsp;"
  return "<h2>" + name + "</h2><p>" + description + "</p>"
}
// legendPosition can be 'top' or 'bottom'
const chart = new HierarchicalPieChart(d3, data, { legendFn: legendFn, legendPosition: 'top' })

Custom label function (a label is the tooltip that appears when hovering the chart)

const labelFn = (d) => { return d.name + ": " + d.description }
const chart = new HierarchicalPieChart(d3, data, { labelFn: labelFn })

Custom color scheme

const color = d3.scaleOrdinal(d3.schemeCategory10)
const colorFn = (d) => { return color(d.name) }
const chart = new HierarchicalPieChart(d3, data, { colorFn: colorFn })

Credits

The original credit goes to Andreas Dewes for creating this awesome sample http://bl.ocks.org/adewes/4710330. My work includes making the code nicer and more customizable.