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 as src/jsx/index.ts, src/utils/index.ts, and src/designs/components/index.ts expose the public API (Infographic, layout utilities, component factories).
  • Built‑in editor is provided by the site/ app (site/src/components/AIPlayground/index.tsx and site/src/components/IconPage/index.tsx). These components import the core from src/ 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)

  1. site/src/components/AIPlayground/index.tsx → imports Infographic from src/jsx/index.ts.
  2. src/jsx/index.ts (the hub module) re‑exports 95 internal modules, including layout factories from src/designs/layouts/index.ts and utility helpers from src/utils/index.ts.
  3. src/utils/index.ts provides shared helpers (e.g., deepClone, mergeOptions). It also pulls types from src/types/index.ts.
  4. When new Infographic(opts) is called, the constructor (found in src/infographic.ts – implied by the public API) creates a renderer (src/render/svgRenderer.ts) and a store (src/state/store.ts).
  5. The renderer walks the parsed infographic AST (produced by src/parser/infographicParser.ts) and instantiates component classes from src/designs/components/index.ts.
  6. Each component renders SVG elements via src/render/svgElements.ts and 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.ts is depended on by 95 modules; keep its public surface stable.
  • MEDIUM / cognitive‑load – High branching – dev/src/utils/storage.ts has 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 permissions for GITHUB_TOKEN (.github/workflows/build.yml).
  • MEDIUM – Enable Dependabot/Renovate (.github/dependabot.yml).
  • MEDIUM – Add a dependency‑vulnerability scan step (dependency-review-action or osv-scanner).
  • MEDIUM – Set persist-credentials: false on the checkout step.
  • LOW – Define timeout-minutes for 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.