@re-cinq/floor-graph 0.0.0-stage → 0.6.2
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 +44 -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,31 @@
|
|
|
1
|
+
import { declaredIdsOf } from "./declared-ids";
|
|
2
|
+
import { edgeKeyOf } from "./edge-key";
|
|
3
|
+
import { outgoingEdgesOf } from "./node-edges";
|
|
4
|
+
/** Walks from the entry and every outside start; reports declared stations never reached and edges touching undeclared nodes. */
|
|
5
|
+
export function reachabilityOf(definition) {
|
|
6
|
+
const reached = reachedFrom([definition.entry, ...outsideStartIdsOf(definition)], definition);
|
|
7
|
+
const declaredIds = declaredIdsOf(definition);
|
|
8
|
+
const unreachable = new Set([...declaredIds].filter((id) => !reached.has(id)));
|
|
9
|
+
return { unreachable, danglingEdges: danglingEdgeKeysOf(definition, declaredIds) };
|
|
10
|
+
}
|
|
11
|
+
function outsideStartIdsOf(definition) {
|
|
12
|
+
const outsideStarted = definition.nodes.filter((node) => node.outsideStart);
|
|
13
|
+
return outsideStarted.map((node) => node.id);
|
|
14
|
+
}
|
|
15
|
+
function danglingEdgeKeysOf(definition, declaredIds) {
|
|
16
|
+
const dangling = definition.edges.filter((edge) => !declaredIds.has(edge.to) || !declaredIds.has(edge.from));
|
|
17
|
+
return new Set(dangling.map(edgeKeyOf));
|
|
18
|
+
}
|
|
19
|
+
function reachedFrom(startIds, definition) {
|
|
20
|
+
const reached = new Set(startIds);
|
|
21
|
+
const frontier = [...startIds];
|
|
22
|
+
for (const current of frontier) {
|
|
23
|
+
const nextIds = outgoingEdgesOf(definition, current)
|
|
24
|
+
.filter((edge) => !reached.has(edge.to))
|
|
25
|
+
.map((edge) => edge.to);
|
|
26
|
+
nextIds.forEach((id) => reached.add(id));
|
|
27
|
+
frontier.push(...nextIds);
|
|
28
|
+
}
|
|
29
|
+
return reached;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=reachability.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ElkLayout, LaidOutNode } from "../elk-layout";
|
|
2
|
+
import type { VisibleGraph, VisibleNode } from "../graph-view-model";
|
|
3
|
+
export interface RemovedStation {
|
|
4
|
+
node: LaidOutNode;
|
|
5
|
+
model: VisibleNode;
|
|
6
|
+
}
|
|
7
|
+
/** A layout together with the graph it was drawn from. */
|
|
8
|
+
export interface Drawn {
|
|
9
|
+
layout: ElkLayout;
|
|
10
|
+
graph: VisibleGraph;
|
|
11
|
+
}
|
|
12
|
+
/** The stations of `before` that `after` no longer has, with the model each was drawn from. */
|
|
13
|
+
export declare function removedStationsOf({ layout, graph }: Drawn, after: ElkLayout): RemovedStation[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { diffLayouts } from "./layout-diff";
|
|
2
|
+
/** The stations of `before` that `after` no longer has, with the model each was drawn from. */
|
|
3
|
+
export function removedStationsOf({ layout, graph }, after) {
|
|
4
|
+
const gone = new Set(diffLayouts(layout, after).removed);
|
|
5
|
+
const models = new Map(graph.nodes.map((model) => [model.id, model]));
|
|
6
|
+
return layout.nodes.flatMap((node) => {
|
|
7
|
+
const model = models.get(node.id);
|
|
8
|
+
return model && gone.has(node.id) ? [{ node, model }] : [];
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=removed-stations.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function stationVisitsOf(visits) {
|
|
2
|
+
return [...visits]
|
|
3
|
+
.sort((earlier, later) => earlier.iteration - later.iteration)
|
|
4
|
+
.reduce((stations, visit) => stations.set(visit.nodeId, afterVisit(stations.get(visit.nodeId), visit)), new Map());
|
|
5
|
+
}
|
|
6
|
+
function afterVisit(before, visit) {
|
|
7
|
+
return {
|
|
8
|
+
count: (before?.count ?? 0) + 1,
|
|
9
|
+
outcome: visit.open ? before?.outcome : visit.outcome,
|
|
10
|
+
open: visit.open,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=station-visits.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition } from "../assembly-line-definition";
|
|
2
|
+
export type Direction = "right" | "left" | "up" | "down";
|
|
3
|
+
export interface Cursor {
|
|
4
|
+
nodeId: string;
|
|
5
|
+
lineIndex: number;
|
|
6
|
+
}
|
|
7
|
+
/** The cursor after one step in `direction`; right follows the edge at the cursor's line index, left returns along the first incoming edge, down and up cycle the station's lines with wrapping; impossible moves stay put. */
|
|
8
|
+
export declare function stepAlong(definition: AssemblyLineDefinition, cursor: Cursor, direction: Direction): Cursor;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { declaredIdsOf } from "./declared-ids";
|
|
2
|
+
import { incomingEdgesOf, outgoingEdgesOf } from "./node-edges";
|
|
3
|
+
const stepRight = (definition, cursor) => {
|
|
4
|
+
const edge = cursor.lineIndex < 0 ? undefined : outgoingEdgesOf(definition, cursor.nodeId).at(cursor.lineIndex);
|
|
5
|
+
if (!edge || !declaredIdsOf(definition).has(edge.to))
|
|
6
|
+
return cursor;
|
|
7
|
+
return { nodeId: edge.to, lineIndex: 0 };
|
|
8
|
+
};
|
|
9
|
+
function cycleLine(offset) {
|
|
10
|
+
return (definition, cursor) => {
|
|
11
|
+
const edgeCount = outgoingEdgesOf(definition, cursor.nodeId).length;
|
|
12
|
+
if (edgeCount === 0)
|
|
13
|
+
return cursor;
|
|
14
|
+
return { nodeId: cursor.nodeId, lineIndex: (((cursor.lineIndex + offset) % edgeCount) + edgeCount) % edgeCount };
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const stepLeft = (definition, cursor) => {
|
|
18
|
+
const incoming = incomingEdgesOf(definition, cursor.nodeId).at(0);
|
|
19
|
+
if (!incoming || !declaredIdsOf(definition).has(incoming.from))
|
|
20
|
+
return cursor;
|
|
21
|
+
return { nodeId: incoming.from, lineIndex: outgoingEdgesOf(definition, incoming.from).indexOf(incoming) };
|
|
22
|
+
};
|
|
23
|
+
const stepsByDirection = { right: stepRight, left: stepLeft, down: cycleLine(1), up: cycleLine(-1) };
|
|
24
|
+
/** The cursor after one step in `direction`; right follows the edge at the cursor's line index, left returns along the first incoming edge, down and up cycle the station's lines with wrapping; impossible moves stay put. */
|
|
25
|
+
export function stepAlong(definition, cursor, direction) {
|
|
26
|
+
return stepsByDirection[direction](definition, cursor);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=step-along.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const COUNT_CHAR_WIDTH = 6;
|
|
2
|
+
export declare const COUNT_GAP = 3;
|
|
3
|
+
/** What a line taken more than once says beside its label. */
|
|
4
|
+
export declare function countTextOf(count: number): string;
|
|
5
|
+
/** The room that text takes after the label: zero for a line taken once or never. */
|
|
6
|
+
export declare function countWidthOf(count: number): number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const COUNT_CHAR_WIDTH = 6;
|
|
2
|
+
export const COUNT_GAP = 3;
|
|
3
|
+
/** What a line taken more than once says beside its label. */
|
|
4
|
+
export function countTextOf(count) {
|
|
5
|
+
return `×${count}`;
|
|
6
|
+
}
|
|
7
|
+
/** The room that text takes after the label: zero for a line taken once or never. */
|
|
8
|
+
export function countWidthOf(count) {
|
|
9
|
+
return count > 1 ? COUNT_GAP + countTextOf(count).length * COUNT_CHAR_WIDTH : 0;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=taken-count.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition, DefinitionEdge } from "../assembly-line-definition";
|
|
2
|
+
/** One station run, as `docs/assembly_run_storage.md`, "The rows", describes it. */
|
|
3
|
+
export interface Visit {
|
|
4
|
+
nodeId: string;
|
|
5
|
+
iteration: number;
|
|
6
|
+
outcome?: string;
|
|
7
|
+
open: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Lore's rule, first match wins: an edge whose `on` equals the outcome, then one whose `on` is a `-<on>` suffix of it, then the `always` edge. */
|
|
10
|
+
export declare function edgeTakenBy(outgoing: readonly DefinitionEdge[], outcome: string | undefined): DefinitionEdge | undefined;
|
|
11
|
+
/** Maps an `edgeKeyOf` key to how often a run took that edge. */
|
|
12
|
+
export declare function takenLinesOf(definition: AssemblyLineDefinition, visits: readonly Visit[]): ReadonlyMap<string, number>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { edgeKeyOf } from "./edge-key";
|
|
2
|
+
import { outgoingEdgesOf } from "./node-edges";
|
|
3
|
+
/** Lore's rule, first match wins: an edge whose `on` equals the outcome, then one whose `on` is a `-<on>` suffix of it, then the `always` edge. */
|
|
4
|
+
export function edgeTakenBy(outgoing, outcome) {
|
|
5
|
+
return (outgoing.find((edge) => edge.on === outcome) ??
|
|
6
|
+
outgoing.find((edge) => edge.on && outcome?.endsWith(`-${edge.on}`)) ??
|
|
7
|
+
outgoing.find((edge) => edge.on === "always"));
|
|
8
|
+
}
|
|
9
|
+
/** Maps an `edgeKeyOf` key to how often a run took that edge. */
|
|
10
|
+
export function takenLinesOf(definition, visits) {
|
|
11
|
+
return visits
|
|
12
|
+
.filter((visit) => !visit.open)
|
|
13
|
+
.map((visit) => edgeTakenBy(outgoingEdgesOf(definition, visit.nodeId), visit.outcome))
|
|
14
|
+
.filter((edge) => edge !== undefined)
|
|
15
|
+
.reduce((taken, edge) => {
|
|
16
|
+
const key = edgeKeyOf(edge);
|
|
17
|
+
return taken.set(key, (taken.get(key) ?? 0) + 1);
|
|
18
|
+
}, new Map());
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=taken-lines.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition } from "../assembly-line-definition";
|
|
2
|
+
import { type Visit } from "./taken-lines";
|
|
3
|
+
/** The visited stations, the lines the run took and the stations those lines reach. A run always starts at the entry, so the entry counts as visited even when the run records no visit for it. */
|
|
4
|
+
export declare function visitedPartOf(definition: AssemblyLineDefinition, visits: readonly Visit[]): AssemblyLineDefinition;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { edgeKeyOf } from "./edge-key";
|
|
2
|
+
import { takenLinesOf } from "./taken-lines";
|
|
3
|
+
/** The visited stations, the lines the run took and the stations those lines reach. A run always starts at the entry, so the entry counts as visited even when the run records no visit for it. */
|
|
4
|
+
export function visitedPartOf(definition, visits) {
|
|
5
|
+
const taken = takenLinesOf(definition, withEntryVisit(definition.entry, visits));
|
|
6
|
+
const edges = definition.edges.filter((edge) => taken.has(edgeKeyOf(edge)));
|
|
7
|
+
const keptIds = new Set([
|
|
8
|
+
definition.entry,
|
|
9
|
+
...visits.map((visit) => visit.nodeId),
|
|
10
|
+
...edges.map((edge) => edge.to),
|
|
11
|
+
]);
|
|
12
|
+
return {
|
|
13
|
+
...definition,
|
|
14
|
+
exit: keptIds.has(definition.exit) ? definition.exit : "",
|
|
15
|
+
nodes: definition.nodes.filter((node) => keptIds.has(node.id)),
|
|
16
|
+
edges,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function withEntryVisit(entry, visits) {
|
|
20
|
+
return visits.some((visit) => visit.nodeId === entry)
|
|
21
|
+
? visits
|
|
22
|
+
: [{ nodeId: entry, iteration: 0, open: false }, ...visits];
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=visited-part.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { VisibleNode } from "./graph-view-model";
|
|
2
|
+
export interface LabelledNode {
|
|
3
|
+
node: VisibleNode;
|
|
4
|
+
/** Nothing leaves it. */
|
|
5
|
+
isTerminal: boolean;
|
|
6
|
+
/** No start leads to it. */
|
|
7
|
+
isUnreachable?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function nodeAriaLabel({ node, isTerminal, isUnreachable }: LabelledNode): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { badgesOf } from "./node-badges";
|
|
2
|
+
import { FAMILY_LABEL, typeFamilyOf } from "./node-type-family";
|
|
3
|
+
export function nodeAriaLabel({ node, isTerminal, isUnreachable }) {
|
|
4
|
+
const family = FAMILY_LABEL[typeFamilyOf(node.type)].toLowerCase();
|
|
5
|
+
const badges = badgesOf(node).map(({ description }) => description);
|
|
6
|
+
const outcomes = node.outcomes.length > 0 ? [`outcomes: ${node.outcomes.join(", ")}`] : [];
|
|
7
|
+
const terminal = isTerminal ? ["terminal"] : [];
|
|
8
|
+
const unreachable = isUnreachable ? ["unreachable"] : [];
|
|
9
|
+
return [node.id, family, ...badges, ...outcomes, ...terminal, ...unreachable].join(", ");
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=node-aria-label.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VisibleNode } from "./graph-view-model";
|
|
2
|
+
export type NodeBadgeKind = "entry" | "exit" | "fail" | "fanout" | "event" | "problem";
|
|
3
|
+
export interface NodeBadge {
|
|
4
|
+
kind: NodeBadgeKind;
|
|
5
|
+
label: string;
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function badgesOf(node: VisibleNode): NodeBadge[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function badgesOf(node) {
|
|
2
|
+
return [...rolesOf(node), ...factsOf(node)];
|
|
3
|
+
}
|
|
4
|
+
function rolesOf(node) {
|
|
5
|
+
const roles = [
|
|
6
|
+
node.isEntry ? { kind: "entry", label: "entry", description: "the line starts here" } : undefined,
|
|
7
|
+
node.isExit ? { kind: "exit", label: "exit", description: "the line ends here" } : undefined,
|
|
8
|
+
node.isFail ? { kind: "fail", label: "fail", description: "the line ends here as failed" } : undefined,
|
|
9
|
+
];
|
|
10
|
+
return roles.filter((badge) => badge !== undefined);
|
|
11
|
+
}
|
|
12
|
+
function factsOf(node) {
|
|
13
|
+
const facts = [
|
|
14
|
+
node.fanout ? { kind: "fanout", label: "fan-out", description: `fans out over ${node.fanout.over} to ${node.fanout.to}` } : undefined,
|
|
15
|
+
node.outsideStart ? { kind: "event", label: "event", description: `started by the outside event ${node.outsideStart}` } : undefined,
|
|
16
|
+
node.hasProblem ? { kind: "problem", label: "problem", description: "has a problem" } : undefined,
|
|
17
|
+
];
|
|
18
|
+
return facts.filter((badge) => badge !== undefined);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=node-badges.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AssemblyLineDefinition } from "./assembly-line-definition";
|
|
2
|
+
import { type NodeTypeFamily } from "./node-type-family";
|
|
3
|
+
export interface NodeTooltip {
|
|
4
|
+
title: string;
|
|
5
|
+
kind: string;
|
|
6
|
+
family: NodeTypeFamily;
|
|
7
|
+
description: string;
|
|
8
|
+
}
|
|
9
|
+
/** Null for a node the line does not have. */
|
|
10
|
+
export declare function nodeTooltipOf(nodeId: string, definition: AssemblyLineDefinition): NodeTooltip | null;
|
|
11
|
+
/** A node's id as its box and its tooltip title it: the first letter up. */
|
|
12
|
+
export declare function nodeTitle(id: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { FAMILY_LABEL, typeFamilyOf, } from "./node-type-family";
|
|
2
|
+
const NO_DESCRIPTION = "No description yet.";
|
|
3
|
+
/** Null for a node the line does not have. */
|
|
4
|
+
export function nodeTooltipOf(nodeId, definition) {
|
|
5
|
+
const node = definition.nodes.find((candidate) => candidate.id === nodeId);
|
|
6
|
+
if (!node) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const family = typeFamilyOf(node.type);
|
|
10
|
+
return {
|
|
11
|
+
title: nodeTitle(node.id),
|
|
12
|
+
kind: FAMILY_LABEL[family],
|
|
13
|
+
family,
|
|
14
|
+
description: family === "marker"
|
|
15
|
+
? markerSentence(nodeId, definition)
|
|
16
|
+
: (node.description ?? NO_DESCRIPTION),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** A node's id as its box and its tooltip title it: the first letter up. */
|
|
20
|
+
export function nodeTitle(id) {
|
|
21
|
+
return id.charAt(0).toUpperCase() + id.slice(1);
|
|
22
|
+
}
|
|
23
|
+
function markerSentence(nodeId, { entry, exit, fail }) {
|
|
24
|
+
if (nodeId === fail) {
|
|
25
|
+
return "The line ends here, as failed.";
|
|
26
|
+
}
|
|
27
|
+
if (nodeId === exit) {
|
|
28
|
+
return "The line ends here.";
|
|
29
|
+
}
|
|
30
|
+
return nodeId === entry
|
|
31
|
+
? "Where the line starts."
|
|
32
|
+
: "A waypoint the line passes through; no work happens here.";
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=node-tooltip.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DefinitionNodeKind } from "./assembly-line-definition";
|
|
2
|
+
export type NodeTypeFamily = "agent" | "service" | "person" | "marker";
|
|
3
|
+
/** A family as the legend and a node's tooltip name it. */
|
|
4
|
+
export declare const FAMILY_LABEL: Record<NodeTypeFamily, string>;
|
|
5
|
+
/** agent: an AI pod runs it. person: it waits on someone. marker: a point in the line with no work of its own. service: run by a machine. */
|
|
6
|
+
export declare function typeFamilyOf(nodeType: DefinitionNodeKind | undefined): NodeTypeFamily;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** A family as the legend and a node's tooltip name it. */
|
|
2
|
+
export const FAMILY_LABEL = {
|
|
3
|
+
agent: "Agent",
|
|
4
|
+
service: "Service",
|
|
5
|
+
person: "Human",
|
|
6
|
+
marker: "Marker",
|
|
7
|
+
};
|
|
8
|
+
const FAMILY_OF_TYPE = {
|
|
9
|
+
agent: "agent",
|
|
10
|
+
service: "service",
|
|
11
|
+
human: "person",
|
|
12
|
+
marker: "marker",
|
|
13
|
+
};
|
|
14
|
+
/** agent: an AI pod runs it. person: it waits on someone. marker: a point in the line with no work of its own. service: run by a machine. */
|
|
15
|
+
export function typeFamilyOf(nodeType) {
|
|
16
|
+
return nodeType === undefined ? "marker" : FAMILY_OF_TYPE[nodeType];
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=node-type-family.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ElkLayout } from "./elk-layout";
|
|
2
|
+
import type { VisibleGraph } from "./graph-view-model";
|
|
3
|
+
export type Drawing = ReturnType<typeof drawingOf>;
|
|
4
|
+
/** Everything the drawing needs: ELK's layout, the viewport it fits, and the model lookups. */
|
|
5
|
+
export declare function drawingOf(layout: ElkLayout, graph: VisibleGraph, name: string, stops: ReadonlySet<string>): {
|
|
6
|
+
layout: ElkLayout;
|
|
7
|
+
stops: ReadonlySet<string>;
|
|
8
|
+
view: import("./run-graph-geometry").FittedView;
|
|
9
|
+
titleId: string;
|
|
10
|
+
nodeById: Map<string, import("./graph-view-model").VisibleNode>;
|
|
11
|
+
edgeByKey: Map<string, import("./graph-view-model").VisibleEdge>;
|
|
12
|
+
toneByEdge: Map<string, import("./graph-view-model").ConnectorTone>;
|
|
13
|
+
nodesWithOutgoing: Set<string>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { edgeKeyOf } from "./metro/edge-key";
|
|
2
|
+
import { fitView } from "./run-graph-geometry";
|
|
3
|
+
/** Everything the drawing needs: ELK's layout, the viewport it fits, and the model lookups. */
|
|
4
|
+
export function drawingOf(layout, graph, name, stops) {
|
|
5
|
+
return {
|
|
6
|
+
layout,
|
|
7
|
+
stops,
|
|
8
|
+
view: fitView(layout.contentBox),
|
|
9
|
+
titleId: `graph-title-${name}`,
|
|
10
|
+
...graphLookups(graph),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** The lookups that let the drawing match a laid-out node or edge back to its model. A node with no outgoing edge is terminal, which is read from the EDGES rather than from the node, because a definition does not mark its own ends. */
|
|
14
|
+
function graphLookups({ nodes, edges }) {
|
|
15
|
+
return {
|
|
16
|
+
nodeById: new Map(nodes.map((node) => [node.id, node])),
|
|
17
|
+
edgeByKey: new Map(edges.map((edge) => [edgeKeyOf(edge), edge])),
|
|
18
|
+
toneByEdge: new Map(edges.map((edge) => [edgeKeyOf(edge), edge.tone])),
|
|
19
|
+
nodesWithOutgoing: new Set(edges.map((edge) => edge.from)),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=run-graph-drawing.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Box } from "./elk-layout";
|
|
2
|
+
export declare const NODE_WIDTH = 216;
|
|
3
|
+
export declare const NODE_HEIGHT = 60;
|
|
4
|
+
export declare const VIEW_PADDING = 28;
|
|
5
|
+
export declare function cardWidthOf(title: string, subtitle?: string): number;
|
|
6
|
+
export interface FittedView {
|
|
7
|
+
viewBox: string;
|
|
8
|
+
originX: number;
|
|
9
|
+
originY: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function fitView(box: Box): FittedView;
|
|
14
|
+
export declare function revealBoxOf(node: {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
width: number;
|
|
18
|
+
}, view: FittedView, nodeHeight: number): Box;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Station card size, the same for every card; ELK is given the same size.
|
|
2
|
+
export const NODE_WIDTH = 216;
|
|
3
|
+
export const NODE_HEIGHT = 60;
|
|
4
|
+
// Clear space kept around the drawing.
|
|
5
|
+
export const VIEW_PADDING = 28;
|
|
6
|
+
// Where a node's text starts (right of the glyph) and the gap it leaves at the far edge.
|
|
7
|
+
const LABEL_LEFT_OFFSET = 40;
|
|
8
|
+
const LABEL_RIGHT_PADDING = 12;
|
|
9
|
+
// Average advance of the node font in px — an average, not a measurement, since SVG text cannot reflow and per-glyph measuring needs a DOM round-trip.
|
|
10
|
+
const LABEL_CHAR_WIDTH = 6.8;
|
|
11
|
+
export function cardWidthOf(title, subtitle = "") {
|
|
12
|
+
const longestLine = Math.max(title.length, subtitle.length);
|
|
13
|
+
return Math.max(NODE_WIDTH, Math.ceil(LABEL_LEFT_OFFSET + longestLine * LABEL_CHAR_WIDTH + LABEL_RIGHT_PADDING));
|
|
14
|
+
}
|
|
15
|
+
const PADDING = VIEW_PADDING;
|
|
16
|
+
const MIN_VIEW_WIDTH = 480;
|
|
17
|
+
const MIN_VIEW_HEIGHT = 200;
|
|
18
|
+
// A padded viewBox around the content, floored to a natural size.
|
|
19
|
+
export function fitView(box) {
|
|
20
|
+
const width = Math.max(box.maxX - box.minX + PADDING * 2, MIN_VIEW_WIDTH);
|
|
21
|
+
const height = Math.max(box.maxY - box.minY + PADDING * 2, MIN_VIEW_HEIGHT);
|
|
22
|
+
const originX = box.minX - PADDING;
|
|
23
|
+
const originY = (box.minY + box.maxY) / 2 - height / 2;
|
|
24
|
+
return {
|
|
25
|
+
viewBox: `${originX} ${originY} ${width} ${height}`,
|
|
26
|
+
originX,
|
|
27
|
+
originY,
|
|
28
|
+
width,
|
|
29
|
+
height,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// A node's box in drawing coordinates, which start at the viewBox origin rather than at the layout's.
|
|
33
|
+
export function revealBoxOf(node, view, nodeHeight) {
|
|
34
|
+
const minX = node.x - node.width / 2 - view.originX;
|
|
35
|
+
const minY = node.y - nodeHeight / 2 - view.originY;
|
|
36
|
+
return { minX, minY, maxX: minX + node.width, maxY: minY + nodeHeight };
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=run-graph-geometry.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ConnectorTone } from "./graph-view-model";
|
|
2
|
+
export declare function classes(...names: (string | undefined)[]): string;
|
|
3
|
+
export declare function edgeStrokeClass(tone: ConnectorTone): string;
|
|
4
|
+
export declare function textFillClass(tone: ConnectorTone): string;
|
|
5
|
+
export declare function portFillClass(tone: ConnectorTone | "in"): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import styles from "./run-graph.module.css";
|
|
2
|
+
const EDGE_STROKE = {
|
|
3
|
+
ok: styles.toneOk,
|
|
4
|
+
warn: styles.toneWarn,
|
|
5
|
+
err: styles.toneErr,
|
|
6
|
+
neutral: styles.toneNeutral,
|
|
7
|
+
};
|
|
8
|
+
const TEXT_FILL = {
|
|
9
|
+
ok: styles.outOk,
|
|
10
|
+
warn: styles.outWarn,
|
|
11
|
+
err: styles.outErr,
|
|
12
|
+
neutral: styles.outNeutral,
|
|
13
|
+
};
|
|
14
|
+
// Join class names, dropping ones a CSS module does not define (e.g. `styles.forward` when `.forward` has no rule).
|
|
15
|
+
export function classes(...names) {
|
|
16
|
+
return names.filter(Boolean).join(" ");
|
|
17
|
+
}
|
|
18
|
+
export function edgeStrokeClass(tone) {
|
|
19
|
+
return EDGE_STROKE[tone];
|
|
20
|
+
}
|
|
21
|
+
export function textFillClass(tone) {
|
|
22
|
+
return TEXT_FILL[tone];
|
|
23
|
+
}
|
|
24
|
+
const PORT_FILL = {
|
|
25
|
+
ok: styles.portOk,
|
|
26
|
+
warn: styles.portWarn,
|
|
27
|
+
err: styles.portErr,
|
|
28
|
+
neutral: styles.portNeutral,
|
|
29
|
+
in: styles.portIn,
|
|
30
|
+
};
|
|
31
|
+
export function portFillClass(tone) {
|
|
32
|
+
return PORT_FILL[tone];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=run-graph-tone-classes.js.map
|