@antv/layout 1.0.0-alpha.8 → 1.0.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.
Files changed (68) hide show
  1. package/README.md +223 -22
  2. package/dist/c1c68049e416ee50a3be.worker.js +2 -0
  3. package/dist/c1c68049e416ee50a3be.worker.js.map +1 -0
  4. package/dist/index.min.js +1 -1
  5. package/dist/index.min.js.map +1 -1
  6. package/esm/c1c68049e416ee50a3be.worker.js +2 -0
  7. package/esm/c1c68049e416ee50a3be.worker.js.map +1 -0
  8. package/esm/index.esm.js +1 -1
  9. package/esm/index.esm.js.map +1 -1
  10. package/lib/{Circular.d.ts → circular.d.ts} +7 -7
  11. package/lib/concentric.d.ts +7 -7
  12. package/lib/d3Force/forceInBox.d.ts +8 -8
  13. package/lib/d3Force/index.d.ts +26 -10
  14. package/lib/dagre/acyclic.d.ts +4 -0
  15. package/lib/dagre/add-border-segments.d.ts +2 -0
  16. package/lib/dagre/coordinate-system.d.ts +4 -0
  17. package/lib/dagre/data/list.d.ts +12 -0
  18. package/lib/dagre/greedy-fas.d.ts +3 -0
  19. package/lib/dagre/layout.d.ts +18 -0
  20. package/lib/dagre/nesting-graph.d.ts +8 -0
  21. package/lib/dagre/normalize.d.ts +5 -0
  22. package/lib/dagre/order/add-subgraph-constraints.d.ts +3 -0
  23. package/lib/dagre/order/barycenter.d.ts +14 -0
  24. package/lib/dagre/order/build-layer-graph.d.ts +3 -0
  25. package/lib/dagre/order/cross-count.d.ts +3 -0
  26. package/lib/dagre/order/index.d.ts +2 -0
  27. package/lib/dagre/order/init-data-order.d.ts +6 -0
  28. package/lib/dagre/order/init-order.d.ts +3 -0
  29. package/lib/dagre/order/resolve-conflicts.d.ts +20 -0
  30. package/lib/dagre/order/sort-subgraph.d.ts +7 -0
  31. package/lib/dagre/order/sort.d.ts +7 -0
  32. package/lib/dagre/parent-dummy-chains.d.ts +3 -0
  33. package/lib/dagre/position/bk.d.ts +25 -0
  34. package/lib/dagre/position/index.d.ts +7 -0
  35. package/lib/dagre/rank/feasible-tree.d.ts +5 -0
  36. package/lib/dagre/rank/index.d.ts +2 -0
  37. package/lib/dagre/rank/network-simplex.d.ts +16 -0
  38. package/lib/dagre/rank/util.d.ts +6 -0
  39. package/lib/dagre/util.d.ts +35 -0
  40. package/lib/dagre.d.ts +31 -0
  41. package/lib/force/index.d.ts +25 -12
  42. package/lib/force/types.d.ts +3 -3
  43. package/lib/forceAtlas2/body.d.ts +33 -0
  44. package/lib/forceAtlas2/index.d.ts +106 -0
  45. package/lib/forceAtlas2/quad.d.ts +27 -0
  46. package/lib/forceAtlas2/quadTree.d.ts +20 -0
  47. package/lib/fruchterman.d.ts +53 -0
  48. package/lib/grid.d.ts +7 -7
  49. package/lib/index.d.ts +5 -0
  50. package/lib/mds.d.ts +7 -7
  51. package/lib/radial/index.d.ts +7 -7
  52. package/lib/radial/{RadialNonoverlapForce.d.ts → radial-nonoverlap-force.d.ts} +1 -1
  53. package/lib/random.d.ts +7 -7
  54. package/lib/registry.d.ts +3 -3
  55. package/lib/supervisor.d.ts +51 -0
  56. package/lib/types.d.ts +137 -60
  57. package/lib/util/function.d.ts +7 -1
  58. package/lib/util/math.d.ts +1 -1
  59. package/lib/util/number.d.ts +0 -2
  60. package/lib/util/object.d.ts +5 -5
  61. package/lib/util/string.d.ts +0 -1
  62. package/lib/worker.d.ts +2 -1
  63. package/package.json +16 -5
  64. package/dist/e4d617f312325ea0e2e1.worker.js +0 -2
  65. package/dist/e4d617f312325ea0e2e1.worker.js.map +0 -1
  66. package/esm/e4d617f312325ea0e2e1.worker.js +0 -2
  67. package/esm/e4d617f312325ea0e2e1.worker.js.map +0 -1
  68. package/lib/Supervisor.d.ts +0 -65
