d3-visualization
Build deterministic, offline D3.js **v6** visualizations from local CSV data, writing a browser-openable single-page app with vendored dependencies, stable force layouts, tooltips, legends, linked selections, and (when present) a small linked price-history view.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- d3-visualization
- description
- Build deterministic, offline D3.js **v6** visualizations from local CSV data, writing a browser-openable single-page app with vendored dependencies, stable force layouts, tooltips, legends, linked selections, and (when present) a small linked price-history view.
02 资源文件 4
- 脚本scripts/bubble_chart_example.js3.6 KB
- 脚本scripts/check_tooltip.js1.7 KB
- 脚本scripts/interactive_table_example.js4.3 KB
- 脚本scripts/tooltip_handler.js5.6 KB
03 SKILL.md 正文
Steps
- Inspect input data using only built-in tools (no pandas).
- Use
head,ls, and/or Python stdlibcsvto confirm columns, sector categories, which rows have missingmarketCap(often ETFs), and the filename pattern inindiv-stock/for mapping ticker → price CSV.
- Use
- Create the required output tree and copy data exactly into it.
- Create
/root/output/{js,css,data}and copy:/root/data/stock-descriptions.csv→/root/output/data/stock-descriptions.csv/root/data/indiv-stock/→/root/output/data/indiv-stock/
- Create
- Vendor D3.js v6 locally (no CDN).
- Place the minified bundle at:
/root/output/js/d3.v6.min.js(pin to a v6 release, e.g. 6.7.0).
- Place the minified bundle at:
- Author
/root/output/index.htmlas a single-page app that loads only local files.- Include:
<link rel="stylesheet" href="css/style.css"><script src="js/d3.v6.min.js"></script><script defer src="js/visualization.js"></script>
- Layout scaffolding:
- Left: bubble chart SVG + legend container + tooltip element.
- Right: table container.
- Add a small “details” area (inside either panel) reserved for a sparkline/mini line chart of the selected ticker’s price history so
indiv-stock/is actually visualized without changing the “two main charts side-by-side” requirement.
- Include:
- Implement
/root/output/js/visualization.jsusing deterministic D3 v6 patterns.- Load metadata from
data/stock-descriptions.csvviad3.csv(...), parsing:marketCapas number when present; mark ETFs (or missing market cap) for uniform sizing and for conditional tooltip behavior.
- Bubble chart:
- Radius:
d3.scaleSqrtonmarketCap; for ETFs/missing market cap use a fixed radius. - Color:
d3.scaleOrdinalby sector; render a legend mapping color → sector name. - Force clustering by sector using
forceX/forceYtoward sector centers arranged near the overall center (e.g., a small grid/ring around center so clusters are close together). - Add
forceCollide(r + padding)to prevent overlap. - Determinism: sort nodes by ticker before binding; set deterministic initial positions (e.g., grid based on sorted index); run the simulation for a fixed number of ticks (e.g.,
for (let i=0;i<N;i++) sim.tick(); sim.stop();) before rendering positions. - Labels: ticker symbol centered inside each bubble.
- Tooltip on hover: show ticker, name, sector only for non-ETF entries (skip tooltip entirely when
marketCapis missing per requirement).
- Radius:
- Table (50 rows):
- Columns exactly: “Ticker symbol”, “Full company name”, “Sector”, “Market cap”.
- Format market cap using
d3.format(e.g., to “1.64T”, “850.20B”, etc.).
- Linked selection (bubble ↔ row):
- Maintain a single
selectedTicker. - On bubble click: set selection, apply
.selectedclass to bubble and matching<tr>, scroll row into view if needed. - On row click: set selection, apply
.selectedclass to row and matching bubble.
- Maintain a single
- Price history visualization from
data/indiv-stock/:- On selection (bubble or row), load that ticker’s history CSV from
data/indiv-stock/(based on the observed filename pattern), parse date + close/adj close, and render a small line chart/sparkline in the details area. - Cache loaded histories to avoid repeated reads.
- If a history file is missing, show a small message in the details area rather than failing.
- On selection (bubble or row), load that ticker’s history CSV from
- Load metadata from
- Write
/root/output/css/style.cssfor layout + interaction.- Use flexbox to place the bubble chart and table side-by-side horizontally.
- Add styles for
.tooltip(absolute-positioned,pointer-events:none) and.selectedhighlights for both bubbles and table rows.
- Use terminal/tooling safely and verify outputs.
- When using the terminal tool, run one command per call or chain with
&&(don’t submit multiple separate commands unchained). - When writing files from shell, prefer heredocs like
cat <<'EOF' > fileto avoid quoting/interpolation errors. - Verify:
- All required paths exist under
/root/output/. node --check /root/output/js/visualization.jspasses.
- All required paths exist under
- When using the terminal tool, run one command per call or chain with
Expected Result
Opening /root/output/index.html in a browser shows (1) a sector-clustered bubble chart sized by market cap (ETFs uniform), colored by sector with legend, collision-free, ticker labels, and tooltips only for non-ETFs; and (2) a table of all 50 stocks with the specified columns and formatted market caps. Clicking either a bubble or table row highlights the other, and a small linked line/sparkline view renders that selection’s price history from /root/output/data/indiv-stock/.
04 同仓库更多 Skills
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms