D3.force, multiple sets of multiple foci
This example demonstrates a force-directed graph with 100 nodes that can be toggled between two different grouping schemes. Clicking the "groupA" or "groupB" buttons switches the nodes’ attraction toward one of two sets of focal points—five horizontally arranged foci for groupA, or two diagonal foci for groupB—causing the layout to reorganize smoothly. The simulation uses d3.forceSimulation with d3.forceLink, d3.forceManyBody, and d3.forceCenter, while each tick nudges nodes toward their assigned foci based on the current selection. Nodes are rendered as SVG circles colored by groupA, and dragging is enabled via d3.drag.
AI-generated descriptionExample showing how to use multiple sets of multiple foci and toggle between them. Uses d3v4. Based on the answer to this question/answer (v3) on stack overflow and on the canonical force layout by Mike Bostock.