@taylorwong/ichartjs 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.6 - 2026-09-18
4
+
5
+ - Added compact per-chart visual settings with explicit default font sizing, capability-aware visibility toggles, bilingual labels, and theme-aware hamburger icon contrast.
6
+ - Added shared page-level preferences with localStorage persistence and Agent JSON patch support through the Preferences API and Playground settings page.
7
+ - Synchronized Runtime, Playground, package metadata, release-pinned installation guidance, and roadmap status for the `v2.0.6` release.
8
+
9
+ ## 2.0.5 - 2026-09-18
10
+
11
+ - Hardened JSON, SVG, PNG, and JPEG export contracts with deterministic type errors, JSON output representations, and an explicit optional Node `canvas` path through `exportAsync()`.
12
+ - Aligned Canvas and SVG background, fill, stroke, and transparent-paint behavior; normalized `theme.branding` into the shared branding contract.
13
+ - Hardened the Playground server's port detection, path containment, malformed URI handling, and escaped 404 responses.
14
+ - Added bilingual usage-scenario guidance for Runtime integration, Coding Agents, the official Skill, one-off artifacts, project/diagram workflows, and CI reports.
15
+ - Expanded export, headless Canvas, branding, documentation, and package regression coverage.
16
+
3
17
  ## 2.0.4 - 2026-09-18
4
18
 
5
19
  - Synchronized current Agent documentation, scoped package paths, GitHub fallback instructions, Skill links, Playground links, and release status.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  iChart.js is an Agent-first, renderer-independent visualization runtime. An Agent can inspect data, choose an appropriate chart, generate and validate a JSON-friendly Spec, render it with SVG or Canvas, and explain the result through public APIs.
4
4
 
5
+ Use it in one of three ways: integrate the Runtime into a web project, let a Coding Agent modify a project, or install the official Skill so an Agent can orchestrate chart selection and delivery. The Runtime produces interactive pages, SVG/PNG/JPEG artifacts, JSON checkpoints, and integration code; the Skill does not replace the Runtime.
6
+
5
7
  ## For AI Agents
6
8
 
7
9
  Do not guess chart types or configuration fields from source code. Use the public planning contract:
@@ -24,10 +26,12 @@ getCapabilities
24
26
  | Machine-readable capability manifest | `@taylorwong/ichartjs/capabilities.json` |
25
27
  | Intent and chart recipes | `@taylorwong/ichartjs/recipes/*` |
26
28
  | Agent quickstart | [`docs/agent/quickstart.md`](docs/agent/quickstart.md) |
29
+ | Usage scenarios and output formats | [`docs/agent/usage-scenarios.md`](docs/agent/usage-scenarios.md) |
27
30
  | Chinese quickstart | [`docs/agent/zh-CN/quickstart.md`](docs/agent/zh-CN/quickstart.md) |
28
31
  | Coding Agent integration | [`docs/agent/coding-agent-integration.md`](docs/agent/coding-agent-integration.md) |
29
32
  | Frontend integration | [`docs/agent/frontend-integration.md`](docs/agent/frontend-integration.md) |
30
33
  | Visual style and themes | [`docs/agent/theme-guide.md`](docs/agent/theme-guide.md) |
