@antv/layout 1.0.0-alpha.12 → 1.0.0-alpha.14
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 +213 -17
- package/dist/b6a955aaa104d7ff3f17.worker.js +2 -0
- package/dist/b6a955aaa104d7ff3f17.worker.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/esm/b6a955aaa104d7ff3f17.worker.js +2 -0
- package/esm/b6a955aaa104d7ff3f17.worker.js.map +1 -0
- package/esm/index.esm.js +1 -1
- package/esm/index.esm.js.map +1 -1
- package/lib/forceAtlas2/body.d.ts +33 -0
- package/lib/forceAtlas2/index.d.ts +109 -0
- package/lib/forceAtlas2/quad.d.ts +27 -0
- package/lib/forceAtlas2/quadTree.d.ts +20 -0
- package/lib/index.d.ts +3 -0
- package/lib/types.d.ts +40 -22
- package/lib/util/common.d.ts +22 -0
- package/lib/util/function.d.ts +0 -1
- package/lib/util/number.d.ts +0 -2
- package/lib/util/object.d.ts +1 -2
- package/lib/util/string.d.ts +0 -1
- package/package.json +5 -3
- package/dist/1f8aa319de677a5a27b9.worker.js +0 -2
- package/dist/1f8aa319de677a5a27b9.worker.js.map +0 -1
- package/esm/1f8aa319de677a5a27b9.worker.js +0 -2
- package/esm/1f8aa319de677a5a27b9.worker.js.map +0 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Quad from './quad';
|
|
2
|
+
/**
|
|
3
|
+
* @fileOverview body
|
|
4
|
+
* @author shiwu.wyy@antfin.com
|
|
5
|
+
*/
|
|
6
|
+
type BodyProps = {
|
|
7
|
+
id?: Number;
|
|
8
|
+
rx: number;
|
|
9
|
+
ry: number;
|
|
10
|
+
fx?: number;
|
|
11
|
+
fy?: number;
|
|
12
|
+
mass: number;
|
|
13
|
+
degree: number;
|
|
14
|
+
g?: number;
|
|
15
|
+
};
|
|
16
|
+
export default class Body {
|
|
17
|
+
id: Number;
|
|
18
|
+
rx: number;
|
|
19
|
+
ry: number;
|
|
20
|
+
fx: number;
|
|
21
|
+
fy: number;
|
|
22
|
+
mass: number;
|
|
23
|
+
degree: number;
|
|
24
|
+
g: number;
|
|
25
|
+
constructor(params: BodyProps);
|
|
26
|
+
distanceTo(bo: Body): number;
|
|
27
|
+
setPos(x: number, y: number): void;
|
|
28
|
+
resetForce(): void;
|
|
29
|
+
addForce(b: Body): void;
|
|
30
|
+
in(quad: Quad): boolean;
|
|
31
|
+
add(bo: Body): Body;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Graph, LayoutMapping, ForceAtlas2LayoutOptions, LayoutWithIterations } 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 = layout.execute(graph); // { nodes: [], edges: [] }
|
|
9
|
+
*
|
|
10
|
+
* // Or use different options later.
|
|
11
|
+
* const layout = new ForceAtlas2Layout({ 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 ForceAtlas2Layout implements LayoutWithIterations<ForceAtlas2LayoutOptions> {
|
|
18
|
+
options: ForceAtlas2LayoutOptions;
|
|
19
|
+
id: string;
|
|
20
|
+
constructor(options?: ForceAtlas2LayoutOptions);
|
|
21
|
+
stop: () => void;
|
|
22
|
+
restart: () => void;
|
|
23
|
+
tick: (iterations?: number | undefined) => LayoutMapping;
|
|
24
|
+
/**
|
|
25
|
+
* Return the positions of nodes and edges(if needed).
|
|
26
|
+
*/
|
|
27
|
+
execute(graph: Graph, options?: ForceAtlas2LayoutOptions): LayoutMapping;
|
|
28
|
+
/**
|
|
29
|
+
* To directly assign the positions to the nodes.
|
|
30
|
+
*/
|
|
31
|
+
assign(graph: Graph, options?: ForceAtlas2LayoutOptions): void;
|
|
32
|
+
private genericForceAtlas2Layout;
|
|
33
|
+
/**
|
|
34
|
+
* Init the node positions if there is no initial positions.
|
|
35
|
+
* And pre-calculate the size (max of width and height) for each node.
|
|
36
|
+
* @param calcGraph graph for calculation
|
|
37
|
+
* @param graph origin graph
|
|
38
|
+
* @param nodeSize node size config from layout options
|
|
39
|
+
* @returns {SizeMap} node'id mapped to max of its width and height
|
|
40
|
+
*/
|
|
41
|
+
private getSizes;
|
|
42
|
+
/**
|
|
43
|
+
* Format the options.
|
|
44
|
+
* @param options input options
|
|
45
|
+
* @param nodeNum number of nodes
|
|
46
|
+
* @returns formatted options
|
|
47
|
+
*/
|
|
48
|
+
private formatOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Loops for fa2.
|
|
51
|
+
* @param calcGraph graph for calculation
|
|
52
|
+
* @param graph original graph
|
|
53
|
+
* @param iteration iteration number
|
|
54
|
+
* @param sizes nodes' size
|
|
55
|
+
* @param options formatted layout options
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
private run;
|
|
59
|
+
/**
|
|
60
|
+
* One step for a loop.
|
|
61
|
+
* @param graph graph for calculation
|
|
62
|
+
* @param params parameters for a loop
|
|
63
|
+
* @param options formatted layout's input options
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
private oneStep;
|
|
67
|
+
/**
|
|
68
|
+
* Calculate the attract forces for nodes.
|
|
69
|
+
* @param graph graph for calculation
|
|
70
|
+
* @param iter current iteration index
|
|
71
|
+
* @param preventOverlapIters the iteration number for preventing overlappings
|
|
72
|
+
* @param sizes nodes' sizes
|
|
73
|
+
* @param forces forces for nodes, which will be modified
|
|
74
|
+
* @param options formatted layout's input options
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
private getAttrForces;
|
|
78
|
+
/**
|
|
79
|
+
* Calculate the repulsive forces for nodes under barnesHut mode.
|
|
80
|
+
* @param graph graph for calculatiion
|
|
81
|
+
* @param forces forces for nodes, which will be modified
|
|
82
|
+
* @param bodies force body map
|
|
83
|
+
* @param options formatted layout's input options
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
private getOptRepGraForces;
|
|
87
|
+
/**
|
|
88
|
+
* Calculate the repulsive forces for nodes.
|
|
89
|
+
* @param graph graph for calculatiion
|
|
90
|
+
* @param iter current iteration index
|
|
91
|
+
* @param preventOverlapIters the iteration number for preventing overlappings
|
|
92
|
+
* @param forces forces for nodes, which will be modified
|
|
93
|
+
* @param krPrime larger the krPrime, larger the repulsive force
|
|
94
|
+
* @param sizes nodes' sizes
|
|
95
|
+
* @param options formatted layout's input options
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
private getRepGraForces;
|
|
99
|
+
/**
|
|
100
|
+
* Update node positions.
|
|
101
|
+
* @param graph graph for calculatiion
|
|
102
|
+
* @param forces forces for nodes, which will be modified
|
|
103
|
+
* @param preForces previous forces for nodes, which will be modified
|
|
104
|
+
* @param sg constant for move distance of one step
|
|
105
|
+
* @param options formatted layout's input options
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
private updatePos;
|
|
109
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PointTuple } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* @fileOverview quad
|
|
4
|
+
* @author shiwu.wyy@antfin.com
|
|
5
|
+
*/
|
|
6
|
+
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
|
+
}
|
package/lib/index.d.ts
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Graph as IGraph, Node as INode, Edge as IEdge, PlainObject } from "@antv/graphlib";
|
|
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
3
|
visible?: boolean;
|
|
4
4
|
size?: number | number[];
|
|
@@ -27,6 +27,7 @@ export type IndexMap = {
|
|
|
27
27
|
[nodeId: string]: number;
|
|
28
28
|
};
|
|
29
29
|
export type Graph = IGraph<NodeData, EdgeData>;
|
|
30
|
+
export type GraphView = IGraphView<NodeData, EdgeData>;
|
|
30
31
|
export type PointTuple = [number, number];
|
|
31
32
|
export type Point = {
|
|
32
33
|
x: number;
|
|
@@ -114,11 +115,11 @@ export interface GridLayoutOptions extends CommonOptions {
|
|
|
114
115
|
rows?: number;
|
|
115
116
|
cols?: number;
|
|
116
117
|
sortBy?: string;
|
|
117
|
-
position?: (
|
|
118
|
+
position?: (node?: Node) => {
|
|
118
119
|
row?: number;
|
|
119
120
|
col?: number;
|
|
120
|
-
}
|
|
121
|
-
nodeSpacing?: ((node?: Node) => number) | number
|
|
121
|
+
};
|
|
122
|
+
nodeSpacing?: ((node?: Node) => number) | number;
|
|
122
123
|
}
|
|
123
124
|
export interface RandomLayoutOptions extends CommonOptions {
|
|
124
125
|
center?: PointTuple;
|
|
@@ -133,7 +134,6 @@ export interface ConcentricLayoutOptions extends CommonOptions {
|
|
|
133
134
|
center?: PointTuple;
|
|
134
135
|
preventOverlap?: boolean;
|
|
135
136
|
nodeSize?: number | PointTuple;
|
|
136
|
-
minNodeSpacing?: number;
|
|
137
137
|
sweep?: number;
|
|
138
138
|
equidistant?: boolean;
|
|
139
139
|
startAngle?: number;
|
|
@@ -142,7 +142,7 @@ export interface ConcentricLayoutOptions extends CommonOptions {
|
|
|
142
142
|
sortBy?: string;
|
|
143
143
|
width?: number;
|
|
144
144
|
height?: number;
|
|
145
|
-
nodeSpacing?: number | number[] | ((node?: Node) => number)
|
|
145
|
+
nodeSpacing?: number | number[] | ((node?: Node) => number);
|
|
146
146
|
}
|
|
147
147
|
export interface RadialLayoutOptions extends CommonOptions {
|
|
148
148
|
center?: PointTuple;
|
|
@@ -153,18 +153,18 @@ export interface RadialLayoutOptions extends CommonOptions {
|
|
|
153
153
|
focusNode?: string | Node | null;
|
|
154
154
|
unitRadius?: number | null;
|
|
155
155
|
preventOverlap?: boolean;
|
|
156
|
-
nodeSize?: number | number[]
|
|
157
|
-
nodeSpacing?: number | Function
|
|
156
|
+
nodeSize?: number | number[];
|
|
157
|
+
nodeSpacing?: number | Function;
|
|
158
158
|
maxPreventOverlapIteration?: number;
|
|
159
159
|
strictRadial?: boolean;
|
|
160
|
-
sortBy?: string
|
|
160
|
+
sortBy?: string;
|
|
161
161
|
sortStrength?: number;
|
|
162
162
|
}
|
|
163
163
|
export interface DagreLayoutOptions extends CommonOptions {
|
|
164
164
|
rankdir?: "TB" | "BT" | "LR" | "RL";
|
|
165
165
|
align?: "UL" | "UR" | "DL" | "DR";
|
|
166
166
|
begin?: PointTuple;
|
|
167
|
-
nodeSize?: number | number[]
|
|
167
|
+
nodeSize?: number | number[];
|
|
168
168
|
nodesep?: number;
|
|
169
169
|
ranksep?: number;
|
|
170
170
|
controlPoints?: boolean;
|
|
@@ -177,18 +177,18 @@ export interface DagreLayoutOptions extends CommonOptions {
|
|
|
177
177
|
nodes: OutNode[];
|
|
178
178
|
edges: Edge[];
|
|
179
179
|
};
|
|
180
|
-
nodesepFunc?: (
|
|
181
|
-
ranksepFunc?: (
|
|
180
|
+
nodesepFunc?: (d?: Node) => number;
|
|
181
|
+
ranksepFunc?: (d?: Node) => number;
|
|
182
182
|
}
|
|
183
183
|
export interface D3ForceLayoutOptions extends CommonOptions {
|
|
184
184
|
center?: PointTuple;
|
|
185
|
-
linkDistance?: number | ((edge?: Edge) => number)
|
|
186
|
-
edgeStrength?: number | ((edge?: Edge) => number)
|
|
187
|
-
nodeStrength?: number | ((node
|
|
185
|
+
linkDistance?: number | ((edge?: Edge) => number);
|
|
186
|
+
edgeStrength?: number | ((edge?: Edge) => number);
|
|
187
|
+
nodeStrength?: number | ((node?: Node) => number);
|
|
188
188
|
preventOverlap?: boolean;
|
|
189
189
|
collideStrength?: number;
|
|
190
|
-
nodeSize?: number | number[] | ((node?: Node) => number)
|
|
191
|
-
nodeSpacing?: number | number[] | ((node?: Node) => number)
|
|
190
|
+
nodeSize?: number | number[] | ((node?: Node) => number);
|
|
191
|
+
nodeSpacing?: number | number[] | ((node?: Node) => number);
|
|
192
192
|
alpha?: number;
|
|
193
193
|
alphaDecay?: number;
|
|
194
194
|
alphaMin?: number;
|
|
@@ -219,9 +219,9 @@ export interface ForceLayoutOptions extends CommonOptions {
|
|
|
219
219
|
center?: PointTuple;
|
|
220
220
|
width?: number;
|
|
221
221
|
height?: number;
|
|
222
|
-
linkDistance?: number | ((edge?: Edge, source?: any, target?: any) => number)
|
|
223
|
-
nodeStrength?: number | ((d?: Node) => number)
|
|
224
|
-
edgeStrength?: number | ((d?: Edge) => number)
|
|
222
|
+
linkDistance?: number | ((edge?: Edge, source?: any, target?: any) => number);
|
|
223
|
+
nodeStrength?: number | ((d?: Node) => number);
|
|
224
|
+
edgeStrength?: number | ((d?: Edge) => number);
|
|
225
225
|
preventOverlap?: boolean;
|
|
226
226
|
nodeSize?: number | number[] | ((d?: Node) => number);
|
|
227
227
|
nodeSpacing?: number | ((d?: Node) => number);
|
|
@@ -241,8 +241,8 @@ export interface ForceLayoutOptions extends CommonOptions {
|
|
|
241
241
|
collideStrength?: number;
|
|
242
242
|
distanceThresholdMode?: "mean" | "max" | "min";
|
|
243
243
|
onTick?: (data: LayoutMapping) => void;
|
|
244
|
-
getMass?: (
|
|
245
|
-
getCenter?: (
|
|
244
|
+
getMass?: (node?: Node) => number;
|
|
245
|
+
getCenter?: (node?: Node, degree?: number) => number[];
|
|
246
246
|
monitor?: (params: {
|
|
247
247
|
energy: number;
|
|
248
248
|
nodes: Node[];
|
|
@@ -250,6 +250,24 @@ export interface ForceLayoutOptions extends CommonOptions {
|
|
|
250
250
|
iterations: number;
|
|
251
251
|
}) => void;
|
|
252
252
|
}
|
|
253
|
+
export interface ForceAtlas2LayoutOptions extends CommonOptions {
|
|
254
|
+
center?: PointTuple;
|
|
255
|
+
width?: number;
|
|
256
|
+
height?: number;
|
|
257
|
+
kr?: number;
|
|
258
|
+
kg?: number;
|
|
259
|
+
ks?: number;
|
|
260
|
+
ksmax?: number;
|
|
261
|
+
tao?: number;
|
|
262
|
+
maxIteration?: number;
|
|
263
|
+
mode?: "normal" | "linlog";
|
|
264
|
+
preventOverlap?: boolean;
|
|
265
|
+
dissuadeHubs?: boolean;
|
|
266
|
+
barnesHut?: boolean;
|
|
267
|
+
prune?: boolean;
|
|
268
|
+
nodeSize?: number | number[] | ((node?: Node) => number);
|
|
269
|
+
onTick?: (data: LayoutMapping) => void;
|
|
270
|
+
}
|
|
253
271
|
export interface FruchtermanLayoutOptions extends CommonOptions {
|
|
254
272
|
center?: PointTuple;
|
|
255
273
|
maxIteration?: number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PointTuple, LayoutMapping, Graph } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Assign or only return the result for the graph who has no nodes or only one node.
|
|
4
|
+
* @param graph original graph
|
|
5
|
+
* @param assign whether assign result to original graph
|
|
6
|
+
* @param center the layout center
|
|
7
|
+
* @param onLayoutEnd callback for layout end
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const handleSingleNodeGraph: (graph: Graph, assign: boolean, center: PointTuple, onLayoutEnd?: ((data: LayoutMapping) => void) | undefined) => {
|
|
11
|
+
nodes: {
|
|
12
|
+
data: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
visible?: boolean | undefined;
|
|
16
|
+
size?: number | number[] | undefined;
|
|
17
|
+
bboxSize?: number[] | undefined;
|
|
18
|
+
};
|
|
19
|
+
id: import("@antv/graphlib").ID;
|
|
20
|
+
}[];
|
|
21
|
+
edges: import("@antv/graphlib").Edge<import("../types").EdgeData>[];
|
|
22
|
+
} | undefined;
|
package/lib/util/function.d.ts
CHANGED
package/lib/util/number.d.ts
CHANGED
package/lib/util/object.d.ts
CHANGED
package/lib/util/string.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/layout",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.14",
|
|
4
4
|
"description": "graph layout algorithm",
|
|
5
5
|
"main": "dist/index.min.js",
|
|
6
6
|
"module": "esm/index.esm.js",
|
|
@@ -21,12 +21,14 @@
|
|
|
21
21
|
"antv"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@antv/graphlib": "^2.0.0-alpha.
|
|
24
|
+
"@antv/graphlib": "^2.0.0-alpha.3",
|
|
25
|
+
"@antv/util": "^3.0.0",
|
|
25
26
|
"@naoak/workerize-transferable": "^0.1.0",
|
|
26
27
|
"d3-force": "^3.0.0",
|
|
27
28
|
"d3-quadtree": "^3.0.1",
|
|
28
29
|
"eventemitter3": "^4.0.0",
|
|
29
|
-
"ml-matrix": "^6.10.4"
|
|
30
|
+
"ml-matrix": "^6.10.4",
|
|
31
|
+
"tslib": "^2.5.0"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
32
34
|
"@babel/core": "^7.7.7",
|