@loadmap/react 0.30.0 → 0.31.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.
@@ -1,5 +1,5 @@
1
1
  import { compare, headroom, sourceText } from "@loadmap/core";
2
- import { capital, compact, fmt, monthOf, multiple, multiples, pct, secs } from "@loadmap/core/format";
2
+ import { capital, compact, duration, fmt, monthOf, multiple, multiples, pct, secs } from "@loadmap/core/format";
3
3
  import { anchor, directionOf, labelsAt, layout, legPath, localElk, pointAt, structureKey } from "@loadmap/layout";
4
4
  import { Suspense, lazy, memo, useCallback, useEffect, useId, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
@@ -211,7 +211,7 @@ function stepDetail(a, b, components) {
211
211
  }).filter(Boolean).join(" · ");
212
212
  }
213
213
  // src/Diagram.tsx
214
- const Detail = lazy(() => import("./later-CWI3R8Sh.js").then((m) => ({ default: m.Detail })));
214
+ const Detail = lazy(() => import("./later-DMXCwr0t.js").then((m) => ({ default: m.Detail })));
215
215
  const STATE_STROKE = {
216
216
  off: "var(--lm-line)",
217
217
  ok: "var(--lm-ok)",
@@ -809,30 +809,40 @@ function RateStrokes({ lm, scene }) {
809
809
  const max = Math.max(1e-9, ...Object.values(ev.flows));
810
810
  const out = [];
811
811
  for (const f of Object.keys(flows)) {
812
- const seq = [scene.flowFrom[f], ...(ev.routes[f] ?? []).map((s) => scene.stageNode[s])].filter((n, i, a) => n && n !== a[i - 1]);
813
- const rate = ev.flows[f] ?? 0;
814
- const legs = seq.slice(1).map((to, i) => [
815
- seq[i],
816
- to,
817
- rate
818
- ]);
819
- const last = (ev.routes[f] ?? []).at(-1);
820
- const st = last ? ev.stages[last] : void 0;
821
- if (st?.kind === "fanout") for (const b of st.to[f] ?? []) legs.push([
822
- scene.stageNode[last],
823
- scene.stageNode[b.stage],
824
- rate * b.share
825
- ]);
812
+ const legs = [];
813
+ for (const way of ev.paths[f] ?? []) {
814
+ const seq = [scene.flowFrom[f], ...way.stages.map((s) => scene.stageNode[s])].filter((n, i, a) => n && n !== a[i - 1]);
815
+ const rate = (ev.flows[f] ?? 0) * way.share;
816
+ for (const [i, to] of seq.slice(1).entries()) legs.push([
817
+ seq[i],
818
+ to,
819
+ rate
820
+ ]);
821
+ const last = way.stages.at(-1);
822
+ const st = last ? ev.stages[last] : void 0;
823
+ if (st?.kind === "fanout") for (const b of st.to[f] ?? []) legs.push([
824
+ scene.stageNode[last],
825
+ scene.stageNode[b.stage],
826
+ rate * b.share
827
+ ]);
828
+ }
829
+ const on = /* @__PURE__ */ new Map();
826
830
  for (const [from, to, r] of legs) {
827
831
  const e = scene.edges.find((x) => x.from === from && x.to === to);
828
- if (e) out.push(/* @__PURE__ */ jsx("path", {
829
- d: pathOf(e.points),
830
- fill: "none",
831
- stroke: tokenColor(flows[f].color),
832
- strokeOpacity: ".45",
833
- strokeWidth: 1.5 + 6 * Math.min(r, max) / max
834
- }, `${f}:${e.id}`));
832
+ if (!e) continue;
833
+ const had = on.get(e.id);
834
+ on.set(e.id, {
835
+ points: e.points,
836
+ r: (had?.r ?? 0) + r
837
+ });
835
838
  }
839
+ for (const [id, { points, r }] of on) out.push(/* @__PURE__ */ jsx("path", {
840
+ d: pathOf(points),
841
+ fill: "none",
842
+ stroke: tokenColor(flows[f].color),
843
+ strokeOpacity: ".45",
844
+ strokeWidth: 1.5 + 6 * Math.min(r, max) / max
845
+ }, `${f}:${id}`));
836
846
  }
837
847
  return /* @__PURE__ */ jsx("g", { children: out });
838
848
  }
@@ -1935,7 +1945,7 @@ function Meters({ lm }) {
1935
1945
  const flowLabel = (f) => model.def.flows[f]?.label ?? f;
1936
1946
  const items = [];
1937
1947
  for (const s of Object.values(ev.stages)) {
1938
- if (s.kind === "queue") for (const f of model.flowIds.filter((x) => ev.routes[x]?.includes(s.id))) {
1948
+ if (s.kind === "queue") for (const f of model.flowIds.filter((x) => ev.paths[x]?.some((p) => p.stages.includes(s.id)))) {
1939
1949
  const q = sim.queue(s.id, f);
1940
1950
  const rules = ev.overload[f] ?? {};
1941
1951
  items.push({
@@ -1978,7 +1988,7 @@ function Meters({ lm }) {
1978
1988
  label: `answered at ${s.label} /s (${pct(s.hit)} hits)`,
1979
1989
  state: "ok"
1980
1990
  });
1981
- if ((s.kind === "pass" || s.kind === "limit" || s.kind === "cache") && sim.shed(s.id) > 0) items.push({
1991
+ if ((s.kind === "pass" || s.kind === "limit" || s.kind === "cache" || s.kind === "split") && sim.shed(s.id) > 0) items.push({
1982
1992
  key: `${s.id}/shed`,
1983
1993
  value: pct(sim.shed(s.id)),
1984
1994
  label: `rejected at ${s.label}`,
@@ -2002,6 +2012,24 @@ function Meters({ lm }) {
2002
2012
  state: r.failed > .005 ? "over" : "ok"
2003
2013
  });
2004
2014
  }
2015
+ for (const f of model.flowIds) {
2016
+ const l = ev.latency[f];
2017
+ if (!l) continue;
2018
+ const scenario = model.scenarioOf(lm.values)?.label;
2019
+ const goal = model.expectations.find((e) => e.flow === f && e.p99 != null && (e.scenario == null || e.scenario === scenario) && (e.target == null || lm.values.load <= e.target))?.p99;
2020
+ items.push({
2021
+ key: `${f}/p99`,
2022
+ value: duration(l.p99),
2023
+ label: `${flowLabel(f)} p99`,
2024
+ state: !Number.isFinite(l.p99) || goal != null && l.p99 > goal ? "over" : "ok"
2025
+ });
2026
+ if (l.timedOut != null) items.push({
2027
+ key: `${f}/late`,
2028
+ value: pct(l.timedOut),
2029
+ label: `${flowLabel(f)} timed out`,
2030
+ state: l.timedOut > .005 ? "over" : l.timedOut > 0 ? "warn" : "ok"
2031
+ });
2032
+ }
2005
2033
  return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Live" }), /* @__PURE__ */ jsx("div", {
2006
2034
  className: "lm-meters",
2007
2035
  children: items.map((m) => /* @__PURE__ */ jsxs("div", {
@@ -3015,7 +3043,7 @@ var Engine = class {
3015
3043
  return this.colors[c] || c;
3016
3044
  }
3017
3045
  outcomeColor(outcome) {
3018
- if (outcome === "dropped" || outcome === "rejected") return this.colors.drop || "#b7392e";
3046
+ if (outcome === "dropped" || outcome === "rejected" || outcome === "timedout") return this.colors.drop || "#b7392e";
3019
3047
  if (outcome === "superseded" || outcome === "unread") return this.colors.muted || "#5d6d7c";
3020
3048
  return this.colors.ok || "#2a7f5a";
3021
3049
  }
@@ -3725,8 +3753,8 @@ function canvasMeasure(fontFamily) {
3725
3753
  };
3726
3754
  }
3727
3755
  // src/Loadmap.tsx
3728
- const Dock = lazy(() => import("./later-CWI3R8Sh.js").then((m) => ({ default: m.Dock })));
3729
- const VerdictLine = lazy(() => import("./later-CWI3R8Sh.js").then((m) => ({ default: m.VerdictLine })));
3756
+ const Dock = lazy(() => import("./later-DMXCwr0t.js").then((m) => ({ default: m.Dock })));
3757
+ const VerdictLine = lazy(() => import("./later-DMXCwr0t.js").then((m) => ({ default: m.VerdictLine })));
3730
3758
  /** What the page's own switch says, on `<html>`: `data-theme`, or a `dark` or `light` class; null when it says nothing. */
3731
3759
  function pageTheme() {
3732
3760
  if (typeof document === "undefined") return null;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as useComparison, D as workerElk, O as Diagram, S as scenarioColor, _ as Verdict, a as usePageTheme, b as HeadroomChart, c as injectStyles, f as Controls, g as Meters, h as LoadRange, i as handleOf, l as Story, m as LoadBar, n as Loadmap, o as useLoadmap, p as Limits, r as LoadmapRoot, s as LOADMAP_CSS, t as LOADMAP_PANELS, u as Assumptions, x as Scenarios, y as Compare } from "./Loadmap-epsQJpUL.js";
1
+ import { C as useComparison, D as workerElk, O as Diagram, S as scenarioColor, _ as Verdict, a as usePageTheme, b as HeadroomChart, c as injectStyles, f as Controls, g as Meters, h as LoadRange, i as handleOf, l as Story, m as LoadBar, n as Loadmap, o as useLoadmap, p as Limits, r as LoadmapRoot, s as LOADMAP_CSS, t as LOADMAP_PANELS, u as Assumptions, x as Scenarios, y as Compare } from "./Loadmap-ffFuZ7cp.js";
2
2
  import { fitLinear } from "@loadmap/core/calibrate";
3
3
  import { compact, fmt, multiple, pct, secs } from "@loadmap/core/format";
4
4
  import { MEASURES, fromSnapshot, originText, parseSnapshot, summarize } from "@loadmap/core/measure";
@@ -1,4 +1,4 @@
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-epsQJpUL.js";
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-ffFuZ7cp.js";
2
2
  import { reach } from "@loadmap/core";
3
3
  import { compact, fmt, multiple, multiples, pct } from "@loadmap/core/format";
4
4
  import { useEffect, useLayoutEffect, useRef, useState } from "react";
@@ -418,6 +418,7 @@ function Detail({ lm, scene, id, board, detailId }) {
418
418
  cap.unit,
419
419
  cap.within ? ` ${plusMinus(cap)}` : ""
420
420
  ] }),
421
+ c.held && heldText(model, c.held) && /* @__PURE__ */ jsx("span", { children: heldText(model, c.held) }),
421
422
  /* @__PURE__ */ jsxs("span", {
422
423
  className: "lm-sub",
423
424
  children: [
@@ -480,6 +481,15 @@ function Detail({ lm, scene, id, board, detailId }) {
480
481
  ]
481
482
  });
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
+ }
483
493
  /** What a box's building blocks do at these values: pods running, cache answers, what a stage turns away. */
484
494
  function blocks(lm, n) {
485
495
  const out = [];
@@ -487,7 +497,7 @@ function blocks(lm, n) {
487
497
  const s = lm.ev.stages[id];
488
498
  if (s?.kind === "workers" && s.autoscale) out.push(`${s.running} of ${s.pods} pods running, each held near ${pct(s.autoscale.target)}`);
489
499
  if (s?.kind === "cache") out.push(`${pct(s.hit)} answered here`);
490
- if ((s?.kind === "pass" || s?.kind === "limit" || s?.kind === "cache") && s.shed > 0) out.push(`${pct(s.shed)} of what reaches it turned away`);
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`);
491
501
  }
492
502
  return out;
493
503
  }
package/dist/source.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as usePageTheme, c as injectStyles, n as Loadmap } from "./Loadmap-epsQJpUL.js";
1
+ import { a as usePageTheme, c as injectStyles, n as Loadmap } from "./Loadmap-ffFuZ7cp.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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loadmap/react",
3
- "version": "0.30.0",
3
+ "version": "0.31.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.30.0",
43
- "@loadmap/dsl": "0.30.0",
44
- "@loadmap/sim": "0.30.0",
45
- "@loadmap/layout": "0.30.0",
42
+ "@loadmap/core": "0.31.0",
43
+ "@loadmap/dsl": "0.31.0",
44
+ "@loadmap/sim": "0.31.0",
45
+ "@loadmap/layout": "0.31.0",
46
46
  "elkjs": "^0.12.1"
47
47
  },
48
48
  "peerDependencies": {