@antv/layout 1.0.0-alpha.15 → 1.0.0-alpha.17

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/lib/Circular.d.ts CHANGED
@@ -5,14 +5,14 @@ import type { Graph, CircularLayoutOptions, Layout, LayoutMapping } from "./type
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new CircularLayout({ radius: 10 });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new CircularLayout({ radius: 10 });
12
- * const positions = layout.execute(graph, { radius: 20 }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { radius: 20 }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { radius: 20 });
15
+ * await layout.assign(graph, { radius: 20 });
16
16
  */
17
17
  export declare class CircularLayout implements Layout<CircularLayoutOptions> {
18
18
  options: CircularLayoutOptions;
@@ -21,10 +21,10 @@ export declare class CircularLayout implements Layout<CircularLayoutOptions> {
21
21
  /**
22
22
  * Return the positions of nodes and edges(if needed).
23
23
  */
24
- execute(graph: Graph, options?: CircularLayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: CircularLayoutOptions): Promise<LayoutMapping>;
25
25
  /**
26
26
  * To directly assign the positions to the nodes.
27
27
  */
28
- assign(graph: Graph, options?: CircularLayoutOptions): void;
28
+ assign(graph: Graph, options?: CircularLayoutOptions): Promise<void>;
29
29
  private genericCircularLayout;
30
30
  }
@@ -13,16 +13,6 @@ export interface Payload {
13
13
  nodes: Node<any>[];
14
14
  edges: Edge<any>[];
15
15
  }
16
- export declare const SupervisorEvent: {
17
- /**
18
- * Get triggerred when each iteration finished.
19
- */
20
- LAYOUT_ITERATION: string;
21
- /**
22
- * Get triggerred when layout calculation is done.
23
- */
24
- LAYOUT_END: string;
25
- };
26
16
  interface SupervisorOptions {
27
17
  /**
28
18
  * Iterations run in algorithm such as d3force, will be passed in `tick()` later.
@@ -34,21 +24,10 @@ interface SupervisorOptions {
34
24
  * const graph = new Graph();
35
25
  * const layout = new CircularLayout();
36
26
  *
37
- * const supervisor = new Supervisor(graph, layout, { auto: true });
38
- * supervisor.start();
27
+ * const supervisor = new Supervisor(graph, layout, { iterations: 1000 });
28
+ * const positions = await supervisor.execute();
39
29
  * supervisor.stop();
40
30
  * supervisor.kill();
41
- *
42
- * // lifecycle
43
- * supervisor.on('tick', () => {
44
- * });
45
- * supervisor.on('layoutend', () => {
46
- * });
47
- *
48
- * // Re-layout when graph changed.
49
- * graph.addNodes([{ id: 'node1' }, { id: 'node2' }]);
50
- *
51
- * // TODO: Custom layout.
52
31
  */
53
32
  export declare class Supervisor extends EventEmitter implements LayoutSupervisor {
54
33
  private graph;
@@ -64,7 +43,7 @@ export declare class Supervisor extends EventEmitter implements LayoutSupervisor
64
43
  private running;
65
44
  constructor(graph: Graph<any, any>, layout: Layout<any>, options?: Partial<SupervisorOptions> | undefined);
66
45
  spawnWorker(): void;
67
- start(): this;
46
+ execute(): Promise<any>;
68
47
  stop(): this;
69
48
  kill(): void;
70
49
  isRunning(): boolean;
@@ -5,14 +5,14 @@ import type { Graph, LayoutMapping, ConcentricLayoutOptions, Layout } from "./ty
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new ConcentricLayout({ nodeSpacing: 10 });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new ConcentricLayout({ nodeSpacing: 10});
12
- * const positions = layout.execute(graph, { nodeSpacing: 10 }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { nodeSpacing: 10 }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { nodeSpacing: 10 });
15
+ * await layout.assign(graph, { nodeSpacing: 10 });
16
16
  */
17
17
  export declare class ConcentricLayout implements Layout<ConcentricLayoutOptions> {
18
18
  options: ConcentricLayoutOptions;
@@ -21,10 +21,10 @@ export declare class ConcentricLayout implements Layout<ConcentricLayoutOptions>
21
21
  /**
22
22
  * Return the positions of nodes and edges(if needed).
23
23
  */
24
- execute(graph: Graph, options?: ConcentricLayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: ConcentricLayoutOptions): Promise<LayoutMapping>;
25
25
  /**
26
26
  * To directly assign the positions to the nodes.
27
27
  */
28
- assign(graph: Graph, options?: ConcentricLayoutOptions): void;
28
+ assign(graph: Graph, options?: ConcentricLayoutOptions): Promise<void>;
29
29
  private genericConcentricLayout;
30
30
  }
@@ -6,14 +6,14 @@ import { Graph, Node, LayoutMapping, OutNode, D3ForceLayoutOptions, Edge, Layout
6
6
  * @example
7
7
  * // Assign layout options when initialization.
8
8
  * const layout = new D3ForceLayout({ center: [100, 100] });
9
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
9
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
10
10
  *
11
11
  * // Or use different options later.
12
12
  * const layout = new D3ForceLayout({ center: [100, 100] });
13
- * const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
14
14
  *
15
15
  * // If you want to assign the positions directly to the nodes, use assign method.
16
- * layout.assign(graph, { center: [100, 100] });
16
+ * await layout.assign(graph, { center: [100, 100] });
17
17
  */
18
18
  export declare class D3ForceLayout implements LayoutWithIterations<D3ForceLayoutOptions> {
19
19
  options: D3ForceLayoutOptions;
@@ -23,25 +23,21 @@ export declare class D3ForceLayout implements LayoutWithIterations<D3ForceLayout
23
23
  private lastLayoutEdges;
24
24
  private lastAssign;
25
25
  private lastGraph;
26
- private lastOptions;
27
- private running;
28
26
  constructor(options?: D3ForceLayoutOptions);
29
27
  /**
30
28
  * Return the positions of nodes and edges(if needed).
31
29
  */
32
- execute(graph: Graph, options?: D3ForceLayoutOptions): LayoutMapping;
30
+ execute(graph: Graph, options?: D3ForceLayoutOptions): Promise<LayoutMapping>;
33
31
  /**
34
32
  * To directly assign the positions to the nodes.
35
33
  */
36
- assign(graph: Graph, options?: D3ForceLayoutOptions): void;
34
+ assign(graph: Graph, options?: D3ForceLayoutOptions): Promise<void>;
37
35
  /**
38
36
  * Stop simulation immediately.
39
37
  */
40
38
  stop(): void;
41
- restart(): void;
42
39
  /**
43
40
  * Manually steps the simulation by the specified number of iterations.
44
- * When finished it will trigger `onLayoutEnd` callback.
45
41
  * @see https://github.com/d3/d3-force#simulation_tick
46
42
  */
47
43
  tick(iterations?: number): {
@@ -6,14 +6,14 @@ import { CalcGraph, FormatedOptions } from "./types";
6
6
  * @example
7
7
  * // Assign layout options when initialization.
8
8
  * const layout = new ForceLayout({ center: [100, 100] });
9
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
9
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
10
10
  *
11
11
  * // Or use different options later.
12
12
  * const layout = new ForceLayout({ center: [100, 100] });
13
- * const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
14
14
  *
15
15
  * // If you want to assign the positions directly to the nodes, use assign method.
16
- * layout.assign(graph, { center: [100, 100] });
16
+ * await layout.assign(graph, { center: [100, 100] });
17
17
  */
18
18
  export declare class ForceLayout implements LayoutWithIterations<ForceLayoutOptions> {
19
19
  options: ForceLayoutOptions;
@@ -39,19 +39,17 @@ export declare class ForceLayout implements LayoutWithIterations<ForceLayoutOpti
39
39
  /**
40
40
  * Return the positions of nodes and edges(if needed).
41
41
  */
42
- execute(graph: Graph, options?: ForceLayoutOptions): LayoutMapping;
42
+ execute(graph: Graph, options?: ForceLayoutOptions): Promise<LayoutMapping>;
43
43
  /**
44
44
  * To directly assign the positions to the nodes.
45
45
  */
46
- assign(graph: Graph, options?: ForceLayoutOptions): void;
46
+ assign(graph: Graph, options?: ForceLayoutOptions): Promise<void>;
47
47
  /**
48
48
  * Stop simulation immediately.
49
49
  */
50
50
  stop(): void;
51
- restart(): void;
52
51
  /**
53
52
  * Manually steps the simulation by the specified number of iterations.
54
- * When finished it will trigger `onLayoutEnd` callback.
55
53
  * @see https://github.com/d3/d3-force#simulation_tick
56
54
  */
57
55
  tick(iterations?: number): LayoutMapping;
@@ -1,34 +1,31 @@
1
- import type { Graph, LayoutMapping, ForceAtlas2LayoutOptions, LayoutWithIterations } from "../types";
1
+ import type { Graph, LayoutMapping, ForceAtlas2LayoutOptions, Layout } from "../types";
2
2
  /**
3
3
  * Layout nodes with force atlas 2 model
4
4
  *
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new ForceAtlas2Layout({ center: [100, 100] });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new ForceAtlas2Layout({ center: [100, 100] });
12
- * const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { center: [100, 100] });
15
+ * await layout.assign(graph, { center: [100, 100] });
16
16
  */
17
- export declare class ForceAtlas2Layout implements LayoutWithIterations<ForceAtlas2LayoutOptions> {
17
+ export declare class ForceAtlas2Layout implements Layout<ForceAtlas2LayoutOptions> {
18
18
  options: ForceAtlas2LayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: ForceAtlas2LayoutOptions);
21
- stop: () => void;
22
- restart: () => void;
23
- tick: (iterations?: number | undefined) => LayoutMapping;
24
21
  /**
25
22
  * Return the positions of nodes and edges(if needed).
26
23
  */
27
- execute(graph: Graph, options?: ForceAtlas2LayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: ForceAtlas2LayoutOptions): Promise<LayoutMapping>;
28
25
  /**
29
26
  * To directly assign the positions to the nodes.
30
27
  */
31
- assign(graph: Graph, options?: ForceAtlas2LayoutOptions): void;
28
+ assign(graph: Graph, options?: ForceAtlas2LayoutOptions): Promise<void>;
32
29
  private genericForceAtlas2Layout;
33
30
  /**
34
31
  * Init the node positions if there is no initial positions.
@@ -5,14 +5,14 @@ import type { Graph, LayoutMapping, FruchtermanLayoutOptions, LayoutWithIteratio
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new FruchtermanLayout({ center: [100, 100] });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new FruchtermanLayout({ center: [100, 100] });
12
- * const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { center: [100, 100] });
15
+ * await layout.assign(graph, { center: [100, 100] });
16
16
  */
17
17
  export declare class FruchtermanLayout implements LayoutWithIterations<FruchtermanLayoutOptions> {
18
18
  options: FruchtermanLayoutOptions;
@@ -30,19 +30,17 @@ export declare class FruchtermanLayout implements LayoutWithIterations<Fruchterm
30
30
  /**
31
31
  * Return the positions of nodes and edges(if needed).
32
32
  */
33
- execute(graph: Graph, options?: FruchtermanLayoutOptions): LayoutMapping;
33
+ execute(graph: Graph, options?: FruchtermanLayoutOptions): Promise<LayoutMapping>;
34
34
  /**
35
35
  * To directly assign the positions to the nodes.
36
36
  */
37
- assign(graph: Graph, options?: FruchtermanLayoutOptions): void;
37
+ assign(graph: Graph, options?: FruchtermanLayoutOptions): Promise<void>;
38
38
  /**
39
39
  * Stop simulation immediately.
40
40
  */
41
41
  stop(): void;
42
- restart(): void;
43
42
  /**
44
43
  * Manually steps the simulation by the specified number of iterations.
45
- * When finished it will trigger `onLayoutEnd` callback.
46
44
  * @see https://github.com/d3/d3-force#simulation_tick
47
45
  */
48
46
  tick(iterations?: number): LayoutMapping;
package/lib/grid.d.ts CHANGED
@@ -5,14 +5,14 @@ import type { Graph, GridLayoutOptions, LayoutMapping, Layout } from "./types";
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new GridLayout({ rows: 10 });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new GridLayout({ rows: 10 });
12
- * const positions = layout.execute(graph, { rows: 20 }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { rows: 20 }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { rows: 20 });
15
+ * await layout.assign(graph, { rows: 20 });
16
16
  */
17
17
  export declare class GridLayout implements Layout<GridLayoutOptions> {
18
18
  options: GridLayoutOptions;
@@ -21,10 +21,10 @@ export declare class GridLayout implements Layout<GridLayoutOptions> {
21
21
  /**
22
22
  * Return the positions of nodes and edges(if needed).
23
23
  */
24
- execute(graph: Graph, options?: GridLayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: GridLayoutOptions): Promise<LayoutMapping>;
25
25
  /**
26
26
  * To directly assign the positions to the nodes.
27
27
  */
28
- assign(graph: Graph, options?: GridLayoutOptions): void;
28
+ assign(graph: Graph, options?: GridLayoutOptions): Promise<void>;
29
29
  private genericGridLayout;
30
30
  }
package/lib/mds.d.ts CHANGED
@@ -5,14 +5,14 @@ import type { Graph, LayoutMapping, MDSLayoutOptions, Layout } from "./types";
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new MDSLayout({ center: [100, 100] });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new MDSLayout({ center: [100, 100] });
12
- * const positions = layout.execute(graph, { rows: 20 }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { rows: 20 }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { center: [100, 100] });
15
+ * await layout.assign(graph, { center: [100, 100] });
16
16
  */
17
17
  export declare class MDSLayout implements Layout<MDSLayoutOptions> {
18
18
  options: MDSLayoutOptions;
@@ -21,10 +21,10 @@ export declare class MDSLayout implements Layout<MDSLayoutOptions> {
21
21
  /**
22
22
  * Return the positions of nodes and edges(if needed).
23
23
  */
24
- execute(graph: Graph, options?: MDSLayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: MDSLayoutOptions): Promise<LayoutMapping>;
25
25
  /**
26
26
  * To directly assign the positions to the nodes.
27
27
  */
28
- assign(graph: Graph, options?: MDSLayoutOptions): void;
28
+ assign(graph: Graph, options?: MDSLayoutOptions): Promise<void>;
29
29
  private genericMDSLayout;
30
30
  }
@@ -5,14 +5,14 @@ import type { Graph, LayoutMapping, RadialLayoutOptions, Layout } from "../types
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new RadialLayout({ focusNode: 'node0' });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new RadialLayout({ focusNode: 'node0' });
12
- * const positions = layout.execute(graph, { focusNode: 'node0' }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { focusNode: 'node0' }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { focusNode: 'node0' });
15
+ * await layout.assign(graph, { focusNode: 'node0' });
16
16
  */
17
17
  export declare class RadialLayout implements Layout<RadialLayoutOptions> {
18
18
  options: RadialLayoutOptions;
@@ -21,11 +21,11 @@ export declare class RadialLayout implements Layout<RadialLayoutOptions> {
21
21
  /**
22
22
  * Return the positions of nodes and edges(if needed).
23
23
  */
24
- execute(graph: Graph, options?: RadialLayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: RadialLayoutOptions): Promise<LayoutMapping>;
25
25
  /**
26
26
  * To directly assign the positions to the nodes.
27
27
  */
28
- assign(graph: Graph, options?: RadialLayoutOptions): void;
28
+ assign(graph: Graph, options?: RadialLayoutOptions): Promise<void>;
29
29
  private genericRadialLayout;
30
30
  private run;
31
31
  private oneIteration;
package/lib/random.d.ts CHANGED
@@ -5,14 +5,14 @@ import type { Graph, LayoutMapping, RandomLayoutOptions, Layout } from "./types"
5
5
  * @example
6
6
  * // Assign layout options when initialization.
7
7
  * const layout = new RandomLayout({ center: [100, 100] });
8
- * const positions = layout.execute(graph); // { nodes: [], edges: [] }
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
9
  *
10
10
  * // Or use different options later.
11
11
  * const layout = new RandomLayout({ center: [100, 100] });
12
- * const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
12
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
13
  *
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
- * layout.assign(graph, { center: [100, 100] });
15
+ * await layout.assign(graph, { center: [100, 100] });
16
16
  */
17
17
  export declare class RandomLayout implements Layout<RandomLayoutOptions> {
18
18
  options: RandomLayoutOptions;
@@ -21,10 +21,10 @@ export declare class RandomLayout implements Layout<RandomLayoutOptions> {
21
21
  /**
22
22
  * Return the positions of nodes and edges(if needed).
23
23
  */
24
- execute(graph: Graph, options?: RandomLayoutOptions): LayoutMapping;
24
+ execute(graph: Graph, options?: RandomLayoutOptions): Promise<LayoutMapping>;
25
25
  /**
26
26
  * To directly assign the positions to the nodes.
27
27
  */
28
- assign(graph: Graph, options?: RandomLayoutOptions): void;
28
+ assign(graph: Graph, options?: RandomLayoutOptions): Promise<void>;
29
29
  private genericRandomLayout;
30
30
  }
package/lib/types.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Graph as IGraph, Node as INode, Edge as IEdge, PlainObject, GraphView as IGraphView } from "@antv/graphlib";
2
2
  export interface NodeData extends PlainObject {
3
- visible?: boolean;
4
3
  size?: number | number[];
5
4
  bboxSize?: number[];
6
5
  }
@@ -9,7 +8,6 @@ export interface OutNodeData extends NodeData {
9
8
  y: number;
10
9
  }
11
10
  export interface EdgeData extends PlainObject {
12
- visible?: boolean;
13
11
  virtual?: boolean;
14
12
  }
15
13
  /** input node */
@@ -42,11 +40,11 @@ export interface Layout<LayoutOptions> {
42
40
  /**
43
41
  * To directly assign the positions to the nodes.
44
42
  */
45
- assign(graph: Graph, options?: LayoutOptions): void;
43
+ assign(graph: Graph, options?: LayoutOptions): Promise<void>;
46
44
  /**
47
45
  * Return the positions of nodes and edges(if needed).
48
46
  */
49
- execute(graph: Graph, options?: LayoutOptions): LayoutMapping;
47
+ execute(graph: Graph, options?: LayoutOptions): Promise<LayoutMapping>;
50
48
  /**
51
49
  * Layout options, can be changed in runtime.
52
50
  */
@@ -64,11 +62,6 @@ export interface LayoutWithIterations<LayoutOptions> extends Layout<LayoutOption
64
62
  * @see https://github.com/d3/d3-force#simulation_stop
65
63
  */
66
64
  stop: () => void;
67
- /**
68
- * Restarts the simulation’s internal timer and returns the simulation.
69
- * @see https://github.com/d3/d3-force#simulation_restart
70
- */
71
- restart: () => void;
72
65
  /**
73
66
  * Manually steps the simulation by the specified number of iterations.
74
67
  * @see https://github.com/d3/d3-force#simulation_tick
@@ -79,15 +72,12 @@ export interface LayoutConstructor<LayoutOptions> {
79
72
  new (options?: LayoutOptions): Layout<LayoutOptions>;
80
73
  }
81
74
  export interface LayoutSupervisor {
82
- start(): void;
75
+ execute(): Promise<LayoutMapping>;
83
76
  stop(): void;
84
77
  kill(): void;
85
78
  isRunning(): boolean;
86
79
  }
87
- interface CommonOptions {
88
- onLayoutEnd?: (data: LayoutMapping) => void;
89
- }
90
- export interface CircularLayoutOptions extends CommonOptions {
80
+ export interface CircularLayoutOptions {
91
81
  center?: PointTuple;
92
82
  width?: number;
93
83
  height?: number;
@@ -103,7 +93,7 @@ export interface CircularLayoutOptions extends CommonOptions {
103
93
  nodeSpacing?: ((node?: Node) => number) | number;
104
94
  nodeSize?: number | number[];
105
95
  }
106
- export interface GridLayoutOptions extends CommonOptions {
96
+ export interface GridLayoutOptions {
107
97
  width?: number;
108
98
  height?: number;
109
99
  begin?: PointTuple;
@@ -120,16 +110,16 @@ export interface GridLayoutOptions extends CommonOptions {
120
110
  };
121
111
  nodeSpacing?: ((node?: Node) => number) | number;
122
112
  }
123
- export interface RandomLayoutOptions extends CommonOptions {
113
+ export interface RandomLayoutOptions {
124
114
  center?: PointTuple;
125
115
  width?: number;
126
116
  height?: number;
127
117
  }
128
- export interface MDSLayoutOptions extends CommonOptions {
118
+ export interface MDSLayoutOptions {
129
119
  center?: PointTuple;
130
120
  linkDistance?: number;
131
121
  }
132
- export interface ConcentricLayoutOptions extends CommonOptions {
122
+ export interface ConcentricLayoutOptions {
133
123
  center?: PointTuple;
134
124
  preventOverlap?: boolean;
135
125
  nodeSize?: number | PointTuple;
@@ -143,7 +133,7 @@ export interface ConcentricLayoutOptions extends CommonOptions {
143
133
  height?: number;
144
134
  nodeSpacing?: number | number[] | ((node?: Node) => number);
145
135
  }
146
- export interface RadialLayoutOptions extends CommonOptions {
136
+ export interface RadialLayoutOptions {
147
137
  center?: PointTuple;
148
138
  width?: number;
149
139
  height?: number;
@@ -159,7 +149,7 @@ export interface RadialLayoutOptions extends CommonOptions {
159
149
  sortBy?: string;
160
150
  sortStrength?: number;
161
151
  }
162
- export interface DagreLayoutOptions extends CommonOptions {
152
+ export interface DagreLayoutOptions {
163
153
  rankdir?: "TB" | "BT" | "LR" | "RL";
164
154
  align?: "UL" | "UR" | "DL" | "DR";
165
155
  begin?: PointTuple;
@@ -179,7 +169,7 @@ export interface DagreLayoutOptions extends CommonOptions {
179
169
  nodesepFunc?: (d?: Node) => number;
180
170
  ranksepFunc?: (d?: Node) => number;
181
171
  }
182
- export interface D3ForceLayoutOptions extends CommonOptions {
172
+ export interface D3ForceLayoutOptions {
183
173
  center?: PointTuple;
184
174
  linkDistance?: number | ((edge?: Edge) => number);
185
175
  edgeStrength?: number | ((edge?: Edge) => number);
@@ -214,7 +204,7 @@ export interface CentripetalOptions {
214
204
  centerStrength?: number;
215
205
  };
216
206
  }
217
- export interface ForceLayoutOptions extends CommonOptions {
207
+ export interface ForceLayoutOptions {
218
208
  center?: PointTuple;
219
209
  width?: number;
220
210
  height?: number;
@@ -249,7 +239,7 @@ export interface ForceLayoutOptions extends CommonOptions {
249
239
  iterations: number;
250
240
  }) => void;
251
241
  }
252
- export interface ForceAtlas2LayoutOptions extends CommonOptions {
242
+ export interface ForceAtlas2LayoutOptions {
253
243
  center?: PointTuple;
254
244
  width?: number;
255
245
  height?: number;
@@ -267,7 +257,7 @@ export interface ForceAtlas2LayoutOptions extends CommonOptions {
267
257
  nodeSize?: number | number[] | ((node?: Node) => number);
268
258
  onTick?: (data: LayoutMapping) => void;
269
259
  }
270
- export interface FruchtermanLayoutOptions extends CommonOptions {
260
+ export interface FruchtermanLayoutOptions {
271
261
  center?: PointTuple;
272
262
  maxIteration?: number;
273
263
  width?: number;
@@ -279,4 +269,3 @@ export interface FruchtermanLayoutOptions extends CommonOptions {
279
269
  nodeClusterBy?: string;
280
270
  onTick?: (data: LayoutMapping) => void;
281
271
  }
282
- export {};
@@ -1,18 +1,16 @@
1
- import { PointTuple, LayoutMapping, Graph } from "../types";
1
+ import { PointTuple, Graph } from "../types";
2
2
  /**
3
3
  * Assign or only return the result for the graph who has no nodes or only one node.
4
4
  * @param graph original graph
5
5
  * @param assign whether assign result to original graph
6
6
  * @param center the layout center
7
- * @param onLayoutEnd callback for layout end
8
7
  * @returns
9
8
  */
10
- export declare const handleSingleNodeGraph: (graph: Graph, assign: boolean, center: PointTuple, onLayoutEnd?: ((data: LayoutMapping) => void) | undefined) => {
9
+ export declare const handleSingleNodeGraph: (graph: Graph, assign: boolean, center: PointTuple) => {
11
10
  nodes: {
12
11
  data: {
13
12
  x: number;
14
13
  y: number;
15
- visible?: boolean | undefined;
16
14
  size?: number | number[] | undefined;
17
15
  bboxSize?: number[] | undefined;
18
16
  };
package/lib/worker.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { Payload } from "./supervisor";
2
2
  export declare function stopLayout(): void;
3
- export declare function calculateLayout(payload: Payload, transferables: Float32Array[]): Promise<unknown>;
3
+ export declare function calculateLayout(payload: Payload, transferables: Float32Array[]): Promise<(import("./types").LayoutMapping | Float32Array[])[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/layout",
3
- "version": "1.0.0-alpha.15",
3
+ "version": "1.0.0-alpha.17",
4
4
  "description": "graph layout algorithm",
5
5
  "main": "dist/index.min.js",
6
6
  "module": "esm/index.esm.js",
@@ -21,7 +21,7 @@
21
21
  "antv"
22
22
  ],
23
23
  "dependencies": {
24
- "@antv/graphlib": "^2.0.0-alpha.3",
24
+ "@antv/graphlib": "^2.0.0",
25
25
  "@antv/util": "^3.0.0",
26
26
  "@naoak/workerize-transferable": "^0.1.0",
27
27
  "d3-force": "^3.0.0",