Single Axis Force Layout
This example shows a force-directed graph of character co-occurrences in Victor Hugo’s *Les Misérables*, constrained to a single horizontal axis. The nodes are rendered as small circles and links as gray lines, using D3 v4’s force simulation with d3-drag for interactivity. When a node is dragged, it becomes fixed to the pointer and the simulation’s alpha target is temporarily increased to heat up the layout; releasing the node lets it settle back. The distinctive single-axis effect is achieved by resetting every node’s y-coordinate to a fixed value (200) on each tick, so all movement occurs along the x-axis only. Dragging can still move a node vertically, but it springs back to the shared baseline. This example uses SVG and the miserables dataset.
AI-generated descriptionThis example demonstrates applying d3-drag to a force-directed graph computed using d3-force. When the drag gesture starts, the targetted node is fixed to the pointer; it is released when the gesture ends. In addition, the simulation is temporarily “heated” during interaction by setting the target alpha to a non-zero value.
If desired, you could refine this technique by also fixing nodes on mouseover, and releasing them on mouseout. (However, if there’s an active drag gesture during mouseout, you wouldn’t want to release the node until the gesture finishes.)
Compare to the Canvas version.
forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/2675ff61ea5e063ede2b5d63c08020c7'>Force Dragging I</a>
forked from <a href='http://bl.ocks.org/akollegger/'>akollegger</a>'s block: <a href='http://bl.ocks.org/akollegger/54c4be03e148c625217df1984e1c3908'>Force Dragging I</a>
forked from <a href='http://bl.ocks.org/akollegger/'>akollegger</a>'s block: <a href='http://bl.ocks.org/akollegger/4cc1ef18bda1281613d7793692963b45'>Single Axis Force Layout</a>