@dxos/react-ui-graph 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/lib/browser/index.mjs +781 -43
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +781 -43
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/Graph/Graph.d.ts +15 -1
  8. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  9. package/dist/types/src/components/SVG/FPS.d.ts +20 -0
  10. package/dist/types/src/components/SVG/FPS.d.ts.map +1 -0
  11. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  12. package/dist/types/src/components/SVG/SVG.d.ts +3 -1
  13. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  14. package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +5 -0
  15. package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -1
  16. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  17. package/dist/types/src/graph/projector/graph-plexus-projector.d.ts +67 -0
  18. package/dist/types/src/graph/projector/graph-plexus-projector.d.ts.map +1 -0
  19. package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts +2 -0
  20. package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts.map +1 -0
  21. package/dist/types/src/graph/projector/graph-projector.d.ts +8 -0
  22. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  23. package/dist/types/src/graph/projector/graph-swarm-projector.d.ts +72 -0
  24. package/dist/types/src/graph/projector/graph-swarm-projector.d.ts.map +1 -0
  25. package/dist/types/src/graph/projector/index.d.ts +2 -0
  26. package/dist/types/src/graph/projector/index.d.ts.map +1 -1
  27. package/dist/types/src/graph/renderer/graph-renderer.d.ts +20 -0
  28. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  29. package/dist/types/src/graph/renderer/index.d.ts +1 -0
  30. package/dist/types/src/graph/renderer/index.d.ts.map +1 -1
  31. package/dist/types/src/graph/renderer/labels.d.ts +33 -0
  32. package/dist/types/src/graph/renderer/labels.d.ts.map +1 -0
  33. package/dist/types/src/stories/experimental.stories.d.ts +7 -0
  34. package/dist/types/src/stories/experimental.stories.d.ts.map +1 -0
  35. package/dist/types/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +17 -17
  37. package/src/components/Graph/Graph.tsx +70 -2
  38. package/src/components/SVG/FPS.tsx +91 -0
  39. package/src/components/SVG/Root.tsx +2 -1
  40. package/src/components/SVG/SVG.tsx +4 -1
  41. package/src/graph/projector/graph-cluster-projector.ts +12 -0
  42. package/src/graph/projector/graph-force-projector.ts +1 -0
  43. package/src/graph/projector/graph-plexus-projector.test.ts +102 -0
  44. package/src/graph/projector/graph-plexus-projector.ts +309 -0
  45. package/src/graph/projector/graph-projector.ts +15 -1
  46. package/src/graph/projector/graph-swarm-projector.ts +373 -0
  47. package/src/graph/projector/index.ts +2 -0
  48. package/src/graph/renderer/graph-renderer.ts +116 -3
  49. package/src/graph/renderer/index.ts +1 -0
  50. package/src/graph/renderer/labels.ts +138 -0
  51. package/src/stories/experimental.stories.tsx +446 -0
  52. package/styles/graph.css +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-graph",
3
- "version": "0.8.4-main.d05539e30a",
3
+ "version": "0.8.4-main.d9fc60f731",
4
4
  "description": "GEM Graph.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -44,13 +44,13 @@
44
44
  "lodash.defaultsdeep": "^4.6.1",
45
45
  "react-resize-detector": "^11.0.1",
46
46
  "topojson-client": "^3.1.0",
47
- "@dxos/debug": "0.8.4-main.d05539e30a",
48
- "@dxos/async": "0.8.4-main.d05539e30a",
49
- "@dxos/log": "0.8.4-main.d05539e30a",
50
- "@dxos/graph": "0.8.4-main.d05539e30a",
51
- "@dxos/node-std": "0.8.4-main.d05539e30a",
52
- "@dxos/invariant": "0.8.4-main.d05539e30a",
53
- "@dxos/react-ui-mosaic": "0.8.4-main.d05539e30a"
47
+ "@dxos/async": "0.8.4-main.d9fc60f731",
48
+ "@dxos/debug": "0.8.4-main.d9fc60f731",
49
+ "@dxos/graph": "0.8.4-main.d9fc60f731",
50
+ "@dxos/invariant": "0.8.4-main.d9fc60f731",
51
+ "@dxos/node-std": "0.8.4-main.d9fc60f731",
52
+ "@dxos/react-ui-mosaic": "0.8.4-main.d9fc60f731",
53
+ "@dxos/log": "0.8.4-main.d9fc60f731"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@babel/core": "^7.18.13",
@@ -63,21 +63,21 @@
63
63
  "postcss": "^8.5.12",