@@ -0,0 +1,106 @@
1
+ import type { Graph, LayoutMapping, ForceAtlas2LayoutOptions, Layout } from "../types";
2
+ /**
3
+ * Layout nodes with force atlas 2 model
4
+ *
5
+ * @example
6
+ * // Assign layout options when initialization.
7
+ * const layout = new ForceAtlas2Layout({ center: [100, 100] });
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
+ *
10
+ * // Or use different options later.
11
+ * const layout = new ForceAtlas2Layout({ center: [100, 100] });
12
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
+ *
14
+ * // If you want to assign the positions directly to the nodes, use assign method.
15
+ * await layout.assign(graph, { center: [100, 100] });
16
+ */
17
+ export declare class ForceAtlas2Layout implements Layout<ForceAtlas2LayoutOptions> {
18
+ options: ForceAtlas2LayoutOptions;
19
+ id: string;
20
+ constructor(options?: ForceAtlas2LayoutOptions);
21
+ /**
22
+ * Return the positions of nodes and edges(if needed).
23
+ */
24
+ execute(graph: Graph, options?: ForceAtlas2LayoutOptions): Promise<LayoutMapping>;
25
+ /**
26
+ * To directly assign the positions to the nodes.
27
+ */
28
+ assign(graph: Graph, options?: ForceAtlas2LayoutOptions): Promise<void>;
29
+ private genericForceAtlas2Layout;
30
+ /**
31
+ * Init the node positions if there is no initial positions.
32
+ * And pre-calculate the size (max of width and height) for each node.
33
+ * @param calcGraph graph for calculation
34
+ * @param graph origin graph
35
+ * @param nodeSize node size config from layout options
36
+ * @returns {SizeMap} node'id mapped to max of its width and height
37
+ */
38
+ private getSizes;
39
+ /**
40
+ * Format the options.
41
+ * @param options input options
42
+ * @param nodeNum number of nodes
43
+ * @returns formatted options
44
+ */
45
+ private formatOptions;
46
+ /**
47
+ * Loops for fa2.
48
+ * @param calcGraph graph for calculation
49
+ * @param graph original graph
50
+ * @param iteration iteration number
51
+ * @param sizes nodes' size
52
+ * @param options formatted layout options
53
+ * @returns
54
+ */
55
+ private run;
56
+ /**
57
+ * One step for a loop.
58
+ * @param graph graph for calculation
59
+ * @param params parameters for a loop
60
+ * @param options formatted layout's input options
61
+ * @returns
62
+ */
63
+ private oneStep;
64
+ /**
65
+ * Calculate the attract forces for nodes.
66
+ * @param graph graph for calculation
67
+ * @param iter current iteration index
68
+ * @param preventOverlapIters the iteration number for preventing overlappings
69
+ * @param sizes nodes' sizes
70
+ * @param forces forces for nodes, which will be modified
71
+ * @param options formatted layout's input options
72
+ * @returns
73
+ */
74
+ private getAttrForces;
75
+ /**
76
+ * Calculate the repulsive forces for nodes under barnesHut mode.
77
+ * @param graph graph for calculatiion
78
+ * @param forces forces for nodes, which will be modified
79
+ * @param bodies force body map
80
+ * @param options formatted layout's input options
81
+ * @returns
82
+ */
83
+ private getOptRepGraForces;
84
+ /**
85
+ * Calculate the repulsive forces for nodes.
86
+ * @param graph graph for calculatiion
87
+ * @param iter current iteration index
88
+ * @param preventOverlapIters the iteration number for preventing overlappings
89
+ * @param forces forces for nodes, which will be modified
90
+ * @param krPrime larger the krPrime, larger the repulsive force
91
+ * @param sizes nodes' sizes
92
+ * @param options formatted layout's input options
93
+ * @returns
94
+ */
95
+ private getRepGraForces;
96
+ /**
97
+ * Update node positions.
98
+ * @param graph graph for calculatiion
99
+ * @param forces forces for nodes, which will be modified
100
+ * @param preForces previous forces for nodes, which will be modified
101
+ * @param sg constant for move distance of one step
102
+ * @param options formatted layout's input options
103
+ * @returns
104
+ */
105
+ private updatePos;
106
+ }
@@ -0,0 +1,27 @@
1
+ import { PointTuple } from "../types";
2
+ /**
3
+ * @fileOverview quad
4
+ * @author shiwu.wyy@antfin.com
5
+ */
6
+ declare type QuadProps = {
7
+ xmid: number;
8
+ ymid: number;
9
+ length: number;
10
+ massCenter?: PointTuple;
11
+ mass?: number;
12
+ };
13
+ export default class Quad {
14
+ xmid: number;
15
+ ymid: number;
16
+ length: number;
17
+ massCenter: PointTuple;
18
+ mass: number;
19
+ constructor(params: QuadProps);
20
+ getLength(): number;
21
+ contains(x: number, y: number): boolean;
22
+ NW(): Quad;
23
+ NE(): Quad;
24
+ SW(): Quad;
25
+ SE(): Quad;
26
+ }
27
+ export {};
@@ -0,0 +1,20 @@
1
+ import Body from './body';
2
+ import Quad from './quad';
3
+ /**
4
+ * @fileOverview quadTree
5
+ * @author shiwu.wyy@antfin.com
6
+ */
7
+ export default class QuadTree {
8
+ body: Body | null;
9
+ quad: Quad | null;
10
+ theta: number;
11
+ NW: QuadTree | null;
12
+ NE: QuadTree | null;
13
+ SW: QuadTree | null;
14
+ SE: QuadTree | null;
15
+ constructor(param: Quad | null);
16
+ insert(bo: Body): void;
17
+ _putBody(bo: Body): void;
18
+ _isExternal(): boolean;
19
+ updateForce(bo: Body): void;
20
+ }
@@ -0,0 +1,53 @@
1
+ import type { Graph, LayoutMapping, FruchtermanLayoutOptions, LayoutWithIterations } from "./types";
2
+ /**
3
+ * Layout with fructherman force model
4
+ *
5
+ * @example
6
+ * // Assign layout options when initialization.
7
+ * const layout = new FruchtermanLayout({ center: [100, 100] });
8
+ * const positions = await layout.execute(graph); // { nodes: [], edges: [] }
9
+ *
10
+ * // Or use different options later.
11
+ * const layout = new FruchtermanLayout({ center: [100, 100] });
12
+ * const positions = await layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
13
+ *
14
+ * // If you want to assign the positions directly to the nodes, use assign method.
15
+ * await layout.assign(graph, { center: [100, 100] });
16
+ */
17
+ export declare class FruchtermanLayout implements LayoutWithIterations<FruchtermanLayoutOptions> {
18
+ options: FruchtermanLayoutOptions;
19
+ id: string;
20
+ private timeInterval;
21
+ private running;
22
+ private lastLayoutNodes;
23
+ private lastLayoutEdges;
24
+ private lastAssign;
25
+ private lastGraph;
26
+ private lastOptions;
27
+ private lastClusterMap;
28
+ private lastResult;
29
+ constructor(options?: FruchtermanLayoutOptions);
30
+ /**
31
+ * Return the positions of nodes and edges(if needed).
32
+ */
33
+ execute(graph: Graph, options?: FruchtermanLayoutOptions): Promise<LayoutMapping>;
34
+ /**
35
+ * To directly assign the positions to the nodes.
36
+ */
37
+ assign(graph: Graph, options?: FruchtermanLayoutOptions): Promise<void>;
38
+ /**
39
+ * Stop simulation immediately.
40
+ */
41
+ stop(): void;
42
+ /**
43
+ * Manually steps the simulation by the specified number of iterations.
44
+ * @see https://github.com/d3/d3-force#simulation_tick
45
+ */
46
+ tick(iterations?: number): LayoutMapping;
47
+ private genericFruchtermanLayout;
48
+ private formatOptions;
49
+ private runOneStep;
50
+ private applyCalculate;
51
+ private calRepulsive;
52
+ private calAttractive;
53
+ }
package/lib/grid.d.ts CHANGED
@@ -1,30 +1,30 @@
1
- import type { Graph, GridLayoutOptions, LayoutMapping, SyncLayout } from "./types";
1
+ import type { Graph, GridLayoutOptions, LayoutMapping, Layout } from "./types";
2
2
  /**
3
3
  * Layout arranging the nodes in a grid.
4
4
  *
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
- export declare class GridLayout implements SyncLayout<GridLayoutOptions> {
17
+ export declare class GridLayout implements Layout<GridLayoutOptions> {
18
18
  options: GridLayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: 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/index.d.ts CHANGED
@@ -6,5 +6,10 @@ export * from "./random";
6
6
  export * from "./mds";
7
7
  export * from "./concentric";
8
8
  export * from "./radial";
9
+ export * from "./fruchterman";
9
10
  export * from "./d3Force";
10
11
  export * from "./force";
12
+ export * from "./forceAtlas2";
13
+ export * from "./dagre";
14
+ export * from "./types";
15
+ export * from "./util";
package/lib/mds.d.ts CHANGED
@@ -1,30 +1,30 @@
1
- import type { Graph, LayoutMapping, MDSLayoutOptions, SyncLayout } from "./types";
1
+ import type { Graph, LayoutMapping, MDSLayoutOptions, Layout } from "./types";
2
2
  /**
3
3
  * Layout arranging the nodes with multiple dimensional scaling algorithm
4
4
  *
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
- export declare class MDSLayout implements SyncLayout<MDSLayoutOptions> {
17
+ export declare class MDSLayout implements Layout<MDSLayoutOptions> {
18
18
  options: MDSLayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: 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
  }
@@ -1,31 +1,31 @@
1
- import type { Graph, LayoutMapping, RadialLayoutOptions, SyncLayout } from "../types";
1
+ import type { Graph, LayoutMapping, RadialLayoutOptions, Layout } from "../types";
2
2
  /**
3
3
  * Layout arranging the nodes' on a radial shape
4
4
  *
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
- export declare class RadialLayout implements SyncLayout<RadialLayoutOptions> {
17
+ export declare class RadialLayout implements Layout<RadialLayoutOptions> {
18
18
  options: RadialLayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: 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;
@@ -1,5 +1,5 @@
1
1
  import type { Graph, Node, Point } from "../types";
2
- export type RadialNonoverlapForceOptions = {
2
+ export declare type RadialNonoverlapForceOptions = {
3
3
  positions: Point[];
4
4
  focusIdx: number;
5
5
  radii: number[];
package/lib/random.d.ts CHANGED
@@ -1,30 +1,30 @@
1
- import type { Graph, LayoutMapping, RandomLayoutOptions, SyncLayout } from "./types";
1
+ import type { Graph, LayoutMapping, RandomLayoutOptions, Layout } from "./types";
2
2
  /**
3
3
  * Layout randomizing the nodes' position
4
4
  *
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
- export declare class RandomLayout implements SyncLayout<RandomLayoutOptions> {
17
+ export declare class RandomLayout implements Layout<RandomLayoutOptions> {
18
18
  options: RandomLayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: 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/registry.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { SyncLayoutConstructor } from "./types";
2
- export declare const registry: Record<string, SyncLayoutConstructor<any>>;
3
- export declare function registerLayout(id: string, layout: SyncLayoutConstructor<any>): void;
1
+ import type { LayoutConstructor } from "./types";
2
+ export declare const registry: Record<string, LayoutConstructor<any>>;
3
+ export declare function registerLayout(id: string, layout: LayoutConstructor<any>): void;
@@ -0,0 +1,51 @@
1
+ import EventEmitter from "eventemitter3";
2
+ import { Graph, Node, Edge } from "@antv/graphlib";
3
+ import type { Layout, LayoutSupervisor } from "./types";
4
+ /**
5
+ * The payload transferred from main thread to the worker.
6
+ */
7
+ export interface Payload {
8
+ layout: {
9
+ id: string;
10
+ options: any;
11
+ iterations: number;
12
+ };
13
+ nodes: Node<any>[];
14
+ edges: Edge<any>[];
15
+ }
16
+ interface SupervisorOptions {
17
+ /**
18
+ * Iterations run in algorithm such as d3force, will be passed in `tick()` later.
19
+ */
20
+ iterations: number;
21
+ }
22
+ /**
23
+ * @example
24
+ * const graph = new Graph();
25
+ * const layout = new CircularLayout();
26
+ *
27
+ * const supervisor = new Supervisor(graph, layout, { iterations: 1000 });
28
+ * const positions = await supervisor.execute();
29
+ * supervisor.stop();
30
+ * supervisor.kill();
31
+ */
32
+ export declare class Supervisor extends EventEmitter implements LayoutSupervisor {
33
+ private graph;
34
+ private layout;
35
+ private options?;
36
+ /**
37
+ * Internal worker.
38
+ */
39
+ private worker;
40
+ /**
41
+ * Flag of running state.
42
+ */
43
+ private running;
44
+ constructor(graph: Graph<any, any>, layout: Layout<any>, options?: Partial<SupervisorOptions>);
45
+ spawnWorker(): void;
46
+ execute(): Promise<any>;
47
+ stop(): this;
48
+ kill(): void;
49
+ isRunning(): boolean;
50
+ }
51
+ export {};