How antvis/s2 works
Project Type and Purpose
• The README alongside the packages (s2-core, s2-react, s2-react-components, s2-vue, and s2-site) makes it clear that the project provides a core engine plus user interface components and a comprehensive playground/documentation website.
File Structure to Determine Major Components
• Monorepo Structure: At the root, there is a “pnpm-workspace.yaml” which indicates the repository is managed as a monorepo – with packages for core functionality, UI components for React, Vue, documentation (s2-site), and tools/scripts.
• Core Library (packages/s2-core): Contains the engine, cell rendering logic, datasets processing, interaction handlers, layout, facet management, and extension support. It is the foundation that drives the pivot table capabilities.
• Vue Integration (packages/s2-vue): Although stated as “停止维护” (maintenance stopped), this package nonetheless illustrates the intent to support multiple frameworks.
• Documentation/Website (s2-site): Contains pages for guides, API docs, demos, examples, and integration configurations.
• Tests and Configurations: Numerous “__tests__” directories, Jest configs, Rollup and TypeScript configurations appear, hinting at rigorous testing and bundling strategies.
• Supporting Scripts and Configurations: There are husky pre-commit hooks, GitHub workflows, ESLint, Prettier, and build scripts that underline CI/CD and code quality support.
Key Architectural Patterns and Relationships
• Separation of Concerns: The system is divided into a core engine (for heavy computations, rendering, interactions) and separate front-end UI libraries (React, Vue) that wrap or integrate with the core.
• Extensibility: The engine is built with extensibility in mind (see directories for “extends” and “facet”, “renderer”, “interaction”) so custom behaviors (custom cell rendering, custom layouts, plugins) can be seamlessly added.
• Monorepo Communication: Packages are clearly decoupled. They depend on the core (e.g., s2-react-components and s2-react) to perform data processing and rendering while applying framework-specific wrappers.
• Data-Driven Approach: The README highlights that S2 is “完全基于数据驱动的方式” – meaning that data configuration, event handling, and customization are determined by data hooks and configuration objects rather than hardcoded views.
• Testing Strategy: The structure includes extensive unit, integration, and visual regression tests which play a major role in ensuring reliability.