@aranzatech/diagrams-bpmn 0.3.3 → 0.3.4
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/layout/index.cjs +29 -2
- package/dist/layout/index.cjs.map +1 -1
- package/dist/layout/index.js +29 -2
- package/dist/layout/index.js.map +1 -1
- package/package.json +1 -1
package/dist/layout/index.js
CHANGED
|
@@ -629,6 +629,33 @@ function nodeRect(node, byId, cache) {
|
|
|
629
629
|
function rectContainsRect(outer, inner) {
|
|
630
630
|
return inner.x >= outer.x && inner.y >= outer.y && inner.x + inner.width <= outer.x + outer.width && inner.y + inner.height <= outer.y + outer.height;
|
|
631
631
|
}
|
|
632
|
+
function sortNodesParentFirst(nodes) {
|
|
633
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
634
|
+
const memo = /* @__PURE__ */ new Map();
|
|
635
|
+
const depthOf = (node) => {
|
|
636
|
+
const cached = memo.get(node.id);
|
|
637
|
+
if (cached != null) return cached;
|
|
638
|
+
if (!node.parentId) {
|
|
639
|
+
memo.set(node.id, 0);
|
|
640
|
+
return 0;
|
|
641
|
+
}
|
|
642
|
+
const parent = byId.get(node.parentId);
|
|
643
|
+
const depth = parent ? depthOf(parent) + 1 : 0;
|
|
644
|
+
memo.set(node.id, depth);
|
|
645
|
+
return depth;
|
|
646
|
+
};
|
|
647
|
+
return [...nodes].sort((a, b) => {
|
|
648
|
+
const depthDiff = depthOf(a) - depthOf(b);
|
|
649
|
+
if (depthDiff !== 0) return depthDiff;
|
|
650
|
+
const ay = a.position?.y ?? 0;
|
|
651
|
+
const by = b.position?.y ?? 0;
|
|
652
|
+
if (ay !== by) return ay - by;
|
|
653
|
+
const ax = a.position?.x ?? 0;
|
|
654
|
+
const bx = b.position?.x ?? 0;
|
|
655
|
+
if (ax !== bx) return ax - bx;
|
|
656
|
+
return a.id.localeCompare(b.id);
|
|
657
|
+
});
|
|
658
|
+
}
|
|
632
659
|
function gapMidX(sAbs, sW, tAbs, tW) {
|
|
633
660
|
const leftRightEdge = Math.min(sAbs.x + sW, tAbs.x + tW);
|
|
634
661
|
const rightLeftEdge = Math.max(sAbs.x, tAbs.x);
|
|
@@ -902,7 +929,7 @@ async function bpmnCustomLayout(nodes, edges) {
|
|
|
902
929
|
const { bpmnElkLayout: bpmnElkLayout2 } = await import('../elk-QT7H4252.js');
|
|
903
930
|
const elkResult = await bpmnElkLayout2(nodes.filter((n) => !LAYOUT_ARTIFACT_TYPES.has(n.data.elementType)), edges);
|
|
904
931
|
const posArtifacts = positionArtifacts(artifacts, elkResult.nodes, edges, nodes);
|
|
905
|
-
return { nodes: [...elkResult.nodes, ...posArtifacts], edges: elkResult.edges };
|
|
932
|
+
return { nodes: sortNodesParentFirst([...elkResult.nodes, ...posArtifacts]), edges: elkResult.edges };
|
|
906
933
|
}
|
|
907
934
|
const poolIds = new Set(pools.map((p) => p.id));
|
|
908
935
|
const allLaneIds = new Set(lanes.map((l) => l.id));
|
|
@@ -973,7 +1000,7 @@ async function bpmnCustomLayout(nodes, edges) {
|
|
|
973
1000
|
const routedEdges = routeEdges(edges, resultNodes, allBackEdgeIds, allLaneIds, poolIds);
|
|
974
1001
|
const positionedArtifacts = positionArtifacts(artifacts, resultNodes, edges, nodes);
|
|
975
1002
|
return {
|
|
976
|
-
nodes: [...resultNodes, ...positionedArtifacts],
|
|
1003
|
+
nodes: sortNodesParentFirst([...resultNodes, ...positionedArtifacts]),
|
|
977
1004
|
edges: routedEdges
|
|
978
1005
|
};
|
|
979
1006
|
}
|