Remove ELK and baseline Rust solver performance

This commit is contained in:
Meta Vens 2026-05-19 20:33:49 +01:00
commit 1b3a07f09a
17 changed files with 6219 additions and 886 deletions

View file

@ -1,52 +0,0 @@
# ELK Probe
Small local `elkjs` probe for EpiphanyGraph.
This is not the final viewer. It is a migration scout:
- inspect which algorithms and options are actually present in the installed `elkjs` build
- adapt existing EpiphanyGraph partition JSON into ELK graphs
- run sample layouts without crossing the C# boundary
- emit simple SVG artifacts under `out/elk-probe/` for side-by-side comparison
## Install
```powershell
cd E:\Projects\EpiphanyGraph\web\elk-probe
npm install
```
## Inspect Available ELK Surface
```powershell
npm run inspect
```
Writes:
- `out/elk-probe/inspect/known-layout-algorithms.json`
- `out/elk-probe/inspect/known-layout-options.json`
## Probe Existing Graph Output
Point the probe at a render directory that already contains `source-tree.json` and `control-flow.json`:
```powershell
npm run probe -- --render-dir "E:\Projects\EpiphanyGraph\out\benchmarks\aetheria-source-tree-map\20260425T082539Z\candidates\sugiyama-rich\render"
```
Optional flags:
- `--render-dir <path>` explicit input directory; if omitted, the probe tries to use the newest benchmark candidate render it can find
- `--out-dir <path>` custom output directory
- `--source-tree-algorithm <id>` defaults to `org.eclipse.elk.layered`
- `--control-flow-algorithm <id>` defaults to `org.eclipse.elk.stress`
Writes one folder per partition under `out/elk-probe/<timestamp>/` with:
- `input.json`
- `elk-layout.json`
- `layout.svg`
- `layout-summary.json`
The SVG renderer here is deliberately plain. The point is to test layout integration and algorithm availability, not to declare victory with decorative sludge.

View file

@ -1,21 +0,0 @@
{
"name": "@epiphanygraph/elk-probe",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@epiphanygraph/elk-probe",
"version": "0.1.0",
"dependencies": {
"elkjs": "^0.11.0"
}
},
"node_modules/elkjs": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/elkjs/-/elkjs-0.11.1.tgz",
"integrity": "sha512-zxxR9k+rx5ktMwT/FwyLdPCrq7xN6e4VGGHH8hA01vVYKjTFik7nHOxBnAYtrgYUB1RpAiLvA1/U2YraWxyKKg==",
"license": "EPL-2.0"
}
}
}

View file

@ -1,14 +0,0 @@
{
"name": "@epiphanygraph/elk-probe",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "Local elkjs probe for EpiphanyGraph layout experiments.",
"scripts": {
"probe": "node ./src/cli.mjs probe",
"inspect": "node ./src/cli.mjs inspect"
},
"dependencies": {
"elkjs": "^0.11.0"
}
}

View file

