@opentrace/components 0.1.0-pr.110.8
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/assets/d3LayoutWorker-BMQ60AVN.js +864 -0
- package/dist/assets/d3LayoutWorker-BMQ60AVN.js.map +1 -0
- package/dist/assets/spacingWorker-hXLGHyRg.js +123 -0
- package/dist/assets/spacingWorker-hXLGHyRg.js.map +1 -0
- package/dist/components.css +1 -0
- package/dist/opentrace-components.cjs +7565 -0
- package/dist/opentrace-components.cjs.map +1 -0
- package/dist/opentrace-components.js +7565 -0
- package/dist/opentrace-components.js.map +1 -0
- package/dist/src/GraphCanvas.d.ts +60 -0
- package/dist/src/GraphCanvas.d.ts.map +1 -0
- package/dist/src/colors/communityColors.d.ts +31 -0
- package/dist/src/colors/communityColors.d.ts.map +1 -0
- package/dist/src/colors/linkColors.d.ts +2 -0
- package/dist/src/colors/linkColors.d.ts.map +1 -0
- package/dist/src/colors/nodeColors.d.ts +2 -0
- package/dist/src/colors/nodeColors.d.ts.map +1 -0
- package/dist/src/config/graphLayout.d.ts +51 -0
- package/dist/src/config/graphLayout.d.ts.map +1 -0
- package/dist/src/graph/LayoutPipeline.d.ts +26 -0
- package/dist/src/graph/LayoutPipeline.d.ts.map +1 -0
- package/dist/src/graph/drawNodeHover.d.ts +14 -0
- package/dist/src/graph/drawNodeHover.d.ts.map +1 -0
- package/dist/src/graph/spacingWorker.d.ts +43 -0
- package/dist/src/graph/spacingWorker.d.ts.map +1 -0
- package/dist/src/graph/types.d.ts +78 -0
- package/dist/src/graph/types.d.ts.map +1 -0
- package/dist/src/graph/useCommunities.d.ts +8 -0
- package/dist/src/graph/useCommunities.d.ts.map +1 -0
- package/dist/src/graph/useGraphFilters.d.ts +19 -0
- package/dist/src/graph/useGraphFilters.d.ts.map +1 -0
- package/dist/src/graph/useGraphInstance.d.ts +15 -0
- package/dist/src/graph/useGraphInstance.d.ts.map +1 -0
- package/dist/src/graph/useGraphVisuals.d.ts +9 -0
- package/dist/src/graph/useGraphVisuals.d.ts.map +1 -0
- package/dist/src/graph/useHighlights.d.ts +16 -0
- package/dist/src/graph/useHighlights.d.ts.map +1 -0
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/sigma/zoomToNodes.d.ts +15 -0
- package/dist/src/sigma/zoomToNodes.d.ts.map +1 -0
- package/dist/src/types/graph.d.ts +33 -0
- package/dist/src/types/graph.d.ts.map +1 -0
- package/dist/src/utils.d.ts +16 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/workers/d3LayoutWorker.d.ts +22 -0
- package/dist/src/workers/d3LayoutWorker.d.ts.map +1 -0
- package/dist/useHighlights-BHlafcBH.js +6692 -0
- package/dist/useHighlights-BHlafcBH.js.map +1 -0
- package/dist/useHighlights-D6Jl6Woe.cjs +6691 -0
- package/dist/useHighlights-D6Jl6Woe.cjs.map +1 -0
- package/dist/utils.cjs +12 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.js +12 -0
- package/dist/utils.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
function forceCenter(x2, y2) {
|
|
2
|
+
var nodes, strength = 1;
|
|
3
|
+
if (x2 == null) x2 = 0;
|
|
4
|
+
if (y2 == null) y2 = 0;
|
|
5
|
+
function force() {
|
|
6
|
+
var i, n = nodes.length, node, sx = 0, sy = 0;
|
|
7
|
+
for (i = 0; i < n; ++i) {
|
|
8
|
+
node = nodes[i], sx += node.x, sy += node.y;
|
|
9
|
+
}
|
|
10
|
+
for (sx = (sx / n - x2) * strength, sy = (sy / n - y2) * strength, i = 0; i < n; ++i) {
|
|
11
|
+
node = nodes[i], node.x -= sx, node.y -= sy;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
force.initialize = function(_) {
|
|
15
|
+
nodes = _;
|
|
16
|
+
};
|
|
17
|
+
force.x = function(_) {
|
|
18
|
+
return arguments.length ? (x2 = +_, force) : x2;
|
|
19
|
+
};
|
|
20
|
+
force.y = function(_) {
|
|
21
|
+
return arguments.length ? (y2 = +_, force) : y2;
|
|
22
|
+
};
|
|
23
|
+
force.strength = function(_) {
|
|
24
|
+
return arguments.length ? (strength = +_, force) : strength;
|
|
25
|
+
};
|
|
26
|
+
return force;
|
|
27
|
+
}
|
|
28
|
+
function tree_add(d) {
|
|
29
|
+
const x2 = +this._x.call(null, d), y2 = +this._y.call(null, d);
|
|
30
|
+
return add(this.cover(x2, y2), x2, y2, d);
|
|
31
|
+
}
|
|
32
|
+
function add(tree, x2, y2, d) {
|
|
33
|
+
if (isNaN(x2) || isNaN(y2)) return tree;
|
|
34
|
+
var parent, node = tree._root, leaf = { data: d }, x0 = tree._x0, y0 = tree._y0, x1 = tree._x1, y1 = tree._y1, xm, ym, xp, yp, right, bottom, i, j;
|
|
35
|
+
if (!node) return tree._root = leaf, tree;
|
|
36
|
+
while (node.length) {
|
|
37
|
+
if (right = x2 >= (xm = (x0 + x1) / 2)) x0 = xm;
|
|
38
|
+
else x1 = xm;
|
|
39
|
+
if (bottom = y2 >= (ym = (y0 + y1) / 2)) y0 = ym;
|
|
40
|
+
else y1 = ym;
|
|
41
|
+
if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree;
|
|
42
|
+
}
|
|
43
|
+
xp = +tree._x.call(null, node.data);
|
|
44
|
+
yp = +tree._y.call(null, node.data);
|
|
45
|
+
if (x2 === xp && y2 === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
|
|
46
|
+
do {
|
|
47
|
+
parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
|
|
48
|
+
if (right = x2 >= (xm = (x0 + x1) / 2)) x0 = xm;
|
|
49
|
+
else x1 = xm;
|
|
50
|
+
if (bottom = y2 >= (ym = (y0 + y1) / 2)) y0 = ym;
|
|
51
|
+
else y1 = ym;
|
|
52
|
+
} while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | xp >= xm));
|
|
53
|
+
return parent[j] = node, parent[i] = leaf, tree;
|
|
54
|
+
}
|
|
55
|
+
function addAll(data) {
|
|
56
|
+
var d, i, n = data.length, x2, y2, xz = new Array(n), yz = new Array(n), x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
57
|
+
for (i = 0; i < n; ++i) {
|
|
58
|
+
if (isNaN(x2 = +this._x.call(null, d = data[i])) || isNaN(y2 = +this._y.call(null, d))) continue;
|
|
59
|
+
xz[i] = x2;
|
|
60
|
+
yz[i] = y2;
|
|
61
|
+
if (x2 < x0) x0 = x2;
|
|
62
|
+
if (x2 > x1) x1 = x2;
|
|
63
|
+
if (y2 < y0) y0 = y2;
|
|
64
|
+
if (y2 > y1) y1 = y2;
|
|
65
|
+
}
|
|
66
|
+
if (x0 > x1 || y0 > y1) return this;
|
|
67
|
+
this.cover(x0, y0).cover(x1, y1);
|
|
68
|
+
for (i = 0; i < n; ++i) {
|
|
69
|
+
add(this, xz[i], yz[i], data[i]);
|
|
70
|
+
}
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
function tree_cover(x2, y2) {
|
|
74
|
+
if (isNaN(x2 = +x2) || isNaN(y2 = +y2)) return this;
|
|
75
|
+
var x0 = this._x0, y0 = this._y0, x1 = this._x1, y1 = this._y1;
|
|
76
|
+
if (isNaN(x0)) {
|
|
77
|
+
x1 = (x0 = Math.floor(x2)) + 1;
|
|
78
|
+
y1 = (y0 = Math.floor(y2)) + 1;
|
|
79
|
+
} else {
|
|
80
|
+
var z = x1 - x0 || 1, node = this._root, parent, i;
|
|
81
|
+
while (x0 > x2 || x2 >= x1 || y0 > y2 || y2 >= y1) {
|
|
82
|
+
i = (y2 < y0) << 1 | x2 < x0;
|
|
83
|
+
parent = new Array(4), parent[i] = node, node = parent, z *= 2;
|
|
84
|
+
switch (i) {
|
|
85
|
+
case 0:
|
|
86
|
+
x1 = x0 + z, y1 = y0 + z;
|
|
87
|
+
break;
|
|
88
|
+
case 1:
|
|
89
|
+
x0 = x1 - z, y1 = y0 + z;
|
|
90
|
+
break;
|
|
91
|
+
case 2:
|
|
92
|
+
x1 = x0 + z, y0 = y1 - z;
|
|
93
|
+
break;
|
|
94
|
+
case 3:
|
|
95
|
+
x0 = x1 - z, y0 = y1 - z;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (this._root && this._root.length) this._root = node;
|
|
100
|
+
}
|
|
101
|
+
this._x0 = x0;
|
|
102
|
+
this._y0 = y0;
|
|
103
|
+
this._x1 = x1;
|
|
104
|
+
this._y1 = y1;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
function tree_data() {
|
|
108
|
+
var data = [];
|
|
109
|
+
this.visit(function(node) {
|
|
110
|
+
if (!node.length) do
|
|
111
|
+
data.push(node.data);
|
|
112
|
+
while (node = node.next);
|
|
113
|
+
});
|
|
114
|
+
return data;
|
|
115
|
+
}
|
|
116
|
+
function tree_extent(_) {
|
|
117
|
+
return arguments.length ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1]) : isNaN(this._x0) ? void 0 : [[this._x0, this._y0], [this._x1, this._y1]];
|
|
118
|
+
}
|
|
119
|
+
function Quad(node, x0, y0, x1, y1) {
|
|
120
|
+
this.node = node;
|
|
121
|
+
this.x0 = x0;
|
|
122
|
+
this.y0 = y0;
|
|
123
|
+
this.x1 = x1;
|
|
124
|
+
this.y1 = y1;
|
|
125
|
+
}
|
|
126
|
+
function tree_find(x2, y2, radius) {
|
|
127
|
+
var data, x0 = this._x0, y0 = this._y0, x1, y1, x22, y22, x3 = this._x1, y3 = this._y1, quads = [], node = this._root, q, i;
|
|
128
|
+
if (node) quads.push(new Quad(node, x0, y0, x3, y3));
|
|
129
|
+
if (radius == null) radius = Infinity;
|
|
130
|
+
else {
|
|
131
|
+
x0 = x2 - radius, y0 = y2 - radius;
|
|
132
|
+
x3 = x2 + radius, y3 = y2 + radius;
|
|
133
|
+
radius *= radius;
|
|
134
|
+
}
|
|
135
|
+
while (q = quads.pop()) {
|
|
136
|
+
if (!(node = q.node) || (x1 = q.x0) > x3 || (y1 = q.y0) > y3 || (x22 = q.x1) < x0 || (y22 = q.y1) < y0) continue;
|
|
137
|
+
if (node.length) {
|
|
138
|
+
var xm = (x1 + x22) / 2, ym = (y1 + y22) / 2;
|
|
139
|
+
quads.push(
|
|
140
|
+
new Quad(node[3], xm, ym, x22, y22),
|
|
141
|
+
new Quad(node[2], x1, ym, xm, y22),
|
|
142
|
+
new Quad(node[1], xm, y1, x22, ym),
|
|
143
|
+
new Quad(node[0], x1, y1, xm, ym)
|
|
144
|
+
);
|
|
145
|
+
if (i = (y2 >= ym) << 1 | x2 >= xm) {
|
|
146
|
+
q = quads[quads.length - 1];
|
|
147
|
+
quads[quads.length - 1] = quads[quads.length - 1 - i];
|
|
148
|
+
quads[quads.length - 1 - i] = q;
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
var dx = x2 - +this._x.call(null, node.data), dy = y2 - +this._y.call(null, node.data), d2 = dx * dx + dy * dy;
|
|
152
|
+
if (d2 < radius) {
|
|
153
|
+
var d = Math.sqrt(radius = d2);
|
|
154
|
+
x0 = x2 - d, y0 = y2 - d;
|
|
155
|
+
x3 = x2 + d, y3 = y2 + d;
|
|
156
|
+
data = node.data;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return data;
|
|
161
|
+
}
|
|
162
|
+
function tree_remove(d) {
|
|
163
|
+
if (isNaN(x2 = +this._x.call(null, d)) || isNaN(y2 = +this._y.call(null, d))) return this;
|
|
164
|
+
var parent, node = this._root, retainer, previous, next, x0 = this._x0, y0 = this._y0, x1 = this._x1, y1 = this._y1, x2, y2, xm, ym, right, bottom, i, j;
|
|
165
|
+
if (!node) return this;
|
|
166
|
+
if (node.length) while (true) {
|
|
167
|
+
if (right = x2 >= (xm = (x0 + x1) / 2)) x0 = xm;
|
|
168
|
+
else x1 = xm;
|
|
169
|
+
if (bottom = y2 >= (ym = (y0 + y1) / 2)) y0 = ym;
|
|
170
|
+
else y1 = ym;
|
|
171
|
+
if (!(parent = node, node = node[i = bottom << 1 | right])) return this;
|
|
172
|
+
if (!node.length) break;
|
|
173
|
+
if (parent[i + 1 & 3] || parent[i + 2 & 3] || parent[i + 3 & 3]) retainer = parent, j = i;
|
|
174
|
+
}
|
|
175
|
+
while (node.data !== d) if (!(previous = node, node = node.next)) return this;
|
|
176
|
+
if (next = node.next) delete node.next;
|
|
177
|
+
if (previous) return next ? previous.next = next : delete previous.next, this;
|
|
178
|
+
if (!parent) return this._root = next, this;
|
|
179
|
+
next ? parent[i] = next : delete parent[i];
|
|
180
|
+
if ((node = parent[0] || parent[1] || parent[2] || parent[3]) && node === (parent[3] || parent[2] || parent[1] || parent[0]) && !node.length) {
|
|
181
|
+
if (retainer) retainer[j] = node;
|
|
182
|
+
else this._root = node;
|
|
183
|
+
}
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
function removeAll(data) {
|
|
187
|
+
for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]);
|
|
188
|
+
return this;
|
|
189
|
+
}
|
|
190
|
+
function tree_root() {
|
|
191
|
+
return this._root;
|
|
192
|
+
}
|
|
193
|
+
function tree_size() {
|
|
194
|
+
var size = 0;
|
|
195
|
+
this.visit(function(node) {
|
|
196
|
+
if (!node.length) do
|
|
197
|
+
++size;
|
|
198
|
+
while (node = node.next);
|
|
199
|
+
});
|
|
200
|
+
return size;
|
|
201
|
+
}
|
|
202
|
+
function tree_visit(callback) {
|
|
203
|
+
var quads = [], q, node = this._root, child, x0, y0, x1, y1;
|
|
204
|
+
if (node) quads.push(new Quad(node, this._x0, this._y0, this._x1, this._y1));
|
|
205
|
+
while (q = quads.pop()) {
|
|
206
|
+
if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
|
|
207
|
+
var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
|
208
|
+
if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
|
209
|
+
if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
|
210
|
+
if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
|
211
|
+
if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
function tree_visitAfter(callback) {
|
|
217
|
+
var quads = [], next = [], q;
|
|
218
|
+
if (this._root) quads.push(new Quad(this._root, this._x0, this._y0, this._x1, this._y1));
|
|
219
|
+
while (q = quads.pop()) {
|
|
220
|
+
var node = q.node;
|
|
221
|
+
if (node.length) {
|
|
222
|
+
var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
|
223
|
+
if (child = node[0]) quads.push(new Quad(child, x0, y0, xm, ym));
|
|
224
|
+
if (child = node[1]) quads.push(new Quad(child, xm, y0, x1, ym));
|
|
225
|
+
if (child = node[2]) quads.push(new Quad(child, x0, ym, xm, y1));
|
|
226
|
+
if (child = node[3]) quads.push(new Quad(child, xm, ym, x1, y1));
|
|
227
|
+
}
|
|
228
|
+
next.push(q);
|
|
229
|
+
}
|
|
230
|
+
while (q = next.pop()) {
|
|
231
|
+
callback(q.node, q.x0, q.y0, q.x1, q.y1);
|
|
232
|
+
}
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
function defaultX(d) {
|
|
236
|
+
return d[0];
|
|
237
|
+
}
|
|
238
|
+
function tree_x(_) {
|
|
239
|
+
return arguments.length ? (this._x = _, this) : this._x;
|
|
240
|
+
}
|
|
241
|
+
function defaultY(d) {
|
|
242
|
+
return d[1];
|
|
243
|
+
}
|
|
244
|
+
function tree_y(_) {
|
|
245
|
+
return arguments.length ? (this._y = _, this) : this._y;
|
|
246
|
+
}
|
|
247
|
+
function quadtree(nodes, x2, y2) {
|
|
248
|
+
var tree = new Quadtree(x2 == null ? defaultX : x2, y2 == null ? defaultY : y2, NaN, NaN, NaN, NaN);
|
|
249
|
+
return nodes == null ? tree : tree.addAll(nodes);
|
|
250
|
+
}
|
|
251
|
+
function Quadtree(x2, y2, x0, y0, x1, y1) {
|
|
252
|
+
this._x = x2;
|
|
253
|
+
this._y = y2;
|
|
254
|
+
this._x0 = x0;
|
|
255
|
+
this._y0 = y0;
|
|
256
|
+
this._x1 = x1;
|
|
257
|
+
this._y1 = y1;
|
|
258
|
+
this._root = void 0;
|
|
259
|
+
}
|
|
260
|
+
function leaf_copy(leaf) {
|
|
261
|
+
var copy = { data: leaf.data }, next = copy;
|
|
262
|
+
while (leaf = leaf.next) next = next.next = { data: leaf.data };
|
|
263
|
+
return copy;
|
|
264
|
+
}
|
|
265
|
+
var treeProto = quadtree.prototype = Quadtree.prototype;
|
|
266
|
+
treeProto.copy = function() {
|
|
267
|
+
var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1), node = this._root, nodes, child;
|
|
268
|
+
if (!node) return copy;
|
|
269
|
+
if (!node.length) return copy._root = leaf_copy(node), copy;
|
|
270
|
+
nodes = [{ source: node, target: copy._root = new Array(4) }];
|
|
271
|
+
while (node = nodes.pop()) {
|
|
272
|
+
for (var i = 0; i < 4; ++i) {
|
|
273
|
+
if (child = node.source[i]) {
|
|
274
|
+
if (child.length) nodes.push({ source: child, target: node.target[i] = new Array(4) });
|
|
275
|
+
else node.target[i] = leaf_copy(child);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return copy;
|
|
280
|
+
};
|
|
281
|
+
treeProto.add = tree_add;
|
|
282
|
+
treeProto.addAll = addAll;
|
|
283
|
+
treeProto.cover = tree_cover;
|
|
284
|
+
treeProto.data = tree_data;
|
|
285
|
+
treeProto.extent = tree_extent;
|
|
286
|
+
treeProto.find = tree_find;
|
|
287
|
+
treeProto.remove = tree_remove;
|
|
288
|
+
treeProto.removeAll = removeAll;
|
|
289
|
+
treeProto.root = tree_root;
|
|
290
|
+
treeProto.size = tree_size;
|
|
291
|
+
treeProto.visit = tree_visit;
|
|
292
|
+
treeProto.visitAfter = tree_visitAfter;
|
|
293
|
+
treeProto.x = tree_x;
|
|
294
|
+
treeProto.y = tree_y;
|
|
295
|
+
function constant(x2) {
|
|
296
|
+
return function() {
|
|
297
|
+
return x2;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function jiggle(random) {
|
|
301
|
+
return (random() - 0.5) * 1e-6;
|
|
302
|
+
}
|
|
303
|
+
function index(d) {
|
|
304
|
+
return d.index;
|
|
305
|
+
}
|
|
306
|
+
function find(nodeById, nodeId) {
|
|
307
|
+
var node = nodeById.get(nodeId);
|
|
308
|
+
if (!node) throw new Error("node not found: " + nodeId);
|
|
309
|
+
return node;
|
|
310
|
+
}
|
|
311
|
+
function forceLink(links) {
|
|
312
|
+
var id = index, strength = defaultStrength, strengths, distance = constant(30), distances, nodes, count, bias, random, iterations = 1;
|
|
313
|
+
if (links == null) links = [];
|
|
314
|
+
function defaultStrength(link) {
|
|
315
|
+
return 1 / Math.min(count[link.source.index], count[link.target.index]);
|
|
316
|
+
}
|
|
317
|
+
function force(alpha) {
|
|
318
|
+
for (var k = 0, n = links.length; k < iterations; ++k) {
|
|
319
|
+
for (var i = 0, link, source, target, x2, y2, l, b; i < n; ++i) {
|
|
320
|
+
link = links[i], source = link.source, target = link.target;
|
|
321
|
+
x2 = target.x + target.vx - source.x - source.vx || jiggle(random);
|
|
322
|
+
y2 = target.y + target.vy - source.y - source.vy || jiggle(random);
|
|
323
|
+
l = Math.sqrt(x2 * x2 + y2 * y2);
|
|
324
|
+
l = (l - distances[i]) / l * alpha * strengths[i];
|
|
325
|
+
x2 *= l, y2 *= l;
|
|
326
|
+
target.vx -= x2 * (b = bias[i]);
|
|
327
|
+
target.vy -= y2 * b;
|
|
328
|
+
source.vx += x2 * (b = 1 - b);
|
|
329
|
+
source.vy += y2 * b;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function initialize() {
|
|
334
|
+
if (!nodes) return;
|
|
335
|
+
var i, n = nodes.length, m2 = links.length, nodeById = new Map(nodes.map((d, i2) => [id(d, i2, nodes), d])), link;
|
|
336
|
+
for (i = 0, count = new Array(n); i < m2; ++i) {
|
|
337
|
+
link = links[i], link.index = i;
|
|
338
|
+
if (typeof link.source !== "object") link.source = find(nodeById, link.source);
|
|
339
|
+
if (typeof link.target !== "object") link.target = find(nodeById, link.target);
|
|
340
|
+
count[link.source.index] = (count[link.source.index] || 0) + 1;
|
|
341
|
+
count[link.target.index] = (count[link.target.index] || 0) + 1;
|
|
342
|
+
}
|
|
343
|
+
for (i = 0, bias = new Array(m2); i < m2; ++i) {
|
|
344
|
+
link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
|
|
345
|
+
}
|
|
346
|
+
strengths = new Array(m2), initializeStrength();
|
|
347
|
+
distances = new Array(m2), initializeDistance();
|
|
348
|
+
}
|
|
349
|
+
function initializeStrength() {
|
|
350
|
+
if (!nodes) return;
|
|
351
|
+
for (var i = 0, n = links.length; i < n; ++i) {
|
|
352
|
+
strengths[i] = +strength(links[i], i, links);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
function initializeDistance() {
|
|
356
|
+
if (!nodes) return;
|
|
357
|
+
for (var i = 0, n = links.length; i < n; ++i) {
|
|
358
|
+
distances[i] = +distance(links[i], i, links);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
force.initialize = function(_nodes, _random) {
|
|
362
|
+
nodes = _nodes;
|
|
363
|
+
random = _random;
|
|
364
|
+
initialize();
|
|
365
|
+
};
|
|
366
|
+
force.links = function(_) {
|
|
367
|
+
return arguments.length ? (links = _, initialize(), force) : links;
|
|
368
|
+
};
|
|
369
|
+
force.id = function(_) {
|
|
370
|
+
return arguments.length ? (id = _, force) : id;
|
|
371
|
+
};
|
|
372
|
+
force.iterations = function(_) {
|
|
373
|
+
return arguments.length ? (iterations = +_, force) : iterations;
|
|
374
|
+
};
|
|
375
|
+
force.strength = function(_) {
|
|
376
|
+
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initializeStrength(), force) : strength;
|
|
377
|
+
};
|
|
378
|
+
force.distance = function(_) {
|
|
379
|
+
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), initializeDistance(), force) : distance;
|
|
380
|
+
};
|
|
381
|
+
return force;
|
|
382
|
+
}
|
|
383
|
+
var noop = { value: () => {
|
|
384
|
+
} };
|
|
385
|
+
function dispatch() {
|
|
386
|
+
for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) {
|
|
387
|
+
if (!(t = arguments[i] + "") || t in _ || /[\s.]/.test(t)) throw new Error("illegal type: " + t);
|
|
388
|
+
_[t] = [];
|
|
389
|
+
}
|
|
390
|
+
return new Dispatch(_);
|
|
391
|
+
}
|
|
392
|
+
function Dispatch(_) {
|
|
393
|
+
this._ = _;
|
|
394
|
+
}
|
|
395
|
+
function parseTypenames(typenames, types) {
|
|
396
|
+
return typenames.trim().split(/^|\s+/).map(function(t) {
|
|
397
|
+
var name = "", i = t.indexOf(".");
|
|
398
|
+
if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i);
|
|
399
|
+
if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t);
|
|
400
|
+
return { type: t, name };
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
Dispatch.prototype = dispatch.prototype = {
|
|
404
|
+
constructor: Dispatch,
|
|
405
|
+
on: function(typename, callback) {
|
|
406
|
+
var _ = this._, T = parseTypenames(typename + "", _), t, i = -1, n = T.length;
|
|
407
|
+
if (arguments.length < 2) {
|
|
408
|
+
while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t;
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback);
|
|
412
|
+
while (++i < n) {
|
|
413
|
+
if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback);
|
|
414
|
+
else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null);
|
|
415
|
+
}
|
|
416
|
+
return this;
|
|
417
|
+
},
|
|
418
|
+
copy: function() {
|
|
419
|
+
var copy = {}, _ = this._;
|
|
420
|
+
for (var t in _) copy[t] = _[t].slice();
|
|
421
|
+
return new Dispatch(copy);
|
|
422
|
+
},
|
|
423
|
+
call: function(type, that) {
|
|
424
|
+
if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2];
|
|
425
|
+
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
|
426
|
+
for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
|
427
|
+
},
|
|
428
|
+
apply: function(type, that, args) {
|
|
429
|
+
if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type);
|
|
430
|
+
for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
function get(type, name) {
|
|
434
|
+
for (var i = 0, n = type.length, c2; i < n; ++i) {
|
|
435
|
+
if ((c2 = type[i]).name === name) {
|
|
436
|
+
return c2.value;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function set(type, name, callback) {
|
|
441
|
+
for (var i = 0, n = type.length; i < n; ++i) {
|
|
442
|
+
if (type[i].name === name) {
|
|
443
|
+
type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (callback != null) type.push({ name, value: callback });
|
|
448
|
+
return type;
|
|
449
|
+
}
|
|
450
|
+
var frame = 0, timeout = 0, interval = 0, pokeDelay = 1e3, taskHead, taskTail, clockLast = 0, clockNow = 0, clockSkew = 0, clock = typeof performance === "object" && performance.now ? performance : Date, setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) {
|
|
451
|
+
setTimeout(f, 17);
|
|
452
|
+
};
|
|
453
|
+
function now() {
|
|
454
|
+
return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
|
|
455
|
+
}
|
|
456
|
+
function clearNow() {
|
|
457
|
+
clockNow = 0;
|
|
458
|
+
}
|
|
459
|
+
function Timer() {
|
|
460
|
+
this._call = this._time = this._next = null;
|
|
461
|
+
}
|
|
462
|
+
Timer.prototype = timer.prototype = {
|
|
463
|
+
constructor: Timer,
|
|
464
|
+
restart: function(callback, delay, time) {
|
|
465
|
+
if (typeof callback !== "function") throw new TypeError("callback is not a function");
|
|
466
|
+
time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
|
|
467
|
+
if (!this._next && taskTail !== this) {
|
|
468
|
+
if (taskTail) taskTail._next = this;
|
|
469
|
+
else taskHead = this;
|
|
470
|
+
taskTail = this;
|
|
471
|
+
}
|
|
472
|
+
this._call = callback;
|
|
473
|
+
this._time = time;
|
|
474
|
+
sleep();
|
|
475
|
+
},
|
|
476
|
+
stop: function() {
|
|
477
|
+
if (this._call) {
|
|
478
|
+
this._call = null;
|
|
479
|
+
this._time = Infinity;
|
|
480
|
+
sleep();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
function timer(callback, delay, time) {
|
|
485
|
+
var t = new Timer();
|
|
486
|
+
t.restart(callback, delay, time);
|
|
487
|
+
return t;
|
|
488
|
+
}
|
|
489
|
+
function timerFlush() {
|
|
490
|
+
now();
|
|
491
|
+
++frame;
|
|
492
|
+
var t = taskHead, e;
|
|
493
|
+
while (t) {
|
|
494
|
+
if ((e = clockNow - t._time) >= 0) t._call.call(void 0, e);
|
|
495
|
+
t = t._next;
|
|
496
|
+
}
|
|
497
|
+
--frame;
|
|
498
|
+
}
|
|
499
|
+
function wake() {
|
|
500
|
+
clockNow = (clockLast = clock.now()) + clockSkew;
|
|
501
|
+
frame = timeout = 0;
|
|
502
|
+
try {
|
|
503
|
+
timerFlush();
|
|
504
|
+
} finally {
|
|
505
|
+
frame = 0;
|
|
506
|
+
nap();
|
|
507
|
+
clockNow = 0;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function poke() {
|
|
511
|
+
var now2 = clock.now(), delay = now2 - clockLast;
|
|
512
|
+
if (delay > pokeDelay) clockSkew -= delay, clockLast = now2;
|
|
513
|
+
}
|
|
514
|
+
function nap() {
|
|
515
|
+
var t0, t1 = taskHead, t2, time = Infinity;
|
|
516
|
+
while (t1) {
|
|
517
|
+
if (t1._call) {
|
|
518
|
+
if (time > t1._time) time = t1._time;
|
|
519
|
+
t0 = t1, t1 = t1._next;
|
|
520
|
+
} else {
|
|
521
|
+
t2 = t1._next, t1._next = null;
|
|
522
|
+
t1 = t0 ? t0._next = t2 : taskHead = t2;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
taskTail = t0;
|
|
526
|
+
sleep(time);
|
|
527
|
+
}
|
|
528
|
+
function sleep(time) {
|
|
529
|
+
if (frame) return;
|
|
530
|
+
if (timeout) timeout = clearTimeout(timeout);
|
|
531
|
+
var delay = time - clockNow;
|
|
532
|
+
if (delay > 24) {
|
|
533
|
+
if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew);
|
|
534
|
+
if (interval) interval = clearInterval(interval);
|
|
535
|
+
} else {
|
|
536
|
+
if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
|
|
537
|
+
frame = 1, setFrame(wake);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const a = 1664525;
|
|
541
|
+
const c = 1013904223;
|
|
542
|
+
const m = 4294967296;
|
|
543
|
+
function lcg() {
|
|
544
|
+
let s = 1;
|
|
545
|
+
return () => (s = (a * s + c) % m) / m;
|
|
546
|
+
}
|
|
547
|
+
function x(d) {
|
|
548
|
+
return d.x;
|
|
549
|
+
}
|
|
550
|
+
function y(d) {
|
|
551
|
+
return d.y;
|
|
552
|
+
}
|
|
553
|
+
var initialRadius = 10, initialAngle = Math.PI * (3 - Math.sqrt(5));
|
|
554
|
+
function forceSimulation(nodes) {
|
|
555
|
+
var simulation, alpha = 1, alphaMin = 1e-3, alphaDecay = 1 - Math.pow(alphaMin, 1 / 300), alphaTarget = 0, velocityDecay = 0.6, forces = /* @__PURE__ */ new Map(), stepper = timer(step), event = dispatch("tick", "end"), random = lcg();
|
|
556
|
+
if (nodes == null) nodes = [];
|
|
557
|
+
function step() {
|
|
558
|
+
tick();
|
|
559
|
+
event.call("tick", simulation);
|
|
560
|
+
if (alpha < alphaMin) {
|
|
561
|
+
stepper.stop();
|
|
562
|
+
event.call("end", simulation);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function tick(iterations) {
|
|
566
|
+
var i, n = nodes.length, node;
|
|
567
|
+
if (iterations === void 0) iterations = 1;
|
|
568
|
+
for (var k = 0; k < iterations; ++k) {
|
|
569
|
+
alpha += (alphaTarget - alpha) * alphaDecay;
|
|
570
|
+
forces.forEach(function(force) {
|
|
571
|
+
force(alpha);
|
|
572
|
+
});
|
|
573
|
+
for (i = 0; i < n; ++i) {
|
|
574
|
+
node = nodes[i];
|
|
575
|
+
if (node.fx == null) node.x += node.vx *= velocityDecay;
|
|
576
|
+
else node.x = node.fx, node.vx = 0;
|
|
577
|
+
if (node.fy == null) node.y += node.vy *= velocityDecay;
|
|
578
|
+
else node.y = node.fy, node.vy = 0;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return simulation;
|
|
582
|
+
}
|
|
583
|
+
function initializeNodes() {
|
|
584
|
+
for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
|
585
|
+
node = nodes[i], node.index = i;
|
|
586
|
+
if (node.fx != null) node.x = node.fx;
|
|
587
|
+
if (node.fy != null) node.y = node.fy;
|
|
588
|
+
if (isNaN(node.x) || isNaN(node.y)) {
|
|
589
|
+
var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
|
|
590
|
+
node.x = radius * Math.cos(angle);
|
|
591
|
+
node.y = radius * Math.sin(angle);
|
|
592
|
+
}
|
|
593
|
+
if (isNaN(node.vx) || isNaN(node.vy)) {
|
|
594
|
+
node.vx = node.vy = 0;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function initializeForce(force) {
|
|
599
|
+
if (force.initialize) force.initialize(nodes, random);
|
|
600
|
+
return force;
|
|
601
|
+
}
|
|
602
|
+
initializeNodes();
|
|
603
|
+
return simulation = {
|
|
604
|
+
tick,
|
|
605
|
+
restart: function() {
|
|
606
|
+
return stepper.restart(step), simulation;
|
|
607
|
+
},
|
|
608
|
+
stop: function() {
|
|
609
|
+
return stepper.stop(), simulation;
|
|
610
|
+
},
|
|
611
|
+
nodes: function(_) {
|
|
612
|
+
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
|
|
613
|
+
},
|
|
614
|
+
alpha: function(_) {
|
|
615
|
+
return arguments.length ? (alpha = +_, simulation) : alpha;
|
|
616
|
+
},
|
|
617
|
+
alphaMin: function(_) {
|
|
618
|
+
return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
|
|
619
|
+
},
|
|
620
|
+
alphaDecay: function(_) {
|
|
621
|
+
return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
|
|
622
|
+
},
|
|
623
|
+
alphaTarget: function(_) {
|
|
624
|
+
return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
|
|
625
|
+
},
|
|
626
|
+
velocityDecay: function(_) {
|
|
627
|
+
return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
|
|
628
|
+
},
|
|
629
|
+
randomSource: function(_) {
|
|
630
|
+
return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
|
|
631
|
+
},
|
|
632
|
+
force: function(name, _) {
|
|
633
|
+
return arguments.length > 1 ? (_ == null ? forces.delete(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
|
|
634
|
+
},
|
|
635
|
+
find: function(x2, y2, radius) {
|
|
636
|
+
var i = 0, n = nodes.length, dx, dy, d2, node, closest;
|
|
637
|
+
if (radius == null) radius = Infinity;
|
|
638
|
+
else radius *= radius;
|
|
639
|
+
for (i = 0; i < n; ++i) {
|
|
640
|
+
node = nodes[i];
|
|
641
|
+
dx = x2 - node.x;
|
|
642
|
+
dy = y2 - node.y;
|
|
643
|
+
d2 = dx * dx + dy * dy;
|
|
644
|
+
if (d2 < radius) closest = node, radius = d2;
|
|
645
|
+
}
|
|
646
|
+
return closest;
|
|
647
|
+
},
|
|
648
|
+
on: function(name, _) {
|
|
649
|
+
return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
function forceManyBody() {
|
|
654
|
+
var nodes, node, random, alpha, strength = constant(-30), strengths, distanceMin2 = 1, distanceMax2 = Infinity, theta2 = 0.81;
|
|
655
|
+
function force(_) {
|
|
656
|
+
var i, n = nodes.length, tree = quadtree(nodes, x, y).visitAfter(accumulate);
|
|
657
|
+
for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply);
|
|
658
|
+
}
|
|
659
|
+
function initialize() {
|
|
660
|
+
if (!nodes) return;
|
|
661
|
+
var i, n = nodes.length, node2;
|
|
662
|
+
strengths = new Array(n);
|
|
663
|
+
for (i = 0; i < n; ++i) node2 = nodes[i], strengths[node2.index] = +strength(node2, i, nodes);
|
|
664
|
+
}
|
|
665
|
+
function accumulate(quad) {
|
|
666
|
+
var strength2 = 0, q, c2, weight = 0, x2, y2, i;
|
|
667
|
+
if (quad.length) {
|
|
668
|
+
for (x2 = y2 = i = 0; i < 4; ++i) {
|
|
669
|
+
if ((q = quad[i]) && (c2 = Math.abs(q.value))) {
|
|
670
|
+
strength2 += q.value, weight += c2, x2 += c2 * q.x, y2 += c2 * q.y;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
quad.x = x2 / weight;
|
|
674
|
+
quad.y = y2 / weight;
|
|
675
|
+
} else {
|
|
676
|
+
q = quad;
|
|
677
|
+
q.x = q.data.x;
|
|
678
|
+
q.y = q.data.y;
|
|
679
|
+
do
|
|
680
|
+
strength2 += strengths[q.data.index];
|
|
681
|
+
while (q = q.next);
|
|
682
|
+
}
|
|
683
|
+
quad.value = strength2;
|
|
684
|
+
}
|
|
685
|
+
function apply(quad, x1, _, x2) {
|
|
686
|
+
if (!quad.value) return true;
|
|
687
|
+
var x3 = quad.x - node.x, y2 = quad.y - node.y, w = x2 - x1, l = x3 * x3 + y2 * y2;
|
|
688
|
+
if (w * w / theta2 < l) {
|
|
689
|
+
if (l < distanceMax2) {
|
|
690
|
+
if (x3 === 0) x3 = jiggle(random), l += x3 * x3;
|
|
691
|
+
if (y2 === 0) y2 = jiggle(random), l += y2 * y2;
|
|
692
|
+
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
|
693
|
+
node.vx += x3 * quad.value * alpha / l;
|
|
694
|
+
node.vy += y2 * quad.value * alpha / l;
|
|
695
|
+
}
|
|
696
|
+
return true;
|
|
697
|
+
} else if (quad.length || l >= distanceMax2) return;
|
|
698
|
+
if (quad.data !== node || quad.next) {
|
|
699
|
+
if (x3 === 0) x3 = jiggle(random), l += x3 * x3;
|
|
700
|
+
if (y2 === 0) y2 = jiggle(random), l += y2 * y2;
|
|
701
|
+
if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l);
|
|
702
|
+
}
|
|
703
|
+
do
|
|
704
|
+
if (quad.data !== node) {
|
|
705
|
+
w = strengths[quad.data.index] * alpha / l;
|
|
706
|
+
node.vx += x3 * w;
|
|
707
|
+
node.vy += y2 * w;
|
|
708
|
+
}
|
|
709
|
+
while (quad = quad.next);
|
|
710
|
+
}
|
|
711
|
+
force.initialize = function(_nodes, _random) {
|
|
712
|
+
nodes = _nodes;
|
|
713
|
+
random = _random;
|
|
714
|
+
initialize();
|
|
715
|
+
};
|
|
716
|
+
force.strength = function(_) {
|
|
717
|
+
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
|
|
718
|
+
};
|
|
719
|
+
force.distanceMin = function(_) {
|
|
720
|
+
return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
|
|
721
|
+
};
|
|
722
|
+
force.distanceMax = function(_) {
|
|
723
|
+
return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
|
|
724
|
+
};
|
|
725
|
+
force.theta = function(_) {
|
|
726
|
+
return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
|
|
727
|
+
};
|
|
728
|
+
return force;
|
|
729
|
+
}
|
|
730
|
+
function forceX(x2) {
|
|
731
|
+
var strength = constant(0.1), nodes, strengths, xz;
|
|
732
|
+
if (typeof x2 !== "function") x2 = constant(x2 == null ? 0 : +x2);
|
|
733
|
+
function force(alpha) {
|
|
734
|
+
for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
|
735
|
+
node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
function initialize() {
|
|
739
|
+
if (!nodes) return;
|
|
740
|
+
var i, n = nodes.length;
|
|
741
|
+
strengths = new Array(n);
|
|
742
|
+
xz = new Array(n);
|
|
743
|
+
for (i = 0; i < n; ++i) {
|
|
744
|
+
strengths[i] = isNaN(xz[i] = +x2(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
force.initialize = function(_) {
|
|
748
|
+
nodes = _;
|
|
749
|
+
initialize();
|
|
750
|
+
};
|
|
751
|
+
force.strength = function(_) {
|
|
752
|
+
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
|
|
753
|
+
};
|
|
754
|
+
force.x = function(_) {
|
|
755
|
+
return arguments.length ? (x2 = typeof _ === "function" ? _ : constant(+_), initialize(), force) : x2;
|
|
756
|
+
};
|
|
757
|
+
return force;
|
|
758
|
+
}
|
|
759
|
+
function forceY(y2) {
|
|
760
|
+
var strength = constant(0.1), nodes, strengths, yz;
|
|
761
|
+
if (typeof y2 !== "function") y2 = constant(y2 == null ? 0 : +y2);
|
|
762
|
+
function force(alpha) {
|
|
763
|
+
for (var i = 0, n = nodes.length, node; i < n; ++i) {
|
|
764
|
+
node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
function initialize() {
|
|
768
|
+
if (!nodes) return;
|
|
769
|
+
var i, n = nodes.length;
|
|
770
|
+
strengths = new Array(n);
|
|
771
|
+
yz = new Array(n);
|
|
772
|
+
for (i = 0; i < n; ++i) {
|
|
773
|
+
strengths[i] = isNaN(yz[i] = +y2(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
force.initialize = function(_) {
|
|
777
|
+
nodes = _;
|
|
778
|
+
initialize();
|
|
779
|
+
};
|
|
780
|
+
force.strength = function(_) {
|
|
781
|
+
return arguments.length ? (strength = typeof _ === "function" ? _ : constant(+_), initialize(), force) : strength;
|
|
782
|
+
};
|
|
783
|
+
force.y = function(_) {
|
|
784
|
+
return arguments.length ? (y2 = typeof _ === "function" ? _ : constant(+_), initialize(), force) : y2;
|
|
785
|
+
};
|
|
786
|
+
return force;
|
|
787
|
+
}
|
|
788
|
+
self.onmessage = (e) => {
|
|
789
|
+
const { nodeIds, links, communities, config } = e.data;
|
|
790
|
+
const simNodes = nodeIds.map((id) => ({ id }));
|
|
791
|
+
const simulation = forceSimulation(simNodes).force(
|
|
792
|
+
"link",
|
|
793
|
+
forceLink(links).id((d) => d.id).distance(config.linkDistance)
|
|
794
|
+
).force("charge", forceManyBody().strength(config.chargeStrength)).force("center", forceCenter(0, 0)).stop();
|
|
795
|
+
for (let i = 0; i < config.ticks; i++) {
|
|
796
|
+
simulation.tick();
|
|
797
|
+
}
|
|
798
|
+
if (communities && config.clusterStrength) {
|
|
799
|
+
const centroidSums = /* @__PURE__ */ new Map();
|
|
800
|
+
for (const node of simNodes) {
|
|
801
|
+
const cid = communities[node.id];
|
|
802
|
+
if (cid === void 0) continue;
|
|
803
|
+
const entry = centroidSums.get(cid) || { x: 0, y: 0, count: 0 };
|
|
804
|
+
entry.x += node.x ?? 0;
|
|
805
|
+
entry.y += node.y ?? 0;
|
|
806
|
+
entry.count += 1;
|
|
807
|
+
centroidSums.set(cid, entry);
|
|
808
|
+
}
|
|
809
|
+
const centroids = /* @__PURE__ */ new Map();
|
|
810
|
+
for (const [cid, { x: x2, y: y2, count }] of centroidSums) {
|
|
811
|
+
centroids.set(cid, { x: x2 / count, y: y2 / count });
|
|
812
|
+
}
|
|
813
|
+
const baseSep = config.clusterSeparation ?? 1;
|
|
814
|
+
const separation = centroids.size <= 10 ? 1 : baseSep * Math.log10(centroids.size);
|
|
815
|
+
if (separation > 1 && centroids.size > 1) {
|
|
816
|
+
let gx = 0, gy = 0;
|
|
817
|
+
for (const { x: x2, y: y2 } of centroids.values()) {
|
|
818
|
+
gx += x2;
|
|
819
|
+
gy += y2;
|
|
820
|
+
}
|
|
821
|
+
gx /= centroids.size;
|
|
822
|
+
gy /= centroids.size;
|
|
823
|
+
for (const [cid, c2] of centroids) {
|
|
824
|
+
centroids.set(cid, {
|
|
825
|
+
x: gx + (c2.x - gx) * separation,
|
|
826
|
+
y: gy + (c2.y - gy) * separation
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
const nodeCentroid = /* @__PURE__ */ new Map();
|
|
831
|
+
for (const node of simNodes) {
|
|
832
|
+
const cid = communities[node.id];
|
|
833
|
+
if (cid !== void 0 && centroids.has(cid)) {
|
|
834
|
+
nodeCentroid.set(node.id, centroids.get(cid));
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
const sim2 = forceSimulation(simNodes).force(
|
|
838
|
+
"link",
|
|
839
|
+
forceLink(links).id((d) => d.id).distance(config.linkDistance)
|
|
840
|
+
).force("charge", forceManyBody().strength(config.chargeStrength * 0.5)).force(
|
|
841
|
+
"clusterX",
|
|
842
|
+
forceX((d) => nodeCentroid.get(d.id)?.x ?? 0).strength(
|
|
843
|
+
config.clusterStrength
|
|
844
|
+
)
|
|
845
|
+
).force(
|
|
846
|
+
"clusterY",
|
|
847
|
+
forceY((d) => nodeCentroid.get(d.id)?.y ?? 0).strength(
|
|
848
|
+
config.clusterStrength
|
|
849
|
+
)
|
|
850
|
+
).stop();
|
|
851
|
+
for (let i = 0; i < (config.clusterTicks ?? 40); i++) {
|
|
852
|
+
sim2.tick();
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
const positions = simNodes.map((n) => [
|
|
856
|
+
n.id,
|
|
857
|
+
n.x ?? 0,
|
|
858
|
+
n.y ?? 0
|
|
859
|
+
]);
|
|
860
|
+
self.postMessage({
|
|
861
|
+
positions
|
|
862
|
+
});
|
|
863
|
+
};
|
|
864
|
+
//# sourceMappingURL=d3LayoutWorker-BMQ60AVN.js.map
|