d3-bubble-chart
/d3-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.
- 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
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.
Oryginalny opis (EN)
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.
Jak działa
- Core Pattern
- Sizing Bubbles by Market Cap
- Sector Clustering with forceX/forceY
- Tick Handler
- Color Legend
- Tooltip
- Click Selection
- Key Tips
Podgląd SKILL.md
---
name: d3-bubble-chart
description: >
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.
---
# D3 v6 Force-Directed Bubble Chart
## Core Pattern
```js
const simulation = d3.forceSimulation(nodes)
.force("x", d3.forceX(d => sectorX(d.sector)).strength(0.08))
.force("y", d3.forceY(d => sectorY(d.sector)).strength(0.08))
.force("collide", d3.forceCollide(d => d.r + 2).strength(0.9))
.force("charge", d3.forceManyBody().strength(-5))
.on("tick", ticked);
```
## Sizing Bubbles by Market Cap
Use `d3.scaleSqrt` so that *area* (not radius) encodes value — this is perceptually correct:
```js
const radiusScale = d3.scaleSqrt()
.domain([0, d3.max(data, d => d.marketCap)])
.range([minR, maxR]); // e.g. [8, 60]
```
ETFs (no market cap) get a fixed uniform radius (e.g. 18).
## Sector Clustering with forceX/forceY
Pre-compute sector center positions on a grid or circle, then use them as force targets:
```js
const sectors = [...new Set(data.map(d => d.sector))];
const sectorCenters = {};
sectors.forEach((s, i) => {
const angle = (i / sectors.length) * 2 * Math.PI;
sectorCenters[s] = {
x: cx + Math.cos(angle) * clusterRadius,
y: cy + Math.sin(angle) * clusterRadius
};
});
```
Strength 0.05–0.12 creates visible clustering without forcing everything to a single point.
## Tick Handler
```js
function ticked() {
node.attr("cx", d => d.x).attr("cy", d => d.y);
labels.attr("x", d => d.x).attr("y", d => d.y);
}
```
## Color Legend
```js
const legend = svg.append("g").attr("transform", `translate(${legendX}, ${legendY})`);
sectors.forEach((sector, i) => {
legend.append("circle").attr("r", 7).attr("cx", 0).attr("cy", i * 22).attr("fill", color(sector));
legend.append("text").attr("x", 12).attr("y", i * 22 + 5).text(sector);
});
```
## Tooltip
Create a `div` tooltip with `position: absolute; pointer-events: none`:
```js
const tooltip = d3.select("body").append("div").attr("class", "tooltip");
node.on("mouseover", (event, d) => {
tooltip.style("display", "block")
.html(`<b>${d.ticker}</b><br>${d.name}<br>${d.sector}`)
.style("left", event.pageX + 12 + "px")
.style("top", event.pageY - 28 + "px");
}).on("mousemove", (event) => {
tooltip.style("left", event.pageX + 12 + "px")
.style("top", event.pageY - 28 + "px");
}).on("mouseout", () => tooltip.style("display", "none"));
```
## Click Selection
Dispatch a custom event so other components can react:
```js
node.on("click", (event, d) => {
d3.selectAll(".bubble").classed("selected", false);
d3.select(event.currentTarget).classed("selected", true);
document.dispatchEvent(new CustomEvent("stockSelected", { detail: d.ticker }));
});
```
## Key Tips
- Run the simulation with `alphaDecay(0.02)` and `velocityDecay(0.3)` for smoother settling.
- Call `.stop()` then manually run ticks with `simulation.tick(300)` for static initial layout.
- Clamp node positions within the SVG viewBox to prevent overflow.
- Use `viewBox` + `preserveAspectRatio` for responsive sizing.
Wersje
W bazie nie ma innych skilli o nazwie d3-bubble-chart.
Migawka bazy z 13.11.2026 · wersja paczki 4d8fc3784802 (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-force-bubble-chart
Tworzy wykres bąbelkowy w D3.js (v6+) z symulacją sił, grupowaniem według kategorii i pozycjonowaniem kółek SVG bez nakładania. - 100d3-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. - 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. - 90plot-chart
Projektuje lub krytykuje wizualizację danych: dobór typu wykresu, kodowanie i czytelność. - 90ui-ux-chart
Projektuje i przegląda wykresy, wskaźniki KPI i strony raportów: kolory, osie, legendy i podpowiedzi przy danych w czasie oraz porównaniach. - 96data-chart-images
Dostarcza obraz wykresu bez użycia matplotlib, na przykład jako SVG albo HTML.