Skip to content

Commit f87491e

Browse files
committed
🐛 修复tab和反斜杠生成树结构时,空隙部分越来越大的bug
1 parent 9c07b2c commit f87491e

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

app/src/core/service/controlService/autoLayoutEngine/autoLayoutFastTreeMode.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
/**
2-
* 瞬间树形布局算法
3-
* 瞬间:一次性直接移动所有节点到合适的位置
4-
* 树形:此布局算法仅限于树形结构,在代码上游保证
5-
*/
6-
71
import { Rectangle } from "../../../dataStruct/shape/Rectangle";
82
import { Vector } from "../../../dataStruct/Vector";
93
import { GraphMethods } from "../../../stage/stageManager/basicMethods/GraphMethods";
104
import { StageEntityMoveManager } from "../../../stage/stageManager/concreteMethods/StageEntityMoveManager";
115
import { StageManager } from "../../../stage/stageManager/StageManager";
126
import { ConnectableEntity } from "../../../stage/stageObject/abstract/ConnectableEntity";
7+
8+
/**
9+
* 瞬间树形布局算法
10+
* 瞬间:一次性直接移动所有节点到合适的位置
11+
* 树形:此布局算法仅限于树形结构,在代码上游保证
12+
*/
1313
export namespace AutoLayoutFastTree {
1414
/**
15-
* 树形节点的根节点
16-
* @param rootNode
15+
* 向下树形布局
16+
* @param rootNode 树形节点的根节点
1717
*/
1818
export function autoLayoutFastTreeModeDown(rootNode: ConnectableEntity) {
1919
const dfs = (node: ConnectableEntity) => {
@@ -43,6 +43,7 @@ export namespace AutoLayoutFastTree {
4343
};
4444
dfs(rootNode);
4545
}
46+
4647
/**
4748
* 获取当前树的外接矩形,注意不要有环,有环就废了
4849
* @param node
@@ -105,10 +106,14 @@ export namespace AutoLayoutFastTree {
105106
* @param rootNode
106107
*/
107108
export function autoLayoutFastTreeModeRight(rootNode: ConnectableEntity) {
109+
// 树形结构的根节点 左上角位置固定不动
108110
const initLocation = rootNode.collisionBox.getRectangle().leftTop.clone();
109111

110112
const dfs = (node: ConnectableEntity) => {
111-
const childList = GraphMethods.nodeChildrenArray(node);
113+
// 按照从上到下的顺序排序
114+
const childList = GraphMethods.nodeChildrenArray(node).sort(
115+
(a, b) => a.collisionBox.getRectangle().top - b.collisionBox.getRectangle().top,
116+
);
112117
for (const child of childList) {
113118
dfs(child); // 递归口
114119
}
@@ -126,6 +131,9 @@ export namespace AutoLayoutFastTree {
126131
rootNode.isSelected = true;
127132
StageEntityMoveManager.moveConnectableEntitiesWithChildren(delta);
128133
}
134+
135+
// ======================= 反转树的位置系列 ====================
136+
129137
export function treeReverseX(selectedRootEntity: ConnectableEntity) {
130138
treeReverse(selectedRootEntity, "X");
131139
}

0 commit comments

Comments
 (0)