Communitygithub.com

D3.js 專業技能

協助使用 D3.js 建立自訂的互動式資料視覺化,適用於需要比一般圖表庫更細緻控制的圖表、圖形、地圖、力導向佈局或階層圖表。觸發關鍵詞:d3、資料視覺化、圖表、svg、比例尺、力導向圖、樹狀圖、等值區域圖。

D3.js 專業技能 是什麼?

此技能為 AI 代理程式提供建置自訂、互動式 D3.js 資料視覺化的完整指引。D3.js 是一個低階 JavaScript 函式庫,能將資料綁定至 DOM 元素,並提供比例尺、座標軸、形狀產生器、地理投影、力模擬與階層佈局等功能,讓開發者對視覺輸出擁有完整掌控。技能涵蓋資料綁定(使用 join)、比例尺選型(scaleLinear、scaleBand 等)、座標軸建置、圖表類型(如折線圖、區域圖、圓餅圖)與進階視覺化(力導向圖、樹狀圖)的實作,並包含與 React 整合的最佳實踐——讓 D3 負責數學計算與動畫,React 負責 DOM 渲染。技能也提供完整範例,例如即時儀表板與互動式網路圖,以及響應式設計與無障礙存取等指引。支援平台包括 Claude Code、Cursor 與 Codex 等 AI 編碼代理程式。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/TerminalSkills/skills/tree/HEAD/skills/d3

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

D3.js

概述

D3.js 是一個低階 JavaScript 函式庫,透過將資料綁定至 DOM 元素,用於建置自訂、互動式的資料視覺化。它提供比例尺、座標軸、形狀產生器、地理投影、力模擬與階層佈局,讓開發者對視覺輸出擁有完整掌控,同時可透過計算出的比例尺與佈局與 React 整合。

使用說明

  • 綁定資料時,使用 .data(dataset).join("element")(D3 v6+)來實現 enter/update/exit 模式,並透過存取器函數設定屬性與樣式。
  • 建立比例尺時,選擇適當類型(連續型用 scaleLinear、類別長條圖用 scaleBand、日期用 scaleTime、顏色對映用 scaleOrdinal),並務必使用 d3.extent() 從資料設定定義域。
  • 建立座標軸時,使用 d3.axisBottom(scale) 或 d3.axisLeft(scale) 產生,用 d3.format() 配置刻度與標籤格式,並在視窗大小變更時重新產生。
  • 建立圖表類型時,使用形狀產生器(d3.line()、d3.area()、d3.arc()、d3.pie()、d3.stack())與佈局函數(d3.treemap()、d3.forceSimulation()、d3.geoPath())來處理複雜視覺化。
  • 加入互動性時,使用轉場(.transition().duration(750))實現平滑資料更新,懸停時顯示工具提示,並支援拖曳/縮放以進行探索。
  • 與 React 整合時,讓 D3 處理數學計算(比例尺、佈局、資料轉換),React 處理 DOM 渲染;在 useMemo 中計算數值,並使用 useEffect 搭配 ref 進行 D3 驅動的動畫。

範例

範例 1:建置包含多種圖表類型的即時儀表板

使用者需求:「從 API 資料建立包含折線圖、長條圖與圓餅圖的儀表板」

步驟:

  1. 使用 d3.scaleTime() 設定共享的 X 軸比例尺,用 d3.scaleLinear() 設定 Y 軸比例尺
  2. 使用 d3.line() 搭配平滑曲線插值與區域填色建立折線圖
  3. 使用 d3.scaleBand() 配合交錯的進入轉場建立分組長條圖
  4. 使用 d3.pie() 與 d3.arc() 建立甜甜圈圖,並加入懸停工具提示

產出: 一個響應式儀表板,內含動畫圖表,能在資料變更時平滑更新。

範例 2:建立力導向網路圖

使用者需求:「將實體間的關係視覺化為互動式網路圖」

步驟:

  1. 設定 d3.forceSimulation(),包含 forceManyBody、forceLink 與 forceCenter
  2. 使用 d3.scaleOrdinal() 以類別區分顏色,將節點渲染為圓形
  3. 使用 d3.drag() 加入拖曳互動,重新定位節點
  4. 使用 d3.zoom() 實現縮放與平移,並在懸停時顯示工具提示

產出: 一個互動式力導向圖,節點可拖曳、類別以顏色區分,並支援縮放導覽。

指導方針

  • 在 React 應用中,使用 D3 處理比例尺、佈局與資料處理;讓 React 負責 DOM 渲染。
  • 使用 .join() 取代手動 enter/update/exit,以簡化資料綁定。
  • 務必從資料(d3.extent())設定比例尺的定義域,而非硬編碼數值範圍。
  • 使用 d3.format() 格式化座標軸標籤與工具提示:千位數用 ",.0f",貨幣用 "$.2f"。
  • 加入 750 毫秒的轉場,搭配 easeCubicInOut,以實現平滑的資料更新動畫。
  • 透過 ResizeObserver 回呼重新計算比例尺,使視覺化具備響應式。
  • 為 SVG 元素加上 aria-label 屬性與有意義的 <title> 標籤,以提升無障礙性。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

TerminalSkills/skills

>- Run GitHub Actions locally with act. Use when a user asks to test GitHub Actions workflows locally, debug CI pipelines without pushing, or run workflows offline.

TerminalSkills/skills

