npx skills add ...
npx skills add davila7/claude-code-templates --skill d3-viz
Creating interactive data visualisations using d3.js. This skill should be used when creating custom charts, graphs, network diagrams, geographic visualisations, or any complex SVG-based data visualisation that requires fine-grained control over visual elements, transitions, or interactions. Use this for bespoke visualisations beyond standard charting libraries, whether in React, Vue, Svelte, vanilla JavaScript, or any other environment.
npx skills add davila7/claude-code-templates --skill d3-viz
This skill provides guidance for creating sophisticated, interactive data visualisations using d3.js. D3.js (Data-Driven Documents) excels at binding data to DOM elements and applying data-driven transformations to create custom, publication-quality visualisations with precise control over every visual element. The techniques work across any JavaScript environment, including vanilla JavaScript, React, Vue, Svelte, and other frameworks.
Use d3.js for:
Consider alternatives for:
Import d3 at the top of your script:
Or use the CDN version (7.x):
All modules (scales, axes, shapes, transitions, etc.) are accessible through the d3 namespace.
Pattern A: Direct DOM manipulation (recommended for most cases) Use d3 to select DOM elements and manipulate them imperatively. This works in any JavaScript environment:
Pattern B: Declarative rendering (for frameworks with templating) Use d3 for data calculations (scales, layouts) but render elements via your framework:
Use Pattern A for complex visualisations with transitions, interactions, or when leveraging d3's full capabilities. Use Pattern B for simpler visualisations or when your framework prefers declarative rendering.
Follow this standard structure in your drawing function:
Make visualisations responsive to container size:
Or use ResizeObserver for more direct container monitoring:
A chord diagram shows relationships between entities in a circular layout, with ribbons representing flows between them:
A heatmap uses colour to encode values in a two-dimensional grid, useful for showing patterns across categories:
Add smooth transitions to visual changes:
Always validate and prepare data before visualisation:
For large datasets (>1000 elements):
Make visualisations accessible:
Use consistent, professional styling:
Issue: Axes not appearing
Issue: Transitions not working
.transition() before attribute changesIssue: Responsive sizing not working
Issue: Performance problems
.join() instead of separate enter/update/exit selectionsContains detailed reference materials:
d3-patterns.md - Comprehensive collection of visualisation patterns and code examplesscale-reference.md - Complete guide to d3 scales with examplescolour-schemes.md - D3 colour schemes and palette recommendationsContains boilerplate templates:
chart-template.js - Starter template for basic chartinteractive-template.js - Template with tooltips, zoom, and interactionssample-data.json - Example datasets for testingThese templates work with vanilla JavaScript, React, Vue, Svelte, or any other JavaScript environment. Adapt them as needed for your specific framework.
To use these resources, read the relevant files when detailed guidance is needed for specific visualisation types or patterns.