| name | reagraph |
| description | Use when building interactive 2D or 3D graph or network visualizations in React with the reagraph library (GraphCanvas, node-link diagrams, force-directed layouts). Covers data shapes (GraphNode, GraphEdge), 16 layout algorithms, selection, lasso, camera controls, sizing strategies, and theming. |
Reagraph
Reagraph is a WebGL-powered graph visualization library for React built on Three.js, React Three Fiber, D3, and Graphology. It renders interactive node-link diagrams in 2D and 3D with force-directed and hierarchical layouts.
Installation
npm install reagraph
Basic Setup
import { GraphCanvas } from 'reagraph';
const nodes = [
{ id: 'n-1', label: 'Node 1' },
{ id: 'n-2', label: 'Node 2' },
{ id: 'n-3', label: 'Node 3' },
];
const edges = [
{ id: 'e-1', source: 'n-1', target: 'n-2', label: 'Edge 1' },
{ id: 'e-2', source: 'n-1', target: 'n-3', label: 'Edge 2' },
];
function App() {
return (
<GraphCanvas nodes={nodes} edges={edges} />
);
}
Data Shapes
GraphNode
interface GraphNode {
id: string;
label?: string;
subLabel?: string;
size?: number;
fill?: string;
icon?: string;
cluster?: string;
parents?: string[];
data?: any;
labelVisible?: boolean;
fx?: number;
fy?: number;
fz?: number;
}
GraphEdge
interface GraphEdge {
id: string;
source: string;
target: string;
label?: string;
subLabel?: string;
size?: number;
fill?: string;
dashed?: boolean;
dashArray?: [number, number];
labelVisible?: boolean;
interpolation?: 'linear' | 'curved';
arrowPlacement?: 'none' | 'mid' | 'end';
subLabelPlacement?: 'below' | 'above';
}
Common Patterns
- Import from barrel: Always
import { Component } from 'reagraph'
- Ref access: Use
ref on GraphCanvas for imperative methods (centerGraph, fitNodesInView, exportCanvas)
- Per-node styling: Set
fill, size, icon directly on GraphNode objects to override theme defaults
- Per-edge styling: Set
fill, dashed, interpolation directly on GraphEdge objects
- 3D layouts: Append
3d suffix to layout names (e.g. forceDirected3d, treeTd3d)
- Sizing strategies: Use
sizingType prop to auto-size nodes by pagerank, centrality, or custom attribute
Component Index
Graph
GraphCanvas, GraphScene
Nodes
Sphere, SphereWithIcon, SphereWithSvg, Svg, Badge, custom NodeRenderer
Edges
Edge, Arrow, self-loops, dashed, curved, edge aggregation
Layout
16 layout algorithms: forceDirected, circular, concentric, tree, radial, hierarchical, nooverlap, forceatlas2, custom
Interaction
useSelection, Lasso, CameraControls, useCenterGraph, RadialMenu, useCollapse
Styling
Theme (light/dark), SizingType (pagerank, centrality, attribute)