|
| 1 | +--- |
| 2 | +name: data-viz |
| 3 | +description: > |
| 4 | + Build modern, interactive data visualizations and dashboards using code-based |
| 5 | + component libraries (shadcn/ui, Recharts, Tremor, Nivo, D3, Victory, visx). |
| 6 | + Use this skill whenever the user asks to visualize data, build dashboards, |
| 7 | + create analytics views, chart metrics, tell a data story, build a reporting |
| 8 | + interface, create KPI cards, plot graphs, or explore a dataset — even if they |
| 9 | + mention PowerBI, Tableau, Streamlit, Metabase, Looker, Grafana, or similar |
| 10 | + tools. Also trigger when the user says "make a dashboard", "show me the data", |
| 11 | + "chart this", "visualize trends", "build an analytics page", "data story", or |
| 12 | + anything involving turning raw data into interactive visual interfaces. If the |
| 13 | + task involves presenting data visually — this is the skill. Always prefer |
| 14 | + building a real, interactive, code-based UI over exporting to or recommending |
| 15 | + a BI platform. |
| 16 | +--- |
| 17 | + |
| 18 | +# AI-First Data Visualization |
| 19 | + |
| 20 | +## Philosophy |
| 21 | + |
| 22 | +Build production-quality interactive data interfaces with modern component libraries — no vendor lock-in, embeddable anywhere. When no tool is specified, build code-first. When the user explicitly names a BI tool, use it — only suggest code-first if they ask for options or hit a technical blocker. |
| 23 | + |
| 24 | +## Technology Stack |
| 25 | + |
| 26 | +Full API patterns & code: `references/component-guide.md` |
| 27 | + |
| 28 | +### Framework Priority |
| 29 | + |
| 30 | +1. **React + Tailwind** — Default when JSX/TSX supported |
| 31 | +2. **HTML + CSS + Vanilla JS** — Fallback (use D3 or Chart.js) |
| 32 | +3. **Python (Plotly/Dash)** — Python-only environments only |
| 33 | + |
| 34 | +### Library Selection |
| 35 | + |
| 36 | +| Library | Best For | |
| 37 | +|---------|----------| |
| 38 | +| **shadcn/ui charts** | Default first choice — general dashboards, most chart types | |
| 39 | +| **Recharts** | Line, bar, area, composed, radar — fine-grained control | |
| 40 | +| **Tremor** | KPI cards, metric displays, full dashboard layouts | |
| 41 | +| **Nivo** | Heatmaps, treemaps, choropleth, calendar, Sankey, funnel | |
| 42 | +| **visx** | Bespoke custom viz — D3-level control with React | |
| 43 | +| **D3.js** | Force-directed graphs, DAGs, maps — maximum flexibility | |
| 44 | +| **Victory** | When animation quality matters most | |
| 45 | + |
| 46 | +**Supporting**: Tailwind CSS · Radix UI · Framer Motion · Lucide React · date-fns · Papaparse · lodash |
| 47 | + |
| 48 | +## Building a Visualization |
| 49 | + |
| 50 | +### Step 1: Understand the Data Story |
| 51 | + |
| 52 | +Before code, identify: **What question does the data answer?** Who is the audience (exec → KPIs only, analyst → drill-down, public → narrative)? **What's the ONE key insight?** Design around it. |
| 53 | + |
| 54 | +### Step 2: Choose Chart Type |
| 55 | + |
| 56 | +| Data Relationship | Chart Type | Library | |
| 57 | +|---|---|---| |
| 58 | +| Trend over time | Line, Area | shadcn/Recharts | |
| 59 | +| Category comparison | Bar (horizontal if many) | shadcn/Recharts | |
| 60 | +| Part of whole | Donut, Treemap | shadcn/Nivo | |
| 61 | +| Distribution | Histogram, Box, Violin | Nivo/visx | |
| 62 | +| Correlation | Scatter, Bubble | Recharts/visx | |
| 63 | +| Geographic | Choropleth, Dot map | Nivo/D3 | |
| 64 | +| Hierarchical | Treemap, Sunburst | Nivo | |
| 65 | +| Flow / Process | Sankey, Funnel | Nivo/D3 | |
| 66 | +| Single KPI | Metric card, Gauge, Sparkline | Tremor/shadcn | |
| 67 | +| Multi-metric overview | Dashboard grid of cards | Tremor + shadcn | |
| 68 | +| Ranking | Horizontal bar, Bar list | Tremor | |
| 69 | +| Column/model lineage | Force-directed DAG | D3 | |
| 70 | +| Pipeline dependencies | Hierarchical tree, DAG | D3/Nivo | |
| 71 | +| Multi-dimensional quality | Radar/Spider | Recharts | |
| 72 | +| Activity density over time | Calendar heatmap | Nivo | |
| 73 | +| Incremental change breakdown | Waterfall | Recharts (custom) | |
| 74 | + |
| 75 | +### Step 3: Build the Interface |
| 76 | + |
| 77 | +Start from this layout — remove what the data doesn't need: |
| 78 | + |
| 79 | +``` |
| 80 | +┌─────────────────────────────────────────┐ |
| 81 | +│ Header: Title + Description + Date Range│ |
| 82 | +├─────────────────────────────────────────┤ |
| 83 | +│ KPI Row: 3-5 metric cards + sparklines │ |
| 84 | +├─────────────────────────────────────────┤ |
| 85 | +│ Primary Visualization (largest chart) │ |
| 86 | +├──────────────────┬──────────────────────┤ |
| 87 | +│ Secondary Chart │ Supporting Chart/Tbl │ |
| 88 | +├──────────────────┴──────────────────────┤ |
| 89 | +│ Detail Table (sortable, filterable) │ |
| 90 | +└─────────────────────────────────────────┘ |
| 91 | +``` |
| 92 | + |
| 93 | +A single insight might just be one chart with a headline and annotation. Scale complexity to audience. |
| 94 | + |
| 95 | +### Step 4: Design Principles |
| 96 | + |
| 97 | +- **Data-ink ratio**: Remove chartjunk — unnecessary gridlines, redundant labels, decorative borders |
| 98 | +- **Color with purpose**: Encode meaning (red=bad, green=good, blue=neutral). Max 5-7 colors. Single-hue gradient for sequential data |
| 99 | +- **Typography hierarchy**: Title → subtitle (muted) → axis labels (small) → data labels |
| 100 | +- **Responsive**: `min-h-[VALUE]` on all charts. Grid stacks on mobile |
| 101 | +- **Animation**: Entry transitions only, `duration-300` to `duration-500`. Never continuous |
| 102 | +- **Accessibility**: `aria-label` on charts, WCAG AA contrast, don't rely on color alone |
| 103 | + |
| 104 | +### Step 5: Interactivity & Annotations |
| 105 | + |
| 106 | +**Priority**: Tooltips (every chart) → Filtering → Sorting → Drill-down → Cross-filtering → Export → Annotations |
| 107 | + |
| 108 | +**Annotations** turn charts into stories. Mark: inflection points, threshold crossings (amber), external events (indigo/red), anomalies (red), achievements (green). **Limit 3 per chart.** Implementation: `references/component-guide.md` → Annotation Patterns. |
| 109 | + |
| 110 | +### Step 6: Tell the Story |
| 111 | + |
| 112 | +- **Headline states insight**: "Revenue grew 23% QoQ, driven by enterprise" — not "Q3 Revenue Chart" |
| 113 | +- **Annotate key moments** directly on chart |
| 114 | +- **Contextual comparisons**: vs. prior period, vs. target, vs. benchmark |
| 115 | +- **Progressive disclosure**: Overview first — detail on demand |
| 116 | + |
| 117 | +## Environment-Specific Guidance |
| 118 | + |
| 119 | +| Environment | Approach | |
| 120 | +|---|---| |
| 121 | +| **Claude Artifacts** | React (JSX), single file, default export. Available: `recharts`, `lodash`, `d3`, `lucide-react`, shadcn via `@/components/ui/*`, Tailwind | |
| 122 | +| **Claude Code / Terminal** | Vite + React + Tailwind. Add shadcn/ui + Recharts. Structure: `src/components/charts/`, `src/components/cards/`, `src/data/` | |
| 123 | +| **Python / Jupyter** | Plotly for charts, Plotly Dash for dashboards | |
| 124 | +| **Cursor / Bolt / other IDEs** | Match existing framework. Prefer shadcn/ui if present | |
| 125 | + |
| 126 | +## Anti-Patterns |
| 127 | + |
| 128 | +- Screenshot/static charts — build interactive components |
| 129 | +- Defaulting to BI tools unprompted — build code-first when no tool specified |
| 130 | +- Default matplotlib — always customize in Python |
| 131 | +- Rainbow palettes — use deliberate, meaningful colors |
| 132 | +- 3D charts — almost never appropriate |
| 133 | +- Pie charts > 5 slices — use horizontal bar |
| 134 | +- Unlabeled dual y-axes — use two separate charts |
| 135 | +- Truncated bar axes — always start at zero |
0 commit comments