@logicflow/layout 1.2.0-alpha.16 → 2.0.0
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/.turbo/turbo-build.log +24 -0
- package/CHANGELOG.md +919 -0
- package/LICENSE +206 -0
- package/README.md +65 -2
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/es/dagre.d.ts +67 -19
- package/es/dagre.js +268 -105
- package/es/dagre.js.map +1 -0
- package/es/index.js +1 -0
- package/es/index.js.map +1 -0
- package/lib/dagre.d.ts +73 -0
- package/lib/dagre.js +406 -23
- package/lib/dagre.js.map +1 -0
- package/lib/index.js +18 -0
- package/lib/index.js.map +1 -0
- package/package.json +31 -68
- package/rollup.config.js +3 -0
- package/src/dagre.ts +443 -0
- package/src/index.ts +1 -0
- package/stats.html +4842 -0
- package/tsconfig.json +20 -0
- package/cjs/dagre.js +0 -221
- package/cjs/index.js +0 -13
- package/types/dagre.d.ts +0 -25
- /package/{types → lib}/index.d.ts +0 -0
package/lib/dagre.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dagre.js","sourceRoot":"","sources":["../src/dagre.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,6CAAmD;AA8BnD;;;GAGG;AACH;IAAA;IAiZA,CAAC;IAvYC;;;OAGG;IACH,sBAAM,GAAN,UAAO,EAAa;QAClB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;IACd,CAAC;IAED;;;OAGG;IACH,sBAAM,GAAN,UAAO,MAAwB;QAA/B,iBAsIC;QAtIM,uBAAA,EAAA,WAAwB;QACvB,IAAA,KAA6B,IAAI,CAAC,EAAE,CAAC,UAAU,EAA7C,KAAK,WAAA,EAAE,KAAK,WAAA,EAAE,QAAQ,cAAuB,CAAA;QAErD,eAAe;QACf,IAAI,OAAO,GAAG,GAAG,CAAA;QACjB,IAAI,OA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;oBACvB,UAAU,CAAC,IAAI,CAAC;wBACd,CAAC,EAAE,iBAAiB,CAAC,CAAC,GAAG,eAAe,CAAC,KAAK,GAAG,CAAC;wBAClD,CAAC,EAAE,iBAAiB,CAAC,CAAC;qBACvB,CAAC,CAAA;oBACF,UAAU,CAAC,IAAI,CAAC;wBACd,CAAC,EAAE,iBAAiB,CAAC,CAAC,GAAG,eAAe,CAAC,KAAK,GAAG,CAAC,GAAG,MAAM;wBAC3D,CAAC,EAAE,iBAAiB,CAAC,CAAC;qBACvB,CAAC,CAAA;oBACF,UAAU,CAAC,IAAI,CAAC;wBACd,CAAC,EAAE,iBAAiB,CAAC,CAAC,GAAG,eAAe,CAAC,KAAK,GAAG,CAAC,GAAG,MAAM;wBAC3D,CAAC,EAAE,iBAAiB,CAAC,CAAC;qBACvB,CAAC,CAAA;oBACF,UAAU,CAAC,IAAI,CAAC;wBACd,CAAC,EAAE,iBAAiB,CAAC,CAAC,GAAG,eAAe,CAAC,KAAK,GAAG,CAAC;wBAClD,CAAC,EAAE,iBAAiB,CAAC,CAAC;qBACvB,CAAC,CAAA;gBACJ,CAAC;gBAED,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAA;YACrC,CAAC;QACH,CAAC;QAED,oCAAoC;QACpC,OAAO,SAAS,CAAA;IAClB,CAAC;IA/YD,2BAA2B;IACpB,gBAAU,GAAG,OAAO,CAAA;IA+Y7B,YAAC;CAAA,AAjZD,IAiZC;AAjZY,sBAAK"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./dagre"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB"}
|
package/package.json
CHANGED
|
@@ -1,85 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logicflow/layout",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "LogicFlow layout",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"unpkg": "dist/index.min.js",
|
|
9
|
+
"jsdelivr": "dist/index.min.js",
|
|
10
|
+
"homepage": "https://site.logic-flow.cn",
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "https://github.com/didi/LogicFlow",
|
|
12
14
|
"directory": "packages/layout"
|
|
13
15
|
},
|
|
14
|
-
"license": "Apache-2.0",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"dev": "cross-env NODE_ENV=development webpack-dev-server --client-log-level warning --config scripts/webpack.config.dev.js",
|
|
17
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
18
|
-
"types": "tsc -d --declarationDir ./types --outDir temp && rimraf -R temp",
|
|
19
|
-
"build:esm": "tsc --module esnext --target es5 --outDir ./es -d",
|
|
20
|
-
"build:cjs": "tsc --module commonjs --target es5 --outDir ./cjs",
|
|
21
|
-
"build:umd": "cross-env NODE_ENV=production webpack --config scripts/webpack.config.build.js",
|
|
22
|
-
"build": "rimraf ./es ./cjs ./lib && npm run build:esm & npm run build:cjs & npm run build:umd",
|
|
23
|
-
"publish-lib": "npm run build && npm publish"
|
|
24
|
-
},
|
|
25
|
-
"author": "",
|
|
26
|
-
"files": [
|
|
27
|
-
"cjs",
|
|
28
|
-
"es",
|
|
29
|
-
"lib",
|
|
30
|
-
"types",
|
|
31
|
-
"readme.md"
|
|
32
|
-
],
|
|
33
|
-
"standard-version": {
|
|
34
|
-
"skip": {
|
|
35
|
-
"tag": true,
|
|
36
|
-
"commit": true
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
16
|
"keywords": [
|
|
40
|
-
"logicflow",
|
|
17
|
+
"@logicflow/layout",
|
|
18
|
+
"LogicFlow",
|
|
41
19
|
"layout",
|
|
42
20
|
"flowchart",
|
|
43
21
|
"diagram"
|
|
44
22
|
],
|
|
23
|
+
"author": "Logicflow-Team",
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"dagre": "^0.8.5",
|
|
27
|
+
"@logicflow/core": "2.1.1"
|
|
28
|
+
},
|
|
45
29
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@babel/plugin-proposal-decorators": "^7.12.1",
|
|
48
|
-
"@babel/plugin-syntax-jsx": "^7.8.3",
|
|
49
|
-
"@babel/plugin-transform-react-jsx": "^7.10.4",
|
|
50
|
-
"@babel/preset-env": "^7.9.5",
|
|
51
|
-
"@babel/preset-typescript": "^7.9.0",
|
|
52
|
-
"@commitlint/config-conventional": "^8.3.4",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^4.7.0",
|
|
54
|
-
"@typescript-eslint/parser": "^3.2.0",
|
|
55
|
-
"babel-core": "^7.0.0-bridge.0",
|
|
56
|
-
"babel-loader": "^8.1.0",
|
|
57
|
-
"babel-plugin-import": "^1.13.0",
|
|
58
|
-
"case-sensitive-paths-webpack-plugin": "^2.3.0",
|
|
59
|
-
"core-js": "^3.6.5",
|
|
60
|
-
"cross-env": "^7.0.2",
|
|
61
|
-
"css-loader": "^4.2.1",
|
|
62
|
-
"eslint": "^7.0.0",
|
|
63
|
-
"eslint-config-airbnb-typescript": "^9.0.0",
|
|
64
|
-
"eslint-plugin-import": "^2.22.0",
|
|
65
|
-
"eslint-plugin-jsx-a11y": "^6.3.1",
|
|
66
|
-
"eslint-plugin-react": "^7.20.6",
|
|
67
|
-
"eslint-plugin-standard": "^4.0.1",
|
|
68
|
-
"eslint-webpack-plugin": "^2.1.0",
|
|
69
|
-
"html-webpack-plugin": "^4.2.0",
|
|
70
|
-
"less-loader": "^6.0.0",
|
|
71
|
-
"prettier": "^2.2.1",
|
|
72
|
-
"rimraf": "^3.0.2",
|
|
73
|
-
"standard-version": "^9.0.0",
|
|
74
|
-
"style-loader": "^1.2.0",
|
|
75
|
-
"typescript": "^3.8.3",
|
|
76
|
-
"url-loader": "^4.1.0",
|
|
77
|
-
"webpack": "^4.43.0",
|
|
78
|
-
"webpack-bundle-analyzer": "^4.1.0",
|
|
79
|
-
"webpack-cli": "^3.3.11",
|
|
80
|
-
"webpack-dev-server": "^3.10.3"
|
|
30
|
+
"@types/dagre": "^0.7.53"
|
|
81
31
|
},
|
|
82
|
-
"
|
|
83
|
-
"
|
|
32
|
+
"scripts": {
|
|
33
|
+
"clean:turbo": "rss",
|
|
34
|
+
"clean:build": "rss",
|
|
35
|
+
"clean": "rss",
|
|
36
|
+
"build:less": "rss",
|
|
37
|
+
"build:esm": "tsc --module esnext --target es5 --outDir ./es",
|
|
38
|
+
"build:cjs": "tsc --module commonjs --target es5 --outDir ./lib",
|
|
39
|
+
"build:umd": "rollup -c ./rollup.config.js --bundleConfigAsCjs",
|
|
40
|
+
"build:dev": "run-p -s build:cjs build:esm",
|
|
41
|
+
"build:watch": "rss",
|
|
42
|
+
"build:watch:esm": "rss",
|
|
43
|
+
"build:watch:cjs": "rss",
|
|
44
|
+
"build": "run-p -s build:dev build:umd",
|
|
45
|
+
"prebuild": "rss",
|
|
46
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
84
47
|
}
|
|
85
|
-
}
|
|
48
|
+
}
|
package/rollup.config.js
ADDED
package/src/dagre.ts
ADDED
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Dagre布局插件 - 提供自动化图形布局功能
|
|
3
|
+
*
|
|
4
|
+
* 本插件基于dagre.js实现LogicFlow的自动化布局功能,支持多种布局方向
|
|
5
|
+
* 可自动计算节点位置和连线路径,实现整洁的图形展示
|
|
6
|
+
*/
|
|
7
|
+
import LogicFlow, { BaseNodeModel, BaseEdgeModel } from '@logicflow/core'
|
|
8
|
+
import dagre, { GraphLabel, graphlib } from 'dagre'
|
|
9
|
+
|
|
10
|
+
import NodeConfig = LogicFlow.NodeConfig
|
|
11
|
+
import EdgeConfig = LogicFlow.EdgeConfig
|
|
12
|
+
import Point = LogicFlow.Point
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Dagre布局配置选项接口
|
|
16
|
+
* @interface DagreOption
|
|
17
|
+
* @extends GraphLabel - 继承dagre原生配置
|
|
18
|
+
*/
|
|
19
|
+
export interface DagreOption extends GraphLabel {
|
|
20
|
+
/**
|
|
21
|
+
* 是否是默认锚点
|
|
22
|
+
* true: 会根据布局方向自动计算边的路径点
|
|
23
|
+
*/
|
|
24
|
+
isDefaultAnchor?: boolean
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Dagre插件接口定义
|
|
29
|
+
*/
|
|
30
|
+
export interface DagrePlugin {
|
|
31
|
+
/**
|
|
32
|
+
* 执行布局计算
|
|
33
|
+
* @param option - 布局配置选项
|
|
34
|
+
*/
|
|
35
|
+
layout(option: DagreOption): void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Dagre布局类 - LogicFlow自动布局插件
|
|
40
|
+
* 基于dagre.js提供图的自动布局能力
|
|
41
|
+
*/
|
|
42
|
+
export class Dagre {
|
|
43
|
+
/** 插件名称,用于在LogicFlow中注册 */
|
|
44
|
+
static pluginName = 'dagre'
|
|
45
|
+
|
|
46
|
+
/** LogicFlow实例引用 */
|
|
47
|
+
lf: LogicFlow
|
|
48
|
+
|
|
49
|
+
/** 当前布局配置 */
|
|
50
|
+
option: DagreOption // 使用已定义的DagreOption接口替代重复定义
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 插件初始化方法,由LogicFlow自动调用
|
|
54
|
+
* @param lf - LogicFlow实例
|
|
55
|
+
*/
|
|
56
|
+
render(lf: LogicFlow) {
|
|
57
|
+
this.lf = lf
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 执行布局算法,重新排列图中的节点和边
|
|
62
|
+
* @param option - 布局配置选项
|
|
63
|
+
*/
|
|
64
|
+
layout(option: DagreOption = {}) {
|
|
65
|
+
const { nodes, edges, gridSize } = this.lf.graphModel
|
|
66
|
+
|
|
67
|
+
// 根据网格大小调整节点间距
|
|
68
|
+
let nodesep = 100
|
|
69
|
+
let ranksep = 150
|
|
70
|
+
if (gridSize > 20) {
|
|
71
|
+
nodesep = gridSize * 2
|
|
72
|
+
ranksep = gridSize * 2
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 合并默认配置和用户配置
|
|
76
|
+
this.option = {
|
|
77
|
+
// 默认从左到右布局
|
|
78
|
+
rankdir: 'LR',
|
|
79
|
+
// 默认右下角对齐
|
|
80
|
+
align: 'UL',
|
|
81
|
+
// 紧凑树形排名算法
|
|
82
|
+
ranker: 'tight-tree',
|
|
83
|
+
// 层级间距
|
|
84
|
+
ranksep,
|
|
85
|
+
// 同层节点间距
|
|
86
|
+
nodesep,
|
|
87
|
+
// 图的水平边距
|
|
88
|
+
marginx: 120,
|
|
89
|
+
// 图的垂直边距
|
|
90
|
+
marginy: 120,
|
|
91
|
+
// 用户自定义选项覆盖默认值
|
|
92
|
+
...option,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 创建dagre图实例
|
|
96
|
+
const g = new graphlib.Graph()
|
|
97
|
+
g.setGraph(this.option)
|
|
98
|
+
g.setDefaultEdgeLabel(() => ({}))
|
|
99
|
+
|
|
100
|
+
// 将LogicFlow节点添加到dagre图中
|
|
101
|
+
nodes.forEach((node: BaseNodeModel) => {
|
|
102
|
+
g.setNode(node.id, {
|
|
103
|
+
width: node.width || 150,
|
|
104
|
+
height: node.height || 50,
|
|
105
|
+
id: node.id,
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
// 将LogicFlow边添加到dagre图中
|
|
110
|
+
edges.forEach((edge: BaseEdgeModel) => {
|
|
111
|
+
g.setEdge(edge.sourceNodeId, edge.targetNodeId, {
|
|
112
|
+
id: edge.id,
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
// 执行dagre布局算法
|
|
117
|
+
dagre.layout(g)
|
|
118
|
+
|
|
119
|
+
// 存储新的节点和边数据
|
|
120
|
+
const newNodes: NodeConfig[] = []
|
|
121
|
+
const newEdges: EdgeConfig[] = []
|
|
122
|
+
|
|
123
|
+
// 更新节点位置
|
|
124
|
+
nodes.forEach((node: BaseNodeModel) => {
|
|
125
|
+
const { x, y } = g.node(node.id)
|
|
126
|
+
const lfNode = node.getData()
|
|
127
|
+
if (!lfNode) {
|
|
128
|
+
throw new Error(`布局错误:找不到ID为 ${node.id} 的节点`)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 更新节点坐标
|
|
132
|
+
lfNode.x = x
|
|
133
|
+
lfNode.y = y
|
|
134
|
+
|
|
135
|
+
// 更新节点文本位置
|
|
136
|
+
if (lfNode?.text?.x) {
|
|
137
|
+
lfNode.text.x = x
|
|
138
|
+
lfNode.text.y = y
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
newNodes.push(lfNode)
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
// 处理边的路径和锚点
|
|
145
|
+
edges.forEach((edge: BaseEdgeModel) => {
|
|
146
|
+
const lfEdge: any = edge.getData()
|
|
147
|
+
if (!lfEdge) {
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!option.isDefaultAnchor) {
|
|
152
|
+
// 自定义锚点,不调整边的关联锚点,只清除路径相关数据,让LogicFlow自动计算
|
|
153
|
+
delete lfEdge.pointsList
|
|
154
|
+
delete lfEdge.startPoint
|
|
155
|
+
delete lfEdge.endPoint
|
|
156
|
+
} else {
|
|
157
|
+
// 默认锚点,重新计算路径以及边的起点和终点(节点默认锚点为上下左右)
|
|
158
|
+
delete lfEdge.pointsList
|
|
159
|
+
delete lfEdge.startPoint
|
|
160
|
+
delete lfEdge.endPoint
|
|
161
|
+
delete lfEdge.sourceAnchorId
|
|
162
|
+
delete lfEdge.targetAnchorId
|
|
163
|
+
|
|
164
|
+
const model = this.lf.getEdgeModelById(edge.id)
|
|
165
|
+
if (model) {
|
|
166
|
+
// 计算自定义折线路径
|
|
167
|
+
lfEdge.pointsList = this.calcPointsList(model, newNodes)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (lfEdge.pointsList) {
|
|
171
|
+
// 设置边的起点和终点
|
|
172
|
+
const first = lfEdge.pointsList[0]
|
|
173
|
+
const last = lfEdge.pointsList[lfEdge.pointsList.length - 1]
|
|
174
|
+
lfEdge.startPoint = { x: first.x, y: first.y }
|
|
175
|
+
lfEdge.endPoint = { x: last.x, y: last.y }
|
|
176
|
+
|
|
177
|
+
// 调整边标签位置
|
|
178
|
+
if (lfEdge.text && lfEdge.text.value) {
|
|
179
|
+
lfEdge.text = {
|
|
180
|
+
x: last.x - this.getBytesLength(lfEdge.text.value) * 6 - 10,
|
|
181
|
+
y: last.y,
|
|
182
|
+
value: lfEdge.text.value,
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} else if (lfEdge.text && lfEdge.text.value) {
|
|
186
|
+
// 没有自定义路径时保留文本内容
|
|
187
|
+
lfEdge.text = lfEdge.text.value
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
newEdges.push(lfEdge)
|
|
192
|
+
})
|
|
193
|
+
// 将计算好的布局数据应用到画布
|
|
194
|
+
this.lf.renderRawData({
|
|
195
|
+
nodes: newNodes,
|
|
196
|
+
edges: newEdges,
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 计算字符串显示宽度(用于文本定位)
|
|
202
|
+
* @param word - 要计算的文本
|
|
203
|
+
* @returns 估算的文本像素宽度
|
|
204
|
+
*/
|
|
205
|
+
getBytesLength(word: string): number {
|
|
206
|
+
if (!word) {
|
|
207
|
+
return 0
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
let totalLength = 0
|
|
211
|
+
for (let i = 0; i < word.length; i++) {
|
|
212
|
+
const c = word.charCodeAt(i)
|
|
213
|
+
// 大写字母宽度加权
|
|
214
|
+
if (word.match(/[A-Z]/)) {
|
|
215
|
+
totalLength += 1.5
|
|
216
|
+
}
|
|
217
|
+
// ASCII字符和半角字符
|
|
218
|
+
else if ((c >= 0x0001 && c <= 0x007e) || (c >= 0xff60 && c <= 0xff9f)) {
|
|
219
|
+
totalLength += 1
|
|
220
|
+
}
|
|
221
|
+
// 其他字符(如中文)
|
|
222
|
+
else {
|
|
223
|
+
totalLength += 2
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return totalLength
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 优化折线路径点,移除冗余点
|
|
232
|
+
* @param points - 原始路径点数组
|
|
233
|
+
* @returns 优化后的路径点数组
|
|
234
|
+
*/
|
|
235
|
+
pointFilter(points: Point[]): Point[] {
|
|
236
|
+
const allPoints = [...points] // 创建副本避免修改原始数据
|
|
237
|
+
let i = 1
|
|
238
|
+
|
|
239
|
+
// 删除直线上的中间点(保持路径简洁)
|
|
240
|
+
while (i < allPoints.length - 1) {
|
|
241
|
+
const pre = allPoints[i - 1]
|
|
242
|
+
const current = allPoints[i]
|
|
243
|
+
const next = allPoints[i + 1]
|
|
244
|
+
|
|
245
|
+
// 如果三点共线,移除中间点
|
|
246
|
+
if (
|
|
247
|
+
(pre.x === current.x && current.x === next.x) || // 垂直线上的点
|
|
248
|
+
(pre.y === current.y && current.y === next.y)
|
|
249
|
+
) {
|
|
250
|
+
// 水平线上的点
|
|
251
|
+
allPoints.splice(i, 1)
|
|
252
|
+
} else {
|
|
253
|
+
i++
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return allPoints
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 计算边的折线路径点
|
|
262
|
+
* @param model - 边模型
|
|
263
|
+
* @param nodes - 节点数据数组
|
|
264
|
+
* @returns 计算后的路径点数组,如果无法计算则返回undefined
|
|
265
|
+
*/
|
|
266
|
+
calcPointsList(
|
|
267
|
+
model: BaseEdgeModel,
|
|
268
|
+
nodes: NodeConfig[],
|
|
269
|
+
): Point[] | undefined {
|
|
270
|
+
const pointsList: Point[] = []
|
|
271
|
+
|
|
272
|
+
// 获取源节点和目标节点的模型与布局数据
|
|
273
|
+
const sourceNodeModel = this.lf.getNodeModelById(model.sourceNodeId)
|
|
274
|
+
const targetNodeModel = this.lf.getNodeModelById(model.targetNodeId)
|
|
275
|
+
const newSourceNodeData = nodes.find(
|
|
276
|
+
(node: NodeConfig) => node.id === model.sourceNodeId,
|
|
277
|
+
)
|
|
278
|
+
const newTargetNodeData = nodes.find(
|
|
279
|
+
(node: NodeConfig) => node.id === model.targetNodeId,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
// 数据验证
|
|
283
|
+
if (
|
|
284
|
+
!sourceNodeModel ||
|
|
285
|
+
!targetNodeModel ||
|
|
286
|
+
!newSourceNodeData ||
|
|
287
|
+
!newTargetNodeData
|
|
288
|
+
) {
|
|
289
|
+
return undefined
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// 折线偏移量(用于创建合适的转折点)
|
|
293
|
+
const offset = Number(model.offset) || 50
|
|
294
|
+
|
|
295
|
+
// 处理从左到右(LR)布局的边路径
|
|
296
|
+
if (this.option.rankdir === 'LR' && model.modelType === 'polyline-edge') {
|
|
297
|
+
// 正向连线:源节点在目标节点左侧
|
|
298
|
+
if (newSourceNodeData.x < newTargetNodeData.x) {
|
|
299
|
+
// 从源节点右侧中心出发
|
|
300
|
+
pointsList.push({
|
|
301
|
+
x: newSourceNodeData.x + sourceNodeModel.width / 2,
|
|
302
|
+
y: newSourceNodeData.y,
|
|
303
|
+
})
|
|
304
|
+
// 向右延伸一段距离
|
|
305
|
+
pointsList.push({
|
|
306
|
+
x: newSourceNodeData.x + sourceNodeModel.width / 2 + offset,
|
|
307
|
+
y: newSourceNodeData.y,
|
|
308
|
+
})
|
|
309
|
+
// 垂直移动到目标节点的高度
|
|
310
|
+
pointsList.push({
|
|
311
|
+
x: newSourceNodeData.x + sourceNodeModel.width / 2 + offset,
|
|
312
|
+
y: newTargetNodeData.y,
|
|
313
|
+
})
|
|
314
|
+
// 连接到目标节点左侧中心
|
|
315
|
+
pointsList.push({
|
|
316
|
+
x: newTargetNodeData.x - targetNodeModel.width / 2,
|
|
317
|
+
y: newTargetNodeData.y,
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
return this.pointFilter(pointsList)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 反向连线:源节点在目标节点右侧
|
|
324
|
+
if (newSourceNodeData.x > newTargetNodeData.x) {
|
|
325
|
+
// 根据节点相对Y轴位置选择不同路径
|
|
326
|
+
if (newSourceNodeData.y >= newTargetNodeData.y) {
|
|
327
|
+
// 源节点在目标节点的右下方,从源节点上方出发
|
|
328
|
+
pointsList.push({
|
|
329
|
+
x: newSourceNodeData.x,
|
|
330
|
+
y: newSourceNodeData.y + sourceNodeModel.height / 2,
|
|
331
|
+
})
|
|
332
|
+
pointsList.push({
|
|
333
|
+
x: newSourceNodeData.x,
|
|
334
|
+
y: newSourceNodeData.y + sourceNodeModel.height / 2 + offset,
|
|
335
|
+
})
|
|
336
|
+
pointsList.push({
|
|
337
|
+
x: newTargetNodeData.x,
|
|
338
|
+
y: newSourceNodeData.y + sourceNodeModel.height / 2 + offset,
|
|
339
|
+
})
|
|
340
|
+
pointsList.push({
|
|
341
|
+
x: newTargetNodeData.x,
|
|
342
|
+
y: newTargetNodeData.y + targetNodeModel.height / 2,
|
|
343
|
+
})
|
|
344
|
+
} else {
|
|
345
|
+
// 源节点在目标节点的右上方,从源节点下方出发
|
|
346
|
+
pointsList.push({
|
|
347
|
+
x: newSourceNodeData.x,
|
|
348
|
+
y: newSourceNodeData.y - sourceNodeModel.height / 2,
|
|
349
|
+
})
|
|
350
|
+
pointsList.push({
|
|
351
|
+
x: newSourceNodeData.x,
|
|
352
|
+
y: newSourceNodeData.y - sourceNodeModel.height / 2 - offset,
|
|
353
|
+
})
|
|
354
|
+
pointsList.push({
|
|
355
|
+
x: newTargetNodeData.x,
|
|
356
|
+
y: newSourceNodeData.y - sourceNodeModel.height / 2 - offset,
|
|
357
|
+
})
|
|
358
|
+
pointsList.push({
|
|
359
|
+
x: newTargetNodeData.x,
|
|
360
|
+
y: newTargetNodeData.y - targetNodeModel.height / 2,
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return this.pointFilter(pointsList)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// 处理从上到下(TB)布局的边路径
|
|
369
|
+
if (this.option.rankdir === 'TB' && model.modelType === 'polyline-edge') {
|
|
370
|
+
// 正向连线:源节点在目标节点上方
|
|
371
|
+
if (newSourceNodeData.y < newTargetNodeData.y) {
|
|
372
|
+
// 从源节点底部中心出发
|
|
373
|
+
pointsList.push({
|
|
374
|
+
x: newSourceNodeData.x,
|
|
375
|
+
y: newSourceNodeData.y + sourceNodeModel.height / 2,
|
|
376
|
+
})
|
|
377
|
+
// 向下延伸一段距离
|
|
378
|
+
pointsList.push({
|
|
379
|
+
x: newSourceNodeData.x,
|
|
380
|
+
y: newSourceNodeData.y + sourceNodeModel.height / 2 + offset,
|
|
381
|
+
})
|
|
382
|
+
// 水平移动到目标节点的位置
|
|
383
|
+
pointsList.push({
|
|
384
|
+
x: newTargetNodeData.x,
|
|
385
|
+
y: newSourceNodeData.y + sourceNodeModel.height / 2 + offset,
|
|
386
|
+
})
|
|
387
|
+
// 连接到目标节点顶部中心
|
|
388
|
+
pointsList.push({
|
|
389
|
+
x: newTargetNodeData.x,
|
|
390
|
+
y: newTargetNodeData.y - targetNodeModel.height / 2,
|
|
391
|
+
})
|
|
392
|
+
|
|
393
|
+
return this.pointFilter(pointsList)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// 反向连线:源节点在目标节点下方
|
|
397
|
+
if (newSourceNodeData.y > newTargetNodeData.y) {
|
|
398
|
+
if (newSourceNodeData.x >= newTargetNodeData.x) {
|
|
399
|
+
// 源节点在目标节点右下方,从源节点右侧出发
|
|
400
|
+
pointsList.push({
|
|
401
|
+
x: newSourceNodeData.x + sourceNodeModel.width / 2,
|
|
402
|
+
y: newSourceNodeData.y,
|
|
403
|
+
})
|
|
404
|
+
pointsList.push({
|
|
405
|
+
x: newSourceNodeData.x + sourceNodeModel.width / 2 + offset,
|
|
406
|
+
y: newSourceNodeData.y,
|
|
407
|
+
})
|
|
408
|
+
pointsList.push({
|
|
409
|
+
x: newSourceNodeData.x + sourceNodeModel.width / 2 + offset,
|
|
410
|
+
y: newTargetNodeData.y,
|
|
411
|
+
})
|
|
412
|
+
pointsList.push({
|
|
413
|
+
x: newTargetNodeData.x + targetNodeModel.width / 2,
|
|
414
|
+
y: newTargetNodeData.y,
|
|
415
|
+
})
|
|
416
|
+
} else {
|
|
417
|
+
// 源节点在目标节点左下方,从源节点左侧出发
|
|
418
|
+
pointsList.push({
|
|
419
|
+
x: newSourceNodeData.x - sourceNodeModel.width / 2,
|
|
420
|
+
y: newSourceNodeData.y,
|
|
421
|
+
})
|
|
422
|
+
pointsList.push({
|
|
423
|
+
x: newSourceNodeData.x - sourceNodeModel.width / 2 - offset,
|
|
424
|
+
y: newSourceNodeData.y,
|
|
425
|
+
})
|
|
426
|
+
pointsList.push({
|
|
427
|
+
x: newSourceNodeData.x - sourceNodeModel.width / 2 - offset,
|
|
428
|
+
y: newTargetNodeData.y,
|
|
429
|
+
})
|
|
430
|
+
pointsList.push({
|
|
431
|
+
x: newTargetNodeData.x - targetNodeModel.width / 2,
|
|
432
|
+
y: newTargetNodeData.y,
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
return this.pointFilter(pointsList)
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// 无法确定路径时返回undefined,让LogicFlow自行处理
|
|
441
|
+
return undefined
|
|
442
|
+
}
|
|
443
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dagre'
|