snow-d3

ساخت چارت‌ها، نقشه‌ها و گراف‌های تعاملی با D3.js

این Skill برای ساخت انواع visualization داده‌محور در وب با D3.js است؛ از bar، line و scatter chart تا نقشه‌های جغرافیایی، treemap، Sankey و force-directed graph.

با استفاده از الگوهای آماده و راهنمای ماژول‌ها، می‌توانید داده‌ها را به SVG یا Canvas تبدیل کنید و قابلیت‌هایی مثل tooltip، zoom، brush، drag و transition را به‌سادگی اضافه کنید.

چه چیزی می‌گیرید

  • ساخت بیش از ۳۰ نوع چارت، نمودار، نقشه و layout داده‌محور
  • پیاده‌سازی scale، axis، data join و شکل‌های SVG با D3.js v7
  • افزودن تعامل‌هایی مثل tooltip، zoom، brush، drag و transition
  • الگوهای آماده برای responsive chart و ساختار استاندارد margin convention
  • نمونه‌های مستقل HTML برای چارت‌های رایج و پیشرفته

برای چه کاری خوب است

  • توسعه‌دهندگانی که به visualization سفارشی در وب نیاز دارند
  • ساخت dashboard، گزارش تحلیلی یا ابزار اکتشاف داده‌های تعاملی
  • نمایش شبکه‌ها، ساختارهای سلسله‌مراتبی، داده‌های جغرافیایی یا جریان‌ها
  • زمانی که کنترل دقیق روی SVG، Canvas، layout و رفتار چارت مهم است

برای چه کاری نیست

  • ساخت چارت‌های ساده با کامپوننت‌های آماده و بدون نیاز به سفارشی‌سازی
  • پروژه‌هایی که به خروجی ثابت تصویری نیاز دارند و تعامل وب ندارند
  • وقتی داده یا منطق تحلیل آماده نیست و فقط به طراحی گرافیکی نیاز دارید

دربارهٔ این اسکیل

D3.js Data Visualization Skill (snow-d3)

D3 (Data-Driven Documents) v7 — the JavaScript library for bespoke data visualization using web standards (SVG, Canvas, HTML).

When to Use

  • Creating any chart or graph: bar, line, area, scatter, pie, donut, histogram, box plot
  • Building hierarchical visualizations: treemap, sunburst, tree, dendrogram, circle packing
  • Rendering network graphs: force-directed layouts, chord diagrams
  • Making geographic maps: choropleth, bubble map, globe projections
  • Adding interactivity: zoom/pan, brush selection, drag-and-drop, tooltips
  • Implementing animated transitions between data states
  • Customizing every pixel of a visualization with full SVG/Canvas control

Skill Resources

ResourceDescription
API OverviewComplete D3 module API quick reference
Module GuideDeep-dive on each of the 30 D3 modules
Patterns & RecipesCommon patterns, margin convention, responsive charts
Examples IndexReady-to-run standalone HTML examples

Examples Bundled in this Skill

FileChart TypeKey Concepts
01-bar-chart.htmlVertical & horizontal bar chartscaleBand, scaleLinear, axes, data join
02-line-chart.htmlMulti-series line chartscaleTime, line(), curveMonotoneX, tooltip
03-area-chart.htmlStacked area chartarea(), stack(), scaleOrdinal, legend
04-scatter-plot.htmlInteractive scatter plotscaleLinear, symbol(), brush selection
05-pie-donut-chart.htmlPie & donut chartpie(), arc(), schemeTableau10, animation
06-histogram.htmlHistogram with density curvebin(), scaleLinear, area(), normal distribution
07-force-graph.htmlForce-directed network graphforceSimulation, forceLink, forceManyBody
08-tree-layout.htmlCollapsible tree diagramd3.tree(), d3.hierarchy(), click interaction
09-treemap.htmlZoomable treemapd3.treemap(), treemapSquarify, zoom transition
10-choropleth-map.htmlChoropleth world mapgeoNaturalEarth1, geoPath, scaleSequential
11-bubble-chart.htmlBubble / circle packingd3.pack(), scaleSqrt, tooltip, zoom
12-transitions.htmlAnimated bar chart updateselection.transition(), easeElastic, data join
13-brush-zoom.htmlBrush & zoom on time seriesd3.brush(), d3.zoom(), context + focus chart
14-chord-diagram.htmlChord diagramd3.chord(), d3.ribbon(), arc paths
15-heatmap.htmlCalendar heatmapscaleSequential, d3-time, interpolateGreens, GitHub-style grid
16-radial-bar.htmlRadial / polar barscaleRadial, arc(), coxcomb & nightingale modes
17-sankey.htmlSankey / alluvial flowd3-sankey (CDN), sankeyLinkHorizontal(), node/link tooltips
18-box-plot.htmlBox plot + violind3.bin(), d3.area() KDE violin, quartile stats, jitter
19-waterfall.htmlWaterfall / bridgeRunning cumulative totals, positive/negative bars, connector lines
20-gantt.htmlGantt timelinescaleTime, scaleBand, progress bars, today marker
21-parallel-coordinates.htmlParallel coordinatesPer-axis scaleLinear, brushY() filter, polyline rendering
22-radar-chart.htmlRadar / spider chartRadial projection, curveLinearClosed, multi-series overlay
23-bump-chart.htmlBump / ranking chartscalePoint, curveBumpX, rank badges, hover highlight
24-sunburst.htmlSunburst partitiond3.partition(), d3.hierarchy(), click-to-zoom arc tween
25-voronoi.htmlVoronoi diagramd3.Delaunay.from(), .voronoi(), click to add sites
26-contour.htmlDensity contour / KDEd3.contourDensity(), d3.geoPath(), adjustable bandwidth
27-candlestick.htmlCandlestick / OHLCscaleTime, scaleBand, volume bars, crosshair tooltip
28-lollipop.htmlLollipop / dot plotSorted stems & dots, animated transitions, comparison mode
29-matrix-chart.htmlCorrelation matrixPearson correlations, interpolateRdBu, hover values
30-ridgeline.htmlRidgeline / joy plotStacked KDE, curveCatmullRom, adjustable overlap & bandwidth

