Graph

Force-directed node/edge graph with draggable nodes, pan/zoom, hover-highlighting, and keyboard navigation.

Installation

npx dafink-ui add graph

Requires: d3-force, @types/d3-force

Demo

Props

NameTypeDefaultDescription
nodesGraphNode[]-Required. Array of { id, label, group? } objects.
edgesGraphEdge[]-Required. Array of { source, target } objects referencing node ids.
widthnumber600SVG width in pixels.
heightnumber400SVG height in pixels.
classNamestring""Additional classes on the root wrapper div.
onNodeSelect(node: GraphNode) => void-Called when a node is selected via click or keyboard Enter/Space.

Accessibility

Graph uses roving tabindex over a listbox: the SVG root is a single Tab stop (role="application"), and only the selected node (role="option" inside a role="listbox") carries tabIndex=0, with every other node at tabIndex=-1. Node/edge dragging, panning, and mouse-wheel zoom are pointer-only, with no keyboard equivalent for dragging or panning specifically; a hidden aria-live="polite" status region announces the initial node/edge count and every selection change.

KeyFunction
tabMoves focus into the graph container.
right arrowMoves selection to the next node, wrapping from the last node to the first.
down arrowMoves selection to the next node, wrapping from the last node to the first.
left arrowMoves selection to the previous node, wrapping from the first node to the last.
up arrowMoves selection to the previous node, wrapping from the first node to the last.
enterSelects the focused node and fires onNodeSelect.
spaceSelects the focused node and fires onNodeSelect.
escapeClears the selection and returns focus to the graph container.
+Zooms in.
-Zooms out.
0Resets zoom and pan.