d3-visualization
Build offline, deterministic D3.js **v6** web-app visualizations (HTML+CSS+JS) from local datasets, including force-layout bubble charts, tooltips, legends, and **two-way linked** chart↔table selection (with label overlays that don’t break clicking).
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- d3-visualization
- description
- Build offline, deterministic D3.js **v6** web-app visualizations (HTML+CSS+JS) from local datasets, including force-layout bubble charts, tooltips, legends, and **two-way linked** chart↔table selection (with label overlays that don’t break clicking).
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
-
Lock requirements + acceptance checks up front (write them into code comments)
- Confirm required D3 version (v6), required output paths, and required data sources (main CSV +
indiv-stock/folder). - Create an acceptance checklist that explicitly includes:
- Required artifacts exist and are referenced locally:
index.html,css/style.css,js/d3.v6.min.js,js/visualization.js, anddata/copies. - Bubble click works even when clicking the ticker text label (text overlay must not steal pointer events).
- Tooltip shows ticker + name + sector, and is suppressed for ETFs (ETF rows have missing
marketCap/country/website; show nothing for them). - Two-way linking: click bubble highlights table row, click row highlights bubble (single shared selection state).
- Required artifacts exist and are referenced locally:
- Confirm required D3 version (v6), required output paths, and required data sources (main CSV +
-
Inspect data using only built-in tools (do not assume pandas is installed)
- Use Python’s built-in
csvmodule (orhead,wc,ls) to confirm:stock-descriptions.csvcolumns + row count (expect ~50) and which fields are missing for ETFs.- Sector domain (unique sector names) and deterministic ordering (e.g., sort sectors alphabetically for stable colors/legend).
indiv-stock/naming convention (TICKER.csv) and one sample file’s columns (e.g.,Date,Open/High/Low/Close,Volume).
- Identify ETFs deterministically (e.g., missing
marketCap/country/website, not just a label) so tooltip suppression and sizing are correct.
- Use Python’s built-in
-
Create the
/root/output/tree and required files early (scaffold first, then iterate)- Immediately create required directories:
/root/output/js,/root/output/css,/root/output/data. - Copy input data into
/root/output/data/(including the fullindiv-stock/directory). - Vendor D3 v6 to
/root/output/js/d3.v6.min.js(local copy, not CDN at runtime) and verify it’s v6 (e.g.,d3.versionstarts with6.). - Create the three app files right away (even as minimal placeholders first):
/root/output/index.html,/root/output/js/visualization.js,/root/output/css/style.css. - When executing shell actions:
- Run one command per tool call, or chain with
&&in a single call. - Write files with quoted heredocs:
cat > file <<'EOF' ... EOF(prevents JS template strings/backticks from breaking the shell).
- Run one command per tool call, or chain with
- Immediately create required directories:
-
Create an HTML skeleton that supports the required layout and interactivity
- Use a two-column layout (flex/grid) for “bubble chart” (left) and “table” (right).
- Include:
- A chart container (SVG or a div into which the SVG is appended).
- A legend container.
- A table container.
- A tooltip
<div id="tooltip" class="tooltip"></div>(CSS toggles.visible).
-
Load/prepare data deterministically and offline-friendly
- Prefer approaches that work when opened locally:
- If
file://loading is a concern, embed the CSV content at build time and parse viad3.csvParse(...). - If you rely on runtime loading, use relative paths under the output tree (e.g.,
data/stock-descriptions.csv).
- If
- Normalize fields:
marketCap: number ornull- ETF flag from missing fields (
marketCap/country/website) to drive uniform sizing + tooltip suppression.
- Keep ordering stable (e.g., sort by sector then ticker) before binding to marks.
- Prefer approaches that work when opened locally:
-
Bubble chart: force clusters by sector, no overlaps, centered clusters, clickable even with labels
- Scales:
- Radius:
d3.scaleSqrtonmarketCap(ETFs get a uniform radius). - Color:
d3.scaleOrdinalwith sorted sector domain and a fixed scheme.
- Radius:
- Force simulation:
- Use
forceCenter(width/2, height/2). - Compute sector target positions near the center (small circle or compact grid), then cluster via
forceX/forceY. - Use
forceCollide(d => d.r + padding)to prevent overlaps. - For determinism: set initial
(x,y)deterministically; run a fixed number of ticks and stop if you don’t need animation.
- Use
- Rendering pattern that guarantees “clicking text still clicks bubble”:
- Create one
<g class="node">per stock; append<circle>and<text>inside it. - Attach hover/click handlers to the parent
g.node(or the circle), never to the text. - Set label not to capture pointer events:
text.attr('pointer-events', 'none')(or CSS.node text{pointer-events:none}).
- Create one
- Tooltip:
- Use
.visibleclass toggle; tooltip itself should bepointer-events: none. - On hover, return early for ETFs so no tooltip appears at all.
- Use
- Scales:
-
(If required by the task) visibly use
indiv-stock/data- On hover or selection (non-ETF only), render a lightweight mini line chart / sparkline for that ticker using its
indiv-stock/TICKER.csvdata (embed or lazy-load + cache). - Keep it small and robust: if a file is missing/unparseable, fail gracefully without breaking the page.
- On hover or selection (non-ETF only), render a lightweight mini line chart / sparkline for that ticker using its
-
Data table + formatting + true two-way linking
- Render all rows with required columns: ticker, full name, sector, formatted market cap.
- Market cap formatting: consistent
T/B/M/Kformatter (not locale-only). - Implement one shared selection function used by both chart and table:
setSelected(ticker)updates:- bubble/node class (e.g.,
.selected) - table row class (e.g.,
.selected)
- bubble/node class (e.g.,
- Call it from bubble click and row click (avoid separate “highlight” vs “selected” pathways).
-
Verification (must be executed before considering the build “done”)
- Filesystem: confirm
/root/output/containsindex.html,js/d3.v6.min.js,js/visualization.js,css/style.css, anddata/stock-descriptions.csv+data/indiv-stock/. - JS sanity: run
node --checkon generated JS files. - Browser interaction checks:
- 50 bubbles + 50 table rows render; legend includes every sector.
- Clicking the bubble OR its ticker label selects it.
- Bubble click highlights the matching table row; table row click highlights the matching bubble (same selection state).
- Tooltip appears only for non-ETFs; ETFs show no tooltip.
- Sector clusters are compact/centered; collisions prevent overlap.
- Filesystem: confirm
Expected Result
A reproducible, offline-capable D3 v6 single-page app with the required /root/output/ file tree populated, where the bubble chart (non-overlapping sector clusters, labels, legends, conditional tooltips) and the 50-row data table are bidirectionally linked, and the text labels do not block bubble clicking.
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