@graphty/graphty-element 2.5.2 → 2.6.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.
Files changed (135) hide show
  1. package/dist/ai.js +3 -3
  2. package/dist/catalog.d.ts +16 -0
  3. package/dist/catalog.js +34 -32
  4. package/dist/chunks/{AiManager-CrbvKdEK.js → AiManager-4iQpsJW1.js} +4 -4
  5. package/dist/chunks/{DataSource-qU-nLhXN.js → DataSource-BL2UzPff.js} +2 -2
  6. package/dist/chunks/GraphSession-BhuHSXIo.js +12819 -0
  7. package/dist/chunks/{GraphtyLogger-DOTwCiMR.js → GraphtyLogger-B_O67a6c.js} +1 -1
  8. package/dist/chunks/{VoiceInputAdapter-D4NrRL_1.js → VoiceInputAdapter-Cc6mHXTI.js} +1 -1
  9. package/dist/chunks/{XRPivotCameraController-Uqa47vmo.js → XRPivotCameraController-BLa89LXn.js} +2 -2
  10. package/dist/chunks/{algorithms-D-ab-Auu.js → algorithms-BJ6DQMOe.js} +931 -781
  11. package/dist/chunks/{capability-check-Vw3IcqiE.js → capability-check-Am2zliFj.js} +1 -1
  12. package/dist/chunks/{detect-B4Qrw976.js → detect-fyuVnlCT.js} +1 -1
  13. package/dist/chunks/{format-detection-r2IfNFXO.js → format-detection-BHwrAVzW.js} +1 -1
  14. package/dist/chunks/{index-J9MgLio9.js → index-BkBLbvui.js} +2691 -2434
  15. package/dist/chunks/optionsFromZod-CKMYSwTz.js +3636 -0
  16. package/dist/chunks/{paletteRegistry-Kt-6CeoN.js → paletteRegistry-BCFSwJGK.js} +224 -189
  17. package/dist/chunks/parse-BMTqt4SS.js +3658 -0
  18. package/dist/chunks/{types-C_c53VgR.js → types-DFchv4Ny.js} +4 -1
  19. package/dist/custom-elements.json +1 -1
  20. package/dist/extend.d.ts +10 -8
  21. package/dist/extend.js +6 -6
  22. package/dist/graphty-catalog.json +75 -38
  23. package/dist/graphty.bundle.js +55368 -48970
  24. package/dist/graphty.js +19 -19
  25. package/dist/index.d.ts +1 -1
  26. package/dist/logging.js +2 -2
  27. package/dist/schema.d.ts +15 -1
  28. package/dist/schema.js +1 -1
  29. package/dist/session.d.ts +30 -7
  30. package/dist/session.js +40 -37
  31. package/dist/src/Graph.d.ts +35 -7
  32. package/dist/src/acceleration/types.d.ts +79 -43
  33. package/dist/src/algorithms/Algorithm.d.ts +52 -4
  34. package/dist/src/algorithms/BFSAlgorithm.d.ts +3 -0
  35. package/dist/src/algorithms/BellmanFordAlgorithm.d.ts +3 -0
  36. package/dist/src/algorithms/BetweennessCentralityAlgorithm.d.ts +3 -0
  37. package/dist/src/algorithms/BipartiteMatchingAlgorithm.d.ts +3 -0
  38. package/dist/src/algorithms/ClosenessCentralityAlgorithm.d.ts +3 -0
  39. package/dist/src/algorithms/ConnectedComponentsAlgorithm.d.ts +4 -1
  40. package/dist/src/algorithms/DFSAlgorithm.d.ts +3 -0
  41. package/dist/src/algorithms/DegreeAlgorithm.d.ts +3 -0
  42. package/dist/src/algorithms/DijkstraAlgorithm.d.ts +6 -0
  43. package/dist/src/algorithms/EigenvectorCentralityAlgorithm.d.ts +2 -0
  44. package/dist/src/algorithms/FloydWarshallAlgorithm.d.ts +3 -0
  45. package/dist/src/algorithms/GirvanNewmanAlgorithm.d.ts +3 -0
  46. package/dist/src/algorithms/HITSAlgorithm.d.ts +3 -0
  47. package/dist/src/algorithms/KCoreAlgorithm.d.ts +3 -0
  48. package/dist/src/algorithms/KatzCentralityAlgorithm.d.ts +3 -0
  49. package/dist/src/algorithms/KruskalAlgorithm.d.ts +4 -1
  50. package/dist/src/algorithms/LabelPropagationAlgorithm.d.ts +3 -0
  51. package/dist/src/algorithms/LeidenAlgorithm.d.ts +3 -0
  52. package/dist/src/algorithms/LinkPredictionAlgorithm.d.ts +4 -1
  53. package/dist/src/algorithms/LouvainAlgorithm.d.ts +3 -0
  54. package/dist/src/algorithms/MaxFlowAlgorithm.d.ts +3 -0
  55. package/dist/src/algorithms/MinCutAlgorithm.d.ts +3 -0
  56. package/dist/src/algorithms/PageRankAlgorithm.d.ts +3 -0
  57. package/dist/src/algorithms/PrimAlgorithm.d.ts +3 -0
  58. package/dist/src/algorithms/StronglyConnectedComponentsAlgorithm.d.ts +3 -0
  59. package/dist/src/algorithms/input/ScopedInput.d.ts +185 -0
  60. package/dist/src/algorithms/input/derivedInputs.d.ts +199 -0
  61. package/dist/src/algorithms/input/maskBack.d.ts +37 -0
  62. package/dist/src/algorithms/metrics/MetricAlgorithm.d.ts +3 -3
  63. package/dist/src/algorithms/results/DeclaredAlgorithm.d.ts +4 -3
  64. package/dist/src/algorithms/results/types.d.ts +28 -6
  65. package/dist/src/algorithms/utils/communityUtils.d.ts +0 -48
  66. package/dist/src/algorithms/utils/graphUtils.d.ts +2 -68
  67. package/dist/src/algorithms/utils/snapshotGraph.d.ts +3 -1
  68. package/dist/src/catalog/algorithms.d.ts +3 -0
  69. package/dist/src/catalog/layouts.d.ts +2 -0
  70. package/dist/src/catalog/sets/canonical.d.ts +68 -0
  71. package/dist/src/catalog/sets/hash.d.ts +126 -0
  72. package/dist/src/catalog/sets/parse.d.ts +115 -0
  73. package/dist/src/catalog/types.d.ts +329 -8
  74. package/dist/src/data/GraphStore.d.ts +73 -1
  75. package/dist/src/data/edgeIdentity.d.ts +202 -1
  76. package/dist/src/data/ingest.d.ts +3 -1
  77. package/dist/src/data/report.d.ts +20 -0
  78. package/dist/src/graphty-element.d.ts +42 -6
  79. package/dist/src/layout/D3GraphLayoutEngine.d.ts +11 -0
  80. package/dist/src/layout/LayoutEngine.d.ts +56 -0
  81. package/dist/src/layout/NGraphLayoutEngine.d.ts +10 -0
  82. package/dist/src/layout/SimulationLayoutEngine.d.ts +11 -0
  83. package/dist/src/managers/AlgorithmManager.d.ts +8 -0
  84. package/dist/src/managers/DataManager.d.ts +11 -0
  85. package/dist/src/managers/LayoutManager.d.ts +126 -2
  86. package/dist/src/managers/StatsManager.d.ts +1 -0
  87. package/dist/src/session/GraphSession.d.ts +48 -0
  88. package/dist/src/session/attributes.d.ts +121 -1
  89. package/dist/src/session/cost/estimate.d.ts +20 -0
  90. package/dist/src/session/cost/index.d.ts +1 -1
  91. package/dist/src/session/planning.d.ts +32 -2
  92. package/dist/src/session/query.d.ts +7 -0
  93. package/dist/src/session/results/ResultsApi.d.ts +14 -1
  94. package/dist/src/session/runs/Run.d.ts +65 -4
  95. package/dist/src/session/runs/RunsApi.d.ts +58 -2
  96. package/dist/src/session/runs/runId.d.ts +55 -6
  97. package/dist/src/session/runs/types.d.ts +36 -8
  98. package/dist/src/session/scope/ElementMask.d.ts +14 -1
  99. package/dist/src/session/scope/ScopeApi.d.ts +160 -31
  100. package/dist/src/session/scope/index.d.ts +1 -1
  101. package/dist/src/session/selection/SelectionApi.d.ts +15 -10
  102. package/dist/src/session/selection/index.d.ts +1 -1
  103. package/dist/src/session/selection/targets.d.ts +6 -7
  104. package/dist/src/session/sets/SetsApi.d.ts +110 -0
  105. package/dist/src/session/sets/algebra.d.ts +124 -0
  106. package/dist/src/session/sets/cache.d.ts +197 -0
  107. package/dist/src/session/sets/captures.d.ts +83 -0
  108. package/dist/src/session/sets/dependencies.d.ts +167 -0
  109. package/dist/src/session/sets/layers.d.ts +101 -0
  110. package/dist/src/session/sets/notify.d.ts +122 -0
  111. package/dist/src/session/sets/offers.d.ts +103 -0
  112. package/dist/src/session/sets/path.d.ts +37 -0
  113. package/dist/src/session/sets/prepare.d.ts +209 -0
  114. package/dist/src/session/sets/resolve.d.ts +311 -0
  115. package/dist/src/session/sets/signature.d.ts +77 -0
  116. package/dist/src/session/sets/status.d.ts +98 -0
  117. package/dist/src/session/sets/store.d.ts +196 -0
  118. package/dist/src/session/sets/types.d.ts +386 -0
  119. package/dist/src/session/styles/Layer.d.ts +9 -2
  120. package/dist/src/session/styles/StylesApi.d.ts +5 -2
  121. package/dist/src/session/styles/explain.d.ts +5 -2
  122. package/dist/src/session/styles/predicate.d.ts +41 -2
  123. package/dist/src/session/styles/repaint.d.ts +19 -0
  124. package/dist/src/session/styles/selector.d.ts +16 -5
  125. package/dist/src/session/types.d.ts +18 -0
  126. package/dist/src/session/visibility/VisibilityApi.d.ts +47 -3
  127. package/dist/src/session/visibility/filter.d.ts +86 -51
  128. package/dist/src/session/visibility/index.d.ts +1 -1
  129. package/dist/src/testing/fakeAccelerator.d.ts +5 -0
  130. package/dist/src/utils/queue-migration.d.ts +17 -0
  131. package/package.json +15 -9
  132. package/dist/chunks/GraphSession-DuAhRgCd.js +0 -8622
  133. package/dist/chunks/optionsFromZod-B9RncoTX.js +0 -2578
  134. package/dist/chunks/scales-CJCRwi2J.js +0 -3220
  135. package/dist/src/algorithms/utils/index.d.ts +0 -6
@@ -1,2578 +0,0 @@
1
- import { c as he, G as y, S as Ie } from "./pluginRegistry-Bs8bEkz9.js";
2
- import { K as Te, f as Me } from "./types-C_c53VgR.js";
3
- import { b as _e } from "./GraphtyLogger-DOTwCiMR.js";
4
- import { Graph as ze, accelerated as X } from "@graphty/algorithms";
5
- import { INVALID_INDEX as L } from "@graphty/graph-format";
6
- import { z as me } from "zod/v4";
7
- const _ = he({
8
- kind: "camera",
9
- idOf: (e) => e.descriptor.id,
10
- descriptorOf: (e) => e.descriptor,
11
- implementationOf: (e) => e.compute,
12
- builtInIds: () => Te
13
- });
14
- function wn(e, t) {
15
- const n = e.descriptor;
16
- if (n === void 0 || typeof n != "object")
17
- throw new y({
18
- code: "E_BAD_COMMAND",
19
- message: "registerCameraView takes a camera view with a descriptor",
20
- source: "registry",
21
- details: { kind: "camera", field: "descriptor" }
22
- });
23
- if (!Array.isArray(n.modes) || n.modes.length === 0)
24
- throw new y({
25
- code: "E_BAD_COMMAND",
26
- message: `the camera view "${String(n.id)}" declares no drawing modes, so nothing could ever offer it: a view says where it works with \`modes\`, and the element refuses the rest`,
27
- source: "registry",
28
- details: { kind: "camera", name: String(n.id), field: "modes" }
29
- });
30
- if (!Array.isArray(n.options))
31
- throw new y({
32
- code: "E_BAD_COMMAND",
33
- message: `the camera view "${String(n.id)}" declares no options list. A view that takes no configuration declares an empty one, so a form has something to render and the element has something to check a caller's values against`,
34
- source: "registry",
35
- details: { kind: "camera", name: String(n.id), field: "options" }
36
- });
37
- if (typeof e.compute != "function")
38
- throw new y({
39
- code: "E_BAD_COMMAND",
40
- message: `the camera view "${String(n.id)}" was registered without a compute function`,
41
- source: "registry",
42
- details: { kind: "camera", name: String(n.id), field: "compute" }
43
- });
44
- _.register(e, t);
45
- }
46
- function vn() {
47
- return _.descriptors();
48
- }
49
- function On(e) {
50
- return _.byId(e);
51
- }
52
- function kn() {
53
- _.clearForTesting();
54
- }
55
- const Ce = ["forceAtlas2", "fruchtermanReingold", "springElectrical", "release"], xe = [
56
- "pageRank",
57
- "sssp",
58
- "breadthFirstSearch",
59
- "connectedComponents",
60
- "weaklyConnectedComponents",
61
- "minimumSpanningTree"
62
- ];
63
- function Nn(e) {
64
- const t = {
65
- kind: e.backend
66
- };
67
- for (const n of Ce) {
68
- const r = e[n];
69
- typeof r == "function" && (t[n] = r.bind(e));
70
- }
71
- return t;
72
- }
73
- function je(e) {
74
- const t = {
75
- kind: e.backend
76
- };
77
- for (const n of xe) {
78
- const r = e[n];
79
- typeof r == "function" && (t[n] = r.bind(e));
80
- }
81
- return t;
82
- }
83
- const Pe = ["auto", "off", "required"], Sn = "auto";
84
- function An(e) {
85
- return typeof e == "string" && Pe.includes(e);
86
- }
87
- const Le = "f64", $n = "f32", Rn = "acceleration.minNodes", En = 0, Fn = "RTX 4070 SUPER, headless Chromium, 2026-09-25", In = Object.freeze({
88
- breadthFirstSearch: 3e5,
89
- sssp: 3e5,
90
- pageRank: 5e3,
91
- connectedComponents: 5e4
92
- }), z = he({
93
- kind: "algorithm",
94
- idOf: (e) => e.descriptor.key,
95
- descriptorOf: (e) => e.descriptor,
96
- implementationOf: (e) => e.descriptor,
97
- builtInIds: () => Me
98
- });
99
- function De(e, t) {
100
- if (e.descriptor.key !== e.type)
101
- throw new y({
102
- code: "E_BAD_COMMAND",
103
- message: `the algorithm registered as "${e.namespace}:${e.type}" publishes the catalogue key "${e.descriptor.key}". An algorithm has one name: make "descriptor.key" equal "static type".`,
104
- source: "registry",
105
- details: {
106
- kind: "algorithm",
107
- field: "descriptor.key",
108
- key: e.descriptor.key,
109
- type: e.type,
110
- namespace: e.namespace
111
- }
112
- });
113
- z.register(e, t);
114
- }
115
- function Tn() {
116
- return z.descriptors();
117
- }
118
- function Mn(e) {
119
- return z.byId(e);
120
- }
121
- function _n() {
122
- z.clearForTesting();
123
- }
124
- class b extends Error {
125
- /**
126
- * Creates an option validation error
127
- * @param optionKey - The key of the option that failed validation
128
- * @param message - The validation error message
129
- */
130
- constructor(t, n) {
131
- super(`Option '${t}': ${n}`), this.optionKey = t, this.name = "OptionValidationError";
132
- }
133
- }
134
- function Ge(e, t, n) {
135
- if (t == null) {
136
- if (n.required)
137
- throw new b(e, "is required but was not provided");
138
- return;
139
- }
140
- switch (n.type) {
141
- case "number":
142
- Q(e, t, n, !1);
143
- break;
144
- case "integer":
145
- Q(e, t, n, !0);
146
- break;
147
- case "boolean":
148
- if (typeof t != "boolean")
149
- throw new b(e, `must be a boolean, got ${typeof t}`);
150
- break;
151
- case "string":
152
- if (typeof t != "string")
153
- throw new b(e, `must be a string, got ${typeof t}`);
154
- break;
155
- case "select":
156
- Ue(e, t, n);
157
- break;
158
- case "nodeId":
159
- if (typeof t != "string" && typeof t != "number")
160
- throw new b(e, `must be a string or number (node ID), got ${typeof t}`);
161
- break;
162
- default:
163
- throw new b(e, `has unknown type '${n.type}'`);
164
- }
165
- }
166
- function Q(e, t, n, r) {
167
- if (typeof t != "number")
168
- throw new b(e, `must be a number, got ${typeof t}`);
169
- if (Number.isNaN(t))
170
- throw new b(e, "must not be NaN");
171
- if (!Number.isFinite(t))
172
- throw new b(e, "must be finite");
173
- if (r && !Number.isInteger(t))
174
- throw new b(e, `must be an integer, got ${t}`);
175
- if (n.min !== void 0 && t < n.min)
176
- throw new b(e, `must be >= ${n.min}, got ${t}`);
177
- if (n.max !== void 0 && t > n.max)
178
- throw new b(e, `must be <= ${n.max}, got ${t}`);
179
- }
180
- function Ue(e, t, n) {
181
- if (!n.options || n.options.length === 0)
182
- throw new b(e, "is a select type but has no options defined");
183
- if (!n.options.map((i) => i.value).includes(t)) {
184
- const i = n.options.map((s) => `'${String(s.value)}'`).join(", ");
185
- throw new b(e, `must be one of [${i}], got '${String(t)}'`);
186
- }
187
- }
188
- function He(e, t) {
189
- const n = {};
190
- for (const [r, i] of Object.entries(e)) {
191
- const o = t?.[r] ?? i.default;
192
- Ge(r, o, i), n[r] = o;
193
- }
194
- return n;
195
- }
196
- function zn(e) {
197
- return e;
198
- }
199
- function Be(e, t) {
200
- const n = e.getSnapshot(), r = t === "directed" ? n : e.undirected(n).snapshot, i = r.flags.multigraph ? r.simplified({ weights: "sum" }).snapshot : r;
201
- return Ve(i, t);
202
- }
203
- function Cn(e) {
204
- const t = e.getSnapshot();
205
- return t.flags.multigraph ? t.edgeCount - t.simplified({ weights: "sum" }).snapshot.edgeCount : 0;
206
- }
207
- function Ve(e, t) {
208
- const n = new ze({
209
- directed: t !== "undirected"
210
- }), { ids: r } = e;
211
- for (let a = 0; a < e.nodeCount; a++)
212
- n.addNode(r.idOf(a));
213
- const { src: i, dst: s, weights: o } = e.edgeList();
214
- for (let a = 0; a < e.edgeCount; a++) {
215
- const u = r.idOf(i[a]), c = r.idOf(s[a]), h = o === null ? 1 : o[a];
216
- n.addEdge(u, c, h);
217
- }
218
- return n;
219
- }
220
- const E = new Ie("algorithm");
221
- function Je(e, t) {
222
- if (t === null)
223
- return e;
224
- if (e === null)
225
- return t;
226
- const n = new Uint32Array(e.length);
227
- for (let r = 0; r < e.length; r++) {
228
- const i = e[r];
229
- n[r] = i === L ? L : t[i];
230
- }
231
- return n;
232
- }
233
- const Z = class Z {
234
- /**
235
- * Getter for schema options
236
- *
237
- * Algorithms that use the new schema-based options should access
238
- * options via this getter.
239
- * @returns The resolved schema options
240
- */
241
- get schemaOptions() {
242
- return this._schemaOptions;
243
- }
244
- /**
245
- * Creates a new algorithm instance
246
- * @param g - The graph to run the algorithm on
247
- * @param options - Optional configuration options (uses schema defaults if not provided)
248
- */
249
- constructor(t, n) {
250
- this.graph = t, this._schemaOptions = this.resolveOptions(n);
251
- }
252
- /**
253
- * The `@graphty/algorithms` Graph this run reads, built from the element's graph snapshot.
254
- *
255
- * This is the ONLY way an algorithm should obtain its input. The `Node` and `Edge` objects the
256
- * data manager also holds are render objects -- each `Node` builds a Babylon mesh in its
257
- * constructor -- and reading the graph out of them ties every algorithm to a renderer and to
258
- * whatever part of a data load the scene has caught up with.
259
- * @param mode - the shape this algorithm needs; see {@link AlgorithmGraphMode}
260
- * @returns a freshly built Graph for the algorithm package
261
- */
262
- algorithmGraph(t) {
263
- return Be(this.graph.getDataManager(), t);
264
- }
265
- /**
266
- * The route an algorithm with an accelerated implementation takes.
267
- *
268
- * It is the counterpart of {@link algorithmGraph} for the algorithms `@graphty/algorithms`
269
- * can dispatch: instead of copying the snapshot into an object graph, the work runs over the
270
- * snapshot itself, on the attached accelerator or on the index-based CPU port, and the adapter
271
- * writes one loop over an index-aligned result either way.
272
- *
273
- * THE DECISION IS TAKEN ONCE, HERE, BEFORE ANY WORK STARTS. The controller answers "the policy
274
- * is off", "no accelerator", "below `acceleration.minNodes`" or "this accelerator does not
275
- * implement that" up front, and under `acceleration="required"` it throws `E_NO_ACCELERATOR`
276
- * rather than answering quietly. After the work has started there is no second decision: a
277
- * failure from the accelerator propagates with its code and fails the run, because a number
278
- * that silently came from somewhere else is worse than no number.
279
- * @param capability - The accelerator member this work would use, such as `"pageRank"`.
280
- * @param mode - The shape this algorithm needs; see {@link AlgorithmGraphMode}. `"undirected"`
281
- * takes the snapshot's undirected view, which is what collapses a reciprocal pair into one
282
- * edge.
283
- * @returns The snapshot, the edge map onto it, and the runner.
284
- * @example
285
- * ```ts
286
- * const { snapshot, run } = this.accelerated("connectedComponents", "undirected");
287
- * const { value, precision } = await run((dispatch, s) => dispatch.connectedComponents(s));
288
- * const group = value.labels[snapshot.ids.indexOf(nodeId)];
289
- * ```
290
- */
291
- accelerated(t, n) {
292
- const r = this.graph.getDataManager(), i = r.getSnapshot(), s = n === "undirected" ? r.undirected(i) : null, o = s === null ? i : s.snapshot, a = o.flags.multigraph ? o.simplified({ weights: "sum" }) : null, u = a === null ? o : a.snapshot, c = this.graph.acceleration, h = { capability: t, nodeCount: u.nodeCount };
293
- return {
294
- snapshot: u,
295
- edgeRemap: Je(s?.edgeRemap ?? null, a?.edgeRemap ?? null),
296
- run: async (p) => {
297
- const l = await c.run(
298
- h,
299
- (d) => p(X(je(d)), u)
300
- );
301
- return l.accelerated ? { value: l.value, precision: l.precision } : { value: await p(X(null), u), precision: Le };
302
- }
303
- };
304
- }
305
- /**
306
- * The dense row of a node the reader named in an option.
307
- *
308
- * A search takes its source as an id and the snapshot answers in indices, so this is where the
309
- * two meet -- and where an id that names no node in the graph is reported as what it is: an
310
- * option whose value is outside the permitted range, carrying the option's name and what was
311
- * passed, rather than a silent empty result or a search from row zero.
312
- * @param snapshot - The graph the work runs over.
313
- * @param option - The option the id came from, named in the error.
314
- * @param id - The node id the reader gave.
315
- * @returns The node's dense row.
316
- * @throws A `GraphtyError` with `E_OPTION_RANGE` when the graph has no such node.
317
- */
318
- nodeIndex(t, n, r) {
319
- const i = t.ids.indexOf(r);
320
- if (i === L)
321
- throw new y({
322
- code: "E_OPTION_RANGE",
323
- message: `the graph has no node "${String(r)}", so "${n}" names nothing to run from`,
324
- source: "run",
325
- details: { option: n, value: r }
326
- });
327
- return i;
328
- }
329
- /**
330
- * Resolves and validates options against the schema
331
- * @param options - User-provided options (partial)
332
- * @returns Fully resolved options with defaults applied
333
- */
334
- resolveOptions(t) {
335
- const n = this.constructor.optionsSchema;
336
- return Object.keys(n).length === 0 ? {} : He(n, t);
337
- }
338
- /**
339
- * Gets the algorithm type
340
- * @returns The algorithm type identifier
341
- */
342
- get type() {
343
- return this.constructor.type;
344
- }
345
- /**
346
- * Gets the algorithm namespace
347
- * @returns The algorithm namespace identifier
348
- */
349
- get namespace() {
350
- return this.constructor.namespace;
351
- }
352
- /**
353
- * Compute this algorithm and publish what it produced as a result object.
354
- *
355
- * This is the entry point the run machinery calls, and it is the one that makes an algorithm
356
- * startable as a `Run`: it takes a signal it must throw from, a progress channel, a yield, and
357
- * the run id the result is published under -- and it RETURNS the result rather than writing it
358
- * somewhere a caller has to go looking for. `run()` is the 1.10 entry point beside it, which
359
- * returns nothing and can be neither watched nor stopped.
360
- *
361
- * The default refuses, because an algorithm that has not been migrated genuinely cannot answer
362
- * a run: it publishes through side effects under its own names and has no result object to
363
- * hand back. Both shipped families -- a metric and a declared algorithm -- override it.
364
- * @param _context - A signal, a progress channel and a yield.
365
- * @param runId - The id the result is published under.
366
- * @param _fields - The catalogue's descriptors for this algorithm's fields, when the caller
367
- * holds them.
368
- * @returns The result, or undefined when there was nothing to compute.
369
- * @throws A `GraphtyError` with code `E_UNSUPPORTED` when this algorithm has no result to
370
- * publish.
371
- */
372
- publishResult(t, n, r) {
373
- return Promise.reject(
374
- new y({
375
- code: "E_UNSUPPORTED",
376
- message: `The "${this.namespace}:${this.type}" algorithm writes its result through side effects and cannot be started as a run.`,
377
- source: "run",
378
- target: { kind: "run", id: n },
379
- details: { algorithm: `${this.namespace}:${this.type}` }
380
- })
381
- );
382
- }
383
- /**
384
- * Registers an algorithm class in the global registry
385
- * @param cls - The algorithm class to register
386
- * @returns The registered algorithm class
387
- */
388
- static register(t) {
389
- const n = t, r = String(n.type), i = String(n.namespace), { descriptor: s, cost: o, costUnits: a, version: u } = n;
390
- return s !== void 0 && De({
391
- descriptor: s,
392
- namespace: i,
393
- type: r,
394
- ...o === void 0 ? {} : { cost: o },
395
- ...a === void 0 ? {} : { costUnits: a },
396
- ...u === void 0 ? {} : { version: u }
397
- }), E.set(`${i}:${r}`, t), t;
398
- }
399
- /**
400
- * Gets an algorithm instance from the registry
401
- * @param g - The graph to run the algorithm on
402
- * @param namespace - The algorithm namespace
403
- * @param type - The algorithm type
404
- * @param options - Optional algorithm-specific options to pass to constructor
405
- * @returns A new instance of the algorithm, or null if not found
406
- */
407
- static get(t, n, r, i) {
408
- const s = E.get(`${n}:${r}`);
409
- return s ? new s(t, i) : null;
410
- }
411
- /**
412
- * Gets an algorithm class from the registry
413
- * @param namespace - The algorithm namespace
414
- * @param type - The algorithm type
415
- * @returns The algorithm class, or null if not found
416
- */
417
- static getClass(t, n) {
418
- return E.get(`${t}:${n}`) ?? null;
419
- }
420
- /**
421
- * Get the options schema for this algorithm
422
- * @returns The options schema, or an empty object if no options defined
423
- * @deprecated Use getZodOptionsSchema() instead
424
- */
425
- static getOptionsSchema() {
426
- return this.optionsSchema;
427
- }
428
- /**
429
- * Check if this algorithm has configurable options
430
- * @returns true if the algorithm has at least one option defined
431
- * @deprecated Use hasZodOptions() instead
432
- */
433
- static hasOptions() {
434
- return Object.keys(this.optionsSchema).length > 0;
435
- }
436
- /**
437
- * Get the Zod-based options schema for this algorithm.
438
- * @returns The Zod options schema, or an empty object if no schema defined
439
- */
440
- static getZodOptionsSchema() {
441
- return this.zodOptionsSchema ?? {};
442
- }
443
- /**
444
- * Check if this algorithm has a Zod-based options schema.
445
- * @returns true if the algorithm has a Zod options schema defined
446
- */
447
- static hasZodOptions() {
448
- return this.zodOptionsSchema !== void 0 && Object.keys(this.zodOptionsSchema).length > 0;
449
- }
450
- /**
451
- * Get all registered algorithm names.
452
- * @param namespace - Optional namespace to filter by
453
- * @returns Array of algorithm names in "namespace:type" format
454
- */
455
- static getRegisteredAlgorithms(t) {
456
- const n = [];
457
- for (const r of E.keys())
458
- (!t || r.startsWith(`${t}:`)) && n.push(r);
459
- return n.sort();
460
- }
461
- /**
462
- * Get all registered algorithm types.
463
- * This method is provided for API consistency with DataSource.
464
- * @returns Array of algorithm keys in "namespace:type" format
465
- * @since 1.5.0
466
- * @example
467
- * ```typescript
468
- * const types = Algorithm.getRegisteredTypes();
469
- * console.log('Available algorithms:', types);
470
- * // ['graphty:betweenness', 'graphty:closeness', 'graphty:degree', ...]
471
- * ```
472
- */
473
- static getRegisteredTypes() {
474
- return this.getRegisteredAlgorithms();
475
- }
476
- };
477
- Z.optionsSchema = {};
478
- let D = Z;
479
- const ee = 3, qe = 0.1;
480
- function m(e, t) {
481
- return Number.isInteger(e) ? e.toLocaleString(t) : Number(e.toFixed(ee)).toLocaleString(t, { maximumFractionDigits: ee });
482
- }
483
- function Ye(e, t, n) {
484
- const r = e.fields.find((i) => i.name === t);
485
- return r === void 0 ? t : n === "technical" ? r.technicalName : r.plainName.toLowerCase();
486
- }
487
- function C(e, t, n) {
488
- const r = e.fields.find((i) => i.name === t)?.unit;
489
- return r === void 0 ? "" : n === 1 && r.endsWith("s") ? ` ${r.slice(0, -1)}` : ` ${r}`;
490
- }
491
- function R(e, t) {
492
- const n = e.graph[t];
493
- return typeof n == "number" && Number.isFinite(n) ? n : void 0;
494
- }
495
- function We(e) {
496
- return e[0];
497
- }
498
- function Ke(e, t, n) {
499
- const { locale: r, audience: i } = n, s = Ye(e, "value", i), o = We(t.top);
500
- if (o === void 0 || t.median === null)
501
- return `Nothing was measured, so there is no ${s} to report.`;
502
- const a = [
503
- `${o.label} has the highest ${s}, at ${m(o.value, r)}${C(e, "value", o.value)}.`,
504
- `The typical element sits at ${m(t.median, r)}${C(e, "value", t.median)}.`
505
- ];
506
- return t.measured > 0 && t.tiedAtMin / t.measured >= qe && t.min !== null && a.push(
507
- `${m(t.tiedAtMin, r)} of ${m(t.measured, r)} sit at the lowest value, ${m(t.min, r)}${C(e, "value", t.min)}.`
508
- ), t.count > t.measured && a.push(`${m(t.count - t.measured, r)} were not measured.`), a.join(" ");
509
- }
510
- function Ze(e, t, n) {
511
- const { locale: r } = n, i = t.groups ?? [];
512
- if (i.length === 0)
513
- return "Nothing was grouped, so there are no groups to report.";
514
- const s = i[0], o = [
515
- `${m(i.length, r)} ${i.length === 1 ? "group" : "groups"} were found,`,
516
- `the largest holding ${m(s.size, r)} of ${m(t.measured, r)}.`
517
- ], a = R(e, "modularity");
518
- return a !== void 0 && o.push(`Modularity is ${m(a, r)}.`), o.join(" ");
519
- }
520
- function Xe(e, t) {
521
- const { locale: n } = t, r = R(e, "hops"), i = R(e, "cost");
522
- if (r === void 0 && i === void 0)
523
- return "No route was found.";
524
- const s = [];
525
- return r !== void 0 && s.push(`The route runs ${m(r, n)} ${r === 1 ? "hop" : "hops"}.`), i !== void 0 && s.push(`Its total cost is ${m(i, n)}.`), s.join(" ");
526
- }
527
- function Qe(e, t, n) {
528
- const { locale: r } = n, i = R(e, "count") ?? t.measured, s = e.shape === "edge-set" ? "edge" : "node";
529
- return i === 0 ? `No ${s}s were selected.` : `${m(i, r)} ${i === 1 ? s : `${s}s`} were selected.`;
530
- }
531
- function et(e, t) {
532
- const { pairs: n } = e.graph, r = Array.isArray(n) ? n.length : 0;
533
- return r === 0 ? "No pairs were found." : `${m(r, t.locale)} ${r === 1 ? "pair was" : "pairs were"} found.`;
534
- }
535
- function tt(e, t) {
536
- const n = R(e, "steps");
537
- return n === void 0 || n === 0 ? "The series is empty." : `The series covers ${m(n, t.locale)} ${n === 1 ? "step" : "steps"}.`;
538
- }
539
- function te(e, t) {
540
- return e.measured === 0 ? "The run produced no values." : `The run covered ${m(e.measured, t.locale)} of ${m(e.count, t.locale)}.`;
541
- }
542
- function nt(e, t) {
543
- const n = e.summary(), { shape: r } = e;
544
- switch (r) {
545
- case "node-metric":
546
- case "edge-metric":
547
- return Ke(e, n, t);
548
- case "community":
549
- case "layered-grouping":
550
- case "category-table":
551
- return Ze(e, n, t);
552
- case "path":
553
- return Xe(e, t);
554
- case "node-set":
555
- case "edge-set":
556
- return Qe(e, n, t);
557
- case "pair-list":
558
- return et(e, t);
559
- case "temporal":
560
- return tt(e, t);
561
- case "fact":
562
- return te(n, t);
563
- default:
564
- return te(n, t);
565
- }
566
- }
567
- function xn(e, t) {
568
- const n = t === "node", r = n ? e.nodeValue : e.edgeValue, i = n ? e.nodeHas : e.edgeHas, s = n ? e.nodeIdOf : e.edgeIdOf;
569
- return {
570
- value: r,
571
- has: i ?? ((o, a) => rt(r(o, a))),
572
- idOf: s ?? null
573
- };
574
- }
575
- function rt(e) {
576
- return e != null;
577
- }
578
- function I(e) {
579
- return e == null || e === !1 || e === "" ? !1 : Array.isArray(e) ? e.length > 0 : typeof e == "object" ? Object.keys(e).length > 0 : !0;
580
- }
581
- function G(e, t) {
582
- if (e === t)
583
- return !0;
584
- if (Array.isArray(e) && Array.isArray(t))
585
- return e.length === t.length && e.every((n, r) => G(n, t[r]));
586
- if (ne(e) && ne(t)) {
587
- const n = Object.keys(e);
588
- return n.length === Object.keys(t).length && n.every((r) => G(e[r], t[r]));
589
- }
590
- return !1;
591
- }
592
- function ne(e) {
593
- return typeof e == "object" && e !== null && !Array.isArray(e);
594
- }
595
- function f(e, t, n, r = {}) {
596
- return new y({
597
- code: "E_BAD_SELECTOR",
598
- message: `${e} (at character ${String(n)} of ${JSON.stringify(t)})`,
599
- source: "style",
600
- details: { ...r, position: n, where: t }
601
- });
602
- }
603
- const it = Object.freeze({
604
- "[": "index, slice, wildcard and filter expressions",
605
- "]": "index, slice, wildcard and filter expressions",
606
- "{": "multi-select hashes",
607
- "}": "multi-select hashes",
608
- ",": "multi-select lists",
609
- "*": "wildcards",
610
- "@": "the current-node reference",
611
- ":": "slices"
612
- }), st = ["&&", "||", "==", "!=", "<=", ">=", "!", "<", ">", ".", "(", ")"];
613
- function fe(e) {
614
- return /[A-Za-z_]/.test(e);
615
- }
616
- function ge(e) {
617
- return /[A-Za-z0-9_]/.test(e);
618
- }
619
- function x(e, t, n) {
620
- for (let r = t + 1; r < e.length; r++) {
621
- if (e[r] === "\\") {
622
- r++;
623
- continue;
624
- }
625
- if (e[r] === n)
626
- return r;
627
- }
628
- throw f(`A ${n} is opened and never closed`, e, t, { delimiter: n });
629
- }
630
- function ot(e) {
631
- let t = "";
632
- for (let n = 0; n < e.length; n++) {
633
- if (e[n] === "\\" && (e[n + 1] === "'" || e[n + 1] === "\\")) {
634
- t += e[n + 1], n++;
635
- continue;
636
- }
637
- t += e[n];
638
- }
639
- return t;
640
- }
641
- function at(e, t, n) {
642
- const r = n.replace(/\\`/g, "`");
643
- try {
644
- return JSON.parse(r);
645
- } catch {
646
- throw f(
647
- `A literal between backticks must be JSON, so a bare word needs quotes: write \`"${r}"\` rather than \`${r}\``,
648
- e,
649
- t,
650
- { literal: r }
651
- );
652
- }
653
- }
654
- function ct(e, t, n) {
655
- try {
656
- const r = JSON.parse(n);
657
- if (typeof r == "string")
658
- return r;
659
- } catch {
660
- }
661
- throw f(
662
- `A quoted attribute name follows JSON's rules for a string, and ${n} does not`,
663
- e,
664
- t,
665
- { name: n }
666
- );
667
- }
668
- function ut(e) {
669
- const t = [];
670
- let n = 0;
671
- for (; n < e.length; ) {
672
- const r = e.charAt(n);
673
- if (/\s/.test(r)) {
674
- n++;
675
- continue;
676
- }
677
- const i = it[r];
678
- if (i !== void 0)
679
- throw f(`A selector does not support ${i}`, e, n, { construct: i });
680
- if (r === "|" && e.charAt(n + 1) !== "|")
681
- throw f("A selector does not support pipe expressions", e, n, { construct: "pipe expressions" });
682
- if (r === "&" && e.charAt(n + 1) !== "&")
683
- throw f("A selector does not support expression references", e, n, {
684
- construct: "expression references"
685
- });
686
- const s = st.find((o) => e.startsWith(o, n));
687
- if (s !== void 0) {
688
- t.push({ kind: "operator", text: s, at: n }), n += s.length;
689
- continue;
690
- }
691
- if (r === "`") {
692
- const o = x(e, n, "`");
693
- t.push({ kind: "literal", text: "", value: at(e, n, e.slice(n + 1, o)), at: n }), n = o + 1;
694
- continue;
695
- }
696
- if (r === "'") {
697
- const o = x(e, n, "'");
698
- t.push({ kind: "literal", text: "", value: ot(e.slice(n + 1, o)), at: n }), n = o + 1;
699
- continue;
700
- }
701
- if (r === '"') {
702
- const o = x(e, n, '"');
703
- t.push({ kind: "identifier", text: ct(e, n, e.slice(n, o + 1)), at: n }), n = o + 1;
704
- continue;
705
- }
706
- if (fe(r)) {
707
- let o = n + 1;
708
- for (; o < e.length && ge(e.charAt(o)); )
709
- o++;
710
- t.push({ kind: "identifier", text: e.slice(n, o), at: n }), n = o;
711
- continue;
712
- }
713
- throw /[0-9-]/.test(r) ? f(
714
- "A number in a selector goes between backticks, so write `5` rather than 5",
715
- e,
716
- n,
717
- { character: r }
718
- ) : f(`${JSON.stringify(r)} is not something a selector can contain`, e, n, {
719
- character: r
720
- });
721
- }
722
- return t.push({ kind: "end", text: "", at: e.length }), t;
723
- }
724
- const lt = Object.freeze({
725
- "!=": "!=",
726
- "<": "<",
727
- "<=": "<=",
728
- "==": "==",
729
- ">": ">",
730
- ">=": ">="
731
- });
732
- function N(e) {
733
- return e.tokens[e.index];
734
- }
735
- function S(e, t) {
736
- const n = N(e);
737
- return n.kind === "operator" && n.text === t;
738
- }
739
- function dt(e) {
740
- const t = N(e), n = [];
741
- for (; ; ) {
742
- const r = N(e);
743
- if (r.kind !== "identifier")
744
- throw f("A `.` must be followed by an attribute name", e.where, r.at);
745
- if (r.text.includes("."))
746
- throw f(
747
- `A quoted attribute name may not contain a dot: ${JSON.stringify(r.text)} would be indistinguishable from two names`,
748
- e.where,
749
- r.at,
750
- { segment: r.text }
751
- );
752
- if (e.index++, S(e, "("))
753
- throw f(
754
- `A selector does not support functions, so ${r.text}(...) cannot be called here`,
755
- e.where,
756
- r.at,
757
- { construct: "functions", function: r.text }
758
- );
759
- if (n.push(r.text), !S(e, "."))
760
- return { kind: "path", path: n.join("."), at: t.at };
761
- e.index++;
762
- }
763
- }
764
- function pt(e) {
765
- const t = N(e);
766
- if (t.kind === "literal")
767
- return e.index++, { kind: "literal", value: t.value };
768
- if (t.kind === "identifier")
769
- return dt(e);
770
- if (S(e, "(")) {
771
- e.index++;
772
- const n = ye(e);
773
- if (!S(e, ")"))
774
- throw f("A `(` is opened and never closed", e.where, t.at);
775
- return e.index++, { kind: "group", inner: n };
776
- }
777
- throw f(
778
- t.kind === "end" ? "The selector ends where an attribute name, a literal or a `(` should be" : `${JSON.stringify(t.text)} is where an attribute name, a literal or a \`(\` should be`,
779
- e.where,
780
- t.at
781
- );
782
- }
783
- function U(e) {
784
- if (!S(e, "!"))
785
- return pt(e);
786
- const t = N(e);
787
- e.index++;
788
- const n = U(e);
789
- if (n.kind === "path" && n.path.includes("."))
790
- throw f(
791
- `In JMESPath \`!\` binds tighter than \`.\`, so !${n.path} means (!${n.path.split(".")[0]})${n.path.slice(n.path.indexOf("."))} rather than the opposite of ${n.path}. Write !(${n.path}) for that`,
792
- e.where,
793
- t.at,
794
- { path: n.path }
795
- );
796
- return { kind: "not", operand: n };
797
- }
798
- function re(e) {
799
- const t = U(e), n = N(e), r = n.kind === "operator" ? lt[n.text] : void 0;
800
- return r === void 0 ? t : (e.index++, { kind: "compare", operator: r, left: t, right: U(e) });
801
- }
802
- function ie(e) {
803
- let t = re(e);
804
- for (; S(e, "&&"); )
805
- e.index++, t = { kind: "and", left: t, right: re(e) };
806
- return t;
807
- }
808
- function ye(e) {
809
- let t = ie(e);
810
- for (; S(e, "||"); )
811
- e.index++, t = { kind: "or", left: t, right: ie(e) };
812
- return t;
813
- }
814
- function ht(e) {
815
- const t = { where: e, tokens: ut(e), index: 0 }, n = ye(t), r = N(t);
816
- if (r.kind !== "end")
817
- throw f(
818
- `${JSON.stringify(r.text)} is left over at the end of the selector`,
819
- e,
820
- r.at
821
- );
822
- return n;
823
- }
824
- function $(e, t) {
825
- switch (e.kind) {
826
- case "path":
827
- t.includes(e.path) || t.push(e.path);
828
- return;
829
- case "group":
830
- $(e.inner, t);
831
- return;
832
- case "not":
833
- $(e.operand, t);
834
- return;
835
- case "and":
836
- case "or":
837
- case "compare":
838
- $(e.left, t), $(e.right, t);
839
- return;
840
- default:
841
- return;
842
- }
843
- }
844
- function w(e, t) {
845
- switch (e.kind) {
846
- case "path": {
847
- const { path: n } = e, { value: r } = t;
848
- return (i) => {
849
- const s = r(i, n);
850
- return s === void 0 ? null : s;
851
- };
852
- }
853
- case "literal": {
854
- const { value: n } = e;
855
- return () => n;
856
- }
857
- case "group":
858
- return w(e.inner, t);
859
- case "not": {
860
- const n = w(e.operand, t);
861
- return (r) => !I(n(r));
862
- }
863
- case "and": {
864
- const n = w(e.left, t), r = w(e.right, t);
865
- return (i) => {
866
- const s = n(i);
867
- return I(s) ? r(i) : s;
868
- };
869
- }
870
- case "or": {
871
- const n = w(e.left, t), r = w(e.right, t);
872
- return (i) => {
873
- const s = n(i);
874
- return I(s) ? s : r(i);
875
- };
876
- }
877
- default:
878
- return gt(e.operator, e.left, e.right, t);
879
- }
880
- }
881
- const mt = Object.freeze({
882
- "<": (e, t) => e < t,
883
- "<=": (e, t) => e <= t,
884
- ">": (e, t) => e > t,
885
- ">=": (e, t) => e >= t
886
- });
887
- function ft(e, t) {
888
- return e.kind === "literal" ? e : t.kind === "literal" ? t : null;
889
- }
890
- function gt(e, t, n, r) {
891
- if (e === "==" || e === "!=") {
892
- const a = e === "==", u = t.kind === "literal", c = ft(t, n), h = u ? n : t;
893
- if (c !== null && c.value === null && h.kind === "path") {
894
- const { path: d } = h, { has: v } = r;
895
- return (k) => v(k, d) !== a;
896
- }
897
- const p = w(t, r), l = w(n, r);
898
- if (c !== null && c.value !== null && typeof c.value != "object") {
899
- const { value: d } = c, v = u ? l : p;
900
- return (k) => v(k) === d === a;
901
- }
902
- return (d) => G(p(d), l(d)) === a;
903
- }
904
- const i = w(t, r), s = w(n, r), o = mt[e];
905
- return (a) => {
906
- const u = i(a), c = s(a);
907
- return typeof u == "number" && typeof c == "number" ? o(u, c) : null;
908
- };
909
- }
910
- function A(e, t) {
911
- switch (e.kind) {
912
- case "compare":
913
- case "not": {
914
- const n = w(e, t);
915
- return (r) => n(r) === !0;
916
- }
917
- case "group":
918
- return A(e.inner, t);
919
- case "and": {
920
- const n = A(e.left, t), r = A(e.right, t);
921
- return (i) => n(i) && r(i);
922
- }
923
- case "or": {
924
- const n = A(e.left, t), r = A(e.right, t);
925
- return (i) => n(i) || r(i);
926
- }
927
- default: {
928
- const n = w(e, t);
929
- return (r) => I(n(r));
930
- }
931
- }
932
- }
933
- function yt(e) {
934
- return e.split(".").map((t) => bt(t) ? t : JSON.stringify(t)).join(".");
935
- }
936
- function bt(e) {
937
- if (e === "" || !fe(e[0]))
938
- return !1;
939
- for (let t = 1; t < e.length; t++)
940
- if (!ge(e[t]))
941
- return !1;
942
- return !0;
943
- }
944
- function jn(e, t) {
945
- const { has: n } = e;
946
- return (r) => n(r, t);
947
- }
948
- function Pn(e, t) {
949
- const { idOf: n } = e;
950
- if (n === null)
951
- throw new y({
952
- code: "E_UNSUPPORTED",
953
- message: 'This session cannot evaluate an "ids" selector, because it cannot say which id sits at which row. Painting the layer anyway would colour elements it never named.',
954
- source: "style",
955
- details: { match: "ids" }
956
- });
957
- return (r) => t.has(n(r));
958
- }
959
- function Ln(e, t, n) {
960
- const { value: r } = e;
961
- return (i) => {
962
- const s = n();
963
- if (s === void 0)
964
- return !1;
965
- const o = r(i, t);
966
- return typeof o == "number" && Number.isFinite(o) && o >= s;
967
- };
968
- }
969
- function Dn(e, t) {
970
- const n = ht(e), r = [];
971
- if ($(n, r), r.length === 0) {
972
- let i = n;
973
- for (; i.kind === "group"; )
974
- i = i.inner;
975
- const s = i.kind === "literal" && typeof i.value == "string";
976
- throw f(
977
- s ? "The selector is a quoted string literal, which is always true, so it would match every element. Remove the outer quotes so it is read as an expression" : 'The selector reads no attribute of the element, so it answers the same for every element. Write { match: "everything" } for a layer that really is meant to paint the whole graph',
978
- e,
979
- 0,
980
- { constant: !0 }
981
- );
982
- }
983
- return { paths: Object.freeze(r), test: A(n, t) };
984
- }
985
- const H = "results", wt = "$";
986
- function T(e, t) {
987
- return t === void 0 ? `${H}.${e}` : `${H}.${e}.${t}`;
988
- }
989
- function vt(e) {
990
- return `Group ${String(e)}`;
991
- }
992
- function be(e, t) {
993
- const n = Number(e), r = Number(t);
994
- return Number.isFinite(n) && Number.isFinite(r) && String(n) === String(e) && String(r) === String(t) ? n - r : String(e).localeCompare(String(t));
995
- }
996
- const we = {
997
- // -- per element ---------------------------------------------------------------------
998
- value: {
999
- meaning: "The number this metric measured for this element.",
1000
- scope: "element",
1001
- types: ["number", "integer"]
1002
- },
1003
- rank: {
1004
- meaning: "Where this element sits when every measured element is ordered best first, starting at 1.",
1005
- scope: "element",
1006
- types: ["integer"]
1007
- },
1008
- percentile: {
1009
- meaning: "The share of measured elements this one ranks at or above, from 0 to 1.",
1010
- scope: "element",
1011
- types: ["number"]
1012
- },
1013
- group: {
1014
- meaning: "Which group this node was placed in.",
1015
- scope: "element",
1016
- types: ["integer", "string"]
1017
- },
1018
- groupSize: {
1019
- meaning: "How many nodes share this node's group.",
1020
- scope: "element",
1021
- types: ["integer"]
1022
- },
1023
- level: {
1024
- meaning: "How many levels out from the start this node sits, counting the start as 0.",
1025
- scope: "element",
1026
- types: ["integer"]
1027
- },
1028
- levelSize: {
1029
- meaning: "How many nodes share this node's level.",
1030
- scope: "element",
1031
- types: ["integer"]
1032
- },
1033
- category: {
1034
- meaning: "The category this node was sorted into.",
1035
- scope: "element",
1036
- types: ["string"]
1037
- },
1038
- score: {
1039
- meaning: "How strongly this node belongs to its category.",
1040
- scope: "element",
1041
- types: ["number"]
1042
- },
1043
- onPath: {
1044
- meaning: "Whether this element is on the route the run found.",
1045
- scope: "element",
1046
- types: ["boolean"]
1047
- },
1048
- order: {
1049
- meaning: "This node's position along the route, counting the source as 0.",
1050
- scope: "element",
1051
- types: ["integer"]
1052
- },
1053
- in: {
1054
- meaning: "Whether this element is in the set the run selected.",
1055
- scope: "element",
1056
- types: ["boolean"]
1057
- },
1058
- // -- per graph -----------------------------------------------------------------------
1059
- min: {
1060
- meaning: "The lowest value any measured element carries.",
1061
- scope: "graph",
1062
- types: ["number"]
1063
- },
1064
- max: {
1065
- meaning: "The highest value any measured element carries.",
1066
- scope: "graph",
1067
- types: ["number"]
1068
- },
1069
- median: {
1070
- meaning: "The middle value once the measured elements are ordered.",
1071
- scope: "graph",
1072
- types: ["number"]
1073
- },
1074
- mean: {
1075
- meaning: "The average value across the measured elements.",
1076
- scope: "graph",
1077
- types: ["number"]
1078
- },
1079
- measured: {
1080
- meaning: "How many elements the run produced a value for. Smaller than the scope when some elements have nothing to measure. Distinct from RunResult.measured, which counts the nodes and edges the run looked at.",
1081
- scope: "graph",
1082
- types: ["integer"]
1083
- },
1084
- normalization: {
1085
- meaning: 'How the values were scaled before publication: "max", "min-max" or "none".',
1086
- scope: "graph",
1087
- types: ["string"]
1088
- },
1089
- tiedAtMin: {
1090
- meaning: "How many measured elements sit at the lowest value, which is what says whether a colour ramp is about to paint most of the graph one colour.",
1091
- scope: "graph",
1092
- types: ["integer"]
1093
- },
1094
- groupCount: {
1095
- meaning: "How many groups the partition has.",
1096
- scope: "graph",
1097
- types: ["integer"]
1098
- },
1099
- modularity: {
1100
- meaning: "How much better this partition is than a random one, from -0.5 to 1.",
1101
- scope: "graph",
1102
- types: ["number"]
1103
- },
1104
- sizes: {
1105
- meaning: "The size of each group or level, largest first.",
1106
- scope: "graph",
1107
- types: ["table"]
1108
- },
1109
- levelCount: {
1110
- meaning: "How many levels the walk reached.",
1111
- scope: "graph",
1112
- types: ["integer"]
1113
- },
1114
- categories: {
1115
- meaning: "One row per category, with its name and how many elements fell into it.",
1116
- scope: "graph",
1117
- types: ["table"]
1118
- },
1119
- length: {
1120
- meaning: "How many nodes are on the route.",
1121
- scope: "graph",
1122
- types: ["integer"]
1123
- },
1124
- cost: {
1125
- meaning: "What the route costs in total, summing the weight of every edge on it.",
1126
- scope: "graph",
1127
- types: ["number"]
1128
- },
1129
- hops: {
1130
- meaning: "How many edges are on the route.",
1131
- scope: "graph",
1132
- types: ["integer"]
1133
- },
1134
- count: {
1135
- meaning: "How many elements are in the set.",
1136
- scope: "graph",
1137
- types: ["integer"]
1138
- },
1139
- pairs: {
1140
- meaning: "One row per scored pair of elements, best first.",
1141
- scope: "graph",
1142
- types: ["table"]
1143
- },
1144
- steps: {
1145
- meaning: "One row per time step, with the step's window and what was visible in it.",
1146
- scope: "graph",
1147
- types: ["table"]
1148
- },
1149
- series: {
1150
- meaning: "One row per tracked quantity, carrying its value at every step.",
1151
- scope: "graph",
1152
- types: ["table"]
1153
- },
1154
- rates: {
1155
- meaning: "One row per tracked quantity, carrying how fast it changed between steps.",
1156
- scope: "graph",
1157
- types: ["table"]
1158
- },
1159
- changeThreshold: {
1160
- meaning: "The rate of change above which a step counts as a change rather than drift.",
1161
- scope: "graph",
1162
- types: ["number"]
1163
- }
1164
- }, Gn = Object.keys(we), J = {
1165
- "node-metric": {
1166
- shape: "node-metric",
1167
- primaryField: "value",
1168
- nodeFields: ["value", "rank", "percentile"],
1169
- edgeFields: [],
1170
- graphFields: ["min", "max", "median", "mean", "measured", "normalization", "tiedAtMin"],
1171
- optionalGraphFields: [],
1172
- headlineScalar: !1,
1173
- layer: "encoding"
1174
- },
1175
- "edge-metric": {
1176
- shape: "edge-metric",
1177
- primaryField: "value",
1178
- nodeFields: [],
1179
- edgeFields: ["value", "rank", "percentile"],
1180
- graphFields: ["min", "max", "median", "mean", "measured", "normalization", "tiedAtMin"],
1181
- optionalGraphFields: [],
1182
- headlineScalar: !1,
1183
- layer: "encoding"
1184
- },
1185
- community: {
1186
- shape: "community",
1187
- primaryField: "group",
1188
- nodeFields: ["group", "groupSize"],
1189
- edgeFields: [],
1190
- graphFields: ["groupCount", "sizes"],
1191
- // Only an algorithm that scores its own partition can publish modularity. Label
1192
- // propagation and connected components do not, and a required field they cannot fill
1193
- // would be a number invented to satisfy a table.
1194
- optionalGraphFields: ["modularity"],
1195
- headlineScalar: !1,
1196
- layer: "encoding"
1197
- },
1198
- "layered-grouping": {
1199
- shape: "layered-grouping",
1200
- primaryField: "level",
1201
- nodeFields: ["level", "levelSize"],
1202
- edgeFields: [],
1203
- graphFields: ["levelCount", "sizes"],
1204
- optionalGraphFields: [],
1205
- headlineScalar: !1,
1206
- layer: "encoding"
1207
- },
1208
- "category-table": {
1209
- shape: "category-table",
1210
- primaryField: "category",
1211
- nodeFields: ["category", "score", "rank"],
1212
- edgeFields: [],
1213
- graphFields: ["categories"],
1214
- optionalGraphFields: [],
1215
- headlineScalar: !1,
1216
- layer: "encoding"
1217
- },
1218
- path: {
1219
- shape: "path",
1220
- primaryField: "onPath",
1221
- nodeFields: ["onPath", "order"],
1222
- // The edges of the route carry membership but not a position: an edge's place in the
1223
- // route is the order of the node it leaves.
1224
- edgeFields: ["onPath"],
1225
- graphFields: ["length", "cost", "hops"],
1226
- optionalGraphFields: [],
1227
- headlineScalar: !1,
1228
- layer: "highlight"
1229
- },
1230
- "node-set": {
1231
- shape: "node-set",
1232
- primaryField: "in",
1233
- nodeFields: ["in"],
1234
- edgeFields: [],
1235
- graphFields: ["count"],
1236
- optionalGraphFields: [],
1237
- headlineScalar: !0,
1238
- layer: "highlight"
1239
- },
1240
- "edge-set": {
1241
- shape: "edge-set",
1242
- primaryField: "in",
1243
- nodeFields: [],
1244
- edgeFields: ["in"],
1245
- graphFields: ["count"],
1246
- optionalGraphFields: [],
1247
- headlineScalar: !0,
1248
- layer: "highlight"
1249
- },
1250
- "pair-list": {
1251
- shape: "pair-list",
1252
- primaryField: "pairs",
1253
- nodeFields: [],
1254
- edgeFields: [],
1255
- graphFields: ["pairs"],
1256
- optionalGraphFields: [],
1257
- headlineScalar: !1,
1258
- layer: "none"
1259
- },
1260
- temporal: {
1261
- shape: "temporal",
1262
- primaryField: "series",
1263
- nodeFields: [],
1264
- edgeFields: [],
1265
- graphFields: ["steps", "series", "rates", "changeThreshold"],
1266
- optionalGraphFields: [],
1267
- headlineScalar: !1,
1268
- layer: "none"
1269
- },
1270
- fact: {
1271
- shape: "fact",
1272
- primaryField: null,
1273
- nodeFields: [],
1274
- edgeFields: [],
1275
- graphFields: [],
1276
- optionalGraphFields: [],
1277
- headlineScalar: !1,
1278
- layer: "none"
1279
- }
1280
- };
1281
- function B(e) {
1282
- return J[e];
1283
- }
1284
- function Un(e) {
1285
- return J[e].layer === "highlight";
1286
- }
1287
- function Hn(e, t) {
1288
- const n = J[e], r = [], i = [
1289
- { names: n.nodeFields, kind: "node" },
1290
- { names: n.edgeFields, kind: "edge" },
1291
- { names: n.graphFields, kind: "graph" }
1292
- ];
1293
- for (const { names: s, kind: o } of i)
1294
- for (const a of s) {
1295
- const u = t.find((h) => h.name === a && h.kind === o);
1296
- if (u === void 0) {
1297
- r.push({
1298
- field: a,
1299
- kind: o,
1300
- reason: `shape "${e}" requires a ${o} field named "${a}"`
1301
- });
1302
- continue;
1303
- }
1304
- const c = we[a].types;
1305
- c.includes(u.type) || r.push({
1306
- field: a,
1307
- kind: o,
1308
- reason: `${o} field "${a}" is typed "${u.type}", not ${c.map((h) => `"${h}"`).join(" or ")}`
1309
- });
1310
- }
1311
- return n.headlineScalar && !Ot(n, t) && r.push({
1312
- field: null,
1313
- kind: "graph",
1314
- reason: `shape "${e}" requires one graph-level scalar of its own beside "count"`
1315
- }), r;
1316
- }
1317
- function Ot(e, t) {
1318
- const n = [...e.graphFields, ...e.optionalGraphFields];
1319
- return t.some((r) => r.kind === "graph" && !n.includes(r.name));
1320
- }
1321
- const kt = 3;
1322
- function Nt(e, t) {
1323
- if (e === t)
1324
- return 0;
1325
- const n = new Uint32Array(t.length + 1), r = new Uint32Array(t.length + 1);
1326
- for (let i = 0; i <= t.length; i++)
1327
- n[i] = i;
1328
- for (let i = 1; i <= e.length; i++) {
1329
- r[0] = i;
1330
- for (let s = 1; s <= t.length; s++) {
1331
- const o = n[s - 1] + (e[i - 1] === t[s - 1] ? 0 : 1);
1332
- r[s] = Math.min(r[s - 1] + 1, n[s] + 1, o);
1333
- }
1334
- n.set(r);
1335
- }
1336
- return n[t.length];
1337
- }
1338
- function St(e, t, n = kt) {
1339
- const r = e.toLowerCase(), i = t.map((s) => ({
1340
- candidate: s,
1341
- distance: Nt(r, s.toLowerCase())
1342
- }));
1343
- return i.sort((s, o) => s.distance - o.distance || s.candidate.localeCompare(o.candidate)), Object.freeze(i.slice(0, Math.max(n, 0)).map((s) => s.candidate));
1344
- }
1345
- function se(e) {
1346
- return typeof e == "string" ? e : "runId" in e ? e.runId : e.id;
1347
- }
1348
- function At(e) {
1349
- return typeof e == "string" ? void 0 : e.shape;
1350
- }
1351
- function $t(e, t) {
1352
- return e.fields.some((n) => n.name === t) || t in e.graph;
1353
- }
1354
- class Rt {
1355
- #e;
1356
- /**
1357
- * Build the API over a registry.
1358
- * @param registry - Where runs are looked up.
1359
- */
1360
- constructor(t) {
1361
- this.#e = t;
1362
- }
1363
- /**
1364
- * The published path of a run's field.
1365
- *
1366
- * With no field the path names the run's primary field -- `value` for a metric, `group` for a
1367
- * partition, `onPath` for a route -- so a caller binds an encoding to a run without knowing
1368
- * what that algorithm calls its number. A `fact` result has no primary field and addresses
1369
- * its whole result object instead.
1370
- * @param run - The run, its result, or its id.
1371
- * @param field - The field name; the shape's primary field when absent.
1372
- * @returns The path.
1373
- */
1374
- path(t, n) {
1375
- const r = se(t);
1376
- if (n !== void 0)
1377
- return T(r, n);
1378
- const i = At(t) ?? this.#e.entry(r)?.shape, s = i === void 0 ? null : B(i).primaryField;
1379
- return s === null ? T(r) : T(r, s);
1380
- }
1381
- /**
1382
- * The same field, written so a selector expression can read it.
1383
- *
1384
- * The quoting is the whole point: a run id carries its algorithm's name, and a hyphenated
1385
- * name lexes its hyphen as subtraction, so a path pasted into an expression unquoted is a
1386
- * refused selector rather than a comparison. Nothing here decides WHICH field -- that is
1387
- * {@link ResultsApi.path}'s job and this defers to it -- so the two can never name different
1388
- * columns.
1389
- * @param run - The run, its result, or its id.
1390
- * @param field - The field name; the shape's primary field when absent.
1391
- * @returns The path with every segment quoted that needs it.
1392
- */
1393
- term(t, n) {
1394
- return yt(n === void 0 ? this.path(t) : this.path(t, n));
1395
- }
1396
- /**
1397
- * One run's result.
1398
- *
1399
- * The answer always comes from the registry, even when the caller passed a result object: the
1400
- * question is what this session holds, and a result the session never registered is not it.
1401
- * @param run - The run, its result, or its id.
1402
- * @returns The result, or undefined when the session holds no such run or it has not
1403
- * finished.
1404
- */
1405
- get(t) {
1406
- return this.#e.entry(se(t))?.result;
1407
- }
1408
- /**
1409
- * Whether a run, or one of its fields, is available to read.
1410
- * @param run - The run, its result, or its id.
1411
- * @param field - The field name; asks only about the run itself when absent.
1412
- * @returns True when the path would resolve.
1413
- */
1414
- has(t, n) {
1415
- const r = this.get(t);
1416
- return r === void 0 ? !1 : n === void 0 || $t(r, n);
1417
- }
1418
- /**
1419
- * Every run that has published a result, as an expression editor reads them.
1420
- * @returns One root per finished run, in the order the runs were started.
1421
- */
1422
- get roots() {
1423
- const t = [];
1424
- for (const n of this.#e.entries())
1425
- n.result !== void 0 && t.push(Object.freeze({ runId: n.id, label: n.label, fields: n.result.fields }));
1426
- return Object.freeze(t);
1427
- }
1428
- }
1429
- function Bn(e) {
1430
- return new Rt(e);
1431
- }
1432
- const Et = 20, j = 100, Ft = 100, It = Object.freeze([]), Tt = Object.freeze(["max", "min-max", "none"]);
1433
- function ve(e) {
1434
- return typeof e == "string" && Tt.includes(e);
1435
- }
1436
- function Vn(e) {
1437
- return {
1438
- length: e.length,
1439
- get: (t) => e[t]
1440
- };
1441
- }
1442
- const Mt = Object.freeze({
1443
- measured: 0,
1444
- min: Number.NaN,
1445
- max: Number.NaN,
1446
- mean: Number.NaN,
1447
- median: Number.NaN,
1448
- tiedAtMin: 0,
1449
- smallestPositive: null
1450
- });
1451
- function Oe(e) {
1452
- const { length: t } = e, n = new Float64Array(t);
1453
- let r = 0;
1454
- for (let l = 0; l < t; l++) {
1455
- const d = e.get(l);
1456
- Number.isFinite(d) && (n[r] = d, r++);
1457
- }
1458
- if (r === 0)
1459
- return { length: t, ...Mt };
1460
- let i = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY, o = Number.POSITIVE_INFINITY, a = 0, u = 0;
1461
- for (let l = 0; l < r; l++) {
1462
- const d = n[l];
1463
- d < i && (i = d), d > s && (s = d), d > 0 && d < o && (o = d);
1464
- const v = d - u, k = a + v;
1465
- u = k - a - v, a = k;
1466
- }
1467
- const c = n.slice(0, r).sort(), h = c[Math.floor((r - 1) / 2)];
1468
- let p = 0;
1469
- for (; p < r && c[p] === i; )
1470
- p++;
1471
- return {
1472
- length: t,
1473
- measured: r,
1474
- min: i,
1475
- max: s,
1476
- mean: a / r,
1477
- median: h,
1478
- tiedAtMin: p,
1479
- smallestPositive: Number.isFinite(o) ? o : null
1480
- };
1481
- }
1482
- function ke(e) {
1483
- const t = Oe(e);
1484
- return { view: Object.freeze({
1485
- length: e.length,
1486
- get: (r) => e.get(r),
1487
- min: t.min,
1488
- max: t.max,
1489
- mean: t.mean,
1490
- median: t.median
1491
- }), statistics: t };
1492
- }
1493
- function q(e) {
1494
- const t = e.filter((o) => Number.isFinite(o.value)).map((o) => ({ entry: o, label: String(o.id) }));
1495
- t.sort((o, a) => o.entry.value !== a.entry.value ? a.entry.value - o.entry.value : o.label === a.label ? 0 : o.label < a.label ? -1 : 1);
1496
- const n = t.length, r = [];
1497
- let i = 0, s = Number.NaN;
1498
- for (let o = 0; o < n; o++) {
1499
- const { entry: a } = t[o];
1500
- a.value !== s && (i = o + 1, s = a.value), r.push(
1501
- Object.freeze({
1502
- id: a.id,
1503
- value: a.value,
1504
- rank: i,
1505
- percentile: (n - i + 1) / n
1506
- })
1507
- );
1508
- }
1509
- return Object.freeze(r);
1510
- }
1511
- function _t(e, t) {
1512
- let n = Math.min(t, e.length);
1513
- for (; n > 0 && n < e.length && e[n].rank === e[n - 1].rank; )
1514
- n--;
1515
- if (n === e.length || n === t)
1516
- return Object.freeze({ entries: e.slice(0, n), leftOut: null, reason: null });
1517
- const { value: r } = e[n];
1518
- let i = n;
1519
- for (; i < e.length && e[i].value === r; )
1520
- i++;
1521
- const s = i - n, o = `${String(s)} tie at ${String(r)}, and taking them would make ${String(n + s)}, more than the ${String(t)} asked for, so ${n === 0 ? "none are" : `only the top ${String(n)} are`} taken.`;
1522
- return Object.freeze({
1523
- entries: e.slice(0, n),
1524
- leftOut: Object.freeze({ value: r, count: s }),
1525
- reason: o
1526
- });
1527
- }
1528
- function zt(e) {
1529
- const { smallestPositive: t } = e;
1530
- if (e.measured === 0 || !(e.max > 0) || t === null)
1531
- return !1;
1532
- const n = e.min > 0 ? e.min : t;
1533
- return Math.log10(e.max) > Math.log10(n);
1534
- }
1535
- function Ct(e) {
1536
- return e.measured === 0 || !(e.median > 0) || e.max / e.median <= Ft ? "linear" : zt(e) ? "log" : "linear";
1537
- }
1538
- function xt(e, t, n, r) {
1539
- if (!(t > e))
1540
- return { binCount: 1, indexOf: () => 0, rangeOf: () => [e, t] };
1541
- if (r) {
1542
- const s = t - e + 1, o = Math.ceil(s / Math.min(s, n)), a = Math.ceil(s / o);
1543
- return {
1544
- binCount: a,
1545
- indexOf: (u) => Math.min(Math.floor((u - e) / o), a - 1),
1546
- rangeOf: (u) => {
1547
- const c = e + u * o;
1548
- return [c, Math.min(c + o - 1, t)];
1549
- }
1550
- };
1551
- }
1552
- const i = (t - e) / n;
1553
- return {
1554
- binCount: n,
1555
- indexOf: (s) => Math.min(Math.floor((s - e) / i), n - 1),
1556
- rangeOf: (s) => [
1557
- e + s * i,
1558
- s === n - 1 ? t : e + (s + 1) * i
1559
- ]
1560
- };
1561
- }
1562
- function jt(e, t, n, r, i) {
1563
- const s = e > 0 ? 0 : 1, o = s === 0 ? e : n;
1564
- if (!(t > 0) || o === null || !(o > 0))
1565
- return null;
1566
- const a = Math.log10(o), u = Math.log10(t);
1567
- if (!(u > a))
1568
- return null;
1569
- const c = r - s;
1570
- if (c < 1)
1571
- return null;
1572
- const h = (u - a) / c;
1573
- return {
1574
- binCount: r,
1575
- indexOf: (p) => {
1576
- if (!(p > 0))
1577
- return 0;
1578
- const l = Math.floor((Math.log10(p) - a) / h);
1579
- return s + Math.min(Math.max(l, 0), c - 1);
1580
- },
1581
- rangeOf: (p) => {
1582
- if (p < s)
1583
- return [e, 0];
1584
- const l = p - s, d = l === 0 ? o : 10 ** (a + l * h), v = l === c - 1 ? t : 10 ** (a + (l + 1) * h);
1585
- if (!i)
1586
- return [d, v];
1587
- const k = l === 0 ? o : Math.ceil(d);
1588
- return [k, l === c - 1 ? t : Math.max(k, Math.ceil(v) - 1)];
1589
- }
1590
- };
1591
- }
1592
- function Pt(e) {
1593
- if (e === void 0)
1594
- return Et;
1595
- if (!Number.isInteger(e) || e < 1 || e > j)
1596
- throw new y({
1597
- code: "E_OPTION_RANGE",
1598
- source: "run",
1599
- message: `A histogram takes between 1 and ${j} bins; ${String(e)} was asked for.`,
1600
- details: { option: "bins", value: e, min: 1, max: j }
1601
- });
1602
- return e;
1603
- }
1604
- function Lt(e, t) {
1605
- const n = /* @__PURE__ */ new Map();
1606
- for (let r = 0; r < e.length; r++) {
1607
- const i = e.get(r);
1608
- if (!Number.isFinite(i))
1609
- continue;
1610
- const s = n.get(i);
1611
- if (s === void 0) {
1612
- if (n.size >= t)
1613
- return null;
1614
- n.set(i, 1);
1615
- continue;
1616
- }
1617
- n.set(i, s + 1);
1618
- }
1619
- return n;
1620
- }
1621
- function Dt(e, t) {
1622
- const n = Pt(t?.bins), r = t?.integerValued ?? !1, i = Oe(e), s = Ct(i), o = Lt(e, n);
1623
- if (o !== null) {
1624
- if (o.size === 0)
1625
- return Object.freeze({
1626
- bins: It,
1627
- // Nothing was measured, so nothing is on any axis. Reported as linear rather
1628
- // than as the request, because "log scale" over an empty chart is the same false
1629
- // caption this whole return type exists to prevent.
1630
- scale: "linear",
1631
- suggestedScale: "linear",
1632
- binning: "empty"
1633
- });
1634
- const p = [...o.entries()].sort((l, d) => l[0] - d[0]).map(([l, d]) => Object.freeze({ from: l, to: l, count: d }));
1635
- return Object.freeze({
1636
- bins: Object.freeze(p),
1637
- // One bar per distinct value has no bands to space, so neither axis was applied to
1638
- // it. Saying "linear" here is what stops a caption claiming a logarithmic layout of
1639
- // a chart that has none.
1640
- scale: "linear",
1641
- suggestedScale: s,
1642
- binning: "per-value"
1643
- });
1644
- }
1645
- const u = t?.scale === "log" || t?.scale === "auto" && s === "log" ? jt(i.min, i.max, i.smallestPositive, n, r) : null, c = u ?? xt(i.min, i.max, n, r), h = new Array(c.binCount).fill(0);
1646
- for (let p = 0; p < e.length; p++) {
1647
- const l = e.get(p);
1648
- Number.isFinite(l) && (h[c.indexOf(l)] += 1);
1649
- }
1650
- return Object.freeze({
1651
- bins: Object.freeze(
1652
- h.map((p, l) => {
1653
- const [d, v] = c.rangeOf(l);
1654
- return Object.freeze({ from: d, to: v, count: p });
1655
- })
1656
- ),
1657
- // `plan` is null exactly when a logarithmic layout was asked for and could not be built,
1658
- // which is the case a caption must not get wrong.
1659
- scale: u === null ? "linear" : "log",
1660
- suggestedScale: s,
1661
- binning: "banded"
1662
- });
1663
- }
1664
- const Gt = 10, Ut = 10;
1665
- function oe(e) {
1666
- const t = { ids: [], records: [], index: /* @__PURE__ */ new Map() };
1667
- if (e === void 0)
1668
- return t;
1669
- for (const n of e) {
1670
- const r = t.index.get(n.id);
1671
- if (r === void 0) {
1672
- t.index.set(n.id, t.ids.length), t.ids.push(n.id), t.records.push({ ...n.values });
1673
- continue;
1674
- }
1675
- Object.assign(t.records[r], n.values);
1676
- }
1677
- return t;
1678
- }
1679
- function V(e, t) {
1680
- const { records: n } = e;
1681
- return {
1682
- length: n.length,
1683
- get: (r) => Ne(n[r][t])
1684
- };
1685
- }
1686
- function Y(e, t) {
1687
- return e.ids.map((n, r) => ({ id: n, value: Ne(e.records[r][t]) }));
1688
- }
1689
- function Ne(e) {
1690
- return typeof e == "number" ? e : Number.NaN;
1691
- }
1692
- function W(e) {
1693
- return typeof e == "string" || typeof e == "number";
1694
- }
1695
- function P(e) {
1696
- return e.type === "number" || e.type === "integer";
1697
- }
1698
- function g(e, t, n) {
1699
- e[t] === void 0 && (e[t] = n);
1700
- }
1701
- function M(e, t, n) {
1702
- e[t] === void 0 && (e[t] = n);
1703
- }
1704
- function Se(e, t) {
1705
- const n = /* @__PURE__ */ new Map();
1706
- for (const r of e.records) {
1707
- const i = r[t];
1708
- W(i) && n.set(i, (n.get(i) ?? 0) + 1);
1709
- }
1710
- return n;
1711
- }
1712
- function Ht(e) {
1713
- const t = [...e.entries()].map(([n, r]) => ({ group: n, size: r }));
1714
- return t.sort((n, r) => r.size - n.size || be(n.group, r.group)), Object.freeze(t.map((n) => Object.freeze(n)));
1715
- }
1716
- function Ae(e, t) {
1717
- const n = e.find((r) => r.name === t)?.normalization;
1718
- return ve(n) ? n : "none";
1719
- }
1720
- function ae(e, t, n) {
1721
- const { statistics: r } = ke(V(e, "value"));
1722
- for (const i of q(Y(e, "value"))) {
1723
- const s = e.index.get(i.id);
1724
- s !== void 0 && (M(e.records[s], "rank", i.rank), M(e.records[s], "percentile", i.percentile));
1725
- }
1726
- r.measured > 0 && (g(t, "min", r.min), g(t, "max", r.max), g(t, "median", r.median), g(t, "mean", r.mean)), g(t, "measured", r.measured), g(t, "tiedAtMin", r.tiedAtMin), g(t, "normalization", Ae(n, "value"));
1727
- }
1728
- function ce(e, t, n, r, i) {
1729
- const s = Se(e, n);
1730
- for (const o of e.records) {
1731
- const a = o[n];
1732
- W(a) && M(o, r, s.get(a));
1733
- }
1734
- g(t, i, s.size), g(t, "sizes", Ht(s));
1735
- }
1736
- function Bt(e, t) {
1737
- for (const r of q(Y(e, "score"))) {
1738
- const i = e.index.get(r.id);
1739
- i !== void 0 && M(e.records[i], "rank", r.rank);
1740
- }
1741
- const n = [...Se(e, "category").entries()].map(([r, i]) => ({
1742
- category: String(r),
1743
- count: i
1744
- }));
1745
- n.sort((r, i) => i.count - r.count || be(r.category, i.category)), g(t, "categories", Object.freeze(n.map((r) => Object.freeze(r))));
1746
- }
1747
- function F(e, t) {
1748
- let n = 0;
1749
- for (const r of e.records)
1750
- r[t] === !0 && n++;
1751
- return n;
1752
- }
1753
- function ue(e, t) {
1754
- let n = 0;
1755
- for (const r of e.records)
1756
- r[t] !== void 0 && n++;
1757
- return n;
1758
- }
1759
- function Vt(e, t, n, r, i) {
1760
- switch (e) {
1761
- case "node-metric":
1762
- ae(t, r, i);
1763
- break;
1764
- case "edge-metric":
1765
- ae(n, r, i);
1766
- break;
1767
- case "community":
1768
- ce(t, r, "group", "groupSize", "groupCount");
1769
- break;
1770
- case "layered-grouping":
1771
- ce(t, r, "level", "levelSize", "levelCount");
1772
- break;
1773
- case "category-table":
1774
- Bt(t, r);
1775
- break;
1776
- case "path":
1777
- g(r, "length", F(t, "onPath")), g(r, "hops", F(n, "onPath"));
1778
- break;
1779
- case "node-set":
1780
- g(r, "count", F(t, "in"));
1781
- break;
1782
- case "edge-set":
1783
- g(r, "count", F(n, "in"));
1784
- break;
1785
- }
1786
- }
1787
- function Jt(e) {
1788
- switch (e) {
1789
- case "node-metric":
1790
- case "edge-metric":
1791
- return "value";
1792
- case "category-table":
1793
- return "score";
1794
- case "layered-grouping":
1795
- return "level";
1796
- default:
1797
- return null;
1798
- }
1799
- }
1800
- function qt(e, t, n) {
1801
- if (!Array.isArray(e))
1802
- return;
1803
- const r = [];
1804
- for (const i of e) {
1805
- if (typeof i != "object" || i === null)
1806
- continue;
1807
- const s = i, o = s.group ?? s.category, a = s.size ?? s.count;
1808
- if (W(o) && typeof a == "number" && r.push(Object.freeze(n ? { group: o, size: a, name: vt(r.length + 1) } : { group: o, size: a })), r.length === t)
1809
- break;
1810
- }
1811
- return Object.freeze(r);
1812
- }
1813
- class Yt {
1814
- #e;
1815
- #t;
1816
- #n;
1817
- #r;
1818
- #i;
1819
- #s;
1820
- #o = /* @__PURE__ */ new Map();
1821
- #a = /* @__PURE__ */ new Map();
1822
- #c = /* @__PURE__ */ new Map();
1823
- #u;
1824
- /**
1825
- * Build a result around storage that has already been filled and frozen.
1826
- * @param init - What the run published.
1827
- * @param nodes - The published nodes.
1828
- * @param edges - The published edges.
1829
- * @param graph - The graph half, frozen.
1830
- */
1831
- constructor(t, n, r, i) {
1832
- this.runId = t.runId, this.shape = t.shape, this.fields = Object.freeze([...t.fields]), this.measured = Object.freeze({ nodes: t.measured.nodes, edges: t.measured.edges }), this.graph = i, this.#e = n, this.#t = r, this.#n = t.caveats, this.#r = t.durationMs, this.#i = t.labelOf ?? (() => {
1833
- }), this.#s = t.reading ?? nt;
1834
- }
1835
- /**
1836
- * One node's fields.
1837
- * @param id - The node id.
1838
- * @returns The fields, or undefined when the run produced nothing for that node.
1839
- */
1840
- node(t) {
1841
- const n = this.#e.index.get(t);
1842
- return n === void 0 ? void 0 : this.#e.records[n];
1843
- }
1844
- /**
1845
- * One edge's fields.
1846
- * @param id - The edge id.
1847
- * @returns The fields, or undefined when the run produced nothing for that edge.
1848
- */
1849
- edge(t) {
1850
- const n = this.#t.index.get(t);
1851
- return n === void 0 ? void 0 : this.#t.records[n];
1852
- }
1853
- /**
1854
- * One numeric field as a column.
1855
- *
1856
- * The view reads straight through to the result's own storage and its four figures were
1857
- * computed on the first call, so a histogram, a colour ramp's domain and a summary all walk
1858
- * one column rather than three copies of it.
1859
- * @param field - The field name.
1860
- * @returns A view over the values, without an object per element.
1861
- * @throws A GraphtyError coded E_UNKNOWN_ATTRIBUTE when the run published no such field, or
1862
- * E_BAD_COMMAND when the field is not a number published per element.
1863
- */
1864
- column(t) {
1865
- return this.#h(t).view;
1866
- }
1867
- /**
1868
- * The highest-ranked elements on one field.
1869
- *
1870
- * Elements with equal values share a rank and come back in printed-id order, so the top of a
1871
- * ranking does not reshuffle between two runs that measured the same thing.
1872
- * @param field - The field to rank on.
1873
- * @param limit - How many entries to return; the whole ranking when absent.
1874
- * @returns The entries, best first.
1875
- * @throws A GraphtyError coded E_OPTION_RANGE when the limit is not a whole number of
1876
- * entries, E_UNKNOWN_ATTRIBUTE when the run published no such field, or E_BAD_COMMAND when
1877
- * the field is not a number published per element.
1878
- */
1879
- ranking(t, n) {
1880
- n !== void 0 && this.#l(n, "limit");
1881
- const r = this.#a.get(t) ?? this.#f(t);
1882
- return n === void 0 ? r : Object.freeze(r.slice(0, n));
1883
- }
1884
- /**
1885
- * The top `n` elements on one field, cut only between tie groups: a group of equal values is
1886
- * taken whole, and only when all of it fits inside `n`. Kept per field and `n`, because a
1887
- * top selector asks once per element it paints.
1888
- * @param field - The field to rank on.
1889
- * @param n - The most elements the top may hold.
1890
- * @returns The elements taken, and the tie group left out when there was one.
1891
- * @throws A GraphtyError coded E_OPTION_RANGE when n is not a whole number of entries,
1892
- * E_UNKNOWN_ATTRIBUTE when the run published no such field, or E_BAD_COMMAND when the
1893
- * field is not a number published per element.
1894
- */
1895
- top(t, n) {
1896
- const r = `${String(n)}:${t}`, i = this.#c.get(r);
1897
- if (i !== void 0)
1898
- return i;
1899
- const s = _t(this.ranking(t), this.#l(n, "n"));
1900
- return this.#c.set(r, s), s;
1901
- }
1902
- /**
1903
- * Refuse a count of entries that is not a whole number.
1904
- * @param limit - The count.
1905
- * @param option - What the caller called it, for the refusal.
1906
- * @returns The count.
1907
- * @throws A GraphtyError coded E_OPTION_RANGE when it is not a whole number of entries.
1908
- */
1909
- #l(t, n) {
1910
- if (!Number.isInteger(t) || t < 0)
1911
- throw new y({
1912
- code: "E_OPTION_RANGE",
1913
- source: "run",
1914
- message: `A ranking limit is a whole number of entries, not ${String(t)}.`,
1915
- details: { option: n, value: t, min: 0 },
1916
- target: { kind: "run", id: this.runId }
1917
- });
1918
- return t;
1919
- }
1920
- /**
1921
- * The distribution of one numeric field.
1922
- *
1923
- * Whether the field counts things is read off its own descriptor rather than passed in, so a
1924
- * count metric gets whole-number band edges without the caller knowing that it should.
1925
- * @param field - The field to bin.
1926
- * @param options - How to cut the bins.
1927
- * @returns The distribution, carrying the scale that was applied as well as the bars.
1928
- * @throws A GraphtyError coded E_OPTION_RANGE when the bin count is outside the permitted
1929
- * range, E_UNKNOWN_ATTRIBUTE when the run published no such field, or E_BAD_COMMAND when
1930
- * the field is not a number published per element.
1931
- */
1932
- histogram(t, n) {
1933
- const r = this.#d(t), i = r.kind === "edge" ? this.#t : this.#e;
1934
- return Dt(V(i, t), {
1935
- ...n,
1936
- integerValued: r.type === "integer"
1937
- });
1938
- }
1939
- /**
1940
- * The bounded form of this result.
1941
- *
1942
- * Everything on it is either a single figure or a list the element cut to a fixed length, so
1943
- * the object is the same size for a graph of a hundred nodes and a graph of a million.
1944
- * @returns The summary.
1945
- */
1946
- summary() {
1947
- return this.#u ??= this.#g(), this.#u;
1948
- }
1949
- /**
1950
- * What this result means, in one sentence of plain language.
1951
- * @param options - The locale and how technical to be.
1952
- * @returns The sentence.
1953
- */
1954
- reading(t) {
1955
- return this.#s(this, t ?? {});
1956
- }
1957
- /**
1958
- * The descriptor of one numeric per-element field, without complaining when there is none.
1959
- *
1960
- * A summary asks this rather than {@link Result.#descriptorFor} because a summary must not
1961
- * throw: a run whose field list does not declare the field its shape calls primary is a
1962
- * defect in that run, and the summary's job is to say what it can about the result rather
1963
- * than to refuse to describe it at all.
1964
- * @param field - The field name.
1965
- * @returns Its descriptor, or null when the run published no numeric field under that name.
1966
- */
1967
- #m(t) {
1968
- const n = this.fields.find((r) => r.name === t && r.kind !== "graph");
1969
- return n !== void 0 && P(n) ? n : null;
1970
- }
1971
- /**
1972
- * The descriptor of one numeric field the run published per element.
1973
- * @param field - The field name.
1974
- * @returns Its descriptor.
1975
- * @throws A GraphtyError naming what went wrong, with the readable fields in its details.
1976
- */
1977
- #d(t) {
1978
- const n = this.fields.filter((s) => s.name === t), r = n.find((s) => s.kind !== "graph"), i = this.fields.filter((s) => s.kind !== "graph" && P(s)).map((s) => s.name);
1979
- if (r === void 0)
1980
- throw n.length > 0 ? new y({
1981
- code: "E_BAD_COMMAND",
1982
- source: "run",
1983
- message: `"${t}" is a graph-level field of run "${this.runId}"; read it from result.graph.`,
1984
- details: { field: t, kind: "graph", available: i },
1985
- target: { kind: "run", id: this.runId }
1986
- }) : new y({
1987
- code: "E_UNKNOWN_ATTRIBUTE",
1988
- source: "run",
1989
- message: `Run "${this.runId}" published no field named "${t}".`,
1990
- details: { field: t, available: i, candidates: St(t, i) },
1991
- target: { kind: "run", id: this.runId }
1992
- });
1993
- if (!P(r))
1994
- throw new y({
1995
- code: "E_BAD_COMMAND",
1996
- source: "run",
1997
- message: `"${t}" is typed "${r.type}", which is not a column of numbers.`,
1998
- details: { field: t, type: r.type, available: i },
1999
- target: { kind: "run", id: this.runId }
2000
- });
2001
- return r;
2002
- }
2003
- /**
2004
- * The half of the result a per-element field belongs to.
2005
- * @param field - The field name.
2006
- * @returns The nodes or the edges.
2007
- * @throws A GraphtyError naming what went wrong.
2008
- */
2009
- #p(t) {
2010
- return this.#d(t).kind === "edge" ? this.#t : this.#e;
2011
- }
2012
- /**
2013
- * One field's column and statistics, computed on the first ask and kept.
2014
- * @param field - The field name.
2015
- * @returns The view and the statistics behind it.
2016
- * @throws A GraphtyError naming what went wrong.
2017
- */
2018
- #h(t) {
2019
- const n = this.#o.get(t);
2020
- if (n !== void 0)
2021
- return n;
2022
- const r = ke(V(this.#p(t), t));
2023
- return this.#o.set(t, r), r;
2024
- }
2025
- /**
2026
- * Rank one field for the first time and keep the answer.
2027
- * @param field - The field to rank on.
2028
- * @returns The whole ranking, best first.
2029
- * @throws A GraphtyError naming what went wrong.
2030
- */
2031
- #f(t) {
2032
- const n = q(Y(this.#p(t), t));
2033
- return this.#a.set(t, n), n;
2034
- }
2035
- /**
2036
- * Build the bounded form of this result.
2037
- * @returns The summary.
2038
- */
2039
- #g() {
2040
- const t = Jt(this.shape), n = t === null || this.#m(t) === null ? null : t, r = n === null ? null : this.#h(n).statistics, i = r !== null && r.measured > 0 ? r : null, s = n === null ? [] : this.ranking(n, Gt).map(
2041
- (c) => Object.freeze({
2042
- id: c.id,
2043
- label: this.#i(c.id) ?? String(c.id),
2044
- value: c.value,
2045
- rank: c.rank,
2046
- percentile: c.percentile
2047
- })
2048
- ), o = {
2049
- count: this.#y(),
2050
- measured: r === null ? this.#b() : r.measured,
2051
- min: i === null ? null : i.min,
2052
- max: i === null ? null : i.max,
2053
- median: i === null ? null : i.median,
2054
- mean: i === null ? null : i.mean,
2055
- tiedAtMin: r === null ? 0 : r.tiedAtMin,
2056
- normalization: this.#w(n),
2057
- top: Object.freeze(s),
2058
- caveats: this.#n,
2059
- durationMs: this.#r
2060
- }, a = this.graph.sizes ?? this.graph.categories, u = qt(a, Ut, this.shape === "community");
2061
- return Object.freeze(u === void 0 ? o : { ...o, groups: u });
2062
- }
2063
- /**
2064
- * How many elements this result was computed over.
2065
- *
2066
- * A shape publishes per-element fields for nodes, for edges or for neither, and the scope a
2067
- * summary reports is the half or halves it actually measures. A shape that publishes nothing
2068
- * per element reports none, rather than borrowing the graph's size to look busy.
2069
- * @returns The count.
2070
- */
2071
- #y() {
2072
- const t = B(this.shape), n = t.nodeFields.length > 0 ? this.measured.nodes : 0, r = t.edgeFields.length > 0 ? this.measured.edges : 0;
2073
- return n + r;
2074
- }
2075
- /**
2076
- * How many elements carry the shape's primary field, for a shape that measures no number.
2077
- * @returns The count.
2078
- */
2079
- #b() {
2080
- const t = B(this.shape), { primaryField: n } = t;
2081
- if (n === null)
2082
- return 0;
2083
- const r = t.nodeFields.includes(n) ? ue(this.#e, n) : 0, i = t.edgeFields.includes(n) ? ue(this.#t, n) : 0;
2084
- return r + i;
2085
- }
2086
- /**
2087
- * How this result's values were scaled.
2088
- * @param valueField - The field a summary describes, or null when the shape measures no
2089
- * number.
2090
- * @returns The normalisation the run published, the one its field declares, or "none".
2091
- */
2092
- #w(t) {
2093
- const n = this.graph.normalization;
2094
- return ve(n) ? n : t === null ? "none" : Ae(this.fields, t);
2095
- }
2096
- }
2097
- function Wt(e) {
2098
- const t = oe(e.nodes), n = oe(e.edges), r = { ...e.graph };
2099
- Vt(e.shape, t, n, r, e.fields);
2100
- for (const i of t.records)
2101
- Object.freeze(i);
2102
- for (const i of n.records)
2103
- Object.freeze(i);
2104
- return new Yt(e, t, n, Object.freeze(r));
2105
- }
2106
- function Kt(e) {
2107
- const t = e.styles?.config.data.knownFields.nodeLabelPath ?? null;
2108
- if (t === null)
2109
- return;
2110
- const n = e.getDataManager();
2111
- return (r) => {
2112
- const i = n.getNode(r)?.data[t];
2113
- return typeof i == "string" || typeof i == "number" ? String(i) : void 0;
2114
- };
2115
- }
2116
- function Jn(e) {
2117
- return { exact: !0, precision: "f64", notes: [], ...e };
2118
- }
2119
- const Zt = 1024, Xt = 16;
2120
- function Qt() {
2121
- return {
2122
- signal: new AbortController().signal,
2123
- report: () => {
2124
- },
2125
- yieldNow: () => new Promise((e) => {
2126
- setTimeout(e, 0);
2127
- })
2128
- };
2129
- }
2130
- async function qn(e, t, n, r) {
2131
- const i = n.length;
2132
- e.report({ phase: t, completed: 0, total: i });
2133
- let s = performance.now();
2134
- for (let o = 0; o < i; o++)
2135
- o > 0 && o % Zt === 0 && (e.signal.throwIfAborted(), e.report({ phase: t, completed: o, total: i }), performance.now() - s >= Xt && (await e.yieldNow(), s = performance.now())), r(n[o], o);
2136
- e.signal.throwIfAborted(), e.report({ phase: t, completed: i, total: i });
2137
- }
2138
- function en(e, t, n) {
2139
- const r = n?.find((s) => s.name === e.name && s.kind === e.kind), i = {
2140
- name: e.name,
2141
- plainName: r?.plainName ?? e.name,
2142
- technicalName: r?.technicalName ?? e.name,
2143
- kind: e.kind,
2144
- type: e.type,
2145
- path: T(t, e.name),
2146
- ...r?.unit === void 0 ? {} : { unit: r.unit }
2147
- };
2148
- return e.normalization === void 0 ? i : { ...i, normalization: e.normalization };
2149
- }
2150
- class Yn extends D {
2151
- /** What the last run published, kept so a caller holding the algorithm can read the result. */
2152
- #e;
2153
- /**
2154
- * Fill in what the caller did not pass, and refuse what this algorithm does not declare.
2155
- *
2156
- * ONE DECLARATION, NOT TWO. `descriptor.options` is the only list a declared algorithm
2157
- * writes, and this is what makes that true at the point the values reach the running code:
2158
- * the same descriptors the catalogue hands a picker are what the caller's values are checked
2159
- * against. The older `static optionsSchema` remains the answer for a class that declares no
2160
- * descriptor, which is every algorithm the element itself ships.
2161
- *
2162
- * It also fixes the failure vocabulary on the way in. The older schema throws an uncoded
2163
- * `Error` for a bad value and SILENTLY DROPS a name it does not know, where the run path
2164
- * refuses the same name with `E_UNKNOWN_OPTION` -- so the same mistake produced three
2165
- * different outcomes depending on which door the caller came through.
2166
- * @param options - What the caller asked for.
2167
- * @returns Every declared option, with the caller's values where they were given and the
2168
- * declared defaults everywhere else.
2169
- * @throws A `GraphtyError` with `E_UNKNOWN_OPTION` for a name this algorithm does not
2170
- * declare, or `E_OPTION_RANGE` for a value it would not accept.
2171
- */
2172
- resolveOptions(t) {
2173
- const { descriptor: n } = this.constructor;
2174
- return n === void 0 ? super.resolveOptions(t) : _e(n.options, t ?? {}, {
2175
- kind: "algorithm",
2176
- id: n.key
2177
- });
2178
- }
2179
- /**
2180
- * What the last run published.
2181
- *
2182
- * THE REPLACEMENT FOR `algorithmResults`. The 1.x entry point used to scatter its numbers onto
2183
- * the render objects under names it chose for itself, and the only way back to them was to
2184
- * walk the graph. It returns a result object now, and this is where the 1.x `run()` leaves it,
2185
- * so the old call shape still has somewhere to read from.
2186
- * @returns The result, or undefined when nothing has run or there was nothing to compute.
2187
- */
2188
- get result() {
2189
- return this.#e;
2190
- }
2191
- /**
2192
- * Run the algorithm and publish what it produced on the 1.x result paths.
2193
- *
2194
- * The 1.x entry point: it returns nothing, and it publishes under the algorithm's own type
2195
- * rather than under a run id, because there is no run behind it. Whoever wants the result
2196
- * calls {@link DeclaredAlgorithm.computeRun}, which is the same work with a run in front of
2197
- * it.
2198
- * @returns A promise that settles when the result has been published.
2199
- */
2200
- async run() {
2201
- await this.computeRun(Qt(), this.type);
2202
- }
2203
- /**
2204
- * Compute on behalf of a run, and hand the result back.
2205
- *
2206
- * The run machinery's entry point, which is {@link DeclaredAlgorithm.computeRun} under the
2207
- * name every algorithm answers to.
2208
- * @param context - A signal, a progress channel and a yield.
2209
- * @param runId - The id the result is published under.
2210
- * @param fields - The catalogue's descriptors for this algorithm's fields.
2211
- * @returns The result, or undefined when there was nothing to compute.
2212
- * @throws Whatever the context's signal throws once the run has been cancelled.
2213
- */
2214
- publishResult(t, n, r) {
2215
- return this.computeRun(t, n, r);
2216
- }
2217
- /**
2218
- * Compute this algorithm's result, publish it under a run id, and project the 1.x view of it.
2219
- *
2220
- * This is what the run executor calls. The catalogue's own field descriptors are passed in
2221
- * because the catalogue states what a reader sees a field called and cannot be imported here
2222
- * without a cycle -- it reads these classes to publish their options.
2223
- * @param context - What the element gave the run: a signal, a progress channel and a yield.
2224
- * @param runId - The id the result is published under, which is the `<runId>` in
2225
- * `results.<runId>`.
2226
- * @param declared - The catalogue's descriptors for this algorithm's fields, when the caller
2227
- * holds them.
2228
- * @returns The result, or undefined when there was nothing to compute.
2229
- * @throws Whatever the context's signal throws once the run has been cancelled, which is a
2230
- * `DOMException` named `AbortError`.
2231
- */
2232
- async computeRun(t, n, r) {
2233
- const i = Date.now(), s = await this.compute(t);
2234
- if (s === null)
2235
- return;
2236
- const o = this.graph.getDataManager(), a = Kt(this.graph), u = Wt({
2237
- ...a === void 0 ? {} : { labelOf: a },
2238
- runId: n,
2239
- shape: s.shape,
2240
- fields: s.fields.map((c) => en(c, n, r)),
2241
- measured: { nodes: o.nodes.size, edges: o.edges.size },
2242
- graph: s.graph,
2243
- nodes: s.nodes,
2244
- edges: s.edges,
2245
- caveats: s.caveats,
2246
- durationMs: Date.now() - i
2247
- });
2248
- return this.#e = u, u;
2249
- }
2250
- }
2251
- function Wn(e, t = "number") {
2252
- return [
2253
- { name: "value", kind: e, type: t },
2254
- { name: "rank", kind: e, type: "integer" },
2255
- { name: "percentile", kind: e, type: "number" },
2256
- { name: "min", kind: "graph", type: "number" },
2257
- { name: "max", kind: "graph", type: "number" },
2258
- { name: "median", kind: "graph", type: "number" },
2259
- { name: "mean", kind: "graph", type: "number" },
2260
- { name: "measured", kind: "graph", type: "integer" },
2261
- { name: "normalization", kind: "graph", type: "string" },
2262
- { name: "tiedAtMin", kind: "graph", type: "integer" }
2263
- ];
2264
- }
2265
- const le = [
2266
- { name: "group", kind: "node", type: "integer" },
2267
- { name: "groupSize", kind: "node", type: "integer" },
2268
- { name: "groupCount", kind: "graph", type: "integer" },
2269
- { name: "sizes", kind: "graph", type: "table" }
2270
- ];
2271
- function Kn(e) {
2272
- return e ? [...le, { name: "modularity", kind: "graph", type: "number" }] : le;
2273
- }
2274
- const Zn = [
2275
- { name: "level", kind: "node", type: "integer" },
2276
- { name: "levelSize", kind: "node", type: "integer" },
2277
- { name: "levelCount", kind: "graph", type: "integer" },
2278
- { name: "sizes", kind: "graph", type: "table" }
2279
- ], Xn = [
2280
- { name: "onPath", kind: "node", type: "boolean" },
2281
- { name: "order", kind: "node", type: "integer" },
2282
- { name: "onPath", kind: "edge", type: "boolean" },
2283
- { name: "length", kind: "graph", type: "integer" },
2284
- { name: "cost", kind: "graph", type: "number" },
2285
- { name: "hops", kind: "graph", type: "integer" }
2286
- ];
2287
- function Qn(e, t) {
2288
- return [
2289
- { name: "in", kind: e, type: "boolean" },
2290
- { name: "count", kind: "graph", type: "integer" },
2291
- { ...t, kind: "graph" }
2292
- ];
2293
- }
2294
- const tn = `${H}.${wt}`;
2295
- function O(e) {
2296
- return { ...e, path: `${tn}.${e.name}` };
2297
- }
2298
- function er(e) {
2299
- return [
2300
- O({
2301
- name: "value",
2302
- plainName: e.plainName,
2303
- technicalName: e.technicalName,
2304
- kind: "node",
2305
- type: e.type ?? "number",
2306
- ...e.unit === void 0 ? {} : { unit: e.unit }
2307
- }),
2308
- O({ name: "rank", plainName: "Rank", technicalName: "rank", kind: "node", type: "integer" }),
2309
- O({
2310
- name: "percentile",
2311
- plainName: "Percentile",
2312
- technicalName: "percentile",
2313
- kind: "node",
2314
- type: "number"
2315
- }),
2316
- O({ name: "min", plainName: "Lowest", technicalName: "min", kind: "graph", type: "number" }),
2317
- O({ name: "max", plainName: "Highest", technicalName: "max", kind: "graph", type: "number" }),
2318
- O({ name: "median", plainName: "Middle", technicalName: "median", kind: "graph", type: "number" }),
2319
- O({ name: "mean", plainName: "Average", technicalName: "mean", kind: "graph", type: "number" }),
2320
- O({
2321
- name: "measured",
2322
- plainName: "Measured",
2323
- technicalName: "measured",
2324
- kind: "graph",
2325
- type: "integer"
2326
- }),
2327
- O({
2328
- name: "normalization",
2329
- plainName: "Normalization",
2330
- technicalName: "normalization",
2331
- kind: "graph",
2332
- type: "string"
2333
- }),
2334
- O({
2335
- name: "tiedAtMin",
2336
- plainName: "Tied at the lowest value",
2337
- technicalName: "tiedAtMin",
2338
- kind: "graph",
2339
- type: "integer"
2340
- })
2341
- ];
2342
- }
2343
- const nn = 12;
2344
- function tr(e, t = {}) {
2345
- return (rn(e) ? sn(e) : on(e)).map((r) => {
2346
- const i = { ...r.meta, ...t.meta?.[r.name] }, s = r.node === null ? un(r.name, i, r.failure ?? "the schema could not be converted") : cn(r.name, r.node, i), o = t.overrides?.[r.name];
2347
- return o === void 0 ? s : { ...s, ...o };
2348
- });
2349
- }
2350
- function rn(e) {
2351
- return typeof e != "object" || e === null ? !1 : "_zod" in e || "_def" in e;
2352
- }
2353
- function sn(e) {
2354
- const t = $e(e);
2355
- if (t === null)
2356
- return [];
2357
- const { properties: n } = t;
2358
- return n === void 0 ? [] : Object.entries(n).map(([r, i]) => ({ name: r, node: Re(i, t) }));
2359
- }
2360
- function on(e) {
2361
- const t = Object.entries(e), n = {};
2362
- for (const [s, o] of t)
2363
- n[s] = o.schema;
2364
- const r = an(n), i = r?.properties;
2365
- return t.map(([s, o]) => {
2366
- const a = i?.[s];
2367
- return r === null || a === void 0 ? {
2368
- name: s,
2369
- node: null,
2370
- failure: "the schema could not be converted to JSON Schema",
2371
- meta: o.meta
2372
- } : { name: s, node: Re(a, r), meta: o.meta };
2373
- });
2374
- }
2375
- function $e(e) {
2376
- try {
2377
- return me.toJSONSchema(e, { io: "input", unrepresentable: "any" });
2378
- } catch {
2379
- return null;
2380
- }
2381
- }
2382
- function an(e) {
2383
- try {
2384
- return $e(me.object(e));
2385
- } catch {
2386
- return null;
2387
- }
2388
- }
2389
- const de = "#/$defs/";
2390
- function Re(e, t) {
2391
- const n = e.$ref;
2392
- if (n === void 0 || !n.startsWith(de))
2393
- return e;
2394
- const r = n.slice(de.length).replaceAll("~1", "/").replaceAll("~0", "~");
2395
- return t.$defs?.[r] ?? e;
2396
- }
2397
- function cn(e, t, n) {
2398
- const r = Ee(t, 0), i = ln(r), s = {
2399
- name: e,
2400
- plainName: n.label ?? K(e),
2401
- technicalName: e,
2402
- type: i.type
2403
- }, o = n.description ?? t.description ?? i.node?.description;
2404
- o !== void 0 && (s.description = o), "default" in t && (s.default = t.default);
2405
- const a = i.node;
2406
- if (a !== void 0 && (i.type === "number" || i.type === "integer")) {
2407
- const c = pe(a.minimum ?? a.exclusiveMinimum), h = pe(a.maximum ?? a.exclusiveMaximum);
2408
- c !== void 0 && (s.min = c), h !== void 0 && (s.max = h);
2409
- }
2410
- const u = n.step ?? a?.multipleOf;
2411
- return u !== void 0 && (s.step = u), i.values !== void 0 && (s.values = i.values), n.group !== void 0 && (s.group = n.group), n.advanced !== void 0 && (s.advanced = n.advanced), i.unsupportedReason !== void 0 && (s.unsupportedReason = i.unsupportedReason), s;
2412
- }
2413
- function un(e, t, n) {
2414
- const r = {
2415
- name: e,
2416
- plainName: t.label ?? K(e),
2417
- technicalName: e,
2418
- type: "unknown",
2419
- unsupportedReason: n
2420
- };
2421
- return t.description !== void 0 && (r.description = t.description), t.step !== void 0 && (r.step = t.step), t.group !== void 0 && (r.group = t.group), t.advanced !== void 0 && (r.advanced = t.advanced), r;
2422
- }
2423
- function Ee(e, t) {
2424
- if (t >= nn)
2425
- return { arms: [], nullable: !1, unresolvedRef: !0 };
2426
- if (e.$ref !== void 0)
2427
- return { arms: [], nullable: !1, unresolvedRef: !0 };
2428
- const n = e.anyOf ?? e.oneOf;
2429
- if (n === void 0)
2430
- return e.type === "null" ? { arms: [], nullable: !0, unresolvedRef: !1 } : { arms: [e], nullable: !1, unresolvedRef: !1 };
2431
- const r = { arms: [], nullable: !1, unresolvedRef: !1 };
2432
- for (const i of n) {
2433
- const s = Ee(i, t + 1);
2434
- r.arms.push(...s.arms), r.nullable = r.nullable || s.nullable, r.unresolvedRef = r.unresolvedRef || s.unresolvedRef;
2435
- }
2436
- return r;
2437
- }
2438
- function ln(e) {
2439
- if (e.arms.length === 0)
2440
- return e.unresolvedRef ? {
2441
- type: "unknown",
2442
- unsupportedReason: "the schema is recursive, so it has no single value type"
2443
- } : {
2444
- type: "unknown",
2445
- unsupportedReason: e.nullable ? "the only value the schema accepts is null" : "the schema declares no value type"
2446
- };
2447
- const t = pn(e.arms);
2448
- if (t !== void 0)
2449
- return { type: "enum", node: e.arms[0], values: t };
2450
- if (e.arms.length === 1)
2451
- return dn(e.arms[0]);
2452
- const n = e.arms.map((r) => Fe(r));
2453
- return n.length === 2 && n.includes("string") && n.includes("number") ? { type: "node-id" } : {
2454
- type: "unknown",
2455
- unsupportedReason: `the schema is a union of ${n.join(" and ")}, which has no single control`
2456
- };
2457
- }
2458
- function dn(e) {
2459
- switch (Fe(e)) {
2460
- case "integer":
2461
- return { type: "integer", node: e };
2462
- case "number":
2463
- return { type: "number", node: e };
2464
- case "boolean":
2465
- return { type: "boolean", node: e };
2466
- case "string":
2467
- return { type: "string", node: e };
2468
- case "array":
2469
- return {
2470
- type: "unknown",
2471
- node: e,
2472
- unsupportedReason: "an array option has no descriptor type; give it one with an override"
2473
- };
2474
- case "object":
2475
- return {
2476
- type: "unknown",
2477
- node: e,
2478
- unsupportedReason: "an object or record option has no descriptor type; give it one with an override"
2479
- };
2480
- default:
2481
- return {
2482
- type: "unknown",
2483
- node: e,
2484
- unsupportedReason: "the Zod construct has no JSON Schema type, so its values cannot be classified"
2485
- };
2486
- }
2487
- }
2488
- function pn(e) {
2489
- const t = [];
2490
- for (const r of e)
2491
- if (r.enum !== void 0)
2492
- t.push(...r.enum);
2493
- else if ("const" in r)
2494
- t.push(r.const);
2495
- else
2496
- return;
2497
- if (t.length === 0)
2498
- return;
2499
- const n = [];
2500
- for (const r of t) {
2501
- if (typeof r != "string" && typeof r != "number" && typeof r != "boolean")
2502
- return;
2503
- const i = String(r);
2504
- n.push({ value: i, label: K(i) });
2505
- }
2506
- return n;
2507
- }
2508
- function Fe(e) {
2509
- const { type: t } = e;
2510
- return typeof t == "string" ? t : Array.isArray(t) && t.length > 0 ? t[0] : "none";
2511
- }
2512
- function pe(e) {
2513
- if (!(e === Number.MAX_SAFE_INTEGER || e === -Number.MAX_SAFE_INTEGER))
2514
- return e;
2515
- }
2516
- function K(e) {
2517
- const t = e.replace(/([a-z0-9])([A-Z])/gu, "$1 $2").replace(/[_-]+/gu, " ").trim();
2518
- return t === "" ? e : t.split(/\s+/u).map((n) => n.charAt(0).toUpperCase() + n.slice(1)).join(" ");
2519
- }
2520
- export {
2521
- vt as $,
2522
- D as A,
2523
- Mn as B,
2524
- Le as C,
2525
- $n as D,
2526
- Nn as E,
2527
- On as F,
2528
- Kt as G,
2529
- Wt as H,
2530
- En as I,
2531
- Rn as J,
2532
- In as K,
2533
- Zn as L,
2534
- Fn as M,
2535
- Oe as N,
2536
- b as O,
2537
- Xn as P,
2538
- Vn as Q,
2539
- Gn as R,
2540
- Dn as S,
2541
- xn as T,
2542
- B as U,
2543
- be as V,
2544
- St as W,
2545
- Ln as X,
2546
- Xt as Y,
2547
- Pn as Z,
2548
- jn as _,
2549
- Yn as a,
2550
- Un as a0,
2551
- Bn as a1,
2552
- Cn as a2,
2553
- _n as b,
2554
- Hn as c,
2555
- kn as d,
2556
- Kn as e,
2557
- Jn as f,
2558
- zn as g,
2559
- qn as h,
2560
- Wn as i,
2561
- Tn as j,
2562
- vn as k,
2563
- He as l,
2564
- O as m,
2565
- er as n,
2566
- tr as o,
2567
- Pe as p,
2568
- Sn as q,
2569
- wn as r,
2570
- Qn as s,
2571
- H as t,
2572
- J as u,
2573
- Ge as v,
2574
- nt as w,
2575
- An as x,
2576
- yt as y,
2577
- T as z
2578
- };