Interaction Is a Feedback Loop
A static visualization becomes a system when a reader can act on it and see a coherent change. D3's interaction modules make that change possible through browser events, behavior objects, transitions, timers, and rendering updates. This chapter follows the full loop—event, state change, recomputation, rendering—and separates what brush, drag, zoom, and animation behaviors do from the application decisions they cannot make. The result is a practical way to read interactive D3 work without treating a callback as magic.
Interaction does not directly “change the picture.” An input event reaches a behavior, the behavior exposes or changes interaction state, the application decides what that state means, and some part of the visual pipeline is recomputed and rendered. If one link is missing, the user may receive an event without seeing a useful response, or may see a response whose meaning is unclear.
An event becomes a state change
D3 selection events connect browser input to selected elements. Pointer utilities can translate an event into coordinates, and custom dispatch can separate concerns through named callbacks. These mechanisms provide routes for information to move. They do not define the application's state model. A pointer coordinate might identify a mark, a location inside a plot, or a position in a separate overlay; the application must decide which interpretation applies.
The feedback loop can be represented as a small lifecycle. The view begins idle. An input event starts a gesture or request. A brush, drag, or zoom behavior becomes active and exposes the information needed to compute a response. The application changes state or selects a new view. Scales, selections, shapes, layouts, or other computations use that state, and the renderer displays the update. When the gesture ends, the system returns to a stable view—or remains active if the input continues.
The state diagram is intentionally broader than one API. A brush can change the subset of data being considered. A drag can change a subject's position or a node's fixed state. A zoom can change the view through which marks are inspected. The resulting action may require a new selection, a changed scale domain, a force simulation update, or only a redraw. D3 supplies behavior mechanisms for these cases; the application owns the decision about which stage responds.
This division creates clear success and failure conditions. A successful interaction has a recognized input, a behavior that accepts or filters it, a state change that the application understands, and a rendering path that reads the new state. If the event reaches a listener but the state is never changed, the view stays still. If state changes but the scale or layout does not read it, the response is invisible. If the view changes but no label or mark communicates why, the interaction may be technically active but semantically weak.