@re-cinq/floor-graph 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @re-cinq/floor-graph
2
2
 
3
- A React view of an assembly line as a graph: layout, pan and zoom, nodes and edges. [elkjs](https://github.com/kieler/elkjs) lays the line out: stations left to right, every line on its own ports, routed at right angles around stations and labels. It ships compiled JS and its CSS modules, so use it from a bundler such as Vite.
3
+ A React view of an assembly line as a graph: layout, pan and zoom, nodes and edges. [elkjs](https://github.com/kieler/elkjs) lays it out with stations left to right, every edge on its own ports, routed at right angles around stations and labels. The package ships compiled JS and its CSS modules, so use it from a bundler such as Vite.
4
4
 
5
5
  ```
6
6
  npm install @re-cinq/floor-graph
@@ -12,8 +12,34 @@ import { RunGraphView, type AssemblyLineDefinition } from "@re-cinq/floor-graph"
12
12
  <RunGraphView definition={definition} />;
13
13
  ```
14
14
 
15
- The controls hold zoom, fit and two toggles. "Main path" fades every station and line off the path from the entry along `success` (or the first `always` when nothing succeeds). "Compact stops" draws a station with one line in and one `always` line out as a stop on the track, unless it is the entry or is started from outside. The `mainPathOnly` and `compactStops` props set where each toggle starts. `onSelectLine(key)` and `selectedLineKey` select a line by its `from|to|event` key (`edgeKeyOf`). On a focused station, Down and Up choose one of its out-lines (drawn bold), Right moves to the station that line leads to, Left goes back along an in-line, and Enter selects. When the definition changes, new stations and lines flash for 1.2 s (`diffLayouts` against the last layout; the first draw flashes nothing) and moved lines slide to their new route. A station that moves after an edit slides to its new place over 400 ms; motion is off under `prefers-reduced-motion`.
15
+ ## Controls
16
16
 
17
- Pass `run={{ visits }}` (`Visit`: `nodeId`, `iteration`, `outcome?`, `open`) to overlay one assembly run. A line the run did not take fades to 30% (`takenLinesOf`, lore's first-match rule). A line taken more than once shows ×N beside its label, and the layout reserves room for it. An unvisited station fades to 40%; a visited card's own border takes the colour of its last closed outcome, its subtitle counts visits above one (`agent · 2 visits`), and while a visit is open it adds ` · open` and the border pulses. With a run, `show` defaults to `"visited"`: ELK lays out only the entry, the visited stations, the lines the run took and the stations they reach (`visitedPartOf`), so the graph stays small. A "Whole line" toggle brings in the rest, faded; `show="all"` starts there. A station removed by an edit, or hidden by turning "Whole line" off, fades out over 300 ms.
17
+ The controls hold zoom, fit and two toggles. The `mainPathOnly` and `compactStops` props set where each toggle starts.
18
18
 
19
- Started as a copy of re-cinq/lore-security `apps/web-ui/src` at commit 4598c19791154a2ae6afffa65e8b26c0825140b6, with everything about a run stripped. The layout is no longer lore's.
19
+ - "Main path" fades every station and edge off the path from the entry along `success`, or along the first `always` when nothing succeeds.
20
+ - "Compact stops" draws a station with one edge in and one `always` edge out as a stop on the track, unless it is the entry or is started from outside.
21
+
22
+ ## Selection and keyboard
23
+
24
+ `onSelectLine(key)` and `selectedLineKey` select an edge by its `from|to|event` key (`edgeKeyOf`).
25
+
26
+ On a focused station, Down and Up choose one of its outgoing edges, which is drawn bold. Right moves to the station that edge leads to, Left goes back along an incoming edge, and Enter selects.
27
+
28
+ ## When the definition changes
29
+
30
+ New stations and edges flash for 1.2 s (`diffLayouts` against the last layout, and the first draw flashes nothing). Moved edges slide to their new route, and a station that moves slides to its new place over 400 ms. Motion is off under `prefers-reduced-motion`.
31
+
32
+ ## Overlaying an assembly run
33
+
34
+ Pass `run={{ visits }}` to overlay one assembly run. A `Visit` is `nodeId`, `iteration`, `outcome?` and `open`.
35
+
36
+ - An edge the run did not take fades to 30% (`takenLinesOf`, lore's first-match rule).
37
+ - An edge taken more than once shows ×N beside its label, and the layout reserves room for it.
38
+ - An unvisited station fades to 40%.
39
+ - A visited card's border takes the colour of its last closed outcome. Its subtitle counts visits above one (`agent · 2 visits`). While a visit is open the subtitle adds ` · open` and the border's dashes march round it. `waiting={{ id: label }}` makes an open visit there read as that label, with a solid border.
40
+
41
+ With a run, `show` defaults to `"visited"`. ELK then lays out only the entry, the visited stations, the edges the run took and the stations they reach (`visitedPartOf`), so the graph stays small. A "Whole line" toggle brings in the rest, faded, and `show="all"` starts there. A station removed by an edit, or hidden by turning "Whole line" off, fades out over 300 ms.
42
+
43
+ ## Origin
44
+
45
+ The package started as a copy of re-cinq/lore-security `apps/web-ui/src` at commit 4598c19791154a2ae6afffa65e8b26c0825140b6, with everything about a run stripped. The layout is no longer lore's.
package/dist/GraphNode.js CHANGED
@@ -45,11 +45,16 @@ function stationAttrsOf(props, family, shape) {
45
45
  }
46
46
  function runAttrsOf({ visited, outcome, status, }) {
47
47
  return {
48
- "data-open": status?.open || undefined,
48
+ ...openAttrsOf(status),
49
49
  "data-visited": visited === false ? "false" : undefined,
50
50
  "data-outcome": outcome,
51
51
  };
52
52
  }
53
+ function openAttrsOf(status) {
54
+ return status?.waiting
55
+ ? { "data-waiting": "true" }
56
+ : { "data-open": status?.open || undefined };
57
+ }
53
58
  function changeAttrOf({ added, moved, removed }) {
54
59
  if (removed)
55
60
  return { "data-change": "removed", "aria-hidden": true };
@@ -21,6 +21,8 @@ export interface RunGraphViewProps {
21
21
  on: string;
22
22
  };
23
23
  run?: RunOverlay;
24
+ /** Stations that wait on someone, by id, and what they wait on: an open visit there reads as waiting, not working. */
25
+ waiting?: Readonly<Record<string, string>>;
24
26
  /** Draws the whole line or only the part the run walked; defaults to the walked part when a run is given. */
25
27
  show?: "all" | "visited";
26
28
  }
@@ -1,6 +1,6 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // Renders an assembly line — lays out the nodes/connectors from graph-view-model and hands drawing to its sibling files; every node also says its outcomes and badges as text, so meaning never rests on color alone.
3
- import { useMemo, useState } from "react";
3
+ import { useCallback, useMemo, useState } from "react";
4
4
  import { useToggle } from "./use-toggle";
5
5
  import { useElkLayout } from "./use-elk-layout";
6
6
  import { drawingOf } from "./run-graph-drawing";
@@ -34,11 +34,11 @@ export default function RunGraphView(givenProps) {
34
34
  }
35
35
  return (_jsxs("section", { className: styles.panel, "aria-label": `Graph of ${props.definition.name}`, children: [_jsx(GraphCanvas, { view: props, graph: graph }), _jsx(RunGraphLegend, { families: familiesOf(graph) })] }));
36
36
  }
37
- /** The whole definition or the part the run visited, and the toggle between them, offered only with a run. */
37
+ /** The whole definition or the part the run visited, and the toggle between them, offered only with a run. Until it is pressed, the default follows the props, so a run that arrives after the first draw still opens on its visited part. */
38
38
  function useWholeLine({ definition, run, show }) {
39
- const [wholeLineOn, toggleWholeLine] = useToggle({
40
- initiallyOn: (show ?? (run ? "visited" : "all")) === "all",
41
- });
39
+ const [pressedOn, setPressedOn] = useState(null);
40
+ const wholeLineOn = pressedOn ?? (show ?? (run ? "visited" : "all")) === "all";
41
+ const toggleWholeLine = useCallback(() => setPressedOn(!wholeLineOn), [wholeLineOn]);
42
42
  const shown = useMemo(() => run && !wholeLineOn ? visitedPartOf(definition, run.visits) : definition, [definition, run, wholeLineOn]);
43
43
  return useMemo(() => ({
44
44
  definition: shown,
@@ -88,7 +88,7 @@ function useGraphCanvasState(view, graph) {
88
88
  };
89
89
  }
90
90
  /** The stations no start leads to, the lines a run took, and the main line of the definition while `mainPathOnly` is set (else null). */
91
- function useLineMarkings({ definition, run, mainPathOnly: initialMainPathOnly, }) {
91
+ function useLineMarkings({ definition, run, waiting, mainPathOnly: initialMainPathOnly, }) {
92
92
  const [mainPathOnly, toggleMainPath] = useToggle({
93
93
  initiallyOn: initialMainPathOnly,
94
94
  });
@@ -100,7 +100,7 @@ function useLineMarkings({ definition, run, mainPathOnly: initialMainPathOnly, }
100
100
  mainPathOnly,
101
101
  toggleMainPath,
102
102
  taken: useTakenLines(definition, run),
103
- visits: useStationVisits(run),
103
+ visits: useStationVisits(run, waiting),
104
104
  };
105
105
  }
106
106
  /** The layout, asked to compact its stops when `compactStops` is set, and the stations drawn as stops: the pass-through ones. */
@@ -21,6 +21,7 @@ export interface DefinitionEdge {
21
21
  /** The outcome that takes this edge. */
22
22
  on: string;
23
23
  iterationMax?: number;
24
+ unattendedMax?: number;
24
25
  }
25
26
  export interface AssemblyLineDefinition {
26
27
  name: string;
@@ -0,0 +1,3 @@
1
+ import type { DefinitionEdge } from "./assembly-line-definition";
2
+ /** `max I` for iterationMax, then `max U unattended` for unattendedMax; each only when set. */
3
+ export declare function limitTextsOf({ iterationMax, unattendedMax }: DefinitionEdge): string[];
@@ -0,0 +1,7 @@
1
+ /** `max I` for iterationMax, then `max U unattended` for unattendedMax; each only when set. */
2
+ export function limitTextsOf({ iterationMax, unattendedMax }) {
3
+ const iterationText = iterationMax === undefined ? [] : [`max ${iterationMax}`];
4
+ const unattendedText = unattendedMax === undefined ? [] : [`max ${unattendedMax} unattended`];
5
+ return [...iterationText, ...unattendedText];
6
+ }
7
+ //# sourceMappingURL=edge-limit-texts.js.map
package/dist/elk-graph.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { limitTextsOf } from "./edge-limit-texts";
1
2
  import { declaredIdsOf } from "./metro/declared-ids";
2
3
  import { edgeKeyOf } from "./metro/edge-key";
3
4
  import { mainPathOf } from "./metro/main-path";
@@ -120,8 +121,8 @@ function portOf(edge, direction, side) {
120
121
  layoutOptions: { "elk.port.side": side },
121
122
  };
122
123
  }
123
- function edgeLabelOf({ on, iterationMax }, takenCount = 0) {
124
- const text = iterationMax === undefined ? on : `${on} · max ${iterationMax}`;
124
+ function edgeLabelOf(edge, takenCount = 0) {
125
+ const text = [edge.on, ...limitTextsOf(edge)].join(" · ");
125
126
  return {
126
127
  text,
127
128
  width: Math.ceil(text.length * LABEL_CHAR_WIDTH + LABEL_PADDING + countWidthOf(takenCount)),
@@ -1,4 +1,5 @@
1
1
  // Map a definition to drawable nodes and connectors.
2
+ import { limitTextsOf } from "./edge-limit-texts";
2
3
  /** The nodes and connectors to draw: one connector per outcome. */
3
4
  export function deriveVisibleGraph(definition) {
4
5
  if (!definition) {
@@ -39,8 +40,9 @@ function connectorsFor(from, outgoing) {
39
40
  branching,
40
41
  }));
41
42
  }
42
- function hopLabel({ on, iterationMax }) {
43
- return iterationMax === undefined ? on : `${on} (max ${iterationMax})`;
43
+ function hopLabel(edge) {
44
+ const limits = limitTextsOf(edge);
45
+ return limits.length === 0 ? edge.on : `${edge.on} (${limits.join(", ")})`;
44
46
  }
45
47
  /** Outcome (or edge condition) to a connector/badge tone. */
46
48
  export function outcomeTone(outcome) {
@@ -3,5 +3,7 @@ export interface StationVisits {
3
3
  count: number;
4
4
  outcome?: string;
5
5
  open: boolean;
6
+ waiting?: string;
6
7
  }
7
8
  export declare function stationVisitsOf(visits: readonly Visit[]): ReadonlyMap<string, StationVisits>;
9
+ export declare function withWaiting(stations: ReadonlyMap<string, StationVisits>, waiting?: Readonly<Record<string, string>>): ReadonlyMap<string, StationVisits>;
@@ -10,4 +10,12 @@ function afterVisit(before, visit) {
10
10
  open: visit.open,
11
11
  };
12
12
  }
13
+ export function withWaiting(stations, waiting = {}) {
14
+ return new Map([...stations].map(([nodeId, status]) => [
15
+ nodeId,
16
+ status.open && nodeId in waiting
17
+ ? { ...status, waiting: waiting[nodeId] }
18
+ : status,
19
+ ]));
20
+ }
13
21
  //# sourceMappingURL=station-visits.js.map
@@ -1,5 +1,5 @@
1
1
  import type { AssemblyLineDefinition, DefinitionEdge } from "../assembly-line-definition";
2
- /** One station run, as `docs/entities/assembly-run.md` describes it. */
2
+ /** One station run, as `docs/assembly_run_storage.md`, "The rows", describes it. */
3
3
  export interface Visit {
4
4
  nodeId: string;
5
5
  iteration: number;
@@ -129,7 +129,7 @@
129
129
  [data-chosen="true"] .edge {
130
130
  stroke-width: 3.5;
131
131
  }
132
- text[data-selected="true"] {
132
+ .svg text[data-selected="true"] {
133
133
  font-weight: var(--fw-bold, 700);
134
134
  }
135
135
 
@@ -177,13 +177,18 @@ text[data-selected="true"] {
177
177
  stroke-width: 4;
178
178
  filter: brightness(0.8) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.12));
179
179
  }
180
+ /* An open visit: the dashes march round the border. One period of the 6 4 dash is 10, so the loop has no seam. */
180
181
  .node[data-open="true"] .box {
181
182
  stroke-dasharray: 6 4;
182
- animation: openPulse 1.6s ease-in-out infinite;
183
+ animation: openMarch 0.8s linear infinite;
183
184
  }
184
- @keyframes openPulse {
185
- 50% {
186
- opacity: 0.55;
185
+ /* A station waiting on someone: a solid border, no march. */
186
+ .node[data-waiting="true"] .box {
187
+ stroke: var(--wait);
188
+ }
189
+ @keyframes openMarch {
190
+ to {
191
+ stroke-dashoffset: -10;
187
192
  }
188
193
  }
189
194
  @media (prefers-reduced-motion: reduce) {
@@ -388,12 +393,12 @@ text[data-selected="true"] {
388
393
  fill: var(--text-muted);
389
394
  }
390
395
 
391
- [data-dim="true"] {
396
+ .svg [data-dim="true"] {
392
397
  opacity: 0.15;
393
398
  transition: opacity 150ms;
394
399
  }
395
400
 
396
- [data-off-path="true"] {
401
+ .svg [data-off-path="true"] {
397
402
  opacity: 0.25;
398
403
  transition: opacity 150ms;
399
404
  }
@@ -422,14 +427,14 @@ text[data-selected="true"] {
422
427
  opacity: 0;
423
428
  }
424
429
  }
425
- [data-change="added"] {
430
+ .svg [data-change="added"] {
426
431
  animation: changeFlash 1.2s ease-out;
427
432
  }
428
- [data-change="moved"] {
433
+ .svg [data-change="moved"] {
429
434
  transition: transform 400ms ease;
430
435
  }
431
436
 
432
- [data-change="removed"] {
437
+ .svg [data-change="removed"] {
433
438
  animation: changeFade 300ms ease-out forwards;
434
439
  pointer-events: none;
435
440
  }
@@ -437,11 +442,11 @@ text[data-selected="true"] {
437
442
  transition: d 400ms;
438
443
  }
439
444
  @media (prefers-reduced-motion: reduce) {
440
- [data-change="added"],
441
- [data-change="removed"] {
445
+ .svg [data-change="added"],
446
+ .svg [data-change="removed"] {
442
447
  animation: none;
443
448
  }
444
- [data-change="moved"] {
449
+ .svg [data-change="moved"] {
445
450
  transition: none;
446
451
  }
447
452
  .edge {
@@ -449,12 +454,12 @@ text[data-selected="true"] {
449
454
  }
450
455
  }
451
456
 
452
- [data-taken="false"] {
457
+ .svg [data-taken="false"] {
453
458
  opacity: 0.3;
454
459
  transition: opacity 150ms;
455
460
  }
456
461
 
457
- [data-visited="false"] {
462
+ .svg [data-visited="false"] {
458
463
  opacity: 0.4;
459
464
  transition: opacity 150ms;
460
465
  }
@@ -1,6 +1,6 @@
1
1
  export function subtitleOf(kind, status) {
2
2
  const visitCount = status && status.count > 1 ? ` · ${status.count} visits` : "";
3
- const openMark = status?.open ? " · open" : "";
3
+ const openMark = status?.open ? ` · ${status.waiting ?? "open"}` : "";
4
4
  return `${kind}${visitCount}${openMark}`;
5
5
  }
6
6
  //# sourceMappingURL=station-subtitle.js.map
@@ -4,4 +4,4 @@ export interface RunOverlay {
4
4
  visits: readonly Visit[];
5
5
  }
6
6
  export declare function useTakenLines(definition: AssemblyLineDefinition, run: RunOverlay | undefined): ReadonlyMap<string, number> | undefined;
7
- export declare function useStationVisits(run: RunOverlay | undefined): ReadonlyMap<string, import("./metro/station-visits").StationVisits> | undefined;
7
+ export declare function useStationVisits(run: RunOverlay | undefined, waiting?: Readonly<Record<string, string>>): ReadonlyMap<string, import("./metro/station-visits").StationVisits> | undefined;
@@ -1,11 +1,11 @@
1
1
  // The lines an assembly run took, for the graph to mark; undefined while no run is shown.
2
2
  import { useMemo } from "react";
3
- import { stationVisitsOf } from "./metro/station-visits";
3
+ import { stationVisitsOf, withWaiting } from "./metro/station-visits";
4
4
  import { takenLinesOf } from "./metro/taken-lines";
5
5
  export function useTakenLines(definition, run) {
6
6
  return useMemo(() => run && takenLinesOf(definition, run.visits), [definition, run]);
7
7
  }
8
- export function useStationVisits(run) {
9
- return useMemo(() => run && stationVisitsOf(run.visits), [run]);
8
+ export function useStationVisits(run, waiting) {
9
+ return useMemo(() => run && withWaiting(stationVisitsOf(run.visits), waiting), [run, waiting]);
10
10
  }
11
11
  //# sourceMappingURL=use-run-overlay.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@re-cinq/floor-graph",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "A React view of an assembly line as a graph: the layout of its nodes and edges, the viewport that fits and pans it, and the node and edge drawing, with the stylesheets it needs.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "typecheck": "tsc --noEmit"
46
46
  },
47
47
  "dependencies": {
48
- "@re-cinq/floor-contracts": "0.6.1",
48
+ "@re-cinq/floor-contracts": "0.7.0",
49
49
  "elkjs": "0.9.3"
50
50
  },
51
51
  "peerDependencies": {