Guidelines for AI agents working in this repository.
d3plus is a JavaScript data visualization library that extends D3.js. It is organized as a pnpm monorepo with workspaces under packages/. Each package is independently publishable under the @d3plus/ npm scope.
| Package | Purpose |
|---|---|
@d3plus/color |
Color utilities and defaults |
@d3plus/core |
All chart types, components, and shapes |
@d3plus/data |
Data manipulation and filtering |
@d3plus/dom |
DOM utilities |
@d3plus/export |
SVG/image export |
@d3plus/format |
Number and date formatting |
@d3plus/locales |
Translation dictionaries |
@d3plus/math |
Math utilities |
@d3plus/react |
React component wrappers |
@d3plus/text |
Text measurement and wrapping |
@d3plus/types |
Unified TypeScript type definitions |
@d3plus/docs |
Storybook documentation site |
All visualization classes inherit from BaseClass (in packages/core/src/utils/BaseClass.ts). It provides:
- A chainable (fluent) API — public setter methods return
this - Auto-configuration — methods are auto-discovered at construction to set defaults
- Deep config merging via
config()— pass an object to set many properties at once RESETtoken — passRESETas a value to restore a property to its default- Locale and event management built in
When adding a new property to a class, add a corresponding getter/setter method that returns this when called as a setter and returns the stored value when called with no arguments.
Every package follows the same layout:
packages/<name>/
index.ts # Re-exports everything from src/
src/ # Source files (TypeScript, ES modules)
es/ # Build output: transpiled ES modules (gitignored, generated)
umd/ # Build output: UMD bundles (gitignored, generated)
test/ # Mocha tests (*-test.ts)
dev/ # Dev HTML pages (gitignored)
package.json
Each package produces four UMD bundles plus the es/ ESM tree:
umd/<name>.js— standalone (peers are external)umd/<name>.full.js— all dependencies inlinedumd/<name>.min.js— minified standaloneumd/<name>.full.min.js— minified full
pnpm install # Install all workspace dependenciesRun from the repo root, targeting the package you want to work on:
pnpm --filter @d3plus/color run dev # dev server on :4000 + Rollup watch
pnpm --filter @d3plus/react run dev # Vite on :4000
pnpm --filter @d3plus/docs run dev # Storybook on :4000The scripts/dev.js watcher automatically rebuilds ESM and UMD outputs when source files change.
# Build ESM for all packages (run before testing)
pnpm -r --if-present run build:esm
# Build a single package's ESM
pnpm --filter @d3plus/core run build:esm
# Build a single package's UMD
pnpm --filter @d3plus/core run build:umd# Test all packages (pretest builds ESM first)
pnpm test
# Test a single package
pnpm --filter @d3plus/color testEach package's test script runs ESLint on index.ts and src/**/*.ts, then Mocha on test/**/*-test.ts. Tests use JSDOM for DOM emulation.
pnpm run docs # Generates markdown docs from TypeDoc comments- File format: ES modules (
type: "module"everywhere). Use named exports. - TypeScript: All source is
.ts(or.tsxfor the React package). Strict mode is enabled. - Private properties: prefixed with
_(e.g.,this._color). - Getter/setter methods: same method name handles both — no argument → return stored value, argument passed → store and
return this. - Formatting: Prettier with
arrowParens: "avoid"andbracketSpacing: false. Run Prettier before committing. - Linting: ESLint flat config (
eslint.config.jsat root). Fix lint errors before committing. - TypeDoc: Add TypeDoc comments to all public methods. The
pnpm run docsscript generates markdown from them.
- Create
packages/core/src/charts/MyChart.ts— extend an existing chart class orPlot. - Export it from
packages/core/src/charts/index.ts. - Export it from
packages/core/index.ts. - Add a Storybook story in
packages/docs/charts/. - Add a Mocha test in
packages/core/test/.
- Always build ESM before running tests. Tests import from
es/which is generated output. The rootpretestscript does this automatically, but if running a single package's tests in isolation, runpnpm --filter @d3plus/<pkg> run build:esmfirst. es/andumd/are gitignored. Do not commit build output.dev/is gitignored. Do not commit development HTML pages.- Releases require
GITHUB_TOKEN. Thescripts/release.jsscript calls the GitHub Releases API. Do not runpnpm run releasewithout it set. - Circular dependency warnings from Rollup are suppressed in the build config. Don't introduce new circular dependencies between packages.
Releases are automated. Do not run this unless you are the maintainer and have confirmed all tests pass:
GITHUB_TOKEN=<token> node scripts/release.jsThe script bumps the version, publishes all packages to npm with --access=public, commits, tags, and creates a GitHub release.