64
64
  "react": "~19.2.3",
65
65
  "react-dom": "~19.2.3",
66
- "@dxos/random": "0.8.4-main.d05539e30a",
67
- "@dxos/react-ui": "0.8.4-main.d05539e30a",
68
- "@dxos/react-ui-stack": "0.8.4-main.d05539e30a",
69
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.d05539e30a",
70
- "@dxos/storybook-utils": "0.8.4-main.d05539e30a",
71
- "@dxos/ui-theme": "0.8.4-main.d05539e30a"
66
+ "@dxos/react-ui-stack": "0.8.4-main.d9fc60f731",
67
+ "@dxos/storybook-utils": "0.8.4-main.d9fc60f731",
68
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.d9fc60f731",
69
+ "@dxos/ui-theme": "0.8.4-main.d9fc60f731",
70
+ "@dxos/react-ui": "0.8.4-main.d9fc60f731",
71
+ "@dxos/random": "0.8.4-main.d9fc60f731"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "react": "~19.2.3",
75
75
  "react-dom": "~19.2.3",
76
- "@dxos/react-ui": "0.8.4-main.d05539e30a",
77
- "@dxos/ui-theme": "0.8.4-main.d05539e30a"
76
+ "@dxos/react-ui": "0.8.4-main.d9fc60f731",
77
+ "@dxos/ui-theme": "0.8.4-main.d9fc60f731"
78
78
  },
79
79
  "optionalDependencies": {
80
- "@dxos/random": "0.8.4-main.d05539e30a"
80
+ "@dxos/random": "0.8.4-main.d9fc60f731"
81
81
  },
82
82
  "publishConfig": {
83
83
  "access": "public"
@@ -26,8 +26,14 @@ export type GraphController = {
26
26
  findNode: (id: string) => SVGGElement | null;
27
27
  };
28
28
 
29
+ /** Cursor position expressed in the same SVG model coordinates that node `x/y` live in (centered origin, post-zoom). */
30
+ export type ModelPoint = { x: number; y: number };
31
+
29
32
  export type GraphProps<Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge.Any = any> = ThemedClassName<
30
- Pick<GraphRendererOptions<Node>, 'labels' | 'subgraphs' | 'attributes' | 'renderNode'> & {
33
+ Pick<
34
+ GraphRendererOptions<Node>,
35
+ 'labels' | 'subgraphs' | 'attributes' | 'renderNode' | 'highlightOnHover' | 'applyNode' | 'edgeOpacity'
36
+ > & {
31
37
  model?: GraphModel.ReactiveGraphModel<Node, Edge>;
32
38
  projector?: GraphProjector<Node>;
33
39
  renderer?: GraphRenderer<Node>;
@@ -39,6 +45,15 @@ export type GraphProps<Node extends Graph$.Node.Any = any, Edge extends Graph$.E
39
45
  * Use the `null` signal to clear hover-driven previews / highlights.
40
46
  */
41
47
  onInspect?: (node: GraphLayoutNode<Node> | null, event: MouseEvent) => void;
48
+ /**
49
+ * Pointer-move in SVG model coordinates (the same space `node.x/y` live in — centered
50
+ * origin, post-zoom). The CTM lookup is done against the dx-graph group, so zoom + viewBox
51
+ * are both undone in one step. Pair with `onPointerLeave` to clear cursor-driven state.
52
+ * When either handler is set the renderer's `<svg>` is given `pointer-events: all` so
53
+ * events fire across empty canvas, not just over painted nodes.
54
+ */
55
+ onPointerMove?: (point: ModelPoint, event: PointerEvent) => void;
56
+ onPointerLeave?: (event: PointerEvent) => void;
42
57
  }
43
58
  >;
44
59
 
@@ -52,6 +67,8 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
52
67
  arrows,
53
68
  onSelect,
54
69
  onInspect,
70
+ onPointerMove,
71
+ onPointerLeave,
55
72
  ...props
56
73
  }: GraphProps<Node, Edge>,
57
74
  forwardedRef: Ref<GraphController>,
@@ -72,7 +89,14 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
72
89
  // TODO(burdon): Replace drag when projector is updated.
73
90
  drag: drag ? createGraphDrag(context, projector) : undefined,
74
91
  arrows: { end: arrows },
75
- onNodeClick: onSelect,
92
+ // Projector intercept first so built-in interactions (e.g. cluster collapse) can
93
+ // run without consumers wiring them. Returning true suppresses the user handler.
94
+ onNodeClick: (node, event) => {
95
+ if (projector.handleNodeClick(node, event)) {
96
+ return;
97
+ }
98
+ onSelect?.(node, event);
99
+ },
76
100
  onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : undefined,
77
101
  // Pair pointerenter with leave so consumers can clear hover-driven previews.
78
102
  // The callback receives `null` on leave (event still carries the source).
@@ -95,6 +119,9 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
95
119
  props.subgraphs,
96
120
  props.attributes,
97
121
  props.renderNode,
122
+ props.highlightOnHover,
123
+ props.applyNode,
124
+ props.edgeOpacity,
98
125
  ]);
