@venizia/vulcan 0.4.9-0 → 0.4.9-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/base/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +2 -2
- package/base/hooks/codex-guards.ts +15 -5
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +4 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +5 -6
- package/base/hooks/guard-remote-hosts.ts +6 -7
- package/base/hooks/guard-scripting.ts +5 -6
- package/base/hooks/guard-writes.ts +8 -9
- package/base/hooks/post-tool.ts +2 -2
- package/base/hooks/prompt-submit.ts +2 -2
- package/base/hooks/session-start.ts +3 -3
- package/base/hooks/stop.ts +2 -2
- package/base/hooks/subagent-start.ts +2 -2
- package/base/skills/docs-update/SKILL.md +4 -2
- package/base/skills/visualize-work/SKILL.md +9 -0
- package/package.json +3 -3
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +45 -43
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +96 -97
- package/src/agents/hooks-json.ts +38 -36
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +201 -195
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/commands/add.command.ts +2 -2
- package/src/commands/agents.command.ts +11 -17
- package/src/commands/clean.command.ts +6 -6
- package/src/commands/doctor.command.ts +4 -4
- package/src/commands/init.command.ts +12 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +42 -49
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +80 -75
- package/src/commands/visualize.command.ts +7 -13
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +94 -91
- package/src/common/paths.ts +14 -12
- package/src/config/loader.ts +52 -49
- package/src/config/packages.ts +14 -11
- package/src/config/schema.ts +3 -3
- package/src/create/add-app.ts +519 -509
- package/src/create/add-lib.ts +237 -240
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/diff.ts +21 -23
- package/src/create/dockerignore.ts +26 -24
- package/src/create/files.ts +7 -5
- package/src/create/init-monorepo.ts +75 -80
- package/src/create/lib-preset.ts +59 -63
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +26 -23
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +301 -303
- package/src/create/preset-menu.ts +38 -32
- package/src/create/preset.ts +202 -197
- package/src/create/process.ts +79 -72
- package/src/create/scratch.ts +48 -49
- package/src/create/workspace.ts +404 -396
- package/src/doctor/checks.ts +1027 -1014
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -118
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +42 -37
- package/src/hooks/codex-patch.ts +25 -22
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/decision.ts +37 -37
- package/src/hooks/guard-git.ts +51 -49
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +93 -91
- package/src/hooks/guard-package.ts +82 -79
- package/src/hooks/guard-scripting.ts +19 -14
- package/src/hooks/guard-writes.ts +154 -149
- package/src/hooks/owner-reply.ts +127 -127
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +65 -62
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +153 -130
- package/src/hooks/session-digest.ts +98 -101
- package/src/hooks/shell.ts +509 -499
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +106 -104
- package/src/init/scaffold.ts +135 -132
- package/src/local/clean.ts +38 -36
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +144 -138
- package/src/manifest/render.ts +110 -104
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +99 -93
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +71 -69
- package/src/owner/survey.ts +173 -171
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/rules/base.ts +15 -11
- package/src/rules/parser.ts +39 -32
- package/src/rules/slots.ts +8 -6
- package/src/signals/claims.ts +30 -28
- package/src/signals/classify.ts +38 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +79 -81
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +56 -59
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +36 -34
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +59 -61
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +166 -167
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +38 -38
- package/src/ui/prompt.ts +79 -77
- package/src/visualize/assets.ts +33 -24
- package/src/visualize/charts.ts +179 -176
- package/src/visualize/compare-css.ts +3 -2
- package/src/visualize/compare-render.ts +9 -7
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +7 -5
- package/src/visualize/kinds-render.ts +50 -45
- package/src/visualize/kinds-validate.ts +12 -10
- package/src/visualize/labels.ts +21 -17
- package/src/visualize/layout.ts +112 -97
- package/src/visualize/page.ts +92 -104
- package/src/visualize/render.ts +143 -140
- package/src/visualize/sections.ts +395 -384
- package/src/visualize/sources.ts +2 -2
- package/src/visualize/theme.ts +12 -10
- package/src/visualize/validate.ts +13 -9
- package/src/wiki/anchors.ts +38 -36
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +46 -44
package/src/visualize/assets.ts
CHANGED
|
@@ -135,18 +135,18 @@ const BASE_CSS = [
|
|
|
135
135
|
// Tiles: fields of colour with a big number.
|
|
136
136
|
`.slide-tiles{padding-top:56px}`,
|
|
137
137
|
`.tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:2px;border-radius:var(--radius);overflow:hidden}`,
|
|
138
|
-
`.tile{position:relative;display:grid;
|
|
138
|
+
`.tile{position:relative;display:grid;align-content:start;padding:28px 26px 30px;background:var(--bg-soft)}`,
|
|
139
139
|
`.tile.c-ok,.tile.c-warn,.tile.c-bad,.tile.c-info{background:var(--cb)}`,
|
|
140
|
-
`.tile .n{font-size:clamp(36px,4.4vw,60px);line-height:.95;font-weight:650;letter-spacing:-.05em;color:var(--ink);overflow-wrap:anywhere}`,
|
|
140
|
+
`.tile .n{font-size:clamp(36px,4.4vw,60px);line-height:.95;font-weight:650;letter-spacing:-.05em;color:var(--ink);overflow-wrap:anywhere;margin-bottom:10px}`,
|
|
141
141
|
`.tile .l{color:var(--body);font-size:16px}`,
|
|
142
142
|
`.tile .ic{position:absolute;top:22px;right:22px;color:var(--c)}`,
|
|
143
143
|
// The minimap: a track, a stripe and a word per task.
|
|
144
144
|
`.strip{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:2px;border-radius:var(--radius);overflow:hidden}`,
|
|
145
|
-
`.seg{display:grid;
|
|
145
|
+
`.seg{display:grid;align-content:start;padding:0 20px 22px;background:var(--bg-soft)}`,
|
|
146
146
|
`.seg.c-warn{background:var(--accent-soft)}`,
|
|
147
147
|
`.seg .bar{display:block;height:6px;margin:0 -20px 12px;background:var(--c)}`,
|
|
148
148
|
`.seg.c-mut .bar{background:repeating-linear-gradient(90deg,var(--muted) 0 6px,transparent 6px 12px);opacity:.7}`,
|
|
149
|
-
`.seg .nm{display:grid;gap:6px}.seg .tn{font-weight:600;color:var(--ink);font-size:17px;line-height:1.3}`,
|
|
149
|
+
`.seg .nm{display:grid;gap:6px;align-content:start;margin-bottom:10px}.seg .tn{font-weight:600;color:var(--ink);font-size:17px;line-height:1.3}`,
|
|
150
150
|
`.seg .nt{color:var(--muted);font-size:15px;line-height:1.4}`,
|
|
151
151
|
// What the owner has to do, what blocks it, and the two quiet facts.
|
|
152
152
|
`.two{padding-top:72px}`,
|
|
@@ -221,26 +221,32 @@ const BASE_CSS = [
|
|
|
221
221
|
`.ranks{max-width:520px;margin-bottom:28px}`,
|
|
222
222
|
`.ranks svg{display:block;width:100%;height:auto;margin-top:8px}`,
|
|
223
223
|
`.opts{display:grid;grid-template-columns:repeat(auto-fit,minmax(290px,1fr));gap:2px;border-radius:var(--radius);overflow:hidden}`,
|
|
224
|
-
`.opt{display:grid;
|
|
224
|
+
`.opt{display:grid;align-content:start;padding:32px 30px 34px;background:var(--bg-soft)}`,
|
|
225
225
|
`.opt.rec{background:var(--accent-soft)}`,
|
|
226
|
-
`.opt .tag{
|
|
227
|
-
`.opt h3{font-size:24px;line-height:1.2}.opt .ln{color:var(--body);max-width:46ch}`,
|
|
228
|
-
`.opt .tot{display:flex;align-items:baseline;gap:12px;font-size:clamp(64px,7vw,104px);line-height:.85;font-weight:650;letter-spacing:-.05em;color:var(--ink)}`,
|
|
226
|
+
`.opt .tag-slot{display:block}.opt .tag{display:inline-block;margin-bottom:18px;background:var(--accent);color:var(--accent-ink);padding:4px 10px;border-radius:var(--radius);font:650 13px/1.3 var(--font)}`,
|
|
227
|
+
`.opt h3{font-size:24px;line-height:1.2;margin-bottom:18px}.opt .ln{color:var(--body);max-width:46ch;margin-bottom:18px}`,
|
|
228
|
+
`.opt .tot{display:flex;align-items:baseline;gap:12px;font-size:clamp(64px,7vw,104px);line-height:.85;font-weight:650;letter-spacing:-.05em;color:var(--ink);margin-bottom:18px}`,
|
|
229
229
|
`.opt .tot small{font:600 18px/1.2 var(--font);letter-spacing:0;color:var(--ink)}`,
|
|
230
230
|
`.opt.rec .tot{color:var(--accent)}`,
|
|
231
|
-
`.crit{display:grid;
|
|
231
|
+
`.crit{display:grid;margin-bottom:18px}.crit div{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px;align-items:center;font-size:15.5px}.crit div+div{margin-top:8px}`,
|
|
232
232
|
`.dots{display:inline-flex;gap:3px}.dots i{width:16px;height:8px;border-radius:2px;background:var(--line)}.dots i.on{background:var(--ink)}.opt.rec .dots i.on{background:var(--accent)}`,
|
|
233
|
-
`.pc{display:grid
|
|
233
|
+
`.pc{display:grid}.pc li{display:flex;gap:8px;font-size:15.5px}.pc li+li{margin-top:6px}.pc.proslist{margin-bottom:6px}.pc .ic{margin-top:4px}.pc .p .ic{color:var(--ok)}.pc .c .ic{color:var(--bad)}`,
|
|
234
|
+
// The cards of a row take their rows from the grid: the score, the title, each criterion and each pro of one card sit at the height of the same part of its neighbours (see grid-span.ts).
|
|
235
|
+
`@supports (grid-template-rows:subgrid){.steps li{grid-template-rows:subgrid;grid-row-end:span 3}.steps button{grid-template-rows:subgrid;grid-row-end:span 2}.tiles .tile{grid-template-rows:subgrid;grid-row-end:span 2}.strip .seg{grid-template-rows:subgrid;grid-row-end:span 3}.charts figure.chart{grid-template-rows:subgrid;grid-row-end:span 3}.diff .ba{grid-template-rows:subgrid;grid-row-end:span 2}}`,
|
|
236
|
+
`@media (min-width:621px){@supports (grid-template-rows:subgrid){.opt,.crit,.pc{grid-template-rows:subgrid}.idea .branch{grid-template-rows:subgrid;grid-row-end:span 3}}}`,
|
|
237
|
+
// One column (a phone): nothing is shared across cards, so a row kept for a part this card lacks is only a gap.
|
|
238
|
+
`@media (max-width:620px){.opt .ln:empty,.pc:empty{display:none}}`,
|
|
234
239
|
`.note{margin-top:20px;display:flex;gap:8px;max-width:70ch;color:var(--muted);font-size:15.5px}.note .ic{margin-top:4px}`,
|
|
235
240
|
// Idea map: a dark centre between two columns of panels.
|
|
236
|
-
`.idea{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,.7fr) minmax(0,1fr);gap:2px
|
|
237
|
-
`.idea .
|
|
241
|
+
`.idea{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,.7fr) minmax(0,1fr);gap:2px}`,
|
|
242
|
+
`.idea .bs{display:contents}.idea .branch:nth-child(odd){grid-column:1}.idea .branch:nth-child(even){grid-column:3}`,
|
|
238
243
|
`.centre{display:grid;gap:12px;justify-items:center;align-content:center;text-align:center;padding:40px 24px;border-radius:var(--radius)}`,
|
|
244
|
+
`.idea .centre{grid-column:2;grid-row-start:1}`,
|
|
239
245
|
`.centre .ic{color:var(--hot)}.centre b{color:var(--ink);font-size:clamp(20px,2vw,26px);line-height:1.2;letter-spacing:-.02em}`,
|
|
240
|
-
`.branch{display:grid;
|
|
246
|
+
`.branch{display:grid;align-content:start;padding:22px 24px;background:var(--bg-soft);box-shadow:inset 4px 0 0 var(--sc,var(--muted))}`,
|
|
241
247
|
`.branch[data-s="1"]{--sc:var(--s1)}.branch[data-s="2"]{--sc:var(--s2)}.branch[data-s="3"]{--sc:var(--s3)}.branch[data-s="4"]{--sc:var(--s4)}.branch[data-s="5"]{--sc:var(--s5)}`,
|
|
242
|
-
`.branch h3{display:flex;gap:10px;align-items:center;font-size:18px;letter-spacing:-.01em}`,
|
|
243
|
-
`.chips{display:flex;flex-wrap:wrap;gap:6px}.chips li{padding:3px 10px;border-radius:var(--radius);background:var(--bg);color:var(--ink);font-size:15px}`,
|
|
248
|
+
`.branch h3{display:flex;gap:10px;align-items:center;font-size:18px;letter-spacing:-.01em;margin-bottom:12px}`,
|
|
249
|
+
`.chips{display:flex;flex-wrap:wrap;align-content:flex-start;align-items:flex-start;gap:6px;margin-bottom:12px}.chips li{padding:3px 10px;border-radius:var(--radius);background:var(--bg);color:var(--ink);font-size:15px}`,
|
|
244
250
|
// Explainer: a big numeral, the words, then the drawing.
|
|
245
251
|
`.ex{display:grid;gap:60px}`,
|
|
246
252
|
`.estep{display:grid;grid-template-columns:96px minmax(0,1fr) minmax(0,1.3fr);gap:10px 32px;align-items:start}`,
|
|
@@ -256,7 +262,7 @@ const BASE_CSS = [
|
|
|
256
262
|
// Findings: tiles, panels with a chart each, and callouts with a stripe.
|
|
257
263
|
`.charts{display:grid;grid-template-columns:repeat(auto-fit,minmax(340px,1fr));gap:2px;margin-top:2px;border-radius:var(--radius);overflow:hidden}`,
|
|
258
264
|
`.tiles+.charts{margin-top:2px}`,
|
|
259
|
-
`figure.chart{display:grid;
|
|
265
|
+
`figure.chart{display:grid;align-content:start;padding:26px 28px;background:var(--bg-soft)}figure.chart>.lab,figure.chart .cbody{margin-bottom:16px}`,
|
|
260
266
|
`figure.chart svg{display:block;width:100%;max-width:380px;height:auto}`,
|
|
261
267
|
`figure.chart.donut .cbody{display:flex;flex-wrap:wrap;gap:16px;align-items:center}figure.chart.donut svg{max-width:150px;flex:none}`,
|
|
262
268
|
`svg .ct{font:13px var(--font);fill:var(--body)}svg .ct.strong{font-weight:700;fill:var(--ink)}svg .cv{font:600 13px var(--font);fill:var(--ink)}`,
|
|
@@ -272,7 +278,7 @@ const BASE_CSS = [
|
|
|
272
278
|
`.callout{display:flex;gap:14px;padding:20px 24px;background:var(--cb);box-shadow:inset 4px 0 0 var(--c);color:var(--ink)}.callout .ic{color:var(--c);margin-top:2px}`,
|
|
273
279
|
// Before and after: two panels; a plus or a minus, its word, and a line style.
|
|
274
280
|
`.diff{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:2px;border-radius:var(--radius);overflow:hidden}`,
|
|
275
|
-
`.ba{background:var(--bg-soft);padding:28px 30px 30px}.ba h3{font-size:22px;margin-bottom:18px}`,
|
|
281
|
+
`.ba{display:grid;align-content:start;background:var(--bg-soft);padding:28px 30px 30px}.ba h3{font-size:22px;margin-bottom:18px}`,
|
|
276
282
|
`.ba li{display:flex;gap:12px;padding:11px 0 11px 14px;border-left:3px solid transparent;color:var(--body)}`,
|
|
277
283
|
`.ba li .ic{margin-top:4px;flex:none}.ba li.same .ic{opacity:0}`,
|
|
278
284
|
`.ba li.add{border-left:4px solid var(--ink);color:var(--ink);font-weight:550}`,
|
|
@@ -319,7 +325,7 @@ const BASE_CSS = [
|
|
|
319
325
|
`html.present .deck{display:flex;position:fixed;left:0;right:0;bottom:0;z-index:30;gap:12px;align-items:center;justify-content:center;padding:10px;border-top:1px solid var(--line)}`,
|
|
320
326
|
`html.present .deck span{font:600 14px var(--font);color:var(--muted)}`,
|
|
321
327
|
// A phone: panels stack, the bar keeps only the title, the state, present and the switch.
|
|
322
|
-
`@media (max-width:860px){.own,.facts,.q,.estep,.diff,.ev,.log li,.idea{grid-template-columns:minmax(0,1fr)}.q{gap:18px}.idea .centre{order:-1}.estep{gap:12px}.estep .no{font-size:56px}`,
|
|
328
|
+
`@media (max-width:860px){.own,.facts,.q,.estep,.diff,.ev,.log li,.idea{grid-template-columns:minmax(0,1fr)}.q{gap:18px}.idea .centre{order:-1;grid-column:1;grid-row:auto}.idea .branch:nth-child(n){grid-column:1}.estep{gap:12px}.estep .no{font-size:56px}`,
|
|
323
329
|
`.part{padding-top:64px}.hero{padding-block:40px}.figure{margin-top:36px}.foot{margin-top:80px}.sh{margin-bottom:26px}.own .nx,.own .stop{padding:26px 22px}.opt{padding:26px 22px 28px}.q{padding:24px 22px 26px}.ba{padding:24px 22px}`,
|
|
324
330
|
`.top .links,.top .sep,.top .stamp{display:none}.top .wrap{gap:10px}.top .ttl{max-width:none;flex:1 1 auto}.top nav{margin-left:0}`,
|
|
325
331
|
`.stack thead{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}.stack,.stack tbody,.stack tr,.stack td{display:block;width:100%}.stack tr{padding:14px 0;border-top:1px solid var(--line)}.stack tbody tr:first-child{border-top:0;padding-top:0}.stack td{border:0;padding:3px 0}`,
|
|
@@ -333,12 +339,15 @@ const BASE_CSS = [
|
|
|
333
339
|
`.fig{overflow:visible;display:block!important}.path,.path-detail{display:none!important}.steps{display:block}.js .steps .explain{display:block}[data-slide]{display:block!important;break-inside:avoid}.banner{break-after:page}.fig.playing .edge path{animation:none}.focus .node:not(.on),.focus .edge:not(.on){opacity:1}}`,
|
|
334
340
|
].join('\n');
|
|
335
341
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
export class Assets {
|
|
343
|
+
/**
|
|
344
|
+
* The page's stylesheet: the project tokens, the fixed state colours, then the shell and every kind. Light and dark by
|
|
345
|
+
* variables, no image, no font file, the final state in print and under reduced motion.
|
|
346
|
+
*/
|
|
347
|
+
static pageCss(opts: { tokens: string }): string {
|
|
348
|
+
return `${opts.tokens}\n${STATE_CSS}\n${BASE_CSS}`;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
342
351
|
|
|
343
352
|
/** The first script of the page, run before the stylesheet is used: marks the page as scripted and applies the saved theme, so there is no flash. */
|
|
344
353
|
export const HEAD_JS = `(()=>{const r=document.documentElement;r.classList.add('js');try{const s=localStorage.getItem('vz-theme');if(s==='dark'||s==='light')r.setAttribute('data-theme',s)}catch(e){}})();`;
|
package/src/visualize/charts.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IconSet } from './icons.ts';
|
|
2
2
|
import { NodeStates } from './constants.ts';
|
|
3
3
|
import type { TChrome } from './constants.ts';
|
|
4
|
-
import {
|
|
4
|
+
import { FigureLayout } from './layout.ts';
|
|
5
5
|
import type { TVisualizeSpec } from './schema.ts';
|
|
6
6
|
|
|
7
7
|
type TChart = NonNullable<NonNullable<TVisualizeSpec['findings']>['charts']>[number];
|
|
8
8
|
|
|
9
|
-
const escaped = (value: string): string => escapeText({ value });
|
|
10
|
-
|
|
11
|
-
/** 1234567 as 1,234,567 and 0.5 as 0.5: no locale, so the page reads the same everywhere. */
|
|
12
|
-
export const formatNumber = (opts: { value: number }): string => {
|
|
13
|
-
const rounded = Math.round(opts.value * 100) / 100;
|
|
14
|
-
const [whole = '0', fraction] = String(Math.abs(rounded)).split('.');
|
|
15
|
-
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
16
|
-
|
|
17
|
-
return `${rounded < 0 ? '-' : ''}${grouped}${fraction === undefined ? '' : `.${fraction}`}`;
|
|
18
|
-
};
|
|
9
|
+
const escaped = (value: string): string => FigureLayout.escapeText({ value });
|
|
19
10
|
|
|
20
11
|
const shorten = (opts: { value: string; max: number }): string =>
|
|
21
12
|
opts.value.length <= opts.max ? opts.value : `${opts.value.slice(0, opts.max - 1)}…`;
|
|
@@ -45,87 +36,6 @@ const niceScale = (opts: {
|
|
|
45
36
|
|
|
46
37
|
const VIEW_WIDTH = 340;
|
|
47
38
|
|
|
48
|
-
const barChart = (opts: { chart: Extract<TChart, { type: 'bar' }> }): string => {
|
|
49
|
-
const { labels, values } = opts.chart;
|
|
50
|
-
const max = Math.max(...values, 1);
|
|
51
|
-
const rowHeight = 30;
|
|
52
|
-
const left = 120;
|
|
53
|
-
const plot = 150;
|
|
54
|
-
|
|
55
|
-
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${labels.length * rowHeight + 8}" role="img" aria-label="${escaped(opts.chart.title)}">${labels
|
|
56
|
-
.map((label, index) => {
|
|
57
|
-
const y = index * rowHeight + 6;
|
|
58
|
-
const width = Math.max(2, Math.round(((values[index] ?? 0) / max) * plot));
|
|
59
|
-
|
|
60
|
-
return `<g><title>${escaped(label)}: ${formatNumber({ value: values[index] ?? 0 })}${escaped(opts.chart.unit ?? '')}</title><text x="0" y="${y + 16}" class="ct">${escaped(shorten({ value: label, max: 18 }))}</text><rect x="${left}" y="${y + 2}" width="${plot}" height="18" rx="4" class="ctrack"/><path d="${barPath({ x: left, y: y + 2, width, height: 18 })}" fill="var(--s1)"/><text x="${left + width + 6}" y="${y + 16}" class="cv">${formatNumber({ value: values[index] ?? 0 })}${escaped(opts.chart.unit ?? '')}</text></g>`;
|
|
61
|
-
})
|
|
62
|
-
.join('')}</svg>`;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const lineChart = (opts: { chart: Extract<TChart, { type: 'line' }> }): string => {
|
|
66
|
-
const { labels, series } = opts.chart;
|
|
67
|
-
const all = series.flatMap((s) => s.values.slice(0, labels.length));
|
|
68
|
-
const scale = niceScale({ min: Math.min(...all), max: Math.max(...all), ticks: 4 });
|
|
69
|
-
const left = 44;
|
|
70
|
-
const right = 64;
|
|
71
|
-
const top = 12;
|
|
72
|
-
const height = 150;
|
|
73
|
-
const plot = VIEW_WIDTH - left - right;
|
|
74
|
-
const x = (index: number): number => left + (index / (labels.length - 1)) * plot;
|
|
75
|
-
const y = (value: number): number =>
|
|
76
|
-
top + height - ((value - scale.low) / (scale.high - scale.low || 1)) * height;
|
|
77
|
-
const ticks: number[] = [];
|
|
78
|
-
|
|
79
|
-
for (let value = scale.low; value <= scale.high + scale.step / 2; value += scale.step) {
|
|
80
|
-
ticks.push(Math.round(value * 1000) / 1000);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const every = labels.length > 6 ? Math.ceil(labels.length / 6) : 1;
|
|
84
|
-
// The direct labels sit at the last point of each line; where two would touch, they are pushed apart by 15 px.
|
|
85
|
-
const ends = series
|
|
86
|
-
.map((s, index) => ({ index, y: y(s.values.slice(0, labels.length).at(-1) ?? 0) }))
|
|
87
|
-
.sort((a, b) => a.y - b.y);
|
|
88
|
-
|
|
89
|
-
for (let at = 1; at < ends.length; at += 1) {
|
|
90
|
-
const previous = ends[at - 1];
|
|
91
|
-
const current = ends[at];
|
|
92
|
-
|
|
93
|
-
if (previous !== undefined && current !== undefined && current.y - previous.y < 15) {
|
|
94
|
-
current.y = previous.y + 15;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const labelY = new Map(ends.map((end) => [end.index, end.y]));
|
|
99
|
-
|
|
100
|
-
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${top + height + 34}" role="img" aria-label="${escaped(opts.chart.title)}">${ticks
|
|
101
|
-
.map(
|
|
102
|
-
(tick) =>
|
|
103
|
-
`<line x1="${left}" x2="${VIEW_WIDTH - right}" y1="${y(tick)}" y2="${y(tick)}" class="cgrid"/><text x="${left - 6}" y="${y(tick) + 4}" text-anchor="end" class="ct">${formatNumber({ value: tick })}</text>`,
|
|
104
|
-
)
|
|
105
|
-
.join('')}${labels
|
|
106
|
-
.map((label, index) =>
|
|
107
|
-
index % every === 0
|
|
108
|
-
? `<text x="${x(index)}" y="${top + height + 20}" text-anchor="middle" class="ct">${escaped(shorten({ value: label, max: 8 }))}</text>`
|
|
109
|
-
: '',
|
|
110
|
-
)
|
|
111
|
-
.join('')}${series
|
|
112
|
-
.map((s, index) => {
|
|
113
|
-
const points = s.values.slice(0, labels.length);
|
|
114
|
-
const path = points.map((value, i) => `${i === 0 ? 'M' : 'L'}${x(i)} ${y(value)}`).join('');
|
|
115
|
-
const last = points.at(-1) ?? 0;
|
|
116
|
-
|
|
117
|
-
return `<g><path d="${path}" fill="none" stroke="var(--s${index + 1})" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round"/>${points
|
|
118
|
-
.map(
|
|
119
|
-
(value, i) =>
|
|
120
|
-
`<circle cx="${x(i)}" cy="${y(value)}" r="4.5" fill="var(--s${index + 1})" class="cring"><title>${escaped(s.name)}, ${escaped(labels[i] ?? '')}: ${formatNumber({ value })}${escaped(opts.chart.unit ?? '')}</title></circle>`,
|
|
121
|
-
)
|
|
122
|
-
.join(
|
|
123
|
-
'',
|
|
124
|
-
)}<text x="${VIEW_WIDTH - right + 8}" y="${(labelY.get(index) ?? y(last)) + 4}" class="cv">${escaped(shorten({ value: s.name, max: 8 }))}</text></g>`;
|
|
125
|
-
})
|
|
126
|
-
.join('')}</svg>`;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
39
|
const SLOTS = ['var(--s1)', 'var(--s2)', 'var(--s3)', 'var(--s4)', 'var(--s5)'];
|
|
130
40
|
|
|
131
41
|
/** The page colour of a state tone: what waits for the owner is the project's accent, the rest are fixed. */
|
|
@@ -142,103 +52,196 @@ const donutColour = (opts: { index: number; state?: string }): string =>
|
|
|
142
52
|
? (SLOTS[opts.index] ?? 'var(--s5)')
|
|
143
53
|
: (TONE_COLOURS[NodeStates.toneOf(opts.state)] ?? 'var(--muted)');
|
|
144
54
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
};
|
|
55
|
+
export class SpecCharts {
|
|
56
|
+
private static barChart(opts: { chart: Extract<TChart, { type: 'bar' }> }): string {
|
|
57
|
+
const { labels, values } = opts.chart;
|
|
58
|
+
const max = Math.max(...values, 1);
|
|
59
|
+
const rowHeight = 30;
|
|
60
|
+
const left = 120;
|
|
61
|
+
const plot = 150;
|
|
62
|
+
|
|
63
|
+
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${labels.length * rowHeight + 8}" role="img" aria-label="${escaped(opts.chart.title)}">${labels
|
|
64
|
+
.map((label, index) => {
|
|
65
|
+
const y = index * rowHeight + 6;
|
|
66
|
+
const width = Math.max(2, Math.round(((values[index] ?? 0) / max) * plot));
|
|
67
|
+
|
|
68
|
+
return `<g><title>${escaped(label)}: ${SpecCharts.formatNumber({ value: values[index] ?? 0 })}${escaped(opts.chart.unit ?? '')}</title><text x="0" y="${y + 16}" class="ct">${escaped(shorten({ value: label, max: 18 }))}</text><rect x="${left}" y="${y + 2}" width="${plot}" height="18" rx="4" class="ctrack"/><path d="${barPath({ x: left, y: y + 2, width, height: 18 })}" fill="var(--s1)"/><text x="${left + width + 6}" y="${y + 16}" class="cv">${SpecCharts.formatNumber({ value: values[index] ?? 0 })}${escaped(opts.chart.unit ?? '')}</text></g>`;
|
|
69
|
+
})
|
|
70
|
+
.join('')}</svg>`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private static lineChart(opts: { chart: Extract<TChart, { type: 'line' }> }): string {
|
|
74
|
+
const { labels, series } = opts.chart;
|
|
75
|
+
const all = series.flatMap((s) => s.values.slice(0, labels.length));
|
|
76
|
+
const scale = niceScale({ min: Math.min(...all), max: Math.max(...all), ticks: 4 });
|
|
77
|
+
const left = 44;
|
|
78
|
+
const right = 64;
|
|
79
|
+
const top = 12;
|
|
80
|
+
const height = 150;
|
|
81
|
+
const plot = VIEW_WIDTH - left - right;
|
|
82
|
+
const x = (index: number): number => left + (index / (labels.length - 1)) * plot;
|
|
83
|
+
const y = (value: number): number =>
|
|
84
|
+
top + height - ((value - scale.low) / (scale.high - scale.low || 1)) * height;
|
|
85
|
+
const ticks: number[] = [];
|
|
86
|
+
|
|
87
|
+
for (let value = scale.low; value <= scale.high + scale.step / 2; value += scale.step) {
|
|
88
|
+
ticks.push(Math.round(value * 1000) / 1000);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const every = labels.length > 6 ? Math.ceil(labels.length / 6) : 1;
|
|
92
|
+
// The direct labels sit at the last point of each line; where two would touch, they are pushed apart by 15 px.
|
|
93
|
+
const ends = series
|
|
94
|
+
.map((s, index) => ({ index, y: y(s.values.slice(0, labels.length).at(-1) ?? 0) }))
|
|
95
|
+
.sort((a, b) => a.y - b.y);
|
|
96
|
+
|
|
97
|
+
for (let at = 1; at < ends.length; at += 1) {
|
|
98
|
+
const previous = ends[at - 1];
|
|
99
|
+
const current = ends[at];
|
|
165
100
|
|
|
166
|
-
|
|
167
|
-
|
|
101
|
+
if (previous !== undefined && current !== undefined && current.y - previous.y < 15) {
|
|
102
|
+
current.y = previous.y + 15;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
168
105
|
|
|
169
|
-
|
|
170
|
-
const total = chart.parts.reduce((sum, part) => sum + part.value, 0) || 1;
|
|
106
|
+
const labelY = new Map(ends.map((end) => [end.index, end.y]));
|
|
171
107
|
|
|
172
|
-
return `<
|
|
108
|
+
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${top + height + 34}" role="img" aria-label="${escaped(opts.chart.title)}">${ticks
|
|
173
109
|
.map(
|
|
174
|
-
(
|
|
175
|
-
`<
|
|
110
|
+
(tick) =>
|
|
111
|
+
`<line x1="${left}" x2="${VIEW_WIDTH - right}" y1="${y(tick)}" y2="${y(tick)}" class="cgrid"/><text x="${left - 6}" y="${y(tick) + 4}" text-anchor="end" class="ct">${SpecCharts.formatNumber({ value: tick })}</text>`,
|
|
112
|
+
)
|
|
113
|
+
.join('')}${labels
|
|
114
|
+
.map((label, index) =>
|
|
115
|
+
index % every === 0
|
|
116
|
+
? `<text x="${x(index)}" y="${top + height + 20}" text-anchor="middle" class="ct">${escaped(shorten({ value: label, max: 8 }))}</text>`
|
|
117
|
+
: '',
|
|
176
118
|
)
|
|
177
|
-
.join('')}
|
|
119
|
+
.join('')}${series
|
|
120
|
+
.map((s, index) => {
|
|
121
|
+
const points = s.values.slice(0, labels.length);
|
|
122
|
+
const path = points.map((value, i) => `${i === 0 ? 'M' : 'L'}${x(i)} ${y(value)}`).join('');
|
|
123
|
+
const last = points.at(-1) ?? 0;
|
|
124
|
+
|
|
125
|
+
return `<g><path d="${path}" fill="none" stroke="var(--s${index + 1})" stroke-width="2.5" stroke-linejoin="round" stroke-linecap="round"/>${points
|
|
126
|
+
.map(
|
|
127
|
+
(value, i) =>
|
|
128
|
+
`<circle cx="${x(i)}" cy="${y(value)}" r="4.5" fill="var(--s${index + 1})" class="cring"><title>${escaped(s.name)}, ${escaped(labels[i] ?? '')}: ${SpecCharts.formatNumber({ value })}${escaped(opts.chart.unit ?? '')}</title></circle>`,
|
|
129
|
+
)
|
|
130
|
+
.join(
|
|
131
|
+
'',
|
|
132
|
+
)}<text x="${VIEW_WIDTH - right + 8}" y="${(labelY.get(index) ?? y(last)) + 4}" class="cv">${escaped(shorten({ value: s.name, max: 8 }))}</text></g>`;
|
|
133
|
+
})
|
|
134
|
+
.join('')}</svg>`;
|
|
178
135
|
}
|
|
179
136
|
|
|
180
|
-
|
|
181
|
-
|
|
137
|
+
private static donutChart(opts: { chart: Extract<TChart, { type: 'donut' }> }): string {
|
|
138
|
+
const { parts } = opts.chart;
|
|
139
|
+
const total = parts.reduce((sum, part) => sum + part.value, 0) || 1;
|
|
140
|
+
const radius = 54;
|
|
141
|
+
const circumference = 2 * Math.PI * radius;
|
|
142
|
+
let offset = 0;
|
|
143
|
+
const segments = parts
|
|
144
|
+
.map((part, index) => {
|
|
145
|
+
const share = part.value / total;
|
|
146
|
+
const length = Math.max(0, share * circumference - 3);
|
|
147
|
+
const out = `<circle cx="80" cy="80" r="${radius}" fill="none" stroke="${donutColour({ index, state: part.state })}" stroke-width="22" stroke-dasharray="${length.toFixed(2)} ${(circumference - length).toFixed(2)}" stroke-dashoffset="${(-offset).toFixed(2)}" transform="rotate(-90 80 80)"><title>${escaped(part.label)}: ${SpecCharts.formatNumber({ value: part.value })}${escaped(opts.chart.unit ?? '')}</title></circle>`;
|
|
148
|
+
|
|
149
|
+
offset += share * circumference;
|
|
150
|
+
|
|
151
|
+
return out;
|
|
152
|
+
})
|
|
153
|
+
.join('');
|
|
154
|
+
|
|
155
|
+
return `<svg viewBox="0 0 160 160" class="donut-svg" role="img" aria-label="${escaped(opts.chart.title)}">${segments}<text x="80" y="82" text-anchor="middle" class="cbig">${SpecCharts.formatNumber({ value: total })}</text><text x="80" y="100" text-anchor="middle" class="ct">${escaped(opts.chart.unit ?? 'total')}</text></svg>`;
|
|
182
156
|
}
|
|
183
157
|
|
|
184
|
-
|
|
185
|
-
};
|
|
158
|
+
private static legend(opts: { chart: TChart }): string {
|
|
159
|
+
const { chart } = opts;
|
|
160
|
+
|
|
161
|
+
if (chart.type === 'donut') {
|
|
162
|
+
const total = chart.parts.reduce((sum, part) => sum + part.value, 0) || 1;
|
|
163
|
+
|
|
164
|
+
return `<ul class="clegend">${chart.parts
|
|
165
|
+
.map(
|
|
166
|
+
(part, index) =>
|
|
167
|
+
`<li><i class="sw" ${part.state === undefined ? `data-s="${index + 1}"` : `data-t="${NodeStates.toneOf(part.state)}"`}></i><span>${escaped(part.label)}</span><b>${SpecCharts.formatNumber({ value: part.value })}${escaped(chart.unit ?? '')}</b><em>${Math.round((part.value / total) * 100)}%</em></li>`,
|
|
168
|
+
)
|
|
169
|
+
.join('')}</ul>`;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (chart.type === 'line' && chart.series.length > 1) {
|
|
173
|
+
return `<ul class="clegend row">${chart.series.map((s, index) => `<li><i class="sw" data-s="${index + 1}"></i><span>${escaped(s.name)}</span></li>`).join('')}</ul>`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return '';
|
|
177
|
+
}
|
|
186
178
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
? chart.labels.map((label, index) => [
|
|
194
|
-
label,
|
|
195
|
-
formatNumber({ value: chart.values[index] ?? 0 }),
|
|
196
|
-
])
|
|
197
|
-
: chart.type === 'line'
|
|
179
|
+
private static tableView(opts: { chart: TChart; chrome: TChrome }): string {
|
|
180
|
+
const { chart, chrome } = opts;
|
|
181
|
+
const head =
|
|
182
|
+
chart.type === 'line' ? ['', ...chart.series.map((s) => s.name)] : ['', chrome.value];
|
|
183
|
+
const rows =
|
|
184
|
+
chart.type === 'bar'
|
|
198
185
|
? chart.labels.map((label, index) => [
|
|
199
186
|
label,
|
|
200
|
-
|
|
187
|
+
SpecCharts.formatNumber({ value: chart.values[index] ?? 0 }),
|
|
201
188
|
])
|
|
202
|
-
: chart.
|
|
189
|
+
: chart.type === 'line'
|
|
190
|
+
? chart.labels.map((label, index) => [
|
|
191
|
+
label,
|
|
192
|
+
...chart.series.map((s) => SpecCharts.formatNumber({ value: s.values[index] ?? 0 })),
|
|
193
|
+
])
|
|
194
|
+
: chart.parts.map((part) => [part.label, SpecCharts.formatNumber({ value: part.value })]);
|
|
195
|
+
|
|
196
|
+
return `<details class="tv"><summary>${escaped(chrome.tableView)}</summary><div class="tw"><table><thead><tr>${head.map((cell) => `<th>${escaped(cell)}</th>`).join('')}</tr></thead><tbody>${rows.map((row) => `<tr>${row.map((cell) => `<td>${escaped(cell)}</td>`).join('')}</tr>`).join('')}</tbody></table></div></details>`;
|
|
197
|
+
}
|
|
203
198
|
|
|
204
|
-
|
|
205
|
-
}
|
|
199
|
+
/** One chart as a figure: a title, the drawing, a legend when there is more than one thing to tell apart, and its data as a table. */
|
|
200
|
+
static render(opts: { chart: TChart; chrome: TChrome }): string {
|
|
201
|
+
const { chart } = opts;
|
|
202
|
+
const drawing =
|
|
203
|
+
chart.type === 'bar'
|
|
204
|
+
? SpecCharts.barChart({ chart })
|
|
205
|
+
: chart.type === 'line'
|
|
206
|
+
? SpecCharts.lineChart({ chart })
|
|
207
|
+
: SpecCharts.donutChart({ chart });
|
|
208
|
+
|
|
209
|
+
return `<figure class="chart ${chart.type}"><figcaption class="lab">${escaped(chart.title)}</figcaption><div class="cbody">${drawing}${SpecCharts.legend({ chart })}</div>${SpecCharts.tableView({ chart, chrome: opts.chrome })}</figure>`;
|
|
210
|
+
}
|
|
206
211
|
|
|
207
|
-
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
212
|
+
/** Total scores of a comparison as horizontal bars out of the maximum, the recommendation in the accent. */
|
|
213
|
+
static renderTotals(opts: {
|
|
214
|
+
names: string[];
|
|
215
|
+
totals: number[];
|
|
216
|
+
best: number;
|
|
217
|
+
max: number;
|
|
218
|
+
chrome: TChrome;
|
|
219
|
+
}): string {
|
|
220
|
+
const rowHeight = 34;
|
|
221
|
+
const plot = 150;
|
|
222
|
+
|
|
223
|
+
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${opts.names.length * rowHeight + 6}" role="img" aria-label="${escaped(opts.chrome.total)}: ${opts.names.map((n, i) => `${escaped(n)} ${opts.totals[i]}`).join(', ')}">${opts.names
|
|
224
|
+
.map((name, index) => {
|
|
225
|
+
const y = index * rowHeight + 4;
|
|
226
|
+
const total = opts.totals[index] ?? 0;
|
|
227
|
+
const width = Math.max(2, Math.round((total / opts.max) * plot));
|
|
228
|
+
const isBest = index === opts.best;
|
|
229
|
+
|
|
230
|
+
return `<g><title>${escaped(name)}: ${total} ${escaped(opts.chrome.outOf)} ${opts.max}</title><text x="0" y="${y + 19}" class="ct${isBest ? ' strong' : ''}">${escaped(shorten({ value: name, max: 18 }))}</text><rect x="120" y="${y + 5}" width="${plot}" height="20" rx="4" class="ctrack"/><path d="${barPath({ x: 120, y: y + 5, width, height: 20 })}" fill="${isBest ? 'var(--accent)' : 'var(--muted)'}" opacity="${isBest ? 1 : 0.6}"/><text x="${120 + width + 6}" y="${y + 20}" class="cv">${total}</text></g>`;
|
|
231
|
+
})
|
|
232
|
+
.join('')}</svg>`;
|
|
233
|
+
}
|
|
219
234
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
totals: number[];
|
|
224
|
-
best: number;
|
|
225
|
-
max: number;
|
|
226
|
-
chrome: TChrome;
|
|
227
|
-
}): string => {
|
|
228
|
-
const rowHeight = 34;
|
|
229
|
-
const plot = 150;
|
|
230
|
-
|
|
231
|
-
return `<svg viewBox="0 0 ${VIEW_WIDTH} ${opts.names.length * rowHeight + 6}" role="img" aria-label="${escaped(opts.chrome.total)}: ${opts.names.map((n, i) => `${escaped(n)} ${opts.totals[i]}`).join(', ')}">${opts.names
|
|
232
|
-
.map((name, index) => {
|
|
233
|
-
const y = index * rowHeight + 4;
|
|
234
|
-
const total = opts.totals[index] ?? 0;
|
|
235
|
-
const width = Math.max(2, Math.round((total / opts.max) * plot));
|
|
236
|
-
const isBest = index === opts.best;
|
|
237
|
-
|
|
238
|
-
return `<g><title>${escaped(name)}: ${total} ${escaped(opts.chrome.outOf)} ${opts.max}</title><text x="0" y="${y + 19}" class="ct${isBest ? ' strong' : ''}">${escaped(shorten({ value: name, max: 18 }))}</text><rect x="120" y="${y + 5}" width="${plot}" height="20" rx="4" class="ctrack"/><path d="${barPath({ x: 120, y: y + 5, width, height: 20 })}" fill="${isBest ? 'var(--accent)' : 'var(--muted)'}" opacity="${isBest ? 1 : 0.6}"/><text x="${120 + width + 6}" y="${y + 20}" class="cv">${total}</text></g>`;
|
|
239
|
-
})
|
|
240
|
-
.join('')}</svg>`;
|
|
241
|
-
};
|
|
235
|
+
static stateIcon(opts: { state: string; size?: number }): string {
|
|
236
|
+
return IconSet.iconSvg({ name: NodeStates.iconOf(opts.state), size: opts.size });
|
|
237
|
+
}
|
|
242
238
|
|
|
243
|
-
|
|
244
|
-
|
|
239
|
+
/** 1234567 as 1,234,567 and 0.5 as 0.5: no locale, so the page reads the same everywhere. */
|
|
240
|
+
static formatNumber(opts: { value: number }): string {
|
|
241
|
+
const rounded = Math.round(opts.value * 100) / 100;
|
|
242
|
+
const [whole = '0', fraction] = String(Math.abs(rounded)).split('.');
|
|
243
|
+
const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
244
|
+
|
|
245
|
+
return `${rounded < 0 ? '-' : ''}${grouped}${fraction === undefined ? '' : `.${fraction}`}`;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -23,8 +23,9 @@ export const COMPARE_CSS = `.edge.added path{stroke:var(--ink);stroke-width:4.5}
|
|
|
23
23
|
.srcs .src{color:var(--ink);font-size:14px}
|
|
24
24
|
.srcs .by{color:var(--body);font-size:15.5px}
|
|
25
25
|
.terms{display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:2px;margin:0;border-radius:var(--radius);overflow:hidden}
|
|
26
|
-
.terms div{display:grid;
|
|
27
|
-
.terms
|
|
26
|
+
.terms div{display:grid;align-content:start;padding:26px 26px 30px;background:var(--bg-soft)}
|
|
27
|
+
@supports (grid-template-rows:subgrid){.terms div{grid-template-rows:subgrid;grid-row-end:span 2}}
|
|
28
|
+
.terms dt{color:var(--ink);font-size:19px;font-weight:650;letter-spacing:-.02em;margin-bottom:10px}
|
|
28
29
|
.terms dd{margin:0;max-width:52ch;color:var(--body);font-size:16px}
|
|
29
30
|
@media (max-width:700px){.srcs li{grid-template-columns:minmax(0,1fr)}.terms div{padding:22px 22px 26px}}
|
|
30
31
|
`;
|
|
@@ -2,12 +2,12 @@ import { EdgeSides } from './compare-schema.ts';
|
|
|
2
2
|
import type { TCompare } from './compare-schema.ts';
|
|
3
3
|
import type { TChrome } from './constants.ts';
|
|
4
4
|
import type { IDrawing } from './diagrams.ts';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { FigureLayout } from './layout.ts';
|
|
6
|
+
import { SpecSections } from './sections.ts';
|
|
7
7
|
import type { ISectionContext } from './sections.ts';
|
|
8
8
|
import { SourceRefs } from './sources.ts';
|
|
9
9
|
|
|
10
|
-
const escaped = (value: string): string => escapeText({ value });
|
|
10
|
+
const escaped = (value: string): string => FigureLayout.escapeText({ value });
|
|
11
11
|
|
|
12
12
|
/** The two sides of an arrow that is not in both. */
|
|
13
13
|
const ADDED = 'added';
|
|
@@ -57,7 +57,7 @@ export class CompareView {
|
|
|
57
57
|
/** The figure: the flow's own grid drawing with the added and removed arrows as their own classes. */
|
|
58
58
|
private static svgOf(opts: { compare: TCompare; chrome: TChrome }): string {
|
|
59
59
|
const { compare, chrome } = opts;
|
|
60
|
-
const svg =
|
|
60
|
+
const svg = FigureLayout.render({
|
|
61
61
|
flow: {
|
|
62
62
|
nodes: compare.nodes,
|
|
63
63
|
edges: compare.edges.map((edge) => ({
|
|
@@ -165,7 +165,9 @@ export class CompareView {
|
|
|
165
165
|
|
|
166
166
|
return {
|
|
167
167
|
svg: CompareView.svgOf(opts),
|
|
168
|
-
width: figureWidth({
|
|
168
|
+
width: FigureLayout.figureWidth({
|
|
169
|
+
cols: Math.max(...compare.nodes.map((node) => node.col)) + 1,
|
|
170
|
+
}),
|
|
169
171
|
fallback: `<ul class="legend cmp-key">${key}</ul>${CompareView.listOf(opts)}`,
|
|
170
172
|
};
|
|
171
173
|
}
|
|
@@ -185,10 +187,10 @@ export class CompareView {
|
|
|
185
187
|
compare.caption ??
|
|
186
188
|
`${CompareView.wordOf({ compare, chrome, side: EdgeSides.B })} (${count(EdgeSides.B)}), ${CompareView.wordOf({ compare, chrome, side: EdgeSides.A })} (${count(EdgeSides.A)})`;
|
|
187
189
|
|
|
188
|
-
return section({
|
|
190
|
+
return SpecSections.section({
|
|
189
191
|
id: 'compare',
|
|
190
192
|
title: chrome.compareView,
|
|
191
|
-
body: `<figure class="kfig">${figure({ ctx: opts.ctx, drawing: CompareView.drawing({ compare, chrome }) })}<figcaption>${escaped(caption)}</figcaption></figure>`,
|
|
193
|
+
body: `<figure class="kfig">${SpecSections.figure({ ctx: opts.ctx, drawing: CompareView.drawing({ compare, chrome }) })}<figcaption>${escaped(caption)}</figcaption></figure>`,
|
|
192
194
|
});
|
|
193
195
|
}
|
|
194
196
|
}
|