How wuba/react-native-echarts works
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.