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

d3-force-bubble-chart

/d3-force-bubble-chart

Create sector-clustered bubble charts with D3.js force simulation. Use this skill when building bubble charts that need to cluster elements by category (sectors, regions, types), avoid overlap, size bubbles by numeric values, and organize clusters spatially. Common patterns include market analysis dashboards, portfolio visualizations, and categorical bubble charts with dynamic clustering.

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

Create sector-clustered bubble charts with D3.js force simulation. Use this skill when building bubble charts that need to cluster elements by category (sectors, regions, types), avoid overlap, size bubbles by numeric values, and organize clusters spatially. Common patterns include market analysis dashboards, portfolio visualizations, and categorical bubble charts with dynamic clustering.

Original author description

Create sector-clustered bubble charts with D3.js force simulation. Use this skill when building bubble charts that need to cluster elements by category (sectors, regions, types), avoid overlap, size bubbles by numeric values, and organize clusters spatially. Common patterns include market analysis dashboards, portfolio visualizations, and categorical bubble charts with dynamic clustering.

How it works

  1. Key Components
  2. Performance Tips
  3. Testing Checklist
Original SKILL.md headings · 139 lines, 498 words
SKILL.md preview
---
name: d3-force-bubble-chart
description: Create sector-clustered bubble charts with D3.js force simulation. Use this skill when building bubble charts that need to cluster elements by category (sectors, regions, types), avoid overlap, size bubbles by numeric values, and organize clusters spatially. Common patterns include market analysis dashboards, portfolio visualizations, and categorical bubble charts with dynamic clustering.
---

# D3.js Force Simulation Bubble Chart

This skill covers how to build interactive, clustered bubble charts using D3 v6 force simulation.

## Key Components

### 1. Force Simulation Setup

Create a force simulation that organizes bubbles into sector clusters:

```javascript
const simulation = d3.forceSimulation(data)
  .force("x", d3.forceX()
    .strength(0.05)
    .x(d => xPositionBySector(d.sector)))
  .force("y", d3.forceY()
    .strength(0.05)
    .y(d => yPositionBySector(d.sector)))
  .force("collide", d3.forceCollide()
    .radius(d => d.radius + 2))
  .force("charge", d3.forceManyBody().strength(-30))
  .on("tick", updatePositions);
```

**Why these forces:**
- **forceX/forceY**: Pull bubbles toward sector-specific positions, creating clusters
- **forceCollide**: Prevents bubble overlap by pushing circles apart when they collide
- **forceManyBody**: Adds repulsion to prevent tight clustering (negative strength = repulsion)

### 2. Sector Clustering Strategy

Define center positions for each sector. Common approaches:

**Grid layout (simple, predictable):**
```javascript
function getSectorPosition(sector, sectors) {
  const index = sectors.indexOf(sector);
  const cols = Math.ceil(Math.sqrt(sectors.length));
  const x = (index % cols) * (width / cols) + width / (cols * 2);
  const y = Math.floor(index / cols) * (height / 2) + height / 4;
  return {x, y};
}
```

**Circle layout (more compact):**
```javascript
function getSectorPosition(sector, sectors) {
  const index = sectors.indexOf(sector);
  const angle = (index / sectors.length) * 2 * Math.PI;
  const radius = 150;
  return {
    x: width / 2 + radius * Math.cos(angle),
    y: height / 2 + radius * Math.sin(angle)
  };
}
```

### 3. Bubble Sizing

Size bubbles proportionally to numeric values (market cap):

```javascript
const radiusScale = d3.scaleSqrt()
  .domain([0, d3.max(data, d => d.marketCap || 0)])
  .range([3, 40]);

data.forEach(d => {
  d.radius = d.marketCap ? radiusScale(d.marketCap) : 20; // Default for ETFs
});
```

**Why `scaleSqrt`:** Area scales linearly with value (perceived area = value)

### 4. Color by Sector

```javascript
const colorScale = d3.scaleOrdinal()
  .domain(sectors)
  .range(d3.schemeSet2); // or d3.schemeCategory10, etc.
```

### 5. Labels Inside Bubbles

Ensure text remains readable inside bubbles:

```javascript
svg.selectAll("text")
  .attr("x", d => d.x)
  .attr("y", d => d.y)
  .attr("text-anchor", "middle")
  .attr("dy", "0.3em")
  .attr("font-size", d => Math.max(10, d.radius * 0.4) + "px")
  .attr("pointer-events", "none")
  .text(d => d.ticker);
```

### 6. Handling Missing Data

For ETFs (no market cap):
- Set to default radius: `d.radius = 20`
- Still cluster by sector
- Don't exclude from visualization
- Optionally use different styling (stroke, opacity) to indicate missing data

### 7. Hover Tooltips

```javascript
circles.on("mouseover", function(event, d) {
  if (!d.marketCap) return; // Skip ETFs

  const tooltip = d3.select("body").append("div")
    .attr("class", "tooltip")
    .html(`<strong>${d.ticker}</strong><br/>${d.name}<br/>${d.sector}`);

  tooltip
    .style("left", (event.pageX + 10) + "px")
    .style("top", (event.pageY - 28) + "px");
})
.on("mouseout", function() {
  d3.selectAll(".tooltip").remove();
});
```

## Performance Tips

- Use `simulation.alpha(0)` after manual positioning to skip initial layout
- Limit to 100-200 nodes for smooth animations; beyond that, optimize with quadtrees
- Cache radius calculations instead of computing in loops

## Testing Checklist

- [ ] Bubbles cluster by sector visually
- [ ] No overlapping bubbles (forceCollide working)
- [ ] Bubbles sized proportionally to market cap
- [ ] Text labels fit inside bubbles
- [ ] ETFs sized uniformly, no tooltips shown
- [ ] Sector colors distinct and consistent with legend

Versions

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

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

Downloads in the last 30 days: 0 · 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.
  • 100d3-chart-table-sync
    Synchronize interactions between D3 visualizations and HTML tables, enabling click-to-highlight and hover effects across both elements. Use this skill when you need chart and table elements to stay in sync - clicking a bubble highlights its table row, clicking a row highlights…
  • 100d3js-visualization
    Create D3.js charts and interactive data visualizations. Use when building bar charts, line charts, scatter plots, pie charts, force-directed graphs, geographic maps, or any custom data visualization.

Feedback and reports

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