Bounded Force Layout
The visualization shows a bounded force-directed graph of the character co-occurrence network from *Les Misérables*, with nodes restricted to stay within the rectangular SVG canvas. The code leverages the custom `d3.layout.force` API from D3 v3 to simulate the physics, while the `tick` callback clamps each node's `cx` and `cy` attributes to the range `[radius, width - radius]` and `[radius, height - radius]`. The graph reads from a `graph.json` file, and the force simulation is driven by `force.drag` for user interaction.
AI-generated descriptionThis D3 example shows how to constrain the position of nodes within the rectangular bounds of the containing SVG element. As a side-effect of updating the node's cx and cy attributes, we update the node positions to be within the range [radius, width - radius] for x, [radius, height - radius] for y. If you prefer, you could use the each operator to do this as a separate step, rather than as a side-effect of setting attributes.
forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/1129492'>Bounded Force Layout</a>