Skills d3
git clone https://github.com/TerminalSkills/skills
T=$(mktemp -d) && git clone --depth=1 https://github.com/TerminalSkills/skills "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/d3" ~/.claude/skills/terminalskills-skills-d3 && rm -rf "$T"
skills/d3/SKILL.mdD3.js
Overview
D3.js is a low-level JavaScript library for building custom, interactive data visualizations by binding data to DOM elements. It provides scales, axes, shape generators, geographic projections, force simulations, and hierarchical layouts, giving developers full control over the visual output while integrating with React through computed scales and layouts.
Instructions
- When binding data, use
(D3 v6+) for the enter/update/exit pattern, setting attributes and styles from bound data via accessor functions..data(dataset).join("element") - When creating scales, choose the appropriate type (
for continuous,scaleLinear
for categorical bars,scaleBand
for dates,scaleTime
for color mapping) and always set domain from the data usingscaleOrdinal
.d3.extent() - When building axes, create them with
ord3.axisBottom(scale)
, configure ticks and format labels withd3.axisLeft(scale)
, and regenerate on resize.d3.format() - When creating chart types, use shape generators (
,d3.line()
,d3.area()
,d3.arc()
,d3.pie()
) and layout functions (d3.stack()
,d3.treemap()
,d3.forceSimulation()
) for complex visualizations.d3.geoPath() - When adding interactivity, use transitions (
) for smooth data updates, tooltips on hover, and brushing/zooming for exploration..transition().duration(750) - When integrating with React, use D3 for math (scales, layouts, data transforms) and React for DOM rendering, computing values in
and usinguseMemo
with refs for D3-driven animations.useEffect
Examples
Example 1: Build a real-time dashboard with multiple chart types
User request: "Create a dashboard with line charts, bar charts, and a pie chart from API data"
Actions:
- Set up shared scales with
for the x-axis andd3.scaleTime()
for the y-axisd3.scaleLinear() - Build a line chart using
with smooth curve interpolation and area filld3.line() - Build a grouped bar chart using
with staggered enter transitionsd3.scaleBand() - Build a donut chart using
andd3.pie()
with hover tooltipsd3.arc()
Output: A responsive dashboard with animated charts that update smoothly when data changes.
Example 2: Create a force-directed network graph
User request: "Visualize relationships between entities as an interactive network graph"
Actions:
- Set up
withd3.forceSimulation()
,forceManyBody
, andforceLinkforceCenter - Render nodes as circles with
coloring by categoryd3.scaleOrdinal() - Add drag interaction with
to reposition nodesd3.drag() - Implement zoom and pan with
and tooltips on hoverd3.zoom()
Output: An interactive force-directed graph with draggable nodes, color-coded categories, and zoom navigation.
Guidelines
- Use D3 for scales, layouts, and data processing; let React handle DOM rendering in React apps.
- Use
instead of manual enter/update/exit for simpler, cleaner data binding..join() - Always set scale domains from data (
) rather than hardcoding ranges.d3.extent() - Use
for axis labels and tooltips:d3.format()
for thousands,",.0f"
for currency."$.2f" - Add transitions of 750ms with
for smooth data update animations.easeCubicInOut - Make visualizations responsive by recalculating scales on
callbacks.ResizeObserver - Add
to SVG elements and meaningfularia-label
tags for accessibility.<title>