@eventcatalog/visualiser 3.15.1 → 3.15.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/index.js +85 -74
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -74
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7533,98 +7533,109 @@ function layoutGraph(nodes, edges, options = {}, style) {
|
|
|
7533
7533
|
groupChildren.set(id, []);
|
|
7534
7534
|
}
|
|
7535
7535
|
for (const node of nodes) {
|
|
7536
|
-
if (node.parentId && allGroupIds.has(node.parentId)) {
|
|
7536
|
+
if (node.parentId && node.parentId !== node.id && allGroupIds.has(node.parentId)) {
|
|
7537
7537
|
groupChildren.get(node.parentId).push(node);
|
|
7538
7538
|
}
|
|
7539
7539
|
}
|
|
7540
7540
|
const nodeById = new Map(nodes.map((n) => [n.id, n]));
|
|
7541
7541
|
const groupSizes = /* @__PURE__ */ new Map();
|
|
7542
7542
|
const groupInternalLayouts = /* @__PURE__ */ new Map();
|
|
7543
|
+
const computing = /* @__PURE__ */ new Set();
|
|
7543
7544
|
function computeGroupSize(groupId) {
|
|
7544
7545
|
if (groupSizes.has(groupId)) return groupSizes.get(groupId);
|
|
7545
|
-
|
|
7546
|
-
if (children.length === 0) {
|
|
7546
|
+
if (computing.has(groupId)) {
|
|
7547
7547
|
const size = { width: EMPTY_GROUP_WIDTH, height: EMPTY_GROUP_HEIGHT };
|
|
7548
7548
|
groupSizes.set(groupId, size);
|
|
7549
|
-
groupInternalLayouts.set(groupId, {
|
|
7550
|
-
childPositions: /* @__PURE__ */ new Map(),
|
|
7551
|
-
width: size.width,
|
|
7552
|
-
height: size.height
|
|
7553
|
-
});
|
|
7554
7549
|
return size;
|
|
7555
7550
|
}
|
|
7556
|
-
|
|
7557
|
-
|
|
7558
|
-
|
|
7559
|
-
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
7566
|
-
ranksep: Math.max(ranksep, 100),
|
|
7567
|
-
edgesep
|
|
7568
|
-
});
|
|
7569
|
-
for (const child of children) {
|
|
7570
|
-
if (allGroupIds.has(child.id)) {
|
|
7571
|
-
const childSize = groupSizes.get(child.id);
|
|
7572
|
-
ig.setNode(child.id, {
|
|
7573
|
-
width: childSize.width,
|
|
7574
|
-
height: childSize.height
|
|
7551
|
+
computing.add(groupId);
|
|
7552
|
+
try {
|
|
7553
|
+
const children = groupChildren.get(groupId) || [];
|
|
7554
|
+
if (children.length === 0) {
|
|
7555
|
+
const size = { width: EMPTY_GROUP_WIDTH, height: EMPTY_GROUP_HEIGHT };
|
|
7556
|
+
groupSizes.set(groupId, size);
|
|
7557
|
+
groupInternalLayouts.set(groupId, {
|
|
7558
|
+
childPositions: /* @__PURE__ */ new Map(),
|
|
7559
|
+
width: size.width,
|
|
7560
|
+
height: size.height
|
|
7575
7561
|
});
|
|
7576
|
-
|
|
7577
|
-
const s = nodeSize(child.type);
|
|
7578
|
-
ig.setNode(child.id, { width: s.w, height: s.h });
|
|
7562
|
+
return size;
|
|
7579
7563
|
}
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
ig.setEdge(edge.source, edge.target);
|
|
7564
|
+
for (const child of children) {
|
|
7565
|
+
if (allGroupIds.has(child.id)) {
|
|
7566
|
+
computeGroupSize(child.id);
|
|
7567
|
+
}
|
|
7585
7568
|
}
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
const left = pos.x - pos.width / 2;
|
|
7594
|
-
const top = pos.y - pos.height / 2;
|
|
7595
|
-
const right = pos.x + pos.width / 2;
|
|
7596
|
-
const bottom = pos.y + pos.height / 2;
|
|
7597
|
-
childPositions.set(child.id, {
|
|
7598
|
-
x: left,
|
|
7599
|
-
y: top,
|
|
7600
|
-
w: pos.width,
|
|
7601
|
-
h: pos.height
|
|
7569
|
+
const ig = new import_dagre.default.graphlib.Graph();
|
|
7570
|
+
ig.setDefaultEdgeLabel(() => ({}));
|
|
7571
|
+
ig.setGraph({
|
|
7572
|
+
rankdir,
|
|
7573
|
+
nodesep: Math.max(nodesep, 80),
|
|
7574
|
+
ranksep: Math.max(ranksep, 100),
|
|
7575
|
+
edgesep
|
|
7602
7576
|
});
|
|
7603
|
-
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7577
|
+
for (const child of children) {
|
|
7578
|
+
if (allGroupIds.has(child.id)) {
|
|
7579
|
+
const childSize = groupSizes.get(child.id);
|
|
7580
|
+
ig.setNode(child.id, {
|
|
7581
|
+
width: childSize.width,
|
|
7582
|
+
height: childSize.height
|
|
7583
|
+
});
|
|
7584
|
+
} else {
|
|
7585
|
+
const s = nodeSize(child.type);
|
|
7586
|
+
ig.setNode(child.id, { width: s.w, height: s.h });
|
|
7587
|
+
}
|
|
7588
|
+
}
|
|
7589
|
+
const childIdSet = new Set(children.map((c) => c.id));
|
|
7590
|
+
for (const edge of edges) {
|
|
7591
|
+
if (childIdSet.has(edge.source) && childIdSet.has(edge.target)) {
|
|
7592
|
+
ig.setEdge(edge.source, edge.target);
|
|
7593
|
+
}
|
|
7594
|
+
}
|
|
7595
|
+
import_dagre.default.layout(ig);
|
|
7596
|
+
const childPositions = /* @__PURE__ */ new Map();
|
|
7597
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
7598
|
+
for (const child of children) {
|
|
7599
|
+
const pos = ig.node(child.id);
|
|
7600
|
+
if (!pos) continue;
|
|
7601
|
+
const left = pos.x - pos.width / 2;
|
|
7602
|
+
const top = pos.y - pos.height / 2;
|
|
7603
|
+
const right = pos.x + pos.width / 2;
|
|
7604
|
+
const bottom = pos.y + pos.height / 2;
|
|
7605
|
+
childPositions.set(child.id, {
|
|
7606
|
+
x: left,
|
|
7607
|
+
y: top,
|
|
7608
|
+
w: pos.width,
|
|
7609
|
+
h: pos.height
|
|
7610
|
+
});
|
|
7611
|
+
minX = Math.min(minX, left);
|
|
7612
|
+
minY = Math.min(minY, top);
|
|
7613
|
+
maxX = Math.max(maxX, right);
|
|
7614
|
+
maxY = Math.max(maxY, bottom);
|
|
7615
|
+
}
|
|
7616
|
+
const contentH = maxY - minY;
|
|
7617
|
+
const contentW = maxX - minX;
|
|
7618
|
+
const totalW = contentW + GROUP_PADDING_X * 2;
|
|
7619
|
+
const totalH = GROUP_HEADER_HEIGHT + GROUP_CONTENT_PADDING_TOP + contentH + GROUP_CONTENT_PADDING_BOTTOM;
|
|
7620
|
+
const contentTop = GROUP_HEADER_HEIGHT + GROUP_CONTENT_PADDING_TOP;
|
|
7621
|
+
for (const [id, pos] of childPositions) {
|
|
7622
|
+
childPositions.set(id, {
|
|
7623
|
+
x: pos.x - minX + GROUP_PADDING_X,
|
|
7624
|
+
y: pos.y - minY + contentTop,
|
|
7625
|
+
w: pos.w,
|
|
7626
|
+
h: pos.h
|
|
7627
|
+
});
|
|
7628
|
+
}
|
|
7629
|
+
groupSizes.set(groupId, { width: totalW, height: totalH });
|
|
7630
|
+
groupInternalLayouts.set(groupId, {
|
|
7631
|
+
childPositions,
|
|
7632
|
+
width: totalW,
|
|
7633
|
+
height: totalH
|
|
7619
7634
|
});
|
|
7635
|
+
return { width: totalW, height: totalH };
|
|
7636
|
+
} finally {
|
|
7637
|
+
computing.delete(groupId);
|
|
7620
7638
|
}
|
|
7621
|
-
groupSizes.set(groupId, { width: totalW, height: totalH });
|
|
7622
|
-
groupInternalLayouts.set(groupId, {
|
|
7623
|
-
childPositions,
|
|
7624
|
-
width: totalW,
|
|
7625
|
-
height: totalH
|
|
7626
|
-
});
|
|
7627
|
-
return { width: totalW, height: totalH };
|
|
7628
7639
|
}
|
|
7629
7640
|
for (const groupId of allGroupIds) {
|
|
7630
7641
|
computeGroupSize(groupId);
|