@rxflow/bloodline 0.0.1-alpha.0 → 0.0.1-alpha.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/cjs/utils/layoutCells.d.ts +1 -1
- package/cjs/utils/layoutCells.d.ts.map +1 -1
- package/cjs/utils/layoutCells.js +3 -6
- package/esm/utils/layoutCells.d.ts +1 -1
- package/esm/utils/layoutCells.d.ts.map +1 -1
- package/esm/utils/layoutCells.js +3 -6
- package/package.json +2 -2
- package/cjs/utils/_layoutCells.d.ts +0 -14
- package/cjs/utils/_layoutCells.d.ts.map +0 -1
- package/cjs/utils/_layoutCells.js +0 -483
- package/esm/utils/_layoutCells.d.ts +0 -14
- package/esm/utils/_layoutCells.d.ts.map +0 -1
- package/esm/utils/_layoutCells.js +0 -477
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
7
7
|
*/
|
|
8
|
-
import { Edge, Node } from "@xyflow/react";
|
|
9
8
|
import { LayoutConfig } from "@rxflow/base";
|
|
9
|
+
import { Edge, Node } from "@xyflow/react";
|
|
10
10
|
export declare const layoutCells: <NodeType extends Node = Node, EdgeType extends Edge = Edge>(config: LayoutConfig<NodeType, EdgeType>) => {
|
|
11
11
|
nodes: NodeType[];
|
|
12
12
|
edges: EdgeType[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layoutCells.d.ts","sourceRoot":"","sources":["layoutCells.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"layoutCells.d.ts","sourceRoot":"","sources":["layoutCells.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAA8B,YAAY,EAAgB,MAAM,cAAc,CAAC;AAEtF,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,MAAM,eAAe,CAAC;AAmGzC,eAAO,MAAM,WAAW,uEACd,aAAa,QAAQ,EAAE,QAAQ,CAAC;;;CA2LzC,CAAA"}
|
package/cjs/utils/layoutCells.js
CHANGED
|
@@ -247,7 +247,7 @@ const layoutCells = config => {
|
|
|
247
247
|
const childrenNodes = getChildrenNodes(data);
|
|
248
248
|
|
|
249
249
|
// 如果已经存在的,则使用上下节点进行标记。解决直线回连显示问题
|
|
250
|
-
|
|
250
|
+
|
|
251
251
|
childrenNodes.forEach(child => {
|
|
252
252
|
const side = child[_constants.sideSymbol] || 'right';
|
|
253
253
|
const {
|
|
@@ -265,18 +265,15 @@ const layoutCells = config => {
|
|
|
265
265
|
|
|
266
266
|
const sourceHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.downstream, sourceHandleNode);
|
|
267
267
|
const targetHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.upstream, targetHandleNode);
|
|
268
|
-
// if(edgeIndex === 1){
|
|
269
268
|
edges.push({
|
|
270
269
|
id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
271
|
-
type: '
|
|
270
|
+
type: 'smoothstep',
|
|
272
271
|
source: sourceNode,
|
|
273
272
|
target: targetNode,
|
|
274
273
|
sourceHandle: sourceHandle,
|
|
275
274
|
// 可能链接其中某个版本
|
|
276
275
|
targetHandle: targetHandle
|
|
277
276
|
});
|
|
278
|
-
// }
|
|
279
|
-
edgeIndex++;
|
|
280
277
|
} else {
|
|
281
278
|
innerNodes.forEach(innerNode => {
|
|
282
279
|
const sourceNode = side === 'left' ? childId : id; // 上游节点
|
|
@@ -289,7 +286,7 @@ const layoutCells = config => {
|
|
|
289
286
|
const targetHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.upstream, targetHandleNode);
|
|
290
287
|
edges.push({
|
|
291
288
|
id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
292
|
-
type: '
|
|
289
|
+
type: 'smoothstep',
|
|
293
290
|
source: sourceNode,
|
|
294
291
|
target: targetNode,
|
|
295
292
|
sourceHandle: sourceHandle,
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
7
7
|
*/
|
|
8
|
-
import { Edge, Node } from "@xyflow/react";
|
|
9
8
|
import { LayoutConfig } from "@rxflow/base";
|
|
9
|
+
import { Edge, Node } from "@xyflow/react";
|
|
10
10
|
export declare const layoutCells: <NodeType extends Node = Node, EdgeType extends Edge = Edge>(config: LayoutConfig<NodeType, EdgeType>) => {
|
|
11
11
|
nodes: NodeType[];
|
|
12
12
|
edges: EdgeType[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layoutCells.d.ts","sourceRoot":"","sources":["layoutCells.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"layoutCells.d.ts","sourceRoot":"","sources":["layoutCells.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAA8B,YAAY,EAAgB,MAAM,cAAc,CAAC;AAEtF,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,MAAM,eAAe,CAAC;AAmGzC,eAAO,MAAM,WAAW,uEACd,aAAa,QAAQ,EAAE,QAAQ,CAAC;;;CA2LzC,CAAA"}
|
package/esm/utils/layoutCells.js
CHANGED
|
@@ -247,7 +247,7 @@ export var layoutCells = function layoutCells(config) {
|
|
|
247
247
|
var childrenNodes = getChildrenNodes(data);
|
|
248
248
|
|
|
249
249
|
// 如果已经存在的,则使用上下节点进行标记。解决直线回连显示问题
|
|
250
|
-
|
|
250
|
+
|
|
251
251
|
childrenNodes.forEach(function (child) {
|
|
252
252
|
var side = child[sideSymbol] || 'right';
|
|
253
253
|
var innerNodes = child.innerNodes; // 如果有父级的子节点标记
|
|
@@ -263,18 +263,15 @@ export var layoutCells = function layoutCells(config) {
|
|
|
263
263
|
|
|
264
264
|
var sourceHandle = getConnectorId(BloodlineDirection.downstream, sourceHandleNode);
|
|
265
265
|
var targetHandle = getConnectorId(BloodlineDirection.upstream, targetHandleNode);
|
|
266
|
-
// if(edgeIndex === 1){
|
|
267
266
|
edges.push({
|
|
268
267
|
id: "source.".concat(sourceHandle, "_target.").concat(targetHandle),
|
|
269
|
-
type: '
|
|
268
|
+
type: 'smoothstep',
|
|
270
269
|
source: sourceNode,
|
|
271
270
|
target: targetNode,
|
|
272
271
|
sourceHandle: sourceHandle,
|
|
273
272
|
// 可能链接其中某个版本
|
|
274
273
|
targetHandle: targetHandle
|
|
275
274
|
});
|
|
276
|
-
// }
|
|
277
|
-
edgeIndex++;
|
|
278
275
|
} else {
|
|
279
276
|
innerNodes.forEach(function (innerNode) {
|
|
280
277
|
var sourceNode = side === 'left' ? childId : id; // 上游节点
|
|
@@ -287,7 +284,7 @@ export var layoutCells = function layoutCells(config) {
|
|
|
287
284
|
var targetHandle = getConnectorId(BloodlineDirection.upstream, targetHandleNode);
|
|
288
285
|
edges.push({
|
|
289
286
|
id: "source.".concat(sourceHandle, "_target.").concat(targetHandle),
|
|
290
|
-
type: '
|
|
287
|
+
type: 'smoothstep',
|
|
291
288
|
source: sourceNode,
|
|
292
289
|
target: targetNode,
|
|
293
290
|
sourceHandle: sourceHandle,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rxflow/bloodline",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.2",
|
|
4
4
|
"description": "通用血缘关系图",
|
|
5
5
|
"homepage": "https://tree-graph.publib.cn/packages/bloodline",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build": "father build"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@rxflow/base": "^0.0.1-alpha.
|
|
34
|
+
"@rxflow/base": "^0.0.1-alpha.2"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@antv/hierarchy": ">=0.6.14",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author: yanxianliang
|
|
3
|
-
* @date: 2025-07-03 13:20
|
|
4
|
-
* @desc: 血缘布局
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
7
|
-
*/
|
|
8
|
-
import { LayoutConfig } from "@rxflow/base";
|
|
9
|
-
import { Edge, Node } from "@xyflow/react";
|
|
10
|
-
export declare const layoutCells: <NodeType extends Node = Node, EdgeType extends Edge = Edge>(config: LayoutConfig<NodeType, EdgeType>) => {
|
|
11
|
-
nodes: NodeType[];
|
|
12
|
-
edges: EdgeType[];
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=_layoutCells.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_layoutCells.d.ts","sourceRoot":"","sources":["_layoutCells.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAA8B,YAAY,EAAe,MAAM,cAAc,CAAC;AAErF,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,MAAM,eAAe,CAAC;AAoGzC,eAAO,MAAM,WAAW,uEACd,aAAa,QAAQ,EAAE,QAAQ,CAAC;;;CA6WzC,CAAA"}
|
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.layoutCells = void 0;
|
|
7
|
-
var _hierarchy = _interopRequireDefault(require("@antv/hierarchy"));
|
|
8
|
-
var _base = require("@rxflow/base");
|
|
9
|
-
var _last = _interopRequireDefault(require("lodash/last"));
|
|
10
|
-
var _constants = require("../constants");
|
|
11
|
-
var _keys = require("./keys");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
/**
|
|
14
|
-
* @author: yanxianliang
|
|
15
|
-
* @date: 2025-07-03 13:20
|
|
16
|
-
* @desc: 血缘布局
|
|
17
|
-
*
|
|
18
|
-
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
// 支持 innerNodes 配置
|
|
22
|
-
function getChildren(direction, origin) {
|
|
23
|
-
let children = [];
|
|
24
|
-
if (origin.innerNodes) {
|
|
25
|
-
origin.innerNodes.forEach(innerNode => {
|
|
26
|
-
const connectorState = direction === _constants.BloodlineDirection.downstream ? innerNode.downstream : innerNode.upstream;
|
|
27
|
-
if (connectorState?.state === 'expanded') {
|
|
28
|
-
const list = connectorState.list || [];
|
|
29
|
-
children.push(...list.map(child => {
|
|
30
|
-
return {
|
|
31
|
-
...child,
|
|
32
|
-
[_constants.sideSymbol]: direction === _constants.BloodlineDirection.upstream ? _constants.SplitSide.left : _constants.SplitSide.right,
|
|
33
|
-
[_constants.parentIdSymbol]: innerNode.id
|
|
34
|
-
};
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
const connectorState = direction === _constants.BloodlineDirection.downstream ? origin.downstream : origin.upstream;
|
|
40
|
-
if (connectorState?.state === 'expanded') {
|
|
41
|
-
const list = connectorState.list || [];
|
|
42
|
-
children.push(...list.map(child => {
|
|
43
|
-
return {
|
|
44
|
-
...child,
|
|
45
|
-
[_constants.sideSymbol]: direction === _constants.BloodlineDirection.upstream ? _constants.SplitSide.left : _constants.SplitSide.right
|
|
46
|
-
};
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return children;
|
|
51
|
-
}
|
|
52
|
-
function getSiblings(node) {
|
|
53
|
-
const {
|
|
54
|
-
depth,
|
|
55
|
-
side,
|
|
56
|
-
parent
|
|
57
|
-
} = node;
|
|
58
|
-
if (!parent || !parent.children) {
|
|
59
|
-
return {
|
|
60
|
-
firstNode: null
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
let firstNode = null;
|
|
64
|
-
for (const child of parent.children) {
|
|
65
|
-
if (depth === 1 && child.side === side) {
|
|
66
|
-
!firstNode && (firstNode = child);
|
|
67
|
-
}
|
|
68
|
-
if (depth !== 1) {
|
|
69
|
-
!firstNode && (firstNode = child);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
firstNode
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function getChildrenNodes(node, cycleCheckNodeSet) {
|
|
77
|
-
const side = node.side;
|
|
78
|
-
let children = [];
|
|
79
|
-
switch (side) {
|
|
80
|
-
case 'left':
|
|
81
|
-
children = getChildren(_constants.BloodlineDirection.upstream, node);
|
|
82
|
-
break;
|
|
83
|
-
case 'right':
|
|
84
|
-
children = getChildren(_constants.BloodlineDirection.downstream, node);
|
|
85
|
-
break;
|
|
86
|
-
default:
|
|
87
|
-
{
|
|
88
|
-
const leftChildren = getChildren(_constants.BloodlineDirection.upstream, node);
|
|
89
|
-
const rightChildren = getChildren(_constants.BloodlineDirection.downstream, node);
|
|
90
|
-
children = [...(leftChildren || []), ...(rightChildren || [])];
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 支持 nodeList 处理
|
|
95
|
-
|
|
96
|
-
if (cycleCheckNodeSet) {
|
|
97
|
-
// 剔除循环引用的列表
|
|
98
|
-
return children.filter(child => {
|
|
99
|
-
if (cycleCheckNodeSet.has(child.id)) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
cycleCheckNodeSet.add(child.id);
|
|
103
|
-
return true;
|
|
104
|
-
});
|
|
105
|
-
} else {
|
|
106
|
-
return children;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const layoutCells = config => {
|
|
110
|
-
const {
|
|
111
|
-
nodeTypes,
|
|
112
|
-
originNodes,
|
|
113
|
-
theme,
|
|
114
|
-
store,
|
|
115
|
-
flowProps
|
|
116
|
-
} = config;
|
|
117
|
-
|
|
118
|
-
// const {autoHideIntermediateNode} = flowProps as IBloodlineFlowProps;
|
|
119
|
-
|
|
120
|
-
const {
|
|
121
|
-
nodeLookup
|
|
122
|
-
} = store;
|
|
123
|
-
const innerNodeLookup = new Map();
|
|
124
|
-
if (originNodes.length === 0) {
|
|
125
|
-
return {
|
|
126
|
-
nodes: [],
|
|
127
|
-
edges: []
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// 需不需要进行 clone ??? 需要设置 side 等属性,要回显回去吗??不需要的吧
|
|
132
|
-
const root = originNodes[0]; // 根节点
|
|
133
|
-
|
|
134
|
-
const align = theme.align || _constants.Align.top;
|
|
135
|
-
const layoutType = theme.layout || 'compactBox';
|
|
136
|
-
const layoutUtil = layoutType === 'mindmap' ? _hierarchy.default.mindmap : _hierarchy.default.compactBox;
|
|
137
|
-
|
|
138
|
-
// let edges: Edge[] = [];
|
|
139
|
-
|
|
140
|
-
// split side
|
|
141
|
-
root?.upstream?.list?.forEach(item => {
|
|
142
|
-
item[_constants.sideSymbol] = _constants.SplitSide.left;
|
|
143
|
-
});
|
|
144
|
-
root?.downstream?.list?.forEach(item => {
|
|
145
|
-
item[_constants.sideSymbol] = _constants.SplitSide.right;
|
|
146
|
-
});
|
|
147
|
-
const cycleCheckNodeSet = new Set([root.id]); // 循环依赖节点检测
|
|
148
|
-
|
|
149
|
-
const layoutResult = layoutUtil(root, {
|
|
150
|
-
direction: 'H',
|
|
151
|
-
getHGap: () => {
|
|
152
|
-
return 40;
|
|
153
|
-
},
|
|
154
|
-
getVGap: () => {
|
|
155
|
-
return 20;
|
|
156
|
-
},
|
|
157
|
-
getWidth(node) {
|
|
158
|
-
const width = (0, _base.getNodeWidth)(node, nodeTypes, theme, nodeLookup);
|
|
159
|
-
node.measured ?? (node.measured = {});
|
|
160
|
-
node.measured.width = width;
|
|
161
|
-
return width;
|
|
162
|
-
},
|
|
163
|
-
getHeight(node) {
|
|
164
|
-
const height = (0, _base.getNodeHeight)(node, nodeTypes, theme, nodeLookup);
|
|
165
|
-
node.measured ?? (node.measured = {});
|
|
166
|
-
node.measured.height = height;
|
|
167
|
-
return height;
|
|
168
|
-
},
|
|
169
|
-
getSide: node => {
|
|
170
|
-
// side 计算,上下游需要区分左和右
|
|
171
|
-
return node.data[_constants.sideSymbol] || 'right';
|
|
172
|
-
},
|
|
173
|
-
getChildren: node => {
|
|
174
|
-
return getChildrenNodes(node, cycleCheckNodeSet);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
let layoutNodes = [];
|
|
178
|
-
const {
|
|
179
|
-
x: rootX,
|
|
180
|
-
y: rootY
|
|
181
|
-
} = layoutResult;
|
|
182
|
-
// 开始节点x,y 以(0,0)进行修正,根节点需要能够被检测显示在画布区域
|
|
183
|
-
|
|
184
|
-
const loopCycleCheckNodeSet = new Set();
|
|
185
|
-
const edgesCount = {};
|
|
186
|
-
const edgesIndex = {};
|
|
187
|
-
const nodeHandles = {};
|
|
188
|
-
let edges = [];
|
|
189
|
-
|
|
190
|
-
// source 表示上游节点,target 表示下游节点
|
|
191
|
-
layoutResult.BFTraverse(node => {
|
|
192
|
-
const {
|
|
193
|
-
x,
|
|
194
|
-
y,
|
|
195
|
-
data,
|
|
196
|
-
side,
|
|
197
|
-
parent,
|
|
198
|
-
depth
|
|
199
|
-
} = node;
|
|
200
|
-
const {
|
|
201
|
-
id,
|
|
202
|
-
type,
|
|
203
|
-
measured
|
|
204
|
-
} = data;
|
|
205
|
-
if (loopCycleCheckNodeSet.has(id)) {
|
|
206
|
-
// 循环节点进行剔除
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
loopCycleCheckNodeSet.add(id);
|
|
210
|
-
const {
|
|
211
|
-
firstNode
|
|
212
|
-
} = getSiblings(node); // 同级节点
|
|
213
|
-
|
|
214
|
-
const offsetY = firstNode ? firstNode.y - parent.position.y : 0;
|
|
215
|
-
const direction = side === 'left' ? _constants.BloodlineDirection.upstream : _constants.BloodlineDirection.downstream;
|
|
216
|
-
const adjustX = x - rootX;
|
|
217
|
-
// 是否居中, 可居中,可顶部对齐
|
|
218
|
-
const adjustY = align === _constants.Align.top ? y - (parent ? offsetY : rootY) : y - rootY;
|
|
219
|
-
const position = {
|
|
220
|
-
x: adjustX,
|
|
221
|
-
y: adjustY
|
|
222
|
-
};
|
|
223
|
-
node.position = position;
|
|
224
|
-
if (!innerNodeLookup.has(id)) {
|
|
225
|
-
// 已经存在相同的节点了,直接关联到之前的节点上
|
|
226
|
-
// 实例每次都是新的,使用 data 实例缓存,但是所有节点外面都需要包一层????
|
|
227
|
-
const definition = nodeTypes?.[type];
|
|
228
|
-
const instance = {
|
|
229
|
-
id,
|
|
230
|
-
type,
|
|
231
|
-
measured: measured,
|
|
232
|
-
width: measured.width,
|
|
233
|
-
// 宽度固定,高度自动计算
|
|
234
|
-
height: measured.height,
|
|
235
|
-
// 血缘节点高度标准化模式为固定
|
|
236
|
-
data: {
|
|
237
|
-
isRoot: node.isRoot(),
|
|
238
|
-
depth,
|
|
239
|
-
id,
|
|
240
|
-
direction,
|
|
241
|
-
origin: data
|
|
242
|
-
// leaf 节点属性,当展开和折叠时需要处理对应的 leaf。
|
|
243
|
-
},
|
|
244
|
-
position: position,
|
|
245
|
-
zIndex: 10 // 节点默认 zIndex
|
|
246
|
-
};
|
|
247
|
-
const handles = definition?.measureHandles?.(instance);
|
|
248
|
-
instance.handles = (0, _base.parseHandles)(handles);
|
|
249
|
-
|
|
250
|
-
// 重复检测,如果已经存在相同节点,节点id相同,自动复用之前的节点。
|
|
251
|
-
layoutNodes.push(instance);
|
|
252
|
-
innerNodeLookup.set(id, instance);
|
|
253
|
-
}
|
|
254
|
-
const childrenNodes = getChildrenNodes(data);
|
|
255
|
-
childrenNodes.forEach(child => {
|
|
256
|
-
const side = child[_constants.sideSymbol] || 'right';
|
|
257
|
-
const {
|
|
258
|
-
innerNodes
|
|
259
|
-
} = child; // 如果有父级的子节点标记
|
|
260
|
-
// 连线是从 __parentId__ 到 child
|
|
261
|
-
const parentNodeId = child[_constants.parentIdSymbol] || id;
|
|
262
|
-
const childId = child.id;
|
|
263
|
-
if (!innerNodes) {
|
|
264
|
-
const sourceNode = side === 'left' ? childId : id; // 上游节点
|
|
265
|
-
const targetNode = side === 'left' ? id : childId; // 下游节点
|
|
266
|
-
|
|
267
|
-
const sourceHandleNode = side === 'left' ? childId : parentNodeId;
|
|
268
|
-
const targetHandleNode = side === 'left' ? parentNodeId : childId; // targetHandleNode 是
|
|
269
|
-
|
|
270
|
-
const sourceHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.downstream, sourceHandleNode);
|
|
271
|
-
const targetHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.upstream, targetHandleNode);
|
|
272
|
-
const _edge = {
|
|
273
|
-
id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
274
|
-
type: 'smart',
|
|
275
|
-
// 'smart',
|
|
276
|
-
source: sourceNode,
|
|
277
|
-
target: targetNode,
|
|
278
|
-
sourceHandle: sourceHandle,
|
|
279
|
-
// 可能链接其中某个版本
|
|
280
|
-
targetHandle: targetHandle
|
|
281
|
-
};
|
|
282
|
-
edges.push(_edge);
|
|
283
|
-
const {
|
|
284
|
-
source,
|
|
285
|
-
target
|
|
286
|
-
} = _edge;
|
|
287
|
-
if (!edgesCount[sourceHandle]) {
|
|
288
|
-
edgesCount[sourceHandle] = 1;
|
|
289
|
-
} else {
|
|
290
|
-
edgesCount[sourceHandle] += 1;
|
|
291
|
-
}
|
|
292
|
-
if (!edgesCount[targetHandle]) {
|
|
293
|
-
edgesCount[targetHandle] = 1;
|
|
294
|
-
} else {
|
|
295
|
-
edgesCount[targetHandle] += 1;
|
|
296
|
-
}
|
|
297
|
-
if (!edgesCount[`source-${source}`]) {
|
|
298
|
-
edgesCount[`source-${source}`] = 1;
|
|
299
|
-
} else {
|
|
300
|
-
edgesCount[`source-${source}`] += 1;
|
|
301
|
-
}
|
|
302
|
-
if (!edgesCount[`target-${target}`]) {
|
|
303
|
-
edgesCount[`target-${target}`] = 1;
|
|
304
|
-
} else {
|
|
305
|
-
edgesCount[`target-${target}`] += 1;
|
|
306
|
-
}
|
|
307
|
-
edgesIndex[_edge.id] = {
|
|
308
|
-
source: edgesCount[sourceHandle] - 1,
|
|
309
|
-
target: edgesCount[targetHandle] - 1
|
|
310
|
-
};
|
|
311
|
-
if (!nodeHandles[source]) {
|
|
312
|
-
nodeHandles[source] = {
|
|
313
|
-
sourceHandles: {},
|
|
314
|
-
targetHandles: {}
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
if (!nodeHandles[target]) {
|
|
318
|
-
nodeHandles[target] = {
|
|
319
|
-
sourceHandles: {},
|
|
320
|
-
targetHandles: {}
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
if (!nodeHandles[source].sourceHandles[sourceHandle]) {
|
|
324
|
-
nodeHandles[source].sourceHandles[sourceHandle] = 1;
|
|
325
|
-
} else {
|
|
326
|
-
nodeHandles[source].sourceHandles[sourceHandle] += 1;
|
|
327
|
-
}
|
|
328
|
-
if (!nodeHandles[target].targetHandles[targetHandle]) {
|
|
329
|
-
nodeHandles[target].targetHandles[targetHandle] = 1;
|
|
330
|
-
} else {
|
|
331
|
-
nodeHandles[target].targetHandles[targetHandle] += 1;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
//
|
|
335
|
-
// edges.push({
|
|
336
|
-
// id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
337
|
-
// type: 'smart', // 'smart',
|
|
338
|
-
// source: sourceNode,
|
|
339
|
-
// target: targetNode,
|
|
340
|
-
// sourceHandle: sourceHandle, // 可能链接其中某个版本
|
|
341
|
-
// targetHandle: targetHandle,
|
|
342
|
-
// data: {
|
|
343
|
-
// sourcePort: {
|
|
344
|
-
// edges: edgesCount[`source-${edge.source}`],
|
|
345
|
-
// portIndex: parseInt(lastOf(edge.sourceHandle.split('#'))!, 10),
|
|
346
|
-
// portCount: Object.keys(nodeHandles[edge.source].sourceHandles).length,
|
|
347
|
-
// edgeIndex: edgesIndex[edge.id].source,
|
|
348
|
-
// edgeCount: edgesCount[edge.sourceHandle],
|
|
349
|
-
// },
|
|
350
|
-
// targetPort: {
|
|
351
|
-
// edges: edgesCount[`target-${edge.target}`],
|
|
352
|
-
// portIndex: parseInt(lastOf(edge.targetHandle.split('#'))!, 10),
|
|
353
|
-
// portCount: Object.keys(nodeHandles[edge.target].targetHandles).length,
|
|
354
|
-
// edgeIndex: edgesIndex[edge.id].target,
|
|
355
|
-
// edgeCount: edgesCount[edge.targetHandle],
|
|
356
|
-
// },
|
|
357
|
-
// },
|
|
358
|
-
// })
|
|
359
|
-
} else {
|
|
360
|
-
innerNodes.forEach(innerNode => {
|
|
361
|
-
const sourceNode = side === 'left' ? childId : id; // 上游节点
|
|
362
|
-
const targetNode = side === 'left' ? id : childId; // 下游节点
|
|
363
|
-
|
|
364
|
-
const sourceHandleNode = side === 'left' ? innerNode.id : parentNodeId;
|
|
365
|
-
const targetHandleNode = side === 'left' ? parentNodeId : innerNode.id; // targetHandleNode 是
|
|
366
|
-
|
|
367
|
-
const sourceHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.downstream, sourceHandleNode);
|
|
368
|
-
const targetHandle = (0, _keys.getConnectorId)(_constants.BloodlineDirection.upstream, targetHandleNode);
|
|
369
|
-
const _edge = {
|
|
370
|
-
id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
371
|
-
type: 'smart',
|
|
372
|
-
// 'smart',
|
|
373
|
-
source: sourceNode,
|
|
374
|
-
target: targetNode,
|
|
375
|
-
sourceHandle: sourceHandle,
|
|
376
|
-
// 可能链接其中某个版本
|
|
377
|
-
targetHandle: targetHandle
|
|
378
|
-
};
|
|
379
|
-
edges.push(_edge);
|
|
380
|
-
const {
|
|
381
|
-
source,
|
|
382
|
-
target
|
|
383
|
-
} = _edge;
|
|
384
|
-
if (!edgesCount[sourceHandle]) {
|
|
385
|
-
edgesCount[sourceHandle] = 1;
|
|
386
|
-
} else {
|
|
387
|
-
edgesCount[sourceHandle] += 1;
|
|
388
|
-
}
|
|
389
|
-
if (!edgesCount[targetHandle]) {
|
|
390
|
-
edgesCount[targetHandle] = 1;
|
|
391
|
-
} else {
|
|
392
|
-
edgesCount[targetHandle] += 1;
|
|
393
|
-
}
|
|
394
|
-
if (!edgesCount[`source-${source}`]) {
|
|
395
|
-
edgesCount[`source-${source}`] = 1;
|
|
396
|
-
} else {
|
|
397
|
-
edgesCount[`source-${source}`] += 1;
|
|
398
|
-
}
|
|
399
|
-
if (!edgesCount[`target-${target}`]) {
|
|
400
|
-
edgesCount[`target-${target}`] = 1;
|
|
401
|
-
} else {
|
|
402
|
-
edgesCount[`target-${target}`] += 1;
|
|
403
|
-
}
|
|
404
|
-
edgesIndex[_edge.id] = {
|
|
405
|
-
source: edgesCount[sourceHandle] - 1,
|
|
406
|
-
target: edgesCount[targetHandle] - 1
|
|
407
|
-
};
|
|
408
|
-
if (!nodeHandles[source]) {
|
|
409
|
-
nodeHandles[source] = {
|
|
410
|
-
sourceHandles: {},
|
|
411
|
-
targetHandles: {}
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
if (!nodeHandles[target]) {
|
|
415
|
-
nodeHandles[target] = {
|
|
416
|
-
sourceHandles: {},
|
|
417
|
-
targetHandles: {}
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
if (!nodeHandles[source].sourceHandles[sourceHandle]) {
|
|
421
|
-
nodeHandles[source].sourceHandles[sourceHandle] = 1;
|
|
422
|
-
} else {
|
|
423
|
-
nodeHandles[source].sourceHandles[sourceHandle] += 1;
|
|
424
|
-
}
|
|
425
|
-
if (!nodeHandles[target].targetHandles[targetHandle]) {
|
|
426
|
-
nodeHandles[target].targetHandles[targetHandle] = 1;
|
|
427
|
-
} else {
|
|
428
|
-
nodeHandles[target].targetHandles[targetHandle] += 1;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// edges.push({
|
|
432
|
-
// id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
433
|
-
// type: 'smart', // 'smart',
|
|
434
|
-
// source: sourceNode,
|
|
435
|
-
// target: targetNode,
|
|
436
|
-
// sourceHandle: sourceHandle, // 可能链接其中某个版本
|
|
437
|
-
// targetHandle: targetHandle,
|
|
438
|
-
// data: {
|
|
439
|
-
// sourcePort: {
|
|
440
|
-
// edges: edgesCount[`source-${edge.source}`],
|
|
441
|
-
// portIndex: 1,
|
|
442
|
-
// portCount: 1,
|
|
443
|
-
// edgeIndex: edgesIndex[edge.id].source,
|
|
444
|
-
// edgeCount: edgesCount[edge.sourceHandle],
|
|
445
|
-
// },
|
|
446
|
-
// targetPort: {
|
|
447
|
-
// edges: edgesCount[`target-${edge.target}`],
|
|
448
|
-
// portIndex: 1,
|
|
449
|
-
// portCount: 1,
|
|
450
|
-
// edgeIndex: edgesIndex[edge.id].target,
|
|
451
|
-
// edgeCount: edgesCount[edge.targetHandle],
|
|
452
|
-
// },
|
|
453
|
-
// },
|
|
454
|
-
// })
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
edges = edges.map(edge => ({
|
|
460
|
-
...edge,
|
|
461
|
-
data: {
|
|
462
|
-
sourcePort: {
|
|
463
|
-
edges: edgesCount[`source-${edge.source}`],
|
|
464
|
-
portIndex: parseInt((0, _last.default)(edge.sourceHandle.split('#')), 10),
|
|
465
|
-
portCount: Object.keys(nodeHandles[edge.source].sourceHandles).length,
|
|
466
|
-
edgeIndex: edgesIndex[edge.id].source,
|
|
467
|
-
edgeCount: edgesCount[edge.sourceHandle]
|
|
468
|
-
},
|
|
469
|
-
targetPort: {
|
|
470
|
-
edges: edgesCount[`target-${edge.target}`],
|
|
471
|
-
portIndex: parseInt((0, _last.default)(edge.targetHandle.split('#')), 10),
|
|
472
|
-
portCount: Object.keys(nodeHandles[edge.target].targetHandles).length,
|
|
473
|
-
edgeIndex: edgesIndex[edge.id].target,
|
|
474
|
-
edgeCount: edgesCount[edge.targetHandle]
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}));
|
|
478
|
-
return {
|
|
479
|
-
nodes: layoutNodes,
|
|
480
|
-
edges: edges
|
|
481
|
-
};
|
|
482
|
-
};
|
|
483
|
-
exports.layoutCells = layoutCells;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author: yanxianliang
|
|
3
|
-
* @date: 2025-07-03 13:20
|
|
4
|
-
* @desc: 血缘布局
|
|
5
|
-
*
|
|
6
|
-
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
7
|
-
*/
|
|
8
|
-
import { LayoutConfig } from "@rxflow/base";
|
|
9
|
-
import { Edge, Node } from "@xyflow/react";
|
|
10
|
-
export declare const layoutCells: <NodeType extends Node = Node, EdgeType extends Edge = Edge>(config: LayoutConfig<NodeType, EdgeType>) => {
|
|
11
|
-
nodes: NodeType[];
|
|
12
|
-
edges: EdgeType[];
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=_layoutCells.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_layoutCells.d.ts","sourceRoot":"","sources":["_layoutCells.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAA8B,YAAY,EAAe,MAAM,cAAc,CAAC;AAErF,OAAO,EAAC,IAAI,EAAE,IAAI,EAAC,MAAM,eAAe,CAAC;AAoGzC,eAAO,MAAM,WAAW,uEACd,aAAa,QAAQ,EAAE,QAAQ,CAAC;;;CA6WzC,CAAA"}
|
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
-
/**
|
|
15
|
-
* @author: yanxianliang
|
|
16
|
-
* @date: 2025-07-03 13:20
|
|
17
|
-
* @desc: 血缘布局
|
|
18
|
-
*
|
|
19
|
-
* Copyright (c) 2025 by yanxianliang, All Rights Reserved.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import Hierarchy from "@antv/hierarchy";
|
|
23
|
-
import { getNodeHeight, getNodeWidth, parseHandles } from "@rxflow/base";
|
|
24
|
-
import lastOf from 'lodash/last';
|
|
25
|
-
import { Align, BloodlineDirection, parentIdSymbol, sideSymbol, SplitSide } from "../constants";
|
|
26
|
-
import { getConnectorId } from "./keys";
|
|
27
|
-
|
|
28
|
-
// 支持 innerNodes 配置
|
|
29
|
-
function getChildren(direction, origin) {
|
|
30
|
-
var children = [];
|
|
31
|
-
if (origin.innerNodes) {
|
|
32
|
-
origin.innerNodes.forEach(function (innerNode) {
|
|
33
|
-
var connectorState = direction === BloodlineDirection.downstream ? innerNode.downstream : innerNode.upstream;
|
|
34
|
-
if ((connectorState === null || connectorState === void 0 ? void 0 : connectorState.state) === 'expanded') {
|
|
35
|
-
var list = connectorState.list || [];
|
|
36
|
-
children.push.apply(children, _toConsumableArray(list.map(function (child) {
|
|
37
|
-
return _objectSpread(_objectSpread({}, child), {}, _defineProperty(_defineProperty({}, sideSymbol, direction === BloodlineDirection.upstream ? SplitSide.left : SplitSide.right), parentIdSymbol, innerNode.id));
|
|
38
|
-
})));
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
var connectorState = direction === BloodlineDirection.downstream ? origin.downstream : origin.upstream;
|
|
43
|
-
if ((connectorState === null || connectorState === void 0 ? void 0 : connectorState.state) === 'expanded') {
|
|
44
|
-
var list = connectorState.list || [];
|
|
45
|
-
children.push.apply(children, _toConsumableArray(list.map(function (child) {
|
|
46
|
-
return _objectSpread(_objectSpread({}, child), {}, _defineProperty({}, sideSymbol, direction === BloodlineDirection.upstream ? SplitSide.left : SplitSide.right));
|
|
47
|
-
})));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return children;
|
|
51
|
-
}
|
|
52
|
-
function getSiblings(node) {
|
|
53
|
-
var depth = node.depth,
|
|
54
|
-
side = node.side,
|
|
55
|
-
parent = node.parent;
|
|
56
|
-
if (!parent || !parent.children) {
|
|
57
|
-
return {
|
|
58
|
-
firstNode: null
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
var firstNode = null;
|
|
62
|
-
var _iterator = _createForOfIteratorHelper(parent.children),
|
|
63
|
-
_step;
|
|
64
|
-
try {
|
|
65
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
66
|
-
var child = _step.value;
|
|
67
|
-
if (depth === 1 && child.side === side) {
|
|
68
|
-
!firstNode && (firstNode = child);
|
|
69
|
-
}
|
|
70
|
-
if (depth !== 1) {
|
|
71
|
-
!firstNode && (firstNode = child);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
} catch (err) {
|
|
75
|
-
_iterator.e(err);
|
|
76
|
-
} finally {
|
|
77
|
-
_iterator.f();
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
firstNode: firstNode
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
function getChildrenNodes(node, cycleCheckNodeSet) {
|
|
84
|
-
var side = node.side;
|
|
85
|
-
var children = [];
|
|
86
|
-
switch (side) {
|
|
87
|
-
case 'left':
|
|
88
|
-
children = getChildren(BloodlineDirection.upstream, node);
|
|
89
|
-
break;
|
|
90
|
-
case 'right':
|
|
91
|
-
children = getChildren(BloodlineDirection.downstream, node);
|
|
92
|
-
break;
|
|
93
|
-
default:
|
|
94
|
-
{
|
|
95
|
-
var leftChildren = getChildren(BloodlineDirection.upstream, node);
|
|
96
|
-
var rightChildren = getChildren(BloodlineDirection.downstream, node);
|
|
97
|
-
children = [].concat(_toConsumableArray(leftChildren || []), _toConsumableArray(rightChildren || []));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 支持 nodeList 处理
|
|
102
|
-
|
|
103
|
-
if (cycleCheckNodeSet) {
|
|
104
|
-
// 剔除循环引用的列表
|
|
105
|
-
return children.filter(function (child) {
|
|
106
|
-
if (cycleCheckNodeSet.has(child.id)) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
cycleCheckNodeSet.add(child.id);
|
|
110
|
-
return true;
|
|
111
|
-
});
|
|
112
|
-
} else {
|
|
113
|
-
return children;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
export var layoutCells = function layoutCells(config) {
|
|
117
|
-
var _root$upstream, _root$downstream;
|
|
118
|
-
var nodeTypes = config.nodeTypes,
|
|
119
|
-
originNodes = config.originNodes,
|
|
120
|
-
theme = config.theme,
|
|
121
|
-
store = config.store,
|
|
122
|
-
flowProps = config.flowProps;
|
|
123
|
-
|
|
124
|
-
// const {autoHideIntermediateNode} = flowProps as IBloodlineFlowProps;
|
|
125
|
-
|
|
126
|
-
var nodeLookup = store.nodeLookup;
|
|
127
|
-
var innerNodeLookup = new Map();
|
|
128
|
-
if (originNodes.length === 0) {
|
|
129
|
-
return {
|
|
130
|
-
nodes: [],
|
|
131
|
-
edges: []
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// 需不需要进行 clone ??? 需要设置 side 等属性,要回显回去吗??不需要的吧
|
|
136
|
-
var root = originNodes[0]; // 根节点
|
|
137
|
-
|
|
138
|
-
var align = theme.align || Align.top;
|
|
139
|
-
var layoutType = theme.layout || 'compactBox';
|
|
140
|
-
var layoutUtil = layoutType === 'mindmap' ? Hierarchy.mindmap : Hierarchy.compactBox;
|
|
141
|
-
|
|
142
|
-
// let edges: Edge[] = [];
|
|
143
|
-
|
|
144
|
-
// split side
|
|
145
|
-
root === null || root === void 0 || (_root$upstream = root.upstream) === null || _root$upstream === void 0 || (_root$upstream = _root$upstream.list) === null || _root$upstream === void 0 || _root$upstream.forEach(function (item) {
|
|
146
|
-
item[sideSymbol] = SplitSide.left;
|
|
147
|
-
});
|
|
148
|
-
root === null || root === void 0 || (_root$downstream = root.downstream) === null || _root$downstream === void 0 || (_root$downstream = _root$downstream.list) === null || _root$downstream === void 0 || _root$downstream.forEach(function (item) {
|
|
149
|
-
item[sideSymbol] = SplitSide.right;
|
|
150
|
-
});
|
|
151
|
-
var cycleCheckNodeSet = new Set([root.id]); // 循环依赖节点检测
|
|
152
|
-
|
|
153
|
-
var layoutResult = layoutUtil(root, {
|
|
154
|
-
direction: 'H',
|
|
155
|
-
getHGap: function getHGap() {
|
|
156
|
-
return 40;
|
|
157
|
-
},
|
|
158
|
-
getVGap: function getVGap() {
|
|
159
|
-
return 20;
|
|
160
|
-
},
|
|
161
|
-
getWidth: function getWidth(node) {
|
|
162
|
-
var _node$measured;
|
|
163
|
-
var width = getNodeWidth(node, nodeTypes, theme, nodeLookup);
|
|
164
|
-
(_node$measured = node.measured) !== null && _node$measured !== void 0 ? _node$measured : node.measured = {};
|
|
165
|
-
node.measured.width = width;
|
|
166
|
-
return width;
|
|
167
|
-
},
|
|
168
|
-
getHeight: function getHeight(node) {
|
|
169
|
-
var _node$measured2;
|
|
170
|
-
var height = getNodeHeight(node, nodeTypes, theme, nodeLookup);
|
|
171
|
-
(_node$measured2 = node.measured) !== null && _node$measured2 !== void 0 ? _node$measured2 : node.measured = {};
|
|
172
|
-
node.measured.height = height;
|
|
173
|
-
return height;
|
|
174
|
-
},
|
|
175
|
-
getSide: function getSide(node) {
|
|
176
|
-
// side 计算,上下游需要区分左和右
|
|
177
|
-
return node.data[sideSymbol] || 'right';
|
|
178
|
-
},
|
|
179
|
-
getChildren: function getChildren(node) {
|
|
180
|
-
return getChildrenNodes(node, cycleCheckNodeSet);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
var layoutNodes = [];
|
|
184
|
-
var rootX = layoutResult.x,
|
|
185
|
-
rootY = layoutResult.y;
|
|
186
|
-
// 开始节点x,y 以(0,0)进行修正,根节点需要能够被检测显示在画布区域
|
|
187
|
-
|
|
188
|
-
var loopCycleCheckNodeSet = new Set();
|
|
189
|
-
var edgesCount = {};
|
|
190
|
-
var edgesIndex = {};
|
|
191
|
-
var nodeHandles = {};
|
|
192
|
-
var edges = [];
|
|
193
|
-
|
|
194
|
-
// source 表示上游节点,target 表示下游节点
|
|
195
|
-
layoutResult.BFTraverse(function (node) {
|
|
196
|
-
var x = node.x,
|
|
197
|
-
y = node.y,
|
|
198
|
-
data = node.data,
|
|
199
|
-
side = node.side,
|
|
200
|
-
parent = node.parent,
|
|
201
|
-
depth = node.depth;
|
|
202
|
-
var id = data.id,
|
|
203
|
-
type = data.type,
|
|
204
|
-
measured = data.measured;
|
|
205
|
-
if (loopCycleCheckNodeSet.has(id)) {
|
|
206
|
-
// 循环节点进行剔除
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
loopCycleCheckNodeSet.add(id);
|
|
210
|
-
var _getSiblings = getSiblings(node),
|
|
211
|
-
firstNode = _getSiblings.firstNode; // 同级节点
|
|
212
|
-
|
|
213
|
-
var offsetY = firstNode ? firstNode.y - parent.position.y : 0;
|
|
214
|
-
var direction = side === 'left' ? BloodlineDirection.upstream : BloodlineDirection.downstream;
|
|
215
|
-
var adjustX = x - rootX;
|
|
216
|
-
// 是否居中, 可居中,可顶部对齐
|
|
217
|
-
var adjustY = align === Align.top ? y - (parent ? offsetY : rootY) : y - rootY;
|
|
218
|
-
var position = {
|
|
219
|
-
x: adjustX,
|
|
220
|
-
y: adjustY
|
|
221
|
-
};
|
|
222
|
-
node.position = position;
|
|
223
|
-
if (!innerNodeLookup.has(id)) {
|
|
224
|
-
var _definition$measureHa;
|
|
225
|
-
// 已经存在相同的节点了,直接关联到之前的节点上
|
|
226
|
-
// 实例每次都是新的,使用 data 实例缓存,但是所有节点外面都需要包一层????
|
|
227
|
-
var definition = nodeTypes === null || nodeTypes === void 0 ? void 0 : nodeTypes[type];
|
|
228
|
-
var instance = {
|
|
229
|
-
id: id,
|
|
230
|
-
type: type,
|
|
231
|
-
measured: measured,
|
|
232
|
-
width: measured.width,
|
|
233
|
-
// 宽度固定,高度自动计算
|
|
234
|
-
height: measured.height,
|
|
235
|
-
// 血缘节点高度标准化模式为固定
|
|
236
|
-
data: {
|
|
237
|
-
isRoot: node.isRoot(),
|
|
238
|
-
depth: depth,
|
|
239
|
-
id: id,
|
|
240
|
-
direction: direction,
|
|
241
|
-
origin: data
|
|
242
|
-
// leaf 节点属性,当展开和折叠时需要处理对应的 leaf。
|
|
243
|
-
},
|
|
244
|
-
position: position,
|
|
245
|
-
zIndex: 10 // 节点默认 zIndex
|
|
246
|
-
};
|
|
247
|
-
var handles = definition === null || definition === void 0 || (_definition$measureHa = definition.measureHandles) === null || _definition$measureHa === void 0 ? void 0 : _definition$measureHa.call(definition, instance);
|
|
248
|
-
instance.handles = parseHandles(handles);
|
|
249
|
-
|
|
250
|
-
// 重复检测,如果已经存在相同节点,节点id相同,自动复用之前的节点。
|
|
251
|
-
layoutNodes.push(instance);
|
|
252
|
-
innerNodeLookup.set(id, instance);
|
|
253
|
-
}
|
|
254
|
-
var childrenNodes = getChildrenNodes(data);
|
|
255
|
-
childrenNodes.forEach(function (child) {
|
|
256
|
-
var side = child[sideSymbol] || 'right';
|
|
257
|
-
var innerNodes = child.innerNodes; // 如果有父级的子节点标记
|
|
258
|
-
// 连线是从 __parentId__ 到 child
|
|
259
|
-
var parentNodeId = child[parentIdSymbol] || id;
|
|
260
|
-
var childId = child.id;
|
|
261
|
-
if (!innerNodes) {
|
|
262
|
-
var sourceNode = side === 'left' ? childId : id; // 上游节点
|
|
263
|
-
var targetNode = side === 'left' ? id : childId; // 下游节点
|
|
264
|
-
|
|
265
|
-
var sourceHandleNode = side === 'left' ? childId : parentNodeId;
|
|
266
|
-
var targetHandleNode = side === 'left' ? parentNodeId : childId; // targetHandleNode 是
|
|
267
|
-
|
|
268
|
-
var sourceHandle = getConnectorId(BloodlineDirection.downstream, sourceHandleNode);
|
|
269
|
-
var targetHandle = getConnectorId(BloodlineDirection.upstream, targetHandleNode);
|
|
270
|
-
var _edge = {
|
|
271
|
-
id: "source.".concat(sourceHandle, "_target.").concat(targetHandle),
|
|
272
|
-
type: 'smart',
|
|
273
|
-
// 'smart',
|
|
274
|
-
source: sourceNode,
|
|
275
|
-
target: targetNode,
|
|
276
|
-
sourceHandle: sourceHandle,
|
|
277
|
-
// 可能链接其中某个版本
|
|
278
|
-
targetHandle: targetHandle
|
|
279
|
-
};
|
|
280
|
-
edges.push(_edge);
|
|
281
|
-
var source = _edge.source,
|
|
282
|
-
target = _edge.target;
|
|
283
|
-
if (!edgesCount[sourceHandle]) {
|
|
284
|
-
edgesCount[sourceHandle] = 1;
|
|
285
|
-
} else {
|
|
286
|
-
edgesCount[sourceHandle] += 1;
|
|
287
|
-
}
|
|
288
|
-
if (!edgesCount[targetHandle]) {
|
|
289
|
-
edgesCount[targetHandle] = 1;
|
|
290
|
-
} else {
|
|
291
|
-
edgesCount[targetHandle] += 1;
|
|
292
|
-
}
|
|
293
|
-
if (!edgesCount["source-".concat(source)]) {
|
|
294
|
-
edgesCount["source-".concat(source)] = 1;
|
|
295
|
-
} else {
|
|
296
|
-
edgesCount["source-".concat(source)] += 1;
|
|
297
|
-
}
|
|
298
|
-
if (!edgesCount["target-".concat(target)]) {
|
|
299
|
-
edgesCount["target-".concat(target)] = 1;
|
|
300
|
-
} else {
|
|
301
|
-
edgesCount["target-".concat(target)] += 1;
|
|
302
|
-
}
|
|
303
|
-
edgesIndex[_edge.id] = {
|
|
304
|
-
source: edgesCount[sourceHandle] - 1,
|
|
305
|
-
target: edgesCount[targetHandle] - 1
|
|
306
|
-
};
|
|
307
|
-
if (!nodeHandles[source]) {
|
|
308
|
-
nodeHandles[source] = {
|
|
309
|
-
sourceHandles: {},
|
|
310
|
-
targetHandles: {}
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
if (!nodeHandles[target]) {
|
|
314
|
-
nodeHandles[target] = {
|
|
315
|
-
sourceHandles: {},
|
|
316
|
-
targetHandles: {}
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
if (!nodeHandles[source].sourceHandles[sourceHandle]) {
|
|
320
|
-
nodeHandles[source].sourceHandles[sourceHandle] = 1;
|
|
321
|
-
} else {
|
|
322
|
-
nodeHandles[source].sourceHandles[sourceHandle] += 1;
|
|
323
|
-
}
|
|
324
|
-
if (!nodeHandles[target].targetHandles[targetHandle]) {
|
|
325
|
-
nodeHandles[target].targetHandles[targetHandle] = 1;
|
|
326
|
-
} else {
|
|
327
|
-
nodeHandles[target].targetHandles[targetHandle] += 1;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
//
|
|
331
|
-
// edges.push({
|
|
332
|
-
// id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
333
|
-
// type: 'smart', // 'smart',
|
|
334
|
-
// source: sourceNode,
|
|
335
|
-
// target: targetNode,
|
|
336
|
-
// sourceHandle: sourceHandle, // 可能链接其中某个版本
|
|
337
|
-
// targetHandle: targetHandle,
|
|
338
|
-
// data: {
|
|
339
|
-
// sourcePort: {
|
|
340
|
-
// edges: edgesCount[`source-${edge.source}`],
|
|
341
|
-
// portIndex: parseInt(lastOf(edge.sourceHandle.split('#'))!, 10),
|
|
342
|
-
// portCount: Object.keys(nodeHandles[edge.source].sourceHandles).length,
|
|
343
|
-
// edgeIndex: edgesIndex[edge.id].source,
|
|
344
|
-
// edgeCount: edgesCount[edge.sourceHandle],
|
|
345
|
-
// },
|
|
346
|
-
// targetPort: {
|
|
347
|
-
// edges: edgesCount[`target-${edge.target}`],
|
|
348
|
-
// portIndex: parseInt(lastOf(edge.targetHandle.split('#'))!, 10),
|
|
349
|
-
// portCount: Object.keys(nodeHandles[edge.target].targetHandles).length,
|
|
350
|
-
// edgeIndex: edgesIndex[edge.id].target,
|
|
351
|
-
// edgeCount: edgesCount[edge.targetHandle],
|
|
352
|
-
// },
|
|
353
|
-
// },
|
|
354
|
-
// })
|
|
355
|
-
} else {
|
|
356
|
-
innerNodes.forEach(function (innerNode) {
|
|
357
|
-
var sourceNode = side === 'left' ? childId : id; // 上游节点
|
|
358
|
-
var targetNode = side === 'left' ? id : childId; // 下游节点
|
|
359
|
-
|
|
360
|
-
var sourceHandleNode = side === 'left' ? innerNode.id : parentNodeId;
|
|
361
|
-
var targetHandleNode = side === 'left' ? parentNodeId : innerNode.id; // targetHandleNode 是
|
|
362
|
-
|
|
363
|
-
var sourceHandle = getConnectorId(BloodlineDirection.downstream, sourceHandleNode);
|
|
364
|
-
var targetHandle = getConnectorId(BloodlineDirection.upstream, targetHandleNode);
|
|
365
|
-
var _edge = {
|
|
366
|
-
id: "source.".concat(sourceHandle, "_target.").concat(targetHandle),
|
|
367
|
-
type: 'smart',
|
|
368
|
-
// 'smart',
|
|
369
|
-
source: sourceNode,
|
|
370
|
-
target: targetNode,
|
|
371
|
-
sourceHandle: sourceHandle,
|
|
372
|
-
// 可能链接其中某个版本
|
|
373
|
-
targetHandle: targetHandle
|
|
374
|
-
};
|
|
375
|
-
edges.push(_edge);
|
|
376
|
-
var source = _edge.source,
|
|
377
|
-
target = _edge.target;
|
|
378
|
-
if (!edgesCount[sourceHandle]) {
|
|
379
|
-
edgesCount[sourceHandle] = 1;
|
|
380
|
-
} else {
|
|
381
|
-
edgesCount[sourceHandle] += 1;
|
|
382
|
-
}
|
|
383
|
-
if (!edgesCount[targetHandle]) {
|
|
384
|
-
edgesCount[targetHandle] = 1;
|
|
385
|
-
} else {
|
|
386
|
-
edgesCount[targetHandle] += 1;
|
|
387
|
-
}
|
|
388
|
-
if (!edgesCount["source-".concat(source)]) {
|
|
389
|
-
edgesCount["source-".concat(source)] = 1;
|
|
390
|
-
} else {
|
|
391
|
-
edgesCount["source-".concat(source)] += 1;
|
|
392
|
-
}
|
|
393
|
-
if (!edgesCount["target-".concat(target)]) {
|
|
394
|
-
edgesCount["target-".concat(target)] = 1;
|
|
395
|
-
} else {
|
|
396
|
-
edgesCount["target-".concat(target)] += 1;
|
|
397
|
-
}
|
|
398
|
-
edgesIndex[_edge.id] = {
|
|
399
|
-
source: edgesCount[sourceHandle] - 1,
|
|
400
|
-
target: edgesCount[targetHandle] - 1
|
|
401
|
-
};
|
|
402
|
-
if (!nodeHandles[source]) {
|
|
403
|
-
nodeHandles[source] = {
|
|
404
|
-
sourceHandles: {},
|
|
405
|
-
targetHandles: {}
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
if (!nodeHandles[target]) {
|
|
409
|
-
nodeHandles[target] = {
|
|
410
|
-
sourceHandles: {},
|
|
411
|
-
targetHandles: {}
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
if (!nodeHandles[source].sourceHandles[sourceHandle]) {
|
|
415
|
-
nodeHandles[source].sourceHandles[sourceHandle] = 1;
|
|
416
|
-
} else {
|
|
417
|
-
nodeHandles[source].sourceHandles[sourceHandle] += 1;
|
|
418
|
-
}
|
|
419
|
-
if (!nodeHandles[target].targetHandles[targetHandle]) {
|
|
420
|
-
nodeHandles[target].targetHandles[targetHandle] = 1;
|
|
421
|
-
} else {
|
|
422
|
-
nodeHandles[target].targetHandles[targetHandle] += 1;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// edges.push({
|
|
426
|
-
// id: `source.${sourceHandle}_target.${targetHandle}`,
|
|
427
|
-
// type: 'smart', // 'smart',
|
|
428
|
-
// source: sourceNode,
|
|
429
|
-
// target: targetNode,
|
|
430
|
-
// sourceHandle: sourceHandle, // 可能链接其中某个版本
|
|
431
|
-
// targetHandle: targetHandle,
|
|
432
|
-
// data: {
|
|
433
|
-
// sourcePort: {
|
|
434
|
-
// edges: edgesCount[`source-${edge.source}`],
|
|
435
|
-
// portIndex: 1,
|
|
436
|
-
// portCount: 1,
|
|
437
|
-
// edgeIndex: edgesIndex[edge.id].source,
|
|
438
|
-
// edgeCount: edgesCount[edge.sourceHandle],
|
|
439
|
-
// },
|
|
440
|
-
// targetPort: {
|
|
441
|
-
// edges: edgesCount[`target-${edge.target}`],
|
|
442
|
-
// portIndex: 1,
|
|
443
|
-
// portCount: 1,
|
|
444
|
-
// edgeIndex: edgesIndex[edge.id].target,
|
|
445
|
-
// edgeCount: edgesCount[edge.targetHandle],
|
|
446
|
-
// },
|
|
447
|
-
// },
|
|
448
|
-
// })
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
});
|
|
452
|
-
});
|
|
453
|
-
edges = edges.map(function (edge) {
|
|
454
|
-
return _objectSpread(_objectSpread({}, edge), {}, {
|
|
455
|
-
data: {
|
|
456
|
-
sourcePort: {
|
|
457
|
-
edges: edgesCount["source-".concat(edge.source)],
|
|
458
|
-
portIndex: parseInt(lastOf(edge.sourceHandle.split('#')), 10),
|
|
459
|
-
portCount: Object.keys(nodeHandles[edge.source].sourceHandles).length,
|
|
460
|
-
edgeIndex: edgesIndex[edge.id].source,
|
|
461
|
-
edgeCount: edgesCount[edge.sourceHandle]
|
|
462
|
-
},
|
|
463
|
-
targetPort: {
|
|
464
|
-
edges: edgesCount["target-".concat(edge.target)],
|
|
465
|
-
portIndex: parseInt(lastOf(edge.targetHandle.split('#')), 10),
|
|
466
|
-
portCount: Object.keys(nodeHandles[edge.target].targetHandles).length,
|
|
467
|
-
edgeIndex: edgesIndex[edge.id].target,
|
|
468
|
-
edgeCount: edgesCount[edge.targetHandle]
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
});
|
|
473
|
-
return {
|
|
474
|
-
nodes: layoutNodes,
|
|
475
|
-
edges: edges
|
|
476
|
-
};
|
|
477
|
-
};
|