@open-livex-wiki/graph-ui 0.2.1 → 0.2.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/dist/assets/{index-Ci04LT-F.js → index-Dhx4bDx4.js} +3 -3
- package/dist/index.html +1 -1
- package/dist-lib/graph-logic/filters.d.ts +44 -0
- package/dist-lib/graph-logic/filters.d.ts.map +1 -0
- package/dist-lib/graph-logic/filters.js +178 -0
- package/dist-lib/graph-logic/filters.js.map +1 -0
- package/dist-lib/graph-logic/graph-data.d.ts +53 -0
- package/dist-lib/graph-logic/graph-data.d.ts.map +1 -0
- package/dist-lib/graph-logic/graph-data.js +129 -0
- package/dist-lib/graph-logic/graph-data.js.map +1 -0
- package/dist-lib/graph-logic/layout.d.ts +98 -0
- package/dist-lib/graph-logic/layout.d.ts.map +1 -0
- package/dist-lib/graph-logic/layout.js +362 -0
- package/dist-lib/graph-logic/layout.js.map +1 -0
- package/dist-lib/graph-logic.d.ts +3 -190
- package/dist-lib/graph-logic.d.ts.map +1 -1
- package/dist-lib/graph-logic.js +3 -665
- package/dist-lib/graph-logic.js.map +1 -1
- package/package.json +2 -2
package/dist-lib/graph-logic.js
CHANGED
|
@@ -1,666 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
{ bg: "#f5f3ff", border: "#c4b5fd", text: "#3b0764" }, // soft lavender
|
|
5
|
-
{ bg: "#ecfeff", border: "#67e8f9", text: "#164e63" }, // crisp cyan/sky
|
|
6
|
-
{ bg: "#fefce8", border: "#fde047", text: "#713f12" }, // warm butter
|
|
7
|
-
{ bg: "#f0fdf4", border: "#86efac", text: "#14532d" }, // sage mint
|
|
8
|
-
{ bg: "#eff6ff", border: "#93c5fd", text: "#1e3a8a" }, // soft blue
|
|
9
|
-
{ bg: "#fdf2f8", border: "#f9a8d4", text: "#831843" }, // soft rose
|
|
10
|
-
{ bg: "#f8fafc", border: "#cbd5e1", text: "#1e293b" }, // cool slate
|
|
11
|
-
];
|
|
12
|
-
const VALID_FRESHNESS_VALUES = new Set(["fresh", "stale", "unverified"]);
|
|
13
|
-
/**
|
|
14
|
-
* Parses and validates a `livex-graph/v1` payload while preserving optional `freshnessStatus`
|
|
15
|
-
* metadata across schema versions.
|
|
16
|
-
*/
|
|
17
|
-
export function parseGraphDataPayload(raw) {
|
|
18
|
-
const parsed = GraphDataSchema.safeParse(raw);
|
|
19
|
-
if (!parsed.success) {
|
|
20
|
-
return {
|
|
21
|
-
success: false,
|
|
22
|
-
message: parsed.error.issues[0]?.message ?? "schema mismatch",
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const rawNodes = typeof raw === "object" && raw !== null && Array.isArray(raw.nodes)
|
|
26
|
-
? (raw.nodes ?? [])
|
|
27
|
-
: [];
|
|
28
|
-
const nodesWithFreshness = [];
|
|
29
|
-
for (let i = 0; i < parsed.data.nodes.length; i += 1) {
|
|
30
|
-
const validNode = parsed.data.nodes[i];
|
|
31
|
-
const rawNode = rawNodes[i];
|
|
32
|
-
if (typeof rawNode === "object" &&
|
|
33
|
-
rawNode !== null &&
|
|
34
|
-
"freshnessStatus" in rawNode &&
|
|
35
|
-
rawNode.freshnessStatus !== undefined) {
|
|
36
|
-
const candidate = rawNode.freshnessStatus;
|
|
37
|
-
if (typeof candidate !== "string" || !VALID_FRESHNESS_VALUES.has(candidate)) {
|
|
38
|
-
return {
|
|
39
|
-
success: false,
|
|
40
|
-
message: `Invalid freshnessStatus "${String(candidate)}" on node "${validNode.id}"`,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
nodesWithFreshness.push({
|
|
44
|
-
...validNode,
|
|
45
|
-
freshnessStatus: candidate,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
nodesWithFreshness.push(validNode);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
success: true,
|
|
54
|
-
data: {
|
|
55
|
-
...parsed.data,
|
|
56
|
-
nodes: nodesWithFreshness,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Returns true if the node is marked stale either via `stale: true` or `freshnessStatus: "stale"`.
|
|
62
|
-
*/
|
|
63
|
-
export function isNodeStale(node) {
|
|
64
|
-
return node.stale === true || node.freshnessStatus === "stale";
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Resolves explicit, honest freshness badge semantics (`stale` vs `fresh` vs `unverified`) so
|
|
68
|
-
* static snapshots built without `--repos-dir` never falsely claim live source verification.
|
|
69
|
-
*/
|
|
70
|
-
export function resolveNodeFreshness(node) {
|
|
71
|
-
if (isNodeStale(node)) {
|
|
72
|
-
return {
|
|
73
|
-
status: "stale",
|
|
74
|
-
label: "待更新 · Stale",
|
|
75
|
-
description: node.staleReason ?? "关联代码仓 HEAD 已领先当前锚定 Commit,建议执行增量更新。",
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
if (node.freshnessStatus === "fresh") {
|
|
79
|
-
return {
|
|
80
|
-
status: "fresh",
|
|
81
|
-
label: "已回源核验 · Fresh",
|
|
82
|
-
description: "已与本地代码仓当前 HEAD 比对,锚定路径与符号未发生滞后变更。",
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
status: "unverified",
|
|
87
|
-
label: "静态快照 · 未连仓核验",
|
|
88
|
-
description: "当前图谱未提供 --repos-dir 实时比对源码仓,仅展示知识库静态锚定快照。",
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Formats the node count status indicator (`显示 X / Y 节点` when filtered, `Y 节点` when unfiltered).
|
|
93
|
-
*/
|
|
94
|
-
export function formatNodeCountIndicator(visibleDataNodeCount, totalDataNodeCount) {
|
|
95
|
-
if (visibleDataNodeCount < totalDataNodeCount) {
|
|
96
|
-
return `显示 ${visibleDataNodeCount} / ${totalDataNodeCount} 节点`;
|
|
97
|
-
}
|
|
98
|
-
return `${totalDataNodeCount} 节点`;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Builds the relative API endpoint URL used by `olw graph serve --no-markdown` to lazily fetch a
|
|
102
|
-
* node's full Markdown body on demand.
|
|
103
|
-
*/
|
|
104
|
-
export function buildNodeMarkdownEndpoint(nodeId) {
|
|
105
|
-
return `./api/nodes/${encodeURIComponent(nodeId)}/markdown`;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Lazily fetches a node's Markdown body from `./api/nodes/<encodedId>/markdown` with in-memory
|
|
109
|
-
* caching and graceful static-hosting fallback when built with `--no-markdown`.
|
|
110
|
-
*/
|
|
111
|
-
export async function fetchNodeMarkdownLazy(nodeId, options = {}) {
|
|
112
|
-
const cached = options.cache?.get(nodeId);
|
|
113
|
-
if (cached !== undefined) {
|
|
114
|
-
return { status: "loaded", markdown: cached };
|
|
115
|
-
}
|
|
116
|
-
const fetchFn = options.fetchImpl ?? (typeof fetch !== "undefined" ? fetch : undefined);
|
|
117
|
-
if (!fetchFn) {
|
|
118
|
-
return { status: "unavailable" };
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
const res = await fetchFn(buildNodeMarkdownEndpoint(nodeId), {
|
|
122
|
-
cache: "no-store",
|
|
123
|
-
...(options.signal ? { signal: options.signal } : {}),
|
|
124
|
-
});
|
|
125
|
-
if (options.signal?.aborted) {
|
|
126
|
-
return { status: "aborted" };
|
|
127
|
-
}
|
|
128
|
-
if (!res.ok) {
|
|
129
|
-
return { status: "unavailable" };
|
|
130
|
-
}
|
|
131
|
-
const payload = await res.json();
|
|
132
|
-
if (typeof payload === "object" &&
|
|
133
|
-
payload !== null &&
|
|
134
|
-
typeof payload.markdown === "string") {
|
|
135
|
-
const markdown = payload.markdown;
|
|
136
|
-
options.cache?.set(nodeId, markdown);
|
|
137
|
-
return { status: "loaded", markdown };
|
|
138
|
-
}
|
|
139
|
-
return { status: "unavailable" };
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
if (options.signal?.aborted) {
|
|
143
|
-
return { status: "aborted" };
|
|
144
|
-
}
|
|
145
|
-
return { status: "unavailable" };
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Checks whether a single GraphNode matches a free-text search query across title, ID, domainId,
|
|
150
|
-
* sceneId, aliases, and summary.
|
|
151
|
-
*/
|
|
152
|
-
export function matchesSearchQuery(node, rawQuery) {
|
|
153
|
-
const q = rawQuery.trim().toLowerCase();
|
|
154
|
-
if (!q) {
|
|
155
|
-
return true;
|
|
156
|
-
}
|
|
157
|
-
if (node.id.toLowerCase().includes(q)) {
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
if (node.title.toLowerCase().includes(q)) {
|
|
161
|
-
return true;
|
|
162
|
-
}
|
|
163
|
-
if (node.domainId.toLowerCase().includes(q)) {
|
|
164
|
-
return true;
|
|
165
|
-
}
|
|
166
|
-
if (node.sceneId?.toLowerCase().includes(q)) {
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
169
|
-
if (node.aliases.some((alias) => alias.toLowerCase().includes(q))) {
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
if (node.summary.toLowerCase().includes(q)) {
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Searches and ranks graph nodes for instant typeahead / command-K lookup.
|
|
179
|
-
*/
|
|
180
|
-
export function searchGraphNodes(data, rawQuery, limit = 12) {
|
|
181
|
-
const q = rawQuery.trim().toLowerCase();
|
|
182
|
-
if (!q) {
|
|
183
|
-
return [];
|
|
184
|
-
}
|
|
185
|
-
const scored = [];
|
|
186
|
-
for (const node of data.nodes) {
|
|
187
|
-
let score = 0;
|
|
188
|
-
const idLower = node.id.toLowerCase();
|
|
189
|
-
const titleLower = node.title.toLowerCase();
|
|
190
|
-
const sceneLower = node.sceneId?.toLowerCase() ?? "";
|
|
191
|
-
const aliasesLower = node.aliases.map((a) => a.toLowerCase());
|
|
192
|
-
if (idLower === q || titleLower === q || sceneLower === q || aliasesLower.includes(q)) {
|
|
193
|
-
score = 100;
|
|
194
|
-
}
|
|
195
|
-
else if (titleLower.startsWith(q) ||
|
|
196
|
-
idLower.startsWith(q) ||
|
|
197
|
-
sceneLower.startsWith(q) ||
|
|
198
|
-
aliasesLower.some((a) => a.startsWith(q))) {
|
|
199
|
-
score = 80;
|
|
200
|
-
}
|
|
201
|
-
else if (titleLower.includes(q) || aliasesLower.some((a) => a.includes(q))) {
|
|
202
|
-
score = 65;
|
|
203
|
-
}
|
|
204
|
-
else if (idLower.includes(q) || node.domainId.toLowerCase().includes(q)) {
|
|
205
|
-
score = 50;
|
|
206
|
-
}
|
|
207
|
-
else if (node.summary.toLowerCase().includes(q)) {
|
|
208
|
-
score = 30;
|
|
209
|
-
}
|
|
210
|
-
if (score > 0) {
|
|
211
|
-
const typeBoost = node.type === "domain" ? 3 : node.type === "scene" ? 2 : 1;
|
|
212
|
-
scored.push({ node, score: score + typeBoost });
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
scored.sort((a, b) => b.score - a.score || a.node.id.localeCompare(b.node.id));
|
|
216
|
-
return scored.slice(0, limit).map((item) => item.node);
|
|
217
|
-
}
|
|
218
|
-
export function matchesHealthFilter(node, health) {
|
|
219
|
-
const nodeWithFreshness = node;
|
|
220
|
-
switch (health) {
|
|
221
|
-
case "all":
|
|
222
|
-
return true;
|
|
223
|
-
case "stale":
|
|
224
|
-
return isNodeStale(nodeWithFreshness);
|
|
225
|
-
case "fresh":
|
|
226
|
-
return !isNodeStale(nodeWithFreshness) && nodeWithFreshness.freshnessStatus === "fresh";
|
|
227
|
-
case "unverified": {
|
|
228
|
-
if (isNodeStale(nodeWithFreshness)) {
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
if (nodeWithFreshness.freshnessStatus === "unverified") {
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
if (nodeWithFreshness.freshnessStatus === "fresh") {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
return node.type !== "domain";
|
|
238
|
-
}
|
|
239
|
-
case "pending":
|
|
240
|
-
return Boolean(node.hasPendingConfirmations);
|
|
241
|
-
case "low_confidence":
|
|
242
|
-
return node.confidence !== undefined && node.confidence < 0.9;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Filters graph nodes and edges deterministically according to domain, type, health, search query,
|
|
247
|
-
* and `belongs_to` edge visibility.
|
|
248
|
-
*/
|
|
249
|
-
export function filterGraphElements(data, criteria = {}) {
|
|
250
|
-
const domainFilter = criteria.domainId?.trim() ?? "all";
|
|
251
|
-
const nodeType = criteria.nodeType ?? "all";
|
|
252
|
-
const health = criteria.health ?? "all";
|
|
253
|
-
const query = criteria.query?.trim() ?? "";
|
|
254
|
-
const showBelongsTo = criteria.showBelongsTo ?? true;
|
|
255
|
-
const matchedNodeIds = new Set();
|
|
256
|
-
const visibleNodeIds = new Set();
|
|
257
|
-
const nodes = [];
|
|
258
|
-
for (const node of data.nodes) {
|
|
259
|
-
const queryMatched = query.length > 0 ? matchesSearchQuery(node, query) : false;
|
|
260
|
-
if (queryMatched) {
|
|
261
|
-
matchedNodeIds.add(node.id);
|
|
262
|
-
}
|
|
263
|
-
if (domainFilter && domainFilter !== "all" && node.domainId !== domainFilter) {
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
if (nodeType !== "all" && node.type !== nodeType) {
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
if (!matchesHealthFilter(node, health)) {
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
if (query.length > 0 && !queryMatched) {
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
visibleNodeIds.add(node.id);
|
|
276
|
-
nodes.push(node);
|
|
277
|
-
}
|
|
278
|
-
const edges = data.edges.filter((edge) => {
|
|
279
|
-
if (!showBelongsTo && edge.type === "belongs_to") {
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
return visibleNodeIds.has(edge.source) && visibleNodeIds.has(edge.target);
|
|
283
|
-
});
|
|
284
|
-
return {
|
|
285
|
-
nodes,
|
|
286
|
-
edges,
|
|
287
|
-
matchedNodeIds,
|
|
288
|
-
visibleNodeIds,
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Computes the 1-hop neighborhood (`belongs_to` + upstream `dependsOn` + downstream `dependents`)
|
|
293
|
-
* around a focused node for interactive highlighting.
|
|
294
|
-
*/
|
|
295
|
-
export function computeNeighborhood(nodes, edges, focusNodeId) {
|
|
296
|
-
const validIds = new Set(nodes.map((n) => n.id));
|
|
297
|
-
const nodeIds = new Set();
|
|
298
|
-
const edgeIds = new Set();
|
|
299
|
-
if (!validIds.has(focusNodeId)) {
|
|
300
|
-
return { nodeIds, edgeIds };
|
|
301
|
-
}
|
|
302
|
-
nodeIds.add(focusNodeId);
|
|
303
|
-
for (const edge of edges) {
|
|
304
|
-
if (edge.source === focusNodeId && validIds.has(edge.target)) {
|
|
305
|
-
nodeIds.add(edge.target);
|
|
306
|
-
edgeIds.add(edge.id);
|
|
307
|
-
}
|
|
308
|
-
else if (edge.target === focusNodeId && validIds.has(edge.source)) {
|
|
309
|
-
nodeIds.add(edge.source);
|
|
310
|
-
edgeIds.add(edge.id);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return { nodeIds, edgeIds };
|
|
314
|
-
}
|
|
315
|
-
function getSceneSubCols(count) {
|
|
316
|
-
if (count <= 0)
|
|
317
|
-
return 0;
|
|
318
|
-
if (count === 1)
|
|
319
|
-
return 1;
|
|
320
|
-
if (count <= 4)
|
|
321
|
-
return 2;
|
|
322
|
-
if (count <= 18)
|
|
323
|
-
return 3;
|
|
324
|
-
return 4;
|
|
325
|
-
}
|
|
326
|
-
function getInfraSubCols(count) {
|
|
327
|
-
if (count <= 0)
|
|
328
|
-
return 0;
|
|
329
|
-
if (count === 1)
|
|
330
|
-
return 1;
|
|
331
|
-
if (count <= 4)
|
|
332
|
-
return 2;
|
|
333
|
-
if (count <= 12)
|
|
334
|
-
return 3;
|
|
335
|
-
if (count <= 24)
|
|
336
|
-
return 4;
|
|
337
|
-
return 5;
|
|
338
|
-
}
|
|
339
|
-
function computeCenteredGridPositions(count, subCols, columnCenterX, startTopY, cardWidth, cardHeight, gapX, gapY) {
|
|
340
|
-
if (count === 0 || subCols === 0) {
|
|
341
|
-
return [];
|
|
342
|
-
}
|
|
343
|
-
const coords = [];
|
|
344
|
-
const totalRows = Math.ceil(count / subCols);
|
|
345
|
-
for (let row = 0; row < totalRows; row += 1) {
|
|
346
|
-
const rowStartIdx = row * subCols;
|
|
347
|
-
const itemsInRow = Math.min(subCols, count - rowStartIdx);
|
|
348
|
-
const rowWidth = itemsInRow * cardWidth + (itemsInRow - 1) * gapX;
|
|
349
|
-
const rowLeftX = columnCenterX - rowWidth / 2;
|
|
350
|
-
const centerY = startTopY + cardHeight / 2 + row * (cardHeight + gapY);
|
|
351
|
-
for (let col = 0; col < itemsInRow; col += 1) {
|
|
352
|
-
const centerX = rowLeftX + cardWidth / 2 + col * (cardWidth + gapX);
|
|
353
|
-
coords.push({ x: centerX, y: centerY });
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return coords;
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Computes deterministic, collision-free coordinates for Mode B (`依赖层次` / Dependency Hierarchy):
|
|
360
|
-
* - Vertical Domain Columns (infrastructure domain columns placed leftmost like `基建域`, followed
|
|
361
|
-
* by business domain columns sorted by size).
|
|
362
|
-
* - 3 Horizontal Swimlane Tiers:
|
|
363
|
-
* - `01 领域` (top band): Domain header rectangular cards centered atop each column.
|
|
364
|
-
* - `02 场景` (middle band): Multi-column sub-grids of scene cards inside owning domain columns.
|
|
365
|
-
* - `03 知识` (bottom band): Multi-column sub-grids of shared knowledge cards at the bottom.
|
|
366
|
-
*/
|
|
367
|
-
export function computeHierarchyLayout(nodes, options = {}) {
|
|
368
|
-
const domainCardWidth = options.domainCardWidth ?? 128;
|
|
369
|
-
const domainCardHeight = options.domainCardHeight ?? 36;
|
|
370
|
-
const sceneCardWidth = options.sceneCardWidth ?? 124;
|
|
371
|
-
const sceneCardHeight = options.sceneCardHeight ?? 32;
|
|
372
|
-
const infraCardWidth = options.infraCardWidth ?? 120;
|
|
373
|
-
const infraCardHeight = options.infraCardHeight ?? 30;
|
|
374
|
-
const cellGapX = options.cellGapX ?? 12;
|
|
375
|
-
const cellGapY = options.cellGapY ?? 12;
|
|
376
|
-
const columnPaddingX = options.columnPaddingX ?? 22;
|
|
377
|
-
const columnGap = options.columnGap ?? 26;
|
|
378
|
-
const routingChannelHeight = options.routingChannelHeight ?? 76;
|
|
379
|
-
const infraDomainHints = new Set(options.infrastructureDomains ?? ["business-infrastructure"]);
|
|
380
|
-
if (nodes.length === 0) {
|
|
381
|
-
return {
|
|
382
|
-
positions: {},
|
|
383
|
-
nodeBoxes: {},
|
|
384
|
-
columns: [],
|
|
385
|
-
tiers: [],
|
|
386
|
-
bounds: { minX: 0, minY: 0, maxX: 0, maxY: 0, width: 0, height: 0 },
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
const buckets = new Map();
|
|
390
|
-
const ensureBucket = (domainId) => {
|
|
391
|
-
let bucket = buckets.get(domainId);
|
|
392
|
-
if (!bucket) {
|
|
393
|
-
bucket = { domainId, scenes: [], infras: [] };
|
|
394
|
-
buckets.set(domainId, bucket);
|
|
395
|
-
}
|
|
396
|
-
return bucket;
|
|
397
|
-
};
|
|
398
|
-
for (const node of nodes) {
|
|
399
|
-
const bucket = ensureBucket(node.domainId);
|
|
400
|
-
if (node.type === "domain") {
|
|
401
|
-
bucket.domainNode = node;
|
|
402
|
-
}
|
|
403
|
-
else if (node.type === "scene") {
|
|
404
|
-
bucket.scenes.push(node);
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
bucket.infras.push(node);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
for (const bucket of buckets.values()) {
|
|
411
|
-
bucket.scenes.sort((a, b) => a.id.localeCompare(b.id));
|
|
412
|
-
bucket.infras.sort((a, b) => a.id.localeCompare(b.id));
|
|
413
|
-
}
|
|
414
|
-
const isInfraBucket = (bucket) => {
|
|
415
|
-
if (infraDomainHints.has(bucket.domainId)) {
|
|
416
|
-
return true;
|
|
417
|
-
}
|
|
418
|
-
if (bucket.infras.length > 0 && bucket.scenes.length === 0) {
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
return bucket.infras.length > bucket.scenes.length;
|
|
422
|
-
};
|
|
423
|
-
const orderedBuckets = Array.from(buckets.values()).sort((a, b) => {
|
|
424
|
-
const aInfra = isInfraBucket(a);
|
|
425
|
-
const bInfra = isInfraBucket(b);
|
|
426
|
-
if (aInfra !== bInfra) {
|
|
427
|
-
return aInfra ? -1 : 1;
|
|
428
|
-
}
|
|
429
|
-
if (aInfra) {
|
|
430
|
-
const diff = b.infras.length - a.infras.length;
|
|
431
|
-
return diff !== 0 ? diff : a.domainId.localeCompare(b.domainId);
|
|
432
|
-
}
|
|
433
|
-
const aTotal = a.scenes.length + a.infras.length;
|
|
434
|
-
const bTotal = b.scenes.length + b.infras.length;
|
|
435
|
-
if (bTotal !== aTotal) {
|
|
436
|
-
return bTotal - aTotal;
|
|
437
|
-
}
|
|
438
|
-
return a.domainId.localeCompare(b.domainId);
|
|
439
|
-
});
|
|
440
|
-
const colMetrics = orderedBuckets.map((bucket) => {
|
|
441
|
-
const sceneCols = getSceneSubCols(bucket.scenes.length);
|
|
442
|
-
const infraCols = getInfraSubCols(bucket.infras.length);
|
|
443
|
-
const sceneRows = sceneCols > 0 ? Math.ceil(bucket.scenes.length / sceneCols) : 0;
|
|
444
|
-
const infraRows = infraCols > 0 ? Math.ceil(bucket.infras.length / infraCols) : 0;
|
|
445
|
-
const sceneGridW = sceneCols > 0 ? sceneCols * sceneCardWidth + (sceneCols - 1) * cellGapX : 0;
|
|
446
|
-
const infraGridW = infraCols > 0 ? infraCols * infraCardWidth + (infraCols - 1) * cellGapX : 0;
|
|
447
|
-
const innerWidth = Math.max(domainCardWidth, sceneGridW, infraGridW);
|
|
448
|
-
const columnWidth = innerWidth + columnPaddingX * 2;
|
|
449
|
-
return {
|
|
450
|
-
bucket,
|
|
451
|
-
isInfra: isInfraBucket(bucket),
|
|
452
|
-
sceneCols,
|
|
453
|
-
infraCols,
|
|
454
|
-
sceneRows,
|
|
455
|
-
infraRows,
|
|
456
|
-
columnWidth,
|
|
457
|
-
};
|
|
458
|
-
});
|
|
459
|
-
const maxSceneRows = Math.max(0, ...colMetrics.map((m) => m.sceneRows));
|
|
460
|
-
const maxInfraRows = Math.max(0, ...colMetrics.map((m) => m.infraRows));
|
|
461
|
-
const effectiveSceneRows = Math.max(2, maxSceneRows);
|
|
462
|
-
const columnTopY = 0;
|
|
463
|
-
const topInnerPadding = 24;
|
|
464
|
-
const domainCenterY = columnTopY + topInnerPadding + domainCardHeight / 2;
|
|
465
|
-
const sceneStartTopY = columnTopY + topInnerPadding + domainCardHeight + 26;
|
|
466
|
-
const sceneBandBottomY = sceneStartTopY + effectiveSceneRows * sceneCardHeight + (effectiveSceneRows - 1) * cellGapY;
|
|
467
|
-
const infraStartTopY = sceneBandBottomY + routingChannelHeight;
|
|
468
|
-
const infraBandBottomY = maxInfraRows > 0
|
|
469
|
-
? infraStartTopY + maxInfraRows * infraCardHeight + (maxInfraRows - 1) * cellGapY
|
|
470
|
-
: infraStartTopY + infraCardHeight;
|
|
471
|
-
const columnBottomY = (maxInfraRows > 0 ? infraBandBottomY : sceneBandBottomY) + 28;
|
|
472
|
-
const columnHeight = columnBottomY - columnTopY;
|
|
473
|
-
const firstColumnLeftX = 116;
|
|
474
|
-
const positions = {};
|
|
475
|
-
const nodeBoxes = {};
|
|
476
|
-
const columns = [];
|
|
477
|
-
let cursorLeftX = firstColumnLeftX;
|
|
478
|
-
colMetrics.forEach((metric, columnIndex) => {
|
|
479
|
-
const { bucket, isInfra, sceneCols, infraCols, columnWidth } = metric;
|
|
480
|
-
const paletteIndex = isInfra
|
|
481
|
-
? 0
|
|
482
|
-
: ((columnIndex - 1 + DOMAIN_CARD_PALETTES.length) % (DOMAIN_CARD_PALETTES.length - 1)) + 1;
|
|
483
|
-
const columnCenterX = cursorLeftX + columnWidth / 2;
|
|
484
|
-
columns.push({
|
|
485
|
-
domainId: bucket.domainId,
|
|
486
|
-
title: bucket.domainNode?.title ?? bucket.domainId,
|
|
487
|
-
isInfrastructureDomain: isInfra,
|
|
488
|
-
columnIndex,
|
|
489
|
-
x: columnCenterX,
|
|
490
|
-
y: columnTopY + columnHeight / 2,
|
|
491
|
-
left: cursorLeftX,
|
|
492
|
-
top: columnTopY,
|
|
493
|
-
width: columnWidth,
|
|
494
|
-
height: columnHeight,
|
|
495
|
-
paletteIndex,
|
|
496
|
-
sceneCount: bucket.scenes.length,
|
|
497
|
-
infrastructureCount: bucket.infras.length,
|
|
498
|
-
});
|
|
499
|
-
if (bucket.domainNode) {
|
|
500
|
-
const dNode = bucket.domainNode;
|
|
501
|
-
positions[dNode.id] = { x: columnCenterX, y: domainCenterY };
|
|
502
|
-
nodeBoxes[dNode.id] = {
|
|
503
|
-
id: dNode.id,
|
|
504
|
-
type: dNode.type,
|
|
505
|
-
domainId: dNode.domainId,
|
|
506
|
-
x: columnCenterX,
|
|
507
|
-
y: domainCenterY,
|
|
508
|
-
width: domainCardWidth,
|
|
509
|
-
height: domainCardHeight,
|
|
510
|
-
left: columnCenterX - domainCardWidth / 2,
|
|
511
|
-
top: domainCenterY - domainCardHeight / 2,
|
|
512
|
-
right: columnCenterX + domainCardWidth / 2,
|
|
513
|
-
bottom: domainCenterY + domainCardHeight / 2,
|
|
514
|
-
columnIndex,
|
|
515
|
-
tier: "domain",
|
|
516
|
-
paletteIndex,
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
const sceneCoords = computeCenteredGridPositions(bucket.scenes.length, sceneCols, columnCenterX, sceneStartTopY, sceneCardWidth, sceneCardHeight, cellGapX, cellGapY);
|
|
520
|
-
bucket.scenes.forEach((sNode, idx) => {
|
|
521
|
-
const pt = sceneCoords[idx];
|
|
522
|
-
positions[sNode.id] = pt;
|
|
523
|
-
nodeBoxes[sNode.id] = {
|
|
524
|
-
id: sNode.id,
|
|
525
|
-
type: sNode.type,
|
|
526
|
-
domainId: sNode.domainId,
|
|
527
|
-
x: pt.x,
|
|
528
|
-
y: pt.y,
|
|
529
|
-
width: sceneCardWidth,
|
|
530
|
-
height: sceneCardHeight,
|
|
531
|
-
left: pt.x - sceneCardWidth / 2,
|
|
532
|
-
top: pt.y - sceneCardHeight / 2,
|
|
533
|
-
right: pt.x + sceneCardWidth / 2,
|
|
534
|
-
bottom: pt.y + sceneCardHeight / 2,
|
|
535
|
-
columnIndex,
|
|
536
|
-
tier: "scene",
|
|
537
|
-
paletteIndex,
|
|
538
|
-
};
|
|
539
|
-
});
|
|
540
|
-
const infraCoords = computeCenteredGridPositions(bucket.infras.length, infraCols, columnCenterX, infraStartTopY, infraCardWidth, infraCardHeight, cellGapX, cellGapY);
|
|
541
|
-
bucket.infras.forEach((kNode, idx) => {
|
|
542
|
-
const pt = infraCoords[idx];
|
|
543
|
-
positions[kNode.id] = pt;
|
|
544
|
-
nodeBoxes[kNode.id] = {
|
|
545
|
-
id: kNode.id,
|
|
546
|
-
type: kNode.type,
|
|
547
|
-
domainId: kNode.domainId,
|
|
548
|
-
x: pt.x,
|
|
549
|
-
y: pt.y,
|
|
550
|
-
width: infraCardWidth,
|
|
551
|
-
height: infraCardHeight,
|
|
552
|
-
left: pt.x - infraCardWidth / 2,
|
|
553
|
-
top: pt.y - infraCardHeight / 2,
|
|
554
|
-
right: pt.x + infraCardWidth / 2,
|
|
555
|
-
bottom: pt.y + infraCardHeight / 2,
|
|
556
|
-
columnIndex,
|
|
557
|
-
tier: "infrastructure",
|
|
558
|
-
paletteIndex,
|
|
559
|
-
};
|
|
560
|
-
});
|
|
561
|
-
cursorLeftX += columnWidth + columnGap;
|
|
562
|
-
});
|
|
563
|
-
const tierWidth = 76;
|
|
564
|
-
const tierHeight = 28;
|
|
565
|
-
const tierCenterX = 46;
|
|
566
|
-
const sceneLabelY = sceneStartTopY + Math.min(sceneBandBottomY - sceneStartTopY, 180) / 2;
|
|
567
|
-
const infraLabelY = infraStartTopY + Math.min(infraBandBottomY - infraStartTopY, 180) / 2;
|
|
568
|
-
const tiers = [
|
|
569
|
-
{
|
|
570
|
-
id: "01",
|
|
571
|
-
label: "01 领域",
|
|
572
|
-
x: tierCenterX,
|
|
573
|
-
y: domainCenterY,
|
|
574
|
-
width: tierWidth,
|
|
575
|
-
height: tierHeight,
|
|
576
|
-
},
|
|
577
|
-
{
|
|
578
|
-
id: "02",
|
|
579
|
-
label: "02 场景",
|
|
580
|
-
x: tierCenterX,
|
|
581
|
-
y: sceneLabelY,
|
|
582
|
-
width: tierWidth,
|
|
583
|
-
height: tierHeight,
|
|
584
|
-
},
|
|
585
|
-
...(maxInfraRows > 0
|
|
586
|
-
? [
|
|
587
|
-
{
|
|
588
|
-
id: "03",
|
|
589
|
-
label: "03 知识",
|
|
590
|
-
x: tierCenterX,
|
|
591
|
-
y: infraLabelY,
|
|
592
|
-
width: tierWidth,
|
|
593
|
-
height: tierHeight,
|
|
594
|
-
},
|
|
595
|
-
]
|
|
596
|
-
: []),
|
|
597
|
-
];
|
|
598
|
-
const minX = 0;
|
|
599
|
-
const minY = columnTopY;
|
|
600
|
-
const maxX = Math.max(firstColumnLeftX, cursorLeftX - columnGap);
|
|
601
|
-
const maxY = columnBottomY;
|
|
602
|
-
return {
|
|
603
|
-
positions,
|
|
604
|
-
nodeBoxes,
|
|
605
|
-
columns,
|
|
606
|
-
tiers,
|
|
607
|
-
bounds: {
|
|
608
|
-
minX,
|
|
609
|
-
minY,
|
|
610
|
-
maxX,
|
|
611
|
-
maxY,
|
|
612
|
-
width: maxX - minX,
|
|
613
|
-
height: maxY - minY,
|
|
614
|
-
},
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Computes deterministic radial initial coordinates for Mode A (`有机布局` / Organic Layout) so
|
|
619
|
-
* Cytoscape's force-directed solver converges cleanly with shared knowledge near the core and
|
|
620
|
-
* business domains + scenes radiating around it without tangled overlap.
|
|
621
|
-
*/
|
|
622
|
-
export function computeOrganicSeedPositions(nodes) {
|
|
623
|
-
const positions = {};
|
|
624
|
-
if (nodes.length === 0) {
|
|
625
|
-
return positions;
|
|
626
|
-
}
|
|
627
|
-
const infras = nodes
|
|
628
|
-
.filter((n) => n.type === "infrastructure")
|
|
629
|
-
.slice()
|
|
630
|
-
.sort((a, b) => a.id.localeCompare(b.id));
|
|
631
|
-
const domainIds = Array.from(new Set(nodes.map((n) => n.domainId))).sort((a, b) => a.localeCompare(b));
|
|
632
|
-
// Place shared infrastructure nodes in a gentle inner spiral near (0, 0)
|
|
633
|
-
infras.forEach((node, idx) => {
|
|
634
|
-
const angle = idx * 2.399963; // golden angle
|
|
635
|
-
const radius = 55 + Math.sqrt(idx + 1) * 48;
|
|
636
|
-
positions[node.id] = {
|
|
637
|
-
x: Math.cos(angle) * radius,
|
|
638
|
-
y: Math.sin(angle) * radius,
|
|
639
|
-
};
|
|
640
|
-
});
|
|
641
|
-
// Place domains around an outer ring and fan each domain's scenes around its hub
|
|
642
|
-
const domainRingRadius = Math.max(260, 140 + Math.sqrt(nodes.length) * 45);
|
|
643
|
-
domainIds.forEach((domainId, dIdx) => {
|
|
644
|
-
const baseAngle = (2 * Math.PI * dIdx) / Math.max(1, domainIds.length) - Math.PI / 2;
|
|
645
|
-
const hubX = Math.cos(baseAngle) * domainRingRadius;
|
|
646
|
-
const hubY = Math.sin(baseAngle) * domainRingRadius;
|
|
647
|
-
const domainNode = nodes.find((n) => n.type === "domain" && n.domainId === domainId);
|
|
648
|
-
if (domainNode) {
|
|
649
|
-
positions[domainNode.id] = { x: hubX, y: hubY };
|
|
650
|
-
}
|
|
651
|
-
const domainScenes = nodes
|
|
652
|
-
.filter((n) => n.type === "scene" && n.domainId === domainId)
|
|
653
|
-
.slice()
|
|
654
|
-
.sort((a, b) => a.id.localeCompare(b.id));
|
|
655
|
-
domainScenes.forEach((scene, sIdx) => {
|
|
656
|
-
const localAngle = baseAngle + (sIdx - (domainScenes.length - 1) / 2) * 0.42 + (sIdx % 2 === 0 ? -0.08 : 0.08);
|
|
657
|
-
const localRadius = 110 + Math.floor(sIdx / 4) * 72;
|
|
658
|
-
positions[scene.id] = {
|
|
659
|
-
x: hubX + Math.cos(localAngle) * localRadius,
|
|
660
|
-
y: hubY + Math.sin(localAngle) * localRadius,
|
|
661
|
-
};
|
|
662
|
-
});
|
|
663
|
-
});
|
|
664
|
-
return positions;
|
|
665
|
-
}
|
|
1
|
+
export { computeNeighborhood, filterGraphElements, formatNodeCountIndicator, matchesHealthFilter, matchesSearchQuery, searchGraphNodes, } from "./graph-logic/filters.js";
|
|
2
|
+
export { buildNodeMarkdownEndpoint, fetchNodeMarkdownLazy, isNodeStale, parseGraphDataPayload, resolveNodeFreshness, } from "./graph-logic/graph-data.js";
|
|
3
|
+
export { computeHierarchyLayout, computeOrganicSeedPositions, DOMAIN_CARD_PALETTES, } from "./graph-logic/layout.js";
|
|
666
4
|
//# sourceMappingURL=graph-logic.js.map
|