# tanstack/react-charts architecture

> Architecture diagram of the GitHub repository tanstack/react-charts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tanstack/react-charts
- Repository: https://github.com/tanstack/react-charts

## Overview

##### Main Components Structure

a) Public API Layer
- Primary Chart component (src/components/Chart.tsx)
- Public interfaces and types (src/types.ts)

b) Core Components Layer
Create distinct sections for:
- Chart Types (src/seriesTypes/)
- Line Charts
- Bar Charts
- Area Charts
- Axis System (src/components/AxisLinear.tsx)
- Interactive Elements
- Tooltips (src/components/Tooltip.tsx)
- Cursors (src/components/Cursors.tsx)
- Voronoi overlay (src/components/Voronoi.tsx)

c) Utility Layer
Supporting infrastructure:
- Hooks (src/hooks/)
- Utils (src/utils/)
- Chart Context (src/utils/chartContext.tsx)

##### Data Flow and Interactions

- Data flow from user props → Chart component → Series renderers
- Event handling flow through the Voronoi overlay → Cursors → Tooltips
- Context distribution to child components

##### Specific Implementation Details

Key architectural features:
- D3 integration points
- React hooks system
- Performance optimization systems (useSpring, useIsomorphicLayoutEffect)
- Responsive layout handling

**┌─────────────────────────────────────────────┐**
- Public API Layer               │
- ┌─────────────┐    ┌────────────────────┐ │
- Chart     │    │     Types/Props    │ │
- ┘    └────────────────────┘ │
- ┬──────────────────┬──────────┘

**┌──────────────▼──────────────────▼──────────┐**
- Core Components Layer            │
- ┌─────────────┐    ┌────────────────────┐ │
- Series    │    │    Axis System     │ │
- Renderers  │    │                    │ │
- ┘    └────────────────────┘ │
- ┌─────────────┐    ┌────────────────────┐ │
- Tooltips   │    │      Cursors       │ │
- ┘    └────────────────────┘ │
- ┬──────────────────┬──────────┘

**┌──────────────▼──────────────────▼──────────┐**
- Utility Layer                   │
- ┌─────────────┐    ┌────────────────────┐ │
- Hooks    │    │       Utils        │ │
- ┘    └────────────────────┘ │
- ┘

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef core fill:#4CAF50,stroke:#2E7D32,color:white
    classDef interactive fill:#FF9800,stroke:#EF6C00,color:white
    classDef utility fill:#9C27B0,stroke:#6A1B9A,color:white
    
    %% Public API Layer
    subgraph API
        Entry["Entry Point"]
        Chart["Chart Component"]
        Types["Types/Props Interface"]
    end
    
    %% Core Components Layer
    subgraph Core
        Series["Series Renderers"]
        Axis["Axis System"]
    end
    
    %% Interactive Layer
    subgraph Interactive
        Tooltip["Tooltip Component"]
        Cursors["Cursors Component"]
        Voronoi["Voronoi Overlay"]
    end
    
    %% Utility Layer
    subgraph Utils
        Hooks["Utility Hooks"]
        UtilFuncs["Utility Functions"]
        Context["Chart Context"]
        Springs["Performance Springs"]
        AxisUtils["Axis Building Utils"]
        CurveUtils["Curve Utilities"]
    end
    
    %% Relationships
    Entry --> Chart
    Chart --> Series
    Chart --> Axis
    Chart --> Interactive
    Context --> Chart
    Context --> Series
    Context --> Interactive
    Series --> Voronoi
    Voronoi --> Cursors
    Cursors --> Tooltip
    Hooks --> Chart
    UtilFuncs --> Chart
    Springs --> Chart
    AxisUtils --> Axis
    CurveUtils --> Series
    
    %% Style Applications
    class Entry,Chart,Types api
    class Series,Axis core
    class Tooltip,Cursors,Voronoi interactive
    class Hooks,UtilFuncs,Context,Springs,AxisUtils,CurveUtils utility
    
    %% Click Events
    click Entry "https://github.com/TanStack/react-charts/blob/beta/src/index.ts"
    click Chart "https://github.com/TanStack/react-charts/blob/beta/src/components/Chart.tsx"
    click Types "https://github.com/TanStack/react-charts/blob/beta/src/types.ts"
    click Series "https://github.com/TanStack/react-charts/tree/beta/src/seriesTypes/"
    click Axis "https://github.com/TanStack/react-charts/blob/beta/src/components/AxisLinear.tsx"
    click Tooltip "https://github.com/TanStack/react-charts/blob/beta/src/components/Tooltip.tsx"
    click Cursors "https://github.com/TanStack/react-charts/blob/beta/src/components/Cursors.tsx"
    click Voronoi "https://github.com/TanStack/react-charts/blob/beta/src/components/Voronoi.tsx"
    click Hooks "https://github.com/TanStack/react-charts/tree/beta/src/hooks/"
    click UtilFuncs "https://github.com/TanStack/react-charts/tree/beta/src/utils/"
    click Context "https://github.com/TanStack/react-charts/blob/beta/src/utils/chartContext.tsx"
    click Springs "https://github.com/TanStack/react-charts/blob/beta/src/utils/spring.ts"
    click AxisUtils "https://github.com/TanStack/react-charts/blob/beta/src/utils/buildAxis.linear.ts"
    click CurveUtils "https://github.com/TanStack/react-charts/blob/beta/src/utils/curveMonotone.ts"
```