34
+ | Chart and page preferences | [`docs/agent/theme-guide.md`](docs/agent/theme-guide.md#chart-and-page-preferences) |
31
35
  | Official Agent Skill for Codex and WorkBuddy | [`skills/ichartjs/SKILL.md`](skills/ichartjs/SKILL.md) |
32
36
 
33
37
  ### Install
@@ -36,7 +40,7 @@ getCapabilities
36
40
  npm install @taylorwong/ichartjs@^2
37
41
  ```
38
42
 
39
- As a fallback for environments without npm access, install directly from GitHub: `npm install github:wanghetommy/ichartjs#v2.0.4`.
43
+ As a fallback for environments without npm access, install directly from GitHub: `npm install github:wanghetommy/ichartjs#v2.0.6`.
40
44
 
41
45
  ### Optional Agent Skill
42
46
 
@@ -46,13 +50,19 @@ The runtime API remains the source of truth; the Skill only teaches and orchestr
46
50
  https://github.com/wanghetommy/ichartjs/tree/master/skills/ichartjs
47
51
  ```
48
52
 
49
- From a repository checkout, install it into Codex with:
53
+ Install the latest Skill with the standard Agent Skills CLI:
54
+
55
+ ```bash
56
+ npx skills add wanghetommy/ichartjs --skill ichartjs
57
+ ```
58
+
59
+ For a non-interactive global Codex installation:
50
60
 
51
61
  ```bash
52
- cp -R skills/ichartjs "${CODEX_HOME:-$HOME/.codex}/skills/"
62
+ npx skills add wanghetommy/ichartjs --skill ichartjs --agent codex --global --yes
53
63
  ```
54
64
 
55
- WorkBuddy users can import or register the same `skills/ichartjs` folder through the host's Skill interface. Package consumers can copy it from `node_modules/@taylorwong/ichartjs/skills/ichartjs` into their Agent host's Skill directory. After installation, invoke it as `$ichartjs` when the host supports named Skill invocation, or select the `ichartjs` Skill in the host UI.
65
+ For a release-pinned installation, use `npx skills add https://github.com/wanghetommy/ichartjs/tree/v2.0.6/skills/ichartjs --agent codex --global --yes`. WorkBuddy users can import the same tagged `skills/ichartjs` URL through the host's Skill interface; do not assume a `--agent workbuddy` adapter unless the installed CLI declares it. Package consumers can still copy `node_modules/@taylorwong/ichartjs/skills/ichartjs` as a manual fallback. After installation, invoke `$ichartjs` when named Skill invocation is supported, or select `ichartjs` in the host UI.
56
66
 
57
67
  ### Agent workflow
58
68
 
@@ -11,6 +11,7 @@ This is the user-facing Agent entry point for iChart.js 2.0. Read this file firs
11
11
  ## Start Here
12
12
 
13
13
  - [Agent Quickstart](quickstart.md): install, import, plan, validate, render, explain, and self-check.
14
+ - [Usage Scenarios](usage-scenarios.md): choose Runtime, Coding Agent, Skill, one-off artifact, project, diagram, or CI usage and select the right output.
14
15
  - [Coding Agent Integration](coding-agent-integration.md): use from Codex and similar code-editing Agents.
15
16
  - [Frontend Integration](frontend-integration.md): use from ordinary JavaScript applications.
16
17
  - [Visual Style and Themes](theme-guide.md): automatic matching, presets, palettes, switching, and contrast checks.
@@ -2,6 +2,8 @@
2
2
 
3
3
  Use this guide with Codex, WorkBuddy, and similar Agents that can read a repository, edit JavaScript, execute tests, and open a local browser preview.
4
4
 
5
+ For the complete choice between project integration, one-off artifacts, Skill orchestration, and CI output, read [Usage Scenarios](usage-scenarios.md).
6
+
5
7
  ## Responsibility Boundary
6
8
 
7
9
  iChart.js is a JavaScript UI component library. The coding Agent writes or updates the host application and calls the public `@taylorwong/ichartjs` ESM API. The optional Skill provides workflow guidance only; it does not introduce a second runtime or service.
@@ -25,12 +27,16 @@ npm install
25
27
  npm run playground
26
28
  ```
27
29
 
28
- The same official Skill can be imported by Codex, WorkBuddy, and other Agent Skills-compatible hosts from `skills/ichartjs`. Install it into Codex from a repository checkout with:
30
+ Install the official Skill with the standard Agent Skills CLI:
29
31
 
30
32
  ```bash
31
- cp -R skills/ichartjs "${CODEX_HOME:-$HOME/.codex}/skills/"
33
+ npx skills add wanghetommy/ichartjs --skill ichartjs
32
34
  ```
33
35
 
36
+ For global non-interactive Codex setup, append `--agent codex --global --yes`. To pin the released workflow, install `https://github.com/wanghetommy/ichartjs/tree/v2.0.6/skills/ichartjs`. WorkBuddy can import that tagged directory through its Skill interface; only use a host-specific `--agent` value when the installed CLI declares it.
37
+
38
+ Verify discovery with `npx skills add wanghetommy/ichartjs --list`; the result should include `ichartjs`.
39
+
34
40
  ## Agent Request Pattern
35
41
 
36
42
  A useful request is explicit about data, intent, output, and acceptance:
@@ -86,3 +92,5 @@ Use `examples/agent-workflow.mjs` for the full executable lifecycle.
86
92
  - Warnings and assumptions remain visible.
87
93
  - Stable source IDs remain in explanation lineage.
88
94
  - The user receives a working preview URL.
95
+
96
+ The final Agent response should also state whether the deliverable is a live component, code change, SVG/PNG/JPEG artifact, JSON checkpoint, or a combination of these.
@@ -0,0 +1,32 @@
1
+ # Iteration 10 — Export Contract Hardening
2
+
3
+ Iteration 10A hardens the v2.0 export contract without adding chart types or changing chart behavior. The work targets `v2.0.5`, stays on the `2.0.x` line, and keeps the existing dual-engine, single-Scene-Graph architecture.
4
+
5
+ ## 10A — Export Contract Hardening
6
+
7
+ - Keep JSON, SVG, PNG, and JPEG export type detection deterministic.
8
+ - Return stable structured errors for unknown formats and unavailable headless raster paths.
9
+ - Support JSON `string`, `object`, `dataurl`, and `blob` representations.
10
+ - Provide an explicit `exportAsync()` path for optional Node `canvas` raster export.
11
+ - Prevent headless Canvas calls from throwing when no canvas surface is mounted.
12
+ - Keep Canvas and SVG fill, stroke, background, and transparent-paint semantics aligned.
13
+ - Resolve `theme.branding` into the normalized top-level branding contract.
14
+ - Fix playground port detection, path traversal checks, malformed URI handling, and escaped 404 paths.
15
+ - Add regression coverage for export representations, unsupported types, headless Canvas, and theme branding.
16
+
17
+ ## Acceptance
18
+
19
+ - `npm run agent:check` passes.
20
+ - `npm run example:agent` passes.
21
+ - `git diff --check` passes.
22
+ - Browser preview remains available at `http://localhost:3000/playground/project-gallery.html` through `npm run playground`.
23
+ - No new public chart type or chart behavior is introduced by 10A.
24
+
25
+ ## v2.0.5 Release Readiness
26
+
27
+ - Package, Runtime, Playground, documentation home, GitHub fallback instructions, Changelog, and Roadmap identify `2.0.5` consistently.
28
+ - `npm run agent:check` passes with 61 tests, 16 chart types, 24 edit commands, and 7 business schemas.
29
+ - `npm run example:agent` and `git diff --check` pass.
30
+ - `npm pack --dry-run` reports `@taylorwong/ichartjs@2.0.5`, 83 package entries, and includes the English/Chinese usage guides plus this Iteration 10 record.
31
+ - npm identity is `taylorwong`, Registry is `https://registry.npmjs.org/`, and the currently published package remains `2.0.4` before release.
32
+ - Author-only commit, tag, push, npm publish, and `develop` to `master` merge remain pending under `release-sop.md`.
@@ -0,0 +1,44 @@
1
+ # Iteration 11 — Chart Preferences and Agent Adjustments
2
+
3
+ Iteration 11A–11D adds a small, allowlisted preference layer for visual configuration. It does not add chart types or change data encoding behavior. The same contract powers per-chart settings, page-wide defaults, browser persistence, and Agent conversational adjustments.
4
+
5
+ ## 11A — Preferences Contract
6
+
7
+ - Add `createPreferencesStore()`, `normalizePreferences()`, `mergePreferences()`, and `validatePreferences()`.
8
+ - Keep the public fields limited to theme mode/preset/palette, typography scale, density, legend/labels/grid visibility, branding, and motion.
9
+ - Resolve precedence as defaults → global page preferences → chart preferences → temporary Agent patch.
10
+ - Keep preference state separate from business data and provide structured change events with `source`, `scope`, and persistence status.
11
+ - Fall back to memory in Node/SSR and support browser `localStorage` or a host storage adapter explicitly.
12
+
13
+ ## 11B — Per-Chart Settings
14
+
15
+ - Add `Chart#getPreferences()`, `Chart#setPreferences()`, and `Chart#resetPreferences()`.
16
+ - Add the optional `mountChartSettings()` browser UI with an accessible settings button in the chart container's top-right corner.
17
+ - Limit the per-chart menu to high-frequency theme, palette, font-scale, and capability-supported visibility controls; keep advanced and global controls on a dedicated page outside the chart popover.
18
+ - Keep the settings DOM outside SVG/Canvas so it is not included in PNG/SVG exports.
19
+ - Apply changes without recreating the Chart instance and preserve explicit chart colors/background/padding overrides.
20
+
21
+ ## 11C — Global Page Configuration
22
+
23
+ - Allow one `PreferencesStore` to be shared by all charts on a page.
24
+ - Support global and chart scopes with chart-specific inheritance and reset behavior.
25
+ - Persist only the versioned preference document, never business rows or credentials.
26
+ - Expose the effective preferences in `chart.getState()` and the capabilities manifest.
27
+
28
+ ## 11D — Agent and Playground Integration
29
+
30
+ - Let an Agent apply a validated visual patch with `chart.setPreferences(patch, { source: 'agent' })`.
31
+ - Keep Agent updates and UI updates on the same `preferenceschange` event path.
32
+ - Add `preferences-lab.html` and settings controls to the Complete Gallery for browser acceptance.
33
+ - Document conversational examples such as “use dashboard style, status colors, larger labels, and hide the grid.”
34
+
35
+ ## Acceptance
36
+
37
+ - `npm run agent:check` passes.
38
+ - Preferences work in headless memory mode and browser `localStorage` mode.
39
+ - Global updates reach all charts sharing a store; chart updates remain isolated.
40
+ - Invalid preference patches return structured validation details and do not mutate state.
41
+ - Preview pages:
42
+ - `http://localhost:3000/playground/preferences-lab.html`
43
+ - `http://localhost:3000/playground/project-gallery.html`
44
+ - No new chart type, data transform, or export format is introduced.
@@ -8,13 +8,13 @@
8
8
  >
9
9
  > **Agent Policy:** An Agent MUST NOT initiate any step in this SOP on its own.
10
10
  > It MAY execute the sequence **only when explicitly instructed** by the author
11
- > (e.g. "publish v2.0.4", "commit and release patch", or equivalent intent).
11
+ > (e.g. "publish vX.Y.Z", "commit and release patch", or equivalent intent).
12
12
 
13
13
  ## 0. Preconditions (MUST ALL be green)
14
14
 
15
15
  0. `git status -sb` → on `develop`, working tree clean
16
16
  1. `npm run check` → exit 0
17
- 2. `npm test` → exit 0 (60/60)
17
+ 2. `npm test` → exit 0 (all current tests pass)
18
18
  3. `npm run docs:check` → exit 0
19
19
  4. `npm run agent:check` → exit 0
20
20
  5. `npm whoami` → output = `taylorwong`
@@ -1,6 +1,6 @@
1
1
  # iChart.js 2.0 Roadmap
2
2
 
3
- > Roadmap baseline: 2026-09-14. Current release status: `v2.0.3` is published and `v2.0.4` is the documentation/version-consistency patch release. Geographic charts and 3D rendering remain out of scope until explicitly reintroduced.
3
+ > Roadmap baseline: 2026-09-14. Current release status: `v2.0.6` is prepared from the completed Iteration 11 visual preference work. Geographic charts and 3D rendering remain out of scope until explicitly reintroduced.
4
4
 
5
5
  ## Current Status
6
6
 
@@ -12,6 +12,8 @@
12
12
  - Iteration 7 local runtime and browser acceptance are complete for foundational composition, Heatmap, and Radar; physical-device checks remain host integration evidence.
13
13
  - Iteration 8A–8D is complete and accepted in automated tests, Chromium, Firefox 144, WebKit 26, native Safari 26.6.2, and a 390 px touch viewport. Physical iOS/Android and representative release-host measurements remain post-release host/device follow-up. No new public chart type was introduced.
14
14
  - Iteration 9A–9D implemented the lightweight visual style system, adaptive theme planning, runtime switching, renderer integration, and bilingual Agent guidance without adding a chart type; these capabilities remain in the `2.0.x` line.
15
+ - Iteration 10A Export Contract Hardening was implemented and released in `v2.0.5`: export representations and type errors are deterministic, optional Node raster export uses `exportAsync()`, Canvas/SVG paint semantics are aligned, and the playground server has safer port/path handling. No chart behavior or public chart type was added.
16
+ - Iteration 11 visual preference controls are included in the `v2.0.6` release: compact per-chart settings, capability-aware visibility controls, theme-aware icon contrast, explicit font-size defaults, shared page preferences, and Agent-adjustable global settings.
15
17
  - The original `2.0.0` readiness record is historical and superseded by the published `2.0.x` releases. Current release checks are defined by `docs/agent/development/release-sop.md`.
16
18
 
17
19
  ## Iteration 4 — Agent Data Contract and Business Editing
@@ -247,6 +249,29 @@ The following remain deferred beyond this roadmap baseline:
247
249
 
248
250
  They should only be scheduled after the core runtime, diagram model, and project analytics contracts are stable.
249
251
 
252
+ ## Iteration 11 — Chart Preferences and Agent Adjustments
253
+
254
+ ### Goal
255
+
256
+ Allow users and Agents to adjust a chart's visual presentation after creation through one small, auditable contract. The detailed 11A–11D plan is in `docs/agent/development/iteration-11.md`.
257
+
258
+ ### Tasks
259
+
260
+ 1. Add allowlisted preferences for theme, typography scale, density, components, branding, and motion.
261
+ 2. Support chart-scoped and page-global inheritance through an explicit Preferences Store.
262
+ 3. Persist only versioned preference state through browser `localStorage` or a host adapter.
263
+ 4. Add an optional accessible settings button outside the SVG/Canvas export surface.
264
+ 5. Let Agents apply natural-language intent as a validated preference patch with source and scope metadata.
265
+ 6. Add Playground and bilingual guidance for UI and Agent adjustment workflows.
266
+
267
+ ### Verification
268
+
269
+ - Global changes reach all charts sharing a store; chart overrides remain isolated.
270
+ - UI, Agent, and host code use the same `preferenceschange` event path.
271
+ - Invalid patches do not mutate preferences or business data.
272
+ - Settings UI is excluded from SVG, PNG, and JSON chart exports.
273
+ - `npm run agent:check`, `git diff --check`, and `http://localhost:3000/playground/preferences-lab.html` acceptance pass.
274
+
250
275
  ## Recommended Execution Order
251
276
 
252
277
  1. Finish Iteration 3 browser acceptance.
@@ -256,4 +281,5 @@ They should only be scheduled after the core runtime, diagram model, and project
256
281
  5. Execute Iteration 7 foundations before considering additional specialized chart types.
257
282
  6. Execute Iteration 8 to complete existing chart behavior, Agent adaptation, and the 2.0 release gates.
258
283
  7. Execute Iteration 9 to standardize adaptive visual styling without expanding chart count.
259
- 8. Re-evaluate geographic and 3D scope only after usage data confirms demand.
284
+ 8. Execute Iteration 11 to add post-creation chart and page preferences without expanding chart count.
285
+ 9. Re-evaluate geographic and 3D scope only after usage data confirms demand.
@@ -2,13 +2,15 @@
2
2
 
3
3
  Use iChart.js as an ordinary JavaScript UI component inside a browser application. The host application owns data loading, authentication, persistence, routing, and any assistant or natural-language interface.
4
4
 
5
+ This is the production component path. For one-off files or Agent-led repository changes, use [Usage Scenarios](usage-scenarios.md) and the [Coding Agent Integration](coding-agent-integration.md) guide instead.
6
+
5
7
  ## Install
6
8
 
7
9
  ```bash
8
10
  npm install @taylorwong/ichartjs@^2
9
11
  ```
10
12
 
11
- For environments without npm registry access, install from GitHub as a fallback: `npm install github:wanghetommy/ichartjs#v2.0.4`.
13
+ For environments without npm registry access, install from GitHub as a fallback: `npm install github:wanghetommy/ichartjs#v2.0.6`.
12
14
 
13
15
  Use the package through a bundler or another environment that resolves npm ESM imports:
14
16
 
@@ -64,3 +66,5 @@ Add these only in an application that has a demonstrated requirement. Do not dup
64
66
  ## Preview
65
67
 
66
68
  Within this repository, run `npm run playground` and open `http://localhost:3000/playground/project-gallery.html` to inspect every public chart type.
69
+
70
+ In a consumer application, use that application's own development server and return its URL. The Playground is an example and acceptance surface, not a required production dependency.
@@ -4,6 +4,8 @@ Use this guide when an Agent needs to turn user data or project information into
4
4
 
5
5
  ## Import Surface
6
6
 
7
+ Choose the integration mode before starting: use the Runtime for a product component, the Coding Agent guide when modifying a repository, or the official Skill when an Agent must repeatedly plan and deliver charts. See [Usage Scenarios](usage-scenarios.md) for the input/output contract.
8
+
7
9
  ```js
8
10
  import {
9
11
  createChart,
@@ -140,10 +142,11 @@ const jsonString = chart.export({ type: 'json' });
140
142
  // SVG vector export (zero-dependency, browser + headless)
141
143
  const svgString = chart.export({ type: 'svg' });
142
144
 
143
- // PNG raster (browser always works; headless requires the canvas package)
145
+ // PNG raster (browser sync; Node headless uses the optional canvas package)
144
146
  const pngDataUrl = typeof document !== 'undefined'
145
147
  ? chart.toDataURL('image/png')
146
148
  : null;
149
+ const headlessPng = await chart.exportAsync({ type: 'png' });
147
150
 
148
151
  // Browser-only convenience downloads
149
152
  if (typeof document !== 'undefined') {
@@ -50,7 +50,7 @@ When `branding:false`, no signature text appears on the chart or any exported ar
50
50
  ## Exports and Downloads
51
51
 
52
52
  iChart.js exports use a **dual-engine single-source architecture**. Every artifact shares the same Scene Graph produced by `buildScene()`, and the on-screen renderer is fully decoupled from the export backend:
53
- 1. **PNG / JPEG (raster)**: always drawn by a `CanvasRenderer` replaying the shared Scene Graph synchronously. In headless Node, install the optional `canvas` npm package to enable.
53
+ 1. **PNG / JPEG (raster)**: always drawn by a `CanvasRenderer` replaying the shared Scene Graph. Browser export is synchronous; Node headless export uses `exportAsync()` with the optional `canvas` npm package.
54
54
  2. **SVG (vector)**: serialized from an `SVGRenderer` DOM tree (browser) or assembled as a pure string with zero dependencies (headless). Includes XML 1.0 header, expanded font properties, and accessibility attributes.
55
55
  3. **JSON (reconstructable)**: serializes the current `spec` plus `getState()`, used for persistence, agent self-check, and cross-environment rebuild.
56
56
 
@@ -64,21 +64,21 @@ The signature gate inside `buildScene()` guarantees that live rendering, SVG exp
64
64
  |-------------|------------------------|--------------------------|------------------------------|
65
65
  | JSON | ✅ | ✅ | ✅ |
66
66
  | SVG | ✅ | ✅ | ✅ |
67
- | PNG / JPEG | ✅ true raster, sync | ❌ structured `HEADLESS_EXPORT_UNSUPPORTED` | ✅ |
67
+ | PNG / JPEG | ✅ true raster, sync | ❌ structured `HEADLESS_EXPORT_UNSUPPORTED` | ✅ via `exportAsync()` |
68
68
 
69
69
  ### Public Export APIs
70
70
 
71
71
  - `chart.toDataURL(type='image/png')` → data URL string or structured ExportError.
72
72
  - `chart.toBlob(type='image/png')` → Blob or ExportError (headless returns `BLOB_HEADLESS`).
73
73
  - `chart.export({ type, as })` → sync string / JSON object / Blob / ExportError. `as` accepts `string`, `dataurl`, `blob`, `object` (JSON only).
74
- - `chart.exportAsync({ type, as })` → Promise wrapper for future async scenarios.
74
+ - `chart.exportAsync({ type, as })` → Promise export path; enables optional Node `canvas` raster output.
75
75
  - `chart.download({ type })` / `downloadPNG()` / `downloadSVG()` / `downloadJSON()` → triggers a browser save-as. In headless, falls back to returning the raw string or structured error.
76
76
 
77
77
  ### Structured Error Shape
78
78
 
79
79
  All export/download methods return a stable `{ valid:false, code, message?, suggestion?, rasterCode? }` object on failure for reliable agent automation. Common `code` values:
80
- - `HEADLESS_EXPORT_UNSUPPORTED`: raster export requested in headless without the optional `canvas` package.
81
- - `BLOB_HEADLESS`: `toBlob` or `as=blob` used in headless (Blob requires a browser runtime).
80
+ - `HEADLESS_EXPORT_UNSUPPORTED`: synchronous raster export in headless, or raster export without a usable canvas adapter.
81
+ - `BLOB_HEADLESS`: synchronous `toBlob` or headless SVG `as=blob` has no mounted/browser serialization surface; use `exportAsync()` for Node raster or `as=dataurl`/`as=string`.
82
82
  - `DOWNLOAD_HEADLESS`: `chart.download*()` in headless; use `chart.export()` instead.
83
83
  - `EXPORT_TYPE_UNSUPPORTED`: unrecognized export type.
84
84
 
@@ -57,3 +57,34 @@ Built-in modes expose text, muted text, axis, grid, focus, selection, missing-va
57
57
 
58
58
  Preview and acceptance: `http://localhost:3000/playground/theme-gallery.html`.
59
59
 
60
+ ## Chart and Page Preferences
61
+
62
+ Use preferences for visual adjustments that a user or Agent may change after the chart has been created. Keep business data, encodings, and chart selection outside this surface.
63
+
64
+ ```js
65
+ import { createChart, createPreferencesStore, mountChartSettings } from '@taylorwong/ichartjs';
66
+
67
+ const pagePreferences = createPreferencesStore({
68
+ storage: 'localStorage',
69
+ storageKey: 'my-app:chart-preferences'
70
+ });
71
+ const chart = createChart({
72
+ chartId: 'revenue',
73
+ container: '#revenue',
74
+ type: 'line',
75
+ data: { values: rows },
76
+ preferences: pagePreferences
77
+ });
78
+ mountChartSettings(chart, { locale: 'en' });
79
+
80
+ // The same operation can come from an Agent conversation.
81
+ chart.setPreferences({
82
+ theme: { preset: 'dashboard', palette: 'status' },
83
+ typography: { scale: 1.15 },
84
+ components: { grid: false }
85
+ }, { source: 'agent' });
86
+ ```
87
+
88
+ The optional per-chart menu uses a compact hamburger icon and intentionally exposes only high-frequency controls: theme mode, palette, font scale, and supported legend/label/grid visibility. Capability checks hide controls that do not apply to the current chart. Changes apply immediately and the UI supports `en`, `zh-CN`, and automatic document-language detection.
89
+
90
+ Keep low-frequency and page-wide controls in a dedicated settings surface outside the chart popover. Share one store across the page, and call `store.setGlobal()` or `chart.setPreferences(patch, { scope: 'global' })`. The full surface may expose preset, density, branding, and other allowlisted preferences without overloading every chart. The store uses memory in Node/SSR unless `localStorage` or a host adapter is explicitly selected. Preview the quick menu in `http://localhost:3000/playground/project-gallery.html` and the full page at `http://localhost:3000/playground/preferences-lab.html`.
@@ -0,0 +1,198 @@
1
+ # iChart.js Usage Scenarios
2
+
3
+ iChart.js has three layers:
4
+
5
+ 1. **Runtime** — `@taylorwong/ichartjs` executes planning, validation, rendering, interaction, editing, and export.
6
+ 2. **Skill** — `skills/ichartjs/SKILL.md` teaches an Agent how to choose a chart, preserve data lineage, validate a Spec, and report the result.
7
+ 3. **Host project** — the user's web app, Node script, CI job, or Agent workspace provides data, lifecycle, routing, storage, and delivery.
8
+
9
+ The Skill is not a second renderer or service. A Skill-enabled Agent still needs a JavaScript host to render an interactive chart or create a file.
10
+
11
+ ## Choose a Scenario
12
+
13
+ | Need | Use | Runtime location | Typical output |
14
+ | --- | --- | --- | --- |
15
+ | Add a chart to a product | Frontend integration | User's browser app | Interactive SVG or Canvas chart |
16
+ | Ask Codex to change an existing app | Coding Agent + Runtime | Repository and app dev server | Code changes, Spec, tests, preview URL |
17
+ | Reuse charting guidance across Agents | Skill + Runtime | Agent workspace and target project | Validated code, artifacts, explanation |
18
+ | Create a one-off visualization | Node script or standalone HTML | Node.js or browser | SVG, PNG/JPEG, JSON, or HTML |
19
+ | Build project or delivery views | Project scenario + Runtime | Project dashboard | Gantt, Burndown, Timeline, analytics |
20
+ | Build a process or architecture view | Diagram scenario + Runtime | Web app or document workflow | Flow/Swimlane UI, SVG, JSON |
21
+ | Generate scheduled reports | Node script + Runtime | CI or report job | SVG/PNG files and JSON checkpoints |
22
+
23
+ ## Output Contract
24
+
25
+ | Output | Best for | API or delivery |
26
+ | --- | --- | --- |
27
+ | Interactive page | Product dashboards, editors, analysis screens | `createChart()` mounted into a DOM container |
28
+ | SVG DOM | Accessibility, keyboard interaction, diagrams, printing | `renderer: 'svg'` |
29
+ | SVG file/string | Documents, email, vector handoff, zero-dependency headless output | `chart.export({ type: 'svg' })` |
30
+ | PNG/JPEG | Presentations, chat attachments, image reports | Browser `toDataURL()` or Node `exportAsync()` with optional `canvas` |
31
+ | JSON Spec/state | Persistence, Agent checkpoints, cross-environment rebuild | `chart.export({ type: 'json' })` |
32
+ | Data URL or Blob | Embedding or browser download | `as: 'dataurl'` or browser download APIs |
33
+ | Code snippet | Developer handoff or generated page | `createChart()` integration code |
34
+ | Explanation/state | Agent self-check and user-facing audit | `chart.explain()` and `chart.getState()` |
35
+
36
+ JSON is the machine-readable source of truth. SVG and PNG/JPEG are presentation artifacts. Code is the integration artifact. An interactive page is the product artifact.
37
+
38
+ ## Visual Preferences: UI and Agent
39
+
40
+ For post-creation visual adjustments, share a `createPreferencesStore()` with the page's charts. Use `storage: 'localStorage'` only in a browser when the host wants preferences to survive refreshes. `mountChartSettings(chart)` adds an optional accessible quick-settings button outside the export surface; keep the full page-level settings surface as a separate host route.
41
+
42
+ The host or Agent can use the same patch contract:
43
+
44
+ ```js
45
+ chart.setPreferences({
46
+ theme: { preset: 'dashboard', palette: 'status' },
47
+ typography: { scale: 1.15 },
48
+ components: { grid: false }
49
+ }, { source: 'agent' });
50
+ ```
51
+
52
+ Keep the quick menu limited to theme, palette, font scale, and capability-supported visibility toggles. Use `scope: 'global'` for a page-wide update, the default chart scope for a single chart, and `chart.getState().preferences` for an auditable effective result. Preview both layers at `http://localhost:3000/playground/project-gallery.html` and `http://localhost:3000/playground/preferences-lab.html`.
53
+
54
+ ## Scenario 1: Integrate into a Web Project
55
+
56
+ Install the runtime in the host application:
57
+
58
+ ```bash
59
+ npm install @taylorwong/ichartjs@^2
60
+ ```
61
+
62
+ Use the normal component lifecycle:
63
+
64
+ ```js
65
+ import { createChart } from '@taylorwong/ichartjs';
66
+
67
+ const chart = createChart({
68
+ container: '#chart',
69
+ type: 'line',
70
+ renderer: 'svg',
71
+ data: { values: rows },
72
+ encoding: {
73
+ x: { field: 'month', type: 'category' },
74
+ y: { field: 'sales', type: 'quantitative' }
75
+ },
76
+ accessibility: { enabled: true }
77
+ });
78
+ ```
79
+
80
+ The host application owns data loading, authentication, routing, persistence, and state management. Call `setData()` for row changes, `update()` for Spec changes, and `destroy()` before replacing the component.
81
+
82
+ Use this scenario for dashboards, admin pages, project management products, editors, and embedded analytics.
83
+
84
+ ## Scenario 2: Ask a Coding Agent to Modify a Project
85
+
86
+ Give the Agent the intent, data source, desired output, and acceptance requirement:
87
+
88
+ ```text
89
+ Use @taylorwong/ichartjs in the current project. Inspect the order data,
90
+ choose and validate a monthly sales chart, add it to the existing analysis
91
+ page, run focused tests, and return the exact preview URL. Keep assumptions,
92
+ warnings, record lineage, and unsupported requests visible.
93
+ ```
94
+
95
+ The Agent should return:
96
+
97
+ - changed files and the validated Spec;
98
+ - field mappings and chart-selection reasons;
99
+ - assumptions, warnings, and unsupported requests;
100
+ - focused test results and self-check state;
101
+ - the host project's exact preview URL and manual acceptance steps.
102
+
103
+ The repository Playground is only for iChart.js examples:
104
+ `npm run playground` → `http://localhost:3000/playground/project-gallery.html`.
105
+ For a consumer project, return that project's own development URL.
106
+
107
+ ## Scenario 3: Use the Official Skill
108
+
109
+ Install the latest Skill with the standard Agent Skills CLI:
110
+
111
+ ```bash
112
+ npx skills add wanghetommy/ichartjs --skill ichartjs
113
+ ```
114
+
115
+ Install globally for Codex without prompts:
116
+
117
+ ```bash
118
+ npx skills add wanghetommy/ichartjs --skill ichartjs --agent codex --global --yes
119
+ ```
120
+
121
+ For reproducible installation, pin the released Skill directory:
122
+
123
+ ```bash
124
+ npx skills add https://github.com/wanghetommy/ichartjs/tree/v2.0.6/skills/ichartjs \
125
+ --agent codex --global --yes
126
+ ```
127
+
128
+ WorkBuddy users can import the same tagged GitHub directory through the host's Skill interface. Do not assume that `--agent workbuddy` exists unless the installed Skills CLI lists that adapter. A manual copy from `node_modules/@taylorwong/ichartjs/skills/ichartjs` remains a fallback for hosts with custom Skill directories.
129
+
130
+ After installation or selection, ask:
131
+
132
+ ```text
133
+ Use the iChart.js Skill. Read this dataset, create a project Burndown,
134
+ validate the Spec, generate a browser preview, and also export SVG and JSON.
135
+ Return the preview URL, artifact paths, warnings, assumptions, and lineage.
136
+ ```
137
+
138
+ The Skill routes the task to the public Runtime API and scenario guides. It does not replace the package, add a service endpoint, or create a second chart-selection implementation.
139
+
140
+ If the host can edit and run a JavaScript project, the output can be an interactive page. If it cannot run JavaScript, request an SVG, JSON, or code artifact instead.
141
+
142
+ ## Scenario 4: Create a One-Off Artifact
143
+
144
+ For a single chart, an Agent can create a small ESM script or standalone HTML page.
145
+
146
+ Recommended outputs:
147
+
148
+ - `chart.svg` for vector documents and zero-dependency headless generation;
149
+ - `chart.json` for a reproducible Spec and runtime checkpoint;
150
+ - `chart.png` or `chart.jpeg` for presentations and image sharing;
151
+ - `index.html` plus JavaScript when the recipient needs interaction.
152
+
153
+ Headless SVG and JSON work without an extra production dependency. Headless PNG/JPEG uses `chart.exportAsync()` and the optional `canvas` package. Do not add Python, MCP, HTTP, or a CLI merely to create one chart.
154
+
155
+ ## Scenario 5: Project and Diagram Workflows
156
+
157
+ Use the project and diagram contracts when the data has project semantics rather than generic numeric series:
158
+
159
+ - `gantt`, `timeline`, `milestone`, and `burndown` for delivery schedules;
160
+ - project analytics for capacity, velocity, release forecast, risk, and issue aging;
161
+ - `flow` and `swimlane` for process, ownership, responsibility, groups, ports, and controlled editing.
162
+
163
+ Preserve stable record, node, edge, lane, group, and port IDs. For business edits, return a preview before commit and include the audit result.
164
+
165
+ ## Scenario 6: CI and Scheduled Reports
166
+
167
+ Use a Node ESM script in the report job:
168
+
169
+ ```js
170
+ const svg = chart.export({ type: 'svg' });
171
+ const json = chart.export({ type: 'json' });
172
+ const png = await chart.exportAsync({ type: 'png' });
173
+ ```
174
+
175
+ Store JSON as the reproducible checkpoint and SVG/PNG as presentation artifacts. Report export errors as structured results instead of silently substituting another format.
176
+
177
+ ## Boundaries
178
+
179
+ - iChart.js is a JavaScript UI/runtime package, not a data service.
180
+ - A Skill gives Agents workflow instructions; it does not render without a JavaScript host.
181
+ - The host application owns authentication, storage, sharing, and application routing.
182
+ - There is no need for a core CLI, MCP server, HTTP service, or Python API for ordinary usage.
183
+ - If data is prepared in Python, export JSON/CSV and let a JavaScript process render the chart.
184
+ - Do not generate maps or 3D charts unless `getCapabilities()` explicitly declares them.
185
+
186
+ ## Agent Delivery Checklist
187
+
188
+ Every Agent response should state:
189
+
190
+ 1. selected chart/view and the reason;
191
+ 2. input fields, transforms, and stable IDs;
192
+ 3. validated Spec or structured repair request;
193
+ 4. assumptions, warnings, unsupported requests, and accessibility choices;
194
+ 5. explanation/state self-check results;
195
+ 6. exact preview URL, code files, or artifact paths;
196
+ 7. export format and any optional dependency required.
197
+
198
+ Related guides: [Quickstart](quickstart.md), [Frontend Integration](frontend-integration.md), [Coding Agent Integration](coding-agent-integration.md), [Runtime Contract](runtime-contract.md), [Project Scenario](project-scenario.md), and [Diagram Scenario](diagram-scenario.md).
@@ -4,6 +4,7 @@
4
4
 
5
5
  ## 选择场景
6
6
 
7
+ - [使用场景与输出](usage-scenarios.md)
7
8
  - [Agent 快速上手](quickstart.md)
8
9
  - [编码 Agent 集成](coding-agent-integration.md)
9
10
  - [前端项目集成](frontend-integration.md)
@@ -16,12 +16,16 @@ npm install @taylorwong/ichartjs@^2
16
16
 
17
17
  npm Registry 中无作用域的 `ichartjs` 是安全占位包,并非本项目。正式包名是 `@taylorwong/ichartjs`,优先从 npm 安装。
18
18
 
19
- Codex、WorkBuddy 和其他兼容 Agent Skills 的宿主可共同使用 `skills/ichartjs`。从仓库检出目录安装到 Codex:
19
+ 使用标准 Agent Skills CLI 安装官方 Skill:
20
20
 
21
21
  ```bash
22
- cp -R skills/ichartjs "${CODEX_HOME:-$HOME/.codex}/skills/"
22
+ npx skills add wanghetommy/ichartjs --skill ichartjs
23
23
  ```
24
24
 
25
+ Codex 全局无交互安装可追加 `--agent codex --global --yes`。需要固定发布版本时,安装 `https://github.com/wanghetommy/ichartjs/tree/v2.0.6/skills/ichartjs`。WorkBuddy 可通过自身 Skill 界面导入该带 Tag 的目录;只有当前 CLI 明确声明对应适配器时才使用宿主专用 `--agent` 参数。
26
+
27
+ 使用 `npx skills add wanghetommy/ichartjs --list` 验证发现结果,其中应包含 `ichartjs`。
28
+
25
29
  推荐请求:
26
30
 
27
31
  ```text
@@ -6,7 +6,7 @@ iChart.js 应作为普通 JavaScript UI 组件运行在浏览器应用中。数
6
6
  npm install @taylorwong/ichartjs@^2
7
7
  ```
8
8
 
9
- 无法访问 npm Registry 的环境请用 GitHub 源作为后备:`npm install github:wanghetommy/ichartjs#v2.0.4`。
9
+ 无法访问 npm Registry 的环境请用 GitHub 源作为后备:`npm install github:wanghetommy/ichartjs#v2.0.6`。
10
10
 
11
11
  ```js
12
12
  import { createChart } from '@taylorwong/ichartjs';
@@ -53,10 +53,10 @@ const obj = chart.export({ type: 'json', as: 'object' });
53
53
  const svg = chart.export({ type: 'svg' });
54
54
  const svgDataUrl = chart.export({ type: 'svg', as: 'dataurl' });
55
55
 
56
- // 3. PNG / JPEG:同步真光栅
57
- // 浏览器:任意 renderer 均可
58
- // 无头:需安装 npm i canvas,否则返回结构化错误 code=HEADLESS_EXPORT_UNSUPPORTED
56
+ // 3. PNG / JPEG:浏览器同步真光栅;Node 无头使用异步导出
57
+ // Node 无头:安装 npm i canvas 后,exportAsync() 可生成真光栅
59
58
  const png = typeof document !== 'undefined' ? chart.toDataURL('image/png') : null;
59
+ const headlessPng = await chart.exportAsync({ type: 'png' });
60
60
  ```
61
61
 
62
62
  ## Agent 输出要求