|
@@ -6,12 +6,23 @@ import {
|
|
|
WorkflowNodeLinesData,
|
|
WorkflowNodeLinesData,
|
|
|
} from '@flowgram.ai/free-layout-core';
|
|
} from '@flowgram.ai/free-layout-core';
|
|
|
|
|
|
|
|
-import { Layout, type LayoutOptions } from './layout';
|
|
|
|
|
|
|
+import { AutoLayoutOptions } from './type';
|
|
|
|
|
+import { LayoutConfig } from './layout/type';
|
|
|
|
|
+import { DefaultLayoutConfig, Layout, type LayoutOptions } from './layout';
|
|
|
|
|
|
|
|
@injectable()
|
|
@injectable()
|
|
|
export class AutoLayoutService {
|
|
export class AutoLayoutService {
|
|
|
@inject(WorkflowDocument) private readonly document: WorkflowDocument;
|
|
@inject(WorkflowDocument) private readonly document: WorkflowDocument;
|
|
|
|
|
|
|
|
|
|
+ private layoutConfig: LayoutConfig = DefaultLayoutConfig;
|
|
|
|
|
+
|
|
|
|
|
+ public init(options: AutoLayoutOptions) {
|
|
|
|
|
+ this.layoutConfig = {
|
|
|
|
|
+ ...this.layoutConfig,
|
|
|
|
|
+ ...options.layoutConfig,
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public async layout(options: LayoutOptions = {}): Promise<void> {
|
|
public async layout(options: LayoutOptions = {}): Promise<void> {
|
|
|
await this.layoutNode(this.document.root, options);
|
|
await this.layoutNode(this.document.root, options);
|
|
|
}
|
|
}
|
|
@@ -29,7 +40,7 @@ export class AutoLayoutService {
|
|
|
// 先递归执行子节点 autoLayout
|
|
// 先递归执行子节点 autoLayout
|
|
|
await Promise.all(nodes.map(async (child) => this.layoutNode(child, options)));
|
|
await Promise.all(nodes.map(async (child) => this.layoutNode(child, options)));
|
|
|
|
|
|
|
|
- const layout = new Layout();
|
|
|
|
|
|
|
+ const layout = new Layout(this.layoutConfig);
|
|
|
layout.init({ nodes, edges, container: node }, options);
|
|
layout.init({ nodes, edges, container: node }, options);
|
|
|
layout.layout();
|
|
layout.layout();
|
|
|
await layout.position();
|
|
await layout.position();
|