@skillcdn/console 0.5.0 → 0.5.2
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/README.md +87 -12
- package/SKILLCDN.md +3 -3
- package/dist/agent-page.d.ts.map +1 -1
- package/dist/agent-page.js +7 -6
- package/dist/agent-page.js.map +1 -1
- package/dist/api.d.ts +9 -7
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +8 -6
- package/dist/api.js.map +1 -1
- package/dist/charts.d.ts +103 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.js +182 -0
- package/dist/charts.js.map +1 -0
- package/dist/cli/cli.d.ts +58 -2
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +1742 -472
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/command-words.d.ts +20 -0
- package/dist/cli/command-words.d.ts.map +1 -0
- package/dist/cli/command-words.js +51 -0
- package/dist/cli/command-words.js.map +1 -0
- package/dist/cli/credentials.d.ts +54 -5
- package/dist/cli/credentials.d.ts.map +1 -1
- package/dist/cli/credentials.js +126 -20
- package/dist/cli/credentials.js.map +1 -1
- package/dist/cli/directory.d.ts +19 -4
- package/dist/cli/directory.d.ts.map +1 -1
- package/dist/cli/directory.js +16 -8
- package/dist/cli/directory.js.map +1 -1
- package/dist/cli/format.d.ts +70 -9
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +267 -40
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts +13 -4
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +101 -58
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/machine-check.d.ts +36 -0
- package/dist/cli/machine-check.d.ts.map +1 -0
- package/dist/cli/machine-check.js +151 -0
- package/dist/cli/machine-check.js.map +1 -0
- package/dist/cli/main.js +76 -2
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/pack.d.ts +69 -60
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +241 -270
- package/dist/cli/pack.js.map +1 -1
- package/dist/cli/plugin-check.d.ts +42 -0
- package/dist/cli/plugin-check.d.ts.map +1 -1
- package/dist/cli/plugin-check.js +221 -36
- package/dist/cli/plugin-check.js.map +1 -1
- package/dist/cli/plugin-cli.d.ts +6 -1
- package/dist/cli/plugin-cli.d.ts.map +1 -1
- package/dist/cli/plugin-cli.js +21 -4
- package/dist/cli/plugin-cli.js.map +1 -1
- package/dist/cli/plugin-main.js +1 -0
- package/dist/cli/plugin-main.js.map +1 -1
- package/dist/cli/runner-host.d.ts +7 -0
- package/dist/cli/runner-host.d.ts.map +1 -1
- package/dist/cli/runner-host.js +2 -0
- package/dist/cli/runner-host.js.map +1 -1
- package/dist/cli/secret-notes.d.ts +8 -0
- package/dist/cli/secret-notes.d.ts.map +1 -0
- package/dist/cli/secret-notes.js +48 -0
- package/dist/cli/secret-notes.js.map +1 -0
- package/dist/cli/serve.d.ts +33 -1
- package/dist/cli/serve.d.ts.map +1 -1
- package/dist/cli/serve.js +252 -3
- package/dist/cli/serve.js.map +1 -1
- package/dist/client.d.ts +54 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +77 -80
- package/dist/client.js.map +1 -1
- package/dist/components/agent-page.d.ts +164 -8
- package/dist/components/agent-page.d.ts.map +1 -1
- package/dist/components/agent-page.js +588 -151
- package/dist/components/agent-page.js.map +1 -1
- package/dist/components/agents.d.ts.map +1 -1
- package/dist/components/agents.js +1 -1
- package/dist/components/agents.js.map +1 -1
- package/dist/components/board.d.ts.map +1 -1
- package/dist/components/board.js +3 -2
- package/dist/components/board.js.map +1 -1
- package/dist/components/categories.js +1 -1
- package/dist/components/categories.js.map +1 -1
- package/dist/components/charts.d.ts +157 -0
- package/dist/components/charts.d.ts.map +1 -0
- package/dist/components/charts.js +182 -0
- package/dist/components/charts.js.map +1 -0
- package/dist/components/decision-list.d.ts.map +1 -1
- package/dist/components/decision-list.js +1 -1
- package/dist/components/decision-list.js.map +1 -1
- package/dist/components/desk-records.d.ts +102 -0
- package/dist/components/desk-records.d.ts.map +1 -0
- package/dist/components/desk-records.js +221 -0
- package/dist/components/desk-records.js.map +1 -0
- package/dist/components/desk.d.ts +85 -0
- package/dist/components/desk.d.ts.map +1 -0
- package/dist/components/desk.js +135 -0
- package/dist/components/desk.js.map +1 -0
- package/dist/components/event-feed.d.ts.map +1 -1
- package/dist/components/event-feed.js +7 -3
- package/dist/components/event-feed.js.map +1 -1
- package/dist/components/goals.d.ts +2 -0
- package/dist/components/goals.d.ts.map +1 -1
- package/dist/components/goals.js +1 -1
- package/dist/components/goals.js.map +1 -1
- package/dist/components/home.d.ts.map +1 -1
- package/dist/components/home.js +14 -6
- package/dist/components/home.js.map +1 -1
- package/dist/components/icon.d.ts +31 -0
- package/dist/components/icon.d.ts.map +1 -0
- package/dist/components/icon.js +169 -0
- package/dist/components/icon.js.map +1 -0
- package/dist/components/markdown.d.ts +6 -0
- package/dist/components/markdown.d.ts.map +1 -1
- package/dist/components/markdown.js +10 -2
- package/dist/components/markdown.js.map +1 -1
- package/dist/components/people.js +1 -1
- package/dist/components/people.js.map +1 -1
- package/dist/components/plugin-frame.d.ts.map +1 -1
- package/dist/components/plugin-frame.js +7 -0
- package/dist/components/plugin-frame.js.map +1 -1
- package/dist/components/plugin-settings.d.ts.map +1 -1
- package/dist/components/plugin-settings.js +54 -3
- package/dist/components/plugin-settings.js.map +1 -1
- package/dist/components/projects.d.ts +17 -4
- package/dist/components/projects.d.ts.map +1 -1
- package/dist/components/projects.js +51 -12
- package/dist/components/projects.js.map +1 -1
- package/dist/components/rules.d.ts +8 -10
- package/dist/components/rules.d.ts.map +1 -1
- package/dist/components/rules.js +35 -13
- package/dist/components/rules.js.map +1 -1
- package/dist/components/sessions.d.ts.map +1 -1
- package/dist/components/sessions.js +3 -2
- package/dist/components/sessions.js.map +1 -1
- package/dist/components/setup.d.ts +9 -3
- package/dist/components/setup.d.ts.map +1 -1
- package/dist/components/setup.js +12 -6
- package/dist/components/setup.js.map +1 -1
- package/dist/components/shell.d.ts.map +1 -1
- package/dist/components/shell.js +3 -2
- package/dist/components/shell.js.map +1 -1
- package/dist/components/tokens.js +1 -1
- package/dist/components/tokens.js.map +1 -1
- package/dist/components/ui.d.ts +5 -2
- package/dist/components/ui.d.ts.map +1 -1
- package/dist/components/ui.js +10 -7
- package/dist/components/ui.js.map +1 -1
- package/dist/connect-page.js +1 -1
- package/dist/connect-page.js.map +1 -1
- package/dist/console.css +1172 -106
- package/dist/console.d.ts +5 -0
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +52 -39
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +32 -33
- package/dist/data.js.map +1 -1
- package/dist/desk-page.d.ts +38 -0
- package/dist/desk-page.d.ts.map +1 -0
- package/dist/desk-page.js +184 -0
- package/dist/desk-page.js.map +1 -0
- package/dist/desk-records-page.d.ts +18 -0
- package/dist/desk-records-page.d.ts.map +1 -0
- package/dist/desk-records-page.js +130 -0
- package/dist/desk-records-page.js.map +1 -0
- package/dist/desk-records.d.ts +247 -0
- package/dist/desk-records.d.ts.map +1 -0
- package/dist/desk-records.js +543 -0
- package/dist/desk-records.js.map +1 -0
- package/dist/desk.d.ts +122 -0
- package/dist/desk.d.ts.map +1 -0
- package/dist/desk.js +211 -0
- package/dist/desk.js.map +1 -0
- package/dist/feed-stream.d.ts +39 -0
- package/dist/feed-stream.d.ts.map +1 -0
- package/dist/feed-stream.js +117 -0
- package/dist/feed-stream.js.map +1 -0
- package/dist/home-tiles.d.ts +19 -3
- package/dist/home-tiles.d.ts.map +1 -1
- package/dist/home-tiles.js +147 -42
- package/dist/home-tiles.js.map +1 -1
- package/dist/i18n/en.d.ts +228 -6
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +309 -9
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +366 -85
- package/dist/i18n/ko.js.map +1 -1
- package/dist/i18n/particles.d.ts +7 -0
- package/dist/i18n/particles.d.ts.map +1 -0
- package/dist/i18n/particles.js +72 -0
- package/dist/i18n/particles.js.map +1 -0
- package/dist/icons/glyphs.d.ts +605 -0
- package/dist/icons/glyphs.d.ts.map +1 -0
- package/dist/icons/glyphs.js +104 -0
- package/dist/icons/glyphs.js.map +1 -0
- package/dist/icons/index.d.ts +59 -0
- package/dist/icons/index.d.ts.map +1 -0
- package/dist/icons/index.js +157 -0
- package/dist/icons/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/limits.d.ts +20 -0
- package/dist/limits.d.ts.map +1 -1
- package/dist/limits.js +20 -0
- package/dist/limits.js.map +1 -1
- package/dist/marks.d.ts +9 -0
- package/dist/marks.d.ts.map +1 -1
- package/dist/marks.js +9 -0
- package/dist/marks.js.map +1 -1
- package/dist/onboarding.d.ts +6 -0
- package/dist/onboarding.d.ts.map +1 -1
- package/dist/onboarding.js +5 -5
- package/dist/onboarding.js.map +1 -1
- package/dist/plugin/context.d.ts +42 -11
- package/dist/plugin/context.d.ts.map +1 -1
- package/dist/plugin/limits.d.ts +2 -0
- package/dist/plugin/limits.d.ts.map +1 -1
- package/dist/plugin/limits.js +2 -0
- package/dist/plugin/limits.js.map +1 -1
- package/dist/plugin/manifest.d.ts +13 -0
- package/dist/plugin/manifest.d.ts.map +1 -1
- package/dist/plugin/manifest.js +30 -3
- package/dist/plugin/manifest.js.map +1 -1
- package/dist/plugin/rest-schemas.d.ts +55 -0
- package/dist/plugin/rest-schemas.d.ts.map +1 -1
- package/dist/plugin/rest-schemas.js +37 -0
- package/dist/plugin/rest-schemas.js.map +1 -1
- package/dist/plugin/sandbox.d.ts.map +1 -1
- package/dist/plugin/sandbox.js +4 -1
- package/dist/plugin/sandbox.js.map +1 -1
- package/dist/plugin/testing.d.ts +6 -2
- package/dist/plugin/testing.d.ts.map +1 -1
- package/dist/plugin/testing.js +52 -10
- package/dist/plugin/testing.js.map +1 -1
- package/dist/plugin/web.d.ts +3 -0
- package/dist/plugin/web.d.ts.map +1 -1
- package/dist/plugin/web.js +5 -1
- package/dist/plugin/web.js.map +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/dist/records.d.ts +283 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +543 -0
- package/dist/records.js.map +1 -0
- package/dist/routes.d.ts +3 -1
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +3 -1
- package/dist/routes.js.map +1 -1
- package/dist/rules.d.ts +30 -11
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +98 -45
- package/dist/rules.js.map +1 -1
- package/dist/runner/acp.d.ts +1 -1
- package/dist/runner/acp.d.ts.map +1 -1
- package/dist/runner/acp.js +32 -21
- package/dist/runner/acp.js.map +1 -1
- package/dist/runner/awake.d.ts +35 -0
- package/dist/runner/awake.d.ts.map +1 -0
- package/dist/runner/awake.js +95 -0
- package/dist/runner/awake.js.map +1 -0
- package/dist/runner/claude.d.ts +1 -1
- package/dist/runner/claude.d.ts.map +1 -1
- package/dist/runner/claude.js +100 -18
- package/dist/runner/claude.js.map +1 -1
- package/dist/runner/codex.d.ts +1 -1
- package/dist/runner/codex.d.ts.map +1 -1
- package/dist/runner/codex.js +20 -17
- package/dist/runner/codex.js.map +1 -1
- package/dist/runner/config.d.ts +5 -0
- package/dist/runner/config.d.ts.map +1 -1
- package/dist/runner/config.js +9 -0
- package/dist/runner/config.js.map +1 -1
- package/dist/runner/desk.d.ts +43 -2
- package/dist/runner/desk.d.ts.map +1 -1
- package/dist/runner/desk.js +168 -13
- package/dist/runner/desk.js.map +1 -1
- package/dist/runner/process.d.ts.map +1 -1
- package/dist/runner/process.js +11 -4
- package/dist/runner/process.js.map +1 -1
- package/dist/runner/redact.d.ts +39 -4
- package/dist/runner/redact.d.ts.map +1 -1
- package/dist/runner/redact.js +81 -5
- package/dist/runner/redact.js.map +1 -1
- package/dist/runner/runner.d.ts +28 -3
- package/dist/runner/runner.d.ts.map +1 -1
- package/dist/runner/runner.js +371 -54
- package/dist/runner/runner.js.map +1 -1
- package/dist/runner/slack.d.ts.map +1 -1
- package/dist/runner/slack.js +10 -4
- package/dist/runner/slack.js.map +1 -1
- package/dist/runner/task-scheduler.d.ts +20 -0
- package/dist/runner/task-scheduler.d.ts.map +1 -1
- package/dist/runner/task-scheduler.js +34 -4
- package/dist/runner/task-scheduler.js.map +1 -1
- package/dist/runner/types.d.ts +51 -1
- package/dist/runner/types.d.ts.map +1 -1
- package/dist/runner/types.js +26 -0
- package/dist/runner/types.js.map +1 -1
- package/dist/runner.d.ts +6 -6
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +5 -5
- package/dist/runner.js.map +1 -1
- package/dist/schemas.d.ts +603 -6
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +156 -20
- package/dist/schemas.js.map +1 -1
- package/dist/services.d.ts +22 -5
- package/dist/services.d.ts.map +1 -1
- package/dist/services.js +41 -17
- package/dist/services.js.map +1 -1
- package/dist/setup-guide.d.ts +17 -4
- package/dist/setup-guide.d.ts.map +1 -1
- package/dist/setup-guide.js +48 -41
- package/dist/setup-guide.js.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +5 -1
- package/dist/tokens.js.map +1 -1
- package/dist/vocabulary.d.ts +21 -3
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +19 -3
- package/dist/vocabulary.js.map +1 -1
- package/docs/specs/cli.md +73 -44
- package/docs/specs/plugins.md +40 -22
- package/docs/specs/records.md +113 -0
- package/docs/specs/rest.md +30 -21
- package/docs/specs/runner.md +46 -22
- package/package.json +11 -2
- package/skills/building-a-console/SKILL.md +4 -4
- package/skills/building-a-plugin/SKILL.md +6 -6
- package/skills/deploying-a-console/SKILL.md +4 -4
- package/skills/deploying-a-console/references/resources.md +41 -4
- package/skills/deploying-a-console/references/running-it-again.md +3 -2
- package/skills/keeping-a-desk/SKILL.md +133 -0
- package/skills/keeping-a-desk/collections.md +96 -0
- package/skills/planning-the-board/SKILL.md +14 -18
- package/skills/planning-the-board/references/a-task.md +2 -2
- package/skills/planning-the-board/references/project-rules.md +13 -14
- package/skills/planning-the-board/references/setting-up.md +15 -13
- package/skills/running-an-agent/SKILL.md +47 -56
- package/skills/working-the-board/SKILL.md +63 -44
- package/skills/working-the-board/references/terms.md +9 -5
- package/skills/working-the-board/references/the-pack.md +12 -10
- package/skills/working-the-board/references/the-sentence.md +2 -2
- package/src/agent-page.tsx +16 -2
- package/src/api.ts +109 -3
- package/src/charts.ts +250 -0
- package/src/cli/cli.ts +2226 -580
- package/src/cli/command-words.ts +56 -0
- package/src/cli/credentials.ts +181 -20
- package/src/cli/directory.ts +28 -10
- package/src/cli/format.ts +332 -49
- package/src/cli/help.ts +113 -57
- package/src/cli/machine-check.ts +223 -0
- package/src/cli/main.ts +72 -2
- package/src/cli/pack.ts +333 -372
- package/src/cli/plugin-check.ts +275 -34
- package/src/cli/plugin-cli.ts +28 -4
- package/src/cli/plugin-main.ts +1 -0
- package/src/cli/runner-host.ts +8 -0
- package/src/cli/secret-notes.ts +63 -0
- package/src/cli/serve.ts +295 -2
- package/src/client.ts +215 -177
- package/src/components/agent-page.tsx +1044 -281
- package/src/components/agents.tsx +9 -5
- package/src/components/board.tsx +3 -15
- package/src/components/categories.tsx +2 -2
- package/src/components/charts.tsx +680 -0
- package/src/components/decision-list.tsx +11 -7
- package/src/components/desk-records.tsx +724 -0
- package/src/components/desk.tsx +471 -0
- package/src/components/event-feed.tsx +12 -3
- package/src/components/goals.tsx +33 -25
- package/src/components/home.tsx +42 -6
- package/src/components/icon.tsx +337 -0
- package/src/components/markdown.tsx +22 -2
- package/src/components/people.tsx +1 -1
- package/src/components/plugin-frame.tsx +7 -0
- package/src/components/plugin-settings.tsx +171 -12
- package/src/components/projects.tsx +68 -17
- package/src/components/rules.tsx +94 -34
- package/src/components/sessions.tsx +2 -13
- package/src/components/setup.tsx +20 -5
- package/src/components/shell.tsx +3 -20
- package/src/components/tokens.tsx +1 -1
- package/src/components/ui.tsx +16 -8
- package/src/connect-page.tsx +1 -1
- package/src/console.tsx +104 -62
- package/src/data.ts +37 -34
- package/src/desk-page.tsx +332 -0
- package/src/desk-records-page.tsx +256 -0
- package/src/desk-records.ts +808 -0
- package/src/desk.ts +329 -0
- package/src/feed-stream.ts +144 -0
- package/src/home-tiles.ts +170 -46
- package/src/i18n/en.ts +323 -11
- package/src/i18n/ko.ts +378 -87
- package/src/i18n/particles.ts +79 -0
- package/src/icons/glyphs.ts +112 -0
- package/src/icons/index.ts +195 -0
- package/src/index.ts +125 -0
- package/src/limits.ts +20 -0
- package/src/marks.ts +12 -0
- package/src/onboarding.ts +14 -6
- package/src/plugin/context.ts +55 -12
- package/src/plugin/limits.ts +2 -0
- package/src/plugin/manifest.ts +38 -2
- package/src/plugin/rest-schemas.ts +41 -0
- package/src/plugin/sandbox.ts +4 -1
- package/src/plugin/testing.ts +63 -12
- package/src/plugin/web.ts +9 -2
- package/src/plugin.ts +2 -0
- package/src/records.ts +702 -0
- package/src/routes.ts +3 -1
- package/src/rules.ts +108 -47
- package/src/runner/acp.ts +49 -30
- package/src/runner/awake.ts +135 -0
- package/src/runner/claude.ts +131 -26
- package/src/runner/codex.ts +37 -26
- package/src/runner/config.ts +9 -0
- package/src/runner/desk.ts +200 -15
- package/src/runner/process.ts +11 -4
- package/src/runner/redact.ts +92 -6
- package/src/runner/runner.ts +457 -56
- package/src/runner/slack.ts +10 -4
- package/src/runner/task-scheduler.ts +36 -4
- package/src/runner/types.ts +67 -1
- package/src/runner.ts +27 -2
- package/src/schemas.ts +177 -18
- package/src/services.ts +55 -16
- package/src/setup-guide.ts +49 -40
- package/src/styles/README.md +16 -5
- package/src/styles/base.css +17 -0
- package/src/styles/console.css +10 -0
- package/src/styles/drawn-by-pages.json +1 -1
- package/src/styles/pages/agents.css +103 -1
- package/src/styles/pages/board.css +0 -10
- package/src/styles/pages/calendar.css +1 -1
- package/src/styles/pages/connect.css +0 -10
- package/src/styles/pages/decisions.css +3 -1
- package/src/styles/pages/desk.css +126 -0
- package/src/styles/pages/documents.css +5 -0
- package/src/styles/pages/feed.css +5 -2
- package/src/styles/pages/home.css +5 -0
- package/src/styles/pages/roadmap.css +2 -2
- package/src/styles/pages/settings.css +11 -0
- package/src/styles/pages/task.css +0 -20
- package/src/styles/pages/thread.css +1 -1
- package/src/styles/parts/bars.css +80 -0
- package/src/styles/parts/calendar.css +1 -1
- package/src/styles/parts/callout.css +1 -0
- package/src/styles/parts/chart.css +173 -0
- package/src/styles/parts/detail.css +22 -0
- package/src/styles/parts/empty.css +2 -0
- package/src/styles/parts/eyebrow.css +1 -1
- package/src/styles/parts/facts.css +1 -1
- package/src/styles/parts/figures.css +65 -0
- package/src/styles/parts/form.css +2 -1
- package/src/styles/parts/icon.css +191 -0
- package/src/styles/parts/input.css +14 -4
- package/src/styles/parts/legend.css +48 -0
- package/src/styles/parts/mark.css +36 -0
- package/src/styles/parts/menu.css +1 -7
- package/src/styles/parts/page.css +1 -1
- package/src/styles/parts/panel.css +10 -0
- package/src/styles/parts/person.css +5 -2
- package/src/styles/parts/progress.css +5 -2
- package/src/styles/parts/rows.css +1 -0
- package/src/styles/parts/series.css +32 -0
- package/src/styles/parts/settings.css +5 -0
- package/src/styles/parts/share.css +25 -0
- package/src/styles/parts/spark.css +23 -0
- package/src/styles/parts/stat.css +69 -0
- package/src/styles/tokens.css +31 -10
- package/src/tokens.ts +5 -1
- package/src/vocabulary.ts +25 -3
- package/template/desk-web/README.md +8 -0
- package/template/desk-web/index.html +13 -0
- package/template/desk-web/package.json +25 -0
- package/template/desk-web/src/main.tsx +24 -0
- package/template/desk-web/src/page.tsx +51 -0
- package/template/desk-web/tsconfig.json +16 -0
- package/template/desk-web/vite.config.ts +15 -0
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import {
|
|
3
|
+
barLengths,
|
|
4
|
+
CHART_LABEL_ROOM,
|
|
5
|
+
chartLayout,
|
|
6
|
+
chartMeasure,
|
|
7
|
+
columnOf,
|
|
8
|
+
labelledPoints,
|
|
9
|
+
labelStep,
|
|
10
|
+
seriesClass,
|
|
11
|
+
shareParts,
|
|
12
|
+
sparkPoints,
|
|
13
|
+
} from "../charts.js";
|
|
14
|
+
|
|
15
|
+
// The charts (ADR-0123): a figure, a list of bars, a chart over time, a sparkline, a share, the
|
|
16
|
+
// legend they share and a table of figures, each a part of the console's look with its class in
|
|
17
|
+
// the stylesheet and its row in the catalogue. A component here places and the stylesheet
|
|
18
|
+
// draws: every measure is an attribute of an SVG, a share of the box the stylesheet gives it,
|
|
19
|
+
// and no colour and no size is written here. Each takes its figures as props and nothing from
|
|
20
|
+
// the network, says what it shows to a reader who cannot see it (its figures stand beside the
|
|
21
|
+
// drawing as text, or under it as a table), and renders what it is given as text. They lean on
|
|
22
|
+
// React and the measures alone, so that a page of a desk and a plugin's bundle take them
|
|
23
|
+
// without taking the console.
|
|
24
|
+
|
|
25
|
+
/** A number as a language writes it; the browser's language where none is named. */
|
|
26
|
+
function amountWords(value: number, language: string | undefined): string {
|
|
27
|
+
return value.toLocaleString(language, { maximumFractionDigits: 2 });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A share of one as a language writes it: 46%. A part that is something is never said to be
|
|
32
|
+
* none, nor a part that is not the whole to be all of it: under 1% and over 99% say so.
|
|
33
|
+
*/
|
|
34
|
+
function shareWords(share: number, language: string | undefined): string {
|
|
35
|
+
const words = (amount: number) =>
|
|
36
|
+
amount.toLocaleString(language, { style: "percent", maximumFractionDigits: 0 });
|
|
37
|
+
return share > 0 && share < 0.005
|
|
38
|
+
? `<${words(0.01)}`
|
|
39
|
+
: share < 1 && share >= 0.995
|
|
40
|
+
? `>${words(0.99)}`
|
|
41
|
+
: words(share);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An amount of a scale as a language writes it short: 1.5M, 20K. A scale that reaches ten
|
|
46
|
+
* thousand is marked so, since its marks are read at a glance and the figures themselves stand
|
|
47
|
+
* in full beside it.
|
|
48
|
+
*/
|
|
49
|
+
function shortWords(value: number, language: string | undefined): string {
|
|
50
|
+
return value.toLocaleString(language, { notation: "compact", maximumFractionDigits: 1 });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The classes of an element: those that are there. */
|
|
54
|
+
function classes(...names: readonly (string | false | undefined)[]): string {
|
|
55
|
+
return names.filter((name) => typeof name === "string" && name.length > 0).join(" ");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface LegendItem {
|
|
59
|
+
readonly name: string;
|
|
60
|
+
/** The figure beside the name, where the chart is a whole in parts. */
|
|
61
|
+
readonly words?: string | undefined;
|
|
62
|
+
/** Which of the six colours, from nought; its place in the list where left out. */
|
|
63
|
+
readonly series?: number | undefined;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface LegendProps {
|
|
67
|
+
readonly items: readonly LegendItem[];
|
|
68
|
+
/** What the key mirrors: a box for what is filled, a stroke for a line. */
|
|
69
|
+
readonly mark?: "box" | "line" | undefined;
|
|
70
|
+
/** What the legend is of, for a reader who cannot see it. */
|
|
71
|
+
readonly label?: string | undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The key of a chart: each series' colour beside its name. A name is text, never the series' colour. */
|
|
75
|
+
export function Legend(props: LegendProps) {
|
|
76
|
+
return (
|
|
77
|
+
<ul className="sc-legend" aria-label={props.label}>
|
|
78
|
+
{props.items.map((item, index) => (
|
|
79
|
+
<li key={item.name} className="sc-legend-item">
|
|
80
|
+
<span
|
|
81
|
+
className={classes(
|
|
82
|
+
"sc-legend-key",
|
|
83
|
+
props.mark === "line" && "sc-legend-key-line",
|
|
84
|
+
seriesClass(item.series ?? index),
|
|
85
|
+
)}
|
|
86
|
+
aria-hidden="true"
|
|
87
|
+
/>
|
|
88
|
+
<span className="sc-legend-name">{item.name}</span>
|
|
89
|
+
{item.words !== undefined && <span className="sc-legend-value">{item.words}</span>}
|
|
90
|
+
</li>
|
|
91
|
+
))}
|
|
92
|
+
</ul>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface SparklineProps {
|
|
97
|
+
/** The amounts in order, the latest last; what is no amount is passed over. */
|
|
98
|
+
readonly values: readonly (number | undefined)[];
|
|
99
|
+
/** What it shows, for a reader who cannot see it; left out, it is an ornament beside words that say it. */
|
|
100
|
+
readonly label?: string | undefined;
|
|
101
|
+
/** Which of the six colours its last point is drawn in, from nought. */
|
|
102
|
+
readonly series?: number | undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** A sparkline: the run of a figure with no axis, its last amount the dot. */
|
|
106
|
+
export function Sparkline(props: SparklineProps) {
|
|
107
|
+
const points = sparkPoints(props.values);
|
|
108
|
+
const last = points.at(-1);
|
|
109
|
+
return (
|
|
110
|
+
<svg
|
|
111
|
+
className={classes("sc-spark", seriesClass(props.series ?? 0))}
|
|
112
|
+
role={props.label === undefined ? undefined : "img"}
|
|
113
|
+
aria-label={props.label}
|
|
114
|
+
aria-hidden={props.label === undefined ? true : undefined}
|
|
115
|
+
focusable="false"
|
|
116
|
+
>
|
|
117
|
+
{points.slice(1).map((point, index) => {
|
|
118
|
+
const from = points[index] ?? point;
|
|
119
|
+
return (
|
|
120
|
+
<line
|
|
121
|
+
key={`${from.x} ${point.x}`}
|
|
122
|
+
className="sc-spark-line"
|
|
123
|
+
x1={chartMeasure(from.x)}
|
|
124
|
+
y1={chartMeasure(from.y)}
|
|
125
|
+
x2={chartMeasure(point.x)}
|
|
126
|
+
y2={chartMeasure(point.y)}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
})}
|
|
130
|
+
{last !== undefined && (
|
|
131
|
+
<circle className="sc-spark-dot" cx={chartMeasure(last.x)} cy={chartMeasure(last.y)} />
|
|
132
|
+
)}
|
|
133
|
+
</svg>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** How a figure changed: the amount with its sign, against what, and whether that is good. */
|
|
138
|
+
export interface StatChange {
|
|
139
|
+
/** The change as words, its sign first: "+12%", "-3". */
|
|
140
|
+
readonly words: string;
|
|
141
|
+
/** What it is measured against: "than last week". */
|
|
142
|
+
readonly against?: string | undefined;
|
|
143
|
+
/** Whether the change is good or bad, where the page knows; neither where left out. */
|
|
144
|
+
readonly tone?: "good" | "bad" | undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface StatProps {
|
|
148
|
+
readonly label: ReactNode;
|
|
149
|
+
/** The figure, as the page writes it: "12,480", "3.2%", "4 h". */
|
|
150
|
+
readonly value: ReactNode;
|
|
151
|
+
readonly change?: StatChange | undefined;
|
|
152
|
+
/** The run the figure came by, the latest last, drawn as a sparkline. */
|
|
153
|
+
readonly trend?: readonly (number | undefined)[] | undefined;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** A figure: a number under its name and, where given, how it changed and the run it came by. One of a `Stats`. */
|
|
157
|
+
export function Stat(props: StatProps) {
|
|
158
|
+
const { change, trend } = props;
|
|
159
|
+
return (
|
|
160
|
+
<div className="sc-stat">
|
|
161
|
+
<dt className="sc-stat-label">{props.label}</dt>
|
|
162
|
+
<dd className="sc-stat-value">{props.value}</dd>
|
|
163
|
+
{change !== undefined && (
|
|
164
|
+
<dd
|
|
165
|
+
className={classes(
|
|
166
|
+
"sc-stat-change",
|
|
167
|
+
change.tone !== undefined && `sc-stat-change-${change.tone}`,
|
|
168
|
+
)}
|
|
169
|
+
>
|
|
170
|
+
<span className="sc-stat-delta">{change.words}</span>
|
|
171
|
+
{change.against !== undefined && <> {change.against}</>}
|
|
172
|
+
</dd>
|
|
173
|
+
)}
|
|
174
|
+
{trend !== undefined && (
|
|
175
|
+
<dd className="sc-stat-trend">
|
|
176
|
+
<Sparkline values={trend} />
|
|
177
|
+
</dd>
|
|
178
|
+
)}
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Figures side by side, as many across as there is room for. */
|
|
184
|
+
export function Stats(props: {
|
|
185
|
+
readonly children: ReactNode;
|
|
186
|
+
/** What the figures are of, for a reader who cannot see the heading over them. */
|
|
187
|
+
readonly label?: string | undefined;
|
|
188
|
+
}) {
|
|
189
|
+
return (
|
|
190
|
+
<dl className="sc-stats" aria-label={props.label}>
|
|
191
|
+
{props.children}
|
|
192
|
+
</dl>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export interface BarRow {
|
|
197
|
+
/** What tells the row apart: needed where the label is not text, or two rows have one label. */
|
|
198
|
+
readonly id?: string | undefined;
|
|
199
|
+
/** The row's name: text, or what the page shows for it, a mark with a name or a badge. */
|
|
200
|
+
readonly label: ReactNode;
|
|
201
|
+
/** Where the label leads; text alone where left out. */
|
|
202
|
+
readonly href?: string | undefined;
|
|
203
|
+
/** What stands after the label on its line: a badge, say. */
|
|
204
|
+
readonly note?: ReactNode | undefined;
|
|
205
|
+
/** The amount the bar is as long as. What is no amount, or below nothing, has no bar. */
|
|
206
|
+
readonly value: number | undefined;
|
|
207
|
+
/** The amount as words, where the page writes it its own way: "3.2%", "4 h". */
|
|
208
|
+
readonly words?: string | undefined;
|
|
209
|
+
/** Which of the six colours, from nought; the first where left out, as bars of one kind are one colour. */
|
|
210
|
+
readonly series?: number | undefined;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface BarListProps {
|
|
214
|
+
/** What the list is of, for a reader who cannot see the heading over it. */
|
|
215
|
+
readonly label: string;
|
|
216
|
+
readonly rows: readonly BarRow[];
|
|
217
|
+
/** What a full bar stands for; the largest amount where left out. */
|
|
218
|
+
readonly whole?: number | undefined;
|
|
219
|
+
/** Whether the order says something: a ranking is numbered for a reader who cannot see it. */
|
|
220
|
+
readonly ranked?: boolean | undefined;
|
|
221
|
+
/** The language the amounts are written in; the browser's where left out. */
|
|
222
|
+
readonly language?: string | undefined;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** A list of bars: a ranking or a comparison, each row a name, its figure and its bar. */
|
|
226
|
+
export function BarList(props: BarListProps) {
|
|
227
|
+
const lengths = barLengths(
|
|
228
|
+
props.rows.map((row) => row.value),
|
|
229
|
+
props.whole,
|
|
230
|
+
);
|
|
231
|
+
const List = props.ranked === true ? "ol" : "ul";
|
|
232
|
+
// A row is told apart by what the page names it, by its label where that is text, and
|
|
233
|
+
// failing both by its place, which a list given once keeps.
|
|
234
|
+
const rows = props.rows.map((row, at) => ({
|
|
235
|
+
row,
|
|
236
|
+
length: lengths[at] ?? 0,
|
|
237
|
+
key: row.id ?? (typeof row.label === "string" ? row.label : `row ${at}`),
|
|
238
|
+
}));
|
|
239
|
+
return (
|
|
240
|
+
<List className="sc-bars" aria-label={props.label}>
|
|
241
|
+
{rows.map(({ row, length, key }) => {
|
|
242
|
+
return (
|
|
243
|
+
<li key={key} className="sc-bars-row">
|
|
244
|
+
<span className="sc-bars-label">
|
|
245
|
+
{row.href === undefined ? row.label : <a href={row.href}>{row.label}</a>}
|
|
246
|
+
{row.note !== undefined && <> {row.note}</>}
|
|
247
|
+
</span>
|
|
248
|
+
<span className="sc-bars-value">
|
|
249
|
+
{row.words ?? (row.value === undefined ? "" : amountWords(row.value, props.language))}
|
|
250
|
+
</span>
|
|
251
|
+
<svg
|
|
252
|
+
className={classes("sc-bars-bar", seriesClass(row.series ?? 0))}
|
|
253
|
+
aria-hidden="true"
|
|
254
|
+
focusable="false"
|
|
255
|
+
>
|
|
256
|
+
{length > 0 && (
|
|
257
|
+
// The bar's own box is as long as the amount and cuts what is drawn in it: the
|
|
258
|
+
// shape starts before the box and ends with it, so that the bar is square where
|
|
259
|
+
// it starts and round where it ends.
|
|
260
|
+
<svg width={chartMeasure(length)} height="100%" aria-hidden="true">
|
|
261
|
+
<rect className="sc-bars-fill" x="-50%" width="150%" height="100%" />
|
|
262
|
+
</svg>
|
|
263
|
+
)}
|
|
264
|
+
</svg>
|
|
265
|
+
</li>
|
|
266
|
+
);
|
|
267
|
+
})}
|
|
268
|
+
</List>
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface SharePartItem {
|
|
273
|
+
readonly name: string;
|
|
274
|
+
/** The part's amount. What is no amount, or below nothing, has no share. */
|
|
275
|
+
readonly value: number | undefined;
|
|
276
|
+
/** The amount as words, where the page writes it its own way. */
|
|
277
|
+
readonly words?: string | undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export interface ShareBarProps {
|
|
281
|
+
/** What the whole is, for a reader who cannot see the heading over it. */
|
|
282
|
+
readonly label: string;
|
|
283
|
+
/** The parts in the order they stand; six at most are told apart, so fold the rest into one. */
|
|
284
|
+
readonly parts: readonly SharePartItem[];
|
|
285
|
+
/** The language the amounts and the shares are written in; the browser's where left out. */
|
|
286
|
+
readonly language?: string | undefined;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** A share: one whole in its parts, as one bar, with each part's name, amount and share under it. */
|
|
290
|
+
export function ShareBar(props: ShareBarProps) {
|
|
291
|
+
const places = shareParts(props.parts.map((part) => part.value));
|
|
292
|
+
const drawn = places.flatMap((place, index) => (place.width > 0 ? [{ place, index }] : []));
|
|
293
|
+
return (
|
|
294
|
+
// biome-ignore lint/a11y/useSemanticElements: a group with a name, which a fieldset is only of a form's controls
|
|
295
|
+
<div className="sc-share" role="group" aria-label={props.label}>
|
|
296
|
+
<svg className="sc-share-bar" aria-hidden="true" focusable="false">
|
|
297
|
+
{drawn.map(({ place, index }) => (
|
|
298
|
+
<rect
|
|
299
|
+
key={props.parts[index]?.name}
|
|
300
|
+
className={classes("sc-share-part", seriesClass(index))}
|
|
301
|
+
x={chartMeasure(place.start)}
|
|
302
|
+
width={chartMeasure(place.width)}
|
|
303
|
+
height="100%"
|
|
304
|
+
/>
|
|
305
|
+
))}
|
|
306
|
+
{drawn.slice(1).map(({ place, index }) => (
|
|
307
|
+
<line
|
|
308
|
+
key={props.parts[index]?.name}
|
|
309
|
+
className="sc-share-gap"
|
|
310
|
+
x1={chartMeasure(place.start)}
|
|
311
|
+
x2={chartMeasure(place.start)}
|
|
312
|
+
y1="0"
|
|
313
|
+
y2="100%"
|
|
314
|
+
/>
|
|
315
|
+
))}
|
|
316
|
+
</svg>
|
|
317
|
+
<Legend
|
|
318
|
+
items={props.parts.map((part, index) => {
|
|
319
|
+
const amount =
|
|
320
|
+
part.words ??
|
|
321
|
+
(part.value === undefined ? undefined : amountWords(part.value, props.language));
|
|
322
|
+
const share = shareWords(places[index]?.share ?? 0, props.language);
|
|
323
|
+
return {
|
|
324
|
+
name: part.name,
|
|
325
|
+
series: index,
|
|
326
|
+
words: amount === undefined ? share : `${amount} · ${share}`,
|
|
327
|
+
};
|
|
328
|
+
})}
|
|
329
|
+
/>
|
|
330
|
+
</div>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export interface FigureRow {
|
|
335
|
+
/** What tells the row apart: needed where the label is not text, or two rows have one label. */
|
|
336
|
+
readonly id?: string | undefined;
|
|
337
|
+
/** The row's name: text, or what the page shows for it, a day or a badge. */
|
|
338
|
+
readonly label: ReactNode;
|
|
339
|
+
/** The row's figures, one a column after the first: a number is written as the language writes it, words as they are, nothing where there is none. */
|
|
340
|
+
readonly values: readonly (number | string | undefined)[];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface FigureTableProps {
|
|
344
|
+
/** What the table is of: its caption. */
|
|
345
|
+
readonly caption: string;
|
|
346
|
+
/** Whether the caption is shown, or only said to a reader who cannot see the heading over the table. */
|
|
347
|
+
readonly captionShown?: boolean | undefined;
|
|
348
|
+
/** The columns' heads, the first the head of the rows' names. */
|
|
349
|
+
readonly columns: readonly string[];
|
|
350
|
+
readonly rows: readonly FigureRow[];
|
|
351
|
+
/** What the rows come to, under them. */
|
|
352
|
+
readonly foot?: FigureRow | undefined;
|
|
353
|
+
/** The language the numbers are written in; the browser's where left out. */
|
|
354
|
+
readonly language?: string | undefined;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** A row's cells after its name: as many as there are columns for. */
|
|
358
|
+
function figureCells(
|
|
359
|
+
row: FigureRow,
|
|
360
|
+
columns: readonly string[],
|
|
361
|
+
language: string | undefined,
|
|
362
|
+
): ReactNode {
|
|
363
|
+
return columns.slice(1).map((column, index) => {
|
|
364
|
+
const value = row.values[index];
|
|
365
|
+
return <td key={column}>{typeof value === "number" ? amountWords(value, language) : value}</td>;
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** A table of figures: rows by columns, the names at the start and the numbers lined up at the end. */
|
|
370
|
+
export function FigureTable(props: FigureTableProps) {
|
|
371
|
+
const { columns, foot } = props;
|
|
372
|
+
// A row is told apart as a bar's is: by what the page names it, by its label where that is
|
|
373
|
+
// text, and failing both by its place.
|
|
374
|
+
const rows = props.rows.map((row, at) => ({
|
|
375
|
+
row,
|
|
376
|
+
key: row.id ?? (typeof row.label === "string" ? row.label : `row ${at}`),
|
|
377
|
+
}));
|
|
378
|
+
return (
|
|
379
|
+
<div className="sc-figures-box">
|
|
380
|
+
<table className="sc-figures">
|
|
381
|
+
<caption className={classes(props.captionShown !== true && "sc-visually-hidden")}>
|
|
382
|
+
{props.caption}
|
|
383
|
+
</caption>
|
|
384
|
+
<thead>
|
|
385
|
+
<tr>
|
|
386
|
+
{columns.map((column) => (
|
|
387
|
+
<th key={column} scope="col">
|
|
388
|
+
{column}
|
|
389
|
+
</th>
|
|
390
|
+
))}
|
|
391
|
+
</tr>
|
|
392
|
+
</thead>
|
|
393
|
+
<tbody>
|
|
394
|
+
{rows.map(({ row, key }) => (
|
|
395
|
+
<tr key={key}>
|
|
396
|
+
<th scope="row">{row.label}</th>
|
|
397
|
+
{figureCells(row, columns, props.language)}
|
|
398
|
+
</tr>
|
|
399
|
+
))}
|
|
400
|
+
</tbody>
|
|
401
|
+
{foot !== undefined && (
|
|
402
|
+
<tfoot>
|
|
403
|
+
<tr>
|
|
404
|
+
<th scope="row">{foot.label}</th>
|
|
405
|
+
{figureCells(foot, columns, props.language)}
|
|
406
|
+
</tr>
|
|
407
|
+
</tfoot>
|
|
408
|
+
)}
|
|
409
|
+
</table>
|
|
410
|
+
</div>
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export interface ChartSeries {
|
|
415
|
+
readonly name: string;
|
|
416
|
+
/** The series' amounts, one a point in order; nothing where a point has none. */
|
|
417
|
+
readonly values: readonly (number | undefined)[];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export interface ChartProps {
|
|
421
|
+
/** What the chart shows, said to a reader who cannot see it; the page's heading says it to the others. */
|
|
422
|
+
readonly title: string;
|
|
423
|
+
/** The points' names in order, the latest last: days, weeks. */
|
|
424
|
+
readonly points: readonly string[];
|
|
425
|
+
/** One to a few series, measured by one scale; six at most are told apart. */
|
|
426
|
+
readonly series: readonly ChartSeries[];
|
|
427
|
+
/** Columns, for amounts counted in each point; lines, for an amount followed from point to point. */
|
|
428
|
+
readonly kind?: "columns" | "line" | undefined;
|
|
429
|
+
/** How tall: `short` where it stands among other things, in a tile say. */
|
|
430
|
+
readonly size?: "short" | undefined;
|
|
431
|
+
/** An amount as words, where the page writes it its own way; the language's own way where left out. */
|
|
432
|
+
readonly format?: ((value: number) => string) | undefined;
|
|
433
|
+
/** The language the amounts are written in; the browser's where left out. */
|
|
434
|
+
readonly language?: string | undefined;
|
|
435
|
+
/** What stands in the chart's place where no point has an amount. */
|
|
436
|
+
readonly empty?: ReactNode | undefined;
|
|
437
|
+
/**
|
|
438
|
+
* Where the chart's figures stand for a reader who cannot see it: under it, as a table only a
|
|
439
|
+
* screen reader is told, unless the page shows them `beside` it itself, in a `FigureTable`.
|
|
440
|
+
*/
|
|
441
|
+
readonly figures?: "beside" | undefined;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* A chart over time: columns or lines of one to a few series against one scale, with a legend
|
|
446
|
+
* where there are two series or more, the scale's round amounts at the side and the points'
|
|
447
|
+
* names under it, as many as there is room for. Its figures stand under it as a table, for a
|
|
448
|
+
* reader who cannot see it, and a point says its figures to the pointer over it.
|
|
449
|
+
*/
|
|
450
|
+
export function Chart(props: ChartProps) {
|
|
451
|
+
const kind = props.kind ?? "columns";
|
|
452
|
+
const words = props.format ?? ((value: number) => amountWords(value, props.language));
|
|
453
|
+
const layout = chartLayout(
|
|
454
|
+
props.points.length,
|
|
455
|
+
props.series.map((one) => one.values),
|
|
456
|
+
);
|
|
457
|
+
// A point is its place in the order and a series its place among the series: two may have
|
|
458
|
+
// one name, and neither is ever moved.
|
|
459
|
+
const points = props.points.map((name, at) => ({ name, at, across: layout.across[at] ?? 0 }));
|
|
460
|
+
const series = props.series.map((one, index) => ({
|
|
461
|
+
name: one.name,
|
|
462
|
+
index,
|
|
463
|
+
places: layout.series[index] ?? [],
|
|
464
|
+
amounts: points.map((point) => {
|
|
465
|
+
const value = one.values[point.at];
|
|
466
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
467
|
+
}),
|
|
468
|
+
}));
|
|
469
|
+
if (!series.some((one) => one.places.some((place) => place !== undefined))) {
|
|
470
|
+
return (
|
|
471
|
+
<figure className="sc-chart">
|
|
472
|
+
<figcaption className="sc-visually-hidden">{props.title}</figcaption>
|
|
473
|
+
{props.empty !== undefined && <p className="sc-muted">{props.empty}</p>}
|
|
474
|
+
</figure>
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
// The scale's marks are written short where the scale reaches ten thousand, unless the page
|
|
478
|
+
// writes amounts its own way.
|
|
479
|
+
const long = Math.max(Math.abs(layout.scale.min), Math.abs(layout.scale.max)) >= 10_000;
|
|
480
|
+
const marked =
|
|
481
|
+
props.format ?? ((value: number) => (long ? shortWords : amountWords)(value, props.language));
|
|
482
|
+
const names = points.map((point) => point.name);
|
|
483
|
+
// The labels a wide chart has room for, and of those the ones a narrow chart has: the narrow
|
|
484
|
+
// step is so many of the wide one, so that no label stands in the narrow chart alone.
|
|
485
|
+
const step = labelStep(names, CHART_LABEL_ROOM.wide);
|
|
486
|
+
const wide = labelledPoints(points.length, step);
|
|
487
|
+
const narrow = labelledPoints(
|
|
488
|
+
points.length,
|
|
489
|
+
step * Math.ceil(labelStep(names, CHART_LABEL_ROOM.narrow) / step),
|
|
490
|
+
);
|
|
491
|
+
const saidAt = (at: number, name: string): string => {
|
|
492
|
+
const said = series.flatMap((one) => {
|
|
493
|
+
const value = one.amounts[at];
|
|
494
|
+
return value === undefined
|
|
495
|
+
? []
|
|
496
|
+
: [series.length === 1 ? words(value) : `${one.name} ${words(value)}`];
|
|
497
|
+
});
|
|
498
|
+
return said.length === 0 ? name : `${name}: ${said.join(", ")}`;
|
|
499
|
+
};
|
|
500
|
+
return (
|
|
501
|
+
<figure className={classes("sc-chart", props.size === "short" && "sc-chart-short")}>
|
|
502
|
+
{props.figures === "beside" && (
|
|
503
|
+
<figcaption className="sc-visually-hidden">{props.title}</figcaption>
|
|
504
|
+
)}
|
|
505
|
+
{series.length > 1 && (
|
|
506
|
+
<Legend
|
|
507
|
+
mark={kind === "line" ? "line" : "box"}
|
|
508
|
+
items={series.map((one) => ({ name: one.name, series: one.index }))}
|
|
509
|
+
/>
|
|
510
|
+
)}
|
|
511
|
+
<div className="sc-chart-frame" aria-hidden="true">
|
|
512
|
+
<div className="sc-chart-axis">
|
|
513
|
+
{layout.ticks.map((tick) => (
|
|
514
|
+
<span key={tick.value} className="sc-chart-tick">
|
|
515
|
+
{marked(tick.value)}
|
|
516
|
+
</span>
|
|
517
|
+
))}
|
|
518
|
+
</div>
|
|
519
|
+
<div className="sc-chart-plot">
|
|
520
|
+
<svg className="sc-chart-grid" aria-hidden="true" focusable="false">
|
|
521
|
+
{layout.ticks.map((tick) => (
|
|
522
|
+
<line
|
|
523
|
+
key={tick.value}
|
|
524
|
+
className={classes(
|
|
525
|
+
"sc-chart-gridline",
|
|
526
|
+
tick.value === 0 && "sc-chart-gridline-zero",
|
|
527
|
+
)}
|
|
528
|
+
x1="0"
|
|
529
|
+
x2="100%"
|
|
530
|
+
y1={chartMeasure(tick.at)}
|
|
531
|
+
y2={chartMeasure(tick.at)}
|
|
532
|
+
/>
|
|
533
|
+
))}
|
|
534
|
+
</svg>
|
|
535
|
+
{kind === "columns" ? (
|
|
536
|
+
<div className="sc-chart-columns">
|
|
537
|
+
{points.map((point) => (
|
|
538
|
+
<div key={point.at} className="sc-chart-slot">
|
|
539
|
+
{series.map((one) => {
|
|
540
|
+
const column = columnOf(one.places[point.at], layout.zero);
|
|
541
|
+
return (
|
|
542
|
+
<svg
|
|
543
|
+
key={one.index}
|
|
544
|
+
className={classes("sc-chart-column", seriesClass(one.index))}
|
|
545
|
+
aria-hidden="true"
|
|
546
|
+
focusable="false"
|
|
547
|
+
>
|
|
548
|
+
{column !== undefined && (
|
|
549
|
+
// The column's own box runs from zero to the amount and cuts what is
|
|
550
|
+
// drawn in it: the shape ends with the box at the amount and runs on
|
|
551
|
+
// past zero, so that it is round where it ends and square on zero.
|
|
552
|
+
<svg
|
|
553
|
+
y={chartMeasure(column.top)}
|
|
554
|
+
width="100%"
|
|
555
|
+
height={chartMeasure(column.height)}
|
|
556
|
+
aria-hidden="true"
|
|
557
|
+
>
|
|
558
|
+
<rect
|
|
559
|
+
className="sc-chart-bar"
|
|
560
|
+
y={column.down ? "-50%" : "0"}
|
|
561
|
+
width="100%"
|
|
562
|
+
height="150%"
|
|
563
|
+
/>
|
|
564
|
+
</svg>
|
|
565
|
+
)}
|
|
566
|
+
</svg>
|
|
567
|
+
);
|
|
568
|
+
})}
|
|
569
|
+
</div>
|
|
570
|
+
))}
|
|
571
|
+
</div>
|
|
572
|
+
) : (
|
|
573
|
+
<svg className="sc-chart-lines" aria-hidden="true" focusable="false">
|
|
574
|
+
{series.map((one) => {
|
|
575
|
+
const last = one.places.findLastIndex((place) => place !== undefined);
|
|
576
|
+
return (
|
|
577
|
+
<g key={one.index} className={seriesClass(one.index)}>
|
|
578
|
+
{points.slice(1).map((point) => {
|
|
579
|
+
const before = points[point.at - 1];
|
|
580
|
+
const from = one.places[point.at - 1];
|
|
581
|
+
const to = one.places[point.at];
|
|
582
|
+
return before === undefined ||
|
|
583
|
+
from === undefined ||
|
|
584
|
+
to === undefined ? null : (
|
|
585
|
+
<line
|
|
586
|
+
key={point.at}
|
|
587
|
+
className="sc-chart-line"
|
|
588
|
+
x1={chartMeasure(before.across)}
|
|
589
|
+
y1={chartMeasure(from)}
|
|
590
|
+
x2={chartMeasure(point.across)}
|
|
591
|
+
y2={chartMeasure(to)}
|
|
592
|
+
/>
|
|
593
|
+
);
|
|
594
|
+
})}
|
|
595
|
+
{points.map((point) => {
|
|
596
|
+
const place = one.places[point.at];
|
|
597
|
+
// A dot where the line ends, and where an amount has none beside it to
|
|
598
|
+
// be joined to: a line of one point is a dot.
|
|
599
|
+
const alone =
|
|
600
|
+
one.places[point.at - 1] === undefined &&
|
|
601
|
+
one.places[point.at + 1] === undefined;
|
|
602
|
+
return place === undefined || !(point.at === last || alone) ? null : (
|
|
603
|
+
<circle
|
|
604
|
+
key={point.at}
|
|
605
|
+
className="sc-chart-dot"
|
|
606
|
+
cx={chartMeasure(point.across)}
|
|
607
|
+
cy={chartMeasure(place)}
|
|
608
|
+
/>
|
|
609
|
+
);
|
|
610
|
+
})}
|
|
611
|
+
</g>
|
|
612
|
+
);
|
|
613
|
+
})}
|
|
614
|
+
</svg>
|
|
615
|
+
)}
|
|
616
|
+
{/* Over the marks, a point's share of the plot each: what answers the pointer. */}
|
|
617
|
+
<svg aria-hidden="true" focusable="false">
|
|
618
|
+
{points.map((point) => (
|
|
619
|
+
<rect
|
|
620
|
+
key={point.at}
|
|
621
|
+
className="sc-chart-hit"
|
|
622
|
+
x={chartMeasure((point.at * 100) / points.length)}
|
|
623
|
+
y="0"
|
|
624
|
+
width={chartMeasure(100 / points.length)}
|
|
625
|
+
height="100%"
|
|
626
|
+
>
|
|
627
|
+
<title>{saidAt(point.at, point.name)}</title>
|
|
628
|
+
</rect>
|
|
629
|
+
))}
|
|
630
|
+
</svg>
|
|
631
|
+
</div>
|
|
632
|
+
<div className="sc-chart-labels">
|
|
633
|
+
{points.map((point) => (
|
|
634
|
+
<span
|
|
635
|
+
key={point.at}
|
|
636
|
+
className={classes(
|
|
637
|
+
"sc-chart-label",
|
|
638
|
+
!narrow.has(point.at) && "sc-chart-label-wide",
|
|
639
|
+
// In a narrow chart a name at an end stands inside the chart, where there are
|
|
640
|
+
// points enough for it to be wider than its own.
|
|
641
|
+
points.length > 2 && point.at === 0 && "sc-chart-label-start",
|
|
642
|
+
points.length > 2 && point.at === points.length - 1 && "sc-chart-label-end",
|
|
643
|
+
)}
|
|
644
|
+
>
|
|
645
|
+
{wide.has(point.at) ? point.name : ""}
|
|
646
|
+
</span>
|
|
647
|
+
))}
|
|
648
|
+
</div>
|
|
649
|
+
</div>
|
|
650
|
+
{props.figures !== "beside" && (
|
|
651
|
+
<div className="sc-visually-hidden">
|
|
652
|
+
<table>
|
|
653
|
+
<caption>{props.title}</caption>
|
|
654
|
+
<thead>
|
|
655
|
+
<tr>
|
|
656
|
+
<td />
|
|
657
|
+
{series.map((one) => (
|
|
658
|
+
<th key={one.index} scope="col">
|
|
659
|
+
{one.name}
|
|
660
|
+
</th>
|
|
661
|
+
))}
|
|
662
|
+
</tr>
|
|
663
|
+
</thead>
|
|
664
|
+
<tbody>
|
|
665
|
+
{points.map((point) => (
|
|
666
|
+
<tr key={point.at}>
|
|
667
|
+
<th scope="row">{point.name}</th>
|
|
668
|
+
{series.map((one) => {
|
|
669
|
+
const value = one.amounts[point.at];
|
|
670
|
+
return <td key={one.index}>{value === undefined ? "" : words(value)}</td>;
|
|
671
|
+
})}
|
|
672
|
+
</tr>
|
|
673
|
+
))}
|
|
674
|
+
</tbody>
|
|
675
|
+
</table>
|
|
676
|
+
</div>
|
|
677
|
+
)}
|
|
678
|
+
</figure>
|
|
679
|
+
);
|
|
680
|
+
}
|