@logicflow/layout 1.2.0-alpha.16 → 2.0.1

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/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "exclude": ["node_modules", "**/es", "**/lib"],
3
+ "compilerOptions": {
4
+ "module": "ES2020",
5
+ "moduleResolution": "node",
6
+ "sourceMap": true,
7
+ "declaration": true,
8
+ "skipLibCheck": true,
9
+ "esModuleInterop": true,
10
+ "noImplicitAny": true,
11
+ "noEmitOnError": true,
12
+ "noUnusedLocals": true,
13
+ "strictNullChecks": true,
14
+ "resolveJsonModule": true,
15
+ "experimentalDecorators": true,
16
+ "jsx": "react",
17
+ "target": "es6",
18
+ "lib": ["DOM", "ES2020"]
19
+ }
20
+ }
package/cjs/dagre.js DELETED
@@ -1,221 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.Dagre = void 0;
15
- var layout_1 = require("@antv/layout");
16
- var Dagre = /** @class */ (function () {
17
- function Dagre() {
18
- }
19
- Dagre.prototype.render = function (lf) {
20
- this.lf = lf;
21
- };
22
- Dagre.prototype.getBytesLength = function (word) {
23
- if (!word) {
24
- return 0;
25
- }
26
- var totalLength = 0;
27
- for (var i = 0; i < word.length; i++) {
28
- var c = word.charCodeAt(i);
29
- if ((word.match(/[A-Z]/))) {
30
- totalLength += 1.5;
31
- }
32
- else if ((c >= 0x0001 && c <= 0x007e) || (c >= 0xff60 && c <= 0xff9f)) {
33
- totalLength += 1;
34
- }
35
- else {
36
- totalLength += 2;
37
- }
38
- }
39
- return totalLength;
40
- };
41
- /**
42
- * option: {
43
- * rankdir: "TB", // layout 方向, 可选 TB, BT, LR, RL
44
- * align: undefined, // 节点对齐方式,可选 UL, UR, DL, DR
45
- * nodeSize: undefined, // 节点大小
46
- * nodesepFunc: undefined, // 节点水平间距(px)
47
- * ranksepFunc: undefined, // 每一层节点之间间距
48
- * nodesep: 40, // 节点水平间距(px) 注意:如果有grid,需要保证nodesep为grid的偶数倍
49
- * ranksep: 40, // 每一层节点之间间距 注意:如果有grid,需要保证ranksep为grid的偶数倍
50
- * controlPoints: false, // 是否保留布局连线的控制点
51
- * radial: false, // 是否基于 dagre 进行辐射布局
52
- * focusNode: null, // radial 为 true 时生效,关注的节点
53
- * };
54
- */
55
- Dagre.prototype.layout = function (option) {
56
- var _this = this;
57
- if (option === void 0) { option = {}; }
58
- var _a = this.lf.graphModel, nodes = _a.nodes, edges = _a.edges, gridSize = _a.gridSize;
59
- // 为了保证生成的节点在girdSize上,需要处理一下。
60
- var nodesep = 40;
61
- var ranksep = 40;
62
- if (gridSize > 20) {
63
- nodesep = gridSize * 2;
64
- ranksep = gridSize * 2;
65
- }
66
- this.option = __assign({ type: 'dagre', rankdir: 'LR',
67
- // align: 'UL',
68
- // align: 'UR',
69
- align: 'DR', nodesep: nodesep,
70
- ranksep: ranksep, begin: [120, 120] }, option);
71
- var layoutInstance = new layout_1.DagreLayout(this.option);
72
- var layoutData = layoutInstance.layout({
73
- nodes: nodes.map(function (node) { return ({
74
- id: node.id,
75
- size: {
76
- width: node.width,
77
- height: node.height,
78
- },
79
- model: node,
80
- }); }),
81
- edges: edges.map(function (edge) { return ({
82
- source: edge.sourceNodeId,
83
- target: edge.targetNodeId,
84
- model: edge,
85
- }); }),
86
- });
87
- var newGraphData = {
88
- nodes: [],
89
- edges: [],
90
- };
91
- layoutData.nodes.forEach(function (node) {
92
- // @ts-ignore: pass node data
93
- var model = node.model;
94
- var data = model.getData();
95
- // @ts-ignore: pass node data
96
- data.x = node.x;
97
- // @ts-ignore: pass node data
98
- data.y = node.y;
99
- newGraphData.nodes.push(data);
100
- });
101
- layoutData.edges.forEach(function (edge) {
102
- // @ts-ignore: pass edge data
103
- var model = edge.model;
104
- var data = model.getData();
105
- data.pointsList = _this.calcPointsList(model, newGraphData.nodes);
106
- if (data.pointsList) {
107
- var first = data.pointsList[0];
108
- var last = data.pointsList[data.pointsList.length - 1];
109
- data.startPoint = { x: first.x, y: first.y };
110
- data.endPoint = { x: last.x, y: last.y };
111
- if (data.text && data.text.value) {
112
- data.text = {
113
- x: last.x - _this.getBytesLength(data.text.value) * 6 - 10,
114
- y: last.y,
115
- value: data.text.value,
116
- };
117
- }
118
- }
119
- else {
120
- data.startPoint = undefined;
121
- data.endPoint = undefined;
122
- if (data.text && data.text.value) {
123
- data.text = data.text.value;
124
- }
125
- }
126
- newGraphData.edges.push(data);
127
- });
128
- this.lf.render(newGraphData);
129
- };
130
- Dagre.prototype.pointFilter = function (points) {
131
- var allPoints = points;
132
- var i = 1;
133
- while (i < allPoints.length - 1) {
134
- var pre = allPoints[i - 1];
135
- var current = allPoints[i];
136
- var next = allPoints[i + 1];
137
- if ((pre.x === current.x && current.x === next.x)
138
- || (pre.y === current.y && current.y === next.y)) {
139
- allPoints.splice(i, 1);
140
- }
141
- else {
142
- i++;
143
- }
144
- }
145
- return allPoints;
146
- };
147
- Dagre.prototype.calcPointsList = function (model, nodes) {
148
- // 在节点确认从左向右后,通过计算来保证节点连线清晰。
149
- // TODO: 避障
150
- var pointsList = [];
151
- if (this.option.rankdir === 'LR' && model.modelType === 'polyline-edge') {
152
- var sourceNodeModel = this.lf.getNodeModelById(model.sourceNodeId);
153
- var targetNodeModel = this.lf.getNodeModelById(model.targetNodeId);
154
- var newSourceNodeData = nodes.find(function (node) { return node.id === model.sourceNodeId; });
155
- var newTargetNodeData = nodes.find(function (node) { return node.id === model.targetNodeId; });
156
- if (newSourceNodeData.x < newTargetNodeData.x) {
157
- pointsList.push({
158
- x: newSourceNodeData.x + sourceNodeModel.width / 2,
159
- y: newSourceNodeData.y,
160
- });
161
- pointsList.push({
162
- x: newSourceNodeData.x + sourceNodeModel.width / 2 + (model.offset || 50),
163
- y: newSourceNodeData.y,
164
- });
165
- pointsList.push({
166
- x: newSourceNodeData.x + sourceNodeModel.width / 2 + (model.offset || 50),
167
- y: newTargetNodeData.y,
168
- });
169
- pointsList.push({
170
- x: newTargetNodeData.x - targetNodeModel.width / 2,
171
- y: newTargetNodeData.y,
172
- });
173
- return this.pointFilter(pointsList);
174
- }
175
- // 向回连线
176
- if (newSourceNodeData.x > newTargetNodeData.x) {
177
- if (newSourceNodeData.y >= newTargetNodeData.y) {
178
- pointsList.push({
179
- x: newSourceNodeData.x,
180
- y: newSourceNodeData.y + sourceNodeModel.height / 2,
181
- });
182
- pointsList.push({
183
- x: newSourceNodeData.x,
184
- y: newSourceNodeData.y + sourceNodeModel.height / 2 + (model.offset || 50),
185
- });
186
- pointsList.push({
187
- x: newTargetNodeData.x,
188
- y: newSourceNodeData.y + sourceNodeModel.height / 2 + (model.offset || 50),
189
- });
190
- pointsList.push({
191
- x: newTargetNodeData.x,
192
- y: newTargetNodeData.y + targetNodeModel.height / 2,
193
- });
194
- }
195
- else {
196
- pointsList.push({
197
- x: newSourceNodeData.x,
198
- y: newSourceNodeData.y - sourceNodeModel.height / 2,
199
- });
200
- pointsList.push({
201
- x: newSourceNodeData.x,
202
- y: newSourceNodeData.y - sourceNodeModel.height / 2 - (model.offset || 50),
203
- });
204
- pointsList.push({
205
- x: newTargetNodeData.x,
206
- y: newSourceNodeData.y - sourceNodeModel.height / 2 - (model.offset || 50),
207
- });
208
- pointsList.push({
209
- x: newTargetNodeData.x,
210
- y: newTargetNodeData.y - targetNodeModel.height / 2,
211
- });
212
- }
213
- return this.pointFilter(pointsList);
214
- }
215
- }
216
- return undefined;
217
- };
218
- Dagre.pluginName = 'dagre';
219
- return Dagre;
220
- }());
221
- exports.Dagre = Dagre;
package/cjs/index.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./dagre"), exports);
package/types/dagre.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import { DagreLayoutOptions } from '@antv/layout';
2
- export declare class Dagre {
3
- static pluginName: string;
4
- lf: any;
5
- option: DagreLayoutOptions;
6
- render(lf: any): void;
7
- getBytesLength(word: string): number;
8
- /**
9
- * option: {
10
- * rankdir: "TB", // layout 方向, 可选 TB, BT, LR, RL
11
- * align: undefined, // 节点对齐方式,可选 UL, UR, DL, DR
12
- * nodeSize: undefined, // 节点大小
13
- * nodesepFunc: undefined, // 节点水平间距(px)
14
- * ranksepFunc: undefined, // 每一层节点之间间距
15
- * nodesep: 40, // 节点水平间距(px) 注意:如果有grid,需要保证nodesep为grid的偶数倍
16
- * ranksep: 40, // 每一层节点之间间距 注意:如果有grid,需要保证ranksep为grid的偶数倍
17
- * controlPoints: false, // 是否保留布局连线的控制点
18
- * radial: false, // 是否基于 dagre 进行辐射布局
19
- * focusNode: null, // radial 为 true 时生效,关注的节点
20
- * };
21
- */
22
- layout(option?: {}): void;
23
- pointFilter(points: any): any;
24
- calcPointsList(model: any, nodes: any): any;
25
- }
File without changes