Infographic – Technical Briefing
Repository: https://github.com/moses-y/Infographic (clone with git clone https://github.com/moses-y/Infographic)
📌 Problem
Creating high‑quality, AI‑driven infographics requires a declarative syntax, reusable visual components, and an editor that can turn raw text prompts into SVG output. The original AntV Infographic library solves this, but the fork bundles several independent demos, a playground, and a test harness, making the codebase dense and hard to navigate for newcomers.
âś… What This Does
- Core engine lives under
src/. Files such assrc/jsx/index.ts,src/utils/index.ts, andsrc/designs/components/index.tsexpose the public API (Infographic, layout utilities, component factories). - Built‑in editor is provided by the
site/app (site/src/components/AIPlayground/index.tsxandsite/src/components/IconPage/index.tsx). These components import the core fromsrc/and render a live editing canvas. - Demo & dev harness in
dev/(dev/src/App.tsx) shows a minimal runtime that loads the core, supplies static data, and renders to an HTML page (dev/index.html). - Test suite (
__tests__/) validates core utilities, JSX helpers, and editor interactions, covering >100 test files.
đź”§ How It Is Wired
Entry point – The most concrete start for a production build is the Next.js page in site/src/pages/index.tsx (generated by the Next.js framework). It imports site/src/components/AIPlayground/index.tsx, which in turn imports the core entry src/jsx/index.ts.
Call flow (simplified)
site/src/components/AIPlayground/index.tsx→ importsInfographicfromsrc/jsx/index.ts.src/jsx/index.ts(the hub module) re‑exports 95 internal modules, including layout factories fromsrc/designs/layouts/index.tsand utility helpers fromsrc/utils/index.ts.src/utils/index.tsprovides shared helpers (e.g.,deepClone,mergeOptions). It also pulls types fromsrc/types/index.ts.- When
new Infographic(opts)is called, the constructor (found insrc/infographic.ts– implied by the public API) creates a renderer (src/render/svgRenderer.ts) and a store (src/state/store.ts). - The renderer walks the parsed infographic AST (produced by
src/parser/infographicParser.ts) and instantiates component classes fromsrc/designs/components/index.ts. - Each component renders SVG elements via
src/render/svgElements.tsand registers them with the store for later editing.
Circular dependencies – The import graph shows 237 modules in cycles, the most connected being src/jsx/index.ts, src/utils/index.ts, and src/designs/components/index.ts. This means a change in any of those files can trigger recompilation of many others, raising the risk of inadvertent breakage.
High‑branching hotspot – dev/src/utils/storage.ts contains 13 conditional branches across 46 lines, indicating a decision‑heavy utility that could be split for readability and testability.
▶️ How To Use It
# Clone and install
git clone https://github.com/moses-y/Infographic
cd Infographic
npm install # uses package.json at the repo root
Build the playground (Next.js):
cd site
npm run build # Next.js builds the UI
npm start # serves the editor at http://localhost:3000
Run the minimal demo:
cd dev
npm run dev # Vite serves dev/index.html on http://localhost:5173
Run the test suite:
npm test # invokes jest configured in the root package.json
No additional environment variables or secret files are required; the repo ships with a default tsconfig.json and Vite/Next configs.
🌍 Real‑World Use
A SaaS product that lets marketers type a short brief (e.g., “annual sales growth chart”) can call the core API (new Infographic(opts)) from a serverless function, feed the generated SVG into an email template, and let the built‑in editor (AIPlayground) fine‑tune layout before delivery. The modular component system (src/designs/components/*) makes it easy to swap a bar‑chart for a hand‑drawn style without altering the parsing logic.
🛠️ Code Health & Issues
Measured findings (static analysis)
- HIGH / soundness – Import cycles (43 files) – e.g.,
src/jsx/index.ts,src/designs/components/index.ts,src/utils/index.ts. Break cycles by extracting shared types or using lazy imports. - HIGH / clarity – Hub module (16 files) –
src/jsx/index.tsis depended on by 95 modules; keep its public surface stable. - MEDIUM / cognitive‑load – High branching –
dev/src/utils/storage.tshas 13 branches; refactor into smaller strategy functions.
Code‑health audit (9 items)
- HIGH – Pin third‑party GitHub Actions to commit SHAs (
.github/workflows/*.yml). - HIGH – Add a lockfile for
dev/package.json. - HIGH – Invoke the test suite in CI (no test step currently).
- MEDIUM – Declare least‑privilege
permissionsforGITHUB_TOKEN(.github/workflows/build.yml). - MEDIUM – Enable Dependabot/Renovate (
.github/dependabot.yml). - MEDIUM – Add a dependency‑vulnerability scan step (
dependency-review-actionorosv-scanner). - MEDIUM – Set
persist-credentials: falseon the checkout step. - LOW – Define
timeout-minutesfor workflow jobs. - LOW – Add missing convention files (
.editorconfig,.gitattributes, formatter config).
No Dockerfile, no committed secrets, and a licence (LICENSE) is present.
📌 Bottom Line
The repository delivers a full‑featured infographic engine with a ready‑to‑run editor, but the monolithic hub (src/jsx/index.ts) and pervasive import cycles make maintenance risky. Adding a lockfile, tightening CI, and breaking the cycles would improve reliability. It is suitable for teams that need a customizable SVG infographic pipeline and are comfortable refactoring the core to reduce coupling.