@atolis-hq/corum 0.1.41 → 0.1.43
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/package.json +1 -1
- package/web/app.jsx +6 -2
- package/web/graph-utils.js +67 -2
- package/web/graph-utils.test.js +38 -0
- package/web/graph.jsx +498 -59
- package/web/index.html +1 -1
- package/web/style.css +121 -0
package/package.json
CHANGED
package/web/app.jsx
CHANGED
|
@@ -15,13 +15,17 @@ const { buildNavTree, buildOverlayIndicatorIds } = window.CorumNav;
|
|
|
15
15
|
const { parseRoute, buildRoute } = window.CorumRouter;
|
|
16
16
|
const { SearchModal } = window.CorumSearch;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
// uses-type is excluded here: it's the auto-generated type-reference edge
|
|
19
|
+
// (schema/field-level), surfaced via SchemaCard node-ref links and the
|
|
20
|
+
// includedSchemaNodes panel instead of the root-to-root Connections list.
|
|
21
|
+
const PANEL_EDGE_TYPES = new Set(['triggers', 'produces', 'calls', 'implements', 'reads']);
|
|
19
22
|
|
|
20
23
|
const EDGE_TYPE_STYLES = {
|
|
21
24
|
triggers: { background: '#fef3c7', color: '#b45309' },
|
|
22
25
|
produces: { background: '#ccfbf1', color: '#0f766e' },
|
|
23
26
|
calls: { background: '#ede9fe', color: '#6d28d9' },
|
|
24
27
|
implements: { background: '#f1f5f9', color: '#475569' },
|
|
28
|
+
reads: { background: '#dbeafe', color: '#1d4ed8' },
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
function classifyEdges(edges, clusterIds) {
|
|
@@ -808,7 +812,7 @@ function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, ove
|
|
|
808
812
|
const overlayParam = overlayRefs && overlayRefs.length > 0
|
|
809
813
|
? '&' + overlayRefs.map(ref => `overlayRefs=${encodeURIComponent(ref)}`).join('&')
|
|
810
814
|
: '';
|
|
811
|
-
fetch(`/api/cluster?nodeId=${encodeURIComponent(nodeId)}&includeEdges=maps-to,reads,triggers,produces,calls,implements${refParam}${overlayParam}`)
|
|
815
|
+
fetch(`/api/cluster?nodeId=${encodeURIComponent(nodeId)}&includeEdges=maps-to,reads,uses-type,triggers,produces,calls,implements${refParam}${overlayParam}`)
|
|
812
816
|
.then(response => response.ok ? response.json() : Promise.reject(response.status))
|
|
813
817
|
.then(setCluster)
|
|
814
818
|
.catch(err => setError(String(err)));
|
package/web/graph-utils.js
CHANGED
|
@@ -42,9 +42,74 @@ function applyEdgeTypeFilter(edges, visibleTypes) {
|
|
|
42
42
|
return edges.filter(e => visibleTypes.has(e.type));
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// Weakly connected components. Edges use {from, to}; extraLinks are additional
|
|
46
|
+
// affinity pairs (e.g. group co-membership) that merge components without
|
|
47
|
+
// being real edges. Returns arrays of node ids.
|
|
48
|
+
function computeConnectedComponents(nodes, edges, extraLinks = []) {
|
|
49
|
+
const adjacency = new Map(nodes.map(n => [n.id, []]));
|
|
50
|
+
for (const link of [...edges, ...extraLinks]) {
|
|
51
|
+
if (!adjacency.has(link.from) || !adjacency.has(link.to)) continue;
|
|
52
|
+
adjacency.get(link.from).push(link.to);
|
|
53
|
+
adjacency.get(link.to).push(link.from);
|
|
54
|
+
}
|
|
55
|
+
const visited = new Set();
|
|
56
|
+
const components = [];
|
|
57
|
+
for (const node of nodes) {
|
|
58
|
+
if (visited.has(node.id)) continue;
|
|
59
|
+
const component = [];
|
|
60
|
+
const queue = [node.id];
|
|
61
|
+
visited.add(node.id);
|
|
62
|
+
while (queue.length) {
|
|
63
|
+
const id = queue.pop();
|
|
64
|
+
component.push(id);
|
|
65
|
+
for (const next of adjacency.get(id)) {
|
|
66
|
+
if (visited.has(next)) continue;
|
|
67
|
+
visited.add(next);
|
|
68
|
+
queue.push(next);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
components.push(component);
|
|
72
|
+
}
|
|
73
|
+
return components;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Scope threads (connected components) to those containing an interaction:
|
|
77
|
+
// an edge of scope.edgeType whose endpoints match the optional
|
|
78
|
+
// fromTemplate/toTemplate. Returns the node ids of matching threads.
|
|
79
|
+
function filterThreadScope(nodes, edges, scope) {
|
|
80
|
+
const components = computeConnectedComponents(nodes, edges);
|
|
81
|
+
const templateById = new Map(nodes.map(n => [n.id, n.template]));
|
|
82
|
+
const matchingEdges = edges.filter(e =>
|
|
83
|
+
e.type === scope.edgeType &&
|
|
84
|
+
(!scope.fromTemplate || templateById.get(e.from) === scope.fromTemplate) &&
|
|
85
|
+
(!scope.toTemplate || templateById.get(e.to) === scope.toTemplate)
|
|
86
|
+
);
|
|
87
|
+
const matchEndpoints = new Set(matchingEdges.flatMap(e => [e.from, e.to]));
|
|
88
|
+
const nodeIds = new Set();
|
|
89
|
+
let matchCount = 0;
|
|
90
|
+
for (const component of components) {
|
|
91
|
+
if (!component.some(id => matchEndpoints.has(id))) continue;
|
|
92
|
+
matchCount += 1;
|
|
93
|
+
for (const id of component) nodeIds.add(id);
|
|
94
|
+
}
|
|
95
|
+
return { nodeIds, threadCount: components.length, matchCount };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Scope to one owner: the owner node itself, nodes owned by it, plus their
|
|
99
|
+
// direct neighbours via the given edges.
|
|
100
|
+
function filterOwnerScope(nodes, edges, parentId) {
|
|
101
|
+
const memberIds = new Set(nodes.filter(n => n.id === parentId || n.parentId === parentId).map(n => n.id));
|
|
102
|
+
const nodeIds = new Set(memberIds);
|
|
103
|
+
for (const e of edges) {
|
|
104
|
+
if (memberIds.has(e.from)) nodeIds.add(e.to);
|
|
105
|
+
if (memberIds.has(e.to)) nodeIds.add(e.from);
|
|
106
|
+
}
|
|
107
|
+
return nodeIds;
|
|
108
|
+
}
|
|
109
|
+
|
|
45
110
|
if (typeof module !== 'undefined' && module.exports) {
|
|
46
|
-
module.exports = { buildComponentMap, applyEdgeTypeFilter, getDisplayName };
|
|
111
|
+
module.exports = { buildComponentMap, applyEdgeTypeFilter, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope };
|
|
47
112
|
}
|
|
48
113
|
if (typeof window !== 'undefined') {
|
|
49
|
-
window.CorumGraphUtils = { buildComponentMap, applyEdgeTypeFilter, getDisplayName };
|
|
114
|
+
window.CorumGraphUtils = { buildComponentMap, applyEdgeTypeFilter, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope };
|
|
50
115
|
}
|
package/web/graph-utils.test.js
CHANGED
|
@@ -43,6 +43,44 @@ const { buildComponentMap, applyEdgeTypeFilter, getDisplayName } = graphUtils;
|
|
|
43
43
|
const none = applyEdgeTypeFilter(edges, new Set([]));
|
|
44
44
|
assert(none.length === 0, 'applyEdgeTypeFilter: empty set returns nothing');
|
|
45
45
|
|
|
46
|
+
const { computeConnectedComponents, filterThreadScope, filterOwnerScope } = graphUtils;
|
|
47
|
+
|
|
48
|
+
const ccAll = computeConnectedComponents(nodes, edges);
|
|
49
|
+
assert(ccAll.length === 1, 'computeConnectedComponents: fully linked graph is one component');
|
|
50
|
+
const ccSplit = computeConnectedComponents(nodes, [edges[0], edges[2]]);
|
|
51
|
+
assert(ccSplit.length === 2, 'computeConnectedComponents: removing bridge edge splits components');
|
|
52
|
+
const ccIsolated = computeConnectedComponents([...nodes, { id: 'lone.Node.x', template: 'X', component: 'lone' }], edges);
|
|
53
|
+
assert(ccIsolated.some(c => c.length === 1 && c[0] === 'lone.Node.x'), 'computeConnectedComponents: isolated node is own component');
|
|
54
|
+
const ccMerged = computeConnectedComponents(nodes, [edges[0], edges[2]], [{ from: 'orders.DomainModel.order', to: 'payments.DomainModel.payment' }]);
|
|
55
|
+
assert(ccMerged.length === 1, 'computeConnectedComponents: extraLinks merge components');
|
|
56
|
+
|
|
57
|
+
const splitEdges = [edges[0], edges[2]];
|
|
58
|
+
const scoped = filterThreadScope(nodes, splitEdges, { edgeType: 'reads', fromTemplate: 'RestAPI', toTemplate: null });
|
|
59
|
+
assert(scoped.threadCount === 2 && scoped.matchCount === 2, 'filterThreadScope: both threads have RestAPI reads');
|
|
60
|
+
const scopedNone = filterThreadScope(nodes, splitEdges, { edgeType: 'calls', fromTemplate: null, toTemplate: null });
|
|
61
|
+
assert(scopedNone.matchCount === 0 && scopedNone.nodeIds.size === 0, 'filterThreadScope: no matching threads yields empty set');
|
|
62
|
+
const scopedTo = filterThreadScope(nodes, splitEdges, { edgeType: 'reads', fromTemplate: null, toTemplate: 'DomainModel' });
|
|
63
|
+
assert(scopedTo.nodeIds.has('orders.RestAPI.ordersApi'), 'filterThreadScope: matching thread includes all its nodes');
|
|
64
|
+
|
|
65
|
+
const aggNodes = [
|
|
66
|
+
{ id: 'a.T.agg', template: 'T', parentId: null },
|
|
67
|
+
{ id: 'a.T.agg.ops.one', template: 'Op', parentId: 'a.T.agg' },
|
|
68
|
+
{ id: 'a.T.agg.ops.two', template: 'Op', parentId: 'a.T.agg' },
|
|
69
|
+
{ id: 'a.T.other', template: 'T', parentId: null },
|
|
70
|
+
{ id: 'a.T.unrelated', template: 'T', parentId: null },
|
|
71
|
+
];
|
|
72
|
+
const aggEdges = [
|
|
73
|
+
{ id: 'ae1', from: 'a.T.agg.ops.one', to: 'a.T.other', type: 'reads' },
|
|
74
|
+
{ id: 'ae2', from: 'a.T.unrelated', to: 'a.T.other', type: 'reads' },
|
|
75
|
+
{ id: 'ae3', from: 'a.T.reader', to: 'a.T.agg', type: 'reads' },
|
|
76
|
+
];
|
|
77
|
+
const aggScope = filterOwnerScope([...aggNodes, { id: 'a.T.reader', template: 'T', parentId: null }], aggEdges, 'a.T.agg');
|
|
78
|
+
assert(aggScope.has('a.T.agg.ops.one') && aggScope.has('a.T.agg.ops.two'), 'filterOwnerScope: keeps members');
|
|
79
|
+
assert(aggScope.has('a.T.agg'), 'filterOwnerScope: keeps the owner node itself');
|
|
80
|
+
assert(aggScope.has('a.T.other'), 'filterOwnerScope: keeps direct neighbours');
|
|
81
|
+
assert(aggScope.has('a.T.reader'), 'filterOwnerScope: keeps neighbours of the owner node');
|
|
82
|
+
assert(!aggScope.has('a.T.unrelated'), 'filterOwnerScope: drops unrelated nodes');
|
|
83
|
+
|
|
46
84
|
console.log(`\n${passed} passed, ${failed} failed`);
|
|
47
85
|
if (failed > 0) process.exit(1);
|
|
48
86
|
})();
|
package/web/graph.jsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/* Graph view: interactive three-level canvas using React Flow +
|
|
1
|
+
/* Graph view: interactive three-level canvas using React Flow + ELK.js. */
|
|
2
2
|
|
|
3
3
|
const { useState, useEffect, useMemo, useCallback, useRef } = React;
|
|
4
4
|
const { navigate, Icon, TemplateBadge, StateTag, StabilityTag } = window.CorumPrimitives;
|
|
5
5
|
const { buildRoute, parseRoute } = window.CorumRouter;
|
|
6
|
-
const { buildComponentMap, applyEdgeTypeFilter, getDisplayName } = window.CorumGraphUtils;
|
|
6
|
+
const { buildComponentMap, applyEdgeTypeFilter, getDisplayName, computeConnectedComponents, filterThreadScope, filterOwnerScope } = window.CorumGraphUtils;
|
|
7
7
|
|
|
8
8
|
const RF = window.ReactFlow;
|
|
9
9
|
const ReactFlowCanvas = RF.ReactFlow || RF.default;
|
|
@@ -15,6 +15,7 @@ const EDGE_STYLES = {
|
|
|
15
15
|
'calls': { stroke: '#6d28d9', strokeWidth: 1.5 },
|
|
16
16
|
'implements': { stroke: '#475569', strokeWidth: 1.5 },
|
|
17
17
|
'reads': { stroke: '#1d4ed8', strokeWidth: 1.5 },
|
|
18
|
+
'uses-type': { stroke: '#0891b2', strokeWidth: 1.5 },
|
|
18
19
|
'maps-to': { stroke: '#be185d', strokeWidth: 1.5 },
|
|
19
20
|
'derived-from': { stroke: '#6b7280', strokeWidth: 1.5, strokeDasharray: '5,5' },
|
|
20
21
|
};
|
|
@@ -25,11 +26,12 @@ const EDGE_PILL_STYLES = {
|
|
|
25
26
|
'calls': { background: '#ede9fe', color: '#6d28d9' },
|
|
26
27
|
'implements': { background: '#f1f5f9', color: '#475569' },
|
|
27
28
|
'reads': { background: '#dbeafe', color: '#1d4ed8' },
|
|
29
|
+
'uses-type': { background: '#cffafe', color: '#0891b2' },
|
|
28
30
|
'maps-to': { background: '#fce7f3', color: '#be185d' },
|
|
29
31
|
'derived-from': { background: '#f3f4f6', color: '#6b7280' },
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
const ALL_EDGE_TYPES = ['triggers', 'produces', 'reads', 'calls', 'implements', 'maps-to', 'derived-from'];
|
|
34
|
+
const ALL_EDGE_TYPES = ['triggers', 'produces', 'reads', 'uses-type', 'calls', 'implements', 'maps-to', 'derived-from'];
|
|
33
35
|
const DEPTH_STEPS = [1, 2, 3, 4, 5, Infinity];
|
|
34
36
|
|
|
35
37
|
const NODE_W = 210;
|
|
@@ -49,20 +51,263 @@ function saveVisibleEdgeTypes(types) {
|
|
|
49
51
|
try { localStorage.setItem('corum:graphEdgeTypes', JSON.stringify([...types])); } catch {}
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
function
|
|
54
|
+
function loadLayoutMode() {
|
|
55
|
+
try {
|
|
56
|
+
const stored = localStorage.getItem('corum:graphLayoutMode');
|
|
57
|
+
if (stored === 'flat' || stored === 'grouped') return stored;
|
|
58
|
+
} catch {}
|
|
59
|
+
return 'flat';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function saveLayoutMode(mode) {
|
|
63
|
+
try { localStorage.setItem('corum:graphLayoutMode', mode); } catch {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const elk = new ELK();
|
|
67
|
+
|
|
68
|
+
const ELK_BASE_OPTIONS = {
|
|
69
|
+
'elk.algorithm': 'layered',
|
|
70
|
+
'elk.direction': 'RIGHT',
|
|
71
|
+
'elk.layered.spacing.nodeNodeBetweenLayers': '90',
|
|
72
|
+
'elk.spacing.nodeNode': '40',
|
|
73
|
+
'elk.layered.nodePlacement.strategy': 'NETWORK_SIMPLEX',
|
|
74
|
+
'elk.layered.crossingMinimization.strategy': 'LAYER_SWEEP',
|
|
75
|
+
// Disconnected sub-graphs are separated and stacked by computeLayout, not ELK.
|
|
76
|
+
'elk.separateConnectedComponents': 'false',
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const STACK_GAP = 100;
|
|
80
|
+
const FRAGMENT_GAP = 40;
|
|
81
|
+
|
|
82
|
+
// Flat ELK layout: every node is a direct child of the root.
|
|
83
|
+
async function computeFlatLayout(rfNodes, rfEdges, nodeW, nodeH) {
|
|
53
84
|
if (!rfNodes.length) return rfNodes;
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
85
|
+
const nodeIds = new Set(rfNodes.map(n => n.id));
|
|
86
|
+
const elkGraph = {
|
|
87
|
+
id: 'root',
|
|
88
|
+
layoutOptions: ELK_BASE_OPTIONS,
|
|
89
|
+
children: rfNodes.map(n => ({ id: n.id, width: nodeW, height: nodeH })),
|
|
90
|
+
edges: rfEdges
|
|
91
|
+
.filter(e => nodeIds.has(e.source) && nodeIds.has(e.target))
|
|
92
|
+
.map(e => ({ id: e.id, sources: [e.source], targets: [e.target] })),
|
|
93
|
+
};
|
|
94
|
+
const result = await elk.layout(elkGraph);
|
|
95
|
+
const posById = new Map(result.children.map(c => [c.id, c]));
|
|
60
96
|
return rfNodes.map(n => {
|
|
61
|
-
const pos =
|
|
62
|
-
return { ...n, position: { x: pos.x
|
|
97
|
+
const pos = posById.get(n.id);
|
|
98
|
+
return pos ? { ...n, position: { x: pos.x, y: pos.y } } : n;
|
|
63
99
|
});
|
|
64
100
|
}
|
|
65
101
|
|
|
102
|
+
// Grouped ELK layout: nodes sharing a parentId (2+ visible siblings) are
|
|
103
|
+
// clustered into a compound "group:<parentId>" container node.
|
|
104
|
+
async function computeGroupedLayout(rfNodes, rfEdges, nodeW, nodeH) {
|
|
105
|
+
if (!rfNodes.length) return rfNodes;
|
|
106
|
+
|
|
107
|
+
const parentCounts = new Map();
|
|
108
|
+
for (const n of rfNodes) {
|
|
109
|
+
const pid = n.data?.parentId;
|
|
110
|
+
if (!pid) continue;
|
|
111
|
+
parentCounts.set(pid, (parentCounts.get(pid) ?? 0) + 1);
|
|
112
|
+
}
|
|
113
|
+
const groupParentIds = new Set([...parentCounts.entries()].filter(([, c]) => c >= 2).map(([pid]) => pid));
|
|
114
|
+
|
|
115
|
+
if (!groupParentIds.size) return computeFlatLayout(rfNodes, rfEdges, nodeW, nodeH);
|
|
116
|
+
|
|
117
|
+
const nodeIds = new Set(rfNodes.map(n => n.id));
|
|
118
|
+
const groupChildrenMap = new Map([...groupParentIds].map(pid => [pid, []]));
|
|
119
|
+
const rootChildren = [];
|
|
120
|
+
|
|
121
|
+
for (const n of rfNodes) {
|
|
122
|
+
const pid = n.data?.parentId;
|
|
123
|
+
if (pid && groupParentIds.has(pid)) {
|
|
124
|
+
groupChildrenMap.get(pid).push({ id: n.id, width: nodeW, height: nodeH });
|
|
125
|
+
} else {
|
|
126
|
+
rootChildren.push({ id: n.id, width: nodeW, height: nodeH });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (const pid of groupParentIds) {
|
|
131
|
+
rootChildren.push({
|
|
132
|
+
id: 'group:' + pid,
|
|
133
|
+
layoutOptions: { 'elk.padding': '[top=36,left=16,bottom=16,right=16]' },
|
|
134
|
+
children: groupChildrenMap.get(pid),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const elkGraph = {
|
|
139
|
+
id: 'root',
|
|
140
|
+
layoutOptions: { ...ELK_BASE_OPTIONS, 'elk.hierarchyHandling': 'INCLUDE_CHILDREN' },
|
|
141
|
+
children: rootChildren,
|
|
142
|
+
edges: rfEdges
|
|
143
|
+
.filter(e => nodeIds.has(e.source) && nodeIds.has(e.target))
|
|
144
|
+
.map(e => ({ id: e.id, sources: [e.source], targets: [e.target] })),
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const result = await elk.layout(elkGraph);
|
|
148
|
+
|
|
149
|
+
const groupNodeIds = new Set([...groupParentIds].map(pid => 'group:' + pid));
|
|
150
|
+
const groupBoxes = new Map();
|
|
151
|
+
const nodePositions = new Map();
|
|
152
|
+
|
|
153
|
+
for (const child of result.children) {
|
|
154
|
+
if (groupNodeIds.has(child.id)) {
|
|
155
|
+
groupBoxes.set(child.id, { x: child.x, y: child.y, width: child.width, height: child.height });
|
|
156
|
+
for (const gc of child.children ?? []) {
|
|
157
|
+
nodePositions.set(gc.id, { x: gc.x, y: gc.y });
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
nodePositions.set(child.id, { x: child.x, y: child.y });
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const groupNodes = [...groupBoxes.entries()].map(([gid, box]) => ({
|
|
165
|
+
id: gid,
|
|
166
|
+
type: 'groupCard',
|
|
167
|
+
position: { x: box.x, y: box.y },
|
|
168
|
+
style: { width: box.width, height: box.height },
|
|
169
|
+
data: { label: getDisplayName(gid.slice('group:'.length)) },
|
|
170
|
+
}));
|
|
171
|
+
|
|
172
|
+
const memberNodes = rfNodes.map(n => {
|
|
173
|
+
const pos = nodePositions.get(n.id) ?? { x: 0, y: 0 };
|
|
174
|
+
const pid = n.data?.parentId;
|
|
175
|
+
if (pid && groupParentIds.has(pid)) {
|
|
176
|
+
// The group box already shows the owner; drop the per-card owner chip.
|
|
177
|
+
// No extent constraint: members drag freely and the box refits around them.
|
|
178
|
+
return { ...n, position: pos, parentNode: 'group:' + pid, data: { ...n.data, parentLabel: null } };
|
|
179
|
+
}
|
|
180
|
+
return { ...n, position: pos };
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// Parent/group nodes must precede their children in the React Flow nodes array.
|
|
184
|
+
return [...groupNodes, ...memberNodes];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const GROUP_PAD = { top: 36, right: 16, bottom: 16, left: 16 };
|
|
188
|
+
|
|
189
|
+
// Fit each group box around its children. With shiftOrigin the box origin
|
|
190
|
+
// moves and children are re-based (full normalise, safe after a drag ends);
|
|
191
|
+
// without it the box only grows right/down, which avoids fighting React
|
|
192
|
+
// Flow's pointer tracking mid-drag.
|
|
193
|
+
function fitGroupsToChildren(nodes, shiftOrigin) {
|
|
194
|
+
const fits = new Map();
|
|
195
|
+
for (const g of nodes) {
|
|
196
|
+
if (g.type !== 'groupCard') continue;
|
|
197
|
+
const children = nodes.filter(n => n.parentNode === g.id);
|
|
198
|
+
if (!children.length) continue;
|
|
199
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
200
|
+
for (const c of children) {
|
|
201
|
+
minX = Math.min(minX, c.position.x);
|
|
202
|
+
minY = Math.min(minY, c.position.y);
|
|
203
|
+
maxX = Math.max(maxX, c.position.x + (c.width ?? NODE_W));
|
|
204
|
+
maxY = Math.max(maxY, c.position.y + (c.height ?? NODE_H));
|
|
205
|
+
}
|
|
206
|
+
fits.set(g.id, shiftOrigin
|
|
207
|
+
? {
|
|
208
|
+
dx: minX - GROUP_PAD.left,
|
|
209
|
+
dy: minY - GROUP_PAD.top,
|
|
210
|
+
width: (maxX - minX) + GROUP_PAD.left + GROUP_PAD.right,
|
|
211
|
+
height: (maxY - minY) + GROUP_PAD.top + GROUP_PAD.bottom,
|
|
212
|
+
}
|
|
213
|
+
: {
|
|
214
|
+
dx: 0,
|
|
215
|
+
dy: 0,
|
|
216
|
+
width: Math.max(g.style?.width ?? 0, maxX + GROUP_PAD.right),
|
|
217
|
+
height: Math.max(g.style?.height ?? 0, maxY + GROUP_PAD.bottom),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
if (!fits.size) return nodes;
|
|
221
|
+
return nodes.map(n => {
|
|
222
|
+
if (n.type === 'groupCard' && fits.has(n.id)) {
|
|
223
|
+
const f = fits.get(n.id);
|
|
224
|
+
return { ...n, position: { x: n.position.x + f.dx, y: n.position.y + f.dy }, style: { ...n.style, width: f.width, height: f.height } };
|
|
225
|
+
}
|
|
226
|
+
if (n.parentNode && fits.has(n.parentNode)) {
|
|
227
|
+
const f = fits.get(n.parentNode);
|
|
228
|
+
if (!f.dx && !f.dy) return n;
|
|
229
|
+
return { ...n, position: { x: n.position.x - f.dx, y: n.position.y - f.dy } };
|
|
230
|
+
}
|
|
231
|
+
return n;
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Lay out each connected component independently, then stack them as
|
|
236
|
+
// left-aligned rows so every flow reads left-to-right from a common edge.
|
|
237
|
+
// Small fragments (pairs/singletons) are packed into a compact grid below.
|
|
238
|
+
async function computeLayout(rfNodes, rfEdges, nodeW, nodeH, mode) {
|
|
239
|
+
if (!rfNodes.length) return rfNodes;
|
|
240
|
+
|
|
241
|
+
// In grouped mode, group co-membership must not split across components.
|
|
242
|
+
const extraLinks = [];
|
|
243
|
+
if (mode === 'grouped') {
|
|
244
|
+
const byParent = new Map();
|
|
245
|
+
for (const n of rfNodes) {
|
|
246
|
+
const pid = n.data?.parentId;
|
|
247
|
+
if (!pid) continue;
|
|
248
|
+
if (!byParent.has(pid)) byParent.set(pid, []);
|
|
249
|
+
byParent.get(pid).push(n.id);
|
|
250
|
+
}
|
|
251
|
+
for (const ids of byParent.values()) {
|
|
252
|
+
for (let i = 1; i < ids.length; i++) extraLinks.push({ from: ids[0], to: ids[i] });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const links = rfEdges.map(e => ({ from: e.source, to: e.target }));
|
|
257
|
+
const components = computeConnectedComponents(rfNodes, links, extraLinks)
|
|
258
|
+
.sort((a, b) => b.length - a.length);
|
|
259
|
+
const flows = components.filter(c => c.length >= 3);
|
|
260
|
+
const fragments = components.filter(c => c.length < 3);
|
|
261
|
+
const nodeById = new Map(rfNodes.map(n => [n.id, n]));
|
|
262
|
+
|
|
263
|
+
const layouts = await Promise.all(flows.map(ids => {
|
|
264
|
+
const idSet = new Set(ids);
|
|
265
|
+
const subNodes = ids.map(id => nodeById.get(id));
|
|
266
|
+
const subEdges = rfEdges.filter(e => idSet.has(e.source) && idSet.has(e.target));
|
|
267
|
+
return mode === 'grouped'
|
|
268
|
+
? computeGroupedLayout(subNodes, subEdges, nodeW, nodeH)
|
|
269
|
+
: computeFlatLayout(subNodes, subEdges, nodeW, nodeH);
|
|
270
|
+
}));
|
|
271
|
+
|
|
272
|
+
const out = [];
|
|
273
|
+
let offsetY = 0;
|
|
274
|
+
let maxWidth = 0;
|
|
275
|
+
for (const layoutNodes of layouts) {
|
|
276
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
277
|
+
for (const n of layoutNodes) {
|
|
278
|
+
if (n.parentNode) continue; // group members are positioned relative to their group
|
|
279
|
+
const w = n.style?.width ?? nodeW;
|
|
280
|
+
const h = n.style?.height ?? nodeH;
|
|
281
|
+
minX = Math.min(minX, n.position.x);
|
|
282
|
+
minY = Math.min(minY, n.position.y);
|
|
283
|
+
maxX = Math.max(maxX, n.position.x + w);
|
|
284
|
+
maxY = Math.max(maxY, n.position.y + h);
|
|
285
|
+
}
|
|
286
|
+
for (const n of layoutNodes) {
|
|
287
|
+
out.push(n.parentNode ? n : { ...n, position: { x: n.position.x - minX, y: n.position.y - minY + offsetY } });
|
|
288
|
+
}
|
|
289
|
+
offsetY += (maxY - minY) + STACK_GAP;
|
|
290
|
+
maxWidth = Math.max(maxWidth, maxX - minX);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const wrapWidth = Math.max(maxWidth, 1600);
|
|
294
|
+
let gx = 0, gy = offsetY;
|
|
295
|
+
for (const ids of fragments) {
|
|
296
|
+
const idSet = new Set(ids);
|
|
297
|
+
const subEdges = rfEdges.filter(e => idSet.has(e.source) && idSet.has(e.target));
|
|
298
|
+
// Order pairs source-first so the arrow reads left-to-right.
|
|
299
|
+
const ordered = ids.length === 2 && subEdges.length ? [subEdges[0].source, subEdges[0].target] : ids;
|
|
300
|
+
const fragW = ordered.length * nodeW + (ordered.length - 1) * FRAGMENT_GAP;
|
|
301
|
+
if (gx > 0 && gx + fragW > wrapWidth) { gx = 0; gy += nodeH + FRAGMENT_GAP; }
|
|
302
|
+
ordered.forEach((id, i) => {
|
|
303
|
+
out.push({ ...nodeById.get(id), position: { x: gx + i * (nodeW + FRAGMENT_GAP), y: gy } });
|
|
304
|
+
});
|
|
305
|
+
gx += fragW + FRAGMENT_GAP * 2;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
|
|
66
311
|
function makeRFEdge(edge, edgeStyles) {
|
|
67
312
|
const style = edgeStyles[edge.type] || { stroke: '#a8acb5', strokeWidth: 1.5 };
|
|
68
313
|
return {
|
|
@@ -78,7 +323,7 @@ function makeRFEdge(edge, edgeStyles) {
|
|
|
78
323
|
};
|
|
79
324
|
}
|
|
80
325
|
|
|
81
|
-
function buildRFNodesForNodes(graphNodes, templateMap, onNodeClick, viewingRef) {
|
|
326
|
+
function buildRFNodesForNodes(graphNodes, templateMap, onNodeClick, viewingRef, fadedIds) {
|
|
82
327
|
return graphNodes.map(n => {
|
|
83
328
|
const tmpl = templateMap.get(n.template);
|
|
84
329
|
const colour = tmpl?.ui?.colour ?? 'var(--ink-4)';
|
|
@@ -98,6 +343,8 @@ function buildRFNodesForNodes(graphNodes, templateMap, onNodeClick, viewingRef)
|
|
|
98
343
|
onClick: () => onNodeClick(n.id),
|
|
99
344
|
viewingRef,
|
|
100
345
|
parentLabel,
|
|
346
|
+
parentId: n.parentId ?? null,
|
|
347
|
+
faded: fadedIds?.has(n.id) ?? false,
|
|
101
348
|
},
|
|
102
349
|
};
|
|
103
350
|
});
|
|
@@ -123,7 +370,7 @@ function ComponentCardNode({ data }) {
|
|
|
123
370
|
function NodeCardNode({ data }) {
|
|
124
371
|
const colour = data.colour ?? 'var(--ink-4)';
|
|
125
372
|
return (
|
|
126
|
-
<div className=
|
|
373
|
+
<div className={`graph-node-card${data.faded ? ' faded' : ''}${data.focal ? ' focal' : ''}`} onClick={data.onClick}>
|
|
127
374
|
{data.parentLabel && (
|
|
128
375
|
<div className="graph-node-card-owner">{data.parentLabel}</div>
|
|
129
376
|
)}
|
|
@@ -154,7 +401,16 @@ function NodeCardNode({ data }) {
|
|
|
154
401
|
);
|
|
155
402
|
}
|
|
156
403
|
|
|
157
|
-
|
|
404
|
+
// Grouped-mode compound container: label only, member nodes render as children.
|
|
405
|
+
function GroupCardNode({ data }) {
|
|
406
|
+
return (
|
|
407
|
+
<div className="graph-group-card">
|
|
408
|
+
<div className="graph-group-card-label">{data.label}</div>
|
|
409
|
+
</div>
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const nodeTypes = { componentCard: ComponentCardNode, nodeCard: NodeCardNode, groupCard: GroupCardNode };
|
|
158
414
|
|
|
159
415
|
function GraphBreadcrumb({ level, selectedComponent, focalNodeId, onNavigateToRoot, onNavigateToComponent }) {
|
|
160
416
|
return (
|
|
@@ -179,10 +435,91 @@ function GraphBreadcrumb({ level, selectedComponent, focalNodeId, onNavigateToRo
|
|
|
179
435
|
);
|
|
180
436
|
}
|
|
181
437
|
|
|
182
|
-
function
|
|
438
|
+
function ScopePopover({ scope, onScope, scopeOptions, onClose }) {
|
|
439
|
+
const [edgeType, setEdgeType] = useState(scope?.edgeType ?? '');
|
|
440
|
+
const [fromTemplate, setFromTemplate] = useState(scope?.fromTemplate ?? '');
|
|
441
|
+
const [toTemplate, setToTemplate] = useState(scope?.toTemplate ?? '');
|
|
442
|
+
const [owner, setOwner] = useState(scope?.owner ?? '');
|
|
443
|
+
|
|
444
|
+
function apply() {
|
|
445
|
+
if (!edgeType && !owner) { onScope(null); onClose(); return; }
|
|
446
|
+
onScope({
|
|
447
|
+
edgeType: edgeType || null,
|
|
448
|
+
fromTemplate: edgeType ? (fromTemplate || null) : null,
|
|
449
|
+
toTemplate: edgeType ? (toTemplate || null) : null,
|
|
450
|
+
owner: owner || null,
|
|
451
|
+
});
|
|
452
|
+
onClose();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return (
|
|
456
|
+
<div className="graph-scope-popover">
|
|
457
|
+
<div className="graph-scope-row">
|
|
458
|
+
<label className="graph-scope-label">Interaction</label>
|
|
459
|
+
<select className="graph-scope-select" value={edgeType} onChange={e => setEdgeType(e.target.value)}>
|
|
460
|
+
<option value="">any</option>
|
|
461
|
+
{scopeOptions.edgeTypes.map(t => <option key={t} value={t}>{t}</option>)}
|
|
462
|
+
</select>
|
|
463
|
+
</div>
|
|
464
|
+
<div className="graph-scope-row">
|
|
465
|
+
<label className="graph-scope-label">From</label>
|
|
466
|
+
<select className="graph-scope-select" value={fromTemplate} onChange={e => setFromTemplate(e.target.value)} disabled={!edgeType}>
|
|
467
|
+
<option value="">any template</option>
|
|
468
|
+
{scopeOptions.templates.map(t => <option key={t.name} value={t.name}>{t.label}</option>)}
|
|
469
|
+
</select>
|
|
470
|
+
</div>
|
|
471
|
+
<div className="graph-scope-row">
|
|
472
|
+
<label className="graph-scope-label">To</label>
|
|
473
|
+
<select className="graph-scope-select" value={toTemplate} onChange={e => setToTemplate(e.target.value)} disabled={!edgeType}>
|
|
474
|
+
<option value="">any template</option>
|
|
475
|
+
{scopeOptions.templates.map(t => <option key={t.name} value={t.name}>{t.label}</option>)}
|
|
476
|
+
</select>
|
|
477
|
+
</div>
|
|
478
|
+
<div className="graph-scope-row">
|
|
479
|
+
<label className="graph-scope-label">Owner</label>
|
|
480
|
+
<select className="graph-scope-select" value={owner} onChange={e => setOwner(e.target.value)}>
|
|
481
|
+
<option value="">any</option>
|
|
482
|
+
{scopeOptions.owners.map(o => <option key={o.id} value={o.id}>{o.label}</option>)}
|
|
483
|
+
</select>
|
|
484
|
+
</div>
|
|
485
|
+
<div className="graph-scope-actions">
|
|
486
|
+
<button className="graph-toolbar-btn" onClick={() => { onScope(null); onClose(); }}>Clear</button>
|
|
487
|
+
<button className="graph-toolbar-btn active" onClick={apply}>Apply</button>
|
|
488
|
+
</div>
|
|
489
|
+
</div>
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function describeScope(scope, scopeOptions) {
|
|
494
|
+
const parts = [];
|
|
495
|
+
if (scope.edgeType) {
|
|
496
|
+
const from = scope.fromTemplate
|
|
497
|
+
? (scopeOptions.templates.find(t => t.name === scope.fromTemplate)?.label ?? scope.fromTemplate)
|
|
498
|
+
: 'any';
|
|
499
|
+
const to = scope.toTemplate
|
|
500
|
+
? (scopeOptions.templates.find(t => t.name === scope.toTemplate)?.label ?? scope.toTemplate)
|
|
501
|
+
: 'any';
|
|
502
|
+
parts.push(`${scope.edgeType} · ${from} → ${to}`);
|
|
503
|
+
}
|
|
504
|
+
if (scope.owner) parts.push(getDisplayName(scope.owner));
|
|
505
|
+
return parts.join(' · ');
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function GraphToolbar({ visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggleMinimap, onResetLayout, level, depth, onDepth, allNodes, focalNodeId, onFocalNode, layoutMode, onLayoutMode, scope, onScope, scopeOptions, scopeInfo }) {
|
|
183
509
|
const [searchQuery, setSearchQuery] = useState('');
|
|
184
510
|
const [searchOpen, setSearchOpen] = useState(false);
|
|
511
|
+
const [scopeOpen, setScopeOpen] = useState(false);
|
|
185
512
|
const searchRef = useRef(null);
|
|
513
|
+
const scopeRef = useRef(null);
|
|
514
|
+
|
|
515
|
+
useEffect(() => {
|
|
516
|
+
if (!scopeOpen) return;
|
|
517
|
+
function handleClick(e) {
|
|
518
|
+
if (scopeRef.current && !scopeRef.current.contains(e.target)) setScopeOpen(false);
|
|
519
|
+
}
|
|
520
|
+
document.addEventListener('mousedown', handleClick);
|
|
521
|
+
return () => document.removeEventListener('mousedown', handleClick);
|
|
522
|
+
}, [scopeOpen]);
|
|
186
523
|
|
|
187
524
|
const searchResults = useMemo(() => {
|
|
188
525
|
if (!searchQuery.trim()) return [];
|
|
@@ -259,6 +596,46 @@ function GraphToolbar({ visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggl
|
|
|
259
596
|
<div className="graph-toolbar-sep" />
|
|
260
597
|
</>
|
|
261
598
|
)}
|
|
599
|
+
{level === 'interior' && scopeOptions && (
|
|
600
|
+
<>
|
|
601
|
+
<div className="graph-scope" ref={scopeRef}>
|
|
602
|
+
<button
|
|
603
|
+
className={`graph-toolbar-btn${scope ? ' active' : ''}`}
|
|
604
|
+
onClick={() => setScopeOpen(v => !v)}
|
|
605
|
+
>Scope</button>
|
|
606
|
+
{scopeOpen && (
|
|
607
|
+
<ScopePopover
|
|
608
|
+
key={scope ? describeScope(scope, scopeOptions) : 'empty'}
|
|
609
|
+
scope={scope}
|
|
610
|
+
onScope={onScope}
|
|
611
|
+
scopeOptions={scopeOptions}
|
|
612
|
+
onClose={() => setScopeOpen(false)}
|
|
613
|
+
/>
|
|
614
|
+
)}
|
|
615
|
+
</div>
|
|
616
|
+
{scope && (
|
|
617
|
+
<span className="graph-scope-pill">
|
|
618
|
+
{describeScope(scope, scopeOptions)}
|
|
619
|
+
<span className="graph-scope-pill-clear" onClick={() => onScope(null)}>×</span>
|
|
620
|
+
</span>
|
|
621
|
+
)}
|
|
622
|
+
{scope && scopeInfo && (
|
|
623
|
+
<span className="graph-scope-count">{scopeInfo.matchCount} of {scopeInfo.threadCount} threads</span>
|
|
624
|
+
)}
|
|
625
|
+
</>
|
|
626
|
+
)}
|
|
627
|
+
{level !== 'component' && (
|
|
628
|
+
<div className="graph-layout-toggle">
|
|
629
|
+
<button
|
|
630
|
+
className={`graph-toolbar-btn${layoutMode === 'flat' ? ' active' : ''}`}
|
|
631
|
+
onClick={() => onLayoutMode('flat')}
|
|
632
|
+
>Flat</button>
|
|
633
|
+
<button
|
|
634
|
+
className={`graph-toolbar-btn${layoutMode === 'grouped' ? ' active' : ''}`}
|
|
635
|
+
onClick={() => onLayoutMode('grouped')}
|
|
636
|
+
>Grouped</button>
|
|
637
|
+
</div>
|
|
638
|
+
)}
|
|
262
639
|
<button className="graph-toolbar-btn" onClick={onResetLayout}>Reset layout</button>
|
|
263
640
|
<button className={`graph-toolbar-btn${showMinimap ? ' active' : ''}`} onClick={onToggleMinimap}>Minimap</button>
|
|
264
641
|
</div>
|
|
@@ -272,6 +649,8 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
272
649
|
const [showMinimap, setShowMinimap] = useState(false);
|
|
273
650
|
const [depth, setDepth] = useState(2);
|
|
274
651
|
const [layoutKey, setLayoutKey] = useState(0);
|
|
652
|
+
const [layoutMode, setLayoutMode] = useState(loadLayoutMode);
|
|
653
|
+
const [scope, setScope] = useState(null);
|
|
275
654
|
const [focusData, setFocusData] = useState(null);
|
|
276
655
|
const [reactFlowInstance, setReactFlowInstance] = useState(null);
|
|
277
656
|
const pendingViewportRef = useRef(null);
|
|
@@ -285,6 +664,8 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
285
664
|
const focalNodeId = route.params.get('focus') ?? null;
|
|
286
665
|
const level = focalNodeId ? 'focus' : selectedComponent ? 'interior' : 'component';
|
|
287
666
|
|
|
667
|
+
useEffect(() => { setScope(null); }, [selectedComponent]);
|
|
668
|
+
|
|
288
669
|
const navToRoot = useCallback(() => {
|
|
289
670
|
navigate(buildRoute({ pathname: '/graph', params: {}, branch: viewingRef }));
|
|
290
671
|
}, [viewingRef]);
|
|
@@ -354,15 +735,20 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
354
735
|
label: e.types.join(', '),
|
|
355
736
|
};
|
|
356
737
|
});
|
|
357
|
-
return { rfN
|
|
738
|
+
return { rfN, rfE };
|
|
358
739
|
}, [graphData, visibleEdgeTypes, layoutKey, navToComponent]);
|
|
359
740
|
|
|
360
741
|
useEffect(() => {
|
|
361
742
|
if (level !== 'component' || !level1) return;
|
|
743
|
+
let cancelled = false;
|
|
362
744
|
pendingViewportRef.current = { type: 'full' };
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
745
|
+
computeLayout(level1.rfN, level1.rfE, COMP_W, COMP_H, layoutMode).then(positioned => {
|
|
746
|
+
if (cancelled) return;
|
|
747
|
+
setRfNodes(positioned);
|
|
748
|
+
setRfEdges(level1.rfE);
|
|
749
|
+
});
|
|
750
|
+
return () => { cancelled = true; };
|
|
751
|
+
}, [level, level1, layoutMode]);
|
|
366
752
|
|
|
367
753
|
// Level 2: component interior
|
|
368
754
|
const level2 = useMemo(() => {
|
|
@@ -381,20 +767,64 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
381
767
|
const externalNodes = graphData.nodes.filter(n => externalNodeIds.has(n.id));
|
|
382
768
|
const allVisibleNodes = [...compNodes, ...externalNodes];
|
|
383
769
|
const allVisibleEdges = [...internalEdges, ...crossEdges];
|
|
384
|
-
|
|
385
|
-
|
|
770
|
+
|
|
771
|
+
// Options for the scope popover reflect the unscoped view.
|
|
772
|
+
const typedEdges = applyEdgeTypeFilter(allVisibleEdges, visibleEdgeTypes);
|
|
773
|
+
const parentCounts = new Map();
|
|
774
|
+
for (const n of allVisibleNodes) {
|
|
775
|
+
if (!n.parentId) continue;
|
|
776
|
+
parentCounts.set(n.parentId, (parentCounts.get(n.parentId) ?? 0) + 1);
|
|
777
|
+
}
|
|
778
|
+
const scopeOptions = {
|
|
779
|
+
edgeTypes: ALL_EDGE_TYPES.filter(t => visibleEdgeTypes.has(t) && typedEdges.some(e => e.type === t)),
|
|
780
|
+
templates: [...new Set(allVisibleNodes.map(n => n.template))].sort()
|
|
781
|
+
.map(name => ({ name, label: templateMap.get(name)?.ui?.displayName ?? name })),
|
|
782
|
+
owners: [...parentCounts.entries()].filter(([, c]) => c >= 2).map(([pid]) => pid).sort()
|
|
783
|
+
.map(pid => ({ id: pid, label: getDisplayName(pid) })),
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
// Apply the active scope: threads containing an interaction, then owner.
|
|
787
|
+
let visibleNodes = allVisibleNodes;
|
|
788
|
+
let visibleEdges = allVisibleEdges;
|
|
789
|
+
let scopeInfo = null;
|
|
790
|
+
if (scope) {
|
|
791
|
+
let keep = null;
|
|
792
|
+
if (scope.edgeType) {
|
|
793
|
+
const result = filterThreadScope(visibleNodes, typedEdges, scope);
|
|
794
|
+
keep = result.nodeIds;
|
|
795
|
+
scopeInfo = { matchCount: result.matchCount, threadCount: result.threadCount };
|
|
796
|
+
}
|
|
797
|
+
if (scope.owner) {
|
|
798
|
+
const baseNodes = keep ? visibleNodes.filter(n => keep.has(n.id)) : visibleNodes;
|
|
799
|
+
const baseEdges = typedEdges.filter(e => !keep || (keep.has(e.from) && keep.has(e.to)));
|
|
800
|
+
keep = filterOwnerScope(baseNodes, baseEdges, scope.owner);
|
|
801
|
+
}
|
|
802
|
+
if (keep) {
|
|
803
|
+
const keepIds = keep;
|
|
804
|
+
visibleNodes = visibleNodes.filter(n => keepIds.has(n.id));
|
|
805
|
+
visibleEdges = visibleEdges.filter(e => keepIds.has(e.from) && keepIds.has(e.to));
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
const rfN = buildRFNodesForNodes(visibleNodes, templateMap, navToFocus, viewingRef, externalNodeIds);
|
|
810
|
+
const rfE = buildRFEdgesForEdges(visibleEdges, visibleEdgeTypes).map(e => {
|
|
386
811
|
const isCross = crossEdges.some(ce => ce.id === e.id);
|
|
387
812
|
return isCross ? { ...e, style: { ...e.style, opacity: 0.45 }, labelStyle: { ...e.labelStyle, opacity: 0.45 } } : e;
|
|
388
813
|
});
|
|
389
|
-
return { rfN
|
|
390
|
-
}, [graphData, selectedComponent, visibleEdgeTypes, templateMap, layoutKey, navToFocus]);
|
|
814
|
+
return { rfN, rfE, scopeOptions, scopeInfo };
|
|
815
|
+
}, [graphData, selectedComponent, visibleEdgeTypes, templateMap, layoutKey, navToFocus, scope]);
|
|
391
816
|
|
|
392
817
|
useEffect(() => {
|
|
393
818
|
if (level !== 'interior' || !level2) return;
|
|
819
|
+
let cancelled = false;
|
|
394
820
|
pendingViewportRef.current = { type: 'full' };
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
821
|
+
computeLayout(level2.rfN, level2.rfE, NODE_W, NODE_H, layoutMode).then(positioned => {
|
|
822
|
+
if (cancelled) return;
|
|
823
|
+
setRfNodes(positioned);
|
|
824
|
+
setRfEdges(level2.rfE);
|
|
825
|
+
});
|
|
826
|
+
return () => { cancelled = true; };
|
|
827
|
+
}, [level, level2, layoutMode]);
|
|
398
828
|
|
|
399
829
|
useEffect(() => {
|
|
400
830
|
if (level === 'focus') return;
|
|
@@ -415,30 +845,27 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
415
845
|
...(focalNode && !focusData.nodes.some(n => n.id === focalNodeId) ? [focalNode] : []),
|
|
416
846
|
...focusData.nodes,
|
|
417
847
|
].map(n => ({ ...n, parentId: parentIdMap.get(n.id) ?? null }));
|
|
418
|
-
const rfN = buildRFNodesForNodes(lineageNodes, templateMap,
|
|
419
|
-
|
|
420
|
-
}, viewingRef);
|
|
848
|
+
const rfN = buildRFNodesForNodes(lineageNodes, templateMap, navToFocus, viewingRef)
|
|
849
|
+
.map(n => n.id === focalNodeId ? { ...n, data: { ...n.data, focal: true } } : n);
|
|
421
850
|
const rfE = buildRFEdgesForEdges(applyEdgeTypeFilter(focusData.edges, visibleEdgeTypes), visibleEdgeTypes);
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
rfN: layoutedN.map(n => n.id === focalNodeId
|
|
425
|
-
? { ...n, style: { outline: '2px solid var(--accent)', outlineOffset: '2px', borderRadius: 'var(--radius)' } }
|
|
426
|
-
: n
|
|
427
|
-
),
|
|
428
|
-
rfE,
|
|
429
|
-
};
|
|
430
|
-
}, [focusData, focalNodeId, visibleEdgeTypes, templateMap, layoutKey, viewingRef, graphData, nodeById]);
|
|
851
|
+
return { rfN, rfE };
|
|
852
|
+
}, [focusData, focalNodeId, visibleEdgeTypes, templateMap, layoutKey, viewingRef, graphData, nodeById, navToFocus]);
|
|
431
853
|
|
|
432
854
|
useEffect(() => {
|
|
433
855
|
if (level !== 'focus' || !level3) return;
|
|
856
|
+
let cancelled = false;
|
|
434
857
|
const focalChanged = lastFocusedNodeIdRef.current !== focalNodeId;
|
|
435
858
|
if (focalChanged) {
|
|
436
859
|
pendingViewportRef.current = { type: 'focus', nodeId: focalNodeId };
|
|
437
860
|
}
|
|
438
861
|
lastFocusedNodeIdRef.current = focalNodeId;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
862
|
+
computeLayout(level3.rfN, level3.rfE, NODE_W, NODE_H, layoutMode).then(positioned => {
|
|
863
|
+
if (cancelled) return;
|
|
864
|
+
setRfNodes(positioned);
|
|
865
|
+
setRfEdges(level3.rfE);
|
|
866
|
+
});
|
|
867
|
+
return () => { cancelled = true; };
|
|
868
|
+
}, [level, level3, focalNodeId, layoutMode]);
|
|
442
869
|
|
|
443
870
|
useEffect(() => {
|
|
444
871
|
if (!reactFlowInstance || !rfNodes.length) return;
|
|
@@ -447,22 +874,16 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
447
874
|
const pending = pendingViewportRef.current;
|
|
448
875
|
if (!pending) return;
|
|
449
876
|
if (pending.type === 'focus' && !rfNodes.some(node => node.id === pending.nodeId)) return;
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
reactFlowInstance.fitView({
|
|
457
|
-
duration: 0,
|
|
458
|
-
padding: 0.2,
|
|
459
|
-
});
|
|
460
|
-
} else {
|
|
461
|
-
reactFlowInstance.fitView({
|
|
462
|
-
duration: 0,
|
|
463
|
-
padding: 0.2,
|
|
464
|
-
});
|
|
877
|
+
const measuredId = pending.type === 'focus' ? pending.nodeId : rfNodes[0]?.id;
|
|
878
|
+
const measuredNode = measuredId ? reactFlowInstance.getNode(measuredId) : null;
|
|
879
|
+
if (!measuredNode?.width || !measuredNode?.height) {
|
|
880
|
+
frameId = requestAnimationFrame(fitPendingViewport);
|
|
881
|
+
return;
|
|
465
882
|
}
|
|
883
|
+
reactFlowInstance.fitView({
|
|
884
|
+
duration: 0,
|
|
885
|
+
padding: 0.2,
|
|
886
|
+
});
|
|
466
887
|
pendingViewportRef.current = null;
|
|
467
888
|
}
|
|
468
889
|
frameId = requestAnimationFrame(fitPendingViewport);
|
|
@@ -471,6 +892,16 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
471
892
|
};
|
|
472
893
|
}, [reactFlowInstance, rfNodes, rfEdges]);
|
|
473
894
|
|
|
895
|
+
const handleNodeDrag = useCallback((event, node) => {
|
|
896
|
+
if (!node.parentNode) return;
|
|
897
|
+
setRfNodes(ns => fitGroupsToChildren(ns, false));
|
|
898
|
+
}, [setRfNodes]);
|
|
899
|
+
|
|
900
|
+
const handleNodeDragStop = useCallback((event, node) => {
|
|
901
|
+
if (!node.parentNode) return;
|
|
902
|
+
setRfNodes(ns => fitGroupsToChildren(ns, true));
|
|
903
|
+
}, [setRfNodes]);
|
|
904
|
+
|
|
474
905
|
function handleToggleEdgeType(type) {
|
|
475
906
|
setVisibleEdgeTypes(prev => {
|
|
476
907
|
const next = new Set(prev);
|
|
@@ -487,7 +918,7 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
487
918
|
<div className="graph-section">
|
|
488
919
|
<GraphBreadcrumb
|
|
489
920
|
level={level}
|
|
490
|
-
selectedComponent={selectedComponent}
|
|
921
|
+
selectedComponent={selectedComponent ?? (focalNodeId ? nodeById.get(focalNodeId)?.component ?? null : null)}
|
|
491
922
|
focalNodeId={focalNodeId}
|
|
492
923
|
onNavigateToRoot={navToRoot}
|
|
493
924
|
onNavigateToComponent={navToComponent}
|
|
@@ -497,13 +928,19 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
497
928
|
onToggleEdgeType={handleToggleEdgeType}
|
|
498
929
|
showMinimap={showMinimap}
|
|
499
930
|
onToggleMinimap={() => setShowMinimap(v => !v)}
|
|
500
|
-
onResetLayout={() => setLayoutKey(k => k + 1)}
|
|
931
|
+
onResetLayout={() => { pendingViewportRef.current = { type: 'full' }; setLayoutKey(k => k + 1); }}
|
|
501
932
|
level={level}
|
|
502
933
|
depth={depth}
|
|
503
934
|
onDepth={setDepth}
|
|
504
935
|
allNodes={graphData?.nodes ?? []}
|
|
505
936
|
focalNodeId={focalNodeId}
|
|
506
937
|
onFocalNode={navToFocus}
|
|
938
|
+
layoutMode={layoutMode}
|
|
939
|
+
onLayoutMode={mode => { saveLayoutMode(mode); setLayoutMode(mode); }}
|
|
940
|
+
scope={scope}
|
|
941
|
+
onScope={setScope}
|
|
942
|
+
scopeOptions={level === 'interior' ? level2?.scopeOptions : null}
|
|
943
|
+
scopeInfo={level === 'interior' ? level2?.scopeInfo : null}
|
|
507
944
|
/>
|
|
508
945
|
<div className="graph-canvas-wrap">
|
|
509
946
|
<ReactFlowProvider>
|
|
@@ -512,6 +949,8 @@ function GraphView({ route, viewingRef, templates }) {
|
|
|
512
949
|
edges={rfEdges}
|
|
513
950
|
onNodesChange={onNodesChange}
|
|
514
951
|
onEdgesChange={onEdgesChange}
|
|
952
|
+
onNodeDrag={handleNodeDrag}
|
|
953
|
+
onNodeDragStop={handleNodeDragStop}
|
|
515
954
|
onInit={setReactFlowInstance}
|
|
516
955
|
nodeTypes={nodeTypes}
|
|
517
956
|
fitView
|
package/web/index.html
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
<script src="https://unpkg.com/react@18.3.1/umd/react.production.min.js" crossorigin="anonymous"></script>
|
|
22
22
|
<script src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js" crossorigin="anonymous"></script>
|
|
23
|
-
<script src="https://unpkg.com/
|
|
23
|
+
<script src="https://unpkg.com/elkjs@0.9.3/lib/elk.bundled.js" crossorigin="anonymous"></script>
|
|
24
24
|
<script src="https://unpkg.com/reactflow@11.11.4/dist/umd/index.js" crossorigin="anonymous"></script>
|
|
25
25
|
<script src="https://unpkg.com/@babel/standalone@7.29.0/babel.min.js" crossorigin="anonymous"></script>
|
|
26
26
|
<script src="nav.js"></script>
|
package/web/style.css
CHANGED
|
@@ -1458,6 +1458,127 @@ button {
|
|
|
1458
1458
|
|
|
1459
1459
|
.graph-nav-link:hover { color: var(--ink-2); }
|
|
1460
1460
|
|
|
1461
|
+
/* Flat/Grouped layout mode toggle */
|
|
1462
|
+
.graph-layout-toggle {
|
|
1463
|
+
display: flex;
|
|
1464
|
+
gap: 4px;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
/* External (cross-component) node cards, faded to de-emphasise */
|
|
1468
|
+
.graph-node-card.faded {
|
|
1469
|
+
opacity: 0.5;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/* Focal node highlight: solid outline with a gentle glowing pulse */
|
|
1473
|
+
.graph-node-card.focal {
|
|
1474
|
+
outline: 2px solid var(--accent);
|
|
1475
|
+
outline-offset: 2px;
|
|
1476
|
+
animation: graph-focal-glow 2.4s ease-in-out infinite;
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
@keyframes graph-focal-glow {
|
|
1480
|
+
0%, 100% { box-shadow: 0 0 6px 2px color-mix(in srgb, var(--accent) 45%, transparent); }
|
|
1481
|
+
50% { box-shadow: 0 0 16px 5px color-mix(in srgb, var(--accent) 75%, transparent); }
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
/* Thread/aggregate scope popover */
|
|
1485
|
+
.graph-scope { position: relative; }
|
|
1486
|
+
|
|
1487
|
+
.graph-scope-popover {
|
|
1488
|
+
position: absolute;
|
|
1489
|
+
top: calc(100% + 4px);
|
|
1490
|
+
left: 0;
|
|
1491
|
+
z-index: 100;
|
|
1492
|
+
background: var(--paper);
|
|
1493
|
+
border: 1px solid var(--rule-2);
|
|
1494
|
+
border-radius: var(--radius);
|
|
1495
|
+
box-shadow: 0 4px 16px rgba(0,0,0,0.12);
|
|
1496
|
+
padding: 10px;
|
|
1497
|
+
display: flex;
|
|
1498
|
+
flex-direction: column;
|
|
1499
|
+
gap: 8px;
|
|
1500
|
+
min-width: 240px;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
.graph-scope-row {
|
|
1504
|
+
display: flex;
|
|
1505
|
+
align-items: center;
|
|
1506
|
+
gap: 8px;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
.graph-scope-label {
|
|
1510
|
+
font-size: 11px;
|
|
1511
|
+
font-weight: 500;
|
|
1512
|
+
color: var(--ink-3);
|
|
1513
|
+
width: 64px;
|
|
1514
|
+
flex-shrink: 0;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
.graph-scope-select {
|
|
1518
|
+
font: inherit;
|
|
1519
|
+
font-size: 11px;
|
|
1520
|
+
flex: 1;
|
|
1521
|
+
padding: 3px 6px;
|
|
1522
|
+
border: 1px solid var(--rule-2);
|
|
1523
|
+
border-radius: var(--radius);
|
|
1524
|
+
background: var(--paper);
|
|
1525
|
+
color: var(--ink);
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
.graph-scope-select:disabled { opacity: 0.5; }
|
|
1529
|
+
|
|
1530
|
+
.graph-scope-actions {
|
|
1531
|
+
display: flex;
|
|
1532
|
+
justify-content: flex-end;
|
|
1533
|
+
gap: 6px;
|
|
1534
|
+
margin-top: 2px;
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
.graph-scope-pill {
|
|
1538
|
+
display: inline-flex;
|
|
1539
|
+
align-items: center;
|
|
1540
|
+
gap: 6px;
|
|
1541
|
+
padding: 3px 9px;
|
|
1542
|
+
border-radius: 999px;
|
|
1543
|
+
font-size: 11px;
|
|
1544
|
+
font-weight: 500;
|
|
1545
|
+
background: var(--paper-3);
|
|
1546
|
+
color: var(--ink-2);
|
|
1547
|
+
border: 1.5px solid var(--rule-2);
|
|
1548
|
+
white-space: nowrap;
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
.graph-scope-pill-clear {
|
|
1552
|
+
cursor: pointer;
|
|
1553
|
+
color: var(--ink-3);
|
|
1554
|
+
font-weight: 600;
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
.graph-scope-pill-clear:hover { color: var(--ink); }
|
|
1558
|
+
|
|
1559
|
+
.graph-scope-count {
|
|
1560
|
+
font-size: 11px;
|
|
1561
|
+
color: var(--ink-3);
|
|
1562
|
+
white-space: nowrap;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
/* Grouped-mode compound container card */
|
|
1566
|
+
.graph-group-card {
|
|
1567
|
+
width: 100%;
|
|
1568
|
+
height: 100%;
|
|
1569
|
+
border: 1.5px dashed var(--ink-4);
|
|
1570
|
+
background: rgba(0, 0, 0, 0.02);
|
|
1571
|
+
border-radius: var(--radius);
|
|
1572
|
+
box-sizing: border-box;
|
|
1573
|
+
padding: 6px 10px;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
.graph-group-card-label {
|
|
1577
|
+
font-size: 11px;
|
|
1578
|
+
font-weight: 600;
|
|
1579
|
+
color: var(--ink-3);
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1461
1582
|
/* ── Dashboard ────────────────────────────────────── */
|
|
1462
1583
|
|
|
1463
1584
|
.dashboard-hero {
|