# wuba/react-native-echarts architecture

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

- Interactive diagram: https://gitdiagram.com/wuba/react-native-echarts
- Repository: https://github.com/wuba/react-native-echarts

## Overview

##### Project Type and Purpose
- Project Type: This is a front-end charting library targeted at React Native (with web support) that integrates charting capabilities from Apache ECharts.
- Purpose: It provides a high-performance solution with two rendering options (Skia and SVG) and supports interactive features (gestures) for rich chart displays on various devices.

##### File Structure
- Top-Level Components:
- Configuration and meta files (e.g., .editorconfig, LICENSE, README files, babel.config.js).
- Example folder: Provides a standalone app demonstrating how to integrate and configure the library.
- Scripts folder: Contains build/bootstrap scripts.
- src directory: Core implementation of the library.
▪ Components subdirectory: Definitions for gesture handlers and event handling.
▪ skia subdirectory & svg subdirectory: Contains separate implementations for the two different rendering libraries.
▪ tests: Contains unit and snapshot tests along with subfolders for image snapshots.
- Additional platform-specific files (e.g., files ending with .web.tsx) show that the codebase distinguishes between web and native rendering paths.
- Architectural Patterns:
- Clear separation of rendering strategies: one set of components (Skia) versus another (SVG).
- A modular structure that isolates common functionalities (like gesture handling, styling, utility functions) from rendering specifics.
- Use of a core “index” file that ties together testing, components, and rendering modules.

##### README File
- The README emphasizes the identical usage as Apache ECharts.
- It highlights the dual rendering options (Skia & SVG) and recommends installation of the corresponding native libraries.
- The usage section demonstrates how to register and use chart types and components, reflecting a clear API design for end users.
- Performance and compatibility are key points – the library supports gestures and cross-platform reuse.

a. Main components:
- API/Initialization Layer: The entry point (src/index.tsx) that exposes the charting API.
- Renderer Modules:
- SkiaRenderer (and its supporting components in src/skia) for high-performance native drawing.
- SVGRenderer (and related components in src/svg) using react-native-svg.
- Rendering Components:
- SkiaChart and SvgChart components which wrap the rendering logic and manage DOM/references.
- Gesture & Event Handling: Components in src/components (e.g., RNGestureHandler.tsx, PanResponderHandler.tsx) that capture user interactions.
- Test Modules: Separated testing components in the src/__tests__ folder to verify rendering and behavior.
- Example Application: The standalone example project that demonstrates integration and usage.
- Supporting Utilities & Helpers: Located under src/utils and other helper modules in the rendering directories.

b. Relationships and Interactions:
- The API layer initializes charts by calling echarts.init(…) with a reference to either a SkiaChart or SvgChart component.
- The rendering modules (SkiaRenderer, SVGRenderer) are registered with the ECharts core library and come into play when the user sets a chart option.
- Gesture and event handlers trigger updates and interact with the core charting functions.
- The example app serves as a practical integration point, connecting React component rendering, chart initialization, and dynamic option setting.
- Dependencies between platform-specific utilities (e.g., platform detection in src/utils/platform.ts) and the rendering modules determine which pathway is invoked (native vs. web).

c. Architectural Patterns/Design Principles:
- Separation of Concerns: Rendering logic, gesture handling, and core chart functionality are kept modular.
- Abstraction for Renderer Selection: Users can choose between Skia and SVG renderers by altering imports and registration – a modular plug-and-play design.
- Cross-Platform Adaptability: Distinct files for web vs. native (e.g., *.web.tsx files) which maintain clear boundaries while reusing common ECharts API logic.
- Test-Driven Structure: A dedicated test directory ensures that each architectural component is well covered.

d. Technologies, Frameworks, and Libraries:
- React Native and React for component composition.
- Apache ECharts (core library) for charting logic.
- react-native-skia and react-native-svg for rendering.
- Utility libraries (e.g., Babel, Jest for testing) and configurations (webpack, metro, tsconfig) for building and deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API & Initialization Layer
    API["API Layer (src/index.tsx)"]:::api

    %% Renderers Subgraphs
    subgraph "Skia Renderer"
        SRenderer["Skia Renderer Module"]:::renderer
        SChart["Skia Chart Component"]:::renderer
    end

    subgraph "SVG Renderer"
        SVGRenderer["SVG Renderer Module"]:::renderer
        SVGChart["SVG Chart Component"]:::renderer
    end

    %% Gesture & Event Handlers Subgraph
    subgraph "Gesture & Event Handlers"
        Gesture["Gesture Handler"]:::gesture
        PanResponder["PanResponder Handler"]:::gesture
        RNGesture["RN Gesture Handler"]:::gesture
    end

    %% Supporting Modules Subgraph
    subgraph "Supporting Modules"
        Utils["Utilities & Helpers"]:::utils
        Tests["Test Modules"]:::test
    end

    %% Example Application Subgraph
    subgraph "Example Application"
        AppJS["App.js"]:::example
        AppTS["App.tsx"]:::example
    end

    %% Connections
    %% Example App initializing the API
    AppJS -- "calls init" --> API
    AppTS -- "calls init" --> API

    %% API initializing renderers
    API -- "initializes" --> SRenderer
    API -- "initializes" --> SVGRenderer

    %% Renderers rendering charts
    SRenderer -- "renders" --> SChart
    SVGRenderer -- "renders" --> SVGChart

    %% Gesture Handlers update chart via API
    Gesture -- "triggers update" --> API
    PanResponder -- "triggers update" --> API
    RNGesture -- "triggers update" --> API

    %% Utilities support renderers
    Utils -- "supports" --> SRenderer
    Utils -- "supports" --> SVGRenderer

    %% Tests are connected to API for verification
    Tests -- "tests" --> API

    %% Styles
    classDef api fill:#f9f,stroke:#333,stroke-width:2px;
    classDef renderer fill:#bbf,stroke:#333,stroke-width:2px;
    classDef gesture fill:#ff9,stroke:#333,stroke-width:2px;
    classDef test fill:#9f9,stroke:#333,stroke-width:2px;
    classDef example fill:#f99,stroke:#333,stroke-width:2px;
    classDef utils fill:#9cf,stroke:#333,stroke-width:2px;

    %% Click Events
    click API "https://github.com/wuba/react-native-echarts/blob/main/src/index.tsx"
    click SRenderer "https://github.com/wuba/react-native-echarts/blob/main/src/skia/SkiaRenderer.ts"
    click SVGRenderer "https://github.com/wuba/react-native-echarts/blob/main/src/svg/SVGRenderer.ts"
    click SChart "https://github.com/wuba/react-native-echarts/blob/main/src/skia/skiaChart.tsx"
    click SVGChart "https://github.com/wuba/react-native-echarts/blob/main/src/svg/svgChart.tsx"
    click Gesture "https://github.com/wuba/react-native-echarts/blob/main/src/components/GestureHandler.tsx"
    click PanResponder "https://github.com/wuba/react-native-echarts/blob/main/src/components/PanResponderHandler.tsx"
    click RNGesture "https://github.com/wuba/react-native-echarts/blob/main/src/components/RNGestureHandler.tsx"
    click Tests "https://github.com/wuba/react-native-echarts/tree/main/src/__tests__"
    click AppJS "https://github.com/wuba/react-native-echarts/blob/main/example/App.js"
    click AppTS "https://github.com/wuba/react-native-echarts/blob/main/example/src/App.tsx"
    click Utils "https://github.com/wuba/react-native-echarts/tree/main/src/utils"
```
