feat(auto-layout): sort same from port nodes using y-axis coordinate (#375)

This commit is contained in:
Louis Young 2025-06-13 19:06:26 +08:00 committed by GitHub
parent 39734e5a02
commit b6433f7b99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,7 +25,10 @@ export class LayoutStore {
return this.init; return this.init;
} }
public getNode(id: string): LayoutNode | undefined { public getNode(id?: string): LayoutNode | undefined {
if (!id) {
return undefined;
}
return this.store.nodes.get(id); return this.store.nodes.get(id);
} }
@ -235,8 +238,15 @@ export class LayoutStore {
// 访问后续节点 // 访问后续节点
const { outputLines } = node.getData(WorkflowNodeLinesData); const { outputLines } = node.getData(WorkflowNodeLinesData);
const sortedLines = outputLines.sort((a, b) => { const sortedLines = outputLines.sort((a, b) => {
const aNode = this.getNode(a.to?.id);
const bNode = this.getNode(b.to?.id);
const aPort = a.fromPort; const aPort = a.fromPort;
const bPort = b.fromPort; const bPort = b.fromPort;
// 同端口对比to节点y轴坐标
if (aPort === bPort && aNode && bNode) {
return aNode.position.y - bNode.position.y;
}
// 同from节点的不同端口对比端口y轴坐标
if (aPort && bPort) { if (aPort && bPort) {
return aPort.point.y - bPort.point.y; return aPort.point.y - bPort.point.y;
} }