@intentius/behold 0.29.29 → 0.29.31
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/dist/cli.js +8 -3
- package/package.json +1 -1
- package/web/app.js +261 -4
- package/web/index.html +42 -2
- package/web/kiosk-approval.js +1 -1
- package/web/kiosk-metrics.js +36 -7
- package/web/kiosk-metrics.test.js +52 -3
- package/web/kiosk-runs.js +12 -6
- package/web/kiosk-runs.test.js +11 -1
- package/web/kiosk-shot.js +103 -0
- package/web/kiosk-shot.test.js +79 -0
- package/web/kiosk-trace.js +29 -5
- package/web/kiosk-trace.test.js +29 -1
- package/web/kiosk-vendor.test.js +5 -3
- package/web/kiosk-watch.js +263 -0
- package/web/kiosk-watch.test.js +181 -0
- package/web/kiosk.html +227 -50
- package/web/kiosk.js +565 -71
- package/web/kiosk.test.js +31 -20
- package/web/operator.js +3 -0
- package/web/run-playhead.js +4 -0
- package/web/theme.js +49 -0
- package/web/theme.test.js +56 -1
package/dist/cli.js
CHANGED
|
@@ -24359,7 +24359,9 @@ body { background: var(--bg, #1e1e2e); color: var(--fg, #cdd6f4); padding-bottom
|
|
|
24359
24359
|
color: var(--fg, #cdd6f4); display: none; }
|
|
24360
24360
|
#behold-diff h4 { margin: 0 0 6px; font: 600 10.5px/1.4 ui-sans-serif, system-ui, sans-serif;
|
|
24361
24361
|
text-transform: uppercase; letter-spacing: .07em; color: var(--muted, #777a8c); }
|
|
24362
|
-
#behold-diff .a { color: var(--managed, #a6e3a1); } #behold-diff .r { color: var(--degraded, #f38ba8); } #behold-diff .c { color: var(--foreign, #f9e2af); }
|
|
24362
|
+
#behold-diff .a { color: var(--managed, #a6e3a1); } #behold-diff .r { color: var(--degraded, #f38ba8); } #behold-diff .c { color: var(--foreign, #f9e2af); }
|
|
24363
|
+
#behold-diff .a, #behold-diff .r, #behold-diff .c { padding-left: 7px; margin: 1px 0; box-shadow: inset 3px 0 0 var(--bar-neutral, #9a9eb5); }
|
|
24364
|
+
#behold-diff .a { box-shadow: inset 3px 0 0 var(--bar-managed, #a6e3a1); } #behold-diff .r { box-shadow: inset 3px 0 0 var(--bar-degraded, #f38ba8); } #behold-diff .c { box-shadow: inset 3px 0 0 var(--bar-foreign, #f9e2af); }`;
|
|
24363
24365
|
var THEME_BOOT = `<script type="module">import { initTheme, onThemeChange, mountThemePicker } from "/theme.js"; initTheme(); mountThemePicker(document.getElementById("behold-lanes-pickers")); onThemeChange(() => window.dispatchEvent(new Event("behold-theme")));</script>`;
|
|
24364
24366
|
function laneStripScript(frames) {
|
|
24365
24367
|
return `<script>
|
|
@@ -24394,6 +24396,8 @@ const LF = ${safeJson(frames)};
|
|
|
24394
24396
|
c.clearRect(0, 0, host.clientWidth, H); c.font = "12px ui-sans-serif, system-ui, sans-serif";
|
|
24395
24397
|
subs.forEach((s, r) => {
|
|
24396
24398
|
const y = padT + r * rowH + rowH / 2;
|
|
24399
|
+
// behold#571: each substrate's row has its left bar, as every listed item does (theme.js barInks); an offset row's is amber.
|
|
24400
|
+
c.fillStyle = offset[s] ? css("--bar-foreign", "#f9e2af") : css("--bar-neutral", "#9a9eb5"); c.fillRect(0, padT + r * rowH + 2, 3, rowH - 4);
|
|
24397
24401
|
c.fillStyle = offset[s] ? css("--foreign", "#f9e2af") : css("--muted", "#777a8c"); c.textAlign = "left"; c.fillText(s, 8, y + 4);
|
|
24398
24402
|
c.strokeStyle = css("--line", "#3b3c4a"); c.beginPath(); c.moveTo(padL, y); c.lineTo(host.clientWidth - padR, y); c.stroke();
|
|
24399
24403
|
LF.forEach((f, i) => {
|
|
@@ -26420,6 +26424,7 @@ var KEPT_ATTRIBUTES = [
|
|
|
26420
26424
|
"terragucci.gate.held_seconds",
|
|
26421
26425
|
"terragucci.gate.waiting_since",
|
|
26422
26426
|
"terragucci.gate.approved_at",
|
|
26427
|
+
"terragucci.wait",
|
|
26423
26428
|
"process.exit.code",
|
|
26424
26429
|
"opentofu.resource_instance.address",
|
|
26425
26430
|
"opentofu.resource_instance.action",
|
|
@@ -26507,8 +26512,8 @@ function trimTrace(traceId, body, repo, maxSpans = MAX_SPANS) {
|
|
|
26507
26512
|
if (!own || !projectIs(String(own["terragucci.project"]), repo) || spans.length === 0) return null;
|
|
26508
26513
|
spans.sort((a, b) => a.start - b.start);
|
|
26509
26514
|
const stage = spans.find((s) => s.parent === null && typeof s.attrs["terragucci.stage"] === "string") ?? spans.find((s) => s.parent === null) ?? spans[0];
|
|
26510
|
-
const start = Math.min(...spans.map((s) => s.start));
|
|
26511
|
-
const end = Math.max(...spans.map((s) => s.start + s.ms));
|
|
26515
|
+
const start = stage.parent === null ? stage.start : Math.min(...spans.map((s) => s.start));
|
|
26516
|
+
const end = stage.parent === null ? stage.start + stage.ms : Math.max(...spans.map((s) => s.start + s.ms));
|
|
26512
26517
|
let kept = spans;
|
|
26513
26518
|
if (spans.length > maxSpans) {
|
|
26514
26519
|
const byId = new Map(spans.map((s) => [s.id, s]));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intentius/behold",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.31",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "behold — a live control plane on chant. See your whole estate (every substrate in one graph), coloured by drift; act through delegated, gated Ops.",
|
package/web/app.js
CHANGED
|
@@ -34,7 +34,7 @@ import { edgeKey, edgeLabel, edgeLegend, edgeTitle, isCiKind, viaIndex } from ".
|
|
|
34
34
|
import { readCostLine } from "./read-cost.js";
|
|
35
35
|
import { mountHistoryPicker } from "./history-picker.js";
|
|
36
36
|
import { applyMemberFrame, createMemberFrames, pendingLine, stillPending } from "./pending.js";
|
|
37
|
-
import { initTheme, setTheme, mountThemePicker, readableOn, inkOn, colorForCategory, onThemeChange, getTokens, getTheme, pinTokensFor } from "./theme.js";
|
|
37
|
+
import { initTheme, setTheme, mountThemePicker, readableOn, inkOn, colorForCategory, onThemeChange, getTokens, getTheme, pinTokensFor, barVarFor } from "./theme.js";
|
|
38
38
|
// #399 M2 / #401 M4 of #397: the colour-by modes' arithmetic and the
|
|
39
39
|
// provenance badge's wording — every decision the behaviour overlay makes,
|
|
40
40
|
// pure and unit-tested beside the file. This module owns the fetches, the SVG
|
|
@@ -111,6 +111,7 @@ import { danglingFor, danglingRows, danglingHeading, DANGLING_EXPLAINED } from "
|
|
|
111
111
|
import { comparisonRow, comparisonSummary } from "./cross-env.js";
|
|
112
112
|
// The marker-vs-derived mark on a choudoufu card: how its identity was found.
|
|
113
113
|
import { identityMark, tagGlyphSvg } from "./identity-mark.js";
|
|
114
|
+
import { shotFromMessage, shotViewBox, tweenViewBox, unionBox, sameViewBox } from "./kiosk-shot.js"; // behold#571: Watch's camera
|
|
114
115
|
initTheme();
|
|
115
116
|
// #476: framed in a host pane. The flag is a class on <html>, so the CSS that
|
|
116
117
|
// folds the chrome away needs no JS, and the theme is the host's for this
|
|
@@ -2456,6 +2457,8 @@ function panelDotRow(color, main, tag, onClick) {
|
|
|
2456
2457
|
const dot = document.createElement("span");
|
|
2457
2458
|
dot.className = "dot";
|
|
2458
2459
|
dot.style.background = color;
|
|
2460
|
+
// behold#571: the row's left bar, in its dot's state (barVarFor).
|
|
2461
|
+
row.style.setProperty("--bar", barVarFor(color));
|
|
2459
2462
|
const name = document.createElement("span");
|
|
2460
2463
|
name.className = "grow";
|
|
2461
2464
|
name.textContent = main;
|
|
@@ -3549,6 +3552,8 @@ const TG_TONE = { plan: "var(--frame-pending, var(--pending))", wait: "var(--fra
|
|
|
3549
3552
|
const TG_CARD_TONE = Object.fromEntries(Object.entries(TG_TONE).map(([k, v]) => [k, v.replace("--frame-", "--frame-card-")]));
|
|
3550
3553
|
function drawTgReads() {
|
|
3551
3554
|
if (embedOpts.bare) queueMicrotask(kioskDecorate); // behold#571: once this draw is done
|
|
3555
|
+
if (embedOpts.bare) queueMicrotask(() => (kioskShot ? applyKioskShot(false) : kioskTellBoxes())); // behold#571: the marks moved the boxes
|
|
3556
|
+
if (embedOpts.bare) queueMicrotask(kioskTellDrawn); // behold#571: the kiosk swaps a reloaded frame in once it has drawn
|
|
3552
3557
|
watchTgRuns();
|
|
3553
3558
|
watchChantPr(); // behold#631 // #571: the wave boxes' jobs, while the components zoom is on screen
|
|
3554
3559
|
const svg = document.querySelector("#graph svg");
|
|
@@ -3795,6 +3800,8 @@ function drawTgReads() {
|
|
|
3795
3800
|
.map(boxOf)
|
|
3796
3801
|
.filter(Boolean)
|
|
3797
3802
|
.map((b) => grow(b, 3));
|
|
3803
|
+
// behold#571: a box's title grows as the view zooms out (scaleBoxLabels), so it is kept clear at the largest it gets.
|
|
3804
|
+
textBoxes.push(...boxTitlesAtMost(svg, boxOf).map((b) => grow(b, 3)));
|
|
3798
3805
|
const cardEls = [...svg.querySelectorAll("[data-node-id]")];
|
|
3799
3806
|
const cardBoxOf = new Map(cardEls.map((g) => [g, boxOf(g)]));
|
|
3800
3807
|
// #571: how many of the components graph's own edge points a segment runs over, so a read never hides a dependency line.
|
|
@@ -3849,9 +3856,12 @@ function drawTgReads() {
|
|
|
3849
3856
|
if (crosses({ x: a.x + ux * 4, y: a.y + uy * 4 }, { x: a.x + ux * 4, y: a.y + uy * 4 }, fromBox)) continue;
|
|
3850
3857
|
if (crosses({ x: z.x - ux * 4, y: z.y - uy * 4 }, { x: z.x - ux * 4, y: z.y - uy * 4 }, toBox)) continue;
|
|
3851
3858
|
const texts = textBoxes.filter((t) => crosses(a, z, t)).length;
|
|
3859
|
+
// behold#571: the arrowhead, not only the line, ends clear of every title and mark: a head over text costs most of all.
|
|
3860
|
+
const head = arrowheadBox(p0, p1);
|
|
3861
|
+
const heads = textBoxes.filter((t) => head.x < t.x2 && head.x2 > t.x && head.y < t.y2 && head.y2 > t.y).length;
|
|
3852
3862
|
const cards = others.filter((c) => crosses(a, z, c)).length;
|
|
3853
3863
|
const lines = drawn.filter((d) => crosses(a, z, grow({ x: Math.min(d.p0.x, d.p1.x), y: Math.min(d.p0.y, d.p1.y), x2: Math.max(d.p0.x, d.p1.x), y2: Math.max(d.p0.y, d.p1.y) }, 0)) && Math.hypot(d.p1.x - p1.x, d.p1.y - p1.y) < 30).length;
|
|
3854
|
-
const score = texts * 10000 + cards * 2000 + lines * 500 + nearEdge(a, z) * 400 + len;
|
|
3864
|
+
const score = heads * 30000 + texts * 10000 + cards * 2000 + lines * 500 + nearEdge(a, z) * 400 + len;
|
|
3855
3865
|
if (!best || score < best.score) best = { p0, p1, score };
|
|
3856
3866
|
}
|
|
3857
3867
|
}
|
|
@@ -4390,6 +4400,198 @@ function kioskPopRender() {
|
|
|
4390
4400
|
pop.style.top = `${Math.round(at.top)}px`;
|
|
4391
4401
|
}
|
|
4392
4402
|
/** Wire the frame's pointer once: the popover, and the hover links to the kiosk. Bare frames only. */
|
|
4403
|
+
// --- behold#571: the kiosk's Watch mode -------------------------------------
|
|
4404
|
+
// The kiosk sends a `behold:shot` (web/kiosk-shot.js) with each step: the
|
|
4405
|
+
// roots or waves the step is about, or the whole graph, and how much of the
|
|
4406
|
+
// pane its caption and callouts cover. The frame pans and zooms there, calm
|
|
4407
|
+
// and short, and holds the shot through re-renders and resizes. It tells the
|
|
4408
|
+
// kiosk where each wave box sits after every move (`behold:boxes`), so the
|
|
4409
|
+
// callouts, the log drawer and the badges ride the boxes they describe. A
|
|
4410
|
+
// viewer's own pan or zoom drops the shot and says so (`behold:viewer`).
|
|
4411
|
+
var kioskShot = null; // var: read by the viewBox code, which may run before this line is reached
|
|
4412
|
+
var shotAnim = null;
|
|
4413
|
+
var boxesQueued = false;
|
|
4414
|
+
const reducedMotion = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
4415
|
+
|
|
4416
|
+
/** An element's box in the svg's user units, whatever transform sits over it. */
|
|
4417
|
+
function userBoxOf(svg, el) {
|
|
4418
|
+
let b;
|
|
4419
|
+
try {
|
|
4420
|
+
b = el.getBBox();
|
|
4421
|
+
} catch {
|
|
4422
|
+
return null;
|
|
4423
|
+
}
|
|
4424
|
+
const ctm = el.getCTM && el.getCTM();
|
|
4425
|
+
const root = svg.getCTM && svg.getCTM();
|
|
4426
|
+
if (!ctm || !root || !(b.width > 0 || b.height > 0)) return null;
|
|
4427
|
+
const m = root.inverse().multiply(ctm);
|
|
4428
|
+
const pts = [[b.x, b.y], [b.x + b.width, b.y + b.height]].map(([x, y]) => new DOMPoint(x, y).matrixTransform(m));
|
|
4429
|
+
return { x: Math.min(pts[0].x, pts[1].x), y: Math.min(pts[0].y, pts[1].y), x2: Math.max(pts[0].x, pts[1].x), y2: Math.max(pts[0].y, pts[1].y) };
|
|
4430
|
+
}
|
|
4431
|
+
|
|
4432
|
+
/** What a shot frames, in svg units: its roots' cards and the reads between them, its waves' boxes, else the whole graph. */
|
|
4433
|
+
function kioskShotTarget(svg, shot) {
|
|
4434
|
+
if (!vbInit) return null;
|
|
4435
|
+
const boxes = [];
|
|
4436
|
+
if (shot.whole) {
|
|
4437
|
+
// The whole graph is what is drawn: the boxes, the cards and the reads, not pinhole's margins round them.
|
|
4438
|
+
for (const n of svg.querySelectorAll("rect[data-group-id], [data-node-id], [data-tg-reads] > g, line[data-tg-read-from], text[data-tg-reads='caption']")) boxes.push(userBoxOf(svg, n));
|
|
4439
|
+
return unionBox(boxes) || { x: vbInit[0], y: vbInit[1], x2: vbInit[0] + vbInit[2], y2: vbInit[1] + vbInit[3] };
|
|
4440
|
+
}
|
|
4441
|
+
const named = (tgComponentFacets && tgComponentFacets.roots) || {};
|
|
4442
|
+
const roots = new Set(shot.roots);
|
|
4443
|
+
for (const g of svg.querySelectorAll("[data-node-id]")) {
|
|
4444
|
+
const id = g.getAttribute("data-node-id");
|
|
4445
|
+
if (roots.has(id) || roots.has(named[id])) boxes.push(userBoxOf(svg, g));
|
|
4446
|
+
}
|
|
4447
|
+
// Each card's wave box with it, so a shot never cuts a box's title off.
|
|
4448
|
+
const cards = boxes.filter(Boolean);
|
|
4449
|
+
for (const r of svg.querySelectorAll("rect[data-group-id]")) {
|
|
4450
|
+
const b = userBoxOf(svg, r);
|
|
4451
|
+
if (b && cards.some((c) => (c.x + c.x2) / 2 > b.x && (c.x + c.x2) / 2 < b.x2 && (c.y + c.y2) / 2 > b.y && (c.y + c.y2) / 2 < b.y2)) boxes.push(b);
|
|
4452
|
+
}
|
|
4453
|
+
for (const l of svg.querySelectorAll("line[data-tg-read-from]")) {
|
|
4454
|
+
if (roots.has(l.getAttribute("data-tg-read-from")) && roots.has(l.getAttribute("data-tg-read-to"))) boxes.push(userBoxOf(svg, l));
|
|
4455
|
+
}
|
|
4456
|
+
for (const n of shot.waves) {
|
|
4457
|
+
const r = svg.querySelector(`rect[data-group-id="wave-${n}"]`);
|
|
4458
|
+
if (r) boxes.push(userBoxOf(svg, r));
|
|
4459
|
+
}
|
|
4460
|
+
const u = unionBox(boxes);
|
|
4461
|
+
return u || { x: vbInit[0], y: vbInit[1], x2: vbInit[0] + vbInit[2], y2: vbInit[1] + vbInit[3] };
|
|
4462
|
+
}
|
|
4463
|
+
|
|
4464
|
+
/** The viewBox of the kiosk's shot, at the pane's size now; the insets are the frame's window's, so the pane's own offset comes off them. */
|
|
4465
|
+
function kioskShotBox() {
|
|
4466
|
+
const svg = currentSvg();
|
|
4467
|
+
const host = document.getElementById("graph");
|
|
4468
|
+
if (!svg || !host || !kioskShot) return null;
|
|
4469
|
+
const pane = host.getBoundingClientRect();
|
|
4470
|
+
const i = kioskShot.insets;
|
|
4471
|
+
const insets = {
|
|
4472
|
+
top: Math.max(0, i.top - pane.top),
|
|
4473
|
+
left: Math.max(0, i.left - pane.left),
|
|
4474
|
+
bottom: Math.max(0, i.bottom - (window.innerHeight - pane.bottom)),
|
|
4475
|
+
right: Math.max(0, i.right - (window.innerWidth - pane.right)),
|
|
4476
|
+
};
|
|
4477
|
+
return shotViewBox(kioskShotTarget(svg, kioskShot), pane, insets);
|
|
4478
|
+
}
|
|
4479
|
+
|
|
4480
|
+
/** Move to the shot: a pan and zoom over its time, or at once (a re-render, a resize, reduced motion). */
|
|
4481
|
+
function applyKioskShot(animate) {
|
|
4482
|
+
const to = kioskShotBox();
|
|
4483
|
+
if (!to || !vb) return kioskTellBoxes();
|
|
4484
|
+
if (shotAnim && !animate) {
|
|
4485
|
+
shotAnim.to = to; // a move under way lands on the shot as it is now
|
|
4486
|
+
return;
|
|
4487
|
+
}
|
|
4488
|
+
if (sameViewBox(vb, to)) return kioskTellBoxes();
|
|
4489
|
+
vbAtFit = false;
|
|
4490
|
+
const ms = kioskShot.ms;
|
|
4491
|
+
if (!animate || reducedMotion() || !(ms > 0)) {
|
|
4492
|
+
if (shotAnim) cancelAnimationFrame(shotAnim.raf);
|
|
4493
|
+
shotAnim = null;
|
|
4494
|
+
vb = to;
|
|
4495
|
+
applyVB();
|
|
4496
|
+
return;
|
|
4497
|
+
}
|
|
4498
|
+
if (shotAnim) cancelAnimationFrame(shotAnim.raf);
|
|
4499
|
+
const from = vb.slice();
|
|
4500
|
+
const start = performance.now();
|
|
4501
|
+
shotAnim = { to, raf: 0 };
|
|
4502
|
+
const step = (t) => {
|
|
4503
|
+
if (!shotAnim) return;
|
|
4504
|
+
const f = Math.min(1, (t - start) / ms);
|
|
4505
|
+
vb = tweenViewBox(from, shotAnim.to, f);
|
|
4506
|
+
applyVB();
|
|
4507
|
+
if (f < 1) shotAnim.raf = requestAnimationFrame(step);
|
|
4508
|
+
else shotAnim = null;
|
|
4509
|
+
};
|
|
4510
|
+
shotAnim.raf = requestAnimationFrame(step);
|
|
4511
|
+
}
|
|
4512
|
+
|
|
4513
|
+
/** A viewer moved the graph: the shot goes, and the kiosk holds the view. */
|
|
4514
|
+
var viewerToldAt = 0;
|
|
4515
|
+
function kioskViewerMoved() {
|
|
4516
|
+
if (!embedOpts.bare) return;
|
|
4517
|
+
if (shotAnim) cancelAnimationFrame(shotAnim.raf);
|
|
4518
|
+
shotAnim = null;
|
|
4519
|
+
kioskShot = null;
|
|
4520
|
+
const t = Date.now();
|
|
4521
|
+
if (t - viewerToldAt < 400 || !embedOpts.host || window.parent === window) return;
|
|
4522
|
+
viewerToldAt = t;
|
|
4523
|
+
try {
|
|
4524
|
+
window.parent.postMessage({ type: "behold:viewer" }, embedOpts.host);
|
|
4525
|
+
} catch {
|
|
4526
|
+
/* the parent went away */
|
|
4527
|
+
}
|
|
4528
|
+
}
|
|
4529
|
+
|
|
4530
|
+
/** Tell the kiosk where each wave box sits in the frame's window, once a frame. */
|
|
4531
|
+
function kioskTellBoxes() {
|
|
4532
|
+
if (!embedOpts.bare || !embedOpts.host || window.parent === window || boxesQueued) return;
|
|
4533
|
+
boxesQueued = true;
|
|
4534
|
+
requestAnimationFrame(() => {
|
|
4535
|
+
boxesQueued = false;
|
|
4536
|
+
const svg = currentSvg();
|
|
4537
|
+
if (!svg) return;
|
|
4538
|
+
const waves = {};
|
|
4539
|
+
const rect = (r) => ({ x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) });
|
|
4540
|
+
for (const r of svg.querySelectorAll("rect[data-group-id]")) {
|
|
4541
|
+
const n = tgWaveOfKey(r.getAttribute("data-group-id"));
|
|
4542
|
+
if (n !== null) waves[n] = rect(r.getBoundingClientRect());
|
|
4543
|
+
}
|
|
4544
|
+
// The reads' labels too, which the kiosk's callouts keep clear of.
|
|
4545
|
+
const labels = [...svg.querySelectorAll("[data-tg-reads] > g")].map((g) => rect(g.getBoundingClientRect())).filter((r) => r.w > 0);
|
|
4546
|
+
const host = document.getElementById("graph");
|
|
4547
|
+
const pane = host ? rect(host.getBoundingClientRect()) : null;
|
|
4548
|
+
try {
|
|
4549
|
+
window.parent.postMessage({ type: "behold:boxes", waves, labels, pane, moving: !!shotAnim }, embedOpts.host);
|
|
4550
|
+
} catch {
|
|
4551
|
+
/* the parent went away */
|
|
4552
|
+
}
|
|
4553
|
+
});
|
|
4554
|
+
}
|
|
4555
|
+
|
|
4556
|
+
/**
|
|
4557
|
+
* behold#571: tell the kiosk this page has drawn its graph, once: cards on
|
|
4558
|
+
* the canvas and terragucci's marks on them (or their read answered, or
|
|
4559
|
+
* failed). The kiosk loads a new frame out of sight and swaps it in on this,
|
|
4560
|
+
* so the graph pane never shows an empty frame.
|
|
4561
|
+
*/
|
|
4562
|
+
var drawnTold = false;
|
|
4563
|
+
function kioskTellDrawn() {
|
|
4564
|
+
if (drawnTold || !embedOpts.host || window.parent === window) return;
|
|
4565
|
+
const svg = currentSvg();
|
|
4566
|
+
const failed = !!document.querySelector("#graph > .err");
|
|
4567
|
+
if (!failed && !(svg && svg.querySelector("[data-node-id]"))) return;
|
|
4568
|
+
// The marks: terragucci's reports answered (or refused), or chant's loop has its own.
|
|
4569
|
+
if (!failed && terragucciComponentsRepo && !tgAnswer && !chantPrDrawn()) return;
|
|
4570
|
+
drawnTold = true;
|
|
4571
|
+
try {
|
|
4572
|
+
window.parent.postMessage({ type: "behold:drawn", failed }, embedOpts.host);
|
|
4573
|
+
} catch {
|
|
4574
|
+
/* the parent went away */
|
|
4575
|
+
}
|
|
4576
|
+
}
|
|
4577
|
+
// A graph that failed draws no svg and no reads: say so too, so the kiosk is never left waiting.
|
|
4578
|
+
if (embedOpts.bare) setInterval(kioskTellDrawn, 1000);
|
|
4579
|
+
|
|
4580
|
+
window.addEventListener("message", (e) => {
|
|
4581
|
+
if (!embedOpts.bare) return;
|
|
4582
|
+
const shot = shotFromMessage(e, embedOpts.host);
|
|
4583
|
+
if (!shot) return;
|
|
4584
|
+
if (shot.release) {
|
|
4585
|
+
if (shotAnim) cancelAnimationFrame(shotAnim.raf);
|
|
4586
|
+
shotAnim = null;
|
|
4587
|
+
kioskShot = null;
|
|
4588
|
+
fitGraph();
|
|
4589
|
+
return;
|
|
4590
|
+
}
|
|
4591
|
+
kioskShot = shot;
|
|
4592
|
+
applyKioskShot(true);
|
|
4593
|
+
});
|
|
4594
|
+
|
|
4393
4595
|
function wireKioskFrame() {
|
|
4394
4596
|
if (!embedOpts.bare) return;
|
|
4395
4597
|
const graph = document.getElementById("graph");
|
|
@@ -4415,6 +4617,8 @@ function wireKioskFrame() {
|
|
|
4415
4617
|
const card = e.target.closest && e.target.closest("[data-node-id]");
|
|
4416
4618
|
if (card) kioskPopEvent({ type: "click", id: card.getAttribute("data-node-id") });
|
|
4417
4619
|
else kioskPopEvent({ type: "outside" });
|
|
4620
|
+
// behold#571: a click on the graph holds the kiosk's shot where the viewer is reading.
|
|
4621
|
+
if (card && kioskShot) kioskViewerMoved();
|
|
4418
4622
|
},
|
|
4419
4623
|
true,
|
|
4420
4624
|
);
|
|
@@ -5402,7 +5606,10 @@ function renderApplyProgress(state) {
|
|
|
5402
5606
|
}
|
|
5403
5607
|
for (const w of state.waves) {
|
|
5404
5608
|
const row = document.createElement("div");
|
|
5609
|
+
row.className = "apply-wave-row";
|
|
5405
5610
|
row.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
|
5611
|
+
// behold#571: the wave's left bar, in its status.
|
|
5612
|
+
row.style.setProperty("--bar", barVarFor(APPLY_STATUS_COLOR[w.status]));
|
|
5406
5613
|
const label = document.createElement("span");
|
|
5407
5614
|
label.style.cssText = `font-size:var(--t-caption);color:${APPLY_STATUS_COLOR[w.status] || "var(--muted)"};min-width:52px`;
|
|
5408
5615
|
label.textContent = `wave ${w.wave}`;
|
|
@@ -5824,6 +6031,39 @@ function stepAside(row, xs, own) {
|
|
|
5824
6031
|
/** How far a read's arrowhead reaches back from its tip, and how wide it spreads (marker 7 x stroke 3). */
|
|
5825
6032
|
const ARROWHEAD = { length: 22, half: 11 };
|
|
5826
6033
|
|
|
6034
|
+
/** behold#571: the box an arrowhead drawn from p0 to p1 covers, in the svg's units. */
|
|
6035
|
+
function arrowheadBox(p0, p1) {
|
|
6036
|
+
const len = Math.hypot(p1.x - p0.x, p1.y - p0.y) || 1;
|
|
6037
|
+
const bx = p1.x - ((p1.x - p0.x) / len) * ARROWHEAD.length;
|
|
6038
|
+
const by = p1.y - ((p1.y - p0.y) / len) * ARROWHEAD.length;
|
|
6039
|
+
const h = ARROWHEAD.half;
|
|
6040
|
+
return { x: Math.min(p1.x, bx) - h, y: Math.min(p1.y, by) - h, x2: Math.max(p1.x, bx) + h, y2: Math.max(p1.y, by) + h };
|
|
6041
|
+
}
|
|
6042
|
+
|
|
6043
|
+
/**
|
|
6044
|
+
* behold#571: each box title's box at the largest size scaleBoxLabels gives
|
|
6045
|
+
* it (a zoomed-out view draws it bigger), grown from its anchor, so a line or
|
|
6046
|
+
* an arrowhead placed clear of it stays clear at every zoom.
|
|
6047
|
+
*/
|
|
6048
|
+
function boxTitlesAtMost(svg, boxOf) {
|
|
6049
|
+
const out = [];
|
|
6050
|
+
for (const l of boxLabelsOf(svg)) {
|
|
6051
|
+
const b = boxOf(l.el);
|
|
6052
|
+
if (!b) continue;
|
|
6053
|
+
const chars = Math.max(4, (l.el.textContent || "").length);
|
|
6054
|
+
const cap = Math.max(l.base, Math.min(l.box.h / BOX_LABEL_MAX_H, l.box.w / (chars * BOX_LABEL_EM)));
|
|
6055
|
+
const now = parseFloat(l.el.getAttribute("font-size")) || l.base;
|
|
6056
|
+
const f = cap / now;
|
|
6057
|
+
if (!(f > 1)) continue;
|
|
6058
|
+
const w = (b.x2 - b.x) * f;
|
|
6059
|
+
const h = (b.y2 - b.y) * f;
|
|
6060
|
+
const anchor = l.el.getAttribute("text-anchor");
|
|
6061
|
+
const x = anchor === "end" ? b.x2 - w : anchor === "middle" ? (b.x + b.x2) / 2 - w / 2 : b.x;
|
|
6062
|
+
out.push({ x, y: b.y2 - h, x2: x + w, y2: b.y2 });
|
|
6063
|
+
}
|
|
6064
|
+
return out;
|
|
6065
|
+
}
|
|
6066
|
+
|
|
5827
6067
|
/**
|
|
5828
6068
|
* No arrowhead sits on a mark. A read that ends in a box whose marks its head
|
|
5829
6069
|
* would cover lifts the box's title and marks a row up, the box growing by
|
|
@@ -5857,9 +6097,18 @@ function liftOffArrowheads(svgEl, lines) {
|
|
|
5857
6097
|
}
|
|
5858
6098
|
})
|
|
5859
6099
|
.filter(Boolean);
|
|
6100
|
+
const title = row.nextElementSibling && row.nextElementSibling.tagName.toLowerCase() === "text" ? row.nextElementSibling : null;
|
|
6101
|
+
// behold#571: the box's title is a mark too: a head over it lifts the row as well.
|
|
6102
|
+
if (title) {
|
|
6103
|
+
try {
|
|
6104
|
+
const b = title.getBBox();
|
|
6105
|
+
boxes.push({ x: b.x + dx - 2, y: b.y + dy - 2, x2: b.x + b.width + dx + 2, y2: b.y + b.height + dy + 2 });
|
|
6106
|
+
} catch {
|
|
6107
|
+
/* not laid out */
|
|
6108
|
+
}
|
|
6109
|
+
}
|
|
5860
6110
|
if (!heads.some((h) => boxes.some((b) => hit(h, b)))) continue;
|
|
5861
6111
|
const rect = svgEl.querySelector(`rect[data-group-id="wave-${row.getAttribute("data-pm-wave")}"]`);
|
|
5862
|
-
const title = row.nextElementSibling && row.nextElementSibling.tagName.toLowerCase() === "text" ? row.nextElementSibling : null;
|
|
5863
6112
|
if (!rect) continue;
|
|
5864
6113
|
if (!rect.hasAttribute("data-pm-y0")) {
|
|
5865
6114
|
rect.setAttribute("data-pm-y0", rect.getAttribute("y"));
|
|
@@ -6254,6 +6503,8 @@ function setupGraphViewBox(svg) {
|
|
|
6254
6503
|
vb = fittedViewBox() || a.slice();
|
|
6255
6504
|
vbAtFit = true;
|
|
6256
6505
|
applyVB();
|
|
6506
|
+
// behold#571: in the kiosk's Watch mode a re-render keeps the shot the kiosk asked for.
|
|
6507
|
+
if (kioskShot) queueMicrotask(() => applyKioskShot(false));
|
|
6257
6508
|
} else {
|
|
6258
6509
|
vbInit = vb = null;
|
|
6259
6510
|
}
|
|
@@ -6265,6 +6516,7 @@ function applyVB() {
|
|
|
6265
6516
|
const s = currentSvg();
|
|
6266
6517
|
if (s && vb) s.setAttribute("viewBox", vb.join(" "));
|
|
6267
6518
|
scaleBoxLabels(); // #396 item 7b: box titles/badges keep a legible size at every zoom
|
|
6519
|
+
kioskTellBoxes(); // behold#571: the kiosk's overlays ride the boxes they describe
|
|
6268
6520
|
}
|
|
6269
6521
|
|
|
6270
6522
|
// #396 item 2: the panel is `position: fixed` and floats OVER the graph pane
|
|
@@ -6328,6 +6580,7 @@ function fittedViewBox() {
|
|
|
6328
6580
|
|
|
6329
6581
|
function fitGraph() {
|
|
6330
6582
|
if (!vbInit) return;
|
|
6583
|
+
if (kioskShot) return applyKioskShot(false); // behold#571: the kiosk's shot stands in for the fit
|
|
6331
6584
|
vb = fittedViewBox() || vbInit.slice();
|
|
6332
6585
|
vbAtFit = true;
|
|
6333
6586
|
applyVB();
|
|
@@ -6344,7 +6597,8 @@ let vbAtFit = false;
|
|
|
6344
6597
|
function watchPaneForFit(host) {
|
|
6345
6598
|
if (typeof ResizeObserver === "undefined") return;
|
|
6346
6599
|
new ResizeObserver(() => {
|
|
6347
|
-
if (
|
|
6600
|
+
if (kioskShot) applyKioskShot(false);
|
|
6601
|
+
else if (vbAtFit) fitGraph();
|
|
6348
6602
|
}).observe(host);
|
|
6349
6603
|
}
|
|
6350
6604
|
|
|
@@ -6517,6 +6771,7 @@ function ensureZoomControls(host) {
|
|
|
6517
6771
|
vb[3] = nh;
|
|
6518
6772
|
vbAtFit = false;
|
|
6519
6773
|
applyVB();
|
|
6774
|
+
kioskViewerMoved();
|
|
6520
6775
|
},
|
|
6521
6776
|
{ passive: false },
|
|
6522
6777
|
);
|
|
@@ -6562,6 +6817,7 @@ function ensureZoomControls(host) {
|
|
|
6562
6817
|
touch.pts = pts;
|
|
6563
6818
|
vbAtFit = false;
|
|
6564
6819
|
applyVB();
|
|
6820
|
+
if (touch.moved || pts.length >= 2) kioskViewerMoved();
|
|
6565
6821
|
},
|
|
6566
6822
|
{ passive: false },
|
|
6567
6823
|
);
|
|
@@ -6600,6 +6856,7 @@ function ensureZoomControls(host) {
|
|
|
6600
6856
|
px = e.clientX;
|
|
6601
6857
|
py = e.clientY;
|
|
6602
6858
|
applyVB();
|
|
6859
|
+
if (panMoved) kioskViewerMoved();
|
|
6603
6860
|
});
|
|
6604
6861
|
window.addEventListener("mouseup", () => {
|
|
6605
6862
|
drag = false;
|
package/web/index.html
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
--edge: #56596d; --managed: #a6e3a1; --foreign: #f9e2af; --pending: #89b4fa;
|
|
27
27
|
--degraded: #f38ba8; --neutral: #6d7187; --runtime: #94e2d5;
|
|
28
28
|
--rule: #4e4f64; --focus: #a3b4d0; --active: #3d4660; --well: #11101f; --shadow: #050507;
|
|
29
|
+
--bar-managed: #a6e3a1; --bar-foreign: #f9e2af; --bar-pending: #89b4fa; --bar-degraded: #f38ba8; --bar-runtime: #94e2d5; --bar-neutral: #9a9eb5;
|
|
29
30
|
}
|
|
30
31
|
/* The non-colour half of the identity: type and radii. These can't derive
|
|
31
32
|
from a colour theme, so they're the one static token block — but they
|
|
@@ -115,6 +116,8 @@
|
|
|
115
116
|
Both are off entirely under prefers-reduced-motion. */
|
|
116
117
|
#graph svg { animation: graph-fade-through .18s ease-out; }
|
|
117
118
|
@keyframes graph-fade-through { from { opacity: 0; } to { opacity: 1; } }
|
|
119
|
+
/* behold#571: the kiosk's frame re-renders as the steps move; a fade from nothing at each one reads as the pane flashing. It swaps whole frames in once they have drawn instead. */
|
|
120
|
+
.bare #graph svg { animation: none; }
|
|
118
121
|
#graph [data-node-id].status-changed { animation: status-pulse .85s ease-out 2; }
|
|
119
122
|
@keyframes status-pulse {
|
|
120
123
|
0%, 100% { filter: drop-shadow(0 0 0 var(--pulse, var(--pending))); }
|
|
@@ -557,7 +560,7 @@
|
|
|
557
560
|
.run-verdict { font-size: var(--t-caption); }
|
|
558
561
|
/* What behold does NOT know — a lost stream, an unreachable gate query.
|
|
559
562
|
Same voice as the carve refusal: a statement, not an alarm. */
|
|
560
|
-
.run-lost { border-left: 3px solid var(--foreign); background: var(--well);
|
|
563
|
+
.run-lost { border-left: 3px solid var(--bar-foreign); background: var(--well);
|
|
561
564
|
border-radius: var(--r-ctl); padding: 4px 8px; color: var(--muted);
|
|
562
565
|
font: var(--t-caption)/1.5 var(--font-mono); }
|
|
563
566
|
.run-steps { display: flex; flex-direction: column; gap: 2px; }
|
|
@@ -567,7 +570,7 @@
|
|
|
567
570
|
.run-took { color: var(--muted); }
|
|
568
571
|
/* A human decision is owed: the same --pending edge the carve
|
|
569
572
|
walkthrough's human refusal wears. */
|
|
570
|
-
.run-gate { border: 1px solid var(--pending); border-left: 3px solid var(--
|
|
573
|
+
.run-gate { border: 1px solid var(--pending); border-left: 3px solid var(--bar-foreign);
|
|
571
574
|
border-radius: var(--r-ctl); padding: 6px 8px; background: var(--well);
|
|
572
575
|
display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
|
|
573
576
|
.run-gate-title { font-size: var(--t-body); color: var(--pending); }
|
|
@@ -739,6 +742,43 @@
|
|
|
739
742
|
#graph [data-pending-read] { animation: pending-breathe 2.4s ease-in-out infinite; }
|
|
740
743
|
@keyframes pending-breathe { 0%, 100% { opacity: 0.45; } 50% { opacity: 0.68; } }
|
|
741
744
|
}
|
|
745
|
+
/*
|
|
746
|
+
* behold#571: the left bars, as the kiosk draws them. Every listed item
|
|
747
|
+
* (a panel row, a substrate, a run's step, an op, a converge entry, a
|
|
748
|
+
* wave or root of a terragucci report, a timeline entry) has a bar down
|
|
749
|
+
* its left edge, so the eye can part the items on any theme. Its colour
|
|
750
|
+
* is its state's (theme.js barInks, 3:1 on every ground in every
|
|
751
|
+
* theme): running in the accent, held in the waiting amber, failed,
|
|
752
|
+
* applied, the runtime cyan; neutral where it has none. Rows that touch
|
|
753
|
+
* get a bar inset 2px top and bottom; a card's bar is its inset edge.
|
|
754
|
+
* The inspect pane's sections each get one, beside their rows.
|
|
755
|
+
*/
|
|
756
|
+
#panel .count-row, #panel .node-row, #substrates .sub, .run-step, .operator-row, .operator-entry, .apply-wave-row, #tab-terragucci .tg-root, .tg-timeline .tg-entry, #inspect .why-list li, .k-pop-lines li { position: relative; padding-left: 10px; }
|
|
757
|
+
#panel .count-row::before, #panel .node-row::before, #substrates .sub::before, .run-step::before, .operator-row::before, .operator-entry::before, .apply-wave-row::before, #tab-terragucci .tg-root::before, .tg-timeline .tg-entry::before, #inspect .why-list li::before, .k-pop-lines li::before {
|
|
758
|
+
content: ""; position: absolute; left: 0; top: 2px; bottom: 2px; width: var(--bar-w, 3px); border-radius: 0 2px 2px 0; background: var(--bar, var(--bar-neutral)); pointer-events: none; }
|
|
759
|
+
#panel .node-row { padding-left: 12px; }
|
|
760
|
+
.ws-gate, .tg-progress-wave, #tg-estate .tg-estate-project, #inspect-body > dl, #inspect-body > .tg-inspect, #inspect-body > .why { box-shadow: inset var(--bar-w, 3px) 0 0 var(--bar, var(--bar-neutral)); }
|
|
761
|
+
#inspect-body > dl, #inspect-body > .tg-inspect, #inspect-body > .why { padding-left: 10px; }
|
|
762
|
+
#inspect-body > dl { padding-top: 1px; padding-bottom: 2px; }
|
|
763
|
+
.ws-gate, .tg-progress-wave { padding-left: 11px !important; }
|
|
764
|
+
#substrates .sub.up { --bar: var(--bar-managed); }
|
|
765
|
+
#substrates .sub.down { --bar: var(--bar-degraded); }
|
|
766
|
+
#substrates .sub.on-demand { --bar: var(--bar-pending); }
|
|
767
|
+
.operator-entry-gate-resolution { --bar: var(--bar-managed); }
|
|
768
|
+
/* terragucci's tones: held (a wave) amber, failed or drifted, done, planned in the accent. */
|
|
769
|
+
.tg-wave, .tg-progress-waiting { --bar: var(--bar-foreign); }
|
|
770
|
+
.tg-failed, .tg-drift, .tg-progress-not-applied { --bar: var(--bar-degraded); }
|
|
771
|
+
.tg-ok, .tg-progress-done { --bar: var(--bar-managed); }
|
|
772
|
+
.tg-plan, .tg-progress-in-flight { --bar: var(--bar-pending); }
|
|
773
|
+
.tg-none { --bar: var(--bar-neutral); }
|
|
774
|
+
#tab-terragucci .tg-root:has(.tg-plan) { --bar: var(--bar-pending); }
|
|
775
|
+
#tab-terragucci .tg-root:has(.tg-wave) { --bar: var(--bar-foreign); }
|
|
776
|
+
#tab-terragucci .tg-root:has(.tg-failed), #tab-terragucci .tg-root:has(.tg-drift) { --bar: var(--bar-degraded); }
|
|
777
|
+
.tg-change-wave[data-state="planned"], .tg-change-wave[data-state="applying"] { --bar: var(--bar-pending); }
|
|
778
|
+
.tg-change-wave[data-state="waiting"] { --bar: var(--bar-foreign); }
|
|
779
|
+
.tg-change-wave[data-state="applied"] { --bar: var(--bar-managed); }
|
|
780
|
+
.tg-change-wave[data-state="failed"], .tg-change-wave[data-state="refused"] { --bar: var(--bar-degraded); }
|
|
781
|
+
.k-pop-lines li.k-pop-unknown { --bar: var(--bar-foreign); }
|
|
742
782
|
</style>
|
|
743
783
|
</head>
|
|
744
784
|
<body>
|
package/web/kiosk-approval.js
CHANGED
|
@@ -24,7 +24,7 @@ import { findLine } from "./kiosk-annotations.js";
|
|
|
24
24
|
export const PANEL_STEPS = ["waiting", "approved", "resumed", "applied"];
|
|
25
25
|
|
|
26
26
|
/** The panel's title. */
|
|
27
|
-
export const PANEL_TITLE = "
|
|
27
|
+
export const PANEL_TITLE = "Approval";
|
|
28
28
|
|
|
29
29
|
/** The rows, in order. */
|
|
30
30
|
export const ROWS = [
|
package/web/kiosk-metrics.js
CHANGED
|
@@ -99,11 +99,13 @@ export function metricsModel(answer, delivery = null) {
|
|
|
99
99
|
if (changed) rows.push(["Applied", changed]);
|
|
100
100
|
// The wave's job time leads: the binary's own runs are a small part of it.
|
|
101
101
|
const took = secondsWords(w.seconds);
|
|
102
|
-
|
|
102
|
+
// behold#571: Watch mode's badge on the wave's box reads the same numbers, short ("1.6 s · held 25 s · 4 created").
|
|
103
|
+
const badge = { seconds: took, held, changed, secondsRaw: typeof w.seconds === "number" ? w.seconds : null, heldRaw: typeof w.held_seconds === "number" ? w.held_seconds : null, changesRaw: w.changes || null };
|
|
104
|
+
if (rows.length || took) waves.push({ wave: w.wave, head: `Wave ${w.wave}`, took: took ? `${took} in all` : null, rows, ...badge });
|
|
103
105
|
}
|
|
104
106
|
if (waves.length) {
|
|
105
107
|
const c = answer.run.commit ? ` · ${String(answer.run.commit).slice(0, 8)}` : "";
|
|
106
|
-
run = { label: `${answer.run.current ? "This run" : "Latest run"}${c}`, waves };
|
|
108
|
+
run = { label: `${answer.run.current ? "This run" : "Latest run"}${c}`, current: !!answer.run.current, waves };
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
let dora = null;
|
|
@@ -124,6 +126,25 @@ export function metricsModel(answer, delivery = null) {
|
|
|
124
126
|
return { count, run, dora, ...(note ? { note } : {}) };
|
|
125
127
|
}
|
|
126
128
|
|
|
129
|
+
/**
|
|
130
|
+
* behold#571: the pane's presence holds steady through a cycle. Within one
|
|
131
|
+
* cycle (`same`), or when a read failed (`failed`), an answer with less in it
|
|
132
|
+
* keeps what the last one showed: no pane that comes and goes as the steps
|
|
133
|
+
* move, and no section that drops out for one read. A new cycle with nothing
|
|
134
|
+
* to show shows nothing.
|
|
135
|
+
*/
|
|
136
|
+
export function steadyModel(prev, next, { same = false, failed = false } = {}) {
|
|
137
|
+
if (!prev) return next;
|
|
138
|
+
if (!next) return same || failed ? prev : null;
|
|
139
|
+
if (!(same || failed)) return next;
|
|
140
|
+
const run = next.run || prev.run;
|
|
141
|
+
const dora = next.dora || prev.dora;
|
|
142
|
+
const note = next.note || (next.dora ? null : prev.note) || null;
|
|
143
|
+
const n = run ? run.waves.length : 0;
|
|
144
|
+
const count = [n ? `${n} ${n === 1 ? "wave" : "waves"}` : null, dora ? `${dora.length} delivery` : null].filter(Boolean).join(" · ");
|
|
145
|
+
return { count, run, dora, ...(note ? { note } : {}) };
|
|
146
|
+
}
|
|
147
|
+
|
|
127
148
|
/** The viewer's fold: true open, false folded, null when they never chose. */
|
|
128
149
|
export function metricsStored(store) {
|
|
129
150
|
try {
|
|
@@ -258,7 +279,7 @@ async function defaultFetch(url) {
|
|
|
258
279
|
* Start the pane in `host`. `tool` is the tool of a tool's page, null on
|
|
259
280
|
* /kiosk. Returns `{ stop }`.
|
|
260
281
|
*/
|
|
261
|
-
export function startMetrics(host, { tool = null, fetchJson = defaultFetch, store = null, setTimer = setInterval, clearTimer = clearInterval, doc = document } = {}) {
|
|
282
|
+
export function startMetrics(host, { tool = null, fetchJson = defaultFetch, store = null, setTimer = setInterval, clearTimer = clearInterval, doc = document, onModel = () => {} } = {}) {
|
|
262
283
|
if (!host) return { stop() {} };
|
|
263
284
|
if (doc.head && !doc.getElementById("k-metrics-style")) {
|
|
264
285
|
const style = el(doc, "style");
|
|
@@ -270,6 +291,7 @@ export function startMetrics(host, { tool = null, fetchJson = defaultFetch, stor
|
|
|
270
291
|
let open = metricsStored(shelf);
|
|
271
292
|
if (open === null) open = !(typeof matchMedia === "function" && matchMedia("(max-width: 600px)").matches);
|
|
272
293
|
let model = null;
|
|
294
|
+
let cycle = null;
|
|
273
295
|
let busy = false;
|
|
274
296
|
const draw = () =>
|
|
275
297
|
renderMetrics(host, model, {
|
|
@@ -290,12 +312,19 @@ export function startMetrics(host, { tool = null, fetchJson = defaultFetch, stor
|
|
|
290
312
|
busy = true;
|
|
291
313
|
try {
|
|
292
314
|
const demo = await fetchJson("/api/terragucci/demo");
|
|
293
|
-
const
|
|
294
|
-
const target = metricsTarget(demo,
|
|
295
|
-
const
|
|
315
|
+
const latest = tool && !(demo && demo.demo && demo.demo.tool === tool) ? await fetchJson(`/api/terragucci/cycles/${tool}`) : null;
|
|
316
|
+
const target = metricsTarget(demo, latest, tool);
|
|
317
|
+
const answer = target ? await fetchJson(metricsUrl(target)) : null;
|
|
318
|
+
// behold#571: which cycle this read is of; a read that failed keeps the pane as it was.
|
|
319
|
+
const d = demo && demo.demo;
|
|
320
|
+
const now = d ? `${d.repo}|${d.cycle}` : latest && latest.cycle ? `${latest.cycle.repo}|${latest.cycle.cycle}` : null;
|
|
321
|
+
const failed = !demo || !!demo.error || !target || !answer || !!answer.error;
|
|
322
|
+
const next = steadyModel(model, target ? metricsModel(answer, d ? d.delivery : null) : null, { same: now !== null && now === cycle, failed });
|
|
323
|
+
if (now !== null && !failed) cycle = now;
|
|
296
324
|
if (JSON.stringify(next) !== JSON.stringify(model)) {
|
|
297
325
|
model = next;
|
|
298
326
|
draw();
|
|
327
|
+
onModel(model);
|
|
299
328
|
}
|
|
300
329
|
} finally {
|
|
301
330
|
busy = false;
|
|
@@ -304,5 +333,5 @@ export function startMetrics(host, { tool = null, fetchJson = defaultFetch, stor
|
|
|
304
333
|
draw();
|
|
305
334
|
void tick();
|
|
306
335
|
const timer = setTimer(() => void tick(), METRICS_POLL_MS);
|
|
307
|
-
return { stop: () => clearTimer(timer), tick };
|
|
336
|
+
return { stop: () => clearTimer(timer), tick, model: () => model };
|
|
308
337
|
}
|