99
126
 
100
127
  // External API.
@@ -154,6 +181,47 @@ const GraphInner = <Node extends Graph$.Node.Any = any, Edge extends Graph$.Edge
154
181
  };
155
182
  }, [projector]);
156
183
 
184
+ // Model-space pointer events. Attached to the SVG element so they fire across the entire
185
+ // canvas (with pointer-events: all), not just over painted nodes. The dx-graph group's CTM
186
+ // undoes both the centered viewBox and any active zoom in one step, landing the cursor in
187
+ // the same coordinate space the projector reads.
188
+ useEffect(() => {
189
+ if (!onPointerMove && !onPointerLeave) {
190
+ return;
191
+ }
192
+ const svg = context.svg;
193
+ if (!svg) {
194
+ return;
195
+ }
196
+ const previousPointerEvents = svg.style.pointerEvents;
197
+ svg.style.pointerEvents = 'all';
198
+ const handleMove = (event: PointerEvent) => {
199
+ if (!onPointerMove) {
200
+ return;
201
+ }
202
+ const target = graphRef.current;
203
+ const ctm = target?.getScreenCTM();
204
+ if (!target || !ctm) {
205
+ return;
206
+ }
207
+ const point = svg.createSVGPoint();
208
+ point.x = event.clientX;
209
+ point.y = event.clientY;
210
+ const modelPoint = point.matrixTransform(ctm.inverse());
211
+ onPointerMove({ x: modelPoint.x, y: modelPoint.y }, event);
212
+ };
213
+ const handleLeave = (event: PointerEvent) => {
214
+ onPointerLeave?.(event);
215
+ };
216
+ svg.addEventListener('pointermove', handleMove);
217
+ svg.addEventListener('pointerleave', handleLeave);
218
+ return () => {
219
+ svg.removeEventListener('pointermove', handleMove);
220
+ svg.removeEventListener('pointerleave', handleLeave);
221
+ svg.style.pointerEvents = previousPointerEvents;
222
+ };
223
+ }, [context, onPointerMove, onPointerLeave]);
224
+
157
225
  return <g ref={graphRef} className={mx('dx-graph', classNames)} />;
158
226
  };
159
227
 
