Data Visualization
Visualization is communication. Every visual element must serve understanding.
Critical Rules
🚨 Use established algorithms. Graph layout, tree layout, spatial indexing—these problems are solved. Check dagre, d3-force, ELK.js before implementing anything custom.
🚨 Choose encodings by perceptual accuracy. Position beats length beats angle beats area beats color. Prefer bar charts over pie charts over bubble charts.
🚨 Never rely on color alone. 8% of men are colorblind. Use shape, pattern, or labels as backup encoding.
🚨 Match rendering to scale. SVG for <1000 elements, Canvas for 1000-10000, WebGL for >10000.
1. Visual Encoding
Marks & Channels
Marks are geometric primitives representing data:
- Points (scatter plots, dot plots)
- Lines (line charts, network edges)
- Areas (bar charts, area charts, maps)
Channels are visual properties applied to marks:
- Position (x, y coordinates)
- Size (length, area, volume)
- Color (hue, saturation, lightness)
- Shape (circle, square, triangle)
- Orientation (angle, slope)
Cleveland & McGill Hierarchy (1984)
Visual encodings ranked by perceptual accuracy:
- Position along common scale (most accurate)
- Position on non-aligned scales
- Length
- Angle/slope
- Area
- Volume
- Color saturation/hue (least accurate)
Implication: Bar charts (position) > pie charts (angle) > bubble charts (area)
Preattentive Attributes
Properties processed in <250ms without conscious effort:
- Color (hue, saturation)
- Form (orientation, length, width, size, shape)
- Spatial position
- Motion
Use preattentive attributes for the most important data—they "pop out" automatically.
Channel Effectiveness by Data Type
| Data Type |
Best Channels |
| Quantitative |
Position, length, angle, area |
| Ordinal |
Position, density, saturation |
| Categorical |
Shape, hue, spatial region |
2. Interaction Design
Shneiderman's Mantra (1996)
"Overview first, zoom and filter, then details on demand"
- Overview — Show entire dataset, establish context
- Zoom & Filter — Reduce complexity, focus on subset
- Details on Demand — Tooltips, click-to-expand, drill-down
Interaction Patterns
| Pattern |
Use Case |
| Brushing & linking |
Cross-highlighting across coordinated views |
| Focus + context |
Fisheye lens, detail-on-demand panels |
| Direct manipulation |
Drag nodes, resize elements, reorder |
| Animated transitions |
Help users track changes between states |
| Pan & zoom |
Navigate large visualizations |
| Filtering |
Reduce data to relevant subset |
| Selection |
Highlight specific data points |
3. Chart Selection
By Question Type
| Question |
Chart Type |
Why |
| How do values compare? |
Bar chart |
Position encoding is most accurate |
| How has this changed over time? |
Line chart |
Shows trends, handles many points |
| What's the distribution? |
Histogram, box plot |
Shows spread, outliers, shape |
| What's the relationship? |
Scatter plot |
Reveals correlation, clusters |
| What's the part-to-whole? |
Stacked bar, treemap |
Shows composition |
| What are the connections? |
Network graph, Sankey |
Shows relationships, flows |
| What's the hierarchy? |
Tree, sunburst, treemap |
Shows parent-child structure |
| Where is it? |
Choropleth, symbol map |
Geographic context |
By Data Volume
| Volume |
Approach |
| <20 points |
Simple charts, direct labeling |
| 20-500 |
Standard visualization |
| 500-5000 |
Consider aggregation, filtering |
| 5000+ |
Aggregation mandatory, or Canvas/WebGL |
Common Anti-Patterns
- ❌ Pie charts with >5 slices (use bar chart)
- ❌ 3D charts without strong justification
- ❌ Dual-axis with unrelated scales (misleading)
- ❌ Non-zero baselines for bar charts (distorts perception)
- ❌ Truncated axes without clear indication
4. Color
Palette Types
| Type |
Use Case |
Examples |
| Sequential |
Low to high values |
Blues, Greens, Viridis |
| Diverging |
Values diverge from midpoint |
RdBu, BrBG, Spectral |
| Categorical |
Distinct categories |
Set2, Tableau10, Category10 |
Colorblind Safety
- 8% of men, 0.5% of women have color vision deficiency
- Never rely on color alone—use shape, pattern, labels
- Safe sequential: viridis, cividis, plasma
- Safe categorical: ColorBrewer's colorblind-safe options
- Test with: Coblis, Sim Daltonism, Chrome DevTools
Perceptual Uniformity
- Avoid rainbow colormaps (jet)—perceptual steps are uneven
- Use viridis, parula, cividis for sequential data
- These ensure equal perceptual distance between values
Color Guidelines
- 4.5:1 contrast ratio for text (WCAG AA)
- 3:1 contrast for UI components
- Max 7-10 distinct categorical colors
- Use saturation/lightness variation for emphasis
5. Layout Algorithms
🚨 Before implementing ANY layout algorithm, check if a library exists.
Algorithm → Library Mapping
| Problem |
Algorithm |
Libraries |
| Layered/DAG graphs |
Sugiyama (1981) |
dagre, ELK.js |
| Force-directed networks |
Fruchterman-Reingold (1991) |
d3-force, Cytoscape.js |
| Tree layouts |
Reingold-Tilford (1981) |
d3-hierarchy |
| Treemaps |
Squarified (2000) |
d3-hierarchy, ECharts |
| Circle packing |
Wang (2006) |
d3-hierarchy |
| Sankey diagrams |
— |
d3-sankey |
| Chord diagrams |
— |
d3-chord |
| Large graphs (10k+) |
WebGL + spatial indexing |
Sigma.js, G6, deck.gl |
| Spatial queries |
Quadtree, R-tree |
d3-quadtree, rbush |
| Edge crossing minimization |
Barth (2002) |
Built into dagre/ELK |
When to Use Each Layout
| Layout |
Best For |
| Sugiyama (dagre) |
Flowcharts, dependency graphs, DAGs with direction |
| Force-directed |
Social networks, organic relationships, exploration |
| Tree |
Hierarchies with single parent per node |
| Treemap |
Hierarchies with quantitative values |
| Circular |
Emphasizing central nodes, ring structures |
| Matrix |
Dense graphs where edges would overlap |
These problems are solved. Never implement from scratch.
6. Rendering & Performance
Rendering Technology Thresholds
<1000 elements → SVG
- DOM events work naturally
- Accessibility (ARIA) supported
- Crisp at any zoom level
- CSS styling
1000-10000 → Canvas
- Batch rendering
- Manual hit testing required
- Lower memory footprint
- requestAnimationFrame for animation
>10000 → WebGL
- GPU acceleration
- Sigma.js, deck.gl, regl
- Complex setup
- Limited text rendering
Performance Patterns
| Pattern |
When to Use |
| Web Workers |
Layout computation (never block main thread) |
| Spatial indexing |
Hit detection with quadtree/R-tree |
| Level-of-detail |
Simplify distant/small elements |
| Viewport culling |
Only render visible elements |
| Debouncing |
Expensive interactions (zoom, filter) |
| Virtualization |
Long lists of chart components |
| Aggregation |
Too many data points to render individually |
Anti-Patterns
- ❌ 5000 SVG nodes (use Canvas)
- ❌ Layout computation on main thread
- ❌ Hit testing without spatial indexing
- ❌ Rendering off-screen elements
- ❌ Animating thousands of elements individually
7. Libraries
Graph Layouts
| Library |
Best For |
Notes |
| dagre |
Layered DAGs, flowcharts |
Sugiyama algorithm, good defaults |
| dagre-d3 |
dagre + D3 rendering |
SVG output |
| ELK.js |
Complex layouts, compound graphs |
Eclipse Layout Kernel, highly configurable |
| d3-force |
Organic networks |
Fruchterman-Reingold, customizable forces |
| Cytoscape.js |
Graph analysis + visualization |
Rich algorithm library |
| Sigma.js |
Large graphs (10k+) |
WebGL rendering |
| G6/AntV |
Enterprise graphs |
Full-featured, Chinese ecosystem |
| vis-network |
Quick prototypes |
Easy API, limited customization |
Charting
| Library |
Best For |
Notes |
| D3.js |
Custom, highly interactive |
Low-level, maximum control |
| Observable Plot |
Quick exploration |
D3 team, excellent defaults |
| Recharts |
React integration |
Declarative, composable |
| Victory |
React integration |
Animation support |
| ECharts |
Feature-rich dashboards |
Great mobile, large dataset support |
| Vega-Lite |
Grammar of graphics |
Declarative JSON spec |
| Chart.js |
Simple charts |
Easy setup, limited customization |
| Plotly |
Scientific visualization |
3D support, interactivity |
When to Use D3 vs Higher-Level Libraries
Use D3 when:
- Need complete control over rendering
- Building novel/custom visualizations
- Integrating with existing SVG/Canvas code
- Performance-critical with custom optimizations
Use higher-level libraries when:
- Standard chart types suffice
- Faster development time matters
- Team less experienced with D3
- Need built-in responsiveness/animation
8. Composition & Layout
Project Composition (Dashboard Level)
- Visual hierarchy — Guide eye to most important first
- Grid systems — Align elements for coherence
- Grouping — Related visualizations together
- White space — Breathing room, not wasted space
- Reading flow — Z-pattern or F-pattern for Western audiences
Chart Composition (Single Chart)
| Element |
Guidelines |
| Title |
Clear, descriptive; top-left or centered above |
| Subtitle |
Additional context; smaller, below title |
| Axes |
Labeled with units; tick marks at meaningful intervals |
| Legend |
Embedded when possible; external if complex |
| Aspect ratio |
Affects slope perception; 45° banking for trends |
| Margins |
Enough for labels; consistent across charts |
Aspect Ratio Guidelines
- Line charts: ~16:9 for trends (banking to 45°)
- Bar charts: Depends on number of bars
- Scatter plots: Often square (1:1) for correlation
- Maps: Preserve geographic proportions
9. Annotation
Annotation Types
| Type |
Purpose |
| Title |
The "what" — identifies the visualization |
| Subtitle |
Additional context, data source |
| Caption |
The "so what" — key insight or takeaway |
| Axis labels |
Variable names and units |
| Legend |
Decode color/shape/size mappings |
| Callouts |
Highlight specific data points |
| Reference lines |
Benchmarks, targets, averages |
| Source citation |
Data provenance |
Best Practices
- Annotate the insight, not just the data — "Sales peaked in Q3" not just "Sales over time"
- Use callouts sparingly — Highlight 1-3 key points maximum
- Direct labeling — Embed labels in chart when possible (vs separate legend)
- Provide context — Benchmarks, historical reference, targets
- Layer information — Overview visible, details on interaction
Text Hierarchy
- Title (largest, boldest)
- Subtitle/caption
- Axis titles
- Tick labels
- Annotations
- Source (smallest)
10. Accessibility
WCAG Requirements
- AA minimum (AAA preferred)
- 4.5:1 contrast ratio for normal text
- 3:1 contrast for large text and UI components
- No information conveyed by color alone
Keyboard Navigation
- Tab through interactive elements
- Arrow keys for traversing data points
- Enter/Space for selection
- Escape to cancel/close
Screen Reader Support
<svg role="img" aria-labelledby="chart-title chart-desc">
<title id="chart-title">Monthly Sales 2024</title>
<desc id="chart-desc">Bar chart showing sales increasing from $10M in January to $15M in December</desc>
</svg>
- Use ARIA labels and roles
- Provide text alternatives
- Announce dynamic updates with live regions
- Structure for logical reading order
Alternative Representations
- Data tables — Provide as fallback for all charts
- Text summaries — Describe key insights
- Sonification — Audio representation for time-series
- Tactile graphics — For physical accessibility
11. Anti-Patterns Summary
Design Anti-Patterns
| Anti-Pattern |
Why It's Wrong |
What to Do |
| 3D charts |
Distorts perception |
Use 2D |
| Pie >5 slices |
Hard to compare |
Use bar chart |
| Dual unrelated axes |
Misleading correlation |
Separate charts |
| Non-zero baseline |
Exaggerates differences |
Start at zero |
| Rainbow colormap |
Perceptually uneven |
Use viridis |
| Color-only encoding |
Excludes colorblind |
Add shape/pattern |
| Chart junk |
Distracts from data |
Remove decoration |
| Overplotting |
Hides data density |
Aggregate or jitter |
Implementation Anti-Patterns
| Anti-Pattern |
Why It's Wrong |
What to Do |
| Custom graph layout |
Reinventing solved problem |
Use dagre/ELK |
| 5000 SVG nodes |
Poor performance |
Use Canvas |
| Main thread layout |
Blocks UI |
Use Web Worker |
| No spatial indexing |
Slow hit detection |
Use quadtree |
| Rendering off-screen |
Wasted computation |
Viewport culling |
12. Academic Foundations
Seminal Papers
| Paper |
Year |
Contribution |
| Cleveland & McGill "Graphical Perception" |
1984 |
Visual encoding hierarchy |
| Shneiderman "The Eyes Have It" |
1996 |
Overview-zoom-filter-details mantra |
| Gansner et al. "Drawing Directed Graphs" |
1993 |
Foundation for dagre |
| Fruchterman & Reingold "Force-directed Placement" |
1991 |
Foundation for d3-force |
| Sugiyama et al. "Hierarchical Systems" |
1981 |
Layered graph layout |
| Barth et al. "Bilayer Cross Counting" |
2002 |
Edge crossing minimization |
| Brewer "Color Use Guidelines" |
1994 |
ColorBrewer palettes |
Essential Resources
| Resource |
Type |
Focus |
| ColorBrewer (colorbrewer2.org) |
Tool |
Accessible color palettes |
| From Data to Viz (data-to-viz.com) |
Guide |
Chart selection decision tree |
| Visualization Analysis & Design (Munzner) |
Textbook |
Comprehensive theory |
| Data Visualisation (Kirk) |
Textbook |
Practitioner guide |
| Visual Display of Quantitative Information (Tufte) |
Textbook |
Data-ink ratio, chart junk |
| D3 Gallery (observablehq.com/@d3/gallery) |
Examples |
Implementation patterns |
Summary
🚨 Before implementing visualization:
- What question are you answering? → Select chart type
- What's your data volume? → Select rendering technology
- Is there an established algorithm? → Use the library
- Is it accessible? → Color, keyboard, screen reader
- Does it follow perceptual best practices? → Encoding hierarchy
1---2name: data-visualization-23description: Comprehensive data visualization skill covering visual execution and technical implementation. Includes perceptual foundations, chart selection, layout algorithms, and library guidance. Triggers on: charts, graphs, dashboards, 'visualize', 'plot', data presentation, D3, Recharts, Victory.4---5
6# Data Visualization
7
8Visualization is communication. Every visual element must serve understanding.
9
10## Critical Rules
11
12🚨 **Use established algorithms.** Graph layout, tree layout, spatial indexing—these problems are solved. Check dagre, d3-force, ELK.js before implementing anything custom.
13
14🚨 **Choose encodings by perceptual accuracy.** Position beats length beats angle beats area beats color. Prefer bar charts over pie charts over bubble charts.
15
16🚨 **Never rely on color alone.** 8% of men are colorblind. Use shape, pattern, or labels as backup encoding.
17
18🚨 **Match rendering to scale.** SVG for <1000 elements, Canvas for 1000-10000, WebGL for >10000.
19
20---
21
22## 1. Visual Encoding
23
24### Marks & Channels
25
26**Marks** are geometric primitives representing data:
27- Points (scatter plots, dot plots)
28- Lines (line charts, network edges)
29- Areas (bar charts, area charts, maps)
30
31**Channels** are visual properties applied to marks:
32- Position (x, y coordinates)
33- Size (length, area, volume)
34- Color (hue, saturation, lightness)
35- Shape (circle, square, triangle)
36- Orientation (angle, slope)
37
38### Cleveland & McGill Hierarchy (1984)
39
40Visual encodings ranked by perceptual accuracy:
41
421. **Position along common scale** (most accurate)
432. Position on non-aligned scales
443. Length
454. Angle/slope
465. Area
476. Volume
487. **Color saturation/hue** (least accurate)
49
50**Implication:** Bar charts (position) > pie charts (angle) > bubble charts (area)
51
52### Preattentive Attributes
53
54Properties processed in <250ms without conscious effort:
55- Color (hue, saturation)
56- Form (orientation, length, width, size, shape)
57- Spatial position
58- Motion
59
60Use preattentive attributes for the most important data—they "pop out" automatically.
61
62### Channel Effectiveness by Data Type
63
64| Data Type | Best Channels |
65|-----------|---------------|
66| Quantitative | Position, length, angle, area |
67| Ordinal | Position, density, saturation |
68| Categorical | Shape, hue, spatial region |
69
70---
71
72## 2. Interaction Design
73
74### Shneiderman's Mantra (1996)
75
76"Overview first, zoom and filter, then details on demand"
77
781. **Overview** — Show entire dataset, establish context
792. **Zoom & Filter** — Reduce complexity, focus on subset
803. **Details on Demand** — Tooltips, click-to-expand, drill-down
81
82### Interaction Patterns
83
84| Pattern | Use Case |
85|---------|----------|
86| Brushing & linking | Cross-highlighting across coordinated views |
87| Focus + context | Fisheye lens, detail-on-demand panels |
88| Direct manipulation | Drag nodes, resize elements, reorder |
89| Animated transitions | Help users track changes between states |
90| Pan & zoom | Navigate large visualizations |
91| Filtering | Reduce data to relevant subset |
92| Selection | Highlight specific data points |
93
94---
95
96## 3. Chart Selection
97
98### By Question Type
99
100| Question | Chart Type | Why |
101|----------|------------|-----|
102| How do values compare? | Bar chart | Position encoding is most accurate |
103| How has this changed over time? | Line chart | Shows trends, handles many points |
104| What's the distribution? | Histogram, box plot | Shows spread, outliers, shape |
105| What's the relationship? | Scatter plot | Reveals correlation, clusters |
106| What's the part-to-whole? | Stacked bar, treemap | Shows composition |
107| What are the connections? | Network graph, Sankey | Shows relationships, flows |
108| What's the hierarchy? | Tree, sunburst, treemap | Shows parent-child structure |
109| Where is it? | Choropleth, symbol map | Geographic context |
110
111### By Data Volume
112
113| Volume | Approach |
114|--------|----------|
115| <20 points | Simple charts, direct labeling |
116| 20-500 | Standard visualization |
117| 500-5000 | Consider aggregation, filtering |
118| 5000+ | Aggregation mandatory, or Canvas/WebGL |
119
120### Common Anti-Patterns
121
122- ❌ Pie charts with >5 slices (use bar chart)
123- ❌ 3D charts without strong justification
124- ❌ Dual-axis with unrelated scales (misleading)
125- ❌ Non-zero baselines for bar charts (distorts perception)
126- ❌ Truncated axes without clear indication
127
128---
129
130## 4. Color
131
132### Palette Types
133
134| Type | Use Case | Examples |
135|------|----------|----------|
136| Sequential | Low to high values | Blues, Greens, Viridis |
137| Diverging | Values diverge from midpoint | RdBu, BrBG, Spectral |
138| Categorical | Distinct categories | Set2, Tableau10, Category10 |
139
140### Colorblind Safety
141
142- 8% of men, 0.5% of women have color vision deficiency
143- **Never rely on color alone**—use shape, pattern, labels
144- Safe sequential: viridis, cividis, plasma
145- Safe categorical: ColorBrewer's colorblind-safe options
146- Test with: Coblis, Sim Daltonism, Chrome DevTools
147
148### Perceptual Uniformity
149
150- **Avoid rainbow colormaps** (jet)—perceptual steps are uneven
151- Use viridis, parula, cividis for sequential data
152- These ensure equal perceptual distance between values
153
154### Color Guidelines
155
156- 4.5:1 contrast ratio for text (WCAG AA)
157- 3:1 contrast for UI components
158- Max 7-10 distinct categorical colors
159- Use saturation/lightness variation for emphasis
160
161---
162
163## 5. Layout Algorithms
164
165🚨 **Before implementing ANY layout algorithm, check if a library exists.**
166
167### Algorithm → Library Mapping
168
169| Problem | Algorithm | Libraries |
170|---------|-----------|-----------|
171| Layered/DAG graphs | Sugiyama (1981) | dagre, ELK.js |
172| Force-directed networks | Fruchterman-Reingold (1991) | d3-force, Cytoscape.js |
173| Tree layouts | Reingold-Tilford (1981) | d3-hierarchy |
174| Treemaps | Squarified (2000) | d3-hierarchy, ECharts |
175| Circle packing | Wang (2006) | d3-hierarchy |
176| Sankey diagrams | — | d3-sankey |
177| Chord diagrams | — | d3-chord |
178| Large graphs (10k+) | WebGL + spatial indexing | Sigma.js, G6, deck.gl |
179| Spatial queries | Quadtree, R-tree | d3-quadtree, rbush |
180| Edge crossing minimization | Barth (2002) | Built into dagre/ELK |
181
182### When to Use Each Layout
183
184| Layout | Best For |
185|--------|----------|
186| Sugiyama (dagre) | Flowcharts, dependency graphs, DAGs with direction |
187| Force-directed | Social networks, organic relationships, exploration |
188| Tree | Hierarchies with single parent per node |
189| Treemap | Hierarchies with quantitative values |
190| Circular | Emphasizing central nodes, ring structures |
191| Matrix | Dense graphs where edges would overlap |
192
193**These problems are solved. Never implement from scratch.**
194
195---
196
197## 6. Rendering & Performance
198
199### Rendering Technology Thresholds
200
201```
202<1000 elements → SVG
203 - DOM events work naturally
204 - Accessibility (ARIA) supported
205 - Crisp at any zoom level
206 - CSS styling
207
2081000-10000 → Canvas
209 - Batch rendering
210 - Manual hit testing required
211 - Lower memory footprint
212 - requestAnimationFrame for animation
213
214>10000 → WebGL
215 - GPU acceleration
216 - Sigma.js, deck.gl, regl
217 - Complex setup
218 - Limited text rendering
219```
220
221### Performance Patterns
222
223| Pattern | When to Use |
224|---------|-------------|
225| Web Workers | Layout computation (never block main thread) |
226| Spatial indexing | Hit detection with quadtree/R-tree |
227| Level-of-detail | Simplify distant/small elements |
228| Viewport culling | Only render visible elements |
229| Debouncing | Expensive interactions (zoom, filter) |
230| Virtualization | Long lists of chart components |
231| Aggregation | Too many data points to render individually |
232
233### Anti-Patterns
234
235- ❌ 5000 SVG nodes (use Canvas)
236- ❌ Layout computation on main thread
237- ❌ Hit testing without spatial indexing
238- ❌ Rendering off-screen elements
239- ❌ Animating thousands of elements individually
240
241---
242
243## 7. Libraries
244
245### Graph Layouts
246
247| Library | Best For | Notes |
248|---------|----------|-------|
249| dagre | Layered DAGs, flowcharts | Sugiyama algorithm, good defaults |
250| dagre-d3 | dagre + D3 rendering | SVG output |
251| ELK.js | Complex layouts, compound graphs | Eclipse Layout Kernel, highly configurable |
252| d3-force | Organic networks | Fruchterman-Reingold, customizable forces |
253| Cytoscape.js | Graph analysis + visualization | Rich algorithm library |
254| Sigma.js | Large graphs (10k+) | WebGL rendering |
255| G6/AntV | Enterprise graphs | Full-featured, Chinese ecosystem |
256| vis-network | Quick prototypes | Easy API, limited customization |
257
258### Charting
259
260| Library | Best For | Notes |
261|---------|----------|-------|
262| D3.js | Custom, highly interactive | Low-level, maximum control |
263| Observable Plot | Quick exploration | D3 team, excellent defaults |
264| Recharts | React integration | Declarative, composable |
265| Victory | React integration | Animation support |
266| ECharts | Feature-rich dashboards | Great mobile, large dataset support |
267| Vega-Lite | Grammar of graphics | Declarative JSON spec |
268| Chart.js | Simple charts | Easy setup, limited customization |
269| Plotly | Scientific visualization | 3D support, interactivity |
270
271### When to Use D3 vs Higher-Level Libraries
272
273**Use D3 when:**
274- Need complete control over rendering
275- Building novel/custom visualizations
276- Integrating with existing SVG/Canvas code
277- Performance-critical with custom optimizations
278
279**Use higher-level libraries when:**
280- Standard chart types suffice
281- Faster development time matters
282- Team less experienced with D3
283- Need built-in responsiveness/animation
284
285---
286
287## 8. Composition & Layout
288
289### Project Composition (Dashboard Level)
290
291- **Visual hierarchy** — Guide eye to most important first
292- **Grid systems** — Align elements for coherence
293- **Grouping** — Related visualizations together
294- **White space** — Breathing room, not wasted space
295- **Reading flow** — Z-pattern or F-pattern for Western audiences
296
297### Chart Composition (Single Chart)
298
299| Element | Guidelines |
300|---------|------------|
301| Title | Clear, descriptive; top-left or centered above |
302| Subtitle | Additional context; smaller, below title |
303| Axes | Labeled with units; tick marks at meaningful intervals |
304| Legend | Embedded when possible; external if complex |
305| Aspect ratio | Affects slope perception; 45° banking for trends |
306| Margins | Enough for labels; consistent across charts |
307
308### Aspect Ratio Guidelines
309
310- **Line charts:** ~16:9 for trends (banking to 45°)
311- **Bar charts:** Depends on number of bars
312- **Scatter plots:** Often square (1:1) for correlation
313- **Maps:** Preserve geographic proportions
314
315---
316
317## 9. Annotation
318
319### Annotation Types
320
321| Type | Purpose |
322|------|---------|
323| Title | The "what" — identifies the visualization |
324| Subtitle | Additional context, data source |
325| Caption | The "so what" — key insight or takeaway |
326| Axis labels | Variable names and units |
327| Legend | Decode color/shape/size mappings |
328| Callouts | Highlight specific data points |
329| Reference lines | Benchmarks, targets, averages |
330| Source citation | Data provenance |
331
332### Best Practices
333
334- **Annotate the insight, not just the data** — "Sales peaked in Q3" not just "Sales over time"
335- **Use callouts sparingly** — Highlight 1-3 key points maximum
336- **Direct labeling** — Embed labels in chart when possible (vs separate legend)
337- **Provide context** — Benchmarks, historical reference, targets
338- **Layer information** — Overview visible, details on interaction
339
340### Text Hierarchy
341
3421. Title (largest, boldest)
3432. Subtitle/caption
3443. Axis titles
3454. Tick labels
3465. Annotations
3476. Source (smallest)
348
349---
350
351## 10. Accessibility
352
353### WCAG Requirements
354
355- **AA minimum** (AAA preferred)
356- 4.5:1 contrast ratio for normal text
357- 3:1 contrast for large text and UI components
358- No information conveyed by color alone
359
360### Keyboard Navigation
361
362- Tab through interactive elements
363- Arrow keys for traversing data points
364- Enter/Space for selection
365- Escape to cancel/close
366
367### Screen Reader Support
368
369```html
370<svg role="img" aria-labelledby="chart-title chart-desc">
371 <title id="chart-title">Monthly Sales 2024</title>
372 <desc id="chart-desc">Bar chart showing sales increasing from $10M in January to $15M in December</desc>
373</svg>
374```
375
376- Use ARIA labels and roles
377- Provide text alternatives
378- Announce dynamic updates with live regions
379- Structure for logical reading order
380
381### Alternative Representations
382
383- **Data tables** — Provide as fallback for all charts
384- **Text summaries** — Describe key insights
385- **Sonification** — Audio representation for time-series
386- **Tactile graphics** — For physical accessibility
387
388---
389
390## 11. Anti-Patterns Summary
391
392### Design Anti-Patterns
393
394| Anti-Pattern | Why It's Wrong | What to Do |
395|--------------|----------------|------------|
396| 3D charts | Distorts perception | Use 2D |
397| Pie >5 slices | Hard to compare | Use bar chart |
398| Dual unrelated axes | Misleading correlation | Separate charts |
399| Non-zero baseline | Exaggerates differences | Start at zero |
400| Rainbow colormap | Perceptually uneven | Use viridis |
401| Color-only encoding | Excludes colorblind | Add shape/pattern |
402| Chart junk | Distracts from data | Remove decoration |
403| Overplotting | Hides data density | Aggregate or jitter |
404
405### Implementation Anti-Patterns
406
407| Anti-Pattern | Why It's Wrong | What to Do |
408|--------------|----------------|------------|
409| Custom graph layout | Reinventing solved problem | Use dagre/ELK |
410| 5000 SVG nodes | Poor performance | Use Canvas |
411| Main thread layout | Blocks UI | Use Web Worker |
412| No spatial indexing | Slow hit detection | Use quadtree |
413| Rendering off-screen | Wasted computation | Viewport culling |
414
415---
416
417## 12. Academic Foundations
418
419### Seminal Papers
420
421| Paper | Year | Contribution |
422|-------|------|--------------|
423| Cleveland & McGill "Graphical Perception" | 1984 | Visual encoding hierarchy |
424| Shneiderman "The Eyes Have It" | 1996 | Overview-zoom-filter-details mantra |
425| Gansner et al. "Drawing Directed Graphs" | 1993 | Foundation for dagre |
426| Fruchterman & Reingold "Force-directed Placement" | 1991 | Foundation for d3-force |
427| Sugiyama et al. "Hierarchical Systems" | 1981 | Layered graph layout |
428| Barth et al. "Bilayer Cross Counting" | 2002 | Edge crossing minimization |
429| Brewer "Color Use Guidelines" | 1994 | ColorBrewer palettes |
430
431### Essential Resources
432
433| Resource | Type | Focus |
434|----------|------|-------|
435| ColorBrewer (colorbrewer2.org) | Tool | Accessible color palettes |
436| From Data to Viz (data-to-viz.com) | Guide | Chart selection decision tree |
437| Visualization Analysis & Design (Munzner) | Textbook | Comprehensive theory |
438| Data Visualisation (Kirk) | Textbook | Practitioner guide |
439| Visual Display of Quantitative Information (Tufte) | Textbook | Data-ink ratio, chart junk |
440| D3 Gallery (observablehq.com/@d3/gallery) | Examples | Implementation patterns |
441
442---
443
444## Summary
445
446🚨 **Before implementing visualization:**
447
4481. **What question are you answering?** → Select chart type
4492. **What's your data volume?** → Select rendering technology
4503. **Is there an established algorithm?** → Use the library
4514. **Is it accessible?** → Color, keyboard, screen reader
4525. **Does it follow perceptual best practices?** → Encoding hierarchy