Network Graph for React
A force-directed React network graph shows who is connected to whom, laid out by a simulation written in the component. Pass nodes (an id, with an optional group and value) and links (a source and a target id).
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/network-graph.jsonService dependencies
NetworkGraphNetworkTabledefaultNetworkGraphLabels- +1 more
Service dependency map
Hover a service to light up what it talks to; drag it and the rest of the graph follows, then settles. Ctrl or ⌘ + scroll, a pinch or the buttons zoom; drag the background to pan. Remove the search services: the rest glide to their new places. Node size is the service's traffic.
Service dependencies
Production, calls in the last hour
- Edge
- Core services
- Data stores
- Third party
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
import { NetworkGraph } from "@/components/sheenui/charts/network-graph";
import { type NetworkGroup, type NetworkNode, type NetworkLink } from "@/components/sheenui/charts/network-graph/model";
import { NetworkTable } from "@/components/sheenui/charts/network-graph/table";
import { networkLegend } from "@/components/sheenui/charts/network-graph/types";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, networkLegend, NetworkTable, NetworkGraph, type NetworkGroup, type NetworkNode, type NetworkLink } from "@sheenui/theme";
const groups: NetworkGroup[] = [
{ id: "edge", label: "Edge", color: 7 },
{ id: "core", label: "Core services", color: 1 },
{ id: "data", label: "Data stores", color: 3 },
{ id: "external", label: "Third party", color: 2 },
];
const nodes: NetworkNode[] = [
{ id: "gateway", label: "API gateway", group: "edge", value: 14 },
{ id: "auth", label: "Auth", group: "core", value: 12 },
{ id: "pg", label: "Postgres", group: "data", value: 13 },
// ...
];
const links: NetworkLink[] = [
{ source: "gateway", target: "auth" },
{ source: "auth", target: "redis" },
// ...
];
<ChartCard
title="Service dependencies"
legend={networkLegend(groups)}
table={<NetworkTable nodes={nodes} links={links} groups={groups} caption="Every service and what it calls" />}
>
<NetworkGraph nodes={nodes} links={links} groups={groups} aria-label="Dependencies between production services" />
</ChartCard>Collaboration network, weighted ties
Forty people in five teams; a tie's weight is how often two people worked together, and it sets the line's thickness. Names are printed only where they fit without colliding; zoom in and more appear.
Collaboration
Shared projects this quarter
- Product
- Design
- Engineering
- Data
- Operations
import { NetworkGraph } from "@/components/sheenui/charts/network-graph";
import { type NetworkGroup, type NetworkLink, type NetworkNode } from "@/components/sheenui/charts/network-graph/model";
// Package build (after the first npm release, or a packed tarball): import { NetworkGraph, type NetworkGroup, type NetworkLink, type NetworkNode } from "@sheenui/theme";
const teams: NetworkGroup[] = [
{ id: "product", label: "Product", color: 1 },
{ id: "design", label: "Design", color: 5 },
{ id: "eng", label: "Engineering", color: 3 },
{ id: "data", label: "Data", color: 4 },
{ id: "ops", label: "Operations", color: 7 },
];
const people: NetworkNode[] = [
{ id: "Ada", group: "product" },
{ id: "Ben", group: "design" },
{ id: "Cleo", group: "eng" },
{ id: "Dev", group: "data" },
{ id: "Eli", group: "ops" },
{ id: "Fay", group: "product" },
{ id: "Gus", group: "design" },
{ id: "Hana", group: "eng" },
];
// value: how often two people worked together; it sets the line's thickness
const ties: NetworkLink[] = [
{ source: "Ada", target: "Fay", value: 6 },
{ source: "Ben", target: "Gus", value: 4 },
{ source: "Cleo", target: "Hana", value: 8 },
{ source: "Ada", target: "Ben", value: 2 },
{ source: "Cleo", target: "Dev", value: 3 },
{ source: "Dev", target: "Eli", value: 5 },
{ source: "Fay", target: "Hana", value: 1 },
];
export function Example() {
return (
<NetworkGraph
nodes={people}
links={ties}
groups={teams}
height={460}
forces={{ charge: -140, linkDistance: 30 }}
aria-label="Who worked with whom this quarter, across five teams"
/>
);
}Files to copy
13 folders · 29 files · 4 packages
- From
theme/src/ components/charts/{network-graph.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-tip.tsx, chart-utils.ts, flow-utils.tsx, heatmap.tsx}components/charts/chart-parts/components/charts/heatmap/components/charts/network-graph/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/status-icons/hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-media-query.ts, use-preferences.ts, use-resolved-scheme.ts}motion/tokens.tslib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/network-graph.jsonRegistry item: network-graph. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Props
NetworkGraphLabels keys and English defaults (10)
NetworkTable props
Keyboard
Accessibility
- The graph is one focusable figure with the role description “network graph”; a node is announced with its group, its connections and up to eight neighbor names.
- The Table view (NetworkTable) is the keyboard list of every node and who it connects to.
- Zoom buttons are real buttons (44px on touch). A plain scroll never hijacks the page: zoom needs Ctrl/⌘, a pinch or the buttons; one finger on the background still scrolls.
- Every moving frame (layout, entrance, drag, pan, zoom) is written straight to the SVG, so the page stays smooth while you drag on a phone.
- Reduced motion: the precomputed layout appears in place, and dragging moves only that node.
All exports on this page
NetworkGraph— Who is connected to whom: services and their dependencies, people who work together, linked pages.NetworkTable— Every node with its group, its number of connections and who it connects to.defaultNetworkGraphLabels— The built-in English strings of NetworkGraph; spread it into your own labels and change what you need.
When to use the network graph
- Use it as a node graph to map service dependencies, where each node is a microservice sized by traffic and a link shows that two services are connected (links are undirected), so you can see which service everything depends on.
- It fits a collaboration or org network, such as forty people in five teams, with link value as how often two people worked together and group colors showing the team.
- It also works for a site's internal link structure or a social graph, where clusters and bridge nodes matter more than precise numbers, and where a user can click a node to open details.
- Skip it when the connections have direction and quantity that must be compared; a Sankey diagram handles weighted flows, and ChordDiagram suits a dense matrix of relationships between a few groups.
- Pair it with ChartCard for the legend and Chart / Table tabs, NetworkTable as the text twin listing each node's connections, and onNodeClick to open a detail Drawer.
Frequently asked questions
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .