用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/cxcscmu/SkillLearnBench --skill run2-d3-bubble-clusters命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Handles reading, populating, and saving .docx files using the python-docx library. Use this skill for any tasks involving template filling or modifying Word documents.
Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.
This skill includes search capability in 13F, such as fuzzy search a fund information using possibly inaccurate name, or fuzzy search a stock cusip info using its name.
基于 SOC 职业分类
正在显示 SKILL.md
| name | run2_d3_bubble_clusters |
| description | Production-ready D3.js bubble chart clustering with optimized force simulation and labeling |
Creating a clustered bubble chart where bubbles group by sector with:
Calculate even distribution of sector centers:
// Get unique sectors and calculate grid dimensions
const sectors = Array.from(new Set(data.map(d => d.sector)));
const numSectors = sectors.length;
const cols = Math.ceil(Math.sqrt(numSectors));
const rows = Math.ceil(numSectors / cols);
// Available space
const width = 800; // SVG width
const height = 600; // SVG height
// Calculate spacing
const spacingX = width / (cols + 1);
const spacingY = height / (rows + 1);
// Map sectors to positions
const sectorPositions = {};
sectors.forEach((sector, i) => {
const col = i % cols;
const row = Math.floor(i / cols);
sectorPositions[sector] = {
x: spacingX * (col + 1),
y: spacingY * (row + 1)
};
});
const simulation = d3.forceSimulation(nodes)
// Clustering forces: Pull nodes toward sector centers
.force("x", d3.forceX()
.strength(0.08) // Moderate pull strength
.x(d => sectorPositions[d.sector].x))
.force("y", d3.forceY()
.strength(0.08) // Balanced x and y
.y(d => sectorPositions[d.sector].y))
// Collision detection: Prevent overlap
.force("collide", d3.forceCollide()
.radius(d => d.radius + 3)) // Add padding
// Charge: Light repulsion for natural spread
.force("charge", d3.forceManyBody()
.strength(-15)) // Negative = repulsion
// Decay: Control convergence speed
.alphaDecay(0.02); // Slower convergence for stability
// Filter data with market cap (exclude nulls)
const marketCapValues = data
.filter(d => d.marketCap)
.map(d => d.marketCap);
// Create scale from filtered data
const radiusScale = d3.scaleSqrt()
.domain([0, d3.max(marketCapValues)])
.range([10, 50]);
// Use uniform size for items without marketCap
const nodes = data.map(d => ({
...d,
radius: d.marketCap ? radiusScale(d.marketCap) : 15
}));
Automatically size labels based on bubble size:
const labels = svg.selectAll("text")
.data(nodes)
.enter()
.append("text")
.attr("x", d => d.x)
.attr("y", d => d.y)
.attr("dy", "0.3em")
.attr("text-anchor", "middle")
.attr("font-size", d => {
// Scale font inversely: larger bubbles = larger text
const size = d.radius;
return Math.max(8, Math.min(14, size / 4));
})
.attr("fill", "white")
.attr("font-weight", "bold")
.attr("pointer-events", "none") // Don't interfere with bubble clicks
.text(d => d.ticker);
simulation.on("tick", () => {
// Update circles
circles
.attr("cx", d => d.x)
.attr("cy", d => d.y);
// Update labels to stay centered in bubbles
labels
.attr("x", d => d.x)
.attr("y", d => d.y);
});
| Parameter | Value | Effect |
|---|---|---|
| forceX/Y strength | 0.08 | Controls cluster tightness |
| forceCollide radius | radius + 3 | Padding between bubbles |
| forceManyBody strength | -15 | Repulsion between clusters |
| alphaDecay | 0.02 | Convergence speed (lower = slower/smoother) |
Adjust these based on:
Sector centers automatically distribute to fill the canvas. For perfect centering:
// Center the overall layout
const minX = Math.min(...Object.values(sectorPositions).map(p => p.x));
const maxX = Math.max(...Object.values(sectorPositions).map(p => p.x));
const minY = Math.min(...Object.values(sectorPositions).map(p => p.y));
const maxY = Math.max(...Object.values(sectorPositions).map(p => p.y));
const offsetX = (width - (maxX - minX)) / 2 - minX;
const offsetY = (height - (maxY - minY)) / 2 - minY;
// Apply offset to all sector positions
Object.values(sectorPositions).forEach(pos => {
pos.x += offsetX;
pos.y += offsetY;
});
Issue: Bubbles clustering too tightly
Issue: Clusters drifting apart
Issue: Labels overlapping bubbles
Issue: Simulation running forever
.stop() after timeout