>- You are an expert in AG2 (formerly AutoGen), the open-source multi-agent conversation framework. You help developers build systems where multiple AI agents collaborate through structured conversations — with tool use, human-in-the-loop, code execution, group chat orchestration, and nested conversations — for complex tasks like software development, research, and data analysis.

TerminalSkills/skills

>- Generate short-form videos with AI — script writing, text-to-speech narration, stock footage selection, subtitle generation, and video assembly. Use when: creating TikTok/YouTube Shorts/Reels content, automating video production, building content pipelines.

TerminalSkills/skills

>- Animate 3D objects and characters in Blender with Python. Use when the user wants to keyframe properties, create armatures and rigs, set up IK/FK chains, animate shape keys for facial animation, edit F-Curves, use the NLA editor to blend actions, add drivers for expression-based animation, or script any animation workflow in Blender.

TerminalSkills/skills

>- Automate motion capture and tracking workflows in Blender with Python. Use when the user wants to import BVH or FBX mocap data, retarget motion to armatures, track camera or object motion from video, solve camera motion, clean up motion capture data, or script any tracking pipeline in Blender.

TerminalSkills/skills

>- You are an expert in Bolt.new by StackBlitz, the AI-powered full-stack development environment that runs entirely in the browser. You help developers go from idea to deployed app in minutes using natural language prompts — Bolt generates complete applications with frontend, backend, database, and deployment, all running in a WebContainer without local setup.

TerminalSkills/skills

>- Assists with using Bun as an all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Use when building HTTP servers, managing packages, running tests, or migrating from Node.js. Trigger words: bun, bun serve, bun install, bun test, bun build, javascript runtime, bun runtime.

TerminalSkills/skills

>- Self-host customer support with Chatwoot. Use when a user asks to set up open-source customer support, add live chat without SaaS costs, build a multi-channel inbox, or deploy a free Intercom alternative.

TerminalSkills/skills

>- You are an expert in Chi, the lightweight, idiomatic Go HTTP router built on `net/http`. You help developers build composable HTTP services using Chi's middleware stack, route groups, URL parameters, sub-routers, and context-based request scoping — providing Express-like ergonomics while staying 100% compatible with Go's standard library.

TerminalSkills/skills

When the user wants to edit, review, or improve existing marketing copy. Also use when the user mentions 'edit this copy,' 'review my copy,' 'copy feedback,' 'proofread,' 'polish this,' 'make this better,' or 'copy sweep.' This skill provides a systematic approach to editing marketing copy through multiple focused passes.

TerminalSkills/skills

>- Add live chat and customer support with Crisp. Use when a user asks to add a chat widget, implement live customer support, set up a help desk, create a knowledge base, or add a chatbot to a website.

TerminalSkills/skills

dbt (data build tool) transforms data in your warehouse using SQL SELECT statements. Learn project setup, models, tests, documentation, incremental materializations, and integration with data warehouses like PostgreSQL, BigQuery, and Snowflake.

TerminalSkills/skills

>- You are an expert in dlt, the open-source Python library for building data pipelines. You help developers load data from any API, file, or database into warehouses and lakes using simple Python decorators — with automatic schema inference, incremental loading, and built-in data contracts. dlt is the "requests library for data pipelines.

TerminalSkills/skills

Data Version Control for ML projects. Track large datasets and models alongside Git, build reproducible ML pipelines, and run experiments with metric comparison. Works with any storage backend including S3, GCS, Azure, and local filesystems.

TerminalSkills/skills

>- You are an expert in E2B, the cloud platform for running AI-generated code in secure sandboxes. You help developers give AI agents the ability to execute code, install packages, read/write files, and run long processes in isolated cloud environments — each sandbox is a lightweight VM that boots in ~150ms with full Linux, filesystem, and networking.

TerminalSkills/skills

>- Transcode, convert, edit, and process audio and video with FFmpeg. Use when a user asks to convert video formats (webm to mp4, mkv to mp4), extract audio from video, compress video files, trim or cut clips, concatenate videos, add subtitles, create thumbnails, apply filters, change resolution or bitrate, re-encode media, create GIFs from video, add watermarks, normalize audio, stream media, or build automated media processing pipelines.

TerminalSkills/skills

>- Create advanced animations with GSAP. Use when building complex timelines, scroll-driven animations, SVG morphing, text animations, or high-performance web animations beyond CSS capabilities.

TerminalSkills/skills

>- Generate deterministic MP4 videos from HTML, CSS, media, and seekable animations using HeyGen's HyperFrames framework. Use when someone asks to "render HTML to video", "make a video with HyperFrames", "create a programmatic video", "turn an animation into MP4", "build a launch/product video from HTML", "render GSAP/Lottie/Three.js to video", or set up an agent-driven video pipeline. Covers init/preview/render/add/lint/inspect commands, data-* timing attributes, animation adapters, and the component catalog.

TerminalSkills/skills

When the user wants to perform load testing, stress testing, or performance testing of APIs and websites using k6. Also use when the user mentions "k6," "load test," "performance test," "stress test," "spike test," "soak test," "thresholds," "virtual users," or "VUs." For browser-based testing, see selenium.

TerminalSkills/skills

>- Lovable (formerly GPT Engineer) is a browser-based AI app builder that turns a natural-language description into a working full-stack web app with a built-in backend, authentication, database and one-click publishing. Use when the user wants to prototype or ship a web app with Lovable, write effective Lovable prompts, connect Supabase or GitHub, review generated security rules, or move a Lovable project into their own editor.

相關技能