@intentius/behold 0.30.1 → 0.30.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/AGENTS.md +31 -1
- package/README.md +11 -6
- package/dist/cli.js +1516 -840
- package/example-choudoufu-estate/chant.workspace.json +1 -1
- package/example-terraform-estate/README.md +1 -1
- package/example-terraform-estate/chant.workspace.json +1 -1
- package/example-terralith/README.md +1 -1
- package/example-three-cloud/package-lock.json +19 -19
- package/example-three-cloud/package.json +4 -4
- package/package.json +5 -5
- package/web/app.js +263 -16
- package/web/embed.js +2 -2
- package/web/event-help-modal.js +18 -12
- package/web/event-help-modal.test.js +28 -1
- package/web/index.html +18 -0
- package/web/kiosk-ask-layout.js +85 -0
- package/web/kiosk-ask-layout.test.js +83 -0
- package/web/kiosk-ask-tips.js +467 -0
- package/web/kiosk-ask-tips.test.js +359 -0
- package/web/kiosk-ask.js +774 -0
- package/web/kiosk-ask.test.js +593 -0
- package/web/kiosk-banner.js +108 -0
- package/web/kiosk-banner.test.js +72 -0
- package/web/kiosk-center-cards.test.js +110 -0
- package/web/kiosk-estate-scene.js +203 -0
- package/web/kiosk-estate-scene.test.js +21 -0
- package/web/kiosk-event-help.js +4 -1
- package/web/kiosk-graph-pane.js +63 -0
- package/web/kiosk-graph-pane.test.js +105 -0
- package/web/kiosk-light-frame.js +196 -0
- package/web/kiosk-light.js +509 -0
- package/web/kiosk-light.test.js +297 -0
- package/web/kiosk-metrics.js +7 -4
- package/web/kiosk-modal-sticky.test.js +2 -1
- package/web/kiosk-refit.test.js +81 -0
- package/web/kiosk-reset.js +49 -0
- package/web/kiosk-reset.test.js +11 -0
- package/web/kiosk-shot.js +40 -2
- package/web/kiosk-shot.test.js +23 -1
- package/web/kiosk-vendor.js +85 -7
- package/web/kiosk-vendor.test.js +9 -9
- package/web/kiosk-watch.js +8 -4
- package/web/kiosk.html +107 -1
- package/web/kiosk.js +149 -23
- package/web/kiosk.test.js +25 -1
- package/web/small-stage.test.js +4 -0
- package/web/terragucci-change.js +30 -13
- package/web/tool-mark.js +4 -4
- package/web/tool-mark.test.js +1 -1
- package/web/vendors/atmos.svg +1 -0
- package/web/vendors/chant.svg +1 -0
- package/web/vendors/choudoufu.svg +1 -0
- package/web/vendors/terragrunt.svg +9 -0
- package/web/vendors/terragucci.svg +1 -0
- package/web/vendors/choudoufu-128.png +0 -0
- package/web/vendors/choudoufu-64.png +0 -0
package/web/embed.js
CHANGED
|
@@ -60,8 +60,8 @@ export function viewFromMessage(event, host) {
|
|
|
60
60
|
for (const k of VIEW_KEYS) {
|
|
61
61
|
if (!(k in d)) continue;
|
|
62
62
|
const v = d[k];
|
|
63
|
-
if (k === "radial" || k === "plan") {
|
|
64
|
-
// plan (behold#922): true is the plan read, false the declared source again.
|
|
63
|
+
if (k === "radial" || k === "plan" || k === "alike") {
|
|
64
|
+
// plan (behold#922): true is the plan read, false the declared source again. alike (behold#939): false draws every card, true stacks them.
|
|
65
65
|
if (typeof v === "boolean") want[k] = v;
|
|
66
66
|
continue;
|
|
67
67
|
}
|
package/web/event-help-modal.js
CHANGED
|
@@ -76,6 +76,8 @@ export function modeLine(mode, kind, { at = null, now = 0, resolved = false, out
|
|
|
76
76
|
if (kind === "waiting") return null;
|
|
77
77
|
// behold#757: a highlight's kicker says what it is, in a replay as live: the replay's banner says which run it is.
|
|
78
78
|
if (kind === "highlight") return HIGHLIGHT_KICKER;
|
|
79
|
+
// The prompt demo's tip cards (web/kiosk-ask-tips.js): the highlight's card, with a kicker of their own.
|
|
80
|
+
if (kind === "tip") return "Tip";
|
|
79
81
|
if (mode === "replay") return `Replay of the run at ${utc(Number.isFinite(replayAt) ? replayAt : now)} UTC`;
|
|
80
82
|
if (mode !== "narrated") return null;
|
|
81
83
|
if (resolved) return outcome ? `Live · ${outcome}` : "Live";
|
|
@@ -121,10 +123,10 @@ export const MODAL_STYLE = `
|
|
|
121
123
|
border: 2px solid var(--bar, var(--focus)); box-shadow: 0 16px 48px color-mix(in srgb, var(--shadow) 80%, transparent); font-size: 1.05em; }
|
|
122
124
|
.eh-modal-held { --bar: var(--bar-foreign, var(--foreign)); } .eh-modal-failed { --bar: var(--bar-degraded, var(--degraded)); } .eh-modal-applied { --bar: var(--bar-managed, var(--managed)); }
|
|
123
125
|
/* behold#757: a step's highlight: the runtime bar's tone (no state's), a kicker in it, and its body set to be read. */
|
|
124
|
-
.eh-modal-highlight { --bar: var(--bar-runtime, var(--runtime, var(--focus))); background: linear-gradient(color-mix(in srgb, var(--bar) 9%, transparent), transparent 5em), var(--surface-pane-b, var(--panel)); box-shadow: inset 5px 0 0 var(--bar), 0 16px 48px color-mix(in srgb, var(--shadow) 80%, transparent); }
|
|
125
|
-
.eh-modal-highlight .eh-modal-mode { text-transform: uppercase; letter-spacing: 0.08em; }
|
|
126
|
-
.eh-modal-highlight .eh-modal-mode::before { content: "\\2605"; margin-right: 0.45em; }
|
|
127
|
-
.eh-modal-highlight .eh-modal-line { color: var(--fg); line-height: 1.45; }
|
|
126
|
+
.eh-modal-highlight, .eh-modal-tip { --bar: var(--bar-runtime, var(--runtime, var(--focus))); background: linear-gradient(color-mix(in srgb, var(--bar) 9%, transparent), transparent 5em), var(--surface-pane-b, var(--panel)); box-shadow: inset 5px 0 0 var(--bar), 0 16px 48px color-mix(in srgb, var(--shadow) 80%, transparent); }
|
|
127
|
+
.eh-modal-highlight .eh-modal-mode, .eh-modal-tip .eh-modal-mode { text-transform: uppercase; letter-spacing: 0.08em; }
|
|
128
|
+
.eh-modal-highlight .eh-modal-mode::before, .eh-modal-tip .eh-modal-mode::before { content: "\\2605"; margin-right: 0.45em; }
|
|
129
|
+
.eh-modal-highlight .eh-modal-line, .eh-modal-tip .eh-modal-line { color: var(--fg); line-height: 1.45; }
|
|
128
130
|
.eh-modal-close { position: absolute; top: 0.4em; right: 0.5em; font-size: 1.3em; background: transparent; border: 0; color: var(--muted); cursor: pointer; }
|
|
129
131
|
.eh-modal-mode { margin: 0 2em 0.3em 0; font: 600 0.8em var(--font-ui); font-variant-numeric: tabular-nums; color: var(--bar, var(--muted)); }
|
|
130
132
|
.eh-modal-title { margin: 0 0 0.5em; font-size: 1.35em; }
|
|
@@ -260,18 +262,20 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
|
|
|
260
262
|
if (st.closeAt !== null) st.closeAt = Math.max(st.closeAt, now() + 2_000);
|
|
261
263
|
});
|
|
262
264
|
|
|
265
|
+
// One close button for the modal's whole life, never detached: render() runs every 250 ms, and taking the button out of
|
|
266
|
+
// the page (or replacing it) between a press and its release (a click lasts 80-150 ms) drops the click, so it never closed.
|
|
267
|
+
const x = el("button", "eh-modal-close", "×");
|
|
268
|
+
x.type = "button";
|
|
269
|
+
x.setAttribute("aria-label", "Close");
|
|
270
|
+
x.addEventListener("click", () => close("viewer"));
|
|
271
|
+
box.appendChild(x);
|
|
263
272
|
const render = () => {
|
|
264
273
|
if (st.closed) return;
|
|
265
274
|
const t = now();
|
|
266
|
-
box.
|
|
267
|
-
const x = el("button", "eh-modal-close", "×");
|
|
268
|
-
x.type = "button";
|
|
269
|
-
x.setAttribute("aria-label", "Close");
|
|
270
|
-
x.addEventListener("click", () => close("viewer"));
|
|
271
|
-
box.appendChild(x);
|
|
275
|
+
for (const c of [...box.children]) if (c !== x) c.remove();
|
|
272
276
|
const line = modeLine(mode, kind, { at: data.at, now: t, resolved: st.resolved, outcome: st.outcome, replayAt: data.replayAt, action: data.action, fix: !!data.fix });
|
|
273
277
|
if (line) box.appendChild(el("p", `eh-modal-mode eh-modal-${mode}`, line));
|
|
274
|
-
box.appendChild(el("h2", "eh-modal-title", data.title || ""));
|
|
278
|
+
if (data.title || kind !== "tip") box.appendChild(el("h2", "eh-modal-title", data.title || ""));
|
|
275
279
|
for (const l of data.lines || []) {
|
|
276
280
|
const p = el("p", `eh-modal-line${l.lit ? " eh-lit" : ""}`, l.text);
|
|
277
281
|
if (l.title) p.title = l.title;
|
|
@@ -288,7 +292,7 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
|
|
|
288
292
|
if (data.progress.words) box.appendChild(el("p", "eh-modal-note", data.progress.words));
|
|
289
293
|
}
|
|
290
294
|
// behold#757: a highlight is words to read: no command, no button.
|
|
291
|
-
if (kind === "waiting" || kind === "highlight") return;
|
|
295
|
+
if (kind === "waiting" || kind === "highlight" || kind === "tip") return;
|
|
292
296
|
const routed = mode === "live" && approveRoute(data.gate);
|
|
293
297
|
// The panel, when there is one, already carries the command.
|
|
294
298
|
if (data.command && !routed && !(data.panel && mode !== "live")) {
|
|
@@ -417,6 +421,8 @@ export function openEventModal(host, { mode, kind, data = {}, actions = {}, doc
|
|
|
417
421
|
render();
|
|
418
422
|
},
|
|
419
423
|
close: () => close(),
|
|
424
|
+
/** The viewer closed it (a click outside, say): onClose sees `closedBy` "viewer". */
|
|
425
|
+
dismiss: () => close("viewer"),
|
|
420
426
|
};
|
|
421
427
|
return api;
|
|
422
428
|
}
|
|
@@ -22,8 +22,9 @@ function fakeDoc() {
|
|
|
22
22
|
n.children.push(c);
|
|
23
23
|
return c;
|
|
24
24
|
},
|
|
25
|
-
replaceChildren() {
|
|
25
|
+
replaceChildren(...kids) {
|
|
26
26
|
n.children = [];
|
|
27
|
+
for (const k of kids) n.appendChild(k);
|
|
27
28
|
},
|
|
28
29
|
setAttribute(k, v) {
|
|
29
30
|
n.attrs[k] = String(v);
|
|
@@ -129,6 +130,32 @@ describe("event-help modal: narrated and replayed modals never write", () => {
|
|
|
129
130
|
});
|
|
130
131
|
});
|
|
131
132
|
|
|
133
|
+
describe("event-help modal: the close button", () => {
|
|
134
|
+
it("is the same element on every redraw, so a press that spans a redraw still clicks it", () => {
|
|
135
|
+
const doc = fakeDoc();
|
|
136
|
+
const c = clock();
|
|
137
|
+
const m = openEventModal(doc.body, { mode: "narrated", kind: "tip", data: { title: "t", lines: [{ text: "b" }] }, doc, ...c });
|
|
138
|
+
const box = doc.body.children[0].children[0];
|
|
139
|
+
const first = box.children[0];
|
|
140
|
+
expect(first.className).toBe("eh-modal-close");
|
|
141
|
+
c.advance(1_000);
|
|
142
|
+
expect(box.children[0]).toBe(first);
|
|
143
|
+
expect(box.children.filter((n) => n.className === "eh-modal-close")).toHaveLength(1);
|
|
144
|
+
first.handlers.click[0]();
|
|
145
|
+
expect(m.state.closedBy).toBe("viewer");
|
|
146
|
+
});
|
|
147
|
+
it("dismiss() closes it as the viewer, close() as the page", () => {
|
|
148
|
+
const doc = fakeDoc();
|
|
149
|
+
const c = clock();
|
|
150
|
+
const a = openEventModal(doc.body, { mode: "narrated", kind: "tip", data: { title: "t" }, doc, ...c });
|
|
151
|
+
a.dismiss();
|
|
152
|
+
expect(a.state.closedBy).toBe("viewer");
|
|
153
|
+
const b = openEventModal(doc.body, { mode: "narrated", kind: "tip", data: { title: "t" }, doc, ...c });
|
|
154
|
+
b.close();
|
|
155
|
+
expect(b.state.closedBy).toBe("page");
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
132
159
|
describe("event-help modal: live mode", () => {
|
|
133
160
|
it("clears an Op's gate only through the route the app already calls", async () => {
|
|
134
161
|
expect(approveRoute({ kind: "converge", op: "fountain-apply", gate: "rollout-gate", approve: { path: "/api/operator/approve/fountain-apply/rollout-gate" } })).toEqual({ method: "POST", path: "/api/operator/approve/fountain-apply/rollout-gate" });
|
package/web/index.html
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
applies that record when it belongs to the stored theme. A blocked or
|
|
11
11
|
empty store leaves the default as it is. -->
|
|
12
12
|
<script>
|
|
13
|
+
// The kiosk's frame (?bare=1) paints nothing until its theme is applied, so the kiosk's own ground shows through:
|
|
14
|
+
// the stylesheet's default --bg is white, and a first load with no stored paint flashed it over a dark pane.
|
|
15
|
+
try { if (/[?&]bare=1(&|$)/.test(location.search)) document.documentElement.style.setProperty("--bg", "transparent"); } catch (e) { /* the default paints */ }
|
|
13
16
|
try {
|
|
14
17
|
var beholdTheme = localStorage.getItem("behold.theme");
|
|
15
18
|
var beholdPaint = beholdTheme && JSON.parse(localStorage.getItem("behold.theme.paint") || "null");
|
|
@@ -1056,6 +1059,21 @@
|
|
|
1056
1059
|
#graph [data-node-id][data-q="lit"] rect:first-of-type { stroke: var(--pending); stroke-width: 3; }
|
|
1057
1060
|
#graph [data-node-id][data-q="path"] rect:first-of-type { stroke: var(--pending); stroke-width: 1.5; }
|
|
1058
1061
|
#graph g[data-edge-from][data-q="path"] path:first-of-type { stroke: var(--pending); stroke-width: 2.5; }
|
|
1062
|
+
/* behold#937: a demo step's lighting (web/kiosk-light-frame.js), the look of the query's lit and dimmed under its own marks. */
|
|
1063
|
+
/* behold#940: ask mode shows the graph and the prompt alone: no trace button between prompts, no zoom rail. */
|
|
1064
|
+
html.kiosk-ask #view-toggles, html.kiosk-ask .dots-rail { display: none !important; }
|
|
1065
|
+
/* behold#942: and no hint line ("cards shrinking to dots"), tooltip or text strip over the graph. */
|
|
1066
|
+
html.kiosk-ask .dots-caption, html.kiosk-ask .dots-tip, html.kiosk-ask #b-tip, html.kiosk-ask #nowline, html.kiosk-ask #export-note { display: none !important; }
|
|
1067
|
+
/* The card tags ("~ plan · 4d") sit where the slots go, and an edge that is not lit crosses boxes to nowhere a viewer reads. */
|
|
1068
|
+
html.kiosk-ask #graph [data-tg-mark], html.kiosk-ask #graph g[data-edge-from]:not([data-kl="path"]) { display: none !important; }
|
|
1069
|
+
#graph [data-kl="dim"] { opacity: .22; transition: opacity .15s; }
|
|
1070
|
+
#graph [data-node-id][data-kl="lit"] rect:first-of-type { stroke: var(--pending); stroke-width: 3; }
|
|
1071
|
+
#graph g[data-edge-from][data-kl="path"] path:first-of-type { stroke: var(--pending); stroke-width: 3; }
|
|
1072
|
+
#graph line[data-kl="path"] { stroke-width: 3.5; }
|
|
1073
|
+
@keyframes kl-pulse { 0% { opacity: 1; } 35% { opacity: .35; } 70% { opacity: 1; } 100% { opacity: 1; } }
|
|
1074
|
+
#graph [data-node-id][data-kl-pulse] { animation: kl-pulse .9s ease-in-out 1; }
|
|
1075
|
+
@keyframes kl-strike { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
|
|
1076
|
+
#graph .kl-strike { stroke-dasharray: 1; stroke-dashoffset: 1; animation: kl-strike .7s ease-out 1.4s forwards; }
|
|
1059
1077
|
#graph [data-node-id][data-q-near] { opacity: .6; }
|
|
1060
1078
|
#graph [data-node-id][data-q-near] rect:first-of-type { stroke: var(--ink2); stroke-width: 1.5; stroke-dasharray: 3 2; }
|
|
1061
1079
|
#graph [data-node-id][data-q-unobserved] rect:first-of-type { stroke: var(--degraded); stroke-dasharray: 5 3; }
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// behold#940: where ask mode puts the roots. The graph's own layout packs the
|
|
2
|
+
// roots in one row, which at 1920x1080 leaves the cards small. Here the roots
|
|
3
|
+
// are stacked, upstream on top, and each root's cards wrap into as many columns
|
|
4
|
+
// as make the whole stack fill the room best. Pure: sizes in, positions out.
|
|
5
|
+
// web/app.js applies the positions to the drawn graph (layout deltas), and
|
|
6
|
+
// web/kiosk-estate-scene.js draws a scene at them.
|
|
7
|
+
|
|
8
|
+
export const PAD = 18;
|
|
9
|
+
/** The room a root's title takes at the top of its box. */
|
|
10
|
+
export const TITLE = 36;
|
|
11
|
+
/** Between cards of a box. */
|
|
12
|
+
export const GAP = 18;
|
|
13
|
+
/** Between boxes: room for the state label under each. */
|
|
14
|
+
export const BOX_GAP = 56;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Upstream first. `edges` are `{from, to}` (from is read by to); a root
|
|
18
|
+
* nothing orders keeps its place. A cycle falls back to the given order.
|
|
19
|
+
*/
|
|
20
|
+
export function orderRoots(paths, edges = []) {
|
|
21
|
+
const left = [...paths];
|
|
22
|
+
const out = [];
|
|
23
|
+
while (left.length) {
|
|
24
|
+
const ready = left.find((p) => !edges.some((e) => e.to === p && e.from !== p && left.includes(e.from)));
|
|
25
|
+
const next = ready === undefined ? left[0] : ready;
|
|
26
|
+
out.push(next);
|
|
27
|
+
left.splice(left.indexOf(next), 1);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The stack's positions.
|
|
34
|
+
*
|
|
35
|
+
* `roots`: in order, each `{ id, cards: [{ id, w, h }] }`; a card's `h` counts what hangs under it (its slots).
|
|
36
|
+
* `open`: the room the stack should fill, `{ width, height }` in any one unit (only the ratio is used).
|
|
37
|
+
* Returns `{ cols, scale, width, height, boxes, cards }`: `boxes[id]` and `cards[id]` are `{ x, y, w, h }` with the
|
|
38
|
+
* stack's top left at 0,0; `scale` is how much the stack grows to fill `open`.
|
|
39
|
+
*/
|
|
40
|
+
export function askLayout(roots, open) {
|
|
41
|
+
const list = roots.filter((r) => r && r.cards && r.cards.length);
|
|
42
|
+
if (!list.length) return { cols: 0, scale: 1, width: 0, height: 0, boxes: {}, cards: {} };
|
|
43
|
+
const cw = Math.max(...list.flatMap((r) => r.cards.map((c) => c.w)));
|
|
44
|
+
const most = Math.max(...list.map((r) => r.cards.length));
|
|
45
|
+
const rowH = list.map((r) => Math.max(...r.cards.map((c) => c.h)));
|
|
46
|
+
const room = open && open.width > 0 && open.height > 0 ? open : { width: 16, height: 9 };
|
|
47
|
+
const shape = (cols) => {
|
|
48
|
+
let width = 0;
|
|
49
|
+
let height = 0;
|
|
50
|
+
list.forEach((r, i) => {
|
|
51
|
+
const used = Math.min(cols, r.cards.length);
|
|
52
|
+
const rows = Math.ceil(r.cards.length / cols);
|
|
53
|
+
const w = used * cw + (used - 1) * GAP + 2 * PAD;
|
|
54
|
+
const h = TITLE + rows * rowH[i] + (rows - 1) * GAP + PAD;
|
|
55
|
+
width = Math.max(width, w);
|
|
56
|
+
height += h + (i ? BOX_GAP : 0);
|
|
57
|
+
});
|
|
58
|
+
return { width, height, scale: Math.min(room.width / width, room.height / height) };
|
|
59
|
+
};
|
|
60
|
+
let best = { cols: 1, ...shape(1) };
|
|
61
|
+
for (let cols = 2; cols <= most; cols++) {
|
|
62
|
+
const s = shape(cols);
|
|
63
|
+
// A wider stack only when it is a clear gain: ties keep the narrower one.
|
|
64
|
+
if (s.scale > best.scale * 1.02) best = { cols, ...s };
|
|
65
|
+
}
|
|
66
|
+
const boxes = {};
|
|
67
|
+
const cards = {};
|
|
68
|
+
let y = 0;
|
|
69
|
+
list.forEach((r, i) => {
|
|
70
|
+
const used = Math.min(best.cols, r.cards.length);
|
|
71
|
+
const rows = Math.ceil(r.cards.length / best.cols);
|
|
72
|
+
const w = used * cw + (used - 1) * GAP + 2 * PAD;
|
|
73
|
+
const h = TITLE + rows * rowH[i] + (rows - 1) * GAP + PAD;
|
|
74
|
+
// Each box is centred on the widest one, so a stack of unequal boxes does not hug the left edge.
|
|
75
|
+
const x0 = Math.round((best.width - w) / 2);
|
|
76
|
+
boxes[r.id] = { x: x0, y, w, h };
|
|
77
|
+
r.cards.forEach((c, k) => {
|
|
78
|
+
const col = k % best.cols;
|
|
79
|
+
const row = Math.floor(k / best.cols);
|
|
80
|
+
cards[c.id] = { x: x0 + PAD + col * (cw + GAP), y: y + TITLE + row * (rowH[i] + GAP), w: c.w, h: c.h };
|
|
81
|
+
});
|
|
82
|
+
y += h + BOX_GAP;
|
|
83
|
+
});
|
|
84
|
+
return { cols: best.cols, scale: best.scale, width: best.width, height: best.height, boxes, cards };
|
|
85
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { BOX_GAP, PAD, TITLE, askLayout, orderRoots } from "./kiosk-ask-layout.js";
|
|
3
|
+
import { askDeltas } from "./kiosk-estate-scene.js";
|
|
4
|
+
|
|
5
|
+
const card = (id, w = 200, h = 64) => ({ id, w, h });
|
|
6
|
+
|
|
7
|
+
describe("ask mode's stack of roots (behold#940)", () => {
|
|
8
|
+
it("puts upstream first, and keeps the given order where nothing orders it", () => {
|
|
9
|
+
expect(orderRoots(["edge", "app", "network"], [{ from: "network", to: "app" }, { from: "app", to: "edge" }])).toEqual(["network", "app", "edge"]);
|
|
10
|
+
expect(orderRoots(["b", "a", "c"], [])).toEqual(["b", "a", "c"]);
|
|
11
|
+
// A cycle does not hang: the given order.
|
|
12
|
+
expect(orderRoots(["a", "b"], [{ from: "a", to: "b" }, { from: "b", to: "a" }])).toEqual(["a", "b"]);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("stacks the roots in order, each box holding its cards", () => {
|
|
16
|
+
const l = askLayout([{ id: "n", cards: [card("n1"), card("n2")] }, { id: "a", cards: [card("a1"), card("a2"), card("a3")] }], { width: 1920, height: 760 });
|
|
17
|
+
expect(l.boxes.n.y).toBe(0);
|
|
18
|
+
expect(l.boxes.a.y).toBeGreaterThan(l.boxes.n.y + l.boxes.n.h);
|
|
19
|
+
for (const [id, box] of [["n1", "n"], ["a3", "a"]]) {
|
|
20
|
+
const c = l.cards[id];
|
|
21
|
+
const b = l.boxes[box];
|
|
22
|
+
expect(c.x).toBeGreaterThanOrEqual(b.x + PAD);
|
|
23
|
+
expect(c.x + c.w).toBeLessThanOrEqual(b.x + b.w);
|
|
24
|
+
expect(c.y).toBeGreaterThanOrEqual(b.y + TITLE);
|
|
25
|
+
expect(c.y + c.h).toBeLessThanOrEqual(b.y + b.h);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("uses the height of a 1920x1080 screen: three roots of 3, 6 and 3 cards do not sit in one row", () => {
|
|
30
|
+
const roots = [{ id: "n", cards: ["a", "b", "c"].map((k) => card(`n${k}`)) }, { id: "a", cards: ["a", "b", "c", "d", "e", "f"].map((k) => card(`a${k}`, 200, 110)) }, { id: "e", cards: ["a", "b", "c"].map((k) => card(`e${k}`)) }];
|
|
31
|
+
const room = { width: 1920, height: 740 };
|
|
32
|
+
const stacked = askLayout(roots, room);
|
|
33
|
+
// The graph's own layout: the roots side by side in one row.
|
|
34
|
+
const oneRow = 12 * 218 + 3 * 2 * PAD + 2 * BOX_GAP;
|
|
35
|
+
const rowScale = Math.min(room.width / oneRow, room.height / (TITLE + 110 + PAD));
|
|
36
|
+
expect(stacked.scale).toBeGreaterThan(rowScale * 1.5);
|
|
37
|
+
expect(stacked.height).toBeGreaterThan(stacked.width / 4);
|
|
38
|
+
// Every box is as wide as its cards need, and the stack fits the room's shape.
|
|
39
|
+
expect(stacked.width * stacked.scale).toBeLessThanOrEqual(room.width + 0.5);
|
|
40
|
+
expect(stacked.height * stacked.scale).toBeLessThanOrEqual(room.height + 0.5);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("wraps into columns only when it gains", () => {
|
|
44
|
+
const one = askLayout([{ id: "a", cards: [card("a")] }], { width: 1000, height: 1000 });
|
|
45
|
+
expect(one.cols).toBe(1);
|
|
46
|
+
const tall = askLayout([{ id: "a", cards: Array.from({ length: 8 }, (_, i) => card(`c${i}`)) }], { width: 1900, height: 300 });
|
|
47
|
+
expect(tall.cols).toBeGreaterThan(3);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("leaves room under a card for what hangs from it", () => {
|
|
51
|
+
const l = askLayout([{ id: "a", cards: [card("x", 200, 64 + 66), card("y", 200, 64)] }], { width: 400, height: 1000 });
|
|
52
|
+
// One column: the second card starts below the first's slots.
|
|
53
|
+
expect(l.cols).toBe(1);
|
|
54
|
+
expect(l.cards.y.y).toBeGreaterThanOrEqual(l.cards.x.y + 130);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("the deltas that stack the drawn graph (behold#940)", () => {
|
|
59
|
+
const roots = [{ member: "m", name: "app", path: "app" }, { member: "m", name: "network", path: "network" }];
|
|
60
|
+
const nodes = new Map([
|
|
61
|
+
["m/app/a", { rect: { x: 400, y: 100, w: 150, h: 60 } }],
|
|
62
|
+
["m/app/b", { rect: { x: 560, y: 100, w: 150, h: 60 } }],
|
|
63
|
+
["m/network/n", { rect: { x: 40, y: 100, w: 150, h: 60 } }],
|
|
64
|
+
["stray", { rect: { x: 0, y: 0, w: 10, h: 10 } }],
|
|
65
|
+
]);
|
|
66
|
+
const boxes = new Map([["box:app", { x: 380, y: 60, w0: 350, h0: 120 }], ["box:network", { x: 20, y: 60, w0: 190, h0: 120 }]]);
|
|
67
|
+
|
|
68
|
+
it("moves each root below the one it reads, and each card into its box", () => {
|
|
69
|
+
const got = askDeltas({ roots, nodes, boxes, edges: [{ from: "network", to: "app" }], open: { width: 800, height: 600 } });
|
|
70
|
+
const at = (id, base) => ({ x: base.x + got.deltas[id].dx, y: base.y + got.deltas[id].dy });
|
|
71
|
+
const net = { ...at("box:network", boxes.get("box:network")), w: boxes.get("box:network").w0 + got.deltas["box:network"].dw };
|
|
72
|
+
const app = at("box:app", boxes.get("box:app"));
|
|
73
|
+
expect(net.y).toBeLessThan(app.y);
|
|
74
|
+
const n = at("m/network/n", nodes.get("m/network/n").rect);
|
|
75
|
+
expect(n.x).toBeGreaterThanOrEqual(net.x);
|
|
76
|
+
expect(n.y).toBeGreaterThan(net.y);
|
|
77
|
+
expect(got.deltas.stray).toBeUndefined();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("is null when no root has a box and cards", () => {
|
|
81
|
+
expect(askDeltas({ roots, nodes: new Map(), boxes, open: { width: 1, height: 1 } })).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
});
|