lw-cdp-ui 1.1.65 → 1.1.67
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/components/lwFlow/config/dagre.js +69 -29
- package/dist/components/lwFlow/index.vue +2 -2
- package/dist/lw-cdp-ui.esm.js +277 -265
- package/dist/lw-cdp-ui.umd.js +5 -5
- package/dist/style.css +1 -1
- package/package.json +3 -3
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import dagre from 'dagre';
|
|
2
2
|
|
|
3
3
|
export default class Dagre {
|
|
4
4
|
static pluginName = 'dagre';
|
|
5
5
|
lf;
|
|
6
6
|
option;
|
|
7
|
+
|
|
7
8
|
render(lf) {
|
|
8
9
|
this.lf = lf;
|
|
9
10
|
}
|
|
11
|
+
|
|
10
12
|
getBytesLength(word) {
|
|
11
13
|
if (!word) {
|
|
12
14
|
return 0;
|
|
@@ -14,7 +16,7 @@ export default class Dagre {
|
|
|
14
16
|
let totalLength = 0;
|
|
15
17
|
for (let i = 0; i < word.length; i++) {
|
|
16
18
|
const c = word.charCodeAt(i);
|
|
17
|
-
if (
|
|
19
|
+
if (word.match(/[A-Z]/)) {
|
|
18
20
|
totalLength += 1.5;
|
|
19
21
|
} else if ((c >= 0x0001 && c <= 0x007e) || (c >= 0xff60 && c <= 0xff9f)) {
|
|
20
22
|
totalLength += 1;
|
|
@@ -24,40 +26,27 @@ export default class Dagre {
|
|
|
24
26
|
}
|
|
25
27
|
return totalLength;
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
* option: {
|
|
29
|
-
* rankdir: "TB", // layout 方向, 可选 TB, BT, LR, RL
|
|
30
|
-
* align: undefined, // 节点对齐方式,可选 UL, UR, DL, DR
|
|
31
|
-
* nodeSize: undefined, // 节点大小
|
|
32
|
-
* nodesepFunc: undefined, // 节点水平间距(px)
|
|
33
|
-
* ranksepFunc: undefined, // 每一层节点之间间距
|
|
34
|
-
* nodesep: 40, // 节点水平间距(px) 注意:如果有grid,需要保证nodesep为grid的偶数倍
|
|
35
|
-
* ranksep: 40, // 每一层节点之间间距 注意:如果有grid,需要保证ranksep为grid的偶数倍
|
|
36
|
-
* controlPoints: false, // 是否保留布局连线的控制点
|
|
37
|
-
* radial: false, // 是否基于 dagre 进行辐射布局
|
|
38
|
-
* focusNode: null, // radial 为 true 时生效,关注的节点
|
|
39
|
-
* };
|
|
40
|
-
*/
|
|
29
|
+
|
|
41
30
|
layout(option = {}) {
|
|
42
31
|
const { nodes, edges, gridSize } = this.lf.graphModel;
|
|
43
|
-
|
|
32
|
+
|
|
44
33
|
let nodesep = 40;
|
|
45
34
|
let ranksep = 40;
|
|
46
35
|
if (gridSize > 20) {
|
|
47
36
|
nodesep = gridSize * 2;
|
|
48
37
|
ranksep = gridSize * 2;
|
|
49
38
|
}
|
|
39
|
+
|
|
50
40
|
this.option = {
|
|
51
41
|
type: 'dagre',
|
|
52
42
|
rankdir: 'LR',
|
|
53
|
-
// align: 'UL',
|
|
54
|
-
// align: 'UR',
|
|
55
43
|
align: 'DR',
|
|
56
44
|
nodesep,
|
|
57
45
|
ranksep,
|
|
58
46
|
begin: [120, 120],
|
|
59
47
|
...option,
|
|
60
48
|
};
|
|
49
|
+
|
|
61
50
|
const layoutInstance = new DagreLayout(this.option);
|
|
62
51
|
const layoutData = layoutInstance.layout({
|
|
63
52
|
nodes: nodes.map((node) => ({
|
|
@@ -74,22 +63,21 @@ export default class Dagre {
|
|
|
74
63
|
model: edge,
|
|
75
64
|
})),
|
|
76
65
|
});
|
|
66
|
+
|
|
77
67
|
const newGraphData = {
|
|
78
68
|
nodes: [],
|
|
79
69
|
edges: [],
|
|
80
70
|
};
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
|
|
72
|
+
layoutData?.nodes.forEach(node => {
|
|
83
73
|
const { model } = node;
|
|
84
74
|
const data = model.getData();
|
|
85
|
-
// @ts-ignore: pass node data
|
|
86
75
|
data.x = node.x;
|
|
87
|
-
// @ts-ignore: pass node data
|
|
88
76
|
data.y = node.y;
|
|
89
77
|
newGraphData.nodes.push(data);
|
|
90
78
|
});
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
|
|
80
|
+
layoutData?.edges.forEach(edge => {
|
|
93
81
|
const { model } = edge;
|
|
94
82
|
const data = model.getData();
|
|
95
83
|
data.pointsList = this.calcPointsList(model, newGraphData.nodes);
|
|
@@ -114,8 +102,10 @@ export default class Dagre {
|
|
|
114
102
|
}
|
|
115
103
|
newGraphData.edges.push(data);
|
|
116
104
|
});
|
|
105
|
+
|
|
117
106
|
this.lf.render(newGraphData);
|
|
118
107
|
}
|
|
108
|
+
|
|
119
109
|
pointFilter(points) {
|
|
120
110
|
const allPoints = points;
|
|
121
111
|
let i = 1;
|
|
@@ -132,9 +122,8 @@ export default class Dagre {
|
|
|
132
122
|
}
|
|
133
123
|
return allPoints;
|
|
134
124
|
}
|
|
125
|
+
|
|
135
126
|
calcPointsList(model, nodes) {
|
|
136
|
-
// 在节点确认从左向右后,通过计算来保证节点连线清晰。
|
|
137
|
-
// TODO: 避障
|
|
138
127
|
const pointsList = [];
|
|
139
128
|
if (this.option.rankdir === 'LR' && model.modelType === 'polyline-edge') {
|
|
140
129
|
const sourceNodeModel = this.lf.getNodeModelById(model.sourceNodeId);
|
|
@@ -160,7 +149,6 @@ export default class Dagre {
|
|
|
160
149
|
});
|
|
161
150
|
return this.pointFilter(pointsList);
|
|
162
151
|
}
|
|
163
|
-
// 向回连线
|
|
164
152
|
if (newSourceNodeData.x > newTargetNodeData.x) {
|
|
165
153
|
if (newSourceNodeData.y >= newTargetNodeData.y) {
|
|
166
154
|
pointsList.push({
|
|
@@ -202,4 +190,56 @@ export default class Dagre {
|
|
|
202
190
|
}
|
|
203
191
|
return undefined;
|
|
204
192
|
}
|
|
205
|
-
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
class DagreLayout {
|
|
196
|
+
constructor(options) {
|
|
197
|
+
this.options = {
|
|
198
|
+
rankdir: 'TB',
|
|
199
|
+
align: null,
|
|
200
|
+
nodesep: 50,
|
|
201
|
+
ranksep: 50,
|
|
202
|
+
controlPoints: false,
|
|
203
|
+
...options,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
layout(data) {
|
|
208
|
+
const { nodes, edges } = data;
|
|
209
|
+
if (!nodes || nodes.length === 0) return;
|
|
210
|
+
|
|
211
|
+
const g = new dagre.graphlib.Graph({ multigraph: true });
|
|
212
|
+
g.setGraph({});
|
|
213
|
+
g.setDefaultEdgeLabel(() => ({}));
|
|
214
|
+
|
|
215
|
+
g.graph().rankdir = this.options.rankdir;
|
|
216
|
+
g.graph().align = this.options.align;
|
|
217
|
+
g.graph().nodesep = this.options.nodesep;
|
|
218
|
+
g.graph().ranksep = this.options.ranksep;
|
|
219
|
+
|
|
220
|
+
nodes.forEach((node) => {
|
|
221
|
+
g.setNode(node.id, { width: node.width || 50, height: node.height || 50 });
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
edges.forEach((edge) => {
|
|
225
|
+
g.setEdge(edge.source, edge.target);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
dagre.layout(g);
|
|
229
|
+
|
|
230
|
+
nodes.forEach((node) => {
|
|
231
|
+
const coord = g.node(node.id);
|
|
232
|
+
node.x = coord.x;
|
|
233
|
+
node.y = coord.y;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
if (this.options.controlPoints) {
|
|
237
|
+
edges.forEach((edge) => {
|
|
238
|
+
const edgeData = g.edge(edge.source, edge.target);
|
|
239
|
+
edge.controlPoints = edgeData.points;
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return { nodes, edges };
|
|
244
|
+
}
|
|
245
|
+
}
|