How ant-design/ant-design-charts works
Project Type and Purpose
• It’s an open‑source, React‑based charting library published under one npm package (@ant‑design/charts) and composed of several internal packages.
• Purpose: provide ready‑made chart and graph components (statistical charts, graph layouts) on top of AntV engines (G2, G6, X6, L7), plus documentation site, examples, build & release tooling.
File Structure
• Root:
– Configuration: babel, eslint, prettier, tsconfig, pnpm-workspace.yaml
– CI/CD: .github/workflows (lint, test, release, site‐publish)
– Scripts: code generators (ast3.0), docs/tools, website build
– Tests: unit tests under tests/ and package‑specific tests
• packages/ (monorepo packages):
– charts/ – aggregation of high‑level React components (Line, Bar, etc.)
– graphs/ – graph layouts (dendrogram, mind‑map, network)
– plots/ – statistical plots (pie, histogram, scatter, etc.)
– util/ – shared utilities and common React wrappers (error boundary, loading)
• site/ – Dumi‑powered documentation & demo website, built from site/docs, site/examples
• public/, template/ – static assets & template engines used during site build
README Insights
• Confirms React + TypeScript stack
• Uses pnpm for workspace management
• Build: webpack & vite for local dev, tsconfig for type checking
• Testing: Jest + Playwright
• Publication: automated via GitHub Actions
Main Components to Illustrate
a. Package Modules (monorepo packages):
– util (core helpers, React wrappers)
– plots (imports util, core adaptor, renderers)
– graphs (imports util, graph core, behaviors, registry)
– charts (public API, re‑exports selected plots & graphs)
b. External Dependencies:
– AntV engines: G2 (for plots), G6/X6 (for graphs), L7 (for geo, maps)
– React & ReactDOM
– Styling linters, bundlers
c. Developer Tooling:
– Build pipelines (webpack/vite configurations per package)
– Scripts: ast3.0 (example codegen), docs generators
– Documentation site (Dumi)
– CI/CD workflows: lint → test → build → deploy (npm, GitHub Pages)
d. Consumers:
– npm install @ant‑design/charts → import specific components (e.g. import { Line } from '@ant-design/charts')
– Documentation site to browse options, examples
Relationships & Data Flow
• util → plots & graphs (shared code)
• plots & graphs → charts (charts package re‑exports both)
• scripts (ast3.0) → generate example code → site/examples
• site/docs + site/examples + Dumi config → documentation site build → GitHub Pages
• CI/CD pipeline triggers on push:
1. lint (eslint, stylelint)
2. unit tests (Jest)
3. build packages (webpack, tsc)
4. publish to npm
5. deploy docs site
• Consumer apps ↔ charts package (via npm)
Architectural Patterns & Principles
• Monorepo managed by pnpm-workspace.yaml
• Modular micro‑packages for clear separation of concerns
• Shared utilities to avoid duplication
• Automated generation of examples & docs for consistency
• CI/CD as code (GitHub Actions workflows)
• Documentation-first approach (Dumi / mdx)
Detailed Capture
• Don’t just show “charts → React”; drill into “charts package” and its direct use of plots & graphs.
• How util sits at the foundation.
• Scripts feeding into site/examples and then into site build.
• Which GitHub Actions workflows target which components (e.g. test.yml vs. publish.yml).