d3-force-bubble-chart
/d3-force-bubble-chart
Buduje wykresy bąbelkowe D3.js v6 z symulacją sił, w których rozmiar zależy od metryki, kolor od kategorii, a klastry powstają przez forceX i forceY.
- Autor
- cxcscmu ↗
- Repozytorium
- SkillLearnBench ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 02.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 02.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Buduje wykresy bąbelkowe D3.js v6 z symulacją sił, w których rozmiar zależy od metryki, kolor od kategorii, a klastry powstają przez forceX i forceY.
Oryginalny opis (EN)
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.
Jak działa
- Overview
- Architecture
- Common Pitfalls
Podgląd SKILL.md
---
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
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · cxcscmu/SkillLearnBench | 100 | MIT |
| cxcscmu/SkillLearnBench | 100 | MIT |
| cxcscmu/SkillLearnBench | 100 | MIT |
Migawka bazy z 13.11.2026 · wersja paczki 40ddabbb158a (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100d3-bubble-chart
Prowadzi przez budowę wykresu bąbelkowego D3.js v6 z symulacją sił: klastry po sektorach, kodowanie rozmiaru, legendy kolorów, podpowiedzi i interaktywny wybór. - 100bubble-chart-generator
Generuje interaktywne wykresy bąbelkowe Chart.js dla macierzy priorytetów (wpływ i wysiłek, ryzyko i wartość) i analiz wielowymiarowych, z trzecim wymiarem jako rozmiar bąbelka. - 100scatter-bubble-analysis
Analizuje pliki CSV lub XLSX i generuje wykresy punktowe, bąbelkowe oraz małe wielokrotności z danymi o zależnościach i wartościach odstających. - 100mparanza-scatter-bubble-analysis
Sprawdza plik CSV lub XLSX i tworzy wykresy punktowe i bąbelkowe, małe wielokrotności oraz dane źródłowe o zależnościach i wartościach odstających. - 90build-interactive-data-table-with-bubble-sync
Buduje tabelę danych HTML, której podświetlenie synchronizuje się z wykresem bąbelkowym D3 po kliknięciu w obu kierunkach. - 100d3
Pomaga budować własne interaktywne wizualizacje danych w D3.js: wykresy, mapy, układy sił i diagramy hierarchiczne, które wymagają kontroli ponad możliwości bibliotek wykresów.