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-graph-react

v1.3.1

Published

<p align="center"> <img src="https://raw.githubusercontent.com/somebodyawesome-dev/d3-graph-react/main/site/static/img/logo.png" width="128" alt="d3-graph-react logo" /> </p>

Readme

d3-graph-react wraps the power of d3-force in a fully typed React component. Describe your network as plain data, render nodes and links as ordinary React components, and let the simulation handle the physics — drag, zoom and pan included, without writing a single line of D3.

📚 Documentation & live playground →

Why?

D3 and React both want to own the DOM. d3-graph-react draws a clean line between the two: D3 computes (force simulation, drag physics, zoom transforms) and React renders (every node and link is a component you control).

  • ⚛️ Nodes are just React components — render avatars, cards, badges, anything.
  • 🖱️ Drag, zoom & pan built in — no event wiring, touch supported.
  • 🧲 Tunable physics — link, charge and gravity forces as simple props.
  • 🌊 Ambient motion — keep the graph gently floating with one prop.
  • 🛠️ Escape hatch to raw D3 — grab the simulation via onSimulationCreated.
  • 🦺 TypeScript-first — generic over your node and link data.

Installation

npm install d3-graph-react

All D3 dependencies are bundled. Requires react and react-dom ^18.2.

Quick start

import { Graph } from "d3-graph-react";

const team = {
  nodes: [
    { id: 1, name: "Ava" },
    { id: 2, name: "Liam" },
    { id: 3, name: "Mia" },
  ],
  links: [
    { source: 0, target: 1 }, // indices into the nodes array, not ids
    { source: 0, target: 2 },
  ],
};

export const TeamGraph = () => (
  <div style={{ height: 500, display: "flex" }}>
    <Graph
      graph={team}
      chargeForce={{ strength: -250 }}
      linkForce={{ length: 130, strength: 1 }}
      gravityForce={{ strength: 0.06, center_x: 250, center_y: 250 }}
      NodeComponent={({ node }) => <strong>{node.name}</strong>}
    />
  </div>
);

[!TIP] Forces are opt-in: a force is only added to the simulation when you pass its prop. Starting with the charge + link + gravity trio above gives a good layout for almost any graph.

Props

| Prop | Type | Default | Description | | ---- | ---- | ------- | ----------- | | graph | { nodes, links } | required | Graph data. Links reference nodes by array index. | | NodeComponent | FC<{ node }> | built-in box | Custom node renderer — receives your node data, fully typed. | | LinkComponent | FC<{ link, sourceNode, targetNode, … }> | built-in line | Custom link renderer with both endpoints' positions and DOM refs. | | zoomScale | [number, number] | [0.5, 8] | Min/max zoom factor. | | onZoom | (event) => void | — | Called on every zoom/pan gesture with the d3 zoom event. | | linkForce | { strength, length } | off | Spring force pulling linked nodes to a target distance. | | gravityForce | { strength, center_x, center_y } | off | Pulls the graph toward a center point. | | chargeForce | { strength } | off | Node repulsion (negative) or attraction (positive). | | isNodeDraggable | boolean | true | Enables drag-and-drop on nodes. | | ambientAlphaTarget | number | 0 | Keeps the simulation gently floating instead of settling (0.02–0.1 works well; costs permanent CPU). | | onSimulationCreated | (simulation) => void | — | Called once per simulation instance with the raw d3-force simulation. | | containerId / containerClassName / svgClassName | string | — | Styling hooks for the container div and svg. |

The simulation settles to rest after animating and automatically reheats when you drag a node or change a force prop.

Full reference with live, interactive examples for every prop: API documentation

License

MIT © somebodyawesome-dev