Procedure

1. Choose the right chart type

Use the table above or the Module Guide to identify which D3 modules are needed.

2. Set up the HTML skeleton

Every standalone D3 chart starts with this template:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My Chart</title>
  <style>/* chart styles */</style>
</head>
<body>
<div id="chart"></div>
<script type="module">
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
// chart code here
</script>
</body>
</html>

3. Apply the margin convention

const width = 800, height = 500;
const margin = { top: 20, right: 30, bottom: 40, left: 50 };
const innerWidth  = width  - margin.left - margin.right;
const innerHeight = height - margin.top  - margin.bottom;

const svg = d3.select("#chart")
  .append("svg")
    .attr("width", width)
    .attr("height", height)
  .append("g")
    .attr("transform", `translate(${margin.left},${margin.top})`);

4. Define scales

// Continuous → continuous
const xScale = d3.scaleLinear().domain([0, d3.max(data, d => d.value)]).range([0, innerWidth]);
// Time
const xTime  = d3.scaleUtc().domain(d3.extent(data, d => d.date)).range([0, innerWidth]);
// Ordinal / categorical
const xBand  = d3.scaleBand().domain(data.map(d => d.name)).range([0, innerWidth]).padding(0.1);
// Color
const color  = d3.scaleOrdinal(d3.schemeTableau10);

5. Draw shapes using data join

svg.selectAll("rect")
  .data(data)
  .join("rect")
    .attr("x", d => xBand(d.name))
    .attr("y", d => yScale(d.value))
    .attr("width", xBand.bandwidth())
    .attr("height", d => innerHeight - yScale(d.value))
    .attr("fill", d => color(d.name));

6. Add axes

svg.append("g").attr("transform", `translate(0,${innerHeight})`).call(d3.axisBottom(xBand));
svg.append("g").call(d3.axisLeft(yScale).ticks(6).tickFormat(d3.format(",.0f")));

7. Add interactivity (tooltips, zoom, brush)

See Patterns & Recipes and the bundled HTML examples.

Key Concepts Quick Reference

ConceptAPINotes
Data joinselection.data(data).join(enter, update, exit)Core D3 pattern
Scalesd3.scaleLinear, scaleBand, scaleTime, scaleOrdinalMap domain→range
Shapesd3.line(), d3.area(), d3.arc(), d3.pie()Generate SVG path d strings
Axesd3.axisBottom(scale), axisLeft, axisTop, axisRightRender tick marks & labels
Transitionsselection.transition().duration(ms).ease(fn)Smooth animations
Zoomd3.zoom().on("zoom", handler)Pan & zoom behavior
Brushd3.brush() / d3.brushX()Range selection
Forced3.forceSimulation(nodes).force("link", d3.forceLink(links))Network physics
Hierarchyd3.hierarchy(data), d3.tree(), d3.treemap(), d3.pack()Tree / nested layouts
Geod3.geoPath(), d3.geoNaturalEarth1()Geographic projections

External Resources

  • Official docs: https://d3js.org/
  • API index: https://d3js.org/api
  • Gallery (Observable): https://observablehq.com/@d3/gallery
  • GitHub: https://github.com/d3/d3
  • CDN: https://cdn.jsdelivr.net/npm/d3@7/+esm
  • npm: npm install d3

دانلود ZIP