@loadmap/react 0.40.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -32
- package/dist/{Loadmap-DbAbcbNc.js → Loadmap-CM8HshXp.js} +1287 -1897
- package/dist/{Loadmap-BMlU1-mr.d.ts → Loadmap-CyxcmVoc.d.ts} +69 -16
- package/dist/camera-RqbxjjVv.js +209 -0
- package/dist/framePanels-BL9_bQ8A.js +24 -0
- package/dist/index.d.ts +128 -37
- package/dist/index.js +5 -2
- package/dist/later-_c1UnFld.js +195 -0
- package/dist/panels-CemD3oVS.js +479 -0
- package/dist/scenarios-D7DDcwS5.js +521 -0
- package/dist/source.d.ts +1 -1
- package/dist/source.js +5 -2
- package/dist/story-mK-TEB6j.js +127 -0
- package/dist/{zoom-DGmIQ7aO.js → zoom-36lBVilV.js} +45 -8
- package/package.json +5 -5
- package/dist/later-DpL22rlH.js +0 -504
|
@@ -45,6 +45,19 @@ function room(vp) {
|
|
|
45
45
|
h: f.h - 2 * m
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* The room a canvas arranges its diagram for: the board less what is always over it (`reserve`) and Fit's margin.
|
|
50
|
+
* Each way keeps a quarter of the board at least, so bars that grow past a low board never hand the whole board back.
|
|
51
|
+
*/
|
|
52
|
+
function kept(vp, reserve) {
|
|
53
|
+
const w = Math.max(vp.w - reserve.left - reserve.right, vp.w / 4);
|
|
54
|
+
const h = Math.max(vp.h - reserve.top - reserve.bottom, vp.h / 4);
|
|
55
|
+
const m = Math.min(vp.margin, w / 4, h / 4);
|
|
56
|
+
return {
|
|
57
|
+
w: w - 2 * m,
|
|
58
|
+
h: h - 2 * m
|
|
59
|
+
};
|
|
60
|
+
}
|
|
48
61
|
/** The view that shows `r` centred in the free part, as large as fits with the margin, no closer than `max`. */
|
|
49
62
|
function frame(r, vp, max = vp.fitMax) {
|
|
50
63
|
const f = free(vp);
|
|
@@ -451,9 +464,11 @@ function actualSize(viewer) {
|
|
|
451
464
|
* The reader's hands on the board: a drag pans (a press that hardly moves is still a click), a pinch zooms about its
|
|
452
465
|
* middle, and the keys + − 0 and the arrows work while the board or a box has the focus. The wheel zooms about the
|
|
453
466
|
* pointer `always` (a board that fills the page), else only with Ctrl or ⌘ held, or a trackpad's pinch, so a page
|
|
454
|
-
* that scrolls keeps its wheel. Returns a function that lets go.
|
|
467
|
+
* that scrolls keeps its wheel. On a canvas in such a page (`page`) one finger scrolls the page too, zoomed or not. Returns a function that lets go.
|
|
455
468
|
*/
|
|
456
469
|
function attachZoom(board, viewer, o) {
|
|
470
|
+
const always = () => typeof o.always === "function" ? o.always() : o.always;
|
|
471
|
+
const paged = () => !!o.page?.();
|
|
457
472
|
board.tabIndex = 0;
|
|
458
473
|
board.setAttribute("role", "group");
|
|
459
474
|
board.setAttribute("aria-label", "Diagram: drag to pan; + and − zoom, 0 fits");
|
|
@@ -478,10 +493,11 @@ function attachZoom(board, viewer, o) {
|
|
|
478
493
|
viewer.setView(to);
|
|
479
494
|
};
|
|
480
495
|
const touch = () => {
|
|
481
|
-
const action =
|
|
496
|
+
const action = paged() ? "pan-x pan-y" : always() || viewer.readerView ? "none" : "pan-x pan-y";
|
|
482
497
|
if (board.style.touchAction !== action) board.style.touchAction = action;
|
|
483
498
|
};
|
|
484
499
|
const down = (e) => {
|
|
500
|
+
touch();
|
|
485
501
|
if (e.button !== 0 && e.button !== 1 || e.target.closest(".lm-zoom, .lm-crumbs")) return;
|
|
486
502
|
if (!viewer.shownView()) return;
|
|
487
503
|
points.set(e.pointerId, at(e));
|
|
@@ -519,6 +535,7 @@ function attachZoom(board, viewer, o) {
|
|
|
519
535
|
return;
|
|
520
536
|
}
|
|
521
537
|
points.set(e.pointerId, p);
|
|
538
|
+
if (!panning && e.pointerType !== "mouse" && paged()) return;
|
|
522
539
|
if (!panning) {
|
|
523
540
|
const slop = e.pointerType === "mouse" ? SLOP.mouse : SLOP.other;
|
|
524
541
|
if (!start || Math.hypot(p.x - start.x, p.y - start.y) < slop) return;
|
|
@@ -532,7 +549,13 @@ function attachZoom(board, viewer, o) {
|
|
|
532
549
|
};
|
|
533
550
|
const up = (e) => {
|
|
534
551
|
if (!points.delete(e.pointerId)) return;
|
|
535
|
-
if (points.size)
|
|
552
|
+
if (points.size) {
|
|
553
|
+
if (paged()) {
|
|
554
|
+
panning = false;
|
|
555
|
+
start = null;
|
|
556
|
+
}
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
536
559
|
if (panning) swallowUntil = e.timeStamp + 300;
|
|
537
560
|
panning = false;
|
|
538
561
|
start = null;
|
|
@@ -545,7 +568,7 @@ function attachZoom(board, viewer, o) {
|
|
|
545
568
|
e.preventDefault();
|
|
546
569
|
};
|
|
547
570
|
const wheel = (e) => {
|
|
548
|
-
if (!
|
|
571
|
+
if (!always() && !e.ctrlKey && !e.metaKey) return;
|
|
549
572
|
const v = viewer.shownView();
|
|
550
573
|
const vp = viewer.viewport;
|
|
551
574
|
if (!v || !vp) return;
|
|
@@ -583,8 +606,15 @@ function attachZoom(board, viewer, o) {
|
|
|
583
606
|
const to = bring(v, viewer.viewport, n);
|
|
584
607
|
if (to) viewer.go(to, true);
|
|
585
608
|
};
|
|
609
|
+
const fingers = (e) => {
|
|
610
|
+
if (paged() && e.touches.length >= 2 && e.cancelable) e.preventDefault();
|
|
611
|
+
};
|
|
586
612
|
touch();
|
|
587
613
|
const off = viewer.engine.subscribe(touch);
|
|
614
|
+
if (o.page) {
|
|
615
|
+
board.addEventListener("touchstart", fingers, { passive: false });
|
|
616
|
+
board.addEventListener("touchmove", fingers, { passive: false });
|
|
617
|
+
}
|
|
588
618
|
board.addEventListener("pointerdown", down);
|
|
589
619
|
board.addEventListener("pointermove", drag);
|
|
590
620
|
board.addEventListener("pointerup", up);
|
|
@@ -593,7 +623,7 @@ function attachZoom(board, viewer, o) {
|
|
|
593
623
|
board.addEventListener("wheel", wheel, { passive: false });
|
|
594
624
|
board.addEventListener("keydown", key);
|
|
595
625
|
board.addEventListener("focusin", focus);
|
|
596
|
-
|
|
626
|
+
const letGo = () => {
|
|
597
627
|
viewer.land();
|
|
598
628
|
off();
|
|
599
629
|
for (const a of [
|
|
@@ -603,6 +633,8 @@ function attachZoom(board, viewer, o) {
|
|
|
603
633
|
]) board.removeAttribute(a);
|
|
604
634
|
board.style.removeProperty("touch-action");
|
|
605
635
|
board.removeAttribute("data-panning");
|
|
636
|
+
board.removeEventListener("touchstart", fingers);
|
|
637
|
+
board.removeEventListener("touchmove", fingers);
|
|
606
638
|
board.removeEventListener("pointerdown", down);
|
|
607
639
|
board.removeEventListener("pointermove", drag);
|
|
608
640
|
board.removeEventListener("pointerup", up);
|
|
@@ -612,6 +644,7 @@ function attachZoom(board, viewer, o) {
|
|
|
612
644
|
board.removeEventListener("keydown", key);
|
|
613
645
|
board.removeEventListener("focusin", focus);
|
|
614
646
|
};
|
|
647
|
+
return Object.assign(letGo, { hands: touch });
|
|
615
648
|
}
|
|
616
649
|
const SIDES = [
|
|
617
650
|
"top",
|
|
@@ -629,7 +662,7 @@ function mountZoom(board, engine, shape) {
|
|
|
629
662
|
let off;
|
|
630
663
|
const wrap = board.parentElement;
|
|
631
664
|
const measure = () => {
|
|
632
|
-
const { canvas, inset } = shape();
|
|
665
|
+
const { canvas, inset, reserve } = shape();
|
|
633
666
|
if (canvas) for (const s of SIDES) wrap?.style.setProperty(`--lm-inset-${s}`, `${inset[s]}px`);
|
|
634
667
|
const r = board.getBoundingClientRect();
|
|
635
668
|
const w = r.width - 2 * board.clientLeft;
|
|
@@ -647,10 +680,14 @@ function mountZoom(board, engine, shape) {
|
|
|
647
680
|
};
|
|
648
681
|
if (!engine.viewer) {
|
|
649
682
|
engine.viewer = new Viewer(engine, vp);
|
|
650
|
-
off = attachZoom(board, engine.viewer, {
|
|
683
|
+
off = attachZoom(board, engine.viewer, {
|
|
684
|
+
always: () => shape().canvas && !shape().scrolls,
|
|
685
|
+
page: () => !!shape().scrolls
|
|
686
|
+
});
|
|
651
687
|
}
|
|
652
688
|
engine.viewer.setViewport(vp);
|
|
653
|
-
|
|
689
|
+
off?.hands();
|
|
690
|
+
if (canvas) engine.setRoom(reserve ? kept(vp, reserve) : room(vp));
|
|
654
691
|
};
|
|
655
692
|
measure();
|
|
656
693
|
const ro = new ResizeObserver(measure);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loadmap/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"description": "Interactive capacity models for React: an architecture diagram with moving dots, the limits ranked, the verdict, scenarios and headroom.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"loadmap",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"dist"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@loadmap/core": "0.
|
|
43
|
-
"@loadmap/dsl": "0.
|
|
44
|
-
"@loadmap/sim": "0.
|
|
45
|
-
"@loadmap/layout": "0.
|
|
42
|
+
"@loadmap/core": "0.42.0",
|
|
43
|
+
"@loadmap/dsl": "0.42.0",
|
|
44
|
+
"@loadmap/sim": "0.42.0",
|
|
45
|
+
"@loadmap/layout": "0.42.0",
|
|
46
46
|
"elkjs": "^0.12.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
package/dist/later-DpL22rlH.js
DELETED
|
@@ -1,504 +0,0 @@
|
|
|
1
|
-
import { A as rankLabels, C as useComparison, E as whenRange, S as scenarioColor, T as useSize, d as CapTag, f as Controls, g as Meters, k as boxComponent, v as plusMinus, w as useHeadroom, y as Compare } from "./Loadmap-DbAbcbNc.js";
|
|
2
|
-
import { reach } from "@loadmap/core";
|
|
3
|
-
import { compact, fmt, multiple, multiples, pct } from "@loadmap/core/format";
|
|
4
|
-
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
// src/compact.tsx
|
|
7
|
-
/** The names a reader sees for the panels, on the tabs and the buttons that open them. */
|
|
8
|
-
const NAMES = {
|
|
9
|
-
verdict: "Verdict",
|
|
10
|
-
live: "Live",
|
|
11
|
-
limits: "Limits",
|
|
12
|
-
controls: "Design",
|
|
13
|
-
headroom: "Headroom",
|
|
14
|
-
compare: "Compare",
|
|
15
|
-
assumptions: "Assumptions"
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* The verdict in one line, from the same evaluation as the sentence: the load, how far the target holds, the first
|
|
19
|
-
* limit and how sure its capacity is, what is past capacity. The sentence is its tooltip and opens under "Why".
|
|
20
|
-
*/
|
|
21
|
-
function VerdictLine({ lm, verdict = true, extra = 0, open, assumptions }) {
|
|
22
|
-
const { ev, model, values } = lm;
|
|
23
|
-
const first = ev.firstLimit;
|
|
24
|
-
const range = ev.target;
|
|
25
|
-
const target = `${pct(model.thresholds.target)} target`;
|
|
26
|
-
const c = first?.capacity;
|
|
27
|
-
const kind = c?.ref ? "published" : c?.provenance === "estimated" ? "estimated" : "range";
|
|
28
|
-
const sure = !c ? "" : kind === "range" ? plusMinus(c) : `${kind === "published" ? "pub" : "est"}${c.within ? ` ${plusMinus(c)}` : ""}`;
|
|
29
|
-
const over = ev.ranked.filter((x) => (x.util ?? 0) > model.thresholds.full);
|
|
30
|
-
const when = range ? whenRange(model, range) : "";
|
|
31
|
-
const estimated = ev.assumptions.filter((a) => a.kind === "capacity" && a.capacity.provenance === "estimated").length;
|
|
32
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
33
|
-
verdict && /* @__PURE__ */ jsx("p", {
|
|
34
|
-
className: "lm-headline",
|
|
35
|
-
title: ev.verdict.text,
|
|
36
|
-
"aria-live": "polite",
|
|
37
|
-
children: !first || !range ? ev.verdict.text : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
38
|
-
/* @__PURE__ */ jsxs("b", {
|
|
39
|
-
className: "lm-num",
|
|
40
|
-
children: [fmt(values.load), "×"]
|
|
41
|
-
}),
|
|
42
|
-
" ·",
|
|
43
|
-
" ",
|
|
44
|
-
values.load < range.low ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
45
|
-
"the ",
|
|
46
|
-
target,
|
|
47
|
-
" holds to ",
|
|
48
|
-
/* @__PURE__ */ jsx("b", {
|
|
49
|
-
className: "lm-num",
|
|
50
|
-
children: multiples(range, model.searchMax, true)
|
|
51
|
-
}),
|
|
52
|
-
when && ` (${when})`
|
|
53
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
54
|
-
"past the ",
|
|
55
|
-
target,
|
|
56
|
-
" from ",
|
|
57
|
-
/* @__PURE__ */ jsx("b", {
|
|
58
|
-
className: "lm-num",
|
|
59
|
-
children: multiple(range.low, model.searchMax)
|
|
60
|
-
})
|
|
61
|
-
] }),
|
|
62
|
-
" ",
|
|
63
|
-
"· limited by ",
|
|
64
|
-
/* @__PURE__ */ jsx("b", { children: first.name }),
|
|
65
|
-
sure && /* @__PURE__ */ jsx("span", {
|
|
66
|
-
className: "lm-tag",
|
|
67
|
-
"data-kind": kind,
|
|
68
|
-
children: sure
|
|
69
|
-
}),
|
|
70
|
-
over.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
71
|
-
" ",
|
|
72
|
-
"· ",
|
|
73
|
-
/* @__PURE__ */ jsx("b", { children: over.map((x) => x.name).join(", ") }),
|
|
74
|
-
" past capacity"
|
|
75
|
-
] })
|
|
76
|
-
] })
|
|
77
|
-
}),
|
|
78
|
-
open && verdict && /* @__PURE__ */ jsx("button", {
|
|
79
|
-
type: "button",
|
|
80
|
-
className: "lm-link",
|
|
81
|
-
onClick: (e) => open("verdict", e.currentTarget),
|
|
82
|
-
children: "Why ›"
|
|
83
|
-
}),
|
|
84
|
-
open && assumptions && /* @__PURE__ */ jsxs("button", {
|
|
85
|
-
type: "button",
|
|
86
|
-
className: "lm-link",
|
|
87
|
-
onClick: (e) => open("assumptions", e.currentTarget),
|
|
88
|
-
children: [
|
|
89
|
-
"What this assumes · ",
|
|
90
|
-
ev.assumptions.length + extra,
|
|
91
|
-
estimated > 0 && ` (${estimated} estimated)`,
|
|
92
|
-
" ›"
|
|
93
|
-
]
|
|
94
|
-
})
|
|
95
|
-
] });
|
|
96
|
-
}
|
|
97
|
-
/** The order of the cards in the dock: what the reader changes first, what it changes next to it. */
|
|
98
|
-
const DOCK = [
|
|
99
|
-
"controls",
|
|
100
|
-
"live",
|
|
101
|
-
"limits",
|
|
102
|
-
"headroom",
|
|
103
|
-
"compare"
|
|
104
|
-
];
|
|
105
|
-
/**
|
|
106
|
-
* Full screen's panels, compact, side by side in a box the screen sizes: what does not fit is left out whole, and
|
|
107
|
-
* each card opens its panel whole. A phone shows one at a time, under tabs.
|
|
108
|
-
*/
|
|
109
|
-
function Dock({ lm, panels, open }) {
|
|
110
|
-
const shown = DOCK.filter((p) => panels.includes(p));
|
|
111
|
-
const [tab, setTab] = useState(null);
|
|
112
|
-
if (!shown.length) return null;
|
|
113
|
-
const active = tab && shown.includes(tab) ? tab : shown[0];
|
|
114
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
115
|
-
className: "lm-dock",
|
|
116
|
-
children: [/* @__PURE__ */ jsx("fieldset", {
|
|
117
|
-
className: "lm-tabs",
|
|
118
|
-
"aria-label": "Panels",
|
|
119
|
-
children: shown.map((p) => /* @__PURE__ */ jsx("button", {
|
|
120
|
-
type: "button",
|
|
121
|
-
"aria-pressed": p === active,
|
|
122
|
-
onClick: () => setTab(p),
|
|
123
|
-
children: NAMES[p]
|
|
124
|
-
}, p))
|
|
125
|
-
}), shown.map((p) => /* @__PURE__ */ jsx(Card, {
|
|
126
|
-
lm,
|
|
127
|
-
panel: p,
|
|
128
|
-
open,
|
|
129
|
-
active: p === active
|
|
130
|
-
}, p))]
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function Card({ lm, panel, open, active }) {
|
|
134
|
-
const box = useRef(null);
|
|
135
|
-
const more = useRef(null);
|
|
136
|
-
useClip(box, more);
|
|
137
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
138
|
-
className: "lm-mini",
|
|
139
|
-
"data-mini": panel,
|
|
140
|
-
"data-active": active || void 0,
|
|
141
|
-
ref: box,
|
|
142
|
-
children: [panel === "controls" ? /* @__PURE__ */ jsx(Controls, {
|
|
143
|
-
lm,
|
|
144
|
-
load: false
|
|
145
|
-
}) : panel === "compare" ? /* @__PURE__ */ jsx(Compare, { lm }) : /* @__PURE__ */ jsx("div", {
|
|
146
|
-
className: "lm-card",
|
|
147
|
-
children: panel === "live" ? /* @__PURE__ */ jsx(Meters, { lm }) : panel === "limits" ? /* @__PURE__ */ jsx(MiniLimits, { lm }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Headroom" }), /* @__PURE__ */ jsx(Sparkline, { lm })] })
|
|
148
|
-
}), /* @__PURE__ */ jsx("button", {
|
|
149
|
-
type: "button",
|
|
150
|
-
className: "lm-more",
|
|
151
|
-
ref: more,
|
|
152
|
-
"aria-label": `${NAMES[panel]}, all of it`,
|
|
153
|
-
onClick: (e) => open(panel, e.currentTarget),
|
|
154
|
-
children: "›"
|
|
155
|
-
})]
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
/** The rows a card leaves out whole when they do not fit. */
|
|
159
|
-
const ROWS = ".lm-meter, .lm-mini-lim, .lm-controls > *, .lm-table tbody tr";
|
|
160
|
-
/**
|
|
161
|
-
* Hides the rows that cross the bottom of the card, and counts them on its button. Runs again when the card's size
|
|
162
|
-
* or its rows change: the meters come and go with the load, and the order of the limits with it.
|
|
163
|
-
*/
|
|
164
|
-
function useClip(box, more) {
|
|
165
|
-
useEffect(() => {
|
|
166
|
-
const card = box.current?.querySelector(".lm-card");
|
|
167
|
-
if (!card) return;
|
|
168
|
-
const clip = () => {
|
|
169
|
-
const r = card.getBoundingClientRect();
|
|
170
|
-
const bottom = r.bottom - Number.parseFloat(getComputedStyle(card).paddingBottom || "0");
|
|
171
|
-
let n = 0;
|
|
172
|
-
for (const row of card.querySelectorAll(ROWS)) {
|
|
173
|
-
const out = r.height > 0 && row.getBoundingClientRect().bottom > bottom + .5;
|
|
174
|
-
row.toggleAttribute("data-clip", out);
|
|
175
|
-
if (out && !row.matches("h3")) n++;
|
|
176
|
-
}
|
|
177
|
-
if (more.current) more.current.dataset.more = n ? `+${n}` : "";
|
|
178
|
-
};
|
|
179
|
-
const ro = new ResizeObserver(clip);
|
|
180
|
-
ro.observe(card);
|
|
181
|
-
const mo = new MutationObserver(clip);
|
|
182
|
-
mo.observe(card, {
|
|
183
|
-
childList: true,
|
|
184
|
-
subtree: true
|
|
185
|
-
});
|
|
186
|
-
clip();
|
|
187
|
-
return () => {
|
|
188
|
-
ro.disconnect();
|
|
189
|
-
mo.disconnect();
|
|
190
|
-
};
|
|
191
|
-
}, [box, more]);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* The limits in their order, a line each: the name and how sure its capacity is, the bar, the utilization, where it
|
|
195
|
-
* is full. The first is the first limit: the verdict line names it.
|
|
196
|
-
*/
|
|
197
|
-
function MiniLimits({ lm }) {
|
|
198
|
-
const { ev, model } = lm;
|
|
199
|
-
const top = Math.max(1.5, model.thresholds.full * 1.5);
|
|
200
|
-
const at = (u) => `${u / top * 100}%`;
|
|
201
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Where it runs out" }), /* @__PURE__ */ jsx("div", {
|
|
202
|
-
className: "lm-mini-limits",
|
|
203
|
-
children: ev.ranked.map((c) => /* @__PURE__ */ jsxs("div", {
|
|
204
|
-
className: "lm-mini-lim",
|
|
205
|
-
"data-component": c.id,
|
|
206
|
-
children: [
|
|
207
|
-
/* @__PURE__ */ jsxs("span", {
|
|
208
|
-
className: "lm-name",
|
|
209
|
-
title: c.name,
|
|
210
|
-
children: [c.name, /* @__PURE__ */ jsx(CapTag, {
|
|
211
|
-
c: c.capacity,
|
|
212
|
-
short: true
|
|
213
|
-
})]
|
|
214
|
-
}),
|
|
215
|
-
/* @__PURE__ */ jsxs("span", {
|
|
216
|
-
className: "lm-track",
|
|
217
|
-
role: "img",
|
|
218
|
-
"aria-label": `${c.name} at ${c.util == null ? "off" : pct(c.util)}`,
|
|
219
|
-
children: [
|
|
220
|
-
/* @__PURE__ */ jsx("span", {
|
|
221
|
-
className: "lm-fill",
|
|
222
|
-
"data-state": c.state,
|
|
223
|
-
style: { width: `${Math.min(100, (c.util ?? 0) / top * 100)}%` }
|
|
224
|
-
}),
|
|
225
|
-
/* @__PURE__ */ jsx("span", {
|
|
226
|
-
className: "lm-tick",
|
|
227
|
-
style: { left: at(model.thresholds.target) }
|
|
228
|
-
}),
|
|
229
|
-
/* @__PURE__ */ jsx("span", {
|
|
230
|
-
className: "lm-tick",
|
|
231
|
-
style: { left: at(model.thresholds.full) }
|
|
232
|
-
})
|
|
233
|
-
]
|
|
234
|
-
}),
|
|
235
|
-
/* @__PURE__ */ jsx("span", {
|
|
236
|
-
className: "lm-val",
|
|
237
|
-
children: c.util == null ? "—" : pct(c.util)
|
|
238
|
-
}),
|
|
239
|
-
/* @__PURE__ */ jsx("span", {
|
|
240
|
-
className: "lm-val lm-sub",
|
|
241
|
-
children: c.missing != null ? "none published" : c.util == null ? "off" : c.full != null && !Number.isFinite(c.full) ? `full > ${fmt(model.searchMax)}×` : `full ${c.fullRange ? multiples(c.fullRange, model.searchMax, true) : multiple(c.full, model.searchMax)}`
|
|
242
|
-
})
|
|
243
|
-
]
|
|
244
|
-
}, c.id))
|
|
245
|
-
})] });
|
|
246
|
-
}
|
|
247
|
-
/** The headroom chart as a sparkline: each scenario's line, the target, the load; where the shown one crosses it. */
|
|
248
|
-
function Sparkline({ lm }) {
|
|
249
|
-
const { model, values } = lm;
|
|
250
|
-
const h = useHeadroom(lm);
|
|
251
|
-
const [box, { width: W, height: H }] = useSize(240);
|
|
252
|
-
const top = Math.max(1.5, model.thresholds.full * 1.5);
|
|
253
|
-
const lx = (x) => W * Math.log(x / h.from) / Math.log(h.to / h.from);
|
|
254
|
-
const ly = (u) => 8 + (H - 10) * (1 - Math.min(u, top * 1.2) / top);
|
|
255
|
-
const path = (s) => {
|
|
256
|
-
let d = "";
|
|
257
|
-
let pen = false;
|
|
258
|
-
for (const [x, u] of s) {
|
|
259
|
-
if (u == null) {
|
|
260
|
-
pen = false;
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
d += `${pen ? "L" : "M"}${lx(x).toFixed(1)} ${ly(u).toFixed(1)}`;
|
|
264
|
-
pen = true;
|
|
265
|
-
}
|
|
266
|
-
return d;
|
|
267
|
-
};
|
|
268
|
-
const line = h.lines.find((l) => l.selected) ?? h.lines[0];
|
|
269
|
-
const target = pct(model.thresholds.target);
|
|
270
|
-
const reaches = line ? `${line.targetRange ? multiples(line.targetRange, model.searchMax, true) : multiple(line.target, model.searchMax)}` : "";
|
|
271
|
-
const when = line ? whenRange(model, line.targetRange) : "";
|
|
272
|
-
const loadX = lx(Math.min(h.to, Math.max(h.from, values.load)));
|
|
273
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
274
|
-
className: "lm-spark",
|
|
275
|
-
ref: box,
|
|
276
|
-
children: H > 0 && /* @__PURE__ */ jsxs("svg", {
|
|
277
|
-
width: W,
|
|
278
|
-
height: H,
|
|
279
|
-
"aria-hidden": "true",
|
|
280
|
-
children: [
|
|
281
|
-
/* @__PURE__ */ jsx("line", {
|
|
282
|
-
className: "lm-spark-th",
|
|
283
|
-
x1: 0,
|
|
284
|
-
x2: W,
|
|
285
|
-
y1: ly(model.thresholds.target),
|
|
286
|
-
y2: ly(model.thresholds.target)
|
|
287
|
-
}),
|
|
288
|
-
h.lines.map((l) => /* @__PURE__ */ jsx("path", {
|
|
289
|
-
d: path(l.envelope),
|
|
290
|
-
fill: "none",
|
|
291
|
-
stroke: scenarioColor(model, l.label),
|
|
292
|
-
strokeWidth: l.selected ? 2 : 1.25
|
|
293
|
-
}, l.label ?? "")),
|
|
294
|
-
/* @__PURE__ */ jsx("line", {
|
|
295
|
-
className: "lm-spark-load",
|
|
296
|
-
x1: loadX,
|
|
297
|
-
x2: loadX,
|
|
298
|
-
y1: 0,
|
|
299
|
-
y2: H
|
|
300
|
-
})
|
|
301
|
-
]
|
|
302
|
-
})
|
|
303
|
-
}), line && /* @__PURE__ */ jsxs("p", {
|
|
304
|
-
className: "lm-spark-text",
|
|
305
|
-
title: `${line.label ?? "It"} reaches the ${target} target at ${reaches}`,
|
|
306
|
-
children: [
|
|
307
|
-
line.label ?? "It",
|
|
308
|
-
" reaches the ",
|
|
309
|
-
target,
|
|
310
|
-
" target at ",
|
|
311
|
-
reaches,
|
|
312
|
-
when && ` (${when})`,
|
|
313
|
-
"."
|
|
314
|
-
]
|
|
315
|
-
})] });
|
|
316
|
-
}
|
|
317
|
-
// src/detail.tsx
|
|
318
|
-
/**
|
|
319
|
-
* A box's component in words, over the board: utilization, demand against capacity and where it came from, where it
|
|
320
|
-
* reaches the target and 100 % (with dates, given growth), and its target in each scenario. HTML, so exports leave it out.
|
|
321
|
-
*/
|
|
322
|
-
function Detail({ lm, scene, id, board, detailId }) {
|
|
323
|
-
const { model, ev } = lm;
|
|
324
|
-
const n = scene.nodes.find((x) => x.id === id);
|
|
325
|
-
const cid = n && boxComponent(lm.ev, n);
|
|
326
|
-
const comparison = useComparison(lm);
|
|
327
|
-
const rows = model.scenarios.length > 1 ? comparison.rows : [];
|
|
328
|
-
useEffect(() => {
|
|
329
|
-
const el = board?.querySelector(`[data-node="${CSS.escape(id)}"]`);
|
|
330
|
-
el?.setAttribute("aria-describedby", detailId);
|
|
331
|
-
return () => el?.removeAttribute("aria-describedby");
|
|
332
|
-
}, [
|
|
333
|
-
board,
|
|
334
|
-
id,
|
|
335
|
-
detailId
|
|
336
|
-
]);
|
|
337
|
-
const c = cid ? ev.components[cid] : void 0;
|
|
338
|
-
const tip = useRef(null);
|
|
339
|
-
const box = n && `${n.x} ${n.y} ${n.w} ${n.h}`;
|
|
340
|
-
useLayoutEffect(() => {
|
|
341
|
-
const el = tip.current;
|
|
342
|
-
const wrap = el?.offsetParent;
|
|
343
|
-
if (!el || !n || !board || !(wrap instanceof HTMLElement)) return;
|
|
344
|
-
const place = () => {
|
|
345
|
-
const p = lm.engine.viewer?.placement();
|
|
346
|
-
const k = p ? p.k : board.clientWidth / scene.width;
|
|
347
|
-
const [dx, dy] = p ? [p.dx, p.dy] : [0, 0];
|
|
348
|
-
const w = wrap.getBoundingClientRect();
|
|
349
|
-
const y = (v) => v - w.top - wrap.clientTop + wrap.scrollTop;
|
|
350
|
-
let lo = 0;
|
|
351
|
-
let hi = innerHeight;
|
|
352
|
-
for (let a = wrap; a; a = a.parentElement) {
|
|
353
|
-
if (getComputedStyle(a).overflowY === "visible") continue;
|
|
354
|
-
const r = a.getBoundingClientRect();
|
|
355
|
-
lo = Math.max(lo, r.top);
|
|
356
|
-
hi = Math.min(hi, r.bottom);
|
|
357
|
-
}
|
|
358
|
-
const [top, bottom] = [y(lo) + 4, y(hi) - 4];
|
|
359
|
-
const h = el.offsetHeight;
|
|
360
|
-
const boxTop = board.offsetTop + dy + n.y * k;
|
|
361
|
-
const boxBottom = board.offsetTop + dy + (n.y + n.h) * k;
|
|
362
|
-
const below = boxBottom + 6;
|
|
363
|
-
const above = boxTop - 6 - h;
|
|
364
|
-
const fits = (n.y + n.h / 2 < scene.height / 2 ? [below, above] : [above, below]).find((t) => t >= top && t + h <= bottom);
|
|
365
|
-
const roomier = bottom - boxBottom >= boxTop - top ? below : above;
|
|
366
|
-
el.style.top = `${Math.max(top, Math.min(fits ?? roomier, bottom - h))}px`;
|
|
367
|
-
el.style.left = `${Math.max(0, Math.min(board.offsetLeft + dx + n.x * k, wrap.clientWidth - el.offsetWidth))}px`;
|
|
368
|
-
};
|
|
369
|
-
place();
|
|
370
|
-
const off = lm.engine.viewer ? lm.engine.subscribe(place) : null;
|
|
371
|
-
const ro = new ResizeObserver(place);
|
|
372
|
-
ro.observe(el);
|
|
373
|
-
ro.observe(board);
|
|
374
|
-
document.addEventListener("scroll", place, {
|
|
375
|
-
capture: true,
|
|
376
|
-
passive: true
|
|
377
|
-
});
|
|
378
|
-
addEventListener("resize", place);
|
|
379
|
-
return () => {
|
|
380
|
-
off?.();
|
|
381
|
-
ro.disconnect();
|
|
382
|
-
document.removeEventListener("scroll", place, { capture: true });
|
|
383
|
-
removeEventListener("resize", place);
|
|
384
|
-
};
|
|
385
|
-
}, [
|
|
386
|
-
box,
|
|
387
|
-
board,
|
|
388
|
-
scene
|
|
389
|
-
]);
|
|
390
|
-
if (!n || !c || !board) return null;
|
|
391
|
-
const at = (r, x) => r ? reach(r, model.searchMax, model.dateAt) : multiple(x, model.searchMax);
|
|
392
|
-
const num = (x) => Math.abs(x) >= 1e3 ? compact(x) : fmt(x);
|
|
393
|
-
const cap = c.capacity;
|
|
394
|
-
const rank = rankLabels(ev, model).get(c.id);
|
|
395
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
396
|
-
id: detailId,
|
|
397
|
-
className: "lm-tip lm-detail",
|
|
398
|
-
role: "tooltip",
|
|
399
|
-
ref: tip,
|
|
400
|
-
children: [
|
|
401
|
-
/* @__PURE__ */ jsxs("b", { children: [c.name, rank && /* @__PURE__ */ jsx("span", {
|
|
402
|
-
className: "lm-tag",
|
|
403
|
-
"data-kind": rank.rank === 1 ? "first" : "rank",
|
|
404
|
-
children: rank.word
|
|
405
|
-
})] }),
|
|
406
|
-
c.missing != null ? /* @__PURE__ */ jsxs("span", { children: [
|
|
407
|
-
"No published benchmark ",
|
|
408
|
-
c.missing,
|
|
409
|
-
"."
|
|
410
|
-
] }) : c.util == null || !cap ? /* @__PURE__ */ jsx("span", { children: "switched off" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
411
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
412
|
-
/* @__PURE__ */ jsx("strong", { children: pct(c.util) }),
|
|
413
|
-
" · ",
|
|
414
|
-
num(c.demand ?? 0),
|
|
415
|
-
" of ",
|
|
416
|
-
fmt(cap.value),
|
|
417
|
-
" ",
|
|
418
|
-
cap.unit,
|
|
419
|
-
cap.within ? ` ${plusMinus(cap)}` : ""
|
|
420
|
-
] }),
|
|
421
|
-
c.held && heldText(model, c.held) && /* @__PURE__ */ jsx("span", { children: heldText(model, c.held) }),
|
|
422
|
-
/* @__PURE__ */ jsxs("span", {
|
|
423
|
-
className: "lm-sub",
|
|
424
|
-
children: [
|
|
425
|
-
"capacity",
|
|
426
|
-
" ",
|
|
427
|
-
/* @__PURE__ */ jsx("span", {
|
|
428
|
-
className: "lm-prov",
|
|
429
|
-
"data-kind": cap.provenance,
|
|
430
|
-
children: cap.provenance
|
|
431
|
-
}),
|
|
432
|
-
cap.source ? `, ${cap.source}` : ""
|
|
433
|
-
]
|
|
434
|
-
}),
|
|
435
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
436
|
-
pct(model.thresholds.target),
|
|
437
|
-
" at ",
|
|
438
|
-
at(c.targetRange, c.target)
|
|
439
|
-
] }),
|
|
440
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
441
|
-
pct(model.thresholds.full),
|
|
442
|
-
" at ",
|
|
443
|
-
at(c.fullRange, c.full)
|
|
444
|
-
] }),
|
|
445
|
-
blocks(lm, n).map((line) => /* @__PURE__ */ jsx("span", { children: line }, line)),
|
|
446
|
-
c.over && /* @__PURE__ */ jsxs("span", {
|
|
447
|
-
className: "lm-sub",
|
|
448
|
-
children: [
|
|
449
|
-
"Past ",
|
|
450
|
-
pct(model.thresholds.full),
|
|
451
|
-
": ",
|
|
452
|
-
c.over,
|
|
453
|
-
"."
|
|
454
|
-
]
|
|
455
|
-
})
|
|
456
|
-
] }),
|
|
457
|
-
rows.length > 0 && /* @__PURE__ */ jsxs("span", {
|
|
458
|
-
className: "lm-sub",
|
|
459
|
-
children: [
|
|
460
|
-
pct(model.thresholds.target),
|
|
461
|
-
" by scenario:",
|
|
462
|
-
" ",
|
|
463
|
-
rows.map((r, i) => {
|
|
464
|
-
const x = r.components.find((y) => y.id === cid);
|
|
465
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
466
|
-
className: "lm-nowrap",
|
|
467
|
-
children: [
|
|
468
|
-
i > 0 && " · ",
|
|
469
|
-
/* @__PURE__ */ jsx("b", {
|
|
470
|
-
className: "lm-key",
|
|
471
|
-
style: { background: scenarioColor(model, r.label) }
|
|
472
|
-
}),
|
|
473
|
-
r.label,
|
|
474
|
-
" ",
|
|
475
|
-
x?.targetRange == null ? "off" : multiples(x.targetRange, model.searchMax, true)
|
|
476
|
-
]
|
|
477
|
-
}, r.label);
|
|
478
|
-
})
|
|
479
|
-
]
|
|
480
|
-
})
|
|
481
|
-
]
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
/** How long a unit of each flow holds a slot: "held 20 ms per order". */
|
|
485
|
-
function heldText(model, held) {
|
|
486
|
-
const time = (s) => s < 1 ? `${fmt(s * 1e3)} ms` : s < 120 ? `${fmt(s)} s` : s < 7200 ? `${fmt(s / 60)} min` : `${fmt(s / 3600)} h`;
|
|
487
|
-
const per = Object.entries(held).filter(([, s]) => s > 0).map(([f, s]) => {
|
|
488
|
-
const flow = model.def.flows[f];
|
|
489
|
-
return `${time(s)} per ${flow?.unit ?? `unit of ${flow?.label ?? f}`}`;
|
|
490
|
-
});
|
|
491
|
-
return per.length ? `held ${per.join(", ")}` : "";
|
|
492
|
-
}
|
|
493
|
-
/** What a box's building blocks do at these values: pods running, cache answers, what a stage turns away. */
|
|
494
|
-
function blocks(lm, n) {
|
|
495
|
-
const out = [];
|
|
496
|
-
for (const id of n.stages) {
|
|
497
|
-
const s = lm.ev.stages[id];
|
|
498
|
-
if (s?.kind === "workers" && s.autoscale) out.push(`${s.running} of ${s.pods} pods running, each held near ${pct(s.autoscale.target)}`);
|
|
499
|
-
if (s?.kind === "cache") out.push(`${pct(s.hit)} answered here`);
|
|
500
|
-
if ((s?.kind === "pass" || s?.kind === "limit" || s?.kind === "cache" || s?.kind === "split") && s.shed > 0) out.push(`${pct(s.shed)} of what reaches it turned away`);
|
|
501
|
-
}
|
|
502
|
-
return out;
|
|
503
|
-
}
|
|
504
|
-
export { Detail, Dock, VerdictLine };
|