@loadmap/react 0.40.0 → 0.41.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
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import { g as whenRange, h as when, m as useSize, p as scenarioColor } from "./Loadmap-CM8HshXp.js";
|
|
2
|
+
import { compare, headroom } from "@loadmap/core";
|
|
3
|
+
import { fmt, multiple, multiples, pct } from "@loadmap/core/format";
|
|
4
|
+
import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
// src/scenarios.tsx
|
|
7
|
+
const lineName = (l) => l.label ?? "These values";
|
|
8
|
+
/** The comparison at the shown load: crossings do not depend on it, the verdicts do. */
|
|
9
|
+
function useComparison(lm) {
|
|
10
|
+
return useMemo(() => compare(lm.model, lm.values.load), [lm.model, lm.values.load]);
|
|
11
|
+
}
|
|
12
|
+
/** "+107 %" against the baseline; "same" within a rounding; nothing where either never runs out. */
|
|
13
|
+
function change(x) {
|
|
14
|
+
if (x == null || !Number.isFinite(x) || x === 0) return "";
|
|
15
|
+
if (Math.abs(x - 1) < .005) return "same";
|
|
16
|
+
return `${x > 1 ? "+" : "−"}${pct(Math.abs(x - 1))}`;
|
|
17
|
+
}
|
|
18
|
+
/** The scenarios side by side: which buys more headroom, where each first runs out, and per component. */
|
|
19
|
+
function Compare({ lm, title = "Scenarios compared" }) {
|
|
20
|
+
const { model } = lm;
|
|
21
|
+
const c = useComparison(lm);
|
|
22
|
+
if (c.rows.length < 2) return null;
|
|
23
|
+
const target = `${pct(model.thresholds.target)} target`;
|
|
24
|
+
const at = (r) => /* @__PURE__ */ jsxs(Fragment, { children: [r ? multiples(r, model.searchMax, true) : multiple(null), whenRange(model, r) && /* @__PURE__ */ jsx("small", { children: whenRange(model, r) })] });
|
|
25
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
26
|
+
className: "lm-card lm-compare",
|
|
27
|
+
children: [
|
|
28
|
+
/* @__PURE__ */ jsx("h3", { children: title }),
|
|
29
|
+
/* @__PURE__ */ jsx("p", {
|
|
30
|
+
className: "lm-compare-text",
|
|
31
|
+
children: c.text
|
|
32
|
+
}),
|
|
33
|
+
/* @__PURE__ */ jsx("div", {
|
|
34
|
+
className: "lm-table-wrap",
|
|
35
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
36
|
+
className: "lm-table",
|
|
37
|
+
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
38
|
+
/* @__PURE__ */ jsx("th", {
|
|
39
|
+
scope: "col",
|
|
40
|
+
children: "Scenario"
|
|
41
|
+
}),
|
|
42
|
+
/* @__PURE__ */ jsx("th", {
|
|
43
|
+
scope: "col",
|
|
44
|
+
children: "Limited by"
|
|
45
|
+
}),
|
|
46
|
+
/* @__PURE__ */ jsx("th", {
|
|
47
|
+
scope: "col",
|
|
48
|
+
children: target
|
|
49
|
+
}),
|
|
50
|
+
/* @__PURE__ */ jsx("th", {
|
|
51
|
+
scope: "col",
|
|
52
|
+
children: "Runs out"
|
|
53
|
+
})
|
|
54
|
+
] }) }), /* @__PURE__ */ jsx("tbody", { children: c.rows.map((r) => /* @__PURE__ */ jsxs("tr", {
|
|
55
|
+
"data-scenario": r.label,
|
|
56
|
+
"aria-current": lm.scenario?.label === r.label || void 0,
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsxs("th", {
|
|
59
|
+
scope: "row",
|
|
60
|
+
children: [/* @__PURE__ */ jsx("i", { style: { background: scenarioColor(model, r.label) } }), r.label]
|
|
61
|
+
}),
|
|
62
|
+
/* @__PURE__ */ jsx("td", {
|
|
63
|
+
className: "lm-text",
|
|
64
|
+
children: r.firstLimit?.name ?? "—"
|
|
65
|
+
}),
|
|
66
|
+
/* @__PURE__ */ jsx("td", {
|
|
67
|
+
"data-multiple": r.target ?? "",
|
|
68
|
+
"data-high": r.targetRange?.high ?? "",
|
|
69
|
+
children: at(r.targetRange)
|
|
70
|
+
}),
|
|
71
|
+
/* @__PURE__ */ jsx("td", {
|
|
72
|
+
"data-multiple": r.full ?? "",
|
|
73
|
+
"data-high": r.fullRange?.high ?? "",
|
|
74
|
+
children: at(r.fullRange)
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
}, r.label)) })]
|
|
78
|
+
})
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ jsxs("h3", { children: [target, ", by component"] }),
|
|
81
|
+
/* @__PURE__ */ jsx("div", {
|
|
82
|
+
className: "lm-table-wrap",
|
|
83
|
+
children: /* @__PURE__ */ jsxs("table", {
|
|
84
|
+
className: "lm-table",
|
|
85
|
+
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsx("th", {
|
|
86
|
+
scope: "col",
|
|
87
|
+
children: "Component"
|
|
88
|
+
}), c.rows.map((r) => /* @__PURE__ */ jsx("th", {
|
|
89
|
+
scope: "col",
|
|
90
|
+
children: r.label
|
|
91
|
+
}, r.label))] }) }), /* @__PURE__ */ jsx("tbody", { children: model.componentIds.map((id, k) => /* @__PURE__ */ jsxs("tr", {
|
|
92
|
+
"data-component": id,
|
|
93
|
+
children: [/* @__PURE__ */ jsx("th", {
|
|
94
|
+
scope: "row",
|
|
95
|
+
children: c.rows[0].components[k].name
|
|
96
|
+
}), c.rows.map((r, i) => {
|
|
97
|
+
const x = r.components[k];
|
|
98
|
+
return /* @__PURE__ */ jsxs("td", {
|
|
99
|
+
"data-multiple": x.target ?? "",
|
|
100
|
+
children: [x.targetRange == null ? "off" : multiples(x.targetRange, model.searchMax, true), i > 0 && change(x.change) && /* @__PURE__ */ jsx("small", { children: change(x.change) })]
|
|
101
|
+
}, r.label);
|
|
102
|
+
})]
|
|
103
|
+
}, id)) })]
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/** Every scenario's line over the load: it depends on every value but the load, which is only the marker. */
|
|
110
|
+
function useHeadroom(lm) {
|
|
111
|
+
const { model, values } = lm;
|
|
112
|
+
const rest = JSON.stringify({
|
|
113
|
+
...values,
|
|
114
|
+
load: null
|
|
115
|
+
});
|
|
116
|
+
return useMemo(() => headroom(model, {
|
|
117
|
+
...values,
|
|
118
|
+
load: model.load.default
|
|
119
|
+
}), [model, rest]);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The width of a label in the chart's 11 px monospace (`--lm-mono`), measured once the chart is on the page, so its
|
|
123
|
+
* labels are kept inside it whatever the theme's font.
|
|
124
|
+
*/
|
|
125
|
+
function useAxisMeasure(el) {
|
|
126
|
+
const [measure, setMeasure] = useState(() => (text, _weight) => text.length * 6.7);
|
|
127
|
+
useLayoutEffect(() => {
|
|
128
|
+
const ctx = el.current && document.createElement("canvas").getContext("2d");
|
|
129
|
+
if (!ctx) return;
|
|
130
|
+
const font = getComputedStyle(el.current).getPropertyValue("--lm-mono").trim() || "monospace";
|
|
131
|
+
setMeasure(() => (text, weight = 400) => {
|
|
132
|
+
ctx.font = `${weight} 11px ${font}`;
|
|
133
|
+
return ctx.measureText(text).width;
|
|
134
|
+
});
|
|
135
|
+
}, [el]);
|
|
136
|
+
return measure;
|
|
137
|
+
}
|
|
138
|
+
/** 1, 2, 5, 10, 20, 50, … inside [from, to]; decades only when there is little room. */
|
|
139
|
+
function ticks(from, to, roomy) {
|
|
140
|
+
const out = [];
|
|
141
|
+
for (let d = Math.floor(Math.log10(from)); d <= Math.ceil(Math.log10(to)); d++) for (const k of roomy ? [
|
|
142
|
+
1,
|
|
143
|
+
2,
|
|
144
|
+
5
|
|
145
|
+
] : [1]) {
|
|
146
|
+
const v = k * 10 ** d;
|
|
147
|
+
if (v >= from * .999 && v <= to * 1.001) out.push(Number(v.toPrecision(6)));
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Utilization over the load multiple. Each scenario's line is its highest utilization, so it crosses the target and
|
|
153
|
+
* 100 % exactly where its first limit does; the dots are those crossings, taken from the limits, not from the line.
|
|
154
|
+
* With a ± on a capacity, a band shows the line at every capacity's low and high bound, and a bracket on the target
|
|
155
|
+
* and 100 % lines spans where the band crosses them. The shown scenario's components are the thin lines under it.
|
|
156
|
+
* Hover or arrow keys read every line at one load.
|
|
157
|
+
*/
|
|
158
|
+
function HeadroomChart({ lm, title = "Headroom" }) {
|
|
159
|
+
const { model, values } = lm;
|
|
160
|
+
const h = useHeadroom(lm);
|
|
161
|
+
const [wrap, { width }] = useSize(640);
|
|
162
|
+
const [hover, setHover] = useState(null);
|
|
163
|
+
const clip = useId().replace(/:/g, "");
|
|
164
|
+
const measure = useAxisMeasure(wrap);
|
|
165
|
+
const tip = useRef(null);
|
|
166
|
+
useLayoutEffect(() => {
|
|
167
|
+
const el = tip.current;
|
|
168
|
+
if (el && hover != null) el.style.left = `${Math.max(0, Math.min(lx(xs[hover]) + 10, W - el.offsetWidth))}px`;
|
|
169
|
+
});
|
|
170
|
+
const dated = !!model.growth;
|
|
171
|
+
const m = {
|
|
172
|
+
l: 44,
|
|
173
|
+
r: 14,
|
|
174
|
+
t: 14,
|
|
175
|
+
b: dated ? 40 : 26
|
|
176
|
+
};
|
|
177
|
+
const W = width;
|
|
178
|
+
const H = Math.round(Math.min(300, Math.max(200, W * .45)));
|
|
179
|
+
const pw = W - m.l - m.r;
|
|
180
|
+
const ph = H - m.t - m.b;
|
|
181
|
+
const top = Math.max(1.5, model.thresholds.full * 1.5);
|
|
182
|
+
const lx = (x) => m.l + pw * Math.log(x / h.from) / Math.log(h.to / h.from);
|
|
183
|
+
const ly = (u) => m.t + ph * (1 - Math.min(u, top * 1.2) / top);
|
|
184
|
+
const path = (s) => {
|
|
185
|
+
let d = "";
|
|
186
|
+
let pen = false;
|
|
187
|
+
for (const [x, u] of s) {
|
|
188
|
+
if (u == null) {
|
|
189
|
+
pen = false;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
d += `${pen ? "L" : "M"}${lx(x).toFixed(1)} ${ly(u).toFixed(1)}`;
|
|
193
|
+
pen = true;
|
|
194
|
+
}
|
|
195
|
+
return d;
|
|
196
|
+
};
|
|
197
|
+
const xs = h.lines[0]?.envelope.map(([x]) => x) ?? [];
|
|
198
|
+
const selected = h.lines.find((l) => l.selected);
|
|
199
|
+
const roomy = W >= 480;
|
|
200
|
+
const tickList = ticks(h.from, h.to, roomy);
|
|
201
|
+
const labelled = (x) => roomy || Number.isInteger(Math.log10(x));
|
|
202
|
+
const near = (px) => {
|
|
203
|
+
let best = 0;
|
|
204
|
+
for (let i = 1; i < xs.length; i++) if (Math.abs(lx(xs[i]) - px) < Math.abs(lx(xs[best]) - px)) best = i;
|
|
205
|
+
return best;
|
|
206
|
+
};
|
|
207
|
+
const onMove = (e) => {
|
|
208
|
+
const r = e.currentTarget.ownerSVGElement.getBoundingClientRect();
|
|
209
|
+
setHover(near(e.clientX - r.left));
|
|
210
|
+
};
|
|
211
|
+
const onKey = (e) => {
|
|
212
|
+
const i = hover ?? near(lx(Math.min(h.to, Math.max(h.from, values.load))));
|
|
213
|
+
if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
|
|
214
|
+
e.preventDefault();
|
|
215
|
+
setHover(Math.max(0, Math.min(xs.length - 1, i + (e.key === "ArrowRight" ? 1 : -1))));
|
|
216
|
+
} else if (e.key === "Escape" && hover != null) {
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
setHover(null);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const area = (b) => {
|
|
222
|
+
const both = b.upper.flatMap(([x, u], i) => {
|
|
223
|
+
const v = b.lower[i][1];
|
|
224
|
+
return u == null || v == null ? [] : [[
|
|
225
|
+
x,
|
|
226
|
+
u,
|
|
227
|
+
v
|
|
228
|
+
]];
|
|
229
|
+
});
|
|
230
|
+
if (both.length < 2) return "";
|
|
231
|
+
const up = both.map(([x, u]) => `${lx(x).toFixed(1)} ${ly(u).toFixed(1)}`);
|
|
232
|
+
const down = both.map(([x, , v]) => `${lx(x).toFixed(1)} ${ly(v).toFixed(1)}`).reverse();
|
|
233
|
+
return `M${up.join("L")}L${down.join("L")}Z`;
|
|
234
|
+
};
|
|
235
|
+
const reaches = (r, x) => r && l0(r) ? multiples(r, model.searchMax) : multiple(x, model.searchMax);
|
|
236
|
+
const l0 = (r) => multiple(r.low, model.searchMax) !== multiple(r.high, model.searchMax);
|
|
237
|
+
const summary = h.lines.map((l) => `${lineName(l)} reaches the ${pct(model.thresholds.target)} target at ${reaches(l.targetRange, l.target)} and ${pct(model.thresholds.full)} at ${reaches(l.fullRange, l.full)}`).join("; ");
|
|
238
|
+
const loadX = lx(Math.min(h.to, Math.max(h.from, values.load)));
|
|
239
|
+
const hx = hover == null ? null : xs[hover];
|
|
240
|
+
const fromLeft = {
|
|
241
|
+
x: 0,
|
|
242
|
+
textAnchor: "start"
|
|
243
|
+
};
|
|
244
|
+
const fromRight = {
|
|
245
|
+
x: W,
|
|
246
|
+
textAnchor: "end"
|
|
247
|
+
};
|
|
248
|
+
/** A label beside a line at x: on the side it prefers if it fits, else the other, else against the nearer edge. */
|
|
249
|
+
const beside = (x, w, prefer, gap = 4) => {
|
|
250
|
+
const right = {
|
|
251
|
+
x: x + gap,
|
|
252
|
+
textAnchor: "start"
|
|
253
|
+
};
|
|
254
|
+
const left = {
|
|
255
|
+
x: x - gap,
|
|
256
|
+
textAnchor: "end"
|
|
257
|
+
};
|
|
258
|
+
const fitsRight = x + gap + w <= W;
|
|
259
|
+
const fitsLeft = x - gap - w >= 0;
|
|
260
|
+
if (prefer === "right" ? fitsRight : !fitsLeft && fitsRight) return right;
|
|
261
|
+
if (fitsLeft) return left;
|
|
262
|
+
return x < W / 2 ? fromLeft : fromRight;
|
|
263
|
+
};
|
|
264
|
+
/** A label centred on x, unless that passes an edge. */
|
|
265
|
+
const centred = (x, w) => x - w / 2 < 0 ? fromLeft : x + w / 2 > W ? fromRight : {
|
|
266
|
+
x,
|
|
267
|
+
textAnchor: "middle"
|
|
268
|
+
};
|
|
269
|
+
const shown = `shown: ${fmt(values.load)}×`;
|
|
270
|
+
/** A crossing's multiple, left of its dot where it fits. */
|
|
271
|
+
const mark = (t, x, y) => /* @__PURE__ */ jsx("text", {
|
|
272
|
+
...beside(x, measure(t, 600), "left", 6),
|
|
273
|
+
y,
|
|
274
|
+
className: "lm-mark",
|
|
275
|
+
children: t
|
|
276
|
+
});
|
|
277
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
278
|
+
className: "lm-card lm-headroom",
|
|
279
|
+
children: [
|
|
280
|
+
/* @__PURE__ */ jsx("h3", { children: title }),
|
|
281
|
+
h.lines.length > 1 && /* @__PURE__ */ jsxs("div", {
|
|
282
|
+
className: "lm-legend",
|
|
283
|
+
children: [h.lines.map((l) => /* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("b", {
|
|
284
|
+
className: "lm-key",
|
|
285
|
+
style: { background: scenarioColor(model, l.label) }
|
|
286
|
+
}), lineName(l)] }, lineName(l))), selected && /* @__PURE__ */ jsxs("span", { children: ["thin lines: each component of ", lineName(selected)] })]
|
|
287
|
+
}),
|
|
288
|
+
/* @__PURE__ */ jsxs("div", {
|
|
289
|
+
className: "lm-chart",
|
|
290
|
+
ref: wrap,
|
|
291
|
+
role: "slider",
|
|
292
|
+
"aria-label": `Utilization over the load multiple. ${summary}.`,
|
|
293
|
+
"aria-valuemin": h.from,
|
|
294
|
+
"aria-valuemax": h.to,
|
|
295
|
+
"aria-valuenow": hx ?? values.load,
|
|
296
|
+
"aria-valuetext": hx == null ? `${fmt(values.load)}×` : `${fmt(hx)}×: ${h.lines.map((l) => `${lineName(l)} ${l.envelope[hover][1] == null ? "off" : pct(l.envelope[hover][1])}`).join(", ")}`,
|
|
297
|
+
tabIndex: 0,
|
|
298
|
+
onKeyDown: onKey,
|
|
299
|
+
onBlur: () => setHover(null),
|
|
300
|
+
children: [/* @__PURE__ */ jsxs("svg", {
|
|
301
|
+
width: W,
|
|
302
|
+
height: H,
|
|
303
|
+
viewBox: `0 0 ${W} ${H}`,
|
|
304
|
+
"aria-hidden": "true",
|
|
305
|
+
children: [
|
|
306
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx("clipPath", {
|
|
307
|
+
id: clip,
|
|
308
|
+
children: /* @__PURE__ */ jsx("rect", {
|
|
309
|
+
x: m.l,
|
|
310
|
+
y: m.t,
|
|
311
|
+
width: pw,
|
|
312
|
+
height: ph + 2
|
|
313
|
+
})
|
|
314
|
+
}) }),
|
|
315
|
+
[
|
|
316
|
+
0,
|
|
317
|
+
model.thresholds.target,
|
|
318
|
+
model.thresholds.full
|
|
319
|
+
].map((u) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
|
|
320
|
+
x1: m.l,
|
|
321
|
+
x2: W - m.r,
|
|
322
|
+
y1: ly(u),
|
|
323
|
+
y2: ly(u),
|
|
324
|
+
stroke: "var(--lm-line)"
|
|
325
|
+
}), /* @__PURE__ */ jsx("text", {
|
|
326
|
+
x: m.l - 6,
|
|
327
|
+
y: ly(u) + 4,
|
|
328
|
+
textAnchor: "end",
|
|
329
|
+
className: "lm-axis",
|
|
330
|
+
children: pct(u)
|
|
331
|
+
})] }, u)),
|
|
332
|
+
/* @__PURE__ */ jsx("text", {
|
|
333
|
+
x: W - m.r,
|
|
334
|
+
y: ly(model.thresholds.target) - 5,
|
|
335
|
+
textAnchor: "end",
|
|
336
|
+
className: "lm-axis",
|
|
337
|
+
children: "target"
|
|
338
|
+
}),
|
|
339
|
+
tickList.map((x) => {
|
|
340
|
+
const label = `${fmt(x)}×`;
|
|
341
|
+
const date = dated && x > 1 ? when(model, x) : "";
|
|
342
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
343
|
+
className: "lm-axis",
|
|
344
|
+
children: [/* @__PURE__ */ jsx("line", {
|
|
345
|
+
x1: lx(x),
|
|
346
|
+
x2: lx(x),
|
|
347
|
+
y1: m.t + ph,
|
|
348
|
+
y2: m.t + ph + 4,
|
|
349
|
+
stroke: "var(--lm-line)"
|
|
350
|
+
}), labelled(x) && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("text", {
|
|
351
|
+
...centred(lx(x), measure(label)),
|
|
352
|
+
y: m.t + ph + 16,
|
|
353
|
+
children: label
|
|
354
|
+
}), date && /* @__PURE__ */ jsx("text", {
|
|
355
|
+
...centred(lx(x), measure(date)),
|
|
356
|
+
y: m.t + ph + 30,
|
|
357
|
+
children: date
|
|
358
|
+
})] })]
|
|
359
|
+
}, x);
|
|
360
|
+
}),
|
|
361
|
+
/* @__PURE__ */ jsxs("g", {
|
|
362
|
+
clipPath: `url(#${clip})`,
|
|
363
|
+
children: [
|
|
364
|
+
[...h.lines].sort((a, b) => Number(a.selected) - Number(b.selected)).map((l) => l.band ? /* @__PURE__ */ jsx("path", {
|
|
365
|
+
"data-band": lineName(l),
|
|
366
|
+
d: area(l.band),
|
|
367
|
+
fill: scenarioColor(model, l.label),
|
|
368
|
+
fillOpacity: l.selected ? .2 : .08
|
|
369
|
+
}, lineName(l)) : null),
|
|
370
|
+
selected?.components.map((c) => /* @__PURE__ */ jsx("path", {
|
|
371
|
+
d: path(c.points),
|
|
372
|
+
fill: "none",
|
|
373
|
+
stroke: "var(--lm-muted)",
|
|
374
|
+
strokeOpacity: ".55",
|
|
375
|
+
strokeWidth: "1"
|
|
376
|
+
}, c.id)),
|
|
377
|
+
[...h.lines].sort((a, b) => Number(a.selected) - Number(b.selected)).map((l) => /* @__PURE__ */ jsx("path", {
|
|
378
|
+
"data-line": lineName(l),
|
|
379
|
+
d: path(l.envelope),
|
|
380
|
+
fill: "none",
|
|
381
|
+
stroke: scenarioColor(model, l.label),
|
|
382
|
+
strokeWidth: "2",
|
|
383
|
+
strokeLinejoin: "round",
|
|
384
|
+
strokeLinecap: "round"
|
|
385
|
+
}, lineName(l)))
|
|
386
|
+
]
|
|
387
|
+
}),
|
|
388
|
+
/* @__PURE__ */ jsx("line", {
|
|
389
|
+
x1: loadX,
|
|
390
|
+
x2: loadX,
|
|
391
|
+
y1: m.t,
|
|
392
|
+
y2: m.t + ph,
|
|
393
|
+
stroke: "var(--lm-fg)",
|
|
394
|
+
strokeOpacity: ".45"
|
|
395
|
+
}),
|
|
396
|
+
/* @__PURE__ */ jsx("text", {
|
|
397
|
+
...beside(loadX, measure(shown), "right"),
|
|
398
|
+
y: m.t + 10,
|
|
399
|
+
className: "lm-axis",
|
|
400
|
+
children: shown
|
|
401
|
+
}),
|
|
402
|
+
h.lines.flatMap((l) => [[
|
|
403
|
+
"target",
|
|
404
|
+
l.targetRange,
|
|
405
|
+
model.thresholds.target
|
|
406
|
+
], [
|
|
407
|
+
"full",
|
|
408
|
+
l.fullRange,
|
|
409
|
+
model.thresholds.full
|
|
410
|
+
]].map(([kind, r, u]) => {
|
|
411
|
+
if (!l.band || !r || !Number.isFinite(r.low) || r.low > h.to) return null;
|
|
412
|
+
const [x1, x2] = [lx(Math.max(h.from, r.low)), lx(Math.min(h.to, r.high))];
|
|
413
|
+
const y = ly(u);
|
|
414
|
+
return /* @__PURE__ */ jsxs("g", {
|
|
415
|
+
"data-range": kind,
|
|
416
|
+
"data-scenario": lineName(l),
|
|
417
|
+
"data-low": r.low,
|
|
418
|
+
"data-high": r.high,
|
|
419
|
+
stroke: scenarioColor(model, l.label),
|
|
420
|
+
strokeWidth: l.selected ? 3 : 2,
|
|
421
|
+
strokeOpacity: l.selected ? 1 : .6,
|
|
422
|
+
children: [
|
|
423
|
+
/* @__PURE__ */ jsx("line", {
|
|
424
|
+
x1,
|
|
425
|
+
x2,
|
|
426
|
+
y1: y,
|
|
427
|
+
y2: y
|
|
428
|
+
}),
|
|
429
|
+
/* @__PURE__ */ jsx("line", {
|
|
430
|
+
x1,
|
|
431
|
+
x2: x1,
|
|
432
|
+
y1: y - 5,
|
|
433
|
+
y2: y + 5
|
|
434
|
+
}),
|
|
435
|
+
Number.isFinite(r.high) && r.high <= h.to && /* @__PURE__ */ jsx("line", {
|
|
436
|
+
x1: x2,
|
|
437
|
+
x2,
|
|
438
|
+
y1: y - 5,
|
|
439
|
+
y2: y + 5
|
|
440
|
+
})
|
|
441
|
+
]
|
|
442
|
+
}, `${lineName(l)}/${kind}/range`);
|
|
443
|
+
})),
|
|
444
|
+
h.lines.flatMap((l) => [[
|
|
445
|
+
"target",
|
|
446
|
+
l.target,
|
|
447
|
+
l.targetRange,
|
|
448
|
+
model.thresholds.target
|
|
449
|
+
], [
|
|
450
|
+
"full",
|
|
451
|
+
l.full,
|
|
452
|
+
l.fullRange,
|
|
453
|
+
model.thresholds.full
|
|
454
|
+
]].map(([kind, x, r, u]) => x != null && Number.isFinite(x) && x >= h.from && x <= h.to ? /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("circle", {
|
|
455
|
+
"data-crossing": kind,
|
|
456
|
+
"data-scenario": lineName(l),
|
|
457
|
+
"data-multiple": x,
|
|
458
|
+
cx: lx(x),
|
|
459
|
+
cy: ly(u),
|
|
460
|
+
r: "4",
|
|
461
|
+
fill: scenarioColor(model, l.label),
|
|
462
|
+
stroke: "var(--lm-surface)",
|
|
463
|
+
strokeWidth: "2"
|
|
464
|
+
}), l.selected && mark(r && l0(r) ? multiples(r, model.searchMax, true) : multiple(x, model.searchMax), lx(r && l0(r) ? Math.max(h.from, r.low) : x), ly(u) - 8)] }, `${lineName(l)}/${kind}`) : null)),
|
|
465
|
+
hx != null && /* @__PURE__ */ jsx("line", {
|
|
466
|
+
x1: lx(hx),
|
|
467
|
+
x2: lx(hx),
|
|
468
|
+
y1: m.t,
|
|
469
|
+
y2: m.t + ph,
|
|
470
|
+
stroke: "var(--lm-fg)",
|
|
471
|
+
strokeOpacity: ".8"
|
|
472
|
+
}),
|
|
473
|
+
/* @__PURE__ */ jsx("rect", {
|
|
474
|
+
x: m.l,
|
|
475
|
+
y: m.t,
|
|
476
|
+
width: pw,
|
|
477
|
+
height: ph,
|
|
478
|
+
fill: "transparent",
|
|
479
|
+
onPointerMove: onMove,
|
|
480
|
+
onPointerDown: onMove,
|
|
481
|
+
onPointerLeave: () => setHover(null)
|
|
482
|
+
})
|
|
483
|
+
]
|
|
484
|
+
}), hover != null && hx != null && /* @__PURE__ */ jsxs("div", {
|
|
485
|
+
className: "lm-tip",
|
|
486
|
+
role: "status",
|
|
487
|
+
ref: tip,
|
|
488
|
+
style: {
|
|
489
|
+
left: lx(hx) + 10,
|
|
490
|
+
top: m.t
|
|
491
|
+
},
|
|
492
|
+
children: [
|
|
493
|
+
/* @__PURE__ */ jsxs("b", { children: [
|
|
494
|
+
fmt(hx),
|
|
495
|
+
"×",
|
|
496
|
+
when(model, hx) && ` · ${when(model, hx)}`
|
|
497
|
+
] }),
|
|
498
|
+
h.lines.map((l) => /* @__PURE__ */ jsxs("span", { children: [
|
|
499
|
+
/* @__PURE__ */ jsx("b", {
|
|
500
|
+
className: "lm-key",
|
|
501
|
+
style: { background: scenarioColor(model, l.label) }
|
|
502
|
+
}),
|
|
503
|
+
/* @__PURE__ */ jsx("strong", { children: l.envelope[hover][1] == null ? "off" : pct(l.envelope[hover][1]) }),
|
|
504
|
+
" ",
|
|
505
|
+
lineName(l)
|
|
506
|
+
] }, lineName(l))),
|
|
507
|
+
selected?.components.map((c) => /* @__PURE__ */ jsxs("span", {
|
|
508
|
+
className: "lm-sub",
|
|
509
|
+
children: [
|
|
510
|
+
/* @__PURE__ */ jsx("strong", { children: c.points[hover][1] == null ? "off" : pct(c.points[hover][1]) }),
|
|
511
|
+
" ",
|
|
512
|
+
c.name
|
|
513
|
+
]
|
|
514
|
+
}, c.id))
|
|
515
|
+
]
|
|
516
|
+
})]
|
|
517
|
+
})
|
|
518
|
+
]
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
export { HeadroomChart as n, useComparison as r, Compare as t };
|
package/dist/source.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as LoadmapProps } from "./Loadmap-
|
|
1
|
+
import { a as LoadmapProps } from "./Loadmap-CyxcmVoc.js";
|
|
2
2
|
import { CompileOptions } from "@loadmap/dsl";
|
|
3
3
|
export interface LoadmapSourceProps extends Omit<LoadmapProps<any>, 'model' | 'view'> {
|
|
4
4
|
/** The `.loadmap` text. Compiled again when its tokens change: spaces, line breaks and comments change nothing. */
|
package/dist/source.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as injectStyles, n as Loadmap, o as usePageTheme } from "./Loadmap-CM8HshXp.js";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { compile, formatDiagnostic, loadCatalogFor, loadedCatalog, needsCatalog, sharedValues } from "@loadmap/dsl";
|
|
@@ -53,6 +53,9 @@ function LoadmapSource({ source, name = "input.loadmap", functions, files, path,
|
|
|
53
53
|
}, [ref]);
|
|
54
54
|
const set = Object.fromEntries(Object.entries(props).filter(([, v]) => v !== void 0));
|
|
55
55
|
const lines = def && [...assumptions ?? [], ...def.options.assumptions];
|
|
56
|
+
const page = def ? pageOptions(def.options) : {};
|
|
57
|
+
if ("fullScreen" in set) delete page.panels;
|
|
58
|
+
if ("fullScreenMode" in set) delete page.chrome;
|
|
56
59
|
return /* @__PURE__ */ jsxs(Fragment, { children: [compiled && !compiled.r.ok && /* @__PURE__ */ jsx(Problems, {
|
|
57
60
|
theme,
|
|
58
61
|
stale: def != null,
|
|
@@ -60,7 +63,7 @@ function LoadmapSource({ source, name = "input.loadmap", functions, files, path,
|
|
|
60
63
|
}), def && /* @__PURE__ */ jsx(Loadmap, {
|
|
61
64
|
model: def.model,
|
|
62
65
|
view: def.view,
|
|
63
|
-
...
|
|
66
|
+
...page,
|
|
64
67
|
...set,
|
|
65
68
|
ref: handle,
|
|
66
69
|
initial: sharedValues(def.model, drawn.current.values),
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { l as stepSeconds } from "./camera-RqbxjjVv.js";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// \0rolldown/runtime.js
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __exportAll = (all, no_symbols) => {
|
|
7
|
+
let target = {};
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
// src/story.tsx
|
|
16
|
+
var story_exports = /* @__PURE__ */ __exportAll({ Story: () => Story });
|
|
17
|
+
/**
|
|
18
|
+
* The model's story, a step at a time: the step's text, where it is, play, back and next. ← and → move through it
|
|
19
|
+
* while the bar has the keyboard focus (the sliders keep their own arrows). The text keeps the room of the longest
|
|
20
|
+
* step, so stepping through it never moves what is below. While it plays, the bar shows the step played from the
|
|
21
|
+
* moment the camera heads for it, before its values change.
|
|
22
|
+
*/
|
|
23
|
+
function Story({ lm }) {
|
|
24
|
+
const bar = useRef(null);
|
|
25
|
+
const { story } = lm.model;
|
|
26
|
+
if (!story.length) return null;
|
|
27
|
+
const i = lm.cue?.step ?? lm.step;
|
|
28
|
+
const last = story.length - 1;
|
|
29
|
+
const go = (to) => {
|
|
30
|
+
const next = Math.max(0, Math.min(last, to));
|
|
31
|
+
if (next !== i || lm.storyPlaying) lm.setStep(next);
|
|
32
|
+
};
|
|
33
|
+
const keys = (e) => {
|
|
34
|
+
if (e.key === "ArrowRight") go(i == null ? 0 : i + 1);
|
|
35
|
+
else if (e.key === "ArrowLeft" && i != null) go(i - 1);
|
|
36
|
+
else return;
|
|
37
|
+
e.preventDefault();
|
|
38
|
+
};
|
|
39
|
+
const playing = lm.storyPlaying;
|
|
40
|
+
return /* @__PURE__ */ jsxs("fieldset", {
|
|
41
|
+
className: "lm-story",
|
|
42
|
+
onKeyDown: keys,
|
|
43
|
+
ref: bar,
|
|
44
|
+
tabIndex: -1,
|
|
45
|
+
"data-playing": playing || void 0,
|
|
46
|
+
children: [
|
|
47
|
+
/* @__PURE__ */ jsx("legend", { children: "Story" }),
|
|
48
|
+
/* @__PURE__ */ jsx("span", {
|
|
49
|
+
className: "lm-sr",
|
|
50
|
+
"aria-live": "polite",
|
|
51
|
+
children: i == null ? `A walk through this model in ${story.length} steps.` : `${i + 1} of ${story.length}. ${story[i].text}${lm.stepChanged ? " You changed the values since." : ""}`
|
|
52
|
+
}),
|
|
53
|
+
/* @__PURE__ */ jsxs("p", {
|
|
54
|
+
"aria-hidden": "true",
|
|
55
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
56
|
+
"data-shown": i == null || void 0,
|
|
57
|
+
children: [
|
|
58
|
+
"A walk through this model in ",
|
|
59
|
+
story.length,
|
|
60
|
+
" steps."
|
|
61
|
+
]
|
|
62
|
+
}), story.map((st, k) => /* @__PURE__ */ jsxs("span", {
|
|
63
|
+
"data-shown": k === i || void 0,
|
|
64
|
+
children: [
|
|
65
|
+
/* @__PURE__ */ jsxs("b", { children: [
|
|
66
|
+
k + 1,
|
|
67
|
+
" of ",
|
|
68
|
+
story.length
|
|
69
|
+
] }),
|
|
70
|
+
" ",
|
|
71
|
+
st.text,
|
|
72
|
+
/* @__PURE__ */ jsx("em", {
|
|
73
|
+
"data-shown": k === i && lm.stepChanged || void 0,
|
|
74
|
+
children: " You changed the values since."
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
}, k))]
|
|
78
|
+
}),
|
|
79
|
+
i != null && /* @__PURE__ */ jsx("span", {
|
|
80
|
+
className: "lm-story-progress",
|
|
81
|
+
"aria-hidden": "true",
|
|
82
|
+
children: story.map((st, k) => /* @__PURE__ */ jsx("i", {
|
|
83
|
+
"data-state": k < i ? "done" : k === i ? "now" : void 0,
|
|
84
|
+
style: k === i ? { "--lm-step": `${lm.cue?.seconds ?? stepSeconds(st, lm.engine.transition)}s` } : void 0
|
|
85
|
+
}, k === i ? `${k}-${playing}` : k))
|
|
86
|
+
}),
|
|
87
|
+
/* @__PURE__ */ jsxs("span", {
|
|
88
|
+
className: "lm-story-nav",
|
|
89
|
+
children: [
|
|
90
|
+
/* @__PURE__ */ jsx("button", {
|
|
91
|
+
type: "button",
|
|
92
|
+
onClick: () => lm.setStoryPlaying(!playing),
|
|
93
|
+
"aria-pressed": playing,
|
|
94
|
+
children: playing ? "❚❚ Pause" : "▶ Play"
|
|
95
|
+
}),
|
|
96
|
+
i != null && /* @__PURE__ */ jsx("button", {
|
|
97
|
+
type: "button",
|
|
98
|
+
onClick: () => go(i - 1),
|
|
99
|
+
"aria-disabled": i === 0,
|
|
100
|
+
children: "Back"
|
|
101
|
+
}),
|
|
102
|
+
/* @__PURE__ */ jsx("button", {
|
|
103
|
+
type: "button",
|
|
104
|
+
onClick: () => go(i == null ? 0 : i + 1),
|
|
105
|
+
"aria-disabled": i === last,
|
|
106
|
+
children: i == null ? "Start" : "Next"
|
|
107
|
+
}),
|
|
108
|
+
i != null && lm.stepChanged && /* @__PURE__ */ jsx("button", {
|
|
109
|
+
type: "button",
|
|
110
|
+
onClick: () => {
|
|
111
|
+
lm.setStep(i);
|
|
112
|
+
bar.current?.focus();
|
|
113
|
+
},
|
|
114
|
+
children: "Show again"
|
|
115
|
+
}),
|
|
116
|
+
i != null && /* @__PURE__ */ jsx("button", {
|
|
117
|
+
type: "button",
|
|
118
|
+
onClick: () => lm.setStep(null),
|
|
119
|
+
"aria-label": "Leave the story",
|
|
120
|
+
children: "Done"
|
|
121
|
+
})
|
|
122
|
+
]
|
|
123
|
+
})
|
|
124
|
+
]
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
export { story_exports as n, Story as t };
|