@@ -0,0 +1,91 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import React, { useEffect, useState } from 'react';
6
+
7
+ import { type ThemedClassName } from '@dxos/react-ui';
8
+ import { mx } from '@dxos/ui-theme';
9
+
10
+ import { useSvgContext } from '../../hooks';
11
+
12
+ export type FPSCorner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
13
+
14
+ export type FPSProps = ThemedClassName<{
15
+ /** Which corner of the SVG viewport to anchor the readout to. */
16
+ corner?: FPSCorner;
17
+ /** Pixels of padding from the chosen corner. */
18
+ margin?: number;
19
+ }>;
20
+
21
+ const PADDING = 8;
22
+
23
+ /**
24
+ * Frame-rate readout — drops into an `<SVG.Root>` alongside `<SVG.Graph>` to display a
25
+ * rolling 1-second average of the browser's repaint rate. Self-contained: runs its own
26
+ * `requestAnimationFrame` loop, so the number reflects actual render rate independent of
27
+ * whichever projector is driving the graph.
28
+ *
29
+ * Anchored to a corner of the SVG viewBox via the `<text>`'s `text-anchor` and `dy`
30
+ * attributes — re-renders on `context.resized` so the position tracks container resizes.
31
+ */
32
+ export const FPS = ({ classNames, corner = 'top-right', margin = PADDING }: FPSProps) => {
33
+ const context = useSvgContext();
34
+ const [size, setSize] = useState(context.size);
35
+ const [fps, setFps] = useState<number | null>(null);
36
+
37
+ // Keep `size` in sync with the SVG context so the corner anchor follows container resizes.
38
+ useEffect(() => {
39
+ setSize(context.size);
40
+ return context.resized.on((ctx) => setSize(ctx.size));
41
+ }, [context]);
42
+
43
+ // Independent rAF loop — measures the browser's actual repaint rate, not any specific
44
+ // projector's tick rate. Rolling 1-second window so the number is responsive but stable.
45
+ useEffect(() => {
46
+ let frames = 0;
47
+ let windowStart = performance.now();
48
+ let rafId = 0;
49
+ const loop = (now: number) => {
50
+ frames++;
51
+ const elapsed = now - windowStart;
52
+ if (elapsed >= 1000) {
53
+ setFps((frames * 1000) / elapsed);
54
+ frames = 0;
55
+ windowStart = now;
56
+ }
57
+ rafId = requestAnimationFrame(loop);
58
+ };
59
+ rafId = requestAnimationFrame(loop);
60
+ return () => cancelAnimationFrame(rafId);
61
+ }, []);
62
+
63
+ if (!size) {
64
+ return null;
65
+ }
66
+
67
+ // The SVG.Root viewBox is centered ([-w/2, w/2] × [-h/2, h/2]); offset from the chosen
68
+ // corner inward by `margin` and pick the corresponding text-anchor / dominant-baseline.
69
+ const halfW = size.width / 2;
70
+ const halfH = size.height / 2;
71
+ const left = corner === 'top-left' || corner === 'bottom-left';
72
+ const top = corner === 'top-left' || corner === 'top-right';
73
+ const x = left ? -halfW + margin : halfW - margin;
74
+ const y = top ? -halfH + margin : halfH - margin;
75
+ const textAnchor = left ? 'start' : 'end';
76
+ const dominantBaseline = top ? 'hanging' : 'alphabetic';
77
+
78
+ return (
79
+ <g className='dx-fps' style={{ pointerEvents: 'none' }}>
80
+ <text
81
+ x={x}
82
+ y={y}
83
+ textAnchor={textAnchor}
84
+ dominantBaseline={dominantBaseline}
85
+ className={mx('font-mono text-xs fill-neutral-500 tabular-nums', classNames)}
86
+ >
87
+ {fps == null ? '— fps' : `${fps.toFixed(0)} fps`}
88
+ </text>
89
+ </g>
90
+ );
91
+ };
@@ -14,7 +14,8 @@ import React, {
14
14
  } from 'react';
15
15
 
16
16
  import { type ThemedClassName } from '@dxos/react-ui';
17
- import { composableProps, mx } from '@dxos/ui-theme';
17
+ import { composableProps } from '@dxos/react-ui';
18
+ import { mx } from '@dxos/ui-theme';
18
19
 
19
20
  import { SVGContext, type SVGContextOptions, SVGContextProvider } from '../../hooks';
20
21
 
@@ -8,6 +8,7 @@ import { type ThemedClassName } from '@dxos/react-ui';
8
8
 
9
9
  import { Graph, type GraphProps as SVGGraphProps } from '../Graph';
