@antv/layout 1.0.0-alpha.10 → 1.0.0-alpha.12

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
@@ -1,4 +1,4 @@
1
- import type { Graph, CircularLayoutOptions, SyncLayout, LayoutMapping } from "./types";
1
+ import type { Graph, CircularLayoutOptions, Layout, LayoutMapping } from "./types";
2
2
  /**
3
3
  * Layout arranging the nodes in a circle.
4
4
  *
@@ -14,7 +14,7 @@ import type { Graph, CircularLayoutOptions, SyncLayout, LayoutMapping } from "./
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
15
  * layout.assign(graph, { radius: 20 });
16
16
  */
17
- export declare class CircularLayout implements SyncLayout<CircularLayoutOptions> {
17
+ export declare class CircularLayout implements Layout<CircularLayoutOptions> {
18
18
  options: CircularLayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: CircularLayoutOptions);
@@ -1,6 +1,6 @@
1
- import EventEmitter from 'eventemitter3';
1
+ import EventEmitter from "eventemitter3";
2
2
  import { Graph, Node, Edge } from "@antv/graphlib";
3
- import type { SyncLayout, LayoutSupervisor } from "./types";
3
+ import type { Layout, LayoutSupervisor } from "./types";
4
4
  /**
5
5
  * The payload transferred from main thread to the worker.
6
6
  */
@@ -8,6 +8,7 @@ export interface Payload {
8
8
  layout: {
9
9
  id: string;
10
10
  options: any;
11
+ iterations: number;
11
12
  };
12
13
  nodes: Node<any>[];
13
14
  edges: Edge<any>[];
@@ -22,6 +23,12 @@ export declare const SupervisorEvent: {
22
23
  */
23
24
  LAYOUT_END: string;
24
25
  };
26
+ interface SupervisorOptions {
27
+ /**
28
+ * Iterations run in algorithm such as d3force, will be passed in `tick()` later.
29
+ */
30
+ iterations: number;
31
+ }
25
32
  /**
26
33
  * @example
27
34
  * const graph = new Graph();
@@ -46,6 +53,7 @@ export declare const SupervisorEvent: {
46
53
  export declare class Supervisor extends EventEmitter implements LayoutSupervisor {
47
54
  private graph;
48
55
  private layout;
56
+ private options?;
49
57
  /**
50
58
  * Internal worker.
51
59
  */
@@ -54,12 +62,11 @@ export declare class Supervisor extends EventEmitter implements LayoutSupervisor
54
62
  * Flag of running state.
55
63
  */
56
64
  private running;
57
- constructor(graph: Graph<any, any>, layout: SyncLayout<any>, options: {
58
- auto: boolean;
59
- });
65
+ constructor(graph: Graph<any, any>, layout: Layout<any>, options?: Partial<SupervisorOptions> | undefined);
60
66
  spawnWorker(): void;
61
67
  start(): this;
62
68
  stop(): this;
63
69
  kill(): void;
64
70
  isRunning(): boolean;
65
71
  }
72
+ export {};
@@ -1,4 +1,4 @@
1
- import type { Graph, LayoutMapping, ConcentricLayoutOptions, SyncLayout } from "./types";
1
+ import type { Graph, LayoutMapping, ConcentricLayoutOptions, Layout } from "./types";
2
2
  /**
3
3
  * Layout arranging the nodes in concentrics
4
4
  *
@@ -14,7 +14,7 @@ import type { Graph, LayoutMapping, ConcentricLayoutOptions, SyncLayout } from "
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
15
  * layout.assign(graph, { nodeSpacing: 10 });
16
16
  */
17
- export declare class ConcentricLayout implements SyncLayout<ConcentricLayoutOptions> {
17
+ export declare class ConcentricLayout implements Layout<ConcentricLayoutOptions> {
18
18
  options: ConcentricLayoutOptions;
19
19
  id: string;
20
20
  constructor(options?: ConcentricLayoutOptions);
@@ -1,4 +1,5 @@
1
- import { Graph, Node, LayoutMapping, D3ForceLayoutOptions, SyncLayout } from "../types";
1
+ import * as d3Force from "d3-force";
2
+ import { Graph, Node, LayoutMapping, OutNode, D3ForceLayoutOptions, Edge, LayoutWithIterations } from "../types";
2
3
  /**
3
4
  * Layout the nodes' positions with d3's basic classic force
4
5
  *
@@ -14,11 +15,15 @@ import { Graph, Node, LayoutMapping, D3ForceLayoutOptions, SyncLayout } from "..
14
15
  * // If you want to assign the positions directly to the nodes, use assign method.
15
16
  * layout.assign(graph, { center: [100, 100] });
16
17
  */
17
- export declare class D3ForceLayout implements SyncLayout<D3ForceLayoutOptions> {
18
+ export declare class D3ForceLayout implements LayoutWithIterations<D3ForceLayoutOptions> {
18
19
  options: D3ForceLayoutOptions;
19
20
  id: string;
20
21
  private forceSimulation;
21
- /** The sign of running */
22
+ private lastLayoutNodes;
23
+ private lastLayoutEdges;
24
+ private lastAssign;
25
+ private lastGraph;
26
+ private lastOptions;
22
27
  private running;
23
28
  constructor(options?: D3ForceLayoutOptions);
24
29
  /**
@@ -33,13 +38,22 @@ export declare class D3ForceLayout implements SyncLayout<D3ForceLayoutOptions> {
33
38
  * Stop simulation immediately.
34
39
  */
35
40
  stop(): void;
36
- isRunning(): boolean;
41
+ restart(): void;
42
+ /**
43
+ * Manually steps the simulation by the specified number of iterations.
44
+ * When finished it will trigger `onLayoutEnd` callback.
45
+ * @see https://github.com/d3/d3-force#simulation_tick
46
+ */
47
+ tick(iterations?: number): {
48
+ nodes: OutNode[];
49
+ edges: Edge[];
50
+ };
37
51
  private genericForceLayout;
38
52
  /**
39
53
  * Prevent overlappings.
40
54
  * @param {object} simulation force simulation of d3
41
55
  */
42
- overlapProcess(simulation: any, options: {
56
+ overlapProcess(simulation: d3Force.Simulation<any, any>, options: {
43
57
  nodeSize: number | number[] | ((d?: Node) => number) | undefined;
44
58
  nodeSpacing: number | number[] | ((d?: Node) => number) | undefined;
45
59
  collideStrength: number;
@@ -1,4 +1,4 @@
1
- import { Graph, LayoutMapping, ForceLayoutOptions, SyncLayout, Point } from "../types";
1
+ import { Graph, LayoutMapping, ForceLayoutOptions, Point, LayoutWithIterations } from "../types";
2
2
  import { CalcGraph, FormatedOptions } from "./types";
3
3
  /**
4
4
  * Layout with faster force
@@ -15,7 +15,7 @@ import { CalcGraph, FormatedOptions } from "./types";
15
15
  * // If you want to assign the positions directly to the nodes, use assign method.
16
16
  * layout.assign(graph, { center: [100, 100] });
17
17
  */
18
- export declare class ForceLayout implements SyncLayout<ForceLayoutOptions> {
18
+ export declare class ForceLayout implements LayoutWithIterations<ForceLayoutOptions> {
19
19
  options: ForceLayoutOptions;
20
20
  id: string;
21
21
  /**
@@ -26,6 +26,15 @@ export declare class ForceLayout implements SyncLayout<ForceLayoutOptions> {
26
26
  * compare with minMovement to end the nodes' movement
27
27
  */
28
28
  private judgingDistance;
29
+ private running;
30
+ private lastLayoutNodes;
31
+ private lastLayoutEdges;
32
+ private lastAssign;
33
+ private lastCalcGraph;
34
+ private lastGraph;
35
+ private lastOptions;
36
+ private lastVelMap;
37
+ private lastResult;
29
38
  constructor(options?: ForceLayoutOptions);
30
39
  /**
31
40
  * Return the positions of nodes and edges(if needed).
@@ -35,6 +44,17 @@ export declare class ForceLayout implements SyncLayout<ForceLayoutOptions> {
35
44
  * To directly assign the positions to the nodes.
36
45
  */
37
46
  assign(graph: Graph, options?: ForceLayoutOptions): void;
47
+ /**
48
+ * Stop simulation immediately.
49
+ */
50
+ stop(): void;
51
+ restart(): void;
52
+ /**
53
+ * Manually steps the simulation by the specified number of iterations.
54
+ * When finished it will trigger `onLayoutEnd` callback.
55
+ * @see https://github.com/d3/d3-force#simulation_tick
56
+ */
57
+ tick(iterations?: number): LayoutMapping;
38
58
  private genericForceLayout;
39
59
  /**
40
60
  * Format merged layout options.
@@ -117,9 +137,4 @@ export declare class ForceLayout implements SyncLayout<ForceLayoutOptions> {
117
137
  updatePosition(graph: Graph, calcGraph: CalcGraph, velMap: {
118
138
  [id: string]: Point;
119
139
  }, options: FormatedOptions): void;
120
- /**
121
- * Stop the animation for no-silence force.
122
- * TODO: confirm the controller and worker's controller
123
- */
124
- stop(): void;
125
140
  }
@@ -1,4 +1,4 @@
1
- import type { Graph, LayoutMapping, FruchtermanLayoutOptions, SyncLayout } from "./types";
1
+ import type { Graph, LayoutMapping, FruchtermanLayoutOptions, LayoutWithIterations } from "./types";
2
2
  /**
3
3
  * Layout with fructherman force model
4
4
  *
@@ -14,10 +14,18 @@ import type { Graph, LayoutMapping, FruchtermanLayoutOptions, SyncLayout } from
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
15
  * layout.assign(graph, { center: [100, 100] });
16
16
  */
17
- export declare class FruchtermanLayout implements SyncLayout<FruchtermanLayoutOptions> {
17
+ export declare class FruchtermanLayout implements LayoutWithIterations<FruchtermanLayoutOptions> {
18
18
  options: FruchtermanLayoutOptions;
19
19
  id: string;
20
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;
21
29
  constructor(options?: FruchtermanLayoutOptions);
22
30
  /**
23
31
  * Return the positions of nodes and edges(if needed).
@@ -27,11 +35,21 @@ export declare class FruchtermanLayout implements SyncLayout<FruchtermanLayoutOp
27
35
  * To directly assign the positions to the nodes.
28
36
  */
29
37
  assign(graph: Graph, options?: FruchtermanLayoutOptions): void;
38
+ /**
39
+ * Stop simulation immediately.
40
+ */
41
+ stop(): void;
42
+ restart(): void;
43
+ /**
44
+ * Manually steps the simulation by the specified number of iterations.
45
+ * When finished it will trigger `onLayoutEnd` callback.
46
+ * @see https://github.com/d3/d3-force#simulation_tick
47
+ */
48
+ tick(iterations?: number): LayoutMapping;
30
49
  private genericFruchtermanLayout;
31
50
  private formatOptions;
32
51
  private runOneStep;
33
52
  private applyCalculate;
34
53
  private calRepulsive;
35
54
  private calAttractive;
36
- stop(): void;
37
55
  }
package/lib/grid.d.ts CHANGED
@@ -1,4 +1,4 @@
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
  *
@@ -14,7 +14,7 @@ import type { Graph, GridLayoutOptions, LayoutMapping, SyncLayout } from "./type
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
15
  * 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);
package/lib/mds.d.ts CHANGED
@@ -1,4 +1,4 @@
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
  *
@@ -14,7 +14,7 @@ import type { Graph, LayoutMapping, MDSLayoutOptions, SyncLayout } from "./types
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
15
  * 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);
@@ -1,4 +1,4 @@
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
  *
@@ -14,7 +14,7 @@ import type { Graph, LayoutMapping, RadialLayoutOptions, SyncLayout } from "../t
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
15
  * 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);
package/lib/random.d.ts CHANGED
@@ -1,4 +1,4 @@
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
  *
@@ -14,7 +14,7 @@ import type { Graph, LayoutMapping, RandomLayoutOptions, SyncLayout } from "./ty
14
14
  * // If you want to assign the positions directly to the nodes, use assign method.
15
15
  * 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);
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;
package/lib/types.d.ts CHANGED
@@ -37,14 +37,45 @@ export type LayoutMapping = {
37
37
  nodes: OutNode[];
38
38
  edges: Edge[];
39
39
  };
40
- export interface SyncLayout<LayoutOptions> {
40
+ export interface Layout<LayoutOptions> {
41
+ /**
42
+ * To directly assign the positions to the nodes.
43
+ */
41
44
  assign(graph: Graph, options?: LayoutOptions): void;
45
+ /**
46
+ * Return the positions of nodes and edges(if needed).
47
+ */
42
48
  execute(graph: Graph, options?: LayoutOptions): LayoutMapping;
49
+ /**
50
+ * Layout options, can be changed in runtime.
51
+ */
43
52
  options: LayoutOptions;
53
+ /**
54
+ * Unique ID, it will get registered and used on the webworker-side.
55
+ */
44
56
  id: string;
45
57
  }
46
- export interface SyncLayoutConstructor<LayoutOptions> {
47
- new (options?: LayoutOptions): SyncLayout<LayoutOptions>;
58
+ export declare function isLayoutWithIterations(layout: any): layout is LayoutWithIterations<any>;
59
+ export interface LayoutWithIterations<LayoutOptions> extends Layout<LayoutOptions> {
60
+ /**
61
+ * Some layout algorithm has n iterations so that the simulation needs to be stopped at any time.
62
+ * This method is useful for running the simulation manually.
63
+ * @see https://github.com/d3/d3-force#simulation_stop
64
+ */
65
+ stop: () => void;
66
+ /**
67
+ * Restarts the simulation’s internal timer and returns the simulation.
68
+ * @see https://github.com/d3/d3-force#simulation_restart
69
+ */
70
+ restart: () => void;
71
+ /**
72
+ * Manually steps the simulation by the specified number of iterations.
73
+ * @see https://github.com/d3/d3-force#simulation_tick
74
+ */
75
+ tick: (iterations?: number) => LayoutMapping;
76
+ }
77
+ export interface LayoutConstructor<LayoutOptions> {
78
+ new (options?: LayoutOptions): Layout<LayoutOptions>;
48
79
  }
49
80
  export interface LayoutSupervisor {
50
81
  start(): void;
@@ -209,7 +240,6 @@ export interface ForceLayoutOptions extends CommonOptions {
209
240
  clusterNodeStrength?: number | ((node: Node) => number);
210
241
  collideStrength?: number;
211
242
  distanceThresholdMode?: "mean" | "max" | "min";
212
- animate?: boolean;
213
243
  onTick?: (data: LayoutMapping) => void;
214
244
  getMass?: ((d: Node) => number) | undefined;
215
245
  getCenter?: ((d?: Node, degree?: number) => number[]) | undefined;
@@ -229,7 +259,6 @@ export interface FruchtermanLayoutOptions extends CommonOptions {
229
259
  speed?: number;
230
260
  clustering?: boolean;
231
261
  clusterGravity?: number;
232
- animate?: boolean;
233
262
  nodeClusterBy?: string;
234
263
  onTick?: (data: LayoutMapping) => void;
235
264
  }
package/lib/worker.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import type { Payload } from "./supervisor";
2
+ export declare function stopLayout(): void;
2
3
  export declare function calculateLayout(payload: Payload, transferables: Float32Array[]): Promise<unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/layout",
3
- "version": "1.0.0-alpha.10",
3
+ "version": "1.0.0-alpha.12",
4
4
  "description": "graph layout algorithm",
5
5
  "main": "dist/index.min.js",
6
6
  "module": "esm/index.esm.js",
@@ -32,6 +32,7 @@
32
32
  "@babel/core": "^7.7.7",
33
33
  "@babel/plugin-proposal-class-properties": "^7.1.0",
34
34
  "@babel/preset-react": "^7.7.4",
35
+ "@types/d3-force": "^3.0.4",
35
36
  "babel-loader": "^8.0.6",
36
37
  "ts-loader": "^7.0.3",
37
38
  "typescript": "^4.0.3",