@antv/layout 1.0.0-alpha.12 → 1.0.0-alpha.13
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/dist/d869b88cfe3353e7436d.worker.js +2 -0
- package/dist/d869b88cfe3353e7436d.worker.js.map +1 -0
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/esm/d869b88cfe3353e7436d.worker.js +2 -0
- package/esm/d869b88cfe3353e7436d.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 +1 -0
- package/lib/types.d.ts +38 -21
- package/lib/util/common.d.ts +22 -0
- package/lib/util/object.d.ts +1 -1
- package/package.json +1 -1
- 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
|
@@ -114,11 +114,11 @@ export interface GridLayoutOptions extends CommonOptions {
|
|
|
114
114
|
rows?: number;
|
|
115
115
|
cols?: number;
|
|
116
116
|
sortBy?: string;
|
|
117
|
-
position?: (
|
|
117
|
+
position?: (node?: Node) => {
|
|
118
118
|
row?: number;
|
|
119
119
|
col?: number;
|
|
120
|
-
}
|
|
121
|
-
nodeSpacing?: ((node?: Node) => number) | number
|
|
120
|
+
};
|
|
121
|
+
nodeSpacing?: ((node?: Node) => number) | number;
|
|
122
122
|
}
|
|
123
123
|
export interface RandomLayoutOptions extends CommonOptions {
|
|
124
124
|
center?: PointTuple;
|
|
@@ -133,7 +133,6 @@ export interface ConcentricLayoutOptions extends CommonOptions {
|
|
|
133
133
|
center?: PointTuple;
|
|
134
134
|
preventOverlap?: boolean;
|
|
135
135
|
nodeSize?: number | PointTuple;
|
|
136
|
-
minNodeSpacing?: number;
|
|
137
136
|
sweep?: number;
|
|
138
137
|
equidistant?: boolean;
|
|
139
138
|
startAngle?: number;
|
|
@@ -142,7 +141,7 @@ export interface ConcentricLayoutOptions extends CommonOptions {
|
|
|
142
141
|
sortBy?: string;
|
|
143
142
|
width?: number;
|
|
144
143
|
height?: number;
|
|
145
|
-
nodeSpacing?: number | number[] | ((node?: Node) => number)
|
|
144
|
+
nodeSpacing?: number | number[] | ((node?: Node) => number);
|
|
146
145
|
}
|
|
147
146
|
export interface RadialLayoutOptions extends CommonOptions {
|
|
148
147
|
center?: PointTuple;
|
|
@@ -153,18 +152,18 @@ export interface RadialLayoutOptions extends CommonOptions {
|
|
|
153
152
|
focusNode?: string | Node | null;
|
|
154
153
|
unitRadius?: number | null;
|
|
155
154
|
preventOverlap?: boolean;
|
|
156
|
-
nodeSize?: number | number[]
|
|
157
|
-
nodeSpacing?: number | Function
|
|
155
|
+
nodeSize?: number | number[];
|
|
156
|
+
nodeSpacing?: number | Function;
|
|
158
157
|
maxPreventOverlapIteration?: number;
|
|
159
158
|
strictRadial?: boolean;
|
|
160
|
-
sortBy?: string
|
|
159
|
+
sortBy?: string;
|
|
161
160
|
sortStrength?: number;
|
|
162
161
|
}
|
|
163
162
|
export interface DagreLayoutOptions extends CommonOptions {
|
|
164
163
|
rankdir?: "TB" | "BT" | "LR" | "RL";
|
|
165
164
|
align?: "UL" | "UR" | "DL" | "DR";
|
|
166
165
|
begin?: PointTuple;
|
|
167
|
-
nodeSize?: number | number[]
|
|
166
|
+
nodeSize?: number | number[];
|
|
168
167
|
nodesep?: number;
|
|
169
168
|
ranksep?: number;
|
|
170
169
|
controlPoints?: boolean;
|
|
@@ -177,18 +176,18 @@ export interface DagreLayoutOptions extends CommonOptions {
|
|
|
177
176
|
nodes: OutNode[];
|
|
178
177
|
edges: Edge[];
|
|
179
178
|
};
|
|
180
|
-
nodesepFunc?: (
|
|
181
|
-
ranksepFunc?: (
|
|
179
|
+
nodesepFunc?: (d?: Node) => number;
|
|
180
|
+
ranksepFunc?: (d?: Node) => number;
|
|
182
181
|
}
|
|
183
182
|
export interface D3ForceLayoutOptions extends CommonOptions {
|
|
184
183
|
center?: PointTuple;
|
|
185
|
-
linkDistance?: number | ((edge?: Edge) => number)
|
|
186
|
-
edgeStrength?: number | ((edge?: Edge) => number)
|
|
187
|
-
nodeStrength?: number | ((node
|
|
184
|
+
linkDistance?: number | ((edge?: Edge) => number);
|
|
185
|
+
edgeStrength?: number | ((edge?: Edge) => number);
|
|
186
|
+
nodeStrength?: number | ((node?: Node) => number);
|
|
188
187
|
preventOverlap?: boolean;
|
|
189
188
|
collideStrength?: number;
|
|
190
|
-
nodeSize?: number | number[] | ((node?: Node) => number)
|
|
191
|
-
nodeSpacing?: number | number[] | ((node?: Node) => number)
|
|
189
|
+
nodeSize?: number | number[] | ((node?: Node) => number);
|
|
190
|
+
nodeSpacing?: number | number[] | ((node?: Node) => number);
|
|
192
191
|
alpha?: number;
|
|
193
192
|
alphaDecay?: number;
|
|
194
193
|
alphaMin?: number;
|
|
@@ -219,9 +218,9 @@ export interface ForceLayoutOptions extends CommonOptions {
|
|
|
219
218
|
center?: PointTuple;
|
|
220
219
|
width?: number;
|
|
221
220
|
height?: number;
|
|
222
|
-
linkDistance?: number | ((edge?: Edge, source?: any, target?: any) => number)
|
|
223
|
-
nodeStrength?: number | ((d?: Node) => number)
|
|
224
|
-
edgeStrength?: number | ((d?: Edge) => number)
|
|
221
|
+
linkDistance?: number | ((edge?: Edge, source?: any, target?: any) => number);
|
|
222
|
+
nodeStrength?: number | ((d?: Node) => number);
|
|
223
|
+
edgeStrength?: number | ((d?: Edge) => number);
|
|
225
224
|
preventOverlap?: boolean;
|
|
226
225
|
nodeSize?: number | number[] | ((d?: Node) => number);
|
|
227
226
|
nodeSpacing?: number | ((d?: Node) => number);
|
|
@@ -241,8 +240,8 @@ export interface ForceLayoutOptions extends CommonOptions {
|
|
|
241
240
|
collideStrength?: number;
|
|
242
241
|
distanceThresholdMode?: "mean" | "max" | "min";
|
|
243
242
|
onTick?: (data: LayoutMapping) => void;
|
|
244
|
-
getMass?: (
|
|
245
|
-
getCenter?: (
|
|
243
|
+
getMass?: (node?: Node) => number;
|
|
244
|
+
getCenter?: (node?: Node, degree?: number) => number[];
|
|
246
245
|
monitor?: (params: {
|
|
247
246
|
energy: number;
|
|
248
247
|
nodes: Node[];
|
|
@@ -250,6 +249,24 @@ export interface ForceLayoutOptions extends CommonOptions {
|
|
|
250
249
|
iterations: number;
|
|
251
250
|
}) => void;
|
|
252
251
|
}
|
|
252
|
+
export interface ForceAtlas2LayoutOptions extends CommonOptions {
|
|
253
|
+
center?: PointTuple;
|
|
254
|
+
width?: number;
|
|
255
|
+
height?: number;
|
|
256
|
+
kr?: number;
|
|
257
|
+
kg?: number;
|
|
258
|
+
ks?: number;
|
|
259
|
+
ksmax?: number;
|
|
260
|
+
tao?: number;
|
|
261
|
+
maxIteration?: number;
|
|
262
|
+
mode?: "normal" | "linlog";
|
|
263
|
+
preventOverlap?: boolean;
|
|
264
|
+
dissuadeHubs?: boolean;
|
|
265
|
+
barnesHut?: boolean;
|
|
266
|
+
prune?: boolean;
|
|
267
|
+
nodeSize?: number | number[] | ((node?: Node) => number);
|
|
268
|
+
onTick?: (data: LayoutMapping) => void;
|
|
269
|
+
}
|
|
253
270
|
export interface FruchtermanLayoutOptions extends CommonOptions {
|
|
254
271
|
center?: PointTuple;
|
|
255
272
|
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/object.d.ts
CHANGED