10
10
  import { Mesh, type MeshProps as SVGMeshProps } from '../Mesh';
11
+ import { FPS, type FPSProps as SVGFPSProps } from './FPS';
11
12
  import { Grid, type GridProps as SVGGridProps } from './Grid';
12
13
  import { Markers, type MarkersProps as SVGMarkersProps } from './Markers';
13
14
  import { Root, type RootProps as SVGRootProps } from './Root';
@@ -22,6 +23,7 @@ type SVG = {
22
23
  Mesh: typeof Mesh;
23
24
  Zoom: typeof Zoom;
24
25
  Graph: typeof Graph;
26
+ FPS: typeof FPS;
25
27
  };
26
28
 
27
29
  export const SVG: SVG = {
@@ -31,6 +33,7 @@ export const SVG: SVG = {
31
33
  Mesh,
32
34
  Zoom,
33
35
  Graph,
36
+ FPS,
34
37
  };
35
38
 
36
- export type { SVGRootProps, SVGGridProps, SVGMarkersProps, SVGZoomProps, SVGGraphProps, SVGMeshProps };
39
+ export type { SVGRootProps, SVGGridProps, SVGMarkersProps, SVGZoomProps, SVGGraphProps, SVGMeshProps, SVGFPSProps };
@@ -95,6 +95,18 @@ export class GraphClusterProjector<
95
95
  // would permanently lose the hidden leaves and they couldn't reappear on expand.
96
96
  #dataNodes: GraphLayoutNode<NodeData>[] = [];
97
97
 
98
+ /**
99
+ * Built-in click semantics: clicking a synthetic root / group node toggles its subtree.
100
+ * Leaf clicks fall through to the consumer's `onSelect` (returns `false`).
101
+ */
102
+ override handleNodeClick(node: GraphLayoutNode<NodeData>, _event: MouseEvent): boolean {
103
+ if (node.type !== CLUSTER_NODE_TYPE_ROOT && node.type !== CLUSTER_NODE_TYPE_GROUP) {
104
+ return false;
105
+ }
106
+ this.toggleCollapsed(node.id);
107
+ return true;
108
+ }
109
+
98
110
  /** Toggle collapse state for a synthetic node id. Triggers a topology re-emit. */
99
111
  toggleCollapsed(id: string): void {
100
112
  if (this.#collapsed.has(id)) {
@@ -153,6 +153,7 @@ export type GraphForceProjectorOptions = GraphProjectorOptions & {
153
153
  /**
154
154
  * D3 force directed graph layout using d3 simulation..
155
155
  */
156
+ // TODO(burdon): Rename ForceGraphProjector.
156
157
  export class GraphForceProjector<NodeData = any> extends GraphProjector<NodeData, GraphForceProjectorOptions> {
157
158
  // https://github.com/d3/d3-force
158
159
  private _simulation = forceSimulation<GraphLayoutNode, GraphLayoutEdge>();
@@ -0,0 +1,102 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { describe, test } from 'vitest';
6
+
7
+ import { type Graph } from '@dxos/graph';
8
+
9
+ import { SVGContext } from '../../hooks';
10
+ import { type GraphLayoutEdge } from '../types';
11
+ import {
12
+ GraphPlexusProjector,
13
+ PLEXUS_NODE_TYPE_FOCUS,
14
+ PLEXUS_NODE_TYPE_OBJECT,
15
+ PLEXUS_NODE_TYPE_RELATION,
16
+ type PlexusRelation,
17
+ } from './graph-plexus-projector';
18
+
19
+ const makeContext = () => {
20
+ const context = new SVGContext({});
21
+ context.setSize({ width: 800, height: 600 });
22
+ return context;
23
+ };
24
+
25
+ // Mirrors plugin-explorer's relationOf: each relation/ref gets separate nodes for the outgoing
26
+ // (focus is source, `→`) and incoming (focus is target, `←`) directions.
27
+ const relationOf = (edge: GraphLayoutEdge, focusId: string): PlexusRelation | undefined => {
28
+ const outgoing = edge.source.id === focusId;
29
+ const incoming = edge.target.id === focusId;
30
+ if (!outgoing && !incoming) {
31
+ return undefined;
32
+ }
33
+ const direction = outgoing ? 'out' : 'in';
34
+ const arrow = outgoing ? '→' : '←';
35
+ if (edge.type === 'relation') {
36
+ return { key: `relation:${direction}:HasRelationship`, label: `HasRelationship ${arrow}` };
37
+ }
38
+ if (edge.type === 'ref') {
39
+ const property = (edge.data as any)?.property ?? 'references';
40
+ return { key: `ref:${direction}:${property}`, label: `${property} ${arrow}` };
41
+ }
42
+ return undefined;
43
+ };
44
+
45
+ const graph: Graph.Any = {
46
+ nodes: [{ id: 'p1' }, { id: 'org' }, { id: 'p2' }, { id: 'p3' }, { id: 'p4' }, { id: 'other' }] as any,
47
+ edges: [
48
+ // Outgoing ref from focus → grouped under "organization →".
49
+ { id: 'e1', type: 'ref', source: 'p1', target: 'org', data: { property: 'organization' } },
50
+ // Outgoing relations from focus → grouped under "HasRelationship →".
51
+ { id: 'e2', type: 'relation', source: 'p1', target: 'p2', data: {} },
52
+ { id: 'e3', type: 'relation', source: 'p1', target: 'p3', data: {} },
53
+ // Incoming relation to focus → separate "HasRelationship ←" node.
54
+ { id: 'e4', type: 'relation', source: 'p4', target: 'p1', data: {} },
55
+ // Edge NOT incident to focus → ignored.
56
+ { id: 'e5', type: 'ref', source: 'other', target: 'org', data: { property: 'organization' } },
57
+ ] as any,
58
+ };
59
+
60
+ describe('GraphPlexusProjector', () => {
61
+ test('fans the focus neighbourhood out by relation and direction', ({ expect }) => {
62
+ const projector = new GraphPlexusProjector(makeContext(), { focus: 'p1', relationOf });
63
+ projector.updateData(graph);
64
+
65
+ const nodes = projector.layout.graph.nodes;
66
+ const byType = (type: string) => nodes.filter((node) => node.type === type);
67
+
68
+ // Exactly one focus node.
69
+ const focus = byType(PLEXUS_NODE_TYPE_FOCUS);
70
+ expect(focus).toHaveLength(1);
71
+ expect(focus[0].id).toBe('p1');
72
+ expect(focus[0].x).toBe(0);
73
+ expect(focus[0].y).toBe(0);
74
+
75
+ // Three relation nodes: outgoing relation, incoming relation, outgoing ref.
76
+ const relations = byType(PLEXUS_NODE_TYPE_RELATION);
77
+ expect(relations.map((node) => node.label).sort()).toEqual([
78
+ 'HasRelationship ←',
79
+ 'HasRelationship →',
80
+ 'organization →',
81
+ ]);
82
+
83
+ // Four object leaves (org, p2, p3 outgoing; p4 incoming); the non-incident edge is excluded.
84
+ const objects = byType(PLEXUS_NODE_TYPE_OBJECT);
85
+ expect(objects.map((node) => node.id).sort()).toEqual(['org', 'p2', 'p3', 'p4']);
86
+ expect(nodes.find((node) => node.id === 'other')).toBeUndefined();
87
+
88
+ // Hierarchy edges: focus→relation (3) + relation→object (4) = 7.
89
+ const edges = projector.layout.graph.edges;
90
+ expect(edges).toHaveLength(7);
91
+ expect(edges.every((edge) => edge.type === 'hierarchy')).toBe(true);
92
+ });
93
+
94
+ test('degrades to a ring when the focus is absent', ({ expect }) => {
95
+ const projector = new GraphPlexusProjector(makeContext(), { focus: 'missing', relationOf });
96
+ projector.updateData(graph);
97
+
98
+ // All nodes laid out, no relation structure.
99
+ expect(projector.layout.graph.nodes).toHaveLength(graph.nodes.length);
100
+ expect(projector.layout.graph.edges).toHaveLength(0);
101
+ });
102
+ });