D3 force bubble
Guide for creating clustered bubble charts using D3.js force simulations (v6+), including collision and categorization.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill d3-force-bubbleAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
1.2 KB, 286 tokens by cl100k_base, as published. Nobody here has run it
D3.js Force Bubble Chart
This skill covers setting up a D3 force simulation to create a clustered bubble chart.
Setup
You need d3.forceSimulation combined with positioning forces (forceX, forceY) and collision forces (forceCollide).
const simulation = d3.forceSimulation(data)
.force("x", d3.forceX(d => clusterCenters[d.category].x).strength(0.1))
.force("y", d3.forceY(d => clusterCenters[d.category].y).strength(0.1))
.force("collide", d3.forceCollide().radius(d => d.radius + 1).iterations(2))
.on("tick", ticked);
function ticked() {
node
.attr("cx", d => d.x)
.attr("cy", d => d.y);
}
Considerations
- Radius Scaling: Use
d3.scaleSqrt()for sizing bubbles by area (e.g., Market Cap). - Collision: Ensure the radius in
forceCollidematches the visible radius. Add a small buffer (e.g.,+ 1) for visual separation. - Clustering: Calculate centers for each category beforehand, or dynamically adjust
forceX/forceYbased on the category of the node.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.