@statelyai/flow 0.6.0 → 0.8.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/README.md +234 -140
- package/dist/esm/index.d.ts +150 -32
- package/dist/esm/index.js +3638 -3132
- package/dist/esm/layout/dagre.js +1 -1
- package/dist/esm/layout/elk.js +637 -25
- package/dist/esm/shared.js +29 -5
- package/package.json +1 -1
package/dist/esm/shared.js
CHANGED
|
@@ -60,7 +60,7 @@ function throwIfAborted(options) {
|
|
|
60
60
|
error.name = "AbortError";
|
|
61
61
|
throw error;
|
|
62
62
|
}
|
|
63
|
-
function edgeLabelPositionsFromNodePositions(graph, positions, getBounds) {
|
|
63
|
+
function edgeLabelPositionsFromNodePositions(graph, positions, getBounds, laidOutBounds, direction = graph.direction ?? "down") {
|
|
64
64
|
const labels = /* @__PURE__ */ new Map();
|
|
65
65
|
const nodes = new Map(graph.nodes.map((node) => [node.id, node]));
|
|
66
66
|
for (const edge of graph.edges) {
|
|
@@ -68,13 +68,37 @@ function edgeLabelPositionsFromNodePositions(graph, positions, getBounds) {
|
|
|
68
68
|
const source = nodes.get(edge.sourceId);
|
|
69
69
|
const target = nodes.get(edge.targetId);
|
|
70
70
|
if (!source || !target) continue;
|
|
71
|
-
const sourceBounds = boundsOf(source, getBounds);
|
|
72
|
-
const targetBounds = boundsOf(target, getBounds);
|
|
71
|
+
const sourceBounds = laidOutBounds?.get(source.id) ?? boundsOf(source, getBounds);
|
|
72
|
+
const targetBounds = laidOutBounds?.get(target.id) ?? boundsOf(target, getBounds);
|
|
73
73
|
const sourcePosition = positions.get(source.id) ?? sourceBounds;
|
|
74
74
|
const targetPosition = positions.get(target.id) ?? targetBounds;
|
|
75
|
+
const sourceRect = {
|
|
76
|
+
...sourceBounds,
|
|
77
|
+
...sourcePosition
|
|
78
|
+
};
|
|
79
|
+
const targetRect = {
|
|
80
|
+
...targetBounds,
|
|
81
|
+
...targetPosition
|
|
82
|
+
};
|
|
83
|
+
const horizontal = direction === "left" || direction === "right";
|
|
84
|
+
const sourceCenter = {
|
|
85
|
+
x: sourceRect.x + sourceRect.width / 2,
|
|
86
|
+
y: sourceRect.y + sourceRect.height / 2
|
|
87
|
+
};
|
|
88
|
+
const targetCenter = {
|
|
89
|
+
x: targetRect.x + targetRect.width / 2,
|
|
90
|
+
y: targetRect.y + targetRect.height / 2
|
|
91
|
+
};
|
|
92
|
+
const gapCenter = horizontal ? {
|
|
93
|
+
x: direction === "left" ? (targetRect.x + targetRect.width + sourceRect.x) / 2 : (sourceRect.x + sourceRect.width + targetRect.x) / 2,
|
|
94
|
+
y: (sourceCenter.y + targetCenter.y) / 2
|
|
95
|
+
} : {
|
|
96
|
+
x: (sourceCenter.x + targetCenter.x) / 2,
|
|
97
|
+
y: direction === "up" ? (targetRect.y + targetRect.height + sourceRect.y) / 2 : (sourceRect.y + sourceRect.height + targetRect.y) / 2
|
|
98
|
+
};
|
|
75
99
|
labels.set(edge.id, {
|
|
76
|
-
x:
|
|
77
|
-
y:
|
|
100
|
+
x: gapCenter.x - edge.label.width / 2,
|
|
101
|
+
y: gapCenter.y - edge.label.height / 2
|
|
78
102
|
});
|
|
79
103
|
}
|
|
80
104
|
return labels.size > 0 ? labels : void 0;
|