@intentius/behold 0.29.42 → 0.29.44
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/AGENTS.md +77 -0
- package/dist/cli.js +3969 -1918
- package/package.json +1 -1
- package/web/app.js +1463 -80
- package/web/carve-narration.js +33 -1
- package/web/chant-live-pace.js +138 -0
- package/web/chant-live-pace.test.js +116 -0
- package/web/chant-pr-marks.js +417 -39
- package/web/chant-pr-marks.test.js +208 -4
- package/web/collision-marks.js +124 -0
- package/web/collision-marks.test.js +89 -0
- package/web/cone.js +269 -0
- package/web/cone.test.js +213 -0
- package/web/dots-cards.js +362 -0
- package/web/dots-cards.test.js +303 -0
- package/web/dots-live.test.js +151 -1
- package/web/dots-lod.js +20 -0
- package/web/dots-lod.test.js +19 -1
- package/web/dots-scene.js +110 -10
- package/web/dots.js +489 -87
- package/web/embed.js +17 -1
- package/web/embed.test.js +19 -1
- package/web/event-help-modal.js +85 -3
- package/web/event-help-modal.test.js +85 -1
- package/web/feature-flags.js +143 -0
- package/web/feature-flags.test.js +96 -0
- package/web/index.html +33 -0
- package/web/kiosk-carve.js +59 -6
- package/web/kiosk-event-help-ui.js +150 -19
- package/web/kiosk-event-help.js +102 -15
- package/web/kiosk-event-help.test.js +58 -1
- package/web/kiosk-metrics.js +4 -3
- package/web/kiosk-runs.js +8 -5
- package/web/kiosk-shot.js +157 -3
- package/web/kiosk-shot.test.js +223 -1
- package/web/kiosk-source.js +43 -0
- package/web/kiosk-source.test.js +39 -0
- package/web/kiosk-story-gate.test.js +44 -0
- package/web/kiosk-track.js +312 -0
- package/web/kiosk-track.test.js +148 -0
- package/web/kiosk-unknown-step.test.js +58 -0
- package/web/kiosk-vendor.js +71 -4
- package/web/kiosk-vendor.test.js +103 -3
- package/web/kiosk-watch.js +154 -1
- package/web/kiosk-watch.test.js +53 -1
- package/web/kiosk.html +57 -22
- package/web/kiosk.js +566 -53
- package/web/kiosk.test.js +2 -1
- package/web/small-stage.test.js +150 -0
- package/web/terragucci-blocked.test.js +192 -0
- package/web/terragucci-change.js +197 -17
- package/web/terragucci-components-live.js +189 -13
- package/web/terragucci-live-pace.js +92 -0
- package/web/terragucci-wave-results.test.js +125 -0
- package/web/terralith.html +7 -7
- package/web/tg-outside.js +124 -0
- package/web/tg-outside.test.js +100 -0
- package/web/tg-read-pills.js +122 -0
- package/web/tg-read-pills.test.js +117 -0
- package/web/theme.js +13 -1
- package/web/theme.test.js +21 -1
- package/web/tooltip.js +19 -7
- package/web/tooltip.test.js +15 -0
- package/web/tours/terralith.json +4 -4
- package/web/trunk-lane.test.js +1 -1
- package/web/view-url.js +8 -2
- package/web/why.js +129 -1
- package/web/why.test.js +113 -1
package/web/kiosk-event-help.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { STRIP, matchingPull, matchingRun } from "./kiosk.js";
|
|
16
16
|
import { defaultStep } from "./kiosk-runs.js";
|
|
17
17
|
import { traceReadyWords } from "./kiosk-wave-traces.js";
|
|
18
|
+
import { resultBlocked, resultFailed, resultWords, waveResultOf } from "./terragucci-change.js";
|
|
18
19
|
|
|
19
20
|
export { EH_STORE, ehStore, ehStored } from "./event-help-store.js";
|
|
20
21
|
|
|
@@ -63,20 +64,35 @@ const jobLines = (job) => (job && Array.isArray(job.steps) ? job.steps.flatMap((
|
|
|
63
64
|
* `waves` is the declared waves (`{ job, wave, roots }`), so a job names its
|
|
64
65
|
* wave and a wave its roots.
|
|
65
66
|
*/
|
|
66
|
-
export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc = null, runDocs = [], approval = null, metrics = null, waveTraces = {}, waves = [], failed = [], strip = null } = {}) {
|
|
67
|
+
export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc = null, runDocs = [], approval = null, metrics = null, waveTraces = {}, waves = [], failed = [], strip = null, chant = false } = {}) {
|
|
67
68
|
if (!demo) return null;
|
|
68
69
|
const pr = matchingPull(answer, demo) || (answer && !answer.error && answer.pull_request && demo.pull !== null && String(answer.pull_request.run && answer.pull_request.run.pull_request) === String(demo.pull) ? answer.pull_request : null);
|
|
69
70
|
const run = matchingRun(progress, demo);
|
|
70
71
|
const jobs = runDoc && Array.isArray(runDoc.jobs) && (!demo.cycle || runDoc.cycle === undefined || runDoc.cycle === demo.cycle) ? runDoc.jobs : [];
|
|
72
|
+
// behold#751: a wave's result by its own report, of the commit the run applied: its job's status is no witness to it,
|
|
73
|
+
// since terragucci fails the job of a wave that applied what it planned and blocked the rest (terragucci#1161).
|
|
74
|
+
const resultOf = (commit, name, started) => {
|
|
75
|
+
const n = waveOfJob(name, waves);
|
|
76
|
+
return n === null ? null : waveResultOf(answer, commit, n, { after: started || null });
|
|
77
|
+
};
|
|
78
|
+
// The cycle's earlier runs' wave jobs that ended as failures, each with its report's word on the wave when there is one.
|
|
79
|
+
const pastJobs = (runDocs || [])
|
|
80
|
+
.filter((d) => d && d.id !== (runDoc && runDoc.id) && (!demo.cycle || d.cycle === undefined || d.cycle === demo.cycle) && Array.isArray(d.jobs))
|
|
81
|
+
.flatMap((d) => d.jobs.filter((j) => j.status === "failure" && waveOfJob(j.name, waves) !== null).map((j) => ({ wave: waveOfJob(j.name, waves), job: j.name, run: d.id, refusal: yodelRefusal(jobLines(j)), result: resultOf(d.commit, j.name, j.started_at) })));
|
|
71
82
|
return {
|
|
72
83
|
cycle: demo.cycle,
|
|
84
|
+
// behold#631: a chant repo's pull-request loop: a cycle may hold a fix's pull request after the first, each told as its own run of beats.
|
|
85
|
+
chant: !!chant,
|
|
86
|
+
// A scenario told in beats (the terralith: stock, adopt, split, team, cross) runs each beat's steps in one cycle.
|
|
87
|
+
beat: demo.beat || null,
|
|
73
88
|
step: demo.step,
|
|
74
89
|
pull: demo.pull,
|
|
75
90
|
label: demo.label || "",
|
|
76
91
|
plan: pr ? { totals: pr.totals || null, roots: pr.roots || [], reads: pr.reads || [] } : null,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
92
|
+
// behold#751: each wave with its report's result, of the run view's commit.
|
|
93
|
+
states: run ? (progress.states || []).map((s) => ({ ...s, result: waveResultOf(answer, run.commit, s.number) })) : [],
|
|
94
|
+
run: runDoc ? { id: runDoc.id, jobs: jobs.map((j) => ({ name: j.name, status: j.status, wave: waveOfJob(j.name, waves), refusal: j.status === "failure" ? yodelRefusal(jobLines(j)) : null, step: j.steps ? defaultStep(j.steps) : -1, result: resultOf(runDoc.commit, j.name, j.started_at) })) } : null,
|
|
95
|
+
approval: approval && Array.isArray(approval.rows) ? { wave: approval.wave, rows: approval.rows.filter((r) => r.state === "lit").map((r) => ({ id: r.id, at: r.at || null, actor: r.id === "approved" ? actorOf(r.text) : null, signed: !!(r.seal && /^signed/.test(r.seal.text || "")) })), ...(Array.isArray(approval.chantWaves) ? { chantWaves: approval.chantWaves } : {}) } : null,
|
|
80
96
|
// The numbers of this cycle's merge only: from the merge on, and only for its commit.
|
|
81
97
|
metrics: metrics && metrics.run && metrics.run.current && stepRank(demo.step, strip) >= stepRank("merged", strip) && (!demo.commit || String(metrics.run.label || "").includes(String(demo.commit).slice(0, 8))) ? metrics.run.waves.map((w) => ({ wave: w.wave, words: [w.seconds, w.held ? `held ${w.held}` : null, w.changed].filter(Boolean).join(" · ") })).filter((w) => w.words) : [],
|
|
82
98
|
// Each wave's trace, once Tempo has it (web/kiosk-wave-traces.js): `{ wave, run, job, words }`.
|
|
@@ -87,9 +103,9 @@ export function ehSnapshot({ demo = null, answer = null, progress = null, runDoc
|
|
|
87
103
|
// The waves this cycle saw fail, kept by the kiosk: a re-run is news only against a failure seen before it.
|
|
88
104
|
failed: [...new Set(failed)],
|
|
89
105
|
// The cycle's earlier runs' failures (the approval panel reads them): a viewer who arrives after the re-run still gets the refusal.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
106
|
+
// behold#751: a failed job whose wave's report says it applied and blocked roots is no failure of the wave: it is `pastBlocked`.
|
|
107
|
+
pastFailures: pastJobs.filter((f) => !f.result || resultFailed(f.result)).map(({ result, ...f }) => f),
|
|
108
|
+
pastBlocked: pastJobs.filter((f) => f.result && !resultFailed(f.result) && resultBlocked(f.result)),
|
|
93
109
|
};
|
|
94
110
|
}
|
|
95
111
|
|
|
@@ -120,6 +136,12 @@ const stepRank = (step, strip = STRIP) => (strip || STRIP).findIndex((s) => s.st
|
|
|
120
136
|
* landing pops a tip but is not a beat of the story); `critical` is a wave
|
|
121
137
|
* held for an approval, a wave that failed, and the cycle applied.
|
|
122
138
|
*/
|
|
139
|
+
/** The story a snapshot belongs to: its cycle, and its beat when the scenario is told in beats. */
|
|
140
|
+
export function storyKey(snap) {
|
|
141
|
+
if (!snap) return null;
|
|
142
|
+
return snap.beat ? `${snap.cycle}:${snap.beat}` : snap.cycle;
|
|
143
|
+
}
|
|
144
|
+
|
|
123
145
|
export function cycleFacts(snap) {
|
|
124
146
|
if (!snap) return [];
|
|
125
147
|
const out = [];
|
|
@@ -127,19 +149,24 @@ export function cycleFacts(snap) {
|
|
|
127
149
|
const strip = snap.strip || STRIP;
|
|
128
150
|
const at = stepRank(snap.step, strip);
|
|
129
151
|
const rank = (step) => stepRank(step, strip);
|
|
130
|
-
|
|
152
|
+
// Each beat of a cycle is a story of its own: the adopt beat's "applied" is not the split's.
|
|
153
|
+
// A chant cycle's second pull request (the fix) is its own run of beats: its ids and its place follow the pull request.
|
|
154
|
+
const c = snap.chant && snap.pull !== null && snap.pull !== undefined ? `${storyKey(snap)}|pr${snap.pull}` : storyKey(snap);
|
|
131
155
|
const runId = snap.run ? snap.run.id : null;
|
|
132
156
|
// The pull request and its plan.
|
|
133
157
|
if (snap.pull !== null && snap.pull !== undefined && at >= 0) add({ id: `${c}|pr`, kind: "pull-request", text: `pull request #${snap.pull} opened`, order: 0, subjects: { roots: snap.plan ? snap.plan.roots : [] } });
|
|
134
158
|
if (snap.plan && snap.plan.totals && at >= rank("planned")) {
|
|
135
159
|
add({ id: `${c}|plan`, kind: "planned", text: planWords(snap.plan.totals), order: 1, subjects: { roots: snap.plan.roots } });
|
|
136
160
|
}
|
|
137
|
-
|
|
161
|
+
// chant's gate comes before its merge: there the merge is said only once its step is reached.
|
|
162
|
+
const merged = snap.chant ? ["merged", "applying", "failed", "resumed", "applied"].includes(snap.step) : at >= rank("merged");
|
|
163
|
+
if (merged && snap.pull !== null && snap.pull !== undefined) add({ id: `${c}|merged`, kind: "merged", text: `pull request #${snap.pull} merged`, order: 2 });
|
|
138
164
|
// Each wave, from the run view; a wave's job, from the pipeline's run.
|
|
139
165
|
const jobOf = (n) => (snap.run ? snap.run.jobs.find((j) => j.wave === n) : null);
|
|
140
166
|
const approved = snap.approval ? snap.approval.rows.find((r) => r.id === "approved") : null;
|
|
141
167
|
const states = [...snap.states].sort((a, b) => a.number - b.number);
|
|
142
|
-
|
|
168
|
+
// behold#751: a wave an earlier run left roots of blocked runs again, as a failed one does.
|
|
169
|
+
const failedBefore = new Set([...(snap.failed || []), ...(snap.pastFailures || []).map((f) => f.wave), ...(snap.pastBlocked || []).map((f) => f.wave)]);
|
|
143
170
|
for (const s of states) {
|
|
144
171
|
const n = s.number;
|
|
145
172
|
const roots = rootsOfWave(n, snap.waves, states);
|
|
@@ -148,7 +175,9 @@ export function cycleFacts(snap) {
|
|
|
148
175
|
const base = 10 + n * 10;
|
|
149
176
|
if (["applying", "waiting", "applied", "failed", "refused"].includes(s.state)) add({ id: `${c}|w${n}|start`, kind: "started", text: `wave ${n} started`, order: base, subjects, trail: false });
|
|
150
177
|
// A failure the run view no longer shows (the re-run moved on) is still the pipeline's run's.
|
|
151
|
-
|
|
178
|
+
// behold#751: unless the wave's report says otherwise: a wave that applied what it planned and blocked the rest ends its
|
|
179
|
+
// job as a failure (terragucci#1161), and is no failed wave. The job's status speaks only where no report of the wave does.
|
|
180
|
+
const failedJob = job && job.status === "failure" && !(job.result && !resultFailed(job.result)) ? job : null;
|
|
152
181
|
const past = (snap.pastFailures || []).find((f) => f.wave === n);
|
|
153
182
|
if (s.state === "failed" || s.state === "refused" || failedJob || past) {
|
|
154
183
|
failedBefore.add(n);
|
|
@@ -167,7 +196,16 @@ export function cycleFacts(snap) {
|
|
|
167
196
|
}
|
|
168
197
|
}
|
|
169
198
|
if (failedBefore.has(n) && (s.state === "applying" || s.state === "applied") && !failedJob) add({ id: `${c}|w${n}|rerun`, kind: "rerun", text: `wave ${n} runs again`, order: base + 6, subjects });
|
|
170
|
-
|
|
199
|
+
// behold#751: what the wave's report says it held back, once the run view settles it, or an earlier run of the cycle did:
|
|
200
|
+
// "wave 3 applied 6, 6 blocked by cluster-a", "wave 3: 6 blocked by cluster-a" for one that ran nothing.
|
|
201
|
+
const nowHeld = ["applied", "blocked"].includes(s.state) ? [s.result, job && job.result].find((r) => r && !resultFailed(r) && resultBlocked(r)) : null;
|
|
202
|
+
const pastHeld = (snap.pastBlocked || []).find((f) => f.wave === n);
|
|
203
|
+
const held = nowHeld || (pastHeld && pastHeld.result);
|
|
204
|
+
if (held) {
|
|
205
|
+
const words = resultWords(held);
|
|
206
|
+
add({ id: `${c}|w${n}|blocked`, kind: "blocked", text: held.state === "applied" ? `wave ${n} ${words}` : `wave ${n}: ${words}`, order: base + 7, subjects: pastHeld && !(job && job.status === "failure") ? { ...subjects, job: pastHeld.job, run: pastHeld.run } : subjects });
|
|
207
|
+
}
|
|
208
|
+
if (s.state === "applied" && !nowHeld) {
|
|
171
209
|
const changed = changedWords(s.totals);
|
|
172
210
|
const under = approved && snap.approval.wave === n && approved.actor ? ` under ${approved.actor}'s approval` : "";
|
|
173
211
|
add({ id: `${c}|w${n}|applied`, kind: "applied-wave", text: `wave ${n} applied${under || (changed ? `: ${changed}` : "")}`, order: base + 7, subjects });
|
|
@@ -186,7 +224,35 @@ export function cycleFacts(snap) {
|
|
|
186
224
|
if (snap.approval && !Number.isInteger(snap.approval.wave)) {
|
|
187
225
|
if (snap.approval.rows.some((r) => r.id === "requested" || r.id === "approved")) add({ id: `${c}|held`, kind: "held", text: "the plan waits for an approval", order: 9, critical: true });
|
|
188
226
|
const ok = snap.approval.rows.find((r) => r.id === "approved");
|
|
189
|
-
|
|
227
|
+
// A chant kiosk names the reviewer alone: "forgejo@forgejo:3000:demo-reviewer, signed" is a principal, not a person.
|
|
228
|
+
if (ok) add({ id: `${c}|approved`, kind: "approved", text: snap.chant ? (ok.actor ? `approved by ${ok.actor.replace(/^.*:/, "")}` : "approved") : ok.actor ? `approved by ${ok.actor}${ok.signed ? ", signed" : ""}` : "approved, signed", order: 9.5 });
|
|
229
|
+
}
|
|
230
|
+
// behold#631: chant's pull-request apply, wave by wave from its run events: started, failed with the reason, applied, and what it left blocked.
|
|
231
|
+
for (const w of snap.approval && Array.isArray(snap.approval.chantWaves) ? snap.approval.chantWaves : []) {
|
|
232
|
+
const n = w.wave;
|
|
233
|
+
const base = 10 + n * 10;
|
|
234
|
+
const subjects = { roots: w.components || [], wave: n, run: runId };
|
|
235
|
+
if (["running", "applied", "failed"].includes(w.state)) add({ id: `${c}|w${n}|start`, kind: "started", text: `wave ${n} started`, order: base, subjects, trail: false });
|
|
236
|
+
// The cards of this wave and the next: what a failure's modal must leave in view (the half that went ahead too).
|
|
237
|
+
const next = snap.approval.chantWaves.find((x) => x.wave === n + 1);
|
|
238
|
+
const inView = [...(w.components || []), ...(next ? next.components || [] : [])];
|
|
239
|
+
for (const f of w.failed || []) {
|
|
240
|
+
// The step's label says why in words ("cluster-a failed: SQS refuses …"); CloudFormation's own words stay in the tooltip.
|
|
241
|
+
const said = typeof snap.label === "string" && snap.label.startsWith(`${f.component} failed:`) ? snap.label.split(/\.\s/)[0].replace(/\.$/, "") : null;
|
|
242
|
+
// The raw error rides along for a tooltip; the roots are the failed card and what it blocked.
|
|
243
|
+
add({ id: `${c}|w${n}|failed|${f.component}`, kind: "failed", text: said || `${f.component} failed`, order: base + 1, subjects: { ...subjects, roots: [f.component, ...(f.blocks || [])] }, critical: true, chant: true, avoid: [...new Set([f.component, ...(f.blocks || []), ...inView])], ...(f.error ? { raw: `${f.component} failed: ${f.error}` } : {}) });
|
|
244
|
+
}
|
|
245
|
+
if (w.state === "applied" || (w.state === "failed" && w.applied)) {
|
|
246
|
+
// A wave with a failure says both halves, by name when there are few: "wave 2: cluster-b applied, cluster-a failed".
|
|
247
|
+
const failedNames = (w.failed || []).map((f) => f.component);
|
|
248
|
+
const appliedNames = w.appliedNames || [];
|
|
249
|
+
const both = appliedNames.length && appliedNames.length <= 2 && failedNames.length <= 2 ? `wave ${n}: ${list(appliedNames)} applied, ${list(failedNames)} failed` : `wave ${n}: ${w.applied} applied, ${failedNames.length} failed`;
|
|
250
|
+
add({ id: `${c}|w${n}|applied`, kind: "applied-wave", text: w.state === "failed" ? both : w.blocked ? `wave ${n} applied ${w.applied}; ${w.blocked} blocked` : `wave ${n} applied`, order: base + 7, subjects });
|
|
251
|
+
}
|
|
252
|
+
if (w.blocked) {
|
|
253
|
+
const by = w.blockedBy && w.blockedBy.length ? ` by ${list(w.blockedBy)}` : "";
|
|
254
|
+
add({ id: `${c}|w${n}|blocked`, kind: "blocked", text: `${w.blocked} in wave ${n} blocked${by}: they did not run`, order: base + 8, subjects });
|
|
255
|
+
}
|
|
190
256
|
}
|
|
191
257
|
// A gate on the whole change (chant's pull-request loop): the plan waits, no wave named.
|
|
192
258
|
// A repo with declared waves names its held wave once the run view has it; this is for a repo without them.
|
|
@@ -203,9 +269,14 @@ export function cycleFacts(snap) {
|
|
|
203
269
|
const i = strip.findIndex((x) => x.id === id);
|
|
204
270
|
return i >= 0 ? i : strip.findIndex((x) => x.id === "waves");
|
|
205
271
|
};
|
|
206
|
-
|
|
272
|
+
// chant's gate comes before the merge: without its own stop it sits with the plan, not after the merge.
|
|
273
|
+
const gateStop = strip.some((x) => x.id === "approval") ? "approval" : snap.chant ? "planned" : "waves";
|
|
207
274
|
const stopOf = (f) => (["pull-request", "planned", "merged", "applied", "reset"].includes(f.kind) ? f.kind : f.kind === "pull-request" ? "pull-request" : ["held", "approved", "resumed"].includes(f.kind) && !Number.isInteger(f.subjects.wave) ? gateStop : "waves");
|
|
208
|
-
|
|
275
|
+
// A chant cycle's pull requests in turn: each one's beats after the one before's, whatever their stops.
|
|
276
|
+
const segment = snap.chant && Number.isInteger(snap.pull) ? snap.pull * 100_000 : 0;
|
|
277
|
+
return [...byId.values()]
|
|
278
|
+
.map((f) => ({ ...f, stop: stopOf(f), order: segment + Math.max(0, stopIndex(stopOf(f))) * 1000 + f.order, ...(snap.chant ? { pull: snap.pull } : {}) }))
|
|
279
|
+
.sort((a, b) => a.order - b.order);
|
|
209
280
|
}
|
|
210
281
|
|
|
211
282
|
/** The story trail: the cycle's facts that are beats of its story. */
|
|
@@ -240,6 +311,22 @@ export function tipsQueue(state, { add = [], now = 0, max = TIPS_AT_ONCE, ms = T
|
|
|
240
311
|
return { shown, waiting };
|
|
241
312
|
}
|
|
242
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Whether the caption already says what a critical modal would, so the modal
|
|
316
|
+
* stays shut: on a held small stage in Watch (`held`) nothing overlays the
|
|
317
|
+
* graph (web/kiosk-watch.js watchOverlays), and the caption says each step
|
|
318
|
+
* (the applied counts, a held wave's approval, a failure's label). Any other
|
|
319
|
+
* stage, and Inspect, open them as they always have.
|
|
320
|
+
*/
|
|
321
|
+
export function modalShownElsewhere(event, { watch = false, held = false } = {}) {
|
|
322
|
+
return !!watch && !!held && !!event;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Whether Tips' bubbles show: everywhere but a held small stage in Watch, where nothing overlays the graph; the trail over the caption stays. */
|
|
326
|
+
export function tipsShown({ watch = false, held = false } = {}) {
|
|
327
|
+
return !(watch && held);
|
|
328
|
+
}
|
|
329
|
+
|
|
243
330
|
/**
|
|
244
331
|
* The critical modals' queue: one at a time, never while a viewer is at the
|
|
245
332
|
* page (a pointer or a key within `quietMs`), and only the newest of each
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// the queues that keep tips and modals calm.
|
|
4
4
|
import { describe, expect, it } from "vitest";
|
|
5
5
|
import { stripFromSteps } from "./kiosk.js";
|
|
6
|
-
import { EH_STORE, cycleFacts, ehSnapshot, ehStore, ehStored, modalQueue, newEvents, storyTrail, tipsQueue, yodelRefusal } from "./kiosk-event-help.js";
|
|
6
|
+
import { EH_STORE, cycleFacts, ehSnapshot, ehStore, ehStored, modalQueue, newEvents, storyKey, storyTrail, tipsQueue, yodelRefusal } from "./kiosk-event-help.js";
|
|
7
7
|
|
|
8
8
|
const C = "9f3c2a71d04e5b8c6a1f2e3d4c5b6a7980716253";
|
|
9
9
|
const P = "1111111111111111111111111111111111111111";
|
|
@@ -80,6 +80,48 @@ describe("event-help: a cycle told in order", () => {
|
|
|
80
80
|
expect(storyTrail(facts("waiting", [st(1, "applied", ["network", "other"]), st(2, "waiting", ["app"])])).map((f) => f.kind)).toEqual(["pull-request", "planned", "merged", "applied-wave", "known", "held"]);
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
+
it("tells a chant cycle's pull requests in turn: the gate before the merge, the reviewer by name, the fix's beats after the first's (#631)", () => {
|
|
84
|
+
// The strip as the kiosk had it: no approval stop of its own.
|
|
85
|
+
const approval = { wave: null, rows: [{ id: "approved", state: "lit", text: "forgejo@forgejo:3000:demo-reviewer approved this exact digest.", seal: { ok: null, text: "signed" } }] };
|
|
86
|
+
const chant = (step, pull) => cycleFacts(ehSnapshot({ demo: { ...demo(step), pull, scenario: "fan-out", tool: "chant" }, answer: null, approval, chant: true }));
|
|
87
|
+
const first = chant("merged", 7);
|
|
88
|
+
expect(storyTrail(first).map((f) => f.text)).toEqual(["pull request #7 opened", "the plan waits for an approval", "approved by demo-reviewer", "pull request #7 merged"]);
|
|
89
|
+
// The fix's gate waits before its merge: no merge chip for it yet.
|
|
90
|
+
expect(chant("waiting", 8).some((f) => f.kind === "merged")).toBe(false);
|
|
91
|
+
const fix = chant("planned", 8);
|
|
92
|
+
expect(fix.find((f) => f.kind === "pull-request")).toMatchObject({ id: "7|pr8|pr", text: "pull request #8 opened", pull: 8 });
|
|
93
|
+
// Every beat of the fix sorts after every beat of the first.
|
|
94
|
+
expect(Math.min(...fix.map((f) => f.order))).toBeGreaterThan(Math.max(...first.map((f) => f.order)));
|
|
95
|
+
// A terragucci cycle keeps its ids and words.
|
|
96
|
+
expect(cycleFacts(ehSnapshot({ demo: demo("merged"), answer, approval })).find((f) => f.kind === "approved").text).toBe("approved by forgejo@forgejo:3000:demo-reviewer, signed");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("tells chant's apply wave by wave from its run events: the failure with its reason, and what it left blocked (#631)", () => {
|
|
100
|
+
const strip = stripFromSteps(["pull-request", "planned", "waiting", "approved", "merged", "applying", "failed", "applied", "reset"]);
|
|
101
|
+
const chantWaves = [
|
|
102
|
+
{ wave: 1, state: "applied", components: ["network"], applied: 1, failed: [], blocked: 0, blockedBy: [] },
|
|
103
|
+
{ wave: 2, state: "failed", components: ["cluster-a", "cluster-b"], applied: 1, failed: [{ component: "cluster-a", reason: "The name of a FIFO queue can only end with '.fifo'" }], blocked: 0, blockedBy: [] },
|
|
104
|
+
{ wave: 3, state: "applied", components: ["app-01", "app-07"], applied: 6, failed: [], blocked: 6, blockedBy: ["cluster-a"] },
|
|
105
|
+
];
|
|
106
|
+
const approval = { wave: null, rows: [{ id: "approved", state: "lit", text: "demo-reviewer approved this exact digest.", seal: { ok: null, text: "signed" } }], chantWaves };
|
|
107
|
+
const f = cycleFacts(ehSnapshot({ demo: { ...demo("failed"), scenario: "fan-out", tool: "chant" }, answer: null, approval, strip }));
|
|
108
|
+
// The step's label does not give the reason here, so the chip says the failure alone; CloudFormation's words never reach it.
|
|
109
|
+
expect(f.find((x) => x.kind === "failed")).toMatchObject({ text: "cluster-a failed", critical: true, chant: true, subjects: { wave: 2, roots: ["cluster-a"] } });
|
|
110
|
+
// A modal for it must leave wave 2 and wave 3 in view.
|
|
111
|
+
expect(f.find((x) => x.kind === "failed").avoid).toEqual(["cluster-a", "cluster-b", "app-01", "app-07"]);
|
|
112
|
+
expect(f.find((x) => x.id === "7|w3|applied")).toMatchObject({ kind: "applied-wave", text: "wave 3 applied 6; 6 blocked" });
|
|
113
|
+
expect(f.find((x) => x.kind === "blocked")).toMatchObject({ text: "6 in wave 3 blocked by cluster-a: they did not run", subjects: { wave: 3 } });
|
|
114
|
+
// A wave with a failure says both halves; by name when the wave says them.
|
|
115
|
+
expect(f.find((x) => x.id === "7|w2|applied")).toMatchObject({ text: "wave 2: 1 applied, 1 failed" });
|
|
116
|
+
const named = cycleFacts(ehSnapshot({ demo: { ...demo("failed"), scenario: "fan-out", tool: "chant" }, answer: null, approval: { ...approval, chantWaves: chantWaves.map((w) => (w.wave === 2 ? { ...w, appliedNames: ["cluster-b"] } : w)) }, strip }));
|
|
117
|
+
expect(named.find((x) => x.id === "7|w2|applied").text).toBe("wave 2: cluster-b applied, cluster-a failed");
|
|
118
|
+
// With the step's label giving the reason, the chip says it in the label's words.
|
|
119
|
+
const said = cycleFacts(ehSnapshot({ demo: { ...demo("failed"), label: "cluster-a failed: SQS refuses a FIFO queue whose name lacks .fifo. Its six apps are held." }, answer: null, approval, strip }));
|
|
120
|
+
expect(said.find((x) => x.kind === "failed").text).toBe("cluster-a failed: SQS refuses a FIFO queue whose name lacks .fifo");
|
|
121
|
+
// A terragucci repo's approval carries no chant waves, so none of these.
|
|
122
|
+
expect(cycleFacts(ehSnapshot({ demo: demo("failed"), answer, waves })).some((x) => x.kind === "blocked")).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
83
125
|
it("names each event's subjects, so the kiosk can place it", () => {
|
|
84
126
|
const held = facts("waiting", [st(1, "applied", ["network", "other"]), st(2, "waiting", ["app"])], { runDoc: { id: 4801, cycle: 7, jobs: [{ name: "apply-wave-2", status: "waiting", steps: [] }] } });
|
|
85
127
|
expect(held.find((f) => f.kind === "held")).toMatchObject({ critical: true, subjects: { roots: ["app"], wave: 2, job: "apply-wave-2", run: 4801 } });
|
|
@@ -160,3 +202,18 @@ describe("event-help: calm queues", () => {
|
|
|
160
202
|
expect(modalQueue({ waiting: [held] }, { now: 30_000, open: true }).next).toBeNull();
|
|
161
203
|
});
|
|
162
204
|
});
|
|
205
|
+
|
|
206
|
+
describe("a cycle told in beats", () => {
|
|
207
|
+
it("keeps each beat's story apart, so one beat's applied is never another's", () => {
|
|
208
|
+
const adopt = cycleFacts(ehSnapshot({ demo: demo("applied", { beat: "adopt" }) }));
|
|
209
|
+
const split = cycleFacts(ehSnapshot({ demo: demo("merged", { beat: "split" }) }));
|
|
210
|
+
const ids = new Set(adopt.map((f) => f.id));
|
|
211
|
+
expect(adopt.find((f) => f.kind === "applied").id).toBe("7:adopt|applied");
|
|
212
|
+
expect(split.some((f) => ids.has(f.id))).toBe(false);
|
|
213
|
+
expect(split.some((f) => f.kind === "applied")).toBe(false);
|
|
214
|
+
expect(storyKey({ cycle: 7, beat: "split" })).not.toBe(storyKey({ cycle: 7, beat: "adopt" }));
|
|
215
|
+
// A scenario with no beats keeps the cycle as its story, as before.
|
|
216
|
+
expect(storyKey({ cycle: 7, beat: null })).toBe(7);
|
|
217
|
+
expect(cycleFacts(ehSnapshot({ demo: demo("applied") })).find((f) => f.kind === "applied").id).toBe("7|applied");
|
|
218
|
+
});
|
|
219
|
+
});
|
package/web/kiosk-metrics.js
CHANGED
|
@@ -279,7 +279,7 @@ async function defaultFetch(url) {
|
|
|
279
279
|
* Start the pane in `host`. `tool` is the tool of a tool's page, null on
|
|
280
280
|
* /kiosk. Returns `{ stop }`.
|
|
281
281
|
*/
|
|
282
|
-
export function startMetrics(host, { tool = null, fetchJson = defaultFetch, store = null, setTimer = setInterval, clearTimer = clearInterval, doc = document, onModel = () => {} } = {}) {
|
|
282
|
+
export function startMetrics(host, { tool = null, reads = { demo: "/api/terragucci/demo", cycle: (t) => `/api/terragucci/cycles/${t}` }, fetchJson = defaultFetch, store = null, setTimer = setInterval, clearTimer = clearInterval, doc = document, onModel = () => {} } = {}) {
|
|
283
283
|
if (!host) return { stop() {} };
|
|
284
284
|
if (doc.head && !doc.getElementById("k-metrics-style")) {
|
|
285
285
|
const style = el(doc, "style");
|
|
@@ -311,8 +311,9 @@ export function startMetrics(host, { tool = null, fetchJson = defaultFetch, stor
|
|
|
311
311
|
if (busy) return;
|
|
312
312
|
busy = true;
|
|
313
313
|
try {
|
|
314
|
-
|
|
315
|
-
const
|
|
314
|
+
// behold#752: the page's own demo, terragucci's or chant's (web/kiosk-source.js).
|
|
315
|
+
const demo = await fetchJson(reads.demo);
|
|
316
|
+
const latest = tool && !(demo && demo.demo && demo.demo.tool === tool) ? await fetchJson(reads.cycle(tool)) : null;
|
|
316
317
|
const target = metricsTarget(demo, latest, tool);
|
|
317
318
|
const answer = target ? await fetchJson(metricsUrl(target)) : null;
|
|
318
319
|
// behold#571: which cycle this read is of; a read that failed keeps the pane as it was.
|
package/web/kiosk-runs.js
CHANGED
|
@@ -414,12 +414,13 @@ export function statusIcon(status) {
|
|
|
414
414
|
}
|
|
415
415
|
|
|
416
416
|
/** The sidebar: the live run pinned, then the recent ones. `pick(id)` selects one; nothing here writes. */
|
|
417
|
-
export function renderSidebar(host, index, selectedId, { now = new Date(), scenarios = {}, titles = {}, names = {}, pick = () => {}, merged = null, replay = false } = {}) {
|
|
417
|
+
export function renderSidebar(host, index, selectedId, { now = new Date(), scenarios = {}, titles = {}, names = {}, pick = () => {}, merged = null, replay = false, chant = false } = {}) {
|
|
418
418
|
host.replaceChildren();
|
|
419
419
|
const head = el("div", "r-side-head");
|
|
420
420
|
head.appendChild(el("div", "r-side-title", "Runs"));
|
|
421
421
|
// behold#571: a tool's page replays an earlier cycle's runs, and says so.
|
|
422
|
-
|
|
422
|
+
// behold#752: chant's demo's runs are built from chant's run events, not copied from the forge.
|
|
423
|
+
head.appendChild(el("div", "r-side-note", replay ? "The replayed cycle's runs, newest first." : chant ? "From chant's run events, newest first." : "From the forge, newest first."));
|
|
423
424
|
host.appendChild(head);
|
|
424
425
|
if (!index || index.error || index.absent || !index.doc) {
|
|
425
426
|
host.appendChild(el("p", "r-note", index ? index.absent || index.error : "Reading the runs…"));
|
|
@@ -817,6 +818,8 @@ export function startRuns(
|
|
|
817
818
|
filter = (index) => index,
|
|
818
819
|
replay = () => false,
|
|
819
820
|
hideLine = null,
|
|
821
|
+
// behold#752: where the live runs are read: terragucci's copies of forge runs, or chant's demo's runs built from its run events.
|
|
822
|
+
urls = { runs: "/api/terragucci/runs", run: (id) => `/api/terragucci/runs/${id}` },
|
|
820
823
|
} = {},
|
|
821
824
|
) {
|
|
822
825
|
const s = { index: null, run: null, selected: null, picked: 0, ui: { job: null, open: null, setup: null }, note: null, flash: null, scrollTo: null, pending: null, featsOpen: false };
|
|
@@ -865,7 +868,7 @@ export function startRuns(
|
|
|
865
868
|
}
|
|
866
869
|
// One merged read of the selected run for both the sidebar and its page.
|
|
867
870
|
const merged = ans && ans.doc ? mergeRun(entry, ans.doc) : null;
|
|
868
|
-
renderSidebar(side, s.index, id, { now: shown(), scenarios, titles: titles(), names: names(), pick, merged, replay: replay() });
|
|
871
|
+
renderSidebar(side, s.index, id, { now: shown(), scenarios, titles: titles(), names: names(), pick, merged, replay: replay(), chant: urls.runs.startsWith("/api/chant/") });
|
|
869
872
|
// The redraw replaces the scrollers: keep where a viewer left them.
|
|
870
873
|
const old = main.querySelector(".r-log");
|
|
871
874
|
const oldSteps = main.querySelector(".r-steps");
|
|
@@ -1068,7 +1071,7 @@ export function startRuns(
|
|
|
1068
1071
|
const readIndex = async () => {
|
|
1069
1072
|
// behold#571: a tool's page reads its replay's runs from `source`, and keeps its own repo's alone.
|
|
1070
1073
|
const src = source();
|
|
1071
|
-
s.index = filter(src ? await src.index() : await fetchJson(
|
|
1074
|
+
s.index = filter(src ? await src.index() : await fetchJson(urls.runs));
|
|
1072
1075
|
const runs = s.index && s.index.doc ? s.index.doc.runs : [];
|
|
1073
1076
|
const live = liveRun(runs);
|
|
1074
1077
|
onLive(live);
|
|
@@ -1087,7 +1090,7 @@ export function startRuns(
|
|
|
1087
1090
|
if (key === lastRunKey && entry && !LIVE.has(entry.status) && s.run && s.run.doc && s.run.doc.id === id) return draw();
|
|
1088
1091
|
if (s.run && s.run.doc && s.run.doc.id !== id && !s.pending) s.ui = { job: null, open: null, setup: null };
|
|
1089
1092
|
lastRunKey = key;
|
|
1090
|
-
s.run = src ? await src.run(id) : await fetchJson(
|
|
1093
|
+
s.run = src ? await src.run(id) : await fetchJson(urls.run(id));
|
|
1091
1094
|
draw();
|
|
1092
1095
|
};
|
|
1093
1096
|
void readIndex();
|
package/web/kiosk-shot.js
CHANGED
|
@@ -13,8 +13,12 @@ export const SHOT_MAX_SCALE = 1.3;
|
|
|
13
13
|
/** Room kept round a shot's target, in svg units. */
|
|
14
14
|
export const SHOT_PAD = 36;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* A `behold:shot` message: what to frame, and the pane's covered edges in
|
|
18
|
+
* pixels. `room`: the caption's tallest in the cycle, as a bottom inset in px
|
|
19
|
+
* (web/kiosk-watch.js captionRoom), which only a held small stage keeps.
|
|
20
|
+
*/
|
|
21
|
+
export function shotMessage({ roots = [], waves = [], whole = false, insets = {}, ms = SHOT_MS, id = null, room = 0 } = {}) {
|
|
18
22
|
const px = (v) => (Number.isFinite(v) && v > 0 ? Math.round(v) : 0);
|
|
19
23
|
return {
|
|
20
24
|
type: "behold:shot",
|
|
@@ -24,6 +28,7 @@ export function shotMessage({ roots = [], waves = [], whole = false, insets = {}
|
|
|
24
28
|
whole: !!whole || (!roots.length && !waves.length),
|
|
25
29
|
insets: { top: px(insets.top), right: px(insets.right), bottom: px(insets.bottom), left: px(insets.left) },
|
|
26
30
|
ms: Number.isFinite(ms) && ms >= 0 ? ms : SHOT_MS,
|
|
31
|
+
...(px(room) ? { room: px(room) } : {}),
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
34
|
|
|
@@ -35,7 +40,7 @@ export function shotFromMessage(event, host) {
|
|
|
35
40
|
// Inspect: no shot; the frame fits the graph as it always has.
|
|
36
41
|
if (d.release === true) return { type: "behold:shot", release: true };
|
|
37
42
|
const list = (v) => (Array.isArray(v) ? v : []);
|
|
38
|
-
return shotMessage({ roots: list(d.roots), waves: list(d.waves), whole: d.whole, insets: d.insets && typeof d.insets === "object" ? d.insets : {}, ms: d.ms, id: d.id ?? null });
|
|
43
|
+
return shotMessage({ roots: list(d.roots), waves: list(d.waves), whole: d.whole, insets: d.insets && typeof d.insets === "object" ? d.insets : {}, ms: d.ms, id: d.id ?? null, room: d.room });
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
/** The smallest box round several `{x, y, x2, y2}`, or null for none. */
|
|
@@ -101,3 +106,152 @@ export function tweenViewBox(a, b, t) {
|
|
|
101
106
|
export function sameViewBox(a, b) {
|
|
102
107
|
return !!a && !!b && a.length === 4 && b.length === 4 && a.every((v, i) => Math.abs(v - b[i]) < 0.5);
|
|
103
108
|
}
|
|
109
|
+
|
|
110
|
+
// --- one framing on a small stage --------------------------------------------
|
|
111
|
+
// When the whole graph fits the stage with its cards drawn readably (a card
|
|
112
|
+
// at least SMALL_STAGE_CARD_PX wide on screen, the width the dots layer's
|
|
113
|
+
// cards are fully drawn at: web/dots-lod.js LOD.cardPx), Watch holds one shot
|
|
114
|
+
// of the whole graph: every step's shot frames the whole
|
|
115
|
+
// graph, and the viewBox stays where it is from step to step and cycle to
|
|
116
|
+
// cycle while the graph and the pane stay, so a root no
|
|
117
|
+
// step is about stays in view and emphasis is by light and dim only. A bigger
|
|
118
|
+
// graph keeps the per-step framing.
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether a stage may be held at all: an estate whose every root runs on
|
|
122
|
+
* choudoufu's live backend, by the reports (`binaries`, root to binary). The
|
|
123
|
+
* scenarios on any other binary (b-waves, failure, tg-planned-outputs) keep
|
|
124
|
+
* Watch as it always was: a shot per step, and their cards over the graph.
|
|
125
|
+
*/
|
|
126
|
+
export function holdsStage(binaries) {
|
|
127
|
+
const b = binaries && typeof binaries === "object" ? Object.values(binaries) : [];
|
|
128
|
+
return b.length > 0 && b.every((x) => x === "choudoufu");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The width in px a card needs on screen for the stage to count as small: dots-lod.js LOD.cardPx. */
|
|
132
|
+
export const SMALL_STAGE_CARD_PX = 90;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Room kept under the whole graph beyond the caption first seen, in px: the
|
|
136
|
+
* caption's extra rows (the cone line, the quiet line) and event-help's trail
|
|
137
|
+
* over it, which grows by a line or two as the cycle's beats come in, all fit
|
|
138
|
+
* in it, so none of them moves the frame.
|
|
139
|
+
*/
|
|
140
|
+
export const HOLD_RESERVE_PX = 24;
|
|
141
|
+
|
|
142
|
+
/** Room kept at the top for the run's caption over the boxes ("Showing the plan of …"), in px. */
|
|
143
|
+
export const HELD_CAPTION_PX = 32;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The most a held stage zooms in, px per svg unit: as large as the stage area
|
|
147
|
+
* (the pane less the caption and its reserve) allows, up to this.
|
|
148
|
+
*/
|
|
149
|
+
export const HELD_MAX_SCALE = 2.4;
|
|
150
|
+
|
|
151
|
+
/** A held framing at least this share of the width the graph needs is kept; a wider one frames again, to fill the stage. */
|
|
152
|
+
export const HELD_FILL = 0.9;
|
|
153
|
+
|
|
154
|
+
const boxInside = (a, b) => a.x >= b.x - 0.5 && a.y >= b.y - 0.5 && a.x2 <= b.x2 + 0.5 && a.y2 <= b.y2 + 0.5;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* What a held stage frames, from the boxes' rects and the cards' own rects
|
|
158
|
+
* (svg units): the graph's boxes, each innermost box that holds a card (a box
|
|
159
|
+
* round other boxes, a member's or the page's, is not what the graph spans),
|
|
160
|
+
* and the cards inside them. A card in no box, a rect bigger than its card
|
|
161
|
+
* (a hover ring) or anything else on the page counts only when no box holds a
|
|
162
|
+
* card at all: then the cards are the graph. Null with no card.
|
|
163
|
+
*/
|
|
164
|
+
export function heldTarget(boxes, cards) {
|
|
165
|
+
const cs = (cards || []).filter(Boolean);
|
|
166
|
+
if (!cs.length) return null;
|
|
167
|
+
const centre = (c) => ({ x: (c.x + c.x2) / 2, y: (c.y + c.y2) / 2 });
|
|
168
|
+
const holds = (b, c) => { const m = centre(c); return m.x > b.x && m.x < b.x2 && m.y > b.y && m.y < b.y2; };
|
|
169
|
+
const cand = (boxes || []).filter((b) => b && cs.some((c) => holds(b, c)));
|
|
170
|
+
const inner = cand.filter((b) => !cand.some((o) => o !== b && boxInside(o, b) && !boxInside(b, o)));
|
|
171
|
+
return inner.length ? unionBox(inner) : unionBox(cs);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** How far the pane's size may differ, in px, and still be the same pane (a swapped-in frame's box can round otherwise). */
|
|
175
|
+
export const PANE_SLACK_PX = 2;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The insets a held stage frames clear of, from a shot's: the run's caption's
|
|
179
|
+
* room at the top, the caption under the stage, and the same margin at the
|
|
180
|
+
* right as at the left. Nothing a step shows sits over the graph in Watch
|
|
181
|
+
* (web/kiosk-watch.js watchOverlays), so no card's room is kept at the side,
|
|
182
|
+
* and the graph has the stage's whole width; a drawer a viewer opens lies
|
|
183
|
+
* over it until they fold it, and never moves the frame.
|
|
184
|
+
*/
|
|
185
|
+
export function heldInsets(insets = {}, room = 0) {
|
|
186
|
+
const n = (v) => (Number.isFinite(v) && v > 0 ? v : 0);
|
|
187
|
+
return { top: n(insets.top) + HELD_CAPTION_PX, right: n(insets.left), bottom: Math.max(n(insets.bottom), n(room)), left: n(insets.left) };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Room kept round a held stage's graph, in svg units: none. The insets'
|
|
192
|
+
* margins (20 px at the sides, the run's caption's room at the top) keep the
|
|
193
|
+
* boxes off the edges, so the scale applied is min(openW / targetW, openH /
|
|
194
|
+
* targetH), up to HELD_MAX_SCALE.
|
|
195
|
+
*/
|
|
196
|
+
export const HELD_PAD = 0;
|
|
197
|
+
|
|
198
|
+
/** How far, in svg units, the graph may lie past a held framing's open part and still be held: a few units, inside the margins. */
|
|
199
|
+
export const HELD_SLACK = 4;
|
|
200
|
+
|
|
201
|
+
/** The middle of a list of card widths, in svg units; 0 for none. */
|
|
202
|
+
export function medianWidth(widths) {
|
|
203
|
+
const w = widths.filter((x) => Number.isFinite(x) && x > 0).sort((a, b) => a - b);
|
|
204
|
+
return w.length ? w[w.length >> 1] : 0;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Whether the stage is small: the whole graph (`whole`, svg units), framed on
|
|
209
|
+
* `pane` clear of `insets`, draws a card `cardW` units wide at least `minPx` on screen.
|
|
210
|
+
*/
|
|
211
|
+
export function smallStage(whole, pane, insets, cardW, { minPx = SMALL_STAGE_CARD_PX } = {}) {
|
|
212
|
+
if (!(cardW > 0)) return false;
|
|
213
|
+
const vb = shotViewBox(whole, pane, insets, { pad: HELD_PAD, maxScale: HELD_MAX_SCALE });
|
|
214
|
+
return !!vb && (cardW * pane.width) / vb[2] >= minPx;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The held whole-graph framing: `held` from the last call (or null), `key`
|
|
219
|
+
* naming the graph drawn (the repo and the view), the pane, the overlays'
|
|
220
|
+
* insets now (heldInsets) and the whole graph's box. The viewBox stays put
|
|
221
|
+
* from step to step and from cycle to cycle while the key and the pane's size
|
|
222
|
+
* stay (to PANE_SLACK_PX), the overlays fit in the room it kept, and the graph
|
|
223
|
+
* still lies in the open part of it (a badge, a label or a box a few units
|
|
224
|
+
* off moves nothing). Otherwise it is framed again, round the graph as it was
|
|
225
|
+
* and as it is, with room for the largest overlay seen so far, and
|
|
226
|
+
* HOLD_RESERVE_PX more under the graph. `{ key, pane, insets, target, vb,
|
|
227
|
+
* reason }`, `reason` saying why it was framed: "first", "key", "pane",
|
|
228
|
+
* "insets", "target", or "held" when it was not.
|
|
229
|
+
*/
|
|
230
|
+
export function heldFrame(held, { key, pane, insets = {}, target }) {
|
|
231
|
+
const i = { top: insets.top || 0, right: insets.right || 0, bottom: insets.bottom || 0, left: insets.left || 0 };
|
|
232
|
+
const samePane = !!held && !!held.pane && Math.abs(held.pane.width - pane.width) <= PANE_SLACK_PX && Math.abs(held.pane.height - pane.height) <= PANE_SLACK_PX;
|
|
233
|
+
const same = !!held && !!held.vb && held.key === key && samePane;
|
|
234
|
+
const roomy = same && ["top", "right", "bottom", "left"].every((k) => i[k] <= held.insets[k]);
|
|
235
|
+
if (roomy && target) {
|
|
236
|
+
const [x, y, w, h] = held.vb;
|
|
237
|
+
const s = held.pane.width / w;
|
|
238
|
+
const open = { x: x + held.insets.left / s, y: y + held.insets.top / s, x2: x + w - held.insets.right / s, y2: y + h - held.insets.bottom / s };
|
|
239
|
+
// A box a few units off (a frame drawn from another checkout) moves nothing: the side margins hold it.
|
|
240
|
+
const inside = target.x >= open.x - HELD_SLACK && target.y >= open.y - HELD_SLACK && target.x2 <= open.x2 + HELD_SLACK && target.y2 <= open.y2 + HELD_SLACK;
|
|
241
|
+
// And it still fills the stage: a framing much wider than the graph needs (the graph got smaller) frames again.
|
|
242
|
+
const ideal = shotViewBox(target, held.pane, held.insets, { pad: HELD_PAD, maxScale: HELD_MAX_SCALE });
|
|
243
|
+
const fills = !ideal || ideal[2] >= held.vb[2] * HELD_FILL;
|
|
244
|
+
if (inside && fills) return held.reason === "held" ? held : { ...held, reason: "held" };
|
|
245
|
+
}
|
|
246
|
+
const reason = !held ? "first" : held.key !== key ? "key" : !samePane ? "pane" : !roomy ? "insets" : !target || !held.target || !boxInside(target, held.target) ? "target" : "fill";
|
|
247
|
+
const keep = same ? held.insets : { top: 0, right: 0, bottom: 0, left: 0 };
|
|
248
|
+
const room = {
|
|
249
|
+
top: Math.max(keep.top, i.top),
|
|
250
|
+
right: Math.max(keep.right, i.right),
|
|
251
|
+
bottom: i.bottom > keep.bottom ? i.bottom + HOLD_RESERVE_PX : keep.bottom,
|
|
252
|
+
left: Math.max(keep.left, i.left),
|
|
253
|
+
};
|
|
254
|
+
// Round the graph as it was and as it is, so a box a few units off never frames twice; a graph that shrank is framed as it is.
|
|
255
|
+
const box = same && target && reason !== "fill" ? unionBox([held.target, target]) : target;
|
|
256
|
+
return { key, pane: { width: pane.width, height: pane.height }, insets: room, target: box, vb: shotViewBox(box, pane, room, { pad: HELD_PAD, maxScale: HELD_MAX_SCALE }), reason };
|
|
257
|
+
}
|