@antv/layout 1.0.0-alpha.1 → 1.0.0-alpha.11
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/README.md +30 -2
- package/dist/2a6b6d9f27a9b35490fa.worker.js +2 -0
- package/dist/2a6b6d9f27a9b35490fa.worker.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/esm/2a6b6d9f27a9b35490fa.worker.js +2 -0
- package/esm/2a6b6d9f27a9b35490fa.worker.js.map +1 -0
- package/esm/index.esm.js +2 -0
- package/esm/index.esm.js.map +1 -0
- package/lib/Circular.d.ts +4 -14
- package/lib/Supervisor.d.ts +13 -6
- package/lib/concentric.d.ts +30 -0
- package/lib/d3Force/forceInBox.d.ts +28 -0
- package/lib/d3Force/index.d.ts +61 -0
- package/lib/force/forceNBody.d.ts +7 -0
- package/lib/force/index.d.ts +125 -0
- package/lib/force/types.d.ts +42 -0
- package/lib/fruchterman.d.ts +57 -0
- package/lib/grid.d.ts +30 -0
- package/lib/index.d.ts +8 -1
- package/lib/mds.d.ts +30 -0
- package/lib/radial/RadialNonoverlapForce.d.ts +16 -0
- package/lib/radial/index.d.ts +32 -0
- package/lib/radial/mds.d.ts +2 -0
- package/lib/random.d.ts +30 -0
- package/lib/registry.d.ts +3 -3
- package/lib/types.d.ts +230 -92
- package/lib/util/function.d.ts +17 -3
- package/lib/util/gpu.d.ts +0 -7
- package/lib/util/math.d.ts +15 -8
- package/lib/util/object.d.ts +8 -0
- package/lib/worker.d.ts +2 -2
- package/package.json +14 -5
- package/dist/3a54d760230d1933f953.worker.js +0 -2
- package/dist/3a54d760230d1933f953.worker.js.map +0 -1
package/lib/Circular.d.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import type { Graph } from "
|
|
2
|
-
import type { CircularLayoutOptions, SyncLayout, LayoutMapping, PointTuple, OutNode } from "./types";
|
|
3
|
-
type INodeData = OutNode & {
|
|
4
|
-
degree: number;
|
|
5
|
-
size: number | PointTuple;
|
|
6
|
-
weight: number;
|
|
7
|
-
children: string[];
|
|
8
|
-
parent: string[];
|
|
9
|
-
};
|
|
10
|
-
type IEdgeData = {};
|
|
1
|
+
import type { Graph, CircularLayoutOptions, Layout, LayoutMapping } from "./types";
|
|
11
2
|
/**
|
|
12
3
|
* Layout arranging the nodes in a circle.
|
|
13
4
|
*
|
|
@@ -23,18 +14,17 @@ type IEdgeData = {};
|
|
|
23
14
|
* // If you want to assign the positions directly to the nodes, use assign method.
|
|
24
15
|
* layout.assign(graph, { radius: 20 });
|
|
25
16
|
*/
|
|
26
|
-
export declare class CircularLayout implements
|
|
17
|
+
export declare class CircularLayout implements Layout<CircularLayoutOptions> {
|
|
27
18
|
options: CircularLayoutOptions;
|
|
28
19
|
id: string;
|
|
29
20
|
constructor(options?: CircularLayoutOptions);
|
|
30
21
|
/**
|
|
31
22
|
* Return the positions of nodes and edges(if needed).
|
|
32
23
|
*/
|
|
33
|
-
execute(graph: Graph
|
|
24
|
+
execute(graph: Graph, options?: CircularLayoutOptions): LayoutMapping;
|
|
34
25
|
/**
|
|
35
26
|
* To directly assign the positions to the nodes.
|
|
36
27
|
*/
|
|
37
|
-
assign(graph: Graph
|
|
28
|
+
assign(graph: Graph, options?: CircularLayoutOptions): void;
|
|
38
29
|
private genericCircularLayout;
|
|
39
30
|
}
|
|
40
|
-
export {};
|
package/lib/Supervisor.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import EventEmitter from
|
|
1
|
+
import EventEmitter from "eventemitter3";
|
|
2
2
|
import { Graph, Node, Edge } from "@antv/graphlib";
|
|
3
|
-
import type {
|
|
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();
|
|
@@ -43,9 +50,10 @@ export declare const SupervisorEvent: {
|
|
|
43
50
|
*
|
|
44
51
|
* // TODO: Custom layout.
|
|
45
52
|
*/
|
|
46
|
-
export declare class Supervisor extends EventEmitter {
|
|
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 {
|
|
|
54
62
|
* Flag of running state.
|
|
55
63
|
*/
|
|
56
64
|
private running;
|
|
57
|
-
constructor(graph: Graph<any, any>, layout:
|
|
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 {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Graph, LayoutMapping, ConcentricLayoutOptions, Layout } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Layout arranging the nodes in concentrics
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Assign layout options when initialization.
|
|
7
|
+
* const layout = new ConcentricLayout({ nodeSpacing: 10 });
|
|
8
|
+
* const positions = layout.execute(graph); // { nodes: [], edges: [] }
|
|
9
|
+
*
|
|
10
|
+
* // Or use different options later.
|
|
11
|
+
* const layout = new ConcentricLayout({ nodeSpacing: 10});
|
|
12
|
+
* const positions = layout.execute(graph, { nodeSpacing: 10 }); // { nodes: [], edges: [] }
|
|
13
|
+
*
|
|
14
|
+
* // If you want to assign the positions directly to the nodes, use assign method.
|
|
15
|
+
* layout.assign(graph, { nodeSpacing: 10 });
|
|
16
|
+
*/
|
|
17
|
+
export declare class ConcentricLayout implements Layout<ConcentricLayoutOptions> {
|
|
18
|
+
options: ConcentricLayoutOptions;
|
|
19
|
+
id: string;
|
|
20
|
+
constructor(options?: ConcentricLayoutOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Return the positions of nodes and edges(if needed).
|
|
23
|
+
*/
|
|
24
|
+
execute(graph: Graph, options?: ConcentricLayoutOptions): LayoutMapping;
|
|
25
|
+
/**
|
|
26
|
+
* To directly assign the positions to the nodes.
|
|
27
|
+
*/
|
|
28
|
+
assign(graph: Graph, options?: ConcentricLayoutOptions): void;
|
|
29
|
+
private genericConcentricLayout;
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface INode {
|
|
2
|
+
id: string;
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
vx: number;
|
|
6
|
+
vy: number;
|
|
7
|
+
cluster: any;
|
|
8
|
+
}
|
|
9
|
+
export default function forceInBox(): {
|
|
10
|
+
(alpha: number): any | undefined;
|
|
11
|
+
initialize(_: any): void;
|
|
12
|
+
template: (x: any) => string | any;
|
|
13
|
+
groupBy: (x: any) => ((d: INode) => any) | any;
|
|
14
|
+
enableGrouping: (x: any) => boolean | any;
|
|
15
|
+
strength: (x: any) => number | any;
|
|
16
|
+
centerX: (_: any) => number | any;
|
|
17
|
+
centerY: (_: any) => number | any;
|
|
18
|
+
nodes: (_: any) => INode[] | any;
|
|
19
|
+
links: (_: any) => any[] | any;
|
|
20
|
+
forceNodeSize: (_: any) => ((d: any) => number) | any;
|
|
21
|
+
nodeSize: (_: any) => ((d: any) => number) | any;
|
|
22
|
+
forceCharge: (_: any) => ((d: any) => number) | any;
|
|
23
|
+
forceLinkDistance: (_: any) => ((d: any) => number) | any;
|
|
24
|
+
forceLinkStrength: (_: any) => ((d: any) => number) | any;
|
|
25
|
+
offset: (_: any) => number[] | any;
|
|
26
|
+
getFocis: () => any;
|
|
27
|
+
};
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as d3Force from "d3-force";
|
|
2
|
+
import { Graph, Node, LayoutMapping, OutNode, D3ForceLayoutOptions, Edge, LayoutWithIterations } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* Layout the nodes' positions with d3's basic classic force
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Assign layout options when initialization.
|
|
8
|
+
* const layout = new D3ForceLayout({ center: [100, 100] });
|
|
9
|
+
* const positions = layout.execute(graph); // { nodes: [], edges: [] }
|
|
10
|
+
*
|
|
11
|
+
* // Or use different options later.
|
|
12
|
+
* const layout = new D3ForceLayout({ center: [100, 100] });
|
|
13
|
+
* const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
|
|
14
|
+
*
|
|
15
|
+
* // If you want to assign the positions directly to the nodes, use assign method.
|
|
16
|
+
* layout.assign(graph, { center: [100, 100] });
|
|
17
|
+
*/
|
|
18
|
+
export declare class D3ForceLayout implements LayoutWithIterations<D3ForceLayoutOptions> {
|
|
19
|
+
options: D3ForceLayoutOptions;
|
|
20
|
+
id: string;
|
|
21
|
+
private forceSimulation;
|
|
22
|
+
private lastLayoutNodes;
|
|
23
|
+
private lastLayoutEdges;
|
|
24
|
+
private lastAssign;
|
|
25
|
+
private lastGraph;
|
|
26
|
+
private lastOptions;
|
|
27
|
+
private running;
|
|
28
|
+
constructor(options?: D3ForceLayoutOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Return the positions of nodes and edges(if needed).
|
|
31
|
+
*/
|
|
32
|
+
execute(graph: Graph, options?: D3ForceLayoutOptions): LayoutMapping;
|
|
33
|
+
/**
|
|
34
|
+
* To directly assign the positions to the nodes.
|
|
35
|
+
*/
|
|
36
|
+
assign(graph: Graph, options?: D3ForceLayoutOptions): void;
|
|
37
|
+
/**
|
|
38
|
+
* Stop simulation immediately.
|
|
39
|
+
*/
|
|
40
|
+
stop(): void;
|
|
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
|
+
};
|
|
51
|
+
private genericForceLayout;
|
|
52
|
+
/**
|
|
53
|
+
* Prevent overlappings.
|
|
54
|
+
* @param {object} simulation force simulation of d3
|
|
55
|
+
*/
|
|
56
|
+
overlapProcess(simulation: d3Force.Simulation<any, any>, options: {
|
|
57
|
+
nodeSize: number | number[] | ((d?: Node) => number) | undefined;
|
|
58
|
+
nodeSpacing: number | number[] | ((d?: Node) => number) | undefined;
|
|
59
|
+
collideStrength: number;
|
|
60
|
+
}): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Graph, LayoutMapping, ForceLayoutOptions, Layout, Point } from "../types";
|
|
2
|
+
import { CalcGraph, FormatedOptions } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Layout with faster force
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Assign layout options when initialization.
|
|
8
|
+
* const layout = new ForceLayout({ center: [100, 100] });
|
|
9
|
+
* const positions = layout.execute(graph); // { nodes: [], edges: [] }
|
|
10
|
+
*
|
|
11
|
+
* // Or use different options later.
|
|
12
|
+
* const layout = new ForceLayout({ center: [100, 100] });
|
|
13
|
+
* const positions = layout.execute(graph, { center: [100, 100] }); // { nodes: [], edges: [] }
|
|
14
|
+
*
|
|
15
|
+
* // If you want to assign the positions directly to the nodes, use assign method.
|
|
16
|
+
* layout.assign(graph, { center: [100, 100] });
|
|
17
|
+
*/
|
|
18
|
+
export declare class ForceLayout implements Layout<ForceLayoutOptions> {
|
|
19
|
+
options: ForceLayoutOptions;
|
|
20
|
+
id: string;
|
|
21
|
+
/**
|
|
22
|
+
* time interval for layout force animations
|
|
23
|
+
*/
|
|
24
|
+
private timeInterval;
|
|
25
|
+
/**
|
|
26
|
+
* compare with minMovement to end the nodes' movement
|
|
27
|
+
*/
|
|
28
|
+
private judgingDistance;
|
|
29
|
+
constructor(options?: ForceLayoutOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Return the positions of nodes and edges(if needed).
|
|
32
|
+
*/
|
|
33
|
+
execute(graph: Graph, options?: ForceLayoutOptions): LayoutMapping;
|
|
34
|
+
/**
|
|
35
|
+
* To directly assign the positions to the nodes.
|
|
36
|
+
*/
|
|
37
|
+
assign(graph: Graph, options?: ForceLayoutOptions): void;
|
|
38
|
+
private genericForceLayout;
|
|
39
|
+
/**
|
|
40
|
+
* Format merged layout options.
|
|
41
|
+
* @param options merged layout options
|
|
42
|
+
* @param graph original graph
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
private formatOptions;
|
|
46
|
+
/**
|
|
47
|
+
* Format centripetalOption in the option.
|
|
48
|
+
* @param options merged layout options
|
|
49
|
+
* @param calcGraph calculation graph
|
|
50
|
+
*/
|
|
51
|
+
private formatCentripetal;
|
|
52
|
+
/**
|
|
53
|
+
* One iteration.
|
|
54
|
+
* @param calcGraph calculation graph
|
|
55
|
+
* @param graph origin graph
|
|
56
|
+
* @param iter current iteration index
|
|
57
|
+
* @param velMap nodes' velocity map
|
|
58
|
+
* @param options formatted layout options
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
private runOneStep;
|
|
62
|
+
/**
|
|
63
|
+
* Calculate graph energy for monitoring convergence.
|
|
64
|
+
* @param accMap acceleration map
|
|
65
|
+
* @param nodes calculation nodes
|
|
66
|
+
* @returns energy
|
|
67
|
+
*/
|
|
68
|
+
private calTotalEnergy;
|
|
69
|
+
/**
|
|
70
|
+
* Calculate the repulsive forces according to coulombs law.
|
|
71
|
+
* @param calcGraph calculation graph
|
|
72
|
+
* @param accMap acceleration map
|
|
73
|
+
* @param options formatted layout options
|
|
74
|
+
*/
|
|
75
|
+
calRepulsive(calcGraph: CalcGraph, accMap: {
|
|
76
|
+
[id: string]: Point;
|
|
77
|
+
}, options: FormatedOptions): void;
|
|
78
|
+
/**
|
|
79
|
+
* Calculate the attractive forces according to hooks law.
|
|
80
|
+
* @param calcGraph calculation graph
|
|
81
|
+
* @param accMap acceleration map
|
|
82
|
+
*/
|
|
83
|
+
calAttractive(calcGraph: CalcGraph, accMap: {
|
|
84
|
+
[id: string]: Point;
|
|
85
|
+
}): void;
|
|
86
|
+
/**
|
|
87
|
+
* Calculate the gravity forces toward center.
|
|
88
|
+
* @param calcGraph calculation graph
|
|
89
|
+
* @param graph origin graph
|
|
90
|
+
* @param accMap acceleration map
|
|
91
|
+
* @param options formatted layout options
|
|
92
|
+
*/
|
|
93
|
+
calGravity(calcGraph: CalcGraph, graph: Graph, accMap: {
|
|
94
|
+
[id: string]: Point;
|
|
95
|
+
}, options: FormatedOptions): void;
|
|
96
|
+
/**
|
|
97
|
+
* Update the velocities for nodes.
|
|
98
|
+
* @param calcGraph calculation graph
|
|
99
|
+
* @param accMap acceleration map
|
|
100
|
+
* @param velMap velocity map
|
|
101
|
+
* @param options formatted layout options
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
updateVelocity(calcGraph: CalcGraph, accMap: {
|
|
105
|
+
[id: string]: Point;
|
|
106
|
+
}, velMap: {
|
|
107
|
+
[id: string]: Point;
|
|
108
|
+
}, options: FormatedOptions): void;
|
|
109
|
+
/**
|
|
110
|
+
* Update nodes' positions.
|
|
111
|
+
* @param graph origin graph
|
|
112
|
+
* @param calcGraph calculatition graph
|
|
113
|
+
* @param velMap velocity map
|
|
114
|
+
* @param options formatted layou options
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
updatePosition(graph: Graph, calcGraph: CalcGraph, velMap: {
|
|
118
|
+
[id: string]: Point;
|
|
119
|
+
}, 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
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Graph as IGraph, Node as INode, Edge as IEdge } from "@antv/graphlib";
|
|
2
|
+
import { CentripetalOptions, Edge, Node, EdgeData, ForceLayoutOptions, NodeData, PointTuple } from "../types";
|
|
3
|
+
export interface CalcNodeData extends NodeData {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
mass: number;
|
|
7
|
+
nodeStrength: number;
|
|
8
|
+
}
|
|
9
|
+
export type CalcNode = INode<CalcNodeData>;
|
|
10
|
+
export interface CalcEdgeData extends EdgeData {
|
|
11
|
+
linkDistance?: number;
|
|
12
|
+
edgeStrength?: number;
|
|
13
|
+
}
|
|
14
|
+
export type CalcEdge = IEdge<CalcEdgeData>;
|
|
15
|
+
export type CalcGraph = IGraph<CalcNodeData, CalcEdgeData>;
|
|
16
|
+
interface FormatCentripetalOptions extends CentripetalOptions {
|
|
17
|
+
leaf: (node: Node, nodes: Node[], edges: Edge[]) => number;
|
|
18
|
+
/** Force strength for single nodes. */
|
|
19
|
+
single: (node: Node) => number;
|
|
20
|
+
/** Force strength for other nodes. */
|
|
21
|
+
others: (node: Node) => number;
|
|
22
|
+
}
|
|
23
|
+
export interface FormatedOptions extends ForceLayoutOptions {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
center: PointTuple;
|
|
27
|
+
minMovement: number;
|
|
28
|
+
maxIteration: number;
|
|
29
|
+
factor: number;
|
|
30
|
+
interval: number;
|
|
31
|
+
damping: number;
|
|
32
|
+
maxSpeed: number;
|
|
33
|
+
coulombDisScale: number;
|
|
34
|
+
centripetalOptions: FormatCentripetalOptions;
|
|
35
|
+
nodeSize: (d?: Node) => number;
|
|
36
|
+
getMass: (d?: Node) => number;
|
|
37
|
+
nodeStrength: (d?: Node) => number;
|
|
38
|
+
edgeStrength: (d?: Edge) => number;
|
|
39
|
+
linkDistance: (edge?: Edge, source?: any, target?: any) => number;
|
|
40
|
+
clusterNodeStrength: (node?: Node) => number;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Graph, LayoutMapping, OutNode, FruchtermanLayoutOptions, Edge, 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 = layout.execute(graph); // { nodes: [], edges: [] }
|
|
9
|
+
*
|
|
10
|
+
* // Or use different options later.
|
|
11
|
+
* const layout = new FruchtermanLayout({ center: [100, 100] });
|
|
12
|
+
* const positions = 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
|
+
* 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
|
+
constructor(options?: FruchtermanLayoutOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Return the positions of nodes and edges(if needed).
|
|
31
|
+
*/
|
|
32
|
+
execute(graph: Graph, options?: FruchtermanLayoutOptions): LayoutMapping;
|
|
33
|
+
/**
|
|
34
|
+
* To directly assign the positions to the nodes.
|
|
35
|
+
*/
|
|
36
|
+
assign(graph: Graph, options?: FruchtermanLayoutOptions): void;
|
|
37
|
+
/**
|
|
38
|
+
* Stop simulation immediately.
|
|
39
|
+
*/
|
|
40
|
+
stop(): void;
|
|
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
|
+
};
|
|
51
|
+
private genericFruchtermanLayout;
|
|
52
|
+
private formatOptions;
|
|
53
|
+
private runOneStep;
|
|
54
|
+
private applyCalculate;
|
|
55
|
+
private calRepulsive;
|
|
56
|
+
private calAttractive;
|
|
57
|
+
}
|
package/lib/grid.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Graph, GridLayoutOptions, LayoutMapping, Layout } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Layout arranging the nodes in a grid.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Assign layout options when initialization.
|
|
7
|
+
* const layout = new GridLayout({ rows: 10 });
|
|
8
|
+
* const positions = layout.execute(graph); // { nodes: [], edges: [] }
|
|
9
|
+
*
|
|
10
|
+
* // Or use different options later.
|
|
11
|
+
* const layout = new GridLayout({ rows: 10 });
|
|
12
|
+
* const positions = layout.execute(graph, { rows: 20 }); // { nodes: [], edges: [] }
|
|
13
|
+
*
|
|
14
|
+
* // If you want to assign the positions directly to the nodes, use assign method.
|
|
15
|
+
* layout.assign(graph, { rows: 20 });
|
|
16
|
+
*/
|
|
17
|
+
export declare class GridLayout implements Layout<GridLayoutOptions> {
|
|
18
|
+
options: GridLayoutOptions;
|
|
19
|
+
id: string;
|
|
20
|
+
constructor(options?: GridLayoutOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Return the positions of nodes and edges(if needed).
|
|
23
|
+
*/
|
|
24
|
+
execute(graph: Graph, options?: GridLayoutOptions): LayoutMapping;
|
|
25
|
+
/**
|
|
26
|
+
* To directly assign the positions to the nodes.
|
|
27
|
+
*/
|
|
28
|
+
assign(graph: Graph, options?: GridLayoutOptions): void;
|
|
29
|
+
private genericGridLayout;
|
|
30
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export * from "./circular";
|
|
2
2
|
export * from "./supervisor";
|
|
3
3
|
export * from "./registry";
|
|
4
|
-
export * from "
|
|
4
|
+
export * from "./grid";
|
|
5
|
+
export * from "./random";
|
|
6
|
+
export * from "./mds";
|
|
7
|
+
export * from "./concentric";
|
|
8
|
+
export * from "./radial";
|
|
9
|
+
export * from "./fruchterman";
|
|
10
|
+
export * from "./d3Force";
|
|
11
|
+
export * from "./force";
|
package/lib/mds.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Graph, LayoutMapping, MDSLayoutOptions, Layout } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Layout arranging the nodes with multiple dimensional scaling algorithm
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Assign layout options when initialization.
|
|
7
|
+
* const layout = new MDSLayout({ center: [100, 100] });
|
|
8
|
+
* const positions = layout.execute(graph); // { nodes: [], edges: [] }
|
|
9
|
+
*
|
|
10
|
+
* // Or use different options later.
|
|
11
|
+
* const layout = new MDSLayout({ center: [100, 100] });
|
|
12
|
+
* const positions = layout.execute(graph, { rows: 20 }); // { nodes: [], edges: [] }
|
|
13
|
+
*
|
|
14
|
+
* // If you want to assign the positions directly to the nodes, use assign method.
|
|
15
|
+
* layout.assign(graph, { center: [100, 100] });
|
|
16
|
+
*/
|
|
17
|
+
export declare class MDSLayout implements Layout<MDSLayoutOptions> {
|
|
18
|
+
options: MDSLayoutOptions;
|
|
19
|
+
id: string;
|
|
20
|
+
constructor(options?: MDSLayoutOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Return the positions of nodes and edges(if needed).
|
|
23
|
+
*/
|
|
24
|
+
execute(graph: Graph, options?: MDSLayoutOptions): LayoutMapping;
|
|
25
|
+
/**
|
|
26
|
+
* To directly assign the positions to the nodes.
|
|
27
|
+
*/
|
|
28
|
+
assign(graph: Graph, options?: MDSLayoutOptions): void;
|
|
29
|
+
private genericMDSLayout;
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Graph, Node, Point } from "../types";
|
|
2
|
+
export type RadialNonoverlapForceOptions = {
|
|
3
|
+
positions: Point[];
|
|
4
|
+
focusIdx: number;
|
|
5
|
+
radii: number[];
|
|
6
|
+
iterations: number;
|
|
7
|
+
height: number;
|
|
8
|
+
width: number;
|
|
9
|
+
k: number;
|
|
10
|
+
strictRadial: boolean;
|
|
11
|
+
nodes: Node[];
|
|
12
|
+
speed?: number;
|
|
13
|
+
gravity?: number;
|
|
14
|
+
nodeSizeFunc: (node: Node) => number;
|
|
15
|
+
};
|
|
16
|
+
export declare const radialNonoverlapForce: (graph: Graph, options: RadialNonoverlapForceOptions) => Point[];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Graph, LayoutMapping, RadialLayoutOptions, Layout } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Layout arranging the nodes' on a radial shape
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Assign layout options when initialization.
|
|
7
|
+
* const layout = new RadialLayout({ focusNode: 'node0' });
|
|
8
|
+
* const positions = layout.execute(graph); // { nodes: [], edges: [] }
|
|
9
|
+
*
|
|
10
|
+
* // Or use different options later.
|
|
11
|
+
* const layout = new RadialLayout({ focusNode: 'node0' });
|
|
12
|
+
* const positions = layout.execute(graph, { focusNode: 'node0' }); // { nodes: [], edges: [] }
|
|
13
|
+
*
|
|
14
|
+
* // If you want to assign the positions directly to the nodes, use assign method.
|
|
15
|
+
* layout.assign(graph, { focusNode: 'node0' });
|
|
16
|
+
*/
|
|
17
|
+
export declare class RadialLayout implements Layout<RadialLayoutOptions> {
|
|
18
|
+
options: RadialLayoutOptions;
|
|
19
|
+
id: string;
|
|
20
|
+
constructor(options?: RadialLayoutOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Return the positions of nodes and edges(if needed).
|
|
23
|
+
*/
|
|
24
|
+
execute(graph: Graph, options?: RadialLayoutOptions): LayoutMapping;
|
|
25
|
+
/**
|
|
26
|
+
* To directly assign the positions to the nodes.
|
|
27
|
+
*/
|
|
28
|
+
assign(graph: Graph, options?: RadialLayoutOptions): void;
|
|
29
|
+
private genericRadialLayout;
|
|
30
|
+
private run;
|
|
31
|
+
private oneIteration;
|
|
32
|
+
}
|
package/lib/random.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Graph, LayoutMapping, RandomLayoutOptions, Layout } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Layout randomizing the nodes' position
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* // Assign layout options when initialization.
|
|
7
|
+
* const layout = new RandomLayout({ center: [100, 100] });
|
|
8
|
+
* const positions = layout.execute(graph); // { nodes: [], edges: [] }
|
|
9
|
+
*
|
|
10
|
+
* // Or use different options later.
|
|
11
|
+
* const layout = new RandomLayout({ center: [100, 100] });
|
|
12
|
+
* const positions = 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
|
+
* layout.assign(graph, { center: [100, 100] });
|
|
16
|
+
*/
|
|
17
|
+
export declare class RandomLayout implements Layout<RandomLayoutOptions> {
|
|
18
|
+
options: RandomLayoutOptions;
|
|
19
|
+
id: string;
|
|
20
|
+
constructor(options?: RandomLayoutOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Return the positions of nodes and edges(if needed).
|
|
23
|
+
*/
|
|
24
|
+
execute(graph: Graph, options?: RandomLayoutOptions): LayoutMapping;
|
|
25
|
+
/**
|
|
26
|
+
* To directly assign the positions to the nodes.
|
|
27
|
+
*/
|
|
28
|
+
assign(graph: Graph, options?: RandomLayoutOptions): void;
|
|
29
|
+
private genericRandomLayout;
|
|
30
|
+
}
|
package/lib/registry.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const registry: Record<string,
|
|
3
|
-
export declare function registerLayout(id: string, layout:
|
|
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;
|