@flowgram-vue/free-auto-layout-plugin 0.2.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/LICENSE +22 -0
- package/dist/index.cjs +2713 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +377 -0
- package/dist/index.js +2705 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
- package/src/create-auto-layout-plugin.ts +23 -0
- package/src/dagre-layout/acyclic.ts +129 -0
- package/src/dagre-layout/graph.ts +71 -0
- package/src/dagre-layout/index.ts +9 -0
- package/src/dagre-layout/layout.ts +151 -0
- package/src/dagre-layout/order.ts +261 -0
- package/src/dagre-layout/rank/feasible-tree.ts +102 -0
- package/src/dagre-layout/rank/index.ts +9 -0
- package/src/dagre-layout/rank/longest-path.ts +79 -0
- package/src/dagre-layout/rank/network-simplex.ts +235 -0
- package/src/dagre-layout/rank/normalize-ranks.ts +26 -0
- package/src/dagre-layout/type.ts +43 -0
- package/src/dagre-lib/acyclic.js +72 -0
- package/src/dagre-lib/add-border-segments.js +41 -0
- package/src/dagre-lib/coordinate-system.js +77 -0
- package/src/dagre-lib/data/list.js +63 -0
- package/src/dagre-lib/debug.js +34 -0
- package/src/dagre-lib/greedy-fas.js +134 -0
- package/src/dagre-lib/index.js +75 -0
- package/src/dagre-lib/layout.js +449 -0
- package/src/dagre-lib/nesting-graph.js +133 -0
- package/src/dagre-lib/normalize.js +98 -0
- package/src/dagre-lib/order/add-subgraph-constraints.js +57 -0
- package/src/dagre-lib/order/barycenter.js +34 -0
- package/src/dagre-lib/order/build-layer-graph.js +80 -0
- package/src/dagre-lib/order/cross-count.js +78 -0
- package/src/dagre-lib/order/index.js +86 -0
- package/src/dagre-lib/order/init-order.js +43 -0
- package/src/dagre-lib/order/resolve-conflicts.js +128 -0
- package/src/dagre-lib/order/sort-subgraph.js +79 -0
- package/src/dagre-lib/order/sort.js +62 -0
- package/src/dagre-lib/parent-dummy-chains.js +90 -0
- package/src/dagre-lib/position/bk.js +431 -0
- package/src/dagre-lib/position/index.js +37 -0
- package/src/dagre-lib/rank/feasible-tree.js +104 -0
- package/src/dagre-lib/rank/index.js +61 -0
- package/src/dagre-lib/rank/network-simplex.js +243 -0
- package/src/dagre-lib/rank/util.js +70 -0
- package/src/dagre-lib/util.js +365 -0
- package/src/dagre-lib/version.js +6 -0
- package/src/env.d.ts +10 -0
- package/src/index.ts +10 -0
- package/src/layout/constant.ts +26 -0
- package/src/layout/dagre.ts +245 -0
- package/src/layout/index.ts +9 -0
- package/src/layout/layout.ts +41 -0
- package/src/layout/position.ts +72 -0
- package/src/layout/store.ts +262 -0
- package/src/layout/type.ts +162 -0
- package/src/services.ts +174 -0
- package/src/type.ts +10 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { Graph } from '@dagrejs/graphlib';
|
|
2
|
+
export { Graph as DagreGraph } from '@dagrejs/graphlib';
|
|
3
|
+
import * as _flowgram_vue_core from '@flowgram-vue/core';
|
|
4
|
+
import { WorkflowNodeEntity, WorkflowLineEntity } from '@flowgram-vue/free-layout-core';
|
|
5
|
+
|
|
6
|
+
declare function layout(g: any, opts: any): void;
|
|
7
|
+
declare function buildLayoutGraph(inputGraph: any): Graph;
|
|
8
|
+
declare function updateInputGraph(inputGraph: any, layoutGraph: any): void;
|
|
9
|
+
declare function makeSpaceForEdgeLabels(g: any): void;
|
|
10
|
+
declare function removeSelfEdges(g: any): void;
|
|
11
|
+
declare function injectEdgeLabelProxies(g: any): void;
|
|
12
|
+
declare function assignRankMinMax(g: any): void;
|
|
13
|
+
declare function removeEdgeLabelProxies(g: any): void;
|
|
14
|
+
declare function insertSelfEdges(g: any): void;
|
|
15
|
+
declare function positionSelfEdges(g: any): void;
|
|
16
|
+
declare function removeBorderNodes(g: any): void;
|
|
17
|
+
declare function fixupEdgeLabelCoords(g: any): void;
|
|
18
|
+
declare function translateGraph(g: any): void;
|
|
19
|
+
declare function assignNodeIntersects(g: any): void;
|
|
20
|
+
declare function reversePointsForReversedEdges(g: any): void;
|
|
21
|
+
|
|
22
|
+
declare namespace acyclic {
|
|
23
|
+
export { run$2 as run };
|
|
24
|
+
export { undo$2 as undo };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare function run$2(g: any): void;
|
|
28
|
+
declare function undo$2(g: any): void;
|
|
29
|
+
|
|
30
|
+
declare namespace nestingGraph {
|
|
31
|
+
export { run$1 as run };
|
|
32
|
+
export { cleanup };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare function run$1(g: any): void;
|
|
36
|
+
declare function cleanup(g: any): void;
|
|
37
|
+
|
|
38
|
+
declare function rank(g: any): void;
|
|
39
|
+
|
|
40
|
+
declare namespace util {
|
|
41
|
+
export { addBorderNode };
|
|
42
|
+
export { addDummyNode };
|
|
43
|
+
export { applyWithChunking };
|
|
44
|
+
export { asNonCompoundGraph };
|
|
45
|
+
export { buildLayerMatrix };
|
|
46
|
+
export { intersectRect };
|
|
47
|
+
export { mapValues };
|
|
48
|
+
export { maxRank };
|
|
49
|
+
export { normalizeRanks };
|
|
50
|
+
export { notime };
|
|
51
|
+
export { partition };
|
|
52
|
+
export { pick };
|
|
53
|
+
export { predecessorWeights };
|
|
54
|
+
export { range };
|
|
55
|
+
export { removeEmptyRanks };
|
|
56
|
+
export { simplify };
|
|
57
|
+
export { successorWeights };
|
|
58
|
+
export { time };
|
|
59
|
+
export { uniqueId };
|
|
60
|
+
export { zipObject };
|
|
61
|
+
}
|
|
62
|
+
declare function addBorderNode(g: any, prefix: any, rank: any, order: any, ...args: any[]): string;
|
|
63
|
+
declare function addDummyNode(g: any, type: any, attrs: any, name: any): string;
|
|
64
|
+
declare function applyWithChunking(fn: any, argsArray: any): any;
|
|
65
|
+
declare function asNonCompoundGraph(g: any): Graph;
|
|
66
|
+
declare function buildLayerMatrix(g: any): never[][];
|
|
67
|
+
declare function intersectRect(rect: any, point: any): {
|
|
68
|
+
x: any;
|
|
69
|
+
y: any;
|
|
70
|
+
};
|
|
71
|
+
declare function mapValues(obj: any, funcOrProp: any): {};
|
|
72
|
+
declare function maxRank(g: any): any;
|
|
73
|
+
declare function normalizeRanks(g: any): void;
|
|
74
|
+
declare function notime(name: any, fn: any): any;
|
|
75
|
+
declare function partition(collection: any, fn: any): {
|
|
76
|
+
lhs: never[];
|
|
77
|
+
rhs: never[];
|
|
78
|
+
};
|
|
79
|
+
declare function pick(source: any, keys: any): {};
|
|
80
|
+
declare function predecessorWeights(g: any): any;
|
|
81
|
+
declare function range(start: any, limit: any, step?: number): any[];
|
|
82
|
+
declare function removeEmptyRanks(g: any): void;
|
|
83
|
+
declare function simplify(g: any): Graph;
|
|
84
|
+
declare function successorWeights(g: any): any;
|
|
85
|
+
declare function time(name: any, fn: any): any;
|
|
86
|
+
declare function uniqueId(prefix: any): string;
|
|
87
|
+
declare function zipObject(props: any, values: any): any;
|
|
88
|
+
|
|
89
|
+
declare namespace normalize {
|
|
90
|
+
export { run };
|
|
91
|
+
export { undo$1 as undo };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
declare function run(g: any): void;
|
|
95
|
+
declare function undo$1(g: any): void;
|
|
96
|
+
|
|
97
|
+
declare function parentDummyChains(g: any): void;
|
|
98
|
+
|
|
99
|
+
declare function addBorderSegments(g: any): void;
|
|
100
|
+
|
|
101
|
+
declare function order(g: any, opts: any): void;
|
|
102
|
+
|
|
103
|
+
declare namespace coordinateSystem {
|
|
104
|
+
export { adjust };
|
|
105
|
+
export { undo };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
declare function adjust(g: any): void;
|
|
109
|
+
declare function undo(g: any): void;
|
|
110
|
+
|
|
111
|
+
declare function position(g: any): void;
|
|
112
|
+
|
|
113
|
+
declare namespace dagreLib {
|
|
114
|
+
export { layout };
|
|
115
|
+
export { buildLayoutGraph };
|
|
116
|
+
export { updateInputGraph };
|
|
117
|
+
export { makeSpaceForEdgeLabels };
|
|
118
|
+
export { removeSelfEdges };
|
|
119
|
+
export { acyclic };
|
|
120
|
+
export { nestingGraph };
|
|
121
|
+
export { rank };
|
|
122
|
+
export { util };
|
|
123
|
+
export { injectEdgeLabelProxies };
|
|
124
|
+
export { removeEmptyRanks };
|
|
125
|
+
export { normalizeRanks };
|
|
126
|
+
export { assignRankMinMax };
|
|
127
|
+
export { removeEdgeLabelProxies };
|
|
128
|
+
export { normalize };
|
|
129
|
+
export { parentDummyChains };
|
|
130
|
+
export { addBorderSegments };
|
|
131
|
+
export { order };
|
|
132
|
+
export { insertSelfEdges };
|
|
133
|
+
export { coordinateSystem };
|
|
134
|
+
export { position };
|
|
135
|
+
export { positionSelfEdges };
|
|
136
|
+
export { removeBorderNodes };
|
|
137
|
+
export { fixupEdgeLabelCoords };
|
|
138
|
+
export { translateGraph };
|
|
139
|
+
export { assignNodeIntersects };
|
|
140
|
+
export { reversePointsForReversedEdges };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
145
|
+
* SPDX-License-Identifier: MIT
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
interface ILayoutStore {
|
|
149
|
+
container: LayoutNode;
|
|
150
|
+
options: LayoutOptions;
|
|
151
|
+
get initialized(): boolean;
|
|
152
|
+
getNode(id?: string): LayoutNode | undefined;
|
|
153
|
+
getNodeByIndex(index: string): LayoutNode | undefined;
|
|
154
|
+
getEdge(id: string): LayoutEdge | undefined;
|
|
155
|
+
nodes: LayoutNode[];
|
|
156
|
+
edges: LayoutEdge[];
|
|
157
|
+
create(params: LayoutParams, options: LayoutOptions): void;
|
|
158
|
+
}
|
|
159
|
+
interface ILayout {
|
|
160
|
+
init(params: LayoutParams, options: LayoutOptions): void;
|
|
161
|
+
layout(): void;
|
|
162
|
+
position(): Promise<void>;
|
|
163
|
+
}
|
|
164
|
+
interface LayoutSize {
|
|
165
|
+
width: number;
|
|
166
|
+
height: number;
|
|
167
|
+
}
|
|
168
|
+
interface LayoutNode {
|
|
169
|
+
id: string;
|
|
170
|
+
/** 节点索引 */
|
|
171
|
+
index: string;
|
|
172
|
+
/** 节点实体 */
|
|
173
|
+
entity: WorkflowNodeEntity;
|
|
174
|
+
/** 层级 */
|
|
175
|
+
rank: number;
|
|
176
|
+
/** 顺序 */
|
|
177
|
+
order: number;
|
|
178
|
+
/** 位置 */
|
|
179
|
+
position: {
|
|
180
|
+
x: number;
|
|
181
|
+
y: number;
|
|
182
|
+
};
|
|
183
|
+
/** 偏移量 */
|
|
184
|
+
offset: {
|
|
185
|
+
x: number;
|
|
186
|
+
y: number;
|
|
187
|
+
};
|
|
188
|
+
/** 边距 */
|
|
189
|
+
padding: {
|
|
190
|
+
top: number;
|
|
191
|
+
bottom: number;
|
|
192
|
+
left: number;
|
|
193
|
+
right: number;
|
|
194
|
+
};
|
|
195
|
+
/** 宽高 */
|
|
196
|
+
size: LayoutSize;
|
|
197
|
+
/** 子节点 */
|
|
198
|
+
layoutNodes: LayoutNode[];
|
|
199
|
+
/** 子线条 */
|
|
200
|
+
layoutEdges: LayoutEdge[];
|
|
201
|
+
/** 被跟随节点 */
|
|
202
|
+
followedBy?: string[];
|
|
203
|
+
/** 跟随节点 */
|
|
204
|
+
followTo?: string;
|
|
205
|
+
}
|
|
206
|
+
interface LayoutEdge {
|
|
207
|
+
id: string;
|
|
208
|
+
/** 线条实体 */
|
|
209
|
+
entity: WorkflowLineEntity;
|
|
210
|
+
/** 起点 */
|
|
211
|
+
from: string;
|
|
212
|
+
/** 终点 */
|
|
213
|
+
to: string;
|
|
214
|
+
/** 起点索引 */
|
|
215
|
+
fromIndex: string;
|
|
216
|
+
/** 终点索引 */
|
|
217
|
+
toIndex: string;
|
|
218
|
+
/** 线条名称 */
|
|
219
|
+
name: string;
|
|
220
|
+
}
|
|
221
|
+
interface LayoutParams {
|
|
222
|
+
container: LayoutNode;
|
|
223
|
+
layoutNodes: LayoutNode[];
|
|
224
|
+
layoutEdges: LayoutEdge[];
|
|
225
|
+
}
|
|
226
|
+
interface LayoutOptions {
|
|
227
|
+
/** Custom layout configuration to override default dagre settings. */
|
|
228
|
+
layoutConfig?: Partial<LayoutConfig>;
|
|
229
|
+
/** The container node entity used as the root for the layout. */
|
|
230
|
+
containerNode?: WorkflowNodeEntity;
|
|
231
|
+
/** Custom function to determine follow-node relationships between layout nodes. */
|
|
232
|
+
getFollowNode?: GetFollowNode;
|
|
233
|
+
/** Whether to animate node movements during layout positioning. */
|
|
234
|
+
enableAnimation?: boolean;
|
|
235
|
+
/** Duration of the position animation in milliseconds. Only effective when `enableAnimation` is true. */
|
|
236
|
+
animationDuration?: number;
|
|
237
|
+
/** When true, skips the fit-view step after layout is applied. */
|
|
238
|
+
disableFitView?: boolean;
|
|
239
|
+
/**
|
|
240
|
+
* When true, aligns nodes by their top edge instead of their center point.
|
|
241
|
+
* Defaults to false (center-aligned). Set to true to place all nodes' top edges on the same horizontal line.
|
|
242
|
+
*/
|
|
243
|
+
alignTopEdge?: boolean;
|
|
244
|
+
/** Filter function to exclude specific nodes from the layout. Return false to skip a node. */
|
|
245
|
+
filterNode?: (params: {
|
|
246
|
+
node: WorkflowNodeEntity;
|
|
247
|
+
parent?: WorkflowNodeEntity;
|
|
248
|
+
}) => boolean;
|
|
249
|
+
/** Filter function to exclude specific edges from the layout. Return false to skip an edge. */
|
|
250
|
+
filterLine?: (params: {
|
|
251
|
+
line: WorkflowLineEntity;
|
|
252
|
+
}) => boolean;
|
|
253
|
+
}
|
|
254
|
+
interface LayoutConfig {
|
|
255
|
+
/** Direction for rank nodes. Can be TB, BT, LR, or RL, where T = top, B = bottom, L = left, and R = right. */
|
|
256
|
+
rankdir: 'TB' | 'BT' | 'LR' | 'RL';
|
|
257
|
+
/** Alignment for rank nodes. Can be UL, UR, DL, or DR, where U = up, D = down, L = left, and R = right. */
|
|
258
|
+
align: 'UL' | 'UR' | 'DL' | 'DR' | undefined;
|
|
259
|
+
/** Number of pixels that separate nodes horizontally in the layout. */
|
|
260
|
+
nodesep: number;
|
|
261
|
+
/** Number of pixels that separate edges horizontally in the layout. */
|
|
262
|
+
edgesep: number;
|
|
263
|
+
/** Number of pixels that separate edges horizontally in the layout. */
|
|
264
|
+
ranksep: number;
|
|
265
|
+
/** Number of pixels to use as a margin around the left and right of the graph. */
|
|
266
|
+
marginx: number;
|
|
267
|
+
/** Number of pixels to use as a margin around the top and bottom of the graph. */
|
|
268
|
+
marginy: number;
|
|
269
|
+
/** If set to greedy, uses a greedy heuristic for finding a feedback arc set for a graph. A feedback arc set is a set of edges that can be removed to make a graph acyclic. */
|
|
270
|
+
acyclicer: 'greedy' | undefined;
|
|
271
|
+
/** Type of algorithm to assigns a rank to each node in the input graph. Possible values: network-simplex, tight-tree or longest-path */
|
|
272
|
+
ranker: 'network-simplex' | 'tight-tree' | 'longest-path';
|
|
273
|
+
}
|
|
274
|
+
type GetFollowNode = (node: LayoutNode, context: {
|
|
275
|
+
store: ILayoutStore;
|
|
276
|
+
/** 业务自定义参数 */
|
|
277
|
+
[key: string]: any;
|
|
278
|
+
}) => {
|
|
279
|
+
followTo?: string;
|
|
280
|
+
} | undefined;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
284
|
+
* SPDX-License-Identifier: MIT
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
interface AutoLayoutOptions {
|
|
288
|
+
layoutConfig?: Partial<LayoutConfig>;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Auto layout plugin - 自动布局插件
|
|
293
|
+
* https://flowgram.ai/guide/plugin/free-auto-layout-plugin.html
|
|
294
|
+
*/
|
|
295
|
+
declare const createFreeAutoLayoutPlugin: _flowgram_vue_core.PluginCreator<AutoLayoutOptions>;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
299
|
+
* SPDX-License-Identifier: MIT
|
|
300
|
+
*/
|
|
301
|
+
|
|
302
|
+
declare class Layout implements ILayout {
|
|
303
|
+
private readonly _store;
|
|
304
|
+
private readonly _layout;
|
|
305
|
+
private readonly _position;
|
|
306
|
+
constructor(config: LayoutConfig);
|
|
307
|
+
init(params: LayoutParams, options: LayoutOptions): void;
|
|
308
|
+
layout(): void;
|
|
309
|
+
position(): Promise<void>;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
314
|
+
* SPDX-License-Identifier: MIT
|
|
315
|
+
*/
|
|
316
|
+
|
|
317
|
+
declare class LayoutStore implements ILayoutStore {
|
|
318
|
+
readonly config: LayoutConfig;
|
|
319
|
+
private indexMap;
|
|
320
|
+
private init;
|
|
321
|
+
private store;
|
|
322
|
+
options: LayoutOptions;
|
|
323
|
+
container: LayoutNode;
|
|
324
|
+
constructor(config: LayoutConfig);
|
|
325
|
+
get initialized(): boolean;
|
|
326
|
+
getNode(id?: string): LayoutNode | undefined;
|
|
327
|
+
getNodeByIndex(index: string): LayoutNode | undefined;
|
|
328
|
+
getEdge(id: string): LayoutEdge | undefined;
|
|
329
|
+
get nodes(): LayoutNode[];
|
|
330
|
+
get edges(): LayoutEdge[];
|
|
331
|
+
create(params: LayoutParams, options: LayoutOptions): void;
|
|
332
|
+
/** 创建布局数据 */
|
|
333
|
+
private createStore;
|
|
334
|
+
/** 创建虚拟线条数据 */
|
|
335
|
+
private createVirtualEdges;
|
|
336
|
+
/** 创建节点索引映射 */
|
|
337
|
+
private createIndexMap;
|
|
338
|
+
/** 节点排序 */
|
|
339
|
+
private sortNodes;
|
|
340
|
+
/** 记录运行选项 */
|
|
341
|
+
private setOptions;
|
|
342
|
+
/** 设置跟随节点配置 */
|
|
343
|
+
private setFollowNode;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
348
|
+
* SPDX-License-Identifier: MIT
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
declare const DefaultLayoutConfig: LayoutConfig;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
355
|
+
* SPDX-License-Identifier: MIT
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
declare class AutoLayoutService {
|
|
359
|
+
private playground;
|
|
360
|
+
private readonly document;
|
|
361
|
+
private layoutConfig;
|
|
362
|
+
init(options: AutoLayoutOptions): void;
|
|
363
|
+
layout(options?: Partial<LayoutOptions>): Promise<void>;
|
|
364
|
+
private fitView;
|
|
365
|
+
private layoutNode;
|
|
366
|
+
private createLayoutNodes;
|
|
367
|
+
/** 创建节点布局数据 */
|
|
368
|
+
private createLayoutNode;
|
|
369
|
+
private createLayoutEdges;
|
|
370
|
+
/** 创建线条布局数据 */
|
|
371
|
+
private createLayoutEdge;
|
|
372
|
+
private getNodesAllLines;
|
|
373
|
+
private getLayoutNodeRect;
|
|
374
|
+
private layoutNodeRect;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export { AutoLayoutService, DefaultLayoutConfig, type GetFollowNode, Layout, type LayoutEdge, type LayoutNode, type LayoutOptions, LayoutStore, createFreeAutoLayoutPlugin, dagreLib };
|