1---2name: visualize-any-data3description: Learn how to visualize data in a sustainable, accurate, and theme aware way.4---56Whenever Claude is asked to visualize data, you must follow the steps below. 7- Chart components live in the `src/components/Charts` directory8- If you need a new core component type, create it in the `src/components/Charts` directory. Inspect the existing components to see how to create a new one. Seperation of concerns is important. Make storybook stories for the new component. 9- `echarts` and `echarts-for-react` are the only libraries you can use to visualize data, and you must use them in the `src/components/Charts` directory.10- If you think the chart can be reusable, create it within the `src/components/*` directory. For example, `src/components/Ethereum/AttestationsByEntity`.1112## Step 1: What Are You Trying to Show?1314| Goal | Best Chart Types | Use When |15|------|------------------|----------|16| **Trend over time** | Line, Step, Area | X-axis is temporal (time, slot, epoch, block) |17| **Compare categories** | Bar, Column, Dot plot | Comparing distinct groups |18| **Show distribution** | Histogram, Box plot, Violin | Understanding spread/shape of data |19| **Show relationship** | Scatter, Bubble | Correlation between two+ variables |20| **Show composition** | Stacked bar, Pie, Treemap | Parts of a whole |21| **Show single value** | Number card, Gauge | Key metric snapshot |2223## Step 2: Time-Series Data Patterns2425### Data Type Detection → Interpolation Method2627| Data Characteristics | Chart Config | Example Metrics |28|---------------------|--------------|-----------------|29| **Integer values only, non-negative** | Step chart: `step: 'middle'` | blob count, transaction count, user count |30| **Values hold between updates (state changes)** | Step chart: `step: 'start'` | validator status, network state, config value |31| **Continuous decimals, volatile** | Line: `smooth: false` | gas price, latency, response time |32| **Continuous decimals, trend focus** | Line: `smooth: true` | moving averages, smoothed rates |33| **Categorical states** | Step chart: `step: 'start'` + colors | validator status, network state |34| **Sparse/irregular events** | Scatter plot | slashing events, errors, alerts |3536### Quick Decision Tree for Time-Series37```38Is data always integers? 39├─ YES → Can you have 3.5 of this thing?40│ ├─ NO → Step chart (step: 'middle')41│ └─ YES → It's rounded data → Line chart42│43└─ NO → Does value stay constant between measurements?44 ├─ YES → Step chart (step: 'start') 45 └─ NO → Line chart (linear or smooth)46```4748## Step 3: Non-Temporal Data Patterns4950### Comparison Charts5152| Scenario | Chart Type | Configuration Notes |53|----------|-----------|---------------------|54| Compare 3-10 categories | **Bar chart** (horizontal if labels long) | Start axis at zero |55| Compare 10+ categories | **Dot plot** or **Horizontal bar** | Easier to read labels |56| Compare across 2 dimensions | **Grouped bar** | Limit to 2-4 groups per category |57| Compare ratios/percentages | **Bar chart** | NOT pie chart |58| Compare ranges | **Box plot** | Shows min/max/quartiles |5960### Distribution Charts6162| Data Type | Chart Type | Use When |63|-----------|-----------|----------|64| Single continuous variable | **Histogram** | Show frequency distribution |65| Multiple distributions to compare | **Box plot** or **Violin plot** | Compare shapes across groups |66| Small dataset (<50 points) | **Dot plot** or **Strip plot** | Show individual points |67| Check for outliers | **Box plot** | Visualize quartiles and extremes |6869### Relationship Charts7071| Scenario | Chart Type | Notes |72|----------|-----------|-------|73| Two continuous variables | **Scatter plot** | Look for correlation |74| Three variables (2 continuous + 1 size) | **Bubble chart** | Size = third dimension |75| Many overlapping points | **Hex bin** or **2D histogram** | Shows density |76| Categorical + continuous | **Box plot** or **Violin** | Distribution per category |7778### Composition Charts7980| Scenario | Chart Type | Use When |81|----------|-----------|----------|82| Parts of whole (2-5 parts) | **Donut chart** | Simple proportions |83| Parts of whole (6+ parts) | **Bar chart** (NOT pie) | Too many slices are unreadable |84| Hierarchical composition | **Treemap** or **Sunburst** | Nested categories |85| Composition over time | **Stacked area** | Show how parts change |86| 100% composition | **Stacked bar (100%)** | Compare proportions across groups |8788## Step 4: Universal Rules8990### Always Do:9192| Rule | Why | How |93|------|-----|-----|94| **Start Y-axis at zero for bars** | Human eyes judge area; starting elsewhere misleads | Set `yAxis: { min: 0 }` |95| **Use consistent colors** | Same metric = same color across charts | Define color palette |96| **Label axes clearly** | Include units (gwei, %, count, etc.) | `name: 'Gas Price (gwei)'` |97| **Limit colors per chart** | Too many colors = cognitive overload | Max 5-7 distinct colors |98| **Show data directly when <20 points** | Let users see actual values | Add data labels or table |99| **Use integers for count data** | Fractional counts don't exist | `yAxis: { minInterval: 1 }` |100| **Use filled step chart for count data** | Step chart is the most accurate way to represent count data | `step: 'middle'`, `showArea: true`, `areaOpacity: 0.3`, `lineWidth: 2` |101| **Disable forced max label** | Prevents awkward tick spacing (e.g., 1, 6, 11, 16, 21, 26, 31, 32) | `axisLabel: { showMaxLabel: false }` in x-axis config |102103### Never Do:104105| Mistake | Why It's Bad | Correct Approach |106|---------|--------------|------------------|107| **Smooth lines for count data** | Implies fractional values exist (e.g., 3.5 transactions) | Use step chart |108| **Pie charts with >5 slices** | Impossible to compare similar-sized slices | Use bar chart |109| **3D charts** | Distorts perception, harder to read | Use 2D always |110| **Dual-axis with unrelated scales** | Can manipulate perception | Only if truly related metrics |111| **Too many series on one chart** | Becomes unreadable | Split into multiple charts |112| **Define your own color palette** | Use the `useThemeColors` hook to get the current theme colors | `const themeColors = useThemeColors();` |113114## Step 5: Common Metric Patterns115116### Pattern Library (Generic)117118| Metric Type | Example | Chart | Settings |119|-------------|---------|-------|----------|120| **Event count per period** | "transactions per block" | Step | `step: 'middle'`, `minInterval: 1` |121| **Total/cumulative** | "total users", "cumulative revenue" | Area or Line | `smooth: false` or filled area |122| **Rate/percentage** | "success rate", "utilization %" | Line | `smooth: false`, range 0-100 |123| **Price/fee** | "gas price", "transaction fee" | Line or Step | Step if updates discrete, Line if continuous |124| **Average** | "average latency", "mean value" | Line | `smooth: true` for trends |125| **Status/state** | "server status", "order state" | Step | `step: 'start'`, use colors |126| **Distribution** | "transaction sizes" | Histogram | Bin count = √n as starting point |127| **Comparison** | "revenue by product" | Bar | Horizontal if many categories |128| **Correlation** | "price vs volume" | Scatter | Add trendline if useful |129130## Step 6: Data Volume Guidelines131132| Data Points | Approach | Reasoning |133|-------------|----------|-----------|134| **< 20 points** | Show all detail, consider data labels | Every point is visible |135| **20-100 points** | Show all, use tooltips | Still manageable |136| **100-1,000 points** | Show all with interaction (zoom/pan) | Need exploration tools |137| **1,000-10,000 points** | Aggregate OR downsample | Too dense for individual points |138| **> 10,000 points** | Must aggregate or use density visualization | Line chart becomes solid blob |139140## Step 7: Interpolation Quick Reference141142### Step Chart: When to Use Which Direction143144| Direction | When to Use | Example |145|-----------|-------------|---------|146| `step: 'middle'` | Value **REPRESENTS THE ENTIRE PERIOD** | Blob count in slot N, transactions in block N, gas used in epoch N |147| `step: 'start'` | Value **HOLDS FROM** this point until next change | Validator status changed at slot N, config updated at block N |148| `step: 'end'` | Rarely used - value measured at end of period | Uncommon - consider `step: 'middle'` instead |149150### Step Chart Visual Styling (IMPORTANT)151152**Always use light fills with visible lines** for better readability and visual hierarchy:153154```tsx155{156 step: 'middle',157 showArea: true,158 areaOpacity: 0.3, // Light 30% fill - NOT solid (1.0)159 lineWidth: 2, // Visible 2px line - NOT hidden (0)160 showSymbol: false,161}162```163164**Why this pattern:**165- ❌ **Heavy style** (`areaOpacity: 1`, `lineWidth: 0`) looks blocky, too visually dominant166- ✅ **Light style** (`areaOpacity: 0.3`, `lineWidth: 2`) maintains data visibility while being easier to read167- The visible line helps trace values, while the light fill provides context without overwhelming168169### Smooth vs Linear for Continuous Data170171| Use Case | Setting | When |172|----------|---------|------|173| **Show volatility/precision** | `smooth: false` | Raw measurements, user needs exact values |174| **Show overall trend** | `smooth: true` | Filtered/averaged data, focus on pattern |175| **Moving average** | `smooth: true` | Already smoothed data |176| **Real-time fluctuations** | `smooth: false` | Price tickers, live monitoring |177178## Step 8: Validation Checklist179180Before finalizing any chart, ask:181182- [ ] **Reality check**: Can the values between my data points actually exist?183 - If NO → Use step chart or scatter184 - If YES → Use line chart185186- [ ] **Zero baseline**: For bar charts, does Y-axis start at zero?187 - If NO and showing bars → Fix it188 189- [ ] **Color count**: Am I using more than 7 colors?190 - If YES → Reduce or group categories191192- [ ] **Label clarity**: Can someone understand the chart without explanation?193 - If NO → Improve axis labels and add units194195- [ ] **Data density**: Are there so many points they overlap?196 - If YES → Aggregate, downsample, or add interaction197198- [ ] **Chart purpose**: Does this visualization answer the user's question?199 - If NO → Choose different chart type200201## Quick Decision Matrix202203| I Have... | I Want To... | Use This |204|-----------|--------------|----------|205| Counts over time | Show exact counts per period | Step chart with filled area (`step: 'middle'`, `showArea: true`, `areaOpacity: 0.3`, `lineWidth: 2`) |206| Measurements over time | Show trend | Line (smooth) |207| Measurements over time | Show volatility | Line (linear) |208| Values that update occasionally | Show when changes occur | Step chart with filled area (`step: 'start'`, `showArea: true`, `areaOpacity: 0.3`, `lineWidth: 2`) |209| Categories to compare | Compare values | Bar chart (horizontal if labels long) |210| Parts of a whole | Show composition | Donut (if ≤5) or Bar chart |211| Two variables | Find correlation | Scatter plot |212| One variable distribution | Understand spread | Histogram or Box plot (small dataset (<50 points) use Dot plot or Strip plot) |213| States over time | Show transitions | Step chart with filled area (`step: 'start'`, `showArea: true`, `areaOpacity: 0.3`, `lineWidth: 2`) + colors |214215## Key Principles to Remember2162171. **Match visualization to data nature** - Don't force continuous interpolation on discrete data2182. **Simpler is better** - Use the simplest chart that answers the question2193. **Context matters** - Same data may need different viz for different questions2204. **Always label clearly** - Include units, axis names, and legends2215. **Test readability** - Can someone understand it in 5 seconds?