A tiny but complete example of rendering data structures interactively. A graph is stored as an adjacency list (each node maps to its neighbours), drawn with SVG, and made interactive with a single piece of state: which node is selected. Click a node below to light up its neighbours.
The whole graph is just an object mapping each node id to an array of the nodes it connects to. Looking up a node’s neighbours is an O(1) object access — no scanning required. A separate positions map says where to draw each node, keeping structure separate from layout.
We store only one thing: selected. The set of highlighted neighbours and every node’s colour are derived from it during render. There is no second “highlighted” array to keep in sync — a key habit for bug-free UI: store the minimum, compute the rest.
Edges are <line> elements and nodes are <circle> elements, mapped straight from the data. Each undirected edge is drawn once (by only drawing when a < b), and an onClick on each circle updates the selection, which re-renders the colours.