@re-cinq/floor-graph 0.0.0-stage → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +18 -2
- package/dist/ArrowMarkerDefs.d.ts +3 -0
- package/dist/ArrowMarkerDefs.js +16 -0
- package/dist/ControlIcon.d.ts +3 -0
- package/dist/ControlIcon.js +5 -0
- package/dist/DanglingStub.d.ts +7 -0
- package/dist/DanglingStub.js +10 -0
- package/dist/ExitDot.d.ts +8 -0
- package/dist/ExitDot.js +7 -0
- package/dist/GraphEdge.d.ts +27 -0
- package/dist/GraphEdge.js +32 -0
- package/dist/GraphNode.d.ts +43 -0
- package/dist/GraphNode.js +138 -0
- package/dist/GraphSvg.d.ts +50 -0
- package/dist/GraphSvg.js +77 -0
- package/dist/GraphViewport.d.ts +16 -0
- package/dist/GraphViewport.js +27 -0
- package/dist/NodeBadges.d.ts +8 -0
- package/dist/NodeBadges.js +19 -0
- package/dist/NodeBox.d.ts +8 -0
- package/dist/NodeBox.js +8 -0
- package/dist/NodeTitle.d.ts +8 -0
- package/dist/NodeTitle.js +7 -0
- package/dist/NodeTooltip.d.ts +9 -0
- package/dist/NodeTooltip.js +30 -0
- package/dist/RunGraphLegend.d.ts +4 -0
- package/dist/RunGraphLegend.js +20 -0
- package/dist/RunGraphView.d.ts +27 -0
- package/dist/RunGraphView.js +151 -0
- package/dist/ToggleButton.d.ts +8 -0
- package/dist/ToggleButton.js +6 -0
- package/dist/TypeGlyph.d.ts +9 -0
- package/dist/TypeGlyph.js +23 -0
- package/dist/ViewportControls.d.ts +13 -0
- package/dist/ViewportControls.js +11 -0
- package/dist/assembly-line-definition.d.ts +35 -0
- package/dist/assembly-line-definition.js +2 -0
- package/dist/elk-graph.d.ts +16 -0
- package/dist/elk-graph.js +131 -0
- package/dist/elk-layout.d.ts +46 -0
- package/dist/elk-layout.js +67 -0
- package/dist/graph-markers.d.ts +2 -0
- package/dist/graph-markers.js +10 -0
- package/dist/graph-view-model.d.ts +33 -0
- package/dist/graph-view-model.js +55 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +6 -0
- package/dist/layout-geometry.d.ts +16 -0
- package/dist/layout-geometry.js +56 -0
- package/dist/metro/declared-ids.d.ts +3 -0
- package/dist/metro/declared-ids.js +5 -0
- package/dist/metro/edge-key.d.ts +3 -0
- package/dist/metro/edge-key.js +5 -0
- package/dist/metro/layout-diff.d.ts +12 -0
- package/dist/metro/layout-diff.js +32 -0
- package/dist/metro/main-path.d.ts +8 -0
- package/dist/metro/main-path.js +26 -0
- package/dist/metro/neighbourhood.d.ts +7 -0
- package/dist/metro/neighbourhood.js +28 -0
- package/dist/metro/node-edges.d.ts +5 -0
- package/dist/metro/node-edges.js +9 -0
- package/dist/metro/pass-through.d.ts +3 -0
- package/dist/metro/pass-through.js +16 -0
- package/dist/metro/reachability.d.ts +8 -0
- package/dist/metro/reachability.js +31 -0
- package/dist/metro/removed-stations.d.ts +13 -0
- package/dist/metro/removed-stations.js +11 -0
- package/dist/metro/station-visits.d.ts +7 -0
- package/dist/metro/station-visits.js +13 -0
- package/dist/metro/step-along.d.ts +8 -0
- package/dist/metro/step-along.js +28 -0
- package/dist/metro/taken-count.d.ts +6 -0
- package/dist/metro/taken-count.js +11 -0
- package/dist/metro/taken-lines.d.ts +12 -0
- package/dist/metro/taken-lines.js +20 -0
- package/dist/metro/visited-part.d.ts +4 -0
- package/dist/metro/visited-part.js +24 -0
- package/dist/node-aria-label.d.ts +9 -0
- package/dist/node-aria-label.js +11 -0
- package/dist/node-badges.d.ts +8 -0
- package/dist/node-badges.js +20 -0
- package/dist/node-tooltip.d.ts +12 -0
- package/dist/node-tooltip.js +34 -0
- package/dist/node-type-family.d.ts +6 -0
- package/dist/node-type-family.js +18 -0
- package/dist/run-graph-drawing.d.ts +14 -0
- package/dist/run-graph-drawing.js +22 -0
- package/dist/run-graph-geometry.d.ts +18 -0
- package/dist/run-graph-geometry.js +38 -0
- package/dist/run-graph-tone-classes.d.ts +5 -0
- package/dist/run-graph-tone-classes.js +34 -0
- package/dist/run-graph.module.css +470 -0
- package/dist/run-graph.test-helpers.d.ts +4 -0
- package/dist/run-graph.test-helpers.js +11 -0
- package/dist/station-subtitle.d.ts +2 -0
- package/dist/station-subtitle.js +6 -0
- package/dist/use-element-size.d.ts +6 -0
- package/dist/use-element-size.js +17 -0
- package/dist/use-elk-layout.d.ts +5 -0
- package/dist/use-elk-layout.js +19 -0
- package/dist/use-keyboard-cursor.d.ts +10 -0
- package/dist/use-keyboard-cursor.js +39 -0
- package/dist/use-layout-changes.d.ts +11 -0
- package/dist/use-layout-changes.js +45 -0
- package/dist/use-measured-box.d.ts +3 -0
- package/dist/use-measured-box.js +13 -0
- package/dist/use-node-size.d.ts +7 -0
- package/dist/use-node-size.js +17 -0
- package/dist/use-node-tooltip.d.ts +20 -0
- package/dist/use-node-tooltip.js +74 -0
- package/dist/use-pointer-drag.d.ts +7 -0
- package/dist/use-pointer-drag.js +23 -0
- package/dist/use-redrawn.d.ts +4 -0
- package/dist/use-redrawn.js +8 -0
- package/dist/use-revealed.d.ts +4 -0
- package/dist/use-revealed.js +11 -0
- package/dist/use-run-overlay.d.ts +7 -0
- package/dist/use-run-overlay.js +11 -0
- package/dist/use-toggle.d.ts +4 -0
- package/dist/use-toggle.js +7 -0
- package/dist/use-wheel-navigation.d.ts +3 -0
- package/dist/use-wheel-navigation.js +19 -0
- package/dist/viewport-input.d.ts +16 -0
- package/dist/viewport-input.js +19 -0
- package/dist/viewport-state.d.ts +46 -0
- package/dist/viewport-state.js +48 -0
- package/dist/viewport.d.ts +27 -0
- package/dist/viewport.js +66 -0
- package/dist/viewport.module.css +67 -0
- package/package.json +69 -4
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { declaredIdsOf } from "./metro/declared-ids";
|
|
2
|
+
import { edgeKeyOf } from "./metro/edge-key";
|
|
3
|
+
import { mainPathOf } from "./metro/main-path";
|
|
4
|
+
import { incomingEdgesOf, outgoingEdgesOf } from "./metro/node-edges";
|
|
5
|
+
import { isPassThrough } from "./metro/pass-through";
|
|
6
|
+
import { countWidthOf } from "./metro/taken-count";
|
|
7
|
+
import { nodeTitle } from "./node-tooltip";
|
|
8
|
+
import { typeFamilyOf } from "./node-type-family";
|
|
9
|
+
const NODE_SIZE = { width: 140, height: 60 };
|
|
10
|
+
// Card height keeps ELK from centring stations on a shorter marker, which made sub-16px turns.
|
|
11
|
+
const MARKER_SIZE = { width: 22, height: NODE_SIZE.height };
|
|
12
|
+
const PORT_SIZE = 8;
|
|
13
|
+
const EXIT_DOT_SIZE = 14;
|
|
14
|
+
const STUB_SIZE = 14;
|
|
15
|
+
const STOP_HEIGHT = 46;
|
|
16
|
+
const STOP_PORT_Y = 14;
|
|
17
|
+
const STOP_MIN_WIDTH = 32;
|
|
18
|
+
const STOP_CHAR_WIDTH = 6.8;
|
|
19
|
+
const STOP_PADDING = 10;
|
|
20
|
+
const TARGET_STUB = { idSuffix: "stub", direction: "in", side: "WEST" };
|
|
21
|
+
const SOURCE_STUB = { idSuffix: "source-stub", direction: "out", side: "EAST" };
|
|
22
|
+
const LABEL_HEIGHT = 16;
|
|
23
|
+
const LABEL_CHAR_WIDTH = 7.3;
|
|
24
|
+
const LABEL_PADDING = 6;
|
|
25
|
+
const LAYOUT_OPTIONS = {
|
|
26
|
+
"elk.algorithm": "layered",
|
|
27
|
+
"elk.direction": "RIGHT",
|
|
28
|
+
"elk.edgeRouting": "ORTHOGONAL",
|
|
29
|
+
"elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES",
|
|
30
|
+
"elk.layered.cycleBreaking.strategy": "MODEL_ORDER",
|
|
31
|
+
"elk.layered.nodePlacement.strategy": "BRANDES_KOEPF",
|
|
32
|
+
"elk.spacing.nodeNode": "36",
|
|
33
|
+
"elk.layered.spacing.nodeNodeBetweenLayers": "56",
|
|
34
|
+
"elk.spacing.edgeEdge": "12",
|
|
35
|
+
"elk.layered.spacing.edgeEdgeBetweenLayers": "12",
|
|
36
|
+
"elk.spacing.edgeNode": "18",
|
|
37
|
+
"elk.layered.spacing.edgeNodeBetweenLayers": "18",
|
|
38
|
+
"elk.spacing.edgeLabel": "4",
|
|
39
|
+
"elk.edgeLabels.placement": "CENTER",
|
|
40
|
+
};
|
|
41
|
+
export function elkGraphOf(definition, size = NODE_SIZE, options = {}) {
|
|
42
|
+
const exitDotEdges = exitDotEdgesOf(definition);
|
|
43
|
+
return {
|
|
44
|
+
id: "root",
|
|
45
|
+
layoutOptions: LAYOUT_OPTIONS,
|
|
46
|
+
children: [
|
|
47
|
+
...definition.nodes.map((node) => options.compactStops && isPassThrough(definition, node.id) ? stopOf(definition, node.id) : ({
|
|
48
|
+
id: node.id,
|
|
49
|
+
...(typeFamilyOf(node.type) === "marker" ? MARKER_SIZE : { width: size.widthOf?.(node.id) ?? size.width, height: size.height }),
|
|
50
|
+
layoutOptions: { "elk.portConstraints": "FIXED_SIDE" },
|
|
51
|
+
ports: [
|
|
52
|
+
...incomingEdgesOf(definition, node.id)
|
|
53
|
+
.filter((edge) => !exitDotEdges.includes(edge))
|
|
54
|
+
.map((edge) => portOf(edge, "in", "WEST")),
|
|
55
|
+
...outgoingEdgesOf(definition, node.id).map((edge) => portOf(edge, "out", "EAST")),
|
|
56
|
+
],
|
|
57
|
+
})),
|
|
58
|
+
...exitDotEdges.map(exitDotOf),
|
|
59
|
+
...undeclaredStubsOf(definition),
|
|
60
|
+
],
|
|
61
|
+
edges: definition.edges.map((edge) => ({
|
|
62
|
+
id: edgeKeyOf(edge),
|
|
63
|
+
sources: [`${edgeKeyOf(edge)}:out`],
|
|
64
|
+
targets: [`${edgeKeyOf(edge)}:in`],
|
|
65
|
+
labels: [edgeLabelOf(edge, options.takenCounts?.get(edgeKeyOf(edge)))],
|
|
66
|
+
})),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function stopOf(definition, nodeId) {
|
|
70
|
+
const width = Math.max(STOP_MIN_WIDTH, Math.ceil(nodeTitle(nodeId).length * STOP_CHAR_WIDTH + STOP_PADDING));
|
|
71
|
+
const [incoming] = incomingEdgesOf(definition, nodeId);
|
|
72
|
+
const [outgoing] = outgoingEdgesOf(definition, nodeId);
|
|
73
|
+
return {
|
|
74
|
+
id: nodeId,
|
|
75
|
+
width,
|
|
76
|
+
height: STOP_HEIGHT,
|
|
77
|
+
layoutOptions: { "elk.portConstraints": "FIXED_POS" },
|
|
78
|
+
ports: [
|
|
79
|
+
{ id: `${edgeKeyOf(incoming)}:in`, x: 0, y: STOP_PORT_Y, width: 0, height: 0 },
|
|
80
|
+
{ id: `${edgeKeyOf(outgoing)}:out`, x: width, y: STOP_PORT_Y, width: 0, height: 0 },
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function exitDotEdgesOf(definition) {
|
|
85
|
+
const mainEdges = mainPathOf(definition).edges;
|
|
86
|
+
return definition.edges.filter((edge) => edge.to === definition.exit && !mainEdges.has(edgeKeyOf(edge)));
|
|
87
|
+
}
|
|
88
|
+
function exitDotOf(edge) {
|
|
89
|
+
return {
|
|
90
|
+
id: `${edgeKeyOf(edge)}:exit`,
|
|
91
|
+
width: EXIT_DOT_SIZE,
|
|
92
|
+
height: EXIT_DOT_SIZE,
|
|
93
|
+
layoutOptions: { "elk.portConstraints": "FIXED_SIDE" },
|
|
94
|
+
ports: [portOf(edge, "in", "WEST")],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function undeclaredStubsOf(definition) {
|
|
98
|
+
const declaredIds = declaredIdsOf(definition);
|
|
99
|
+
const undeclaredTargetEdges = definition.edges.filter((edge) => !declaredIds.has(edge.to));
|
|
100
|
+
const undeclaredSourceEdges = definition.edges.filter((edge) => !declaredIds.has(edge.from));
|
|
101
|
+
return [
|
|
102
|
+
...undeclaredTargetEdges.map((edge) => stubOf(edge, TARGET_STUB)),
|
|
103
|
+
...undeclaredSourceEdges.map((edge) => stubOf(edge, SOURCE_STUB)),
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
function stubOf(edge, { idSuffix, direction, side }) {
|
|
107
|
+
return {
|
|
108
|
+
id: `${edgeKeyOf(edge)}:${idSuffix}`,
|
|
109
|
+
width: STUB_SIZE,
|
|
110
|
+
height: STUB_SIZE,
|
|
111
|
+
layoutOptions: { "elk.portConstraints": "FIXED_SIDE" },
|
|
112
|
+
ports: [portOf(edge, direction, side)],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function portOf(edge, direction, side) {
|
|
116
|
+
return {
|
|
117
|
+
id: `${edgeKeyOf(edge)}:${direction}`,
|
|
118
|
+
width: PORT_SIZE,
|
|
119
|
+
height: PORT_SIZE,
|
|
120
|
+
layoutOptions: { "elk.port.side": side },
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function edgeLabelOf({ on, iterationMax }, takenCount = 0) {
|
|
124
|
+
const text = iterationMax === undefined ? on : `${on} · max ${iterationMax}`;
|
|
125
|
+
return {
|
|
126
|
+
text,
|
|
127
|
+
width: Math.ceil(text.length * LABEL_CHAR_WIDTH + LABEL_PADDING + countWidthOf(takenCount)),
|
|
128
|
+
height: LABEL_HEIGHT,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=elk-graph.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition } from "./assembly-line-definition";
|
|
2
|
+
import { type ElkGraphOptions, type NodeSize } from "./elk-graph";
|
|
3
|
+
export type Box = {
|
|
4
|
+
minX: number;
|
|
5
|
+
minY: number;
|
|
6
|
+
maxX: number;
|
|
7
|
+
maxY: number;
|
|
8
|
+
};
|
|
9
|
+
export interface ElkLayout {
|
|
10
|
+
nodes: {
|
|
11
|
+
id: string;
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
ports: {
|
|
17
|
+
edge: string;
|
|
18
|
+
side: "in" | "out";
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
}[];
|
|
22
|
+
}[];
|
|
23
|
+
edges: {
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
on: string;
|
|
27
|
+
kind: "forward" | "back" | "self";
|
|
28
|
+
d: string;
|
|
29
|
+
mid: {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
vertical: boolean;
|
|
33
|
+
};
|
|
34
|
+
labelBox: Box;
|
|
35
|
+
}[];
|
|
36
|
+
contentBox: {
|
|
37
|
+
minX: number;
|
|
38
|
+
minY: number;
|
|
39
|
+
maxX: number;
|
|
40
|
+
maxY: number;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export type LaidOutNode = ElkLayout["nodes"][number];
|
|
44
|
+
export type LaidOutEdge = ElkLayout["edges"][number];
|
|
45
|
+
/** Lays out a line with ELK: node centres, one SVG path and label centre per edge, and the canvas box. */
|
|
46
|
+
export declare function layoutWithElk(definition: AssemblyLineDefinition, size?: NodeSize, options?: ElkGraphOptions): Promise<ElkLayout>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Runs ELK on a line's graph and maps the result into what the view draws.
|
|
2
|
+
import ELK from "elkjs/lib/elk.bundled.js";
|
|
3
|
+
import { elkGraphOf } from "./elk-graph";
|
|
4
|
+
/** Lays out a line with ELK: node centres, one SVG path and label centre per edge, and the canvas box. */
|
|
5
|
+
export async function layoutWithElk(definition, size, options) {
|
|
6
|
+
const laidOut = await new ELK().layout(elkGraphOf(definition, size, options));
|
|
7
|
+
const nodes = nodesOf(laidOut);
|
|
8
|
+
return {
|
|
9
|
+
nodes,
|
|
10
|
+
edges: edgesOf(laidOut, definition, nodes),
|
|
11
|
+
contentBox: { minX: 0, minY: 0, maxX: laidOut.width ?? 0, maxY: laidOut.height ?? 0 },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function nodesOf(laidOut) {
|
|
15
|
+
return (laidOut.children ?? []).map(({ id, x: left = 0, y: top = 0, width = 0, height = 0, ports = [] }) => ({
|
|
16
|
+
id,
|
|
17
|
+
x: left + width / 2,
|
|
18
|
+
y: top + height / 2,
|
|
19
|
+
width,
|
|
20
|
+
height,
|
|
21
|
+
ports: ports.map((port) => portOf(port, left, top)),
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
function portOf({ id, x: portLeft = 0, y: portTop = 0, width = 0, height = 0 }, left, top) {
|
|
25
|
+
const separator = id.lastIndexOf(":");
|
|
26
|
+
return {
|
|
27
|
+
edge: id.slice(0, separator),
|
|
28
|
+
side: id.slice(separator + 1) === "in" ? "in" : "out",
|
|
29
|
+
x: left + portLeft + width / 2,
|
|
30
|
+
y: top + portTop + height / 2,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function edgesOf(laidOut, definition, nodes) {
|
|
34
|
+
const centreX = new Map(nodes.map(({ id, x: centre }) => [id, centre]));
|
|
35
|
+
return (laidOut.edges ?? []).map((laidOutEdge, index) => {
|
|
36
|
+
const { from, to, on } = definition.edges[index];
|
|
37
|
+
const labelBox = labelBoxOf(laidOutEdge.labels?.[0]);
|
|
38
|
+
return {
|
|
39
|
+
from,
|
|
40
|
+
to,
|
|
41
|
+
on,
|
|
42
|
+
kind: edgeKindOf(from, to, centreX),
|
|
43
|
+
d: pathOf(laidOutEdge.sections?.[0]),
|
|
44
|
+
mid: centreOf(labelBox),
|
|
45
|
+
labelBox,
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function pathOf(section) {
|
|
50
|
+
if (!section)
|
|
51
|
+
return "";
|
|
52
|
+
const { startPoint, bendPoints = [], endPoint } = section;
|
|
53
|
+
return [startPoint, ...bendPoints, endPoint].map(({ x: pointX, y: pointY }, index) => `${index === 0 ? "M" : "L"} ${pointX} ${pointY}`).join(" ");
|
|
54
|
+
}
|
|
55
|
+
function labelBoxOf(label) {
|
|
56
|
+
const { x: left = 0, y: top = 0, width = 0, height = 0 } = label ?? {};
|
|
57
|
+
return { minX: left, minY: top, maxX: left + width, maxY: top + height };
|
|
58
|
+
}
|
|
59
|
+
function centreOf({ minX, minY, maxX, maxY }) {
|
|
60
|
+
return { x: (minX + maxX) / 2, y: (minY + maxY) / 2, vertical: false };
|
|
61
|
+
}
|
|
62
|
+
function edgeKindOf(from, to, centreX) {
|
|
63
|
+
if (from === to)
|
|
64
|
+
return "self";
|
|
65
|
+
return (centreX.get(to) ?? 0) > (centreX.get(from) ?? 0) ? "forward" : "back";
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=elk-layout.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import DanglingStub from "./DanglingStub";
|
|
3
|
+
import ExitDot from "./ExitDot";
|
|
4
|
+
export function markerOf(node, exit) {
|
|
5
|
+
if (node.id.endsWith(":exit")) {
|
|
6
|
+
return _jsx(ExitDot, { node: node, exit: exit }, node.id);
|
|
7
|
+
}
|
|
8
|
+
return node.id.endsWith(":stub") ? _jsx(DanglingStub, { node: node }, node.id) : null;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=graph-markers.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition, DefinitionNode } from "./assembly-line-definition";
|
|
2
|
+
export type ConnectorTone = "ok" | "warn" | "err" | "neutral";
|
|
3
|
+
export interface VisibleNode {
|
|
4
|
+
id: string;
|
|
5
|
+
type: DefinitionNode["type"];
|
|
6
|
+
/** Outcomes leaving this node, in definition order. */
|
|
7
|
+
outcomes: readonly string[];
|
|
8
|
+
isEntry: boolean;
|
|
9
|
+
isExit: boolean;
|
|
10
|
+
isFail: boolean;
|
|
11
|
+
fanout?: DefinitionNode["fanout"];
|
|
12
|
+
outsideStart?: string;
|
|
13
|
+
hasProblem: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface VisibleEdge {
|
|
16
|
+
from: string;
|
|
17
|
+
to: string;
|
|
18
|
+
/** The outcome that takes this hop. */
|
|
19
|
+
on: string;
|
|
20
|
+
tone: ConnectorTone;
|
|
21
|
+
/** The outcome that takes this hop, with its iteration cap when it has one. */
|
|
22
|
+
label: string;
|
|
23
|
+
/** The node has other targets, so the outcome is what tells this hop from its siblings. */
|
|
24
|
+
branching: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface VisibleGraph {
|
|
27
|
+
nodes: readonly VisibleNode[];
|
|
28
|
+
edges: readonly VisibleEdge[];
|
|
29
|
+
}
|
|
30
|
+
/** The nodes and connectors to draw: one connector per outcome. */
|
|
31
|
+
export declare function deriveVisibleGraph(definition: AssemblyLineDefinition | null): VisibleGraph;
|
|
32
|
+
/** Outcome (or edge condition) to a connector/badge tone. */
|
|
33
|
+
export declare function outcomeTone(outcome: string): ConnectorTone;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Map a definition to drawable nodes and connectors.
|
|
2
|
+
/** The nodes and connectors to draw: one connector per outcome. */
|
|
3
|
+
export function deriveVisibleGraph(definition) {
|
|
4
|
+
if (!definition) {
|
|
5
|
+
return { nodes: [], edges: [] };
|
|
6
|
+
}
|
|
7
|
+
const outgoing = new Map(definition.nodes.map((node) => [
|
|
8
|
+
node.id,
|
|
9
|
+
definition.edges.filter((edge) => edge.from === node.id),
|
|
10
|
+
]));
|
|
11
|
+
return {
|
|
12
|
+
nodes: definition.nodes.map((node) => visibleNode(node, definition, outgoing.get(node.id) ?? [])),
|
|
13
|
+
edges: [...outgoing].flatMap(([from, edges]) => connectorsFor(from, edges)),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Outcomes are listed on the SOURCE node, so a connector never repeats a verdict the node already states. */
|
|
17
|
+
function visibleNode(node, { entry, exit, fail }, outgoing) {
|
|
18
|
+
return {
|
|
19
|
+
id: node.id,
|
|
20
|
+
type: node.type,
|
|
21
|
+
outcomes: outgoing.map((edge) => edge.on),
|
|
22
|
+
isEntry: node.id === entry,
|
|
23
|
+
isExit: node.id === exit,
|
|
24
|
+
isFail: node.id === fail,
|
|
25
|
+
fanout: node.fanout,
|
|
26
|
+
outsideStart: node.outsideStart,
|
|
27
|
+
hasProblem: node.hasProblem === true,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** One connector per definition edge, in definition order. The outcome sets the tone; a source with several distinct targets is branching. */
|
|
31
|
+
function connectorsFor(from, outgoing) {
|
|
32
|
+
const branching = new Set(outgoing.map((edge) => edge.to)).size > 1;
|
|
33
|
+
return outgoing.map((edge) => ({
|
|
34
|
+
from,
|
|
35
|
+
to: edge.to,
|
|
36
|
+
on: edge.on,
|
|
37
|
+
tone: outcomeTone(edge.on),
|
|
38
|
+
label: hopLabel(edge),
|
|
39
|
+
branching,
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
function hopLabel({ on, iterationMax }) {
|
|
43
|
+
return iterationMax === undefined ? on : `${on} (max ${iterationMax})`;
|
|
44
|
+
}
|
|
45
|
+
/** Outcome (or edge condition) to a connector/badge tone. */
|
|
46
|
+
export function outcomeTone(outcome) {
|
|
47
|
+
if (outcome.includes("failed")) {
|
|
48
|
+
return "err";
|
|
49
|
+
}
|
|
50
|
+
if (outcome === "changes_requested") {
|
|
51
|
+
return "warn";
|
|
52
|
+
}
|
|
53
|
+
return outcome === "success" ? "ok" : "neutral";
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=graph-view-model.js.map
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default as RunGraphView } from "./RunGraphView";
|
|
2
|
+
export type { RunGraphViewProps } from "./RunGraphView";
|
|
3
|
+
export type { AssemblyLineDefinition, DefinitionEdge, DefinitionNode, DefinitionNodeKind } from "./assembly-line-definition";
|
|
4
|
+
export { deriveVisibleGraph } from "./graph-view-model";
|
|
5
|
+
export type { VisibleGraph, VisibleNode, VisibleEdge } from "./graph-view-model";
|
|
6
|
+
export { edgeKeyOf } from "./metro/edge-key";
|
|
7
|
+
export { mainPathOf } from "./metro/main-path";
|
|
8
|
+
export type { Visit } from "./metro/taken-lines";
|
|
9
|
+
export { visitedPartOf } from "./metro/visited-part";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as RunGraphView } from "./RunGraphView";
|
|
2
|
+
export { deriveVisibleGraph } from "./graph-view-model";
|
|
3
|
+
export { edgeKeyOf } from "./metro/edge-key";
|
|
4
|
+
export { mainPathOf } from "./metro/main-path";
|
|
5
|
+
export { visitedPartOf } from "./metro/visited-part";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ElkLayout } from "./elk-layout";
|
|
2
|
+
/** Lists each edge segment that crosses a station box other than the edge's own endpoints. */
|
|
3
|
+
export declare function linesThroughStations(layout: ElkLayout): {
|
|
4
|
+
edge: string;
|
|
5
|
+
station: string;
|
|
6
|
+
}[];
|
|
7
|
+
/** Lists each edge whose path runs through the label box of another edge. */
|
|
8
|
+
export declare function linesOverLabels(layout: ElkLayout): {
|
|
9
|
+
edge: string;
|
|
10
|
+
label: string;
|
|
11
|
+
}[];
|
|
12
|
+
/** Lists each interior segment of an edge path, never the first or last, shorter than the minimum. */
|
|
13
|
+
export declare function tinyTurns(layout: ElkLayout, minimum: number): {
|
|
14
|
+
edge: string;
|
|
15
|
+
length: number;
|
|
16
|
+
}[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { edgeKeyOf } from "./metro/edge-key";
|
|
2
|
+
const STATION_MARGIN = 2;
|
|
3
|
+
/** Lists each edge segment that crosses a station box other than the edge's own endpoints. */
|
|
4
|
+
export function linesThroughStations(layout) {
|
|
5
|
+
return layout.edges.flatMap((edge) => stationsCrossedBy(edge, layout.nodes).map((station) => ({ edge: edgeKeyOf(edge), station: station.id })));
|
|
6
|
+
}
|
|
7
|
+
/** Lists each edge whose path runs through the label box of another edge. */
|
|
8
|
+
export function linesOverLabels(layout) {
|
|
9
|
+
return layout.edges.flatMap((edge) => labelsCrossedBy(edge, layout.edges).map((labelled) => ({ edge: edgeKeyOf(edge), label: edgeKeyOf(labelled) })));
|
|
10
|
+
}
|
|
11
|
+
/** Lists each interior segment of an edge path, never the first or last, shorter than the minimum. */
|
|
12
|
+
export function tinyTurns(layout, minimum) {
|
|
13
|
+
return layout.edges.flatMap((edge) => segmentsOf(edge)
|
|
14
|
+
.slice(1, -1)
|
|
15
|
+
.map(lengthOf)
|
|
16
|
+
.filter((length) => length < minimum)
|
|
17
|
+
.map((length) => ({ edge: edgeKeyOf(edge), length })));
|
|
18
|
+
}
|
|
19
|
+
/** Paths are axis-aligned, so one of the two spans is always zero. */
|
|
20
|
+
function lengthOf(segment) {
|
|
21
|
+
return segment.right - segment.left + (segment.bottom - segment.top);
|
|
22
|
+
}
|
|
23
|
+
/** The other edges whose label box the edge's path runs through; an edge never counts against its own label. */
|
|
24
|
+
function labelsCrossedBy(edge, edges) {
|
|
25
|
+
const segments = segmentsOf(edge);
|
|
26
|
+
const others = edges.filter((other) => other !== edge);
|
|
27
|
+
return others.filter((other) => segments.some((segment) => overlaps(segment, labelBoxOf(other))));
|
|
28
|
+
}
|
|
29
|
+
/** The stations, other than the edge's own endpoints, whose box the edge's path runs through. */
|
|
30
|
+
function stationsCrossedBy(edge, stations) {
|
|
31
|
+
const segments = segmentsOf(edge);
|
|
32
|
+
const others = stations.filter((station) => station.id !== edge.from && station.id !== edge.to);
|
|
33
|
+
return others.filter((station) => segments.some((segment) => overlaps(segment, stationBoxOf(station))));
|
|
34
|
+
}
|
|
35
|
+
/** One bounding box per straight stretch of the edge's path. */
|
|
36
|
+
function segmentsOf({ d }) {
|
|
37
|
+
const coordinates = (d.match(/-?\d+(\.\d+)?/g) ?? []).map(Number);
|
|
38
|
+
const corners = Array.from({ length: coordinates.length / 2 }, (slot, index) => ({ across: coordinates[index * 2], down: coordinates[index * 2 + 1] }));
|
|
39
|
+
return corners.slice(1).map((end, index) => {
|
|
40
|
+
const start = corners[index];
|
|
41
|
+
return { left: Math.min(start.across, end.across), right: Math.max(start.across, end.across), top: Math.min(start.down, end.down), bottom: Math.max(start.down, end.down) };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function labelBoxOf({ labelBox }) {
|
|
45
|
+
return { left: labelBox.minX, right: labelBox.maxX, top: labelBox.minY, bottom: labelBox.maxY };
|
|
46
|
+
}
|
|
47
|
+
/** The station box shrunk by a margin, so a path grazing the border does not count as crossing. */
|
|
48
|
+
function stationBoxOf(station) {
|
|
49
|
+
const halfWidth = station.width / 2 - STATION_MARGIN;
|
|
50
|
+
const halfHeight = station.height / 2 - STATION_MARGIN;
|
|
51
|
+
return { left: station.x - halfWidth, right: station.x + halfWidth, top: station.y - halfHeight, bottom: station.y + halfHeight };
|
|
52
|
+
}
|
|
53
|
+
function overlaps(first, second) {
|
|
54
|
+
return first.left < second.right && first.right > second.left && first.top < second.bottom && first.bottom > second.top;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=layout-geometry.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ElkLayout } from "../elk-layout";
|
|
2
|
+
export type LayoutDiff = {
|
|
3
|
+
added: string[];
|
|
4
|
+
moved: string[];
|
|
5
|
+
removed: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function diffLayouts(before: ElkLayout | null, after: ElkLayout): LayoutDiff;
|
|
8
|
+
export type NodeOffset = {
|
|
9
|
+
dx: number;
|
|
10
|
+
dy: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function offsetsOf(before: ElkLayout | null, after: ElkLayout): Map<string, NodeOffset>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { edgeKeyOf } from "./edge-key";
|
|
2
|
+
export function diffLayouts(before, after) {
|
|
3
|
+
if (before === null)
|
|
4
|
+
return { added: [], moved: [], removed: [] };
|
|
5
|
+
const beforeSignatures = signaturesOf(before);
|
|
6
|
+
const afterSignatures = signaturesOf(after);
|
|
7
|
+
const afterKeys = [...afterSignatures.keys()];
|
|
8
|
+
return {
|
|
9
|
+
added: afterKeys.filter((key) => !beforeSignatures.has(key)),
|
|
10
|
+
moved: afterKeys.filter((key) => beforeSignatures.has(key) && beforeSignatures.get(key) !== afterSignatures.get(key)),
|
|
11
|
+
removed: [...beforeSignatures.keys()].filter((key) => !afterSignatures.has(key)),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function signaturesOf({ nodes, edges }) {
|
|
15
|
+
const signatures = new Map();
|
|
16
|
+
for (const node of nodes)
|
|
17
|
+
signatures.set(node.id, `${node.x},${node.y}`);
|
|
18
|
+
for (const edge of edges)
|
|
19
|
+
signatures.set(edgeKeyOf(edge), edge.d);
|
|
20
|
+
return signatures;
|
|
21
|
+
}
|
|
22
|
+
export function offsetsOf(before, after) {
|
|
23
|
+
const offsets = new Map();
|
|
24
|
+
const oldNodes = new Map((before?.nodes ?? []).map((node) => [node.id, node]));
|
|
25
|
+
for (const node of after.nodes) {
|
|
26
|
+
const old = oldNodes.get(node.id);
|
|
27
|
+
if (old)
|
|
28
|
+
offsets.set(node.id, { dx: old.x - node.x, dy: old.y - node.y });
|
|
29
|
+
}
|
|
30
|
+
return offsets;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=layout-diff.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition } from "../assembly-line-definition";
|
|
2
|
+
/** The station ids and `edgeKeyOf` keys that make up the main line. */
|
|
3
|
+
export interface MainPath {
|
|
4
|
+
nodes: ReadonlySet<string>;
|
|
5
|
+
edges: ReadonlySet<string>;
|
|
6
|
+
}
|
|
7
|
+
/** The stations and edges from the entry along `success`, or along `always` when nothing succeeds, until the exit, a repeat or a dead end. */
|
|
8
|
+
export declare function mainPathOf(definition: AssemblyLineDefinition): MainPath;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { declaredIdsOf } from "./declared-ids";
|
|
2
|
+
import { edgeKeyOf } from "./edge-key";
|
|
3
|
+
import { outgoingEdgesOf } from "./node-edges";
|
|
4
|
+
/** The stations and edges from the entry along `success`, or along `always` when nothing succeeds, until the exit, a repeat or a dead end. */
|
|
5
|
+
export function mainPathOf(definition) {
|
|
6
|
+
const declaredIds = declaredIdsOf(definition);
|
|
7
|
+
if (!declaredIds.has(definition.entry))
|
|
8
|
+
return { nodes: new Set(), edges: new Set() };
|
|
9
|
+
const nodes = new Set([definition.entry]);
|
|
10
|
+
const edges = new Set();
|
|
11
|
+
let current = definition.entry;
|
|
12
|
+
let next = forwardEdgeFrom(definition, current);
|
|
13
|
+
const canStepTo = (edge) => edge !== undefined && declaredIds.has(edge.to) && !nodes.has(edge.to);
|
|
14
|
+
while (current !== definition.exit && canStepTo(next)) {
|
|
15
|
+
edges.add(edgeKeyOf(next));
|
|
16
|
+
nodes.add(next.to);
|
|
17
|
+
current = next.to;
|
|
18
|
+
next = forwardEdgeFrom(definition, current);
|
|
19
|
+
}
|
|
20
|
+
return { nodes, edges };
|
|
21
|
+
}
|
|
22
|
+
function forwardEdgeFrom(definition, nodeId) {
|
|
23
|
+
const outgoing = outgoingEdgesOf(definition, nodeId);
|
|
24
|
+
return outgoing.find((edge) => edge.on === "success") ?? outgoing.find((edge) => edge.on === "always");
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=main-path.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition } from "../assembly-line-definition";
|
|
2
|
+
export interface Neighbourhood {
|
|
3
|
+
nodes: ReadonlySet<string>;
|
|
4
|
+
edges: ReadonlySet<string>;
|
|
5
|
+
}
|
|
6
|
+
/** `nodeId`, everything reachable from it, everything that reaches it, and the edges between them. */
|
|
7
|
+
export declare function neighbourhoodOf(definition: AssemblyLineDefinition, nodeId: string): Neighbourhood;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { declaredIdsOf } from "./declared-ids";
|
|
2
|
+
import { edgeKeyOf } from "./edge-key";
|
|
3
|
+
import { incomingEdgesOf, outgoingEdgesOf } from "./node-edges";
|
|
4
|
+
/** `nodeId`, everything reachable from it, everything that reaches it, and the edges between them. */
|
|
5
|
+
export function neighbourhoodOf(definition, nodeId) {
|
|
6
|
+
if (!declaredIdsOf(definition).has(nodeId))
|
|
7
|
+
return { nodes: new Set(), edges: new Set() };
|
|
8
|
+
const nodes = new Set([
|
|
9
|
+
...walk(definition, nodeId, outgoingEdgesOf, (edge) => edge.to),
|
|
10
|
+
...walk(definition, nodeId, incomingEdgesOf, (edge) => edge.from),
|
|
11
|
+
]);
|
|
12
|
+
return { nodes, edges: new Set(edgeKeysWithin(definition.edges, nodes)) };
|
|
13
|
+
}
|
|
14
|
+
function edgeKeysWithin(edges, nodes) {
|
|
15
|
+
return edges.filter((edge) => nodes.has(edge.from) && nodes.has(edge.to)).map(edgeKeyOf);
|
|
16
|
+
}
|
|
17
|
+
function walk(definition, startId, edgesAt, nextOf) {
|
|
18
|
+
const visited = new Set([startId]);
|
|
19
|
+
const pending = [startId];
|
|
20
|
+
while (pending.length > 0) {
|
|
21
|
+
const reached = edgesAt(definition, pending.pop()).map(nextOf);
|
|
22
|
+
const unseen = reached.filter((id) => !visited.has(id));
|
|
23
|
+
unseen.forEach((id) => visited.add(id));
|
|
24
|
+
pending.push(...new Set(unseen));
|
|
25
|
+
}
|
|
26
|
+
return visited;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=neighbourhood.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition, DefinitionEdge } from "../assembly-line-definition";
|
|
2
|
+
/** The edges of `definition` that start at `nodeId`, in declaration order. */
|
|
3
|
+
export declare function outgoingEdgesOf(definition: AssemblyLineDefinition, nodeId: string): DefinitionEdge[];
|
|
4
|
+
/** The edges of `definition` that end at `nodeId`, in declaration order. */
|
|
5
|
+
export declare function incomingEdgesOf(definition: AssemblyLineDefinition, nodeId: string): DefinitionEdge[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The edges of `definition` that start at `nodeId`, in declaration order. */
|
|
2
|
+
export function outgoingEdgesOf(definition, nodeId) {
|
|
3
|
+
return definition.edges.filter((edge) => edge.from === nodeId);
|
|
4
|
+
}
|
|
5
|
+
/** The edges of `definition` that end at `nodeId`, in declaration order. */
|
|
6
|
+
export function incomingEdgesOf(definition, nodeId) {
|
|
7
|
+
return definition.edges.filter((edge) => edge.to === nodeId);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=node-edges.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { incomingEdgesOf, outgoingEdgesOf } from "./node-edges";
|
|
2
|
+
/** True when the station `nodeId` of `definition` is a pass-through. */
|
|
3
|
+
export function isPassThrough(definition, nodeId) {
|
|
4
|
+
return isRelayingNode(definition, nodeId) && hasRelayingEdges(definition, nodeId);
|
|
5
|
+
}
|
|
6
|
+
function isRelayingNode(definition, nodeId) {
|
|
7
|
+
const declaredNode = definition.nodes.find((node) => node.id === nodeId);
|
|
8
|
+
const isStartedFromOutside = declaredNode?.outsideStart !== undefined;
|
|
9
|
+
return declaredNode !== undefined && nodeId !== definition.entry && !isStartedFromOutside;
|
|
10
|
+
}
|
|
11
|
+
function hasRelayingEdges(definition, nodeId) {
|
|
12
|
+
const outgoing = outgoingEdgesOf(definition, nodeId);
|
|
13
|
+
const hasSingleAlwaysEdgeOut = outgoing.length === 1 && outgoing[0].on === "always";
|
|
14
|
+
return incomingEdgesOf(definition, nodeId).length === 1 && hasSingleAlwaysEdgeOut;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=pass-through.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition } from "../assembly-line-definition";
|
|
2
|
+
/** Stations nothing leads to, and the `edgeKeyOf` keys of edges with an undeclared source or target. */
|
|
3
|
+
export interface Reachability {
|
|
4
|
+
unreachable: ReadonlySet<string>;
|
|
5
|
+
danglingEdges: ReadonlySet<string>;
|
|
6
|
+
}
|
|
7
|
+
/** Walks from the entry and every outside start; reports declared stations never reached and edges touching undeclared nodes. */
|
|
8
|
+
export declare function reachabilityOf(definition: AssemblyLineDefinition): Reachability;
|