Skip to content
Skills Library
Data & analytics · Building & coding

d3-force-bubble-chart

/d3-force-bubble-chart

Build D3.js v6 force-simulation bubble charts where bubbles are sized by a numeric metric, colored by category, and clustered by category using forceX/forceY. Use this skill whenever the user asks for bubble charts, force-layout visualizations, or clustered circle packing with D3.js. Triggers on: bubble chart, force simulation, cluster layout, circle packing.

Licence
MIT
Last repository change
02.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 02.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Build D3.js v6 force-simulation bubble charts where bubbles are sized by a numeric metric, colored by category, and clustered by category using forceX/forceY. Use this skill whenever the user asks for bubble charts, force-layout visualizations, or clustered circle packing with D3.js. Triggers on: bubble chart, force simulation, cluster layout, circle packing.

Original author description

Build D3.js v6 force-simulation bubble charts where bubbles are sized by a numeric metric, colored by category, and clustered by category using forceX/forceY. Use this skill whenever the user asks for bubble charts, force-layout visualizations, or clustered circle packing with D3.js. Triggers on: bubble chart, force simulation, cluster layout, circle packing.

How it works

  1. Overview
  2. Architecture
  3. Common Pitfalls
Original SKILL.md headings · 95 lines, 393 words
SKILL.md preview
---
name: d3-force-bubble-chart
description: >
  Build D3.js v6 force-simulation bubble charts where bubbles are sized by a numeric metric,
  colored by category, and clustered by category using forceX/forceY. Use this skill whenever
  the user asks for bubble charts, force-layout visualizations, or clustered circle packing
  with D3.js. Triggers on: bubble chart, force simulation, cluster layout, circle packing.
---

# D3 Force Bubble Chart

## Overview

A force-simulation bubble chart uses `d3.forceSimulation` to position circles (bubbles) in a
layout where they are clustered by category, sized by a numeric value, and colored by category.

## Architecture

### Sizing Bubbles

Use `d3.scaleSqrt()` to map a numeric value (e.g., market cap) to bubble radius. Square-root
scaling ensures area is proportional to value, which is perceptually accurate.

```js
const radiusScale = d3.scaleSqrt()
  .domain([0, d3.max(data, d => d.value)])
  .range([minRadius, maxRadius]);
```

For items missing the sizing metric (e.g., ETFs with no market cap), assign a uniform default radius.

### Coloring by Category

Use `d3.scaleOrdinal()` with a color scheme like `d3.schemeTableau10`:

```js
const colorScale = d3.scaleOrdinal()
  .domain(categories)
  .range(d3.schemeTableau10);
```

### Clustering with Force Simulation

Use `forceX` and `forceY` to pull bubbles toward category-specific cluster centers.
Calculate cluster centers by dividing the chart space into a grid or ring layout based on
the number of categories.

```js
// Compute cluster center positions
const sectorCenters = {};
sectors.forEach((sector, i) => {
  const angle = (2 * Math.PI * i) / sectors.length;
  sectorCenters[sector] = {
    x: centerX + clusterRadius * Math.cos(angle),
    y: centerY + clusterRadius * Math.sin(angle)
  };
});

const simulation = d3.forceSimulation(data)
  .force("x", d3.forceX(d => sectorCenters[d.sector].x).strength(0.3))
  .force("y", d3.forceY(d => sectorCenters[d.sector].y).strength(0.3))
  .force("collide", d3.forceCollide(d => radiusScale(d.value) + padding))
  .force("charge", d3.forceManyBody().strength(-5))
  .on("tick", ticked);
```

Key tuning parameters:
- **forceX/forceY strength**: 0.2–0.4 keeps clusters tight without excessive overlap
- **forceCollide padding**: 1–3px between bubbles
- **forceManyBody strength**: Small negative value (-2 to -10) for gentle repulsion

### Labels Inside Bubbles

Add `<text>` elements centered on each bubble. Only show labels when the bubble is large
enough to contain the text (check radius vs. text length).

```js
node.append("text")
  .text(d => d.ticker)
  .attr("text-anchor", "middle")
  .attr("dy", "0.35em")
  .style("font-size", d => Math.min(radiusScale(d.value) * 0.6, 14) + "px");
```

### Tooltips

Use a `<div>` with `position: absolute` that follows the mouse on `mouseover`/`mousemove`
and hides on `mouseout`.

### Legends

Add a legend mapping colors to sector names. Position it in a corner or below the chart.
Use small colored circles/rectangles paired with text labels.

## Common Pitfalls

- Forgetting `forceCollide` causes overlapping bubbles
- Using `forceCenter` with `forceX`/`forceY` creates fighting forces — avoid `forceCenter`
  when using explicit cluster positioning
- Not calling `simulation.stop()` or limiting ticks can cause layout jitter
- Cluster centers too far apart leads to scattered layout — keep `clusterRadius` moderate
  relative to chart width

Versions

RepositoryScoreLicence
This page · cxcscmu/SkillLearnBench100MIT
cxcscmu/SkillLearnBench100MIT
cxcscmu/SkillLearnBench100MIT

Database snapshot: 13.11.2026 · package version 40ddabbb158a (SHA-256 digest of the entire package)

Downloads in the last 30 days: 2 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100d3-bubble-chart
    How to build a D3.js v6 force-directed bubble chart with sector clustering, size encoding, color legends, tooltips, and interactive selection. Use this skill whenever the user wants a bubble chart, force simulation, cluster layout, or interactive SVG circles with D3.
  • 100bubble-chart-generator
    This skill generates interactive Chart.js bubble chart visualizations for priority matrices and multi-dimensional data analysis. Use this skill when users need to create scatter plots with variable bubble sizes, particularly for 2x2 priority matrices (Impact vs Effort, Risk vs…
  • 100scatter-bubble-analysis
    Use when a user wants Codex to inspect a CSV/XLSX file, generate legacy scatter and bubble charts, small multiples, and relationship/outlier source data.
  • 100mparanza-scatter-bubble-analysis
    Use when a user wants Claude to inspect a CSV/XLSX file, generate legacy scatter and bubble charts, small multiples, and relationship/outlier source data.
  • 90build-interactive-data-table-with-bubble-sync
    Use when building an HTML data table that syncs highlighting with a D3 bubble chart on click interactions in both directions.
  • 100d3
    Assists with building custom interactive data visualizations using D3.js. Use when creating charts, graphs, maps, force layouts, or hierarchical diagrams that require fine-grained control beyond what charting libraries provide. Trigger words: d3, data visualization, chart, svg,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.