@ -1,502 +0,0 @@
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import ELK from "elkjs/lib/elk.bundled.js";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
const defaultInspectDir = path.join(repoRoot, "out", "elk-probe", "inspect");
const command = process.argv[2] ?? "inspect";
const args = parseArgs(process.argv.slice(3));
try {
switch (command) {
case "inspect":
await runInspect(args);
break;
case "probe":
await runProbe(args);
break;
default:
throw new Error(`Unknown command '${command}'. Use 'inspect' or 'probe'.`);
}
} catch (error) {
console.error(error instanceof Error ? error.message : error);
process.exitCode = 1;
}
async function runInspect(args) {
const outDir = resolveMaybeRelative(args["out-dir"] ?? defaultInspectDir);
const elk = createElk();
const algorithms = await elk.knownLayoutAlgorithms();
const options = await elk.knownLayoutOptions();
await fs.mkdir(outDir, { recursive: true });
await writeJson(path.join(outDir, "known-layout-algorithms.json"), algorithms);
await writeJson(path.join(outDir, "known-layout-options.json"), options);
console.log(`Wrote algorithm inventory to ${outDir}`);
console.log("");
console.log("Algorithms:");
for (const algorithm of algorithms) {
console.log(`- ${algorithm.id}`);
}
console.log("");
console.log(`Options: ${options.length}`);
}
async function runProbe(args) {
const renderDir = args["render-dir"]
? resolveMaybeRelative(args["render-dir"])
: await findLatestBenchmarkRenderDir();
const outDir = resolveMaybeRelative(
args["out-dir"] ?? path.join(repoRoot, "out", "elk-probe", timestampNow()),
);
const sourceTreeAlgorithm = args["source-tree-algorithm"] ?? "org.eclipse.elk.layered";
const controlFlowAlgorithm = args["control-flow-algorithm"] ?? "org.eclipse.elk.stress";
await assertFile(path.join(renderDir, "source-tree.json"));
await assertFile(path.join(renderDir, "control-flow.json"));
const elk = createElk();
const algorithms = await elk.knownLayoutAlgorithms();
const algorithmIds = new Set(algorithms.map((algorithm) => algorithm.id));
ensureAlgorithmAvailable(sourceTreeAlgorithm, algorithmIds);
ensureAlgorithmAvailable(controlFlowAlgorithm, algorithmIds);
await fs.mkdir(outDir, { recursive: true });
await writeJson(path.join(outDir, "known-layout-algorithms.json"), algorithms);
const partitions = [
{
graphKey: "source-tree",
algorithm: sourceTreeAlgorithm,
},
{
graphKey: "control-flow",
algorithm: controlFlowAlgorithm,
},
];
for (const partition of partitions) {
const inputPath = path.join(renderDir, `${partition.graphKey}.json`);
const report = JSON.parse(await fs.readFile(inputPath, "utf8"));
const partitionOutDir = path.join(outDir, partition.graphKey);
await fs.mkdir(partitionOutDir, { recursive: true });
const elkGraph = buildElkGraph(report, partition.algorithm);
const layout = await elk.layout(elkGraph);
const summary = buildLayoutSummary(report, layout, partition.algorithm);
const svg = renderSvg(layout, report, partition.algorithm);
await writeJson(path.join(partitionOutDir, "input.json"), report);
await writeJson(path.join(partitionOutDir, "elk-graph.json"), elkGraph);
await writeJson(path.join(partitionOutDir, "elk-layout.json"), layout);
await writeJson(path.join(partitionOutDir, "layout-summary.json"), summary);
await fs.writeFile(path.join(partitionOutDir, "layout.svg"), svg, "utf8");
console.log(
`[${partition.graphKey}] ${partition.algorithm} -> ${path.join(partitionOutDir, "layout.svg")}`,
);
}
console.log("");
console.log(`Probe output: ${outDir}`);
}
async function findLatestBenchmarkRenderDir() {
const benchmarkRoot = path.join(repoRoot, "out", "benchmarks", "aetheria-source-tree-map");
const runEntries = await fs.readdir(benchmarkRoot, { withFileTypes: true });
const runNames = runEntries
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
.sort()
.reverse();
for (const runName of runNames) {
const candidateRoot = path.join(benchmarkRoot, runName, "candidates");
try {
const candidateEntries = await fs.readdir(candidateRoot, { withFileTypes: true });
const candidateNames = candidateEntries
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
.sort((left, right) => {
const leftScore = left.includes("rich") ? 0 : 1;
const rightScore = right.includes("rich") ? 0 : 1;
return leftScore - rightScore || left.localeCompare(right);
});
for (const candidateName of candidateNames) {
const renderDir = path.join(candidateRoot, candidateName, "render");
try {
await assertFile(path.join(renderDir, "source-tree.json"));
await assertFile(path.join(renderDir, "control-flow.json"));
return renderDir;
} catch {
// Keep walking until we find a valid render directory.
}
}
} catch {
// Ignore missing candidate folders and keep scanning older runs.
}
}
throw new Error(
"Could not find a benchmark render directory automatically. Pass --render-dir explicitly.",
);
}
function createElk() {
return new ELK();
}
function buildElkGraph(report, algorithm) {
return {
id: report.GraphKey,
layoutOptions: {
"elk.algorithm": algorithm,
...baseGraphOptions(report.GraphKey, algorithm),
},
children: report.Nodes.map((node) => ({
id: node.Id,
width: normalizeSize(node.Bounds.Width, 68, 260),
height: normalizeSize(node.Bounds.Height, 34, 110),
labels: [
{
text: node.Title,
},
],
layoutOptions: {
...nodeOptions(node, report.GraphKey),
},
})),
edges: report.Edges.map((edge, index) => ({
id: `${report.GraphKey}-edge-${index}`,
sources: [edge.SourceId],
targets: [edge.TargetId],
})),
};
}
function baseGraphOptions(graphKey, algorithm) {
const layered = algorithm === "org.eclipse.elk.layered";
if (graphKey === "source-tree") {
return layered
? {
"elk.direction": "DOWN",
"elk.layered.spacing.nodeNodeBetweenLayers": "92",
"elk.spacing.nodeNode": "42",
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
"elk.edgeRouting": "SPLINES",
}
: {
"elk.spacing.nodeNode": "48",
"elk.padding": "[top=40,left=40,bottom=40,right=40]",
};
}
return layered
? {
"elk.direction": "DOWN",
"elk.layered.spacing.nodeNodeBetweenLayers": "124",
"elk.spacing.nodeNode": "84",
"elk.layered.nodePlacement.strategy": "BRANDES_KOEPF",
"elk.edgeRouting": "SPLINES",
}
: {
"elk.spacing.nodeNode": "80",
"elk.padding": "[top=60,left=60,bottom=60,right=60]",
};
}
function nodeOptions(node, graphKey) {
if (graphKey === "source-tree") {
return {
"elk.nodeSize.constraints": "MINIMUM_SIZE",
};
}
return {
"elk.nodeSize.constraints": "MINIMUM_SIZE",
};
}
function buildLayoutSummary(report, layout, algorithm) {
return {
graphKey: report.GraphKey,
graphTitle: report.GraphTitle,
nodeCount: report.NodeCount,
edgeCount: report.EdgeCount,
algorithm,
width: layout.width ?? 0,
height: layout.height ?? 0,
children: layout.children?.length ?? 0,
edgesWithSections:
layout.edges?.filter((edge) => Array.isArray(edge.sections) && edge.sections.length > 0).length ?? 0,
};
}
function renderSvg(layout, report, algorithm) {
const nodeLookup = new Map(report.Nodes.map((node) => [node.Id, node]));
const width = Math.max(1280, Math.ceil((layout.width ?? 0) + 120));
const height = Math.max(860, Math.ceil((layout.height ?? 0) + 140));
const headerHeight = 92;
const offsetX = 60;
const offsetY = headerHeight;
const children = [...(layout.children ?? [])];
const edges = [...(layout.edges ?? [])];
const svg = [];
svg.push(`<?xml version="1.0" encoding="utf-8"?>`);
svg.push(
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="img" aria-labelledby="title desc">`,
);
svg.push(` <title id="title">${escapeXml(report.GraphTitle)} ELK layout</title>`);
svg.push(
` <desc id="desc">ELK probe render for ${escapeXml(report.GraphKey)} using ${escapeXml(algorithm)}.</desc>`,
);
svg.push(` <defs>`);
svg.push(` <linearGradient id="bg" x1="0%" y1="0%" x2="100%" y2="100%">`);
svg.push(` <stop offset="0%" stop-color="#09111c" />`);
svg.push(` <stop offset="100%" stop-color="${report.GraphKey === "control-flow" ? "#190d12" : "#111827"}" />`);
svg.push(` </linearGradient>`);
svg.push(` <marker id="arrow" viewBox="0 0 12 12" refX="10" refY="6" markerWidth="7" markerHeight="7" orient="auto-start-reverse">`);
svg.push(` <path d="M 0 0 L 12 6 L 0 12 z" fill="${report.GraphKey === "control-flow" ? "#fb7185" : "#22d3ee"}" />`);
svg.push(` </marker>`);
svg.push(` </defs>`);
svg.push(` <rect x="0" y="0" width="${width}" height="${height}" fill="url(#bg)" />`);
svg.push(
` <rect x="20" y="20" width="${width - 40}" height="54" rx="18" fill="#0c1626" stroke="${report.GraphKey === "control-flow" ? "#fb7185" : "#22d3ee"}" stroke-opacity="0.5" />`,
);
svg.push(
` <text x="38" y="44" fill="#f8fafc" font-family="Bahnschrift, Segoe UI, sans-serif" font-size="28" font-weight="700">${escapeXml(report.GraphTitle)}</text>`,
);
svg.push(
` <text x="38" y="62" fill="${report.GraphKey === "control-flow" ? "#fdba74" : "#a5f3fc"}" font-family="Bahnschrift, Segoe UI, sans-serif" font-size="12" letter-spacing="0.16em">${escapeXml(algorithm)}</text>`,
);
svg.push(` <g id="edges" fill="none">`);
for (const edge of edges) {
const points = edgeSectionsToPoints(edge.sections, offsetX, offsetY);
if (points.length < 2) {
continue;
}
svg.push(
` <path d="${polylinePath(points)}" stroke="${report.GraphKey === "control-flow" ? "#fb7185" : "#22d3ee"}" stroke-opacity="0.42" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" marker-end="url(#arrow)" />`,
);
}
svg.push(` </g>`);
svg.push(` <g id="nodes">`);
for (const child of children) {
const x = (child.x ?? 0) + offsetX;
const y = (child.y ?? 0) + offsetY;
const widthValue = child.width ?? 80;
const heightValue = child.height ?? 42;
const node = nodeLookup.get(child.id);
const color = nodeColor(node, report.GraphKey);
const lines = wrapLabel(node?.Title ?? child.id, widthValue < 120 ? 16 : 20, 2);
svg.push(
` <rect x="${fmt(x)}" y="${fmt(y)}" width="${fmt(widthValue)}" height="${fmt(heightValue)}" rx="16" fill="#101827" fill-opacity="0.92" stroke="${color}" stroke-width="${node?.IsEntry ? "2.2" : "1.4"}" />`,
);
if (node?.IsEntry) {
svg.push(
` <rect x="${fmt(x - 5)}" y="${fmt(y - 5)}" width="${fmt(widthValue + 10)}" height="${fmt(heightValue + 10)}" rx="20" fill="none" stroke="#fde68a" stroke-width="2.1" stroke-opacity="0.9" />`,
);
}
svg.push(
` <circle cx="${fmt(x + 14)}" cy="${fmt(y + 14)}" r="9" fill="${color}" stroke="#e5e7eb" stroke-opacity="0.4" />`,
);
svg.push(
` <text x="${fmt(x + 14)}" y="${fmt(y + 18)}" text-anchor="middle" fill="#0b1220" font-family="Bahnschrift, Segoe UI, sans-serif" font-size="9" font-weight="700">${escapeXml(tokenFor(node))}</text>`,
);
for (const [index, line] of lines.entries()) {
svg.push(
` <text x="${fmt(x + widthValue / 2)}" y="${fmt(y + 24 + index * 14)}" text-anchor="middle" fill="#f8fafc" font-family="Bahnschrift, Segoe UI, sans-serif" font-size="11.5" font-weight="${node?.IsEntry ? "700" : "600"}">${escapeXml(line)}</text>`,
);
}
}
svg.push(` </g>`);
svg.push(`</svg>`);
return svg.join("\n");
}
function edgeSectionsToPoints(sections = [], offsetX, offsetY) {
const points = [];
for (const section of sections ?? []) {
if (section.startPoint) {
points.push({
x: section.startPoint.x + offsetX,
y: section.startPoint.y + offsetY,
});
}
for (const bendPoint of section.bendPoints ?? []) {
points.push({
x: bendPoint.x + offsetX,
y: bendPoint.y + offsetY,
});
}
if (section.endPoint) {
points.push({
x: section.endPoint.x + offsetX,
y: section.endPoint.y + offsetY,
});
}
}
return dedupeSequential(points);
}
function polylinePath(points) {
const [first, ...rest] = points;
return `M ${fmt(first.x)} ${fmt(first.y)} ${rest.map((point) => `L ${fmt(point.x)} ${fmt(point.y)}`).join(" ")}`;
}
function dedupeSequential(points) {
const deduped = [];
for (const point of points) {
const previous = deduped[deduped.length - 1];
if (!previous || previous.x !== point.x || previous.y !== point.y) {
deduped.push(point);
}
}
return deduped;
}
function nodeColor(node, graphKey) {
if (node?.IsEntry) {
return "#fde68a";
}
if (node?.Role === "anchor") {
return "#94a3b8";
}
if (graphKey === "control-flow") {
return node?.Title?.includes("Server") ? "#60a5fa" : "#fb7185";
}
if (node?.Title?.includes("Shared")) {
return "#67e8f9";
}
if (node?.Title?.includes("UI") || node?.Title?.includes("Client")) {
return "#4ade80";
}
if (node?.Title?.includes("Simulation") || node?.Title?.includes("Zone") || node?.Title?.includes("Galaxy")) {
return "#c084fc";
}
return "#22d3ee";
}
function tokenFor(node) {
if (!node) {
return "N";
}
if (node.IsEntry) {
return "E";
}
if (node.Role === "anchor") {
return "A";
}
const words = node.Title.split(/[\s/_-]+/).filter(Boolean);
if (words.length === 1) {
return words[0].slice(0, 2).toUpperCase();
}
return `${words[0][0] ?? "N"}${words[1][0] ?? ""}`.toUpperCase();
}
function wrapLabel(label, maxChars, maxLines) {
const words = label.split(/\s+/).filter(Boolean);
const lines = [];
let current = "";
for (const word of words) {
const candidate = current ? `${current} ${word}` : word;
if (candidate.length > maxChars && current) {
lines.push(current);
current = word;
if (lines.length === maxLines) {
break;
}
} else {
current = candidate;
}
}
if (current && lines.length < maxLines) {
lines.push(current);
}
if (lines.length === 0) {
lines.push(label);
}
if (lines.length === maxLines && words.length > 0) {
const last = lines[lines.length - 1];
if (last.length > maxChars - 3) {
lines[lines.length - 1] = `${last.slice(0, Math.max(1, maxChars - 3))}...`;
}
}
return lines;
}
function ensureAlgorithmAvailable(algorithm, knownAlgorithms) {
if (!knownAlgorithms.has(algorithm)) {
throw new Error(
`Algorithm '${algorithm}' is not available in this elkjs build.`,
);
}
}
async function assertFile(filePath) {
await fs.access(filePath);
}
async function writeJson(filePath, value) {
await fs.writeFile(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
}
function normalizeSize(value, min, max) {
return Math.max(min, Math.min(max, Math.round(value)));
}
function parseArgs(argv) {
const args = {};
for (let index = 0; index < argv.length; index += 1) {
const token = argv[index];
if (!token.startsWith("--")) {
continue;
}
const key = token.slice(2);
const next = argv[index + 1];
if (!next || next.startsWith("--")) {
args[key] = true;
continue;
}
args[key] = next;
index += 1;
}
return args;
}
function resolveMaybeRelative(targetPath) {
return path.isAbsolute(targetPath) ? targetPath : path.resolve(repoRoot, targetPath);
}
function timestampNow() {
const now = new Date();
const pad = (value) => String(value).padStart(2, "0");
return `${now.getUTCFullYear()}${pad(now.getUTCMonth() + 1)}${pad(now.getUTCDate())}T${pad(now.getUTCHours())}${pad(now.getUTCMinutes())}${pad(now.getUTCSeconds())}Z`;
}
function escapeXml(value) {
return String(value)
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&apos;");
}
function fmt(value) {
return Number(value).toFixed(2).replace(/\.00$/, "");
}

View file

@ -53,7 +53,8 @@ Regenerate it after changing `E:\Projects\epiphany-graph-rs`:
npm run build:solver:wasm
```
ELK remains only as a fallback if the Rust solver fails to instantiate.
If the Rust solver fails to instantiate, layout fails loudly. There is no shadow
engine behind the component.
## Use In Another App
@ -86,7 +87,7 @@ The package exports:
- `EpiphanyGraphViewer`
- state, selection, node, edge, layout mode, motion, performance, and event payload types
The package does not export demo data, validation helpers, ELK probes, SVG renderers,
The package does not export demo data, validation helpers, probes, SVG renderers,
or engine controls. Those are implementation furniture. Consumers get the couch, not
the warehouse inventory.
@ -178,13 +179,12 @@ the rendered state closer to the current layout truth:
- high-error nodes: farthest from their base layout position
- kinetic nodes: nodes carrying the most residual velocity
The base ELK layout is the current ground-truth anchor for browser motion. Combined
The base Rust solver layout is the current ground-truth anchor for browser motion. Combined
force is a live presentation layer around that anchor, not a second source of graph
truth.
The existing benchmark harness under `benchmarks/` measures rendered graph usefulness
against blind graph-truth probes. It does not yet prove realtime sampling optimality.
The first realtime smoke baseline is generated by:
against blind graph-truth probes. The realtime smoke baseline is generated by:
```powershell
npm run tune:simulation
@ -192,6 +192,14 @@ npm run tune:simulation
That writes `benchmarks/realtime/simulation-profile-baseline.json` with cost,
budget-hit, anchor-error, and full-sample-baseline-error data for synthetic expansions
of the mock graph. The viewer's default profile mirrors that baseline. Do not call
the realtime heuristics "extensively tuned" until broader profiled budget sweeps
exist for real client corpora and their results are checked in.
of the mock graph.
The Rust solver performance baseline is generated by:
```powershell
npm run profile:solver
```
That writes `benchmarks/realtime/rust-solver-performance-baseline.json`, CSV rows,
and SVG charts covering hierarchy families, graph sizes, solver latency windows,
meta-heuristic parameters, and convergence error against a high-iteration reference.

View file

@ -7,9 +7,6 @@
"": {
"name": "@epiphanygraph/epiphany-graph-viewer",
"version": "0.1.0",
"dependencies": {
"elkjs": "^0.11.0"
},
"devDependencies": {
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
@ -1484,12 +1481,6 @@
"dev": true,
"license": "ISC"
},
"node_modules/elkjs": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/elkjs/-/elkjs-0.11.1.tgz",
"integrity": "sha512-zxxR9k+rx5ktMwT/FwyLdPCrq7xN6e4VGGHH8hA01vVYKjTFik7nHOxBnAYtrgYUB1RpAiLvA1/U2YraWxyKKg==",
"license": "EPL-2.0"
},
"node_modules/esbuild": {
"version": "0.27.7",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.7.tgz",

View file

@ -24,15 +24,13 @@
"build:solver:wasm": "powershell -ExecutionPolicy Bypass -File ./scripts/Build-RustSolverWasm.ps1",
"typecheck": "tsc --noEmit",
"tune:simulation": "node ./scripts/tune-simulation-profile.mjs",
"profile:solver": "node ./scripts/profile-rust-solver-performance.mjs",
"preview": "vite preview"
},
"peerDependencies": {
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"dependencies": {
"elkjs": "^0.11.0"
},
"devDependencies": {
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",

View file

@ -0,0 +1,459 @@
import fs from "node:fs/promises";
import path from "node:path";
import { performance } from "node:perf_hooks";
const repoRoot = path.resolve(import.meta.dirname, "..", "..", "..");
const packageRoot = path.resolve(import.meta.dirname, "..");
const wasmBytesPath = path.join(packageRoot, "src", "lib", "solver-wasm-bytes.ts");
const outputDir = path.join(repoRoot, "benchmarks", "realtime");
const outputJsonPath = path.join(outputDir, "rust-solver-performance-baseline.json");
const outputCsvPath = path.join(outputDir, "rust-solver-performance-baseline.csv");
const latencySvgPath = path.join(outputDir, "rust-solver-latency.svg");
const convergenceSvgPath = path.join(outputDir, "rust-solver-convergence.svg");
const solver = await loadSolver();
const graphSizes = [24, 64, 128, 256, 512, 1024];
const graphFamilies = [
"chain",
"layered-dag",
"binary-tree",
"hub-spoke",
"clustered-modules",
];
const latencyWindowsMs = [1.5, 3, 6, 12];
const parameterProfiles = [
{ id: "fast-flat", rankGap: 96, nodeGap: 76, edgeLength: 130 },
{ id: "balanced-hierarchy", rankGap: 136, nodeGap: 92, edgeLength: 170 },
{ id: "quality-spacious", rankGap: 180, nodeGap: 118, edgeLength: 230 },
];
const iterationBudgets = [32, 96, 224];
const run = {
generatedAtUtc: new Date().toISOString(),
description:
"Smoke baseline for the Rust WASM graph solver used by the React viewer. Measures graph family, size, latency-window, meta-heuristic parameter, and convergence tradeoffs.",
method: {
graphSizes,
graphFamilies,
latencyWindowsMs,
parameterProfiles,
iterationBudgets,
samplesPerCandidate: 1,
warmupRuns: 0,
reference: "quality-spacious parameters at a size-capped high iteration count",
loss:
"Normalized RMS node displacement from the reference layout after aligning centroids. Lower is closer to the high-iteration solver result.",
},
rows: [],
latencyWindowFrontier: [],
summary: {},
};
for (const family of graphFamilies) {
for (const nodeCount of graphSizes) {
const graph = buildGraph(family, nodeCount);
const referenceIterations = nodeCount <= 256 ? 360 : nodeCount <= 512 ? 280 : 220;
const reference = layoutGraph(graph, {
...parameterProfiles[2],
iterations: referenceIterations,
});
for (const profile of parameterProfiles) {
for (const iterations of iterationBudgets) {
const candidate = measureCandidate(graph, {
...profile,
iterations,
});
run.rows.push({
family,
nodeCount,
edgeCount: graph.edgePairs.length / 2,
profileId: profile.id,
iterations,
rankGap: profile.rankGap,
nodeGap: profile.nodeGap,
edgeLength: profile.edgeLength,
latencyMs: round(candidate.latencyMs),
p95LatencyMs: round(candidate.p95LatencyMs),
loss: round(layoutLoss(candidate.coordinates, reference.coordinates)),
edgeStress: round(edgeStress(graph, candidate.coordinates, profile.edgeLength)),
referenceIterations,
});
}
}
}
}
for (const family of graphFamilies) {
for (const nodeCount of graphSizes) {
const rows = run.rows.filter((row) => row.family === family && row.nodeCount === nodeCount);
for (const budgetMs of latencyWindowsMs) {
const eligible = rows
.filter((row) => row.p95LatencyMs <= budgetMs)
.sort((left, right) => left.loss - right.loss || left.p95LatencyMs - right.p95LatencyMs);
const fallback = rows
.slice()
.sort((left, right) => left.p95LatencyMs - right.p95LatencyMs || left.loss - right.loss);
const best = eligible[0] ?? fallback[0];
run.latencyWindowFrontier.push({
family,
nodeCount,
budgetMs,
metBudget: Boolean(eligible[0]),
profileId: best.profileId,
iterations: best.iterations,
p95LatencyMs: best.p95LatencyMs,
loss: best.loss,
});
}
}
}
run.summary = summarize(run.rows, run.latencyWindowFrontier);
await fs.mkdir(outputDir, { recursive: true });
await fs.writeFile(`${outputJsonPath}.tmp`, `${JSON.stringify(run, null, 2)}\n`);
await fs.rename(`${outputJsonPath}.tmp`, outputJsonPath);
await fs.writeFile(`${outputCsvPath}.tmp`, csvRows(run.rows));
await fs.rename(`${outputCsvPath}.tmp`, outputCsvPath);
await fs.writeFile(`${latencySvgPath}.tmp`, latencySvg(run.rows));
await fs.rename(`${latencySvgPath}.tmp`, latencySvgPath);
await fs.writeFile(`${convergenceSvgPath}.tmp`, convergenceSvg(run.rows));
await fs.rename(`${convergenceSvgPath}.tmp`, convergenceSvgPath);
console.log(`Wrote ${outputJsonPath}`);
console.log(`Wrote ${outputCsvPath}`);
console.log(`Wrote ${latencySvgPath}`);
console.log(`Wrote ${convergenceSvgPath}`);
async function loadSolver() {
const source = await fs.readFile(wasmBytesPath, "utf8");
const match = source.match(/epiphanyGraphSolverWasmBase64\s*=\s*"([^"]+)"/);
if (!match) {
throw new Error(`Could not read embedded solver WASM from ${wasmBytesPath}`);
}
const bytes = Buffer.from(match[1], "base64");
const result = await WebAssembly.instantiate(bytes, {});
const exports = result.instance.exports;
for (const name of [
"memory",
"epiphany_graph_alloc_f32",
"epiphany_graph_dealloc_f32",
"epiphany_graph_alloc_u32",
"epiphany_graph_dealloc_u32",
"epiphany_graph_layout_2d",
]) {
if (!(name in exports)) {
throw new Error(`Rust graph solver wasm is missing ${name}`);
}
}
return exports;
}
function measureCandidate(graph, config) {
const samples = [];
let coordinates = null;
for (let index = 0; index < 1; index += 1) {
const start = performance.now();
coordinates = layoutGraph(graph, config).coordinates;
samples.push(performance.now() - start);
}
return {
coordinates,
latencyMs: average(samples),
p95LatencyMs: percentile(samples, 0.95),
};
}
function layoutGraph(graph, config) {
const nodeCount = graph.nodeWeights.length;
const edgeCount = graph.edgePairs.length / 2;
const nodeWeightsPtr = solver.epiphany_graph_alloc_f32(nodeCount);
const edgePairsPtr = solver.epiphany_graph_alloc_u32(graph.edgePairs.length);
const outputPtr = solver.epiphany_graph_alloc_f32(nodeCount * 4);
try {
new Float32Array(solver.memory.buffer, nodeWeightsPtr, nodeCount).set(graph.nodeWeights);
new Uint32Array(solver.memory.buffer, edgePairsPtr, graph.edgePairs.length).set(graph.edgePairs);
const status = solver.epiphany_graph_layout_2d(
nodeWeightsPtr,
nodeCount,
edgePairsPtr,
edgeCount,
outputPtr,
config.iterations,
config.rankGap,
config.nodeGap,
config.edgeLength,
);
if (status !== 0) {
throw new Error(`Rust graph solver failed with status ${status}`);
}
const coordinates = new Float32Array(nodeCount * 2);
const raw = new Float32Array(solver.memory.buffer, outputPtr, nodeCount * 4);
for (let index = 0; index < nodeCount; index += 1) {
coordinates[index * 2] = raw[index * 4];
coordinates[index * 2 + 1] = raw[index * 4 + 1];
}
return { coordinates };
} finally {
solver.epiphany_graph_dealloc_f32(nodeWeightsPtr, nodeCount);
solver.epiphany_graph_dealloc_u32(edgePairsPtr, graph.edgePairs.length);
solver.epiphany_graph_dealloc_f32(outputPtr, nodeCount * 4);
}
}
function buildGraph(family, nodeCount) {
const edges = [];
if (family === "chain") {
for (let index = 1; index < nodeCount; index += 1) {
edges.push(index - 1, index);
}
} else if (family === "layered-dag") {
const width = Math.max(4, Math.round(Math.sqrt(nodeCount)));
for (let index = 0; index < nodeCount; index += 1) {
const nextLayer = index + width;
if (nextLayer < nodeCount) {
edges.push(index, nextLayer);
}
if (index % width !== width - 1 && nextLayer + 1 < nodeCount) {
edges.push(index, nextLayer + 1);
}
}
} else if (family === "binary-tree") {
for (let index = 1; index < nodeCount; index += 1) {
edges.push(Math.floor((index - 1) / 2), index);
}
} else if (family === "hub-spoke") {
const hubs = Math.max(2, Math.floor(Math.sqrt(nodeCount) / 2));
for (let index = hubs; index < nodeCount; index += 1) {
edges.push(index % hubs, index);
if (index + hubs < nodeCount && index % 3 === 0) {
edges.push(index, index + hubs);
}
}
} else if (family === "clustered-modules") {
const clusterSize = Math.max(6, Math.round(Math.sqrt(nodeCount)));
for (let index = 0; index < nodeCount; index += 1) {
const clusterStart = Math.floor(index / clusterSize) * clusterSize;
const next = clusterStart + ((index - clusterStart + 1) % clusterSize);
if (next < nodeCount && next !== index) {
edges.push(index, next);
}
if (index + clusterSize < nodeCount) {
edges.push(index, index + clusterSize);
}
}
} else {
throw new Error(`Unknown graph family ${family}`);
}
const degrees = new Uint32Array(nodeCount);
for (let index = 0; index < edges.length; index += 2) {
degrees[edges[index]] += 1;
degrees[edges[index + 1]] += 1;
}
const nodeWeights = new Float32Array(nodeCount);
for (let index = 0; index < nodeCount; index += 1) {
nodeWeights[index] = 1 + degrees[index] * 0.18 + deterministicNoise(family, index) * 0.24;
}
return {
nodeWeights,
edgePairs: new Uint32Array(edges),
};
}
function layoutLoss(candidate, reference) {
const count = candidate.length / 2;
const candidateCenter = centroid(candidate);
const referenceCenter = centroid(reference);
let sum = 0;
let maxReferenceRadius = 1;
for (let index = 0; index < count; index += 1) {
const candidateX = candidate[index * 2] - candidateCenter.x;
const candidateY = candidate[index * 2 + 1] - candidateCenter.y;
const referenceX = reference[index * 2] - referenceCenter.x;
const referenceY = reference[index * 2 + 1] - referenceCenter.y;
maxReferenceRadius = Math.max(maxReferenceRadius, Math.hypot(referenceX, referenceY));
sum += (candidateX - referenceX) ** 2 + (candidateY - referenceY) ** 2;
}
return Math.sqrt(sum / count) / maxReferenceRadius;
}
function edgeStress(graph, coordinates, targetLength) {
const stresses = [];
for (let index = 0; index < graph.edgePairs.length; index += 2) {
const source = graph.edgePairs[index];
const target = graph.edgePairs[index + 1];
const length = Math.hypot(
coordinates[source * 2] - coordinates[target * 2],
coordinates[source * 2 + 1] - coordinates[target * 2 + 1],
);
stresses.push(Math.abs(length - targetLength) / Math.max(1, targetLength));
}
return average(stresses);
}
function summarize(rows, frontier) {
const bySize = graphSizes.map((nodeCount) => {
const sizeRows = rows.filter((row) => row.nodeCount === nodeCount);
return {
nodeCount,
bestP95LatencyMs: round(Math.min(...sizeRows.map((row) => row.p95LatencyMs))),
bestLoss: round(Math.min(...sizeRows.map((row) => row.loss))),
medianP95LatencyMs: round(percentile(sizeRows.map((row) => row.p95LatencyMs), 0.5)),
};
});
const largestRealtime = [...frontier]
.filter((row) => row.metBudget)
.sort((left, right) => right.nodeCount - left.nodeCount || left.budgetMs - right.budgetMs)[0];
return {
bySize,
largestBudgetMeetingRun: largestRealtime ?? null,
bestOverallLoss: rows.slice().sort((left, right) => left.loss - right.loss)[0],
fastestOverall: rows.slice().sort((left, right) => left.p95LatencyMs - right.p95LatencyMs)[0],
};
}
function csvRows(rows) {
const header = [
"family",
"nodeCount",
"edgeCount",
"profileId",
"iterations",
"rankGap",
"nodeGap",
"edgeLength",
"latencyMs",
"p95LatencyMs",
"loss",
"edgeStress",
"referenceIterations",
];
return [
header.join(","),
...rows.map((row) => header.map((key) => row[key]).join(",")),
"",
].join("\n");
}
function latencySvg(rows) {
const fastestBySize = graphSizes.map((nodeCount) => ({
x: nodeCount,
y: Math.min(...rows.filter((row) => row.nodeCount === nodeCount).map((row) => row.p95LatencyMs)),
}));
return chartSvg({
title: "Rust Solver P95 Latency By Graph Size",
xLabel: "nodes",
yLabel: "p95 ms",
series: [{ id: "fastest", color: "#22d3ee", points: fastestBySize }],
});
}
function convergenceSvg(rows) {
const byIteration = iterationBudgets.map((iterations) => ({
x: iterations,
y: average(rows.filter((row) => row.iterations === iterations).map((row) => row.loss)),
}));
return chartSvg({
title: "Rust Solver Convergence Loss By Iterations",
xLabel: "iterations",
yLabel: "normalized loss",
series: [{ id: "average loss", color: "#f472b6", points: byIteration }],
});
}
function chartSvg({ title, xLabel, yLabel, series }) {
const width = 920;
const height = 460;
const padding = { left: 74, right: 36, top: 58, bottom: 70 };
const allPoints = series.flatMap((item) => item.points);
const xMin = Math.min(...allPoints.map((point) => point.x));
const xMax = Math.max(...allPoints.map((point) => point.x));
const yMin = 0;
const yMax = Math.max(0.001, Math.max(...allPoints.map((point) => point.y)) * 1.12);
const plotWidth = width - padding.left - padding.right;
const plotHeight = height - padding.top - padding.bottom;
const sx = (value) => padding.left + ((value - xMin) / Math.max(1, xMax - xMin)) * plotWidth;
const sy = (value) => padding.top + plotHeight - ((value - yMin) / Math.max(0.001, yMax - yMin)) * plotHeight;
const paths = series.map((item) => {
const d = item.points
.map((point, index) => `${index === 0 ? "M" : "L"} ${sx(point.x).toFixed(2)} ${sy(point.y).toFixed(2)}`)
.join(" ");
const circles = item.points
.map((point) => `<circle cx="${sx(point.x).toFixed(2)}" cy="${sy(point.y).toFixed(2)}" r="4" fill="${item.color}" />`)
.join("");
return `<path d="${d}" fill="none" stroke="${item.color}" stroke-width="3" />${circles}`;
}).join("");
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
<rect width="100%" height="100%" fill="#071019" />
<text x="${padding.left}" y="32" fill="#e5eef8" font-family="Arial, sans-serif" font-size="22" font-weight="700">${escapeXml(title)}</text>
<line x1="${padding.left}" y1="${padding.top + plotHeight}" x2="${padding.left + plotWidth}" y2="${padding.top + plotHeight}" stroke="#64748b" />
<line x1="${padding.left}" y1="${padding.top}" x2="${padding.left}" y2="${padding.top + plotHeight}" stroke="#64748b" />
<text x="${padding.left + plotWidth / 2}" y="${height - 22}" fill="#cbd5e1" font-family="Arial, sans-serif" font-size="14" text-anchor="middle">${escapeXml(xLabel)}</text>
<text x="22" y="${padding.top + plotHeight / 2}" fill="#cbd5e1" font-family="Arial, sans-serif" font-size="14" text-anchor="middle" transform="rotate(-90 22 ${padding.top + plotHeight / 2})">${escapeXml(yLabel)}</text>
<text x="${padding.left}" y="${padding.top + plotHeight + 22}" fill="#94a3b8" font-family="Arial, sans-serif" font-size="12">${xMin}</text>
<text x="${padding.left + plotWidth}" y="${padding.top + plotHeight + 22}" fill="#94a3b8" font-family="Arial, sans-serif" font-size="12" text-anchor="end">${xMax}</text>
<text x="${padding.left - 10}" y="${padding.top + plotHeight}" fill="#94a3b8" font-family="Arial, sans-serif" font-size="12" text-anchor="end">${round(yMin)}</text>
<text x="${padding.left - 10}" y="${padding.top + 4}" fill="#94a3b8" font-family="Arial, sans-serif" font-size="12" text-anchor="end">${round(yMax)}</text>
${paths}
</svg>
`;
}
function centroid(coordinates) {
let x = 0;
let y = 0;
const count = coordinates.length / 2;
for (let index = 0; index < count; index += 1) {
x += coordinates[index * 2];
y += coordinates[index * 2 + 1];
}
return { x: x / count, y: y / count };
}
function deterministicNoise(family, index) {
let hash = 2166136261;
for (const char of `${family}:${index}`) {
hash ^= char.charCodeAt(0);
hash = Math.imul(hash, 16777619);
}
return ((hash >>> 0) % 1000) / 1000;
}
function average(values) {
const finite = values.filter(Number.isFinite);
if (finite.length === 0) {
return 0;
}
return finite.reduce((sum, value) => sum + value, 0) / finite.length;
}
function percentile(values, fraction) {
const sorted = values.filter(Number.isFinite).sort((left, right) => left - right);
if (sorted.length === 0) {
return 0;
}
return sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * fraction))];
}
function round(value) {
return Number(value.toFixed(4));
}
function escapeXml(value) {
return String(value)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
}

View file

@ -600,7 +600,7 @@ export function EpiphanyGraphViewer({
<div>Wheel to zoom. Drag the void to pan. Click something interesting and the side panel stops being decorative.</div>
</div>
{status === "loading" && <StageMessage tone="#67e8f9">Laying out the graph. ELK is thinking noble thoughts.</StageMessage>}
{status === "loading" && <StageMessage tone="#67e8f9">Laying out the graph. Rust solver is taking the hill.</StageMessage>}
{status === "error" && <StageMessage tone="#fca5a5">{errorMessage ?? "Layout failed."}</StageMessage>}
{status === "ready" && activeLayout && (
<svg

View file

@ -1,4 +1,3 @@
import ELK from "elkjs/lib/elk.bundled.js";
import { layoutWithRustSolver } from "./solver-wasm";
import type {
EpiphanyGraph,
@ -14,33 +13,7 @@ import type {
PositionedPoint,
} from "./types";
const elk = new ELK();
type ElkSection = {
startPoint?: { x: number; y: number };
endPoint?: { x: number; y: number };
bendPoints?: Array<{ x: number; y: number }>;
};
type ElkLayoutNode = {
id: string;
x?: number;
y?: number;
width?: number;
height?: number;
};
type ElkLayoutEdge = {
id?: string;
sections?: ElkSection[];
};
type ElkLayoutGraph = {
width?: number;
height?: number;
children?: ElkLayoutNode[];
edges?: ElkLayoutEdge[];
};
type NodeSizingMode = "layered" | "compact";
type LayoutViewport = {
width: number;
@ -66,111 +39,6 @@ async function layoutGraph(
links: EpiphanyGraphLink[],
mode: EpiphanyGraphLayoutMode = "layered",
viewport?: LayoutViewport,
): Promise<GraphLayout> {
try {
return await layoutGraphWithRustSolver(graphKey, graph, links, mode, viewport);
} catch (error) {
console.warn("Epiphany Rust graph solver failed; falling back to ELK.", error);
}
return layoutGraphWithElk(graphKey, graph, links, mode, viewport);
}
async function layoutGraphWithElk(
graphKey: GraphKey,
graph: EpiphanyGraph,
links: EpiphanyGraphLink[],
mode: EpiphanyGraphLayoutMode = "layered",
viewport?: LayoutViewport,
): Promise<GraphLayout> {
const algorithm = elkAlgorithmForMode(mode);
const nodeDegrees = buildNodeDegrees(graph);
const linkCounts = buildLinkCounts(graphKey, links);
const nodes = graph.nodes.map((node) => {
const size = estimateNodeSize(node, graphKey, algorithm, graph.nodes.length, viewport);
return {
id: node.id,
width: size.width,
height: size.height,
labels: [{ text: node.title }],
};
});
const edges = graph.edges.map((edge, index) => ({
id: resolveEdgeId(edge, index),
sources: [edge.source_id],
targets: [edge.target_id],
}));
const elkGraph = {
id: graphKey,
layoutOptions: {
"elk.algorithm": algorithm,
...layoutOptionsFor(graphKey, algorithm),
},
children: nodes,
edges,
};
const layout = (await elk.layout(elkGraph)) as ElkLayoutGraph;
const childLookup = new Map((layout.children ?? []).map((child) => [child.id, child]));
const positionedNodes: PositionedNode[] = graph.nodes.map((node) => {
const child = childLookup.get(node.id);
const degree = nodeDegrees.get(node.id) ?? 0;
const linkCount = linkCounts.get(node.id) ?? 0;
return {
...node,
code_refs: node.code_refs ?? [],
graphKey,
x: child?.x ?? 0,
y: child?.y ?? 0,
width: child?.width ?? estimateNodeSize(node, graphKey, algorithm, graph.nodes.length, viewport).width,
height: child?.height ?? estimateNodeSize(node, graphKey, algorithm, graph.nodes.length, viewport).height,
degree,
linkCount,
badgeText: nodeBadgeText(node.title),
fill: nodeFill(graphKey, node.status),
stroke: nodeStroke(graphKey, node.status),
};
});
const separatedNodes = normalizeNodeBounds(resizeNodesForSeparation(positionedNodes, algorithm));
const layoutEdgeLookup = new Map((layout.edges ?? []).map((edge, index) => [edge.id ?? `edge-${graphKey}-${index}`, edge]));
const nodeLookup = new Map(separatedNodes.map((node) => [node.id, node]));
const positionedEdges: PositionedEdge[] = graph.edges.map((source, index) => {
const resolvedId = resolveEdgeId(source, index);
const layoutEdge = layoutEdgeLookup.get(resolvedId);
const points = isCompactAlgorithm(algorithm) ? [] : edgeSectionsToPoints(layoutEdge?.sections ?? []);
const fallbackPoints = points.length > 0 ? points : straightEdgePoints(source, nodeLookup);
return {
...source,
id: source.id ?? null,
label: source.label ?? null,
mechanism: source.mechanism ?? null,
code_refs: source.code_refs ?? [],
graphKey,
resolvedId,
points: fallbackPoints,
path: pointsToPath(fallbackPoints),
midpoint: edgeMidpoint(fallbackPoints),
};
});
return {
graphKey,
width: Math.max(720, layoutBounds(separatedNodes).width, layout.width ?? 720),
height: Math.max(520, layoutBounds(separatedNodes).height, layout.height ?? 520),
nodes: separatedNodes,
edges: positionedEdges,
};
}
async function layoutGraphWithRustSolver(
graphKey: GraphKey,
graph: EpiphanyGraph,
links: EpiphanyGraphLink[],
mode: EpiphanyGraphLayoutMode,
viewport?: LayoutViewport,
): Promise<GraphLayout> {
const sizingAlgorithm = sizingAlgorithmForMode(mode);
const nodeDegrees = buildNodeDegrees(graph);
@ -261,20 +129,8 @@ function layoutModeFor(
return mode[graphKey] ?? "layered";
}
function elkAlgorithmForMode(mode: EpiphanyGraphLayoutMode) {
if (mode === "stress" || mode === "combined-force") {
return "org.eclipse.elk.stress";
}
if (mode === "force") {
return "org.eclipse.elk.force";
}
return "org.eclipse.elk.layered";
}
function sizingAlgorithmForMode(mode: EpiphanyGraphLayoutMode) {
return mode === "layered" ? "org.eclipse.elk.layered" : "org.eclipse.elk.stress";
function sizingAlgorithmForMode(mode: EpiphanyGraphLayoutMode): NodeSizingMode {
return mode === "layered" ? "layered" : "compact";
}
function rustSolverConfigFor(graphKey: GraphKey, mode: EpiphanyGraphLayoutMode) {
@ -336,8 +192,8 @@ function layoutBounds(nodes: PositionedNode[]) {
};
}
function resizeNodesForSeparation(nodes: PositionedNode[], algorithm: string): PositionedNode[] {
if (!isCompactAlgorithm(algorithm) || nodes.length < 2) {
function resizeNodesForSeparation(nodes: PositionedNode[], sizingMode: NodeSizingMode): PositionedNode[] {
if (!isCompactSizingMode(sizingMode) || nodes.length < 2) {
return nodes;
}
@ -458,8 +314,8 @@ function relaxOverlappingNodes(nodes: PositionedNode[]): PositionedNode[] {
return relaxedNodes;
}
function isCompactAlgorithm(algorithm: string) {
return algorithm === "org.eclipse.elk.stress" || algorithm === "org.eclipse.elk.force";
function isCompactSizingMode(sizingMode: NodeSizingMode) {
return sizingMode === "compact";
}
function nodeCenter(node: { x: number; y: number; width: number; height: number }) {
@ -469,51 +325,6 @@ function nodeCenter(node: { x: number; y: number; width: number; height: number
};
}
function layoutOptionsFor(graphKey: GraphKey, algorithm: string): Record<string, string> {
if (algorithm === "org.eclipse.elk.stress") {
return {
"elk.padding": "[top=96,left=96,bottom=96,right=96]",
"elk.spacing.nodeNode": graphKey === "architecture" ? "96" : "128",
"elk.stress.desiredEdgeLength": graphKey === "architecture" ? "260" : "340",
"elk.stress.iterationLimit": graphKey === "architecture" ? "240" : "180",
"elk.stress.epsilon": "0.0001",
};
}
if (algorithm === "org.eclipse.elk.force") {
return {
"elk.padding": "[top=96,left=96,bottom=96,right=96]",
"elk.spacing.nodeNode": graphKey === "architecture" ? "96" : "132",
"elk.force.model": "FRUCHTERMAN_REINGOLD",
"elk.force.iterations": graphKey === "architecture" ? "650" : "360",
"elk.force.repulsion": graphKey === "architecture" ? "72" : "120",
"elk.force.temperature": "0.1",
"elk.randomSeed": "17",
};
}
return graphKey === "architecture"
? {
"elk.direction": "DOWN",
"elk.edgeRouting": "SPLINES",
"elk.spacing.nodeNode": "48",
"elk.layered.spacing.nodeNodeBetweenLayers": "88",
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
"elk.padding": "[top=40,left=40,bottom=40,right=40]",
}
: {
"elk.direction": "RIGHT",
"elk.edgeRouting": "SPLINES",
"elk.spacing.nodeNode": "88",
"elk.layered.spacing.nodeNodeBetweenLayers": "176",
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
"elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
"elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
"elk.layered.unnecessaryBendpoints": "true",
"elk.padding": "[top=72,left=84,bottom=72,right=96]",
};
}
function buildNodeDegrees(graph: EpiphanyGraph) {
const degrees = new Map<string, number>();
for (const node of graph.nodes ?? []) {
@ -543,11 +354,11 @@ function resolveEdgeId(edge: EpiphanyGraphEdge, index: number) {
function estimateNodeSize(
node: { title: string; purpose: string; mechanism?: string | null; metaphor?: string | null },
graphKey: GraphKey,
algorithm: string,
sizingMode: NodeSizingMode,
nodeCount: number,
viewport?: LayoutViewport,
) {
const compact = algorithm === "org.eclipse.elk.stress" || algorithm === "org.eclipse.elk.force";
const compact = isCompactSizingMode(sizingMode);
const densityScale = compact ? graphDensityScale(nodeCount, viewport) : 1;
const titleWeight = Math.min(node.title.length, 36);
const purposeWeight = Math.min(node.purpose.length, 110);
@ -638,22 +449,6 @@ function estimateCharacterCapacity(pixelWidth: number, averageCharWidth: number)
return Math.max(12, Math.floor(pixelWidth / averageCharWidth));
}
function edgeSectionsToPoints(sections: ElkSection[]) {
const points: PositionedPoint[] = [];
for (const section of sections) {
if (section.startPoint) {
points.push(section.startPoint);
}
for (const bendPoint of section.bendPoints ?? []) {
points.push(bendPoint);
}
if (section.endPoint) {
points.push(section.endPoint);
}
}
return dedupeSequentialPoints(points);
}
function straightEdgePoints(
edge: EpiphanyGraphEdge,
nodes: Map<string, PositionedNode>,
@ -695,17 +490,6 @@ function edgeMidpoint(points: PositionedPoint[]) {
return points[midIndex];
}
function dedupeSequentialPoints(points: PositionedPoint[]) {
const deduped: PositionedPoint[] = [];
for (const point of points) {
const previous = deduped[deduped.length - 1];
if (!previous || previous.x !== point.x || previous.y !== point.y) {
deduped.push(point);
}
}
return deduped;
}
function nodeBadgeText(title: string) {
const words = title.split(/[\s/_-]+/).filter(Boolean);
if (words.length === 0) {

View file

@ -8,7 +8,6 @@ export default defineConfig({
output: {
manualChunks: {
react: ["react", "react-dom"],
elk: ["elkjs/lib/elk.bundled.js"],
},
},
},