@opendata-ai/openchart-vanilla 2.0.0
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/index.d.ts +327 -0
- package/dist/index.js +4745 -0
- package/dist/index.js.map +1 -0
- package/dist/simulation-worker.js +1196 -0
- package/package.json +58 -0
- package/src/__test-fixtures__/dom.ts +42 -0
- package/src/__test-fixtures__/specs.ts +187 -0
- package/src/__tests__/edit-events.test.ts +747 -0
- package/src/__tests__/events.test.ts +336 -0
- package/src/__tests__/export.test.ts +150 -0
- package/src/__tests__/mount.test.ts +219 -0
- package/src/__tests__/svg-renderer.test.ts +609 -0
- package/src/__tests__/table-mount.test.ts +484 -0
- package/src/__tests__/tooltip.test.ts +201 -0
- package/src/export.ts +105 -0
- package/src/graph/__tests__/canvas-renderer.test.ts +704 -0
- package/src/graph/__tests__/graph-mount.test.ts +213 -0
- package/src/graph/__tests__/interaction.test.ts +205 -0
- package/src/graph/__tests__/keyboard.test.ts +653 -0
- package/src/graph/__tests__/search.test.ts +88 -0
- package/src/graph/__tests__/simulation.test.ts +233 -0
- package/src/graph/__tests__/spatial-index.test.ts +142 -0
- package/src/graph/__tests__/zoom.test.ts +195 -0
- package/src/graph/canvas-renderer.ts +660 -0
- package/src/graph/interaction.ts +359 -0
- package/src/graph/keyboard.ts +208 -0
- package/src/graph/search.ts +50 -0
- package/src/graph/simulation-worker-url.ts +30 -0
- package/src/graph/simulation-worker.ts +265 -0
- package/src/graph/simulation.ts +350 -0
- package/src/graph/spatial-index.ts +121 -0
- package/src/graph/types.ts +44 -0
- package/src/graph/worker-protocol.ts +67 -0
- package/src/graph/zoom.ts +104 -0
- package/src/graph-mount.ts +675 -0
- package/src/index.ts +56 -0
- package/src/mount.ts +1639 -0
- package/src/renderers/table-cells.ts +444 -0
- package/src/resize-observer.ts +46 -0
- package/src/svg-renderer.ts +914 -0
- package/src/table-keyboard.ts +266 -0
- package/src/table-mount.ts +532 -0
- package/src/table-renderer.ts +350 -0
- package/src/tooltip.ts +120 -0
|
@@ -0,0 +1,1196 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
33
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
34
|
+
}) : x)(function(x) {
|
|
35
|
+
if (typeof require !== "undefined")
|
|
36
|
+
return require.apply(this, arguments);
|
|
37
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/center.js
|
|
41
|
+
function center_default(x, y) {
|
|
42
|
+
var nodes, strength = 1;
|
|
43
|
+
if (x == null)
|
|
44
|
+
x = 0;
|
|
45
|
+
if (y == null)
|
|
46
|
+
y = 0;
|
|
47
|
+
function force() {
|
|
48
|
+
var i, n = nodes.length, node, sx = 0, sy = 0;
|
|
49
|
+
for (i = 0;i < n; ++i) {
|
|
50
|
+
node = nodes[i], sx += node.x, sy += node.y;
|
|
51
|
+
}
|
|
52
|
+
for (sx = (sx / n - x) * strength, sy = (sy / n - y) * strength, i = 0;i < n; ++i) {
|
|
53
|
+
node = nodes[i], node.x -= sx, node.y -= sy;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
force.initialize = function(_) {
|
|
57
|
+
nodes = _;
|
|
58
|
+
};
|
|
59
|
+
force.x = function(_) {
|
|
60
|
+
return arguments.length ? (x = +_, force) : x;
|
|
61
|
+
};
|
|
62
|
+
force.y = function(_) {
|
|
63
|
+
return arguments.length ? (y = +_, force) : y;
|
|
64
|
+
};
|
|
65
|
+
force.strength = function(_) {
|
|
66
|
+
return arguments.length ? (strength = +_, force) : strength;
|
|
67
|
+
};
|
|
68
|
+
return force;
|
|
69
|
+
}
|
|
70
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/add.js
|
|
71
|
+
function add_default(d) {
|
|
72
|
+
const x = +this._x.call(null, d), y = +this._y.call(null, d);
|
|
73
|
+
return add(this.cover(x, y), x, y, d);
|
|
74
|
+
}
|
|
75
|
+
function add(tree, x, y, d) {
|
|
76
|
+
if (isNaN(x) || isNaN(y))
|
|
77
|
+
return tree;
|
|
78
|
+
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;
|
|
79
|
+
if (!node)
|
|
80
|
+
return tree._root = leaf, tree;
|
|
81
|
+
while (node.length) {
|
|
82
|
+
if (right = x >= (xm = (x0 + x1) / 2))
|
|
83
|
+
x0 = xm;
|
|
84
|
+
else
|
|
85
|
+
x1 = xm;
|
|
86
|
+
if (bottom = y >= (ym = (y0 + y1) / 2))
|
|
87
|
+
y0 = ym;
|
|
88
|
+
else
|
|
89
|
+
y1 = ym;
|
|
90
|
+
if (parent = node, !(node = node[i = bottom << 1 | right]))
|
|
91
|
+
return parent[i] = leaf, tree;
|
|
92
|
+
}
|
|
93
|
+
xp = +tree._x.call(null, node.data);
|
|
94
|
+
yp = +tree._y.call(null, node.data);
|
|
95
|
+
if (x === xp && y === yp)
|
|
96
|
+
return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree;
|
|
97
|
+
do {
|
|
98
|
+
parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4);
|
|
99
|
+
if (right = x >= (xm = (x0 + x1) / 2))
|
|
100
|
+
x0 = xm;
|
|
101
|
+
else
|
|
102
|
+
x1 = xm;
|
|
103
|
+
if (bottom = y >= (ym = (y0 + y1) / 2))
|
|
104
|
+
y0 = ym;
|
|
105
|
+
else
|
|
106
|
+
y1 = ym;
|
|
107
|
+
} while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | xp >= xm));
|
|
108
|
+
return parent[j] = node, parent[i] = leaf, tree;
|
|
109
|
+
}
|
|
110
|
+
function addAll(data) {
|
|
111
|
+
var d, i, n = data.length, x, y, xz = new Array(n), yz = new Array(n), x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
112
|
+
for (i = 0;i < n; ++i) {
|
|
113
|
+
if (isNaN(x = +this._x.call(null, d = data[i])) || isNaN(y = +this._y.call(null, d)))
|
|
114
|
+
continue;
|
|
115
|
+
xz[i] = x;
|
|
116
|
+
yz[i] = y;
|
|
117
|
+
if (x < x0)
|
|
118
|
+
x0 = x;
|
|
119
|
+
if (x > x1)
|
|
120
|
+
x1 = x;
|
|
121
|
+
if (y < y0)
|
|
122
|
+
y0 = y;
|
|
123
|
+
if (y > y1)
|
|
124
|
+
y1 = y;
|
|
125
|
+
}
|
|
126
|
+
if (x0 > x1 || y0 > y1)
|
|
127
|
+
return this;
|
|
128
|
+
this.cover(x0, y0).cover(x1, y1);
|
|
129
|
+
for (i = 0;i < n; ++i) {
|
|
130
|
+
add(this, xz[i], yz[i], data[i]);
|
|
131
|
+
}
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/cover.js
|
|
136
|
+
function cover_default(x, y) {
|
|
137
|
+
if (isNaN(x = +x) || isNaN(y = +y))
|
|
138
|
+
return this;
|
|
139
|
+
var x0 = this._x0, y0 = this._y0, x1 = this._x1, y1 = this._y1;
|
|
140
|
+
if (isNaN(x0)) {
|
|
141
|
+
x1 = (x0 = Math.floor(x)) + 1;
|
|
142
|
+
y1 = (y0 = Math.floor(y)) + 1;
|
|
143
|
+
} else {
|
|
144
|
+
var z = x1 - x0 || 1, node = this._root, parent, i;
|
|
145
|
+
while (x0 > x || x >= x1 || y0 > y || y >= y1) {
|
|
146
|
+
i = (y < y0) << 1 | x < x0;
|
|
147
|
+
parent = new Array(4), parent[i] = node, node = parent, z *= 2;
|
|
148
|
+
switch (i) {
|
|
149
|
+
case 0:
|
|
150
|
+
x1 = x0 + z, y1 = y0 + z;
|
|
151
|
+
break;
|
|
152
|
+
case 1:
|
|
153
|
+
x0 = x1 - z, y1 = y0 + z;
|
|
154
|
+
break;
|
|
155
|
+
case 2:
|
|
156
|
+
x1 = x0 + z, y0 = y1 - z;
|
|
157
|
+
break;
|
|
158
|
+
case 3:
|
|
159
|
+
x0 = x1 - z, y0 = y1 - z;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (this._root && this._root.length)
|
|
164
|
+
this._root = node;
|
|
165
|
+
}
|
|
166
|
+
this._x0 = x0;
|
|
167
|
+
this._y0 = y0;
|
|
168
|
+
this._x1 = x1;
|
|
169
|
+
this._y1 = y1;
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/data.js
|
|
174
|
+
function data_default() {
|
|
175
|
+
var data = [];
|
|
176
|
+
this.visit(function(node) {
|
|
177
|
+
if (!node.length)
|
|
178
|
+
do
|
|
179
|
+
data.push(node.data);
|
|
180
|
+
while (node = node.next);
|
|
181
|
+
});
|
|
182
|
+
return data;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/extent.js
|
|
186
|
+
function extent_default(_) {
|
|
187
|
+
return arguments.length ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1]) : isNaN(this._x0) ? undefined : [[this._x0, this._y0], [this._x1, this._y1]];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/quad.js
|
|
191
|
+
function quad_default(node, x0, y0, x1, y1) {
|
|
192
|
+
this.node = node;
|
|
193
|
+
this.x0 = x0;
|
|
194
|
+
this.y0 = y0;
|
|
195
|
+
this.x1 = x1;
|
|
196
|
+
this.y1 = y1;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/find.js
|
|
200
|
+
function find_default(x, y, radius) {
|
|
201
|
+
var data, x0 = this._x0, y0 = this._y0, x1, y1, x2, y2, x3 = this._x1, y3 = this._y1, quads = [], node = this._root, q, i;
|
|
202
|
+
if (node)
|
|
203
|
+
quads.push(new quad_default(node, x0, y0, x3, y3));
|
|
204
|
+
if (radius == null)
|
|
205
|
+
radius = Infinity;
|
|
206
|
+
else {
|
|
207
|
+
x0 = x - radius, y0 = y - radius;
|
|
208
|
+
x3 = x + radius, y3 = y + radius;
|
|
209
|
+
radius *= radius;
|
|
210
|
+
}
|
|
211
|
+
while (q = quads.pop()) {
|
|
212
|
+
if (!(node = q.node) || (x1 = q.x0) > x3 || (y1 = q.y0) > y3 || (x2 = q.x1) < x0 || (y2 = q.y1) < y0)
|
|
213
|
+
continue;
|
|
214
|
+
if (node.length) {
|
|
215
|
+
var xm = (x1 + x2) / 2, ym = (y1 + y2) / 2;
|
|
216
|
+
quads.push(new quad_default(node[3], xm, ym, x2, y2), new quad_default(node[2], x1, ym, xm, y2), new quad_default(node[1], xm, y1, x2, ym), new quad_default(node[0], x1, y1, xm, ym));
|
|
217
|
+
if (i = (y >= ym) << 1 | x >= xm) {
|
|
218
|
+
q = quads[quads.length - 1];
|
|
219
|
+
quads[quads.length - 1] = quads[quads.length - 1 - i];
|
|
220
|
+
quads[quads.length - 1 - i] = q;
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
var dx = x - +this._x.call(null, node.data), dy = y - +this._y.call(null, node.data), d2 = dx * dx + dy * dy;
|
|
224
|
+
if (d2 < radius) {
|
|
225
|
+
var d = Math.sqrt(radius = d2);
|
|
226
|
+
x0 = x - d, y0 = y - d;
|
|
227
|
+
x3 = x + d, y3 = y + d;
|
|
228
|
+
data = node.data;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return data;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/remove.js
|
|
236
|
+
function remove_default(d) {
|
|
237
|
+
if (isNaN(x = +this._x.call(null, d)) || isNaN(y = +this._y.call(null, d)))
|
|
238
|
+
return this;
|
|
239
|
+
var parent, node = this._root, retainer, previous, next, x0 = this._x0, y0 = this._y0, x1 = this._x1, y1 = this._y1, x, y, xm, ym, right, bottom, i, j;
|
|
240
|
+
if (!node)
|
|
241
|
+
return this;
|
|
242
|
+
if (node.length)
|
|
243
|
+
while (true) {
|
|
244
|
+
if (right = x >= (xm = (x0 + x1) / 2))
|
|
245
|
+
x0 = xm;
|
|
246
|
+
else
|
|
247
|
+
x1 = xm;
|
|
248
|
+
if (bottom = y >= (ym = (y0 + y1) / 2))
|
|
249
|
+
y0 = ym;
|
|
250
|
+
else
|
|
251
|
+
y1 = ym;
|
|
252
|
+
if (!(parent = node, node = node[i = bottom << 1 | right]))
|
|
253
|
+
return this;
|
|
254
|
+
if (!node.length)
|
|
255
|
+
break;
|
|
256
|
+
if (parent[i + 1 & 3] || parent[i + 2 & 3] || parent[i + 3 & 3])
|
|
257
|
+
retainer = parent, j = i;
|
|
258
|
+
}
|
|
259
|
+
while (node.data !== d)
|
|
260
|
+
if (!(previous = node, node = node.next))
|
|
261
|
+
return this;
|
|
262
|
+
if (next = node.next)
|
|
263
|
+
delete node.next;
|
|
264
|
+
if (previous)
|
|
265
|
+
return next ? previous.next = next : delete previous.next, this;
|
|
266
|
+
if (!parent)
|
|
267
|
+
return this._root = next, this;
|
|
268
|
+
next ? parent[i] = next : delete parent[i];
|
|
269
|
+
if ((node = parent[0] || parent[1] || parent[2] || parent[3]) && node === (parent[3] || parent[2] || parent[1] || parent[0]) && !node.length) {
|
|
270
|
+
if (retainer)
|
|
271
|
+
retainer[j] = node;
|
|
272
|
+
else
|
|
273
|
+
this._root = node;
|
|
274
|
+
}
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
function removeAll(data) {
|
|
278
|
+
for (var i = 0, n = data.length;i < n; ++i)
|
|
279
|
+
this.remove(data[i]);
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/root.js
|
|
284
|
+
function root_default() {
|
|
285
|
+
return this._root;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/size.js
|
|
289
|
+
function size_default() {
|
|
290
|
+
var size = 0;
|
|
291
|
+
this.visit(function(node) {
|
|
292
|
+
if (!node.length)
|
|
293
|
+
do
|
|
294
|
+
++size;
|
|
295
|
+
while (node = node.next);
|
|
296
|
+
});
|
|
297
|
+
return size;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/visit.js
|
|
301
|
+
function visit_default(callback) {
|
|
302
|
+
var quads = [], q, node = this._root, child, x0, y0, x1, y1;
|
|
303
|
+
if (node)
|
|
304
|
+
quads.push(new quad_default(node, this._x0, this._y0, this._x1, this._y1));
|
|
305
|
+
while (q = quads.pop()) {
|
|
306
|
+
if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) {
|
|
307
|
+
var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
|
308
|
+
if (child = node[3])
|
|
309
|
+
quads.push(new quad_default(child, xm, ym, x1, y1));
|
|
310
|
+
if (child = node[2])
|
|
311
|
+
quads.push(new quad_default(child, x0, ym, xm, y1));
|
|
312
|
+
if (child = node[1])
|
|
313
|
+
quads.push(new quad_default(child, xm, y0, x1, ym));
|
|
314
|
+
if (child = node[0])
|
|
315
|
+
quads.push(new quad_default(child, x0, y0, xm, ym));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/visitAfter.js
|
|
322
|
+
function visitAfter_default(callback) {
|
|
323
|
+
var quads = [], next = [], q;
|
|
324
|
+
if (this._root)
|
|
325
|
+
quads.push(new quad_default(this._root, this._x0, this._y0, this._x1, this._y1));
|
|
326
|
+
while (q = quads.pop()) {
|
|
327
|
+
var node = q.node;
|
|
328
|
+
if (node.length) {
|
|
329
|
+
var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2;
|
|
330
|
+
if (child = node[0])
|
|
331
|
+
quads.push(new quad_default(child, x0, y0, xm, ym));
|
|
332
|
+
if (child = node[1])
|
|
333
|
+
quads.push(new quad_default(child, xm, y0, x1, ym));
|
|
334
|
+
if (child = node[2])
|
|
335
|
+
quads.push(new quad_default(child, x0, ym, xm, y1));
|
|
336
|
+
if (child = node[3])
|
|
337
|
+
quads.push(new quad_default(child, xm, ym, x1, y1));
|
|
338
|
+
}
|
|
339
|
+
next.push(q);
|
|
340
|
+
}
|
|
341
|
+
while (q = next.pop()) {
|
|
342
|
+
callback(q.node, q.x0, q.y0, q.x1, q.y1);
|
|
343
|
+
}
|
|
344
|
+
return this;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/x.js
|
|
348
|
+
function defaultX(d) {
|
|
349
|
+
return d[0];
|
|
350
|
+
}
|
|
351
|
+
function x_default(_) {
|
|
352
|
+
return arguments.length ? (this._x = _, this) : this._x;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/y.js
|
|
356
|
+
function defaultY(d) {
|
|
357
|
+
return d[1];
|
|
358
|
+
}
|
|
359
|
+
function y_default(_) {
|
|
360
|
+
return arguments.length ? (this._y = _, this) : this._y;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ../../node_modules/.bun/d3-quadtree@3.0.1/node_modules/d3-quadtree/src/quadtree.js
|
|
364
|
+
function quadtree(nodes, x, y) {
|
|
365
|
+
var tree = new Quadtree(x == null ? defaultX : x, y == null ? defaultY : y, NaN, NaN, NaN, NaN);
|
|
366
|
+
return nodes == null ? tree : tree.addAll(nodes);
|
|
367
|
+
}
|
|
368
|
+
function Quadtree(x, y, x0, y0, x1, y1) {
|
|
369
|
+
this._x = x;
|
|
370
|
+
this._y = y;
|
|
371
|
+
this._x0 = x0;
|
|
372
|
+
this._y0 = y0;
|
|
373
|
+
this._x1 = x1;
|
|
374
|
+
this._y1 = y1;
|
|
375
|
+
this._root = undefined;
|
|
376
|
+
}
|
|
377
|
+
function leaf_copy(leaf) {
|
|
378
|
+
var copy = { data: leaf.data }, next = copy;
|
|
379
|
+
while (leaf = leaf.next)
|
|
380
|
+
next = next.next = { data: leaf.data };
|
|
381
|
+
return copy;
|
|
382
|
+
}
|
|
383
|
+
var treeProto = quadtree.prototype = Quadtree.prototype;
|
|
384
|
+
treeProto.copy = function() {
|
|
385
|
+
var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1), node = this._root, nodes, child;
|
|
386
|
+
if (!node)
|
|
387
|
+
return copy;
|
|
388
|
+
if (!node.length)
|
|
389
|
+
return copy._root = leaf_copy(node), copy;
|
|
390
|
+
nodes = [{ source: node, target: copy._root = new Array(4) }];
|
|
391
|
+
while (node = nodes.pop()) {
|
|
392
|
+
for (var i = 0;i < 4; ++i) {
|
|
393
|
+
if (child = node.source[i]) {
|
|
394
|
+
if (child.length)
|
|
395
|
+
nodes.push({ source: child, target: node.target[i] = new Array(4) });
|
|
396
|
+
else
|
|
397
|
+
node.target[i] = leaf_copy(child);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return copy;
|
|
402
|
+
};
|
|
403
|
+
treeProto.add = add_default;
|
|
404
|
+
treeProto.addAll = addAll;
|
|
405
|
+
treeProto.cover = cover_default;
|
|
406
|
+
treeProto.data = data_default;
|
|
407
|
+
treeProto.extent = extent_default;
|
|
408
|
+
treeProto.find = find_default;
|
|
409
|
+
treeProto.remove = remove_default;
|
|
410
|
+
treeProto.removeAll = removeAll;
|
|
411
|
+
treeProto.root = root_default;
|
|
412
|
+
treeProto.size = size_default;
|
|
413
|
+
treeProto.visit = visit_default;
|
|
414
|
+
treeProto.visitAfter = visitAfter_default;
|
|
415
|
+
treeProto.x = x_default;
|
|
416
|
+
treeProto.y = y_default;
|
|
417
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/constant.js
|
|
418
|
+
function constant_default(x) {
|
|
419
|
+
return function() {
|
|
420
|
+
return x;
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/jiggle.js
|
|
425
|
+
function jiggle_default(random) {
|
|
426
|
+
return (random() - 0.5) * 0.000001;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/collide.js
|
|
430
|
+
function x(d) {
|
|
431
|
+
return d.x + d.vx;
|
|
432
|
+
}
|
|
433
|
+
function y(d) {
|
|
434
|
+
return d.y + d.vy;
|
|
435
|
+
}
|
|
436
|
+
function collide_default(radius) {
|
|
437
|
+
var nodes, radii, random, strength = 1, iterations = 1;
|
|
438
|
+
if (typeof radius !== "function")
|
|
439
|
+
radius = constant_default(radius == null ? 1 : +radius);
|
|
440
|
+
function force() {
|
|
441
|
+
var i, n = nodes.length, tree, node, xi, yi, ri, ri2;
|
|
442
|
+
for (var k = 0;k < iterations; ++k) {
|
|
443
|
+
tree = quadtree(nodes, x, y).visitAfter(prepare);
|
|
444
|
+
for (i = 0;i < n; ++i) {
|
|
445
|
+
node = nodes[i];
|
|
446
|
+
ri = radii[node.index], ri2 = ri * ri;
|
|
447
|
+
xi = node.x + node.vx;
|
|
448
|
+
yi = node.y + node.vy;
|
|
449
|
+
tree.visit(apply);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function apply(quad, x0, y0, x1, y1) {
|
|
453
|
+
var { data, r: rj } = quad, r = ri + rj;
|
|
454
|
+
if (data) {
|
|
455
|
+
if (data.index > node.index) {
|
|
456
|
+
var x2 = xi - data.x - data.vx, y2 = yi - data.y - data.vy, l = x2 * x2 + y2 * y2;
|
|
457
|
+
if (l < r * r) {
|
|
458
|
+
if (x2 === 0)
|
|
459
|
+
x2 = jiggle_default(random), l += x2 * x2;
|
|
460
|
+
if (y2 === 0)
|
|
461
|
+
y2 = jiggle_default(random), l += y2 * y2;
|
|
462
|
+
l = (r - (l = Math.sqrt(l))) / l * strength;
|
|
463
|
+
node.vx += (x2 *= l) * (r = (rj *= rj) / (ri2 + rj));
|
|
464
|
+
node.vy += (y2 *= l) * r;
|
|
465
|
+
data.vx -= x2 * (r = 1 - r);
|
|
466
|
+
data.vy -= y2 * r;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
return x0 > xi + r || x1 < xi - r || y0 > yi + r || y1 < yi - r;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function prepare(quad) {
|
|
475
|
+
if (quad.data)
|
|
476
|
+
return quad.r = radii[quad.data.index];
|
|
477
|
+
for (var i = quad.r = 0;i < 4; ++i) {
|
|
478
|
+
if (quad[i] && quad[i].r > quad.r) {
|
|
479
|
+
quad.r = quad[i].r;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function initialize() {
|
|
484
|
+
if (!nodes)
|
|
485
|
+
return;
|
|
486
|
+
var i, n = nodes.length, node;
|
|
487
|
+
radii = new Array(n);
|
|
488
|
+
for (i = 0;i < n; ++i)
|
|
489
|
+
node = nodes[i], radii[node.index] = +radius(node, i, nodes);
|
|
490
|
+
}
|
|
491
|
+
force.initialize = function(_nodes, _random) {
|
|
492
|
+
nodes = _nodes;
|
|
493
|
+
random = _random;
|
|
494
|
+
initialize();
|
|
495
|
+
};
|
|
496
|
+
force.iterations = function(_) {
|
|
497
|
+
return arguments.length ? (iterations = +_, force) : iterations;
|
|
498
|
+
};
|
|
499
|
+
force.strength = function(_) {
|
|
500
|
+
return arguments.length ? (strength = +_, force) : strength;
|
|
501
|
+
};
|
|
502
|
+
force.radius = function(_) {
|
|
503
|
+
return arguments.length ? (radius = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : radius;
|
|
504
|
+
};
|
|
505
|
+
return force;
|
|
506
|
+
}
|
|
507
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/link.js
|
|
508
|
+
function index(d) {
|
|
509
|
+
return d.index;
|
|
510
|
+
}
|
|
511
|
+
function find(nodeById, nodeId) {
|
|
512
|
+
var node = nodeById.get(nodeId);
|
|
513
|
+
if (!node)
|
|
514
|
+
throw new Error("node not found: " + nodeId);
|
|
515
|
+
return node;
|
|
516
|
+
}
|
|
517
|
+
function link_default(links) {
|
|
518
|
+
var id = index, strength = defaultStrength, strengths, distance = constant_default(30), distances, nodes, count, bias, random, iterations = 1;
|
|
519
|
+
if (links == null)
|
|
520
|
+
links = [];
|
|
521
|
+
function defaultStrength(link) {
|
|
522
|
+
return 1 / Math.min(count[link.source.index], count[link.target.index]);
|
|
523
|
+
}
|
|
524
|
+
function force(alpha) {
|
|
525
|
+
for (var k = 0, n = links.length;k < iterations; ++k) {
|
|
526
|
+
for (var i = 0, link, source, target, x2, y2, l, b;i < n; ++i) {
|
|
527
|
+
link = links[i], source = link.source, target = link.target;
|
|
528
|
+
x2 = target.x + target.vx - source.x - source.vx || jiggle_default(random);
|
|
529
|
+
y2 = target.y + target.vy - source.y - source.vy || jiggle_default(random);
|
|
530
|
+
l = Math.sqrt(x2 * x2 + y2 * y2);
|
|
531
|
+
l = (l - distances[i]) / l * alpha * strengths[i];
|
|
532
|
+
x2 *= l, y2 *= l;
|
|
533
|
+
target.vx -= x2 * (b = bias[i]);
|
|
534
|
+
target.vy -= y2 * b;
|
|
535
|
+
source.vx += x2 * (b = 1 - b);
|
|
536
|
+
source.vy += y2 * b;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
function initialize() {
|
|
541
|
+
if (!nodes)
|
|
542
|
+
return;
|
|
543
|
+
var i, n = nodes.length, m = links.length, nodeById = new Map(nodes.map((d, i2) => [id(d, i2, nodes), d])), link;
|
|
544
|
+
for (i = 0, count = new Array(n);i < m; ++i) {
|
|
545
|
+
link = links[i], link.index = i;
|
|
546
|
+
if (typeof link.source !== "object")
|
|
547
|
+
link.source = find(nodeById, link.source);
|
|
548
|
+
if (typeof link.target !== "object")
|
|
549
|
+
link.target = find(nodeById, link.target);
|
|
550
|
+
count[link.source.index] = (count[link.source.index] || 0) + 1;
|
|
551
|
+
count[link.target.index] = (count[link.target.index] || 0) + 1;
|
|
552
|
+
}
|
|
553
|
+
for (i = 0, bias = new Array(m);i < m; ++i) {
|
|
554
|
+
link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]);
|
|
555
|
+
}
|
|
556
|
+
strengths = new Array(m), initializeStrength();
|
|
557
|
+
distances = new Array(m), initializeDistance();
|
|
558
|
+
}
|
|
559
|
+
function initializeStrength() {
|
|
560
|
+
if (!nodes)
|
|
561
|
+
return;
|
|
562
|
+
for (var i = 0, n = links.length;i < n; ++i) {
|
|
563
|
+
strengths[i] = +strength(links[i], i, links);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
function initializeDistance() {
|
|
567
|
+
if (!nodes)
|
|
568
|
+
return;
|
|
569
|
+
for (var i = 0, n = links.length;i < n; ++i) {
|
|
570
|
+
distances[i] = +distance(links[i], i, links);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
force.initialize = function(_nodes, _random) {
|
|
574
|
+
nodes = _nodes;
|
|
575
|
+
random = _random;
|
|
576
|
+
initialize();
|
|
577
|
+
};
|
|
578
|
+
force.links = function(_) {
|
|
579
|
+
return arguments.length ? (links = _, initialize(), force) : links;
|
|
580
|
+
};
|
|
581
|
+
force.id = function(_) {
|
|
582
|
+
return arguments.length ? (id = _, force) : id;
|
|
583
|
+
};
|
|
584
|
+
force.iterations = function(_) {
|
|
585
|
+
return arguments.length ? (iterations = +_, force) : iterations;
|
|
586
|
+
};
|
|
587
|
+
force.strength = function(_) {
|
|
588
|
+
return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initializeStrength(), force) : strength;
|
|
589
|
+
};
|
|
590
|
+
force.distance = function(_) {
|
|
591
|
+
return arguments.length ? (distance = typeof _ === "function" ? _ : constant_default(+_), initializeDistance(), force) : distance;
|
|
592
|
+
};
|
|
593
|
+
return force;
|
|
594
|
+
}
|
|
595
|
+
// ../../node_modules/.bun/d3-dispatch@3.0.1/node_modules/d3-dispatch/src/dispatch.js
|
|
596
|
+
var noop = { value: () => {} };
|
|
597
|
+
function dispatch() {
|
|
598
|
+
for (var i = 0, n = arguments.length, _ = {}, t;i < n; ++i) {
|
|
599
|
+
if (!(t = arguments[i] + "") || t in _ || /[\s.]/.test(t))
|
|
600
|
+
throw new Error("illegal type: " + t);
|
|
601
|
+
_[t] = [];
|
|
602
|
+
}
|
|
603
|
+
return new Dispatch(_);
|
|
604
|
+
}
|
|
605
|
+
function Dispatch(_) {
|
|
606
|
+
this._ = _;
|
|
607
|
+
}
|
|
608
|
+
function parseTypenames(typenames, types) {
|
|
609
|
+
return typenames.trim().split(/^|\s+/).map(function(t) {
|
|
610
|
+
var name = "", i = t.indexOf(".");
|
|
611
|
+
if (i >= 0)
|
|
612
|
+
name = t.slice(i + 1), t = t.slice(0, i);
|
|
613
|
+
if (t && !types.hasOwnProperty(t))
|
|
614
|
+
throw new Error("unknown type: " + t);
|
|
615
|
+
return { type: t, name };
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
Dispatch.prototype = dispatch.prototype = {
|
|
619
|
+
constructor: Dispatch,
|
|
620
|
+
on: function(typename, callback) {
|
|
621
|
+
var _ = this._, T = parseTypenames(typename + "", _), t, i = -1, n = T.length;
|
|
622
|
+
if (arguments.length < 2) {
|
|
623
|
+
while (++i < n)
|
|
624
|
+
if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name)))
|
|
625
|
+
return t;
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
if (callback != null && typeof callback !== "function")
|
|
629
|
+
throw new Error("invalid callback: " + callback);
|
|
630
|
+
while (++i < n) {
|
|
631
|
+
if (t = (typename = T[i]).type)
|
|
632
|
+
_[t] = set(_[t], typename.name, callback);
|
|
633
|
+
else if (callback == null)
|
|
634
|
+
for (t in _)
|
|
635
|
+
_[t] = set(_[t], typename.name, null);
|
|
636
|
+
}
|
|
637
|
+
return this;
|
|
638
|
+
},
|
|
639
|
+
copy: function() {
|
|
640
|
+
var copy = {}, _ = this._;
|
|
641
|
+
for (var t in _)
|
|
642
|
+
copy[t] = _[t].slice();
|
|
643
|
+
return new Dispatch(copy);
|
|
644
|
+
},
|
|
645
|
+
call: function(type, that) {
|
|
646
|
+
if ((n = arguments.length - 2) > 0)
|
|
647
|
+
for (var args = new Array(n), i = 0, n, t;i < n; ++i)
|
|
648
|
+
args[i] = arguments[i + 2];
|
|
649
|
+
if (!this._.hasOwnProperty(type))
|
|
650
|
+
throw new Error("unknown type: " + type);
|
|
651
|
+
for (t = this._[type], i = 0, n = t.length;i < n; ++i)
|
|
652
|
+
t[i].value.apply(that, args);
|
|
653
|
+
},
|
|
654
|
+
apply: function(type, that, args) {
|
|
655
|
+
if (!this._.hasOwnProperty(type))
|
|
656
|
+
throw new Error("unknown type: " + type);
|
|
657
|
+
for (var t = this._[type], i = 0, n = t.length;i < n; ++i)
|
|
658
|
+
t[i].value.apply(that, args);
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
function get(type, name) {
|
|
662
|
+
for (var i = 0, n = type.length, c;i < n; ++i) {
|
|
663
|
+
if ((c = type[i]).name === name) {
|
|
664
|
+
return c.value;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
function set(type, name, callback) {
|
|
669
|
+
for (var i = 0, n = type.length;i < n; ++i) {
|
|
670
|
+
if (type[i].name === name) {
|
|
671
|
+
type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1));
|
|
672
|
+
break;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
if (callback != null)
|
|
676
|
+
type.push({ name, value: callback });
|
|
677
|
+
return type;
|
|
678
|
+
}
|
|
679
|
+
var dispatch_default = dispatch;
|
|
680
|
+
// ../../node_modules/.bun/d3-timer@3.0.1/node_modules/d3-timer/src/timer.js
|
|
681
|
+
var frame = 0;
|
|
682
|
+
var timeout = 0;
|
|
683
|
+
var interval = 0;
|
|
684
|
+
var pokeDelay = 1000;
|
|
685
|
+
var taskHead;
|
|
686
|
+
var taskTail;
|
|
687
|
+
var clockLast = 0;
|
|
688
|
+
var clockNow = 0;
|
|
689
|
+
var clockSkew = 0;
|
|
690
|
+
var clock = typeof performance === "object" && performance.now ? performance : Date;
|
|
691
|
+
var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) {
|
|
692
|
+
setTimeout(f, 17);
|
|
693
|
+
};
|
|
694
|
+
function now() {
|
|
695
|
+
return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew);
|
|
696
|
+
}
|
|
697
|
+
function clearNow() {
|
|
698
|
+
clockNow = 0;
|
|
699
|
+
}
|
|
700
|
+
function Timer() {
|
|
701
|
+
this._call = this._time = this._next = null;
|
|
702
|
+
}
|
|
703
|
+
Timer.prototype = timer.prototype = {
|
|
704
|
+
constructor: Timer,
|
|
705
|
+
restart: function(callback, delay, time) {
|
|
706
|
+
if (typeof callback !== "function")
|
|
707
|
+
throw new TypeError("callback is not a function");
|
|
708
|
+
time = (time == null ? now() : +time) + (delay == null ? 0 : +delay);
|
|
709
|
+
if (!this._next && taskTail !== this) {
|
|
710
|
+
if (taskTail)
|
|
711
|
+
taskTail._next = this;
|
|
712
|
+
else
|
|
713
|
+
taskHead = this;
|
|
714
|
+
taskTail = this;
|
|
715
|
+
}
|
|
716
|
+
this._call = callback;
|
|
717
|
+
this._time = time;
|
|
718
|
+
sleep();
|
|
719
|
+
},
|
|
720
|
+
stop: function() {
|
|
721
|
+
if (this._call) {
|
|
722
|
+
this._call = null;
|
|
723
|
+
this._time = Infinity;
|
|
724
|
+
sleep();
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
function timer(callback, delay, time) {
|
|
729
|
+
var t = new Timer;
|
|
730
|
+
t.restart(callback, delay, time);
|
|
731
|
+
return t;
|
|
732
|
+
}
|
|
733
|
+
function timerFlush() {
|
|
734
|
+
now();
|
|
735
|
+
++frame;
|
|
736
|
+
var t = taskHead, e;
|
|
737
|
+
while (t) {
|
|
738
|
+
if ((e = clockNow - t._time) >= 0)
|
|
739
|
+
t._call.call(undefined, e);
|
|
740
|
+
t = t._next;
|
|
741
|
+
}
|
|
742
|
+
--frame;
|
|
743
|
+
}
|
|
744
|
+
function wake() {
|
|
745
|
+
clockNow = (clockLast = clock.now()) + clockSkew;
|
|
746
|
+
frame = timeout = 0;
|
|
747
|
+
try {
|
|
748
|
+
timerFlush();
|
|
749
|
+
} finally {
|
|
750
|
+
frame = 0;
|
|
751
|
+
nap();
|
|
752
|
+
clockNow = 0;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function poke() {
|
|
756
|
+
var now2 = clock.now(), delay = now2 - clockLast;
|
|
757
|
+
if (delay > pokeDelay)
|
|
758
|
+
clockSkew -= delay, clockLast = now2;
|
|
759
|
+
}
|
|
760
|
+
function nap() {
|
|
761
|
+
var t0, t1 = taskHead, t2, time = Infinity;
|
|
762
|
+
while (t1) {
|
|
763
|
+
if (t1._call) {
|
|
764
|
+
if (time > t1._time)
|
|
765
|
+
time = t1._time;
|
|
766
|
+
t0 = t1, t1 = t1._next;
|
|
767
|
+
} else {
|
|
768
|
+
t2 = t1._next, t1._next = null;
|
|
769
|
+
t1 = t0 ? t0._next = t2 : taskHead = t2;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
taskTail = t0;
|
|
773
|
+
sleep(time);
|
|
774
|
+
}
|
|
775
|
+
function sleep(time) {
|
|
776
|
+
if (frame)
|
|
777
|
+
return;
|
|
778
|
+
if (timeout)
|
|
779
|
+
timeout = clearTimeout(timeout);
|
|
780
|
+
var delay = time - clockNow;
|
|
781
|
+
if (delay > 24) {
|
|
782
|
+
if (time < Infinity)
|
|
783
|
+
timeout = setTimeout(wake, time - clock.now() - clockSkew);
|
|
784
|
+
if (interval)
|
|
785
|
+
interval = clearInterval(interval);
|
|
786
|
+
} else {
|
|
787
|
+
if (!interval)
|
|
788
|
+
clockLast = clock.now(), interval = setInterval(poke, pokeDelay);
|
|
789
|
+
frame = 1, setFrame(wake);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/lcg.js
|
|
793
|
+
var a = 1664525;
|
|
794
|
+
var c = 1013904223;
|
|
795
|
+
var m = 4294967296;
|
|
796
|
+
function lcg_default() {
|
|
797
|
+
let s = 1;
|
|
798
|
+
return () => (s = (a * s + c) % m) / m;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/simulation.js
|
|
802
|
+
function x2(d) {
|
|
803
|
+
return d.x;
|
|
804
|
+
}
|
|
805
|
+
function y2(d) {
|
|
806
|
+
return d.y;
|
|
807
|
+
}
|
|
808
|
+
var initialRadius = 10;
|
|
809
|
+
var initialAngle = Math.PI * (3 - Math.sqrt(5));
|
|
810
|
+
function simulation_default(nodes) {
|
|
811
|
+
var simulation, alpha = 1, alphaMin = 0.001, alphaDecay = 1 - Math.pow(alphaMin, 1 / 300), alphaTarget = 0, velocityDecay = 0.6, forces = new Map, stepper = timer(step), event = dispatch_default("tick", "end"), random = lcg_default();
|
|
812
|
+
if (nodes == null)
|
|
813
|
+
nodes = [];
|
|
814
|
+
function step() {
|
|
815
|
+
tick();
|
|
816
|
+
event.call("tick", simulation);
|
|
817
|
+
if (alpha < alphaMin) {
|
|
818
|
+
stepper.stop();
|
|
819
|
+
event.call("end", simulation);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
function tick(iterations) {
|
|
823
|
+
var i, n = nodes.length, node;
|
|
824
|
+
if (iterations === undefined)
|
|
825
|
+
iterations = 1;
|
|
826
|
+
for (var k = 0;k < iterations; ++k) {
|
|
827
|
+
alpha += (alphaTarget - alpha) * alphaDecay;
|
|
828
|
+
forces.forEach(function(force) {
|
|
829
|
+
force(alpha);
|
|
830
|
+
});
|
|
831
|
+
for (i = 0;i < n; ++i) {
|
|
832
|
+
node = nodes[i];
|
|
833
|
+
if (node.fx == null)
|
|
834
|
+
node.x += node.vx *= velocityDecay;
|
|
835
|
+
else
|
|
836
|
+
node.x = node.fx, node.vx = 0;
|
|
837
|
+
if (node.fy == null)
|
|
838
|
+
node.y += node.vy *= velocityDecay;
|
|
839
|
+
else
|
|
840
|
+
node.y = node.fy, node.vy = 0;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return simulation;
|
|
844
|
+
}
|
|
845
|
+
function initializeNodes() {
|
|
846
|
+
for (var i = 0, n = nodes.length, node;i < n; ++i) {
|
|
847
|
+
node = nodes[i], node.index = i;
|
|
848
|
+
if (node.fx != null)
|
|
849
|
+
node.x = node.fx;
|
|
850
|
+
if (node.fy != null)
|
|
851
|
+
node.y = node.fy;
|
|
852
|
+
if (isNaN(node.x) || isNaN(node.y)) {
|
|
853
|
+
var radius = initialRadius * Math.sqrt(0.5 + i), angle = i * initialAngle;
|
|
854
|
+
node.x = radius * Math.cos(angle);
|
|
855
|
+
node.y = radius * Math.sin(angle);
|
|
856
|
+
}
|
|
857
|
+
if (isNaN(node.vx) || isNaN(node.vy)) {
|
|
858
|
+
node.vx = node.vy = 0;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
function initializeForce(force) {
|
|
863
|
+
if (force.initialize)
|
|
864
|
+
force.initialize(nodes, random);
|
|
865
|
+
return force;
|
|
866
|
+
}
|
|
867
|
+
initializeNodes();
|
|
868
|
+
return simulation = {
|
|
869
|
+
tick,
|
|
870
|
+
restart: function() {
|
|
871
|
+
return stepper.restart(step), simulation;
|
|
872
|
+
},
|
|
873
|
+
stop: function() {
|
|
874
|
+
return stepper.stop(), simulation;
|
|
875
|
+
},
|
|
876
|
+
nodes: function(_) {
|
|
877
|
+
return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes;
|
|
878
|
+
},
|
|
879
|
+
alpha: function(_) {
|
|
880
|
+
return arguments.length ? (alpha = +_, simulation) : alpha;
|
|
881
|
+
},
|
|
882
|
+
alphaMin: function(_) {
|
|
883
|
+
return arguments.length ? (alphaMin = +_, simulation) : alphaMin;
|
|
884
|
+
},
|
|
885
|
+
alphaDecay: function(_) {
|
|
886
|
+
return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay;
|
|
887
|
+
},
|
|
888
|
+
alphaTarget: function(_) {
|
|
889
|
+
return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget;
|
|
890
|
+
},
|
|
891
|
+
velocityDecay: function(_) {
|
|
892
|
+
return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay;
|
|
893
|
+
},
|
|
894
|
+
randomSource: function(_) {
|
|
895
|
+
return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random;
|
|
896
|
+
},
|
|
897
|
+
force: function(name, _) {
|
|
898
|
+
return arguments.length > 1 ? (_ == null ? forces.delete(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name);
|
|
899
|
+
},
|
|
900
|
+
find: function(x3, y3, radius) {
|
|
901
|
+
var i = 0, n = nodes.length, dx, dy, d2, node, closest;
|
|
902
|
+
if (radius == null)
|
|
903
|
+
radius = Infinity;
|
|
904
|
+
else
|
|
905
|
+
radius *= radius;
|
|
906
|
+
for (i = 0;i < n; ++i) {
|
|
907
|
+
node = nodes[i];
|
|
908
|
+
dx = x3 - node.x;
|
|
909
|
+
dy = y3 - node.y;
|
|
910
|
+
d2 = dx * dx + dy * dy;
|
|
911
|
+
if (d2 < radius)
|
|
912
|
+
closest = node, radius = d2;
|
|
913
|
+
}
|
|
914
|
+
return closest;
|
|
915
|
+
},
|
|
916
|
+
on: function(name, _) {
|
|
917
|
+
return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name);
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/manyBody.js
|
|
923
|
+
function manyBody_default() {
|
|
924
|
+
var nodes, node, random, alpha, strength = constant_default(-30), strengths, distanceMin2 = 1, distanceMax2 = Infinity, theta2 = 0.81;
|
|
925
|
+
function force(_) {
|
|
926
|
+
var i, n = nodes.length, tree = quadtree(nodes, x2, y2).visitAfter(accumulate);
|
|
927
|
+
for (alpha = _, i = 0;i < n; ++i)
|
|
928
|
+
node = nodes[i], tree.visit(apply);
|
|
929
|
+
}
|
|
930
|
+
function initialize() {
|
|
931
|
+
if (!nodes)
|
|
932
|
+
return;
|
|
933
|
+
var i, n = nodes.length, node2;
|
|
934
|
+
strengths = new Array(n);
|
|
935
|
+
for (i = 0;i < n; ++i)
|
|
936
|
+
node2 = nodes[i], strengths[node2.index] = +strength(node2, i, nodes);
|
|
937
|
+
}
|
|
938
|
+
function accumulate(quad) {
|
|
939
|
+
var strength2 = 0, q, c2, weight = 0, x3, y3, i;
|
|
940
|
+
if (quad.length) {
|
|
941
|
+
for (x3 = y3 = i = 0;i < 4; ++i) {
|
|
942
|
+
if ((q = quad[i]) && (c2 = Math.abs(q.value))) {
|
|
943
|
+
strength2 += q.value, weight += c2, x3 += c2 * q.x, y3 += c2 * q.y;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
quad.x = x3 / weight;
|
|
947
|
+
quad.y = y3 / weight;
|
|
948
|
+
} else {
|
|
949
|
+
q = quad;
|
|
950
|
+
q.x = q.data.x;
|
|
951
|
+
q.y = q.data.y;
|
|
952
|
+
do
|
|
953
|
+
strength2 += strengths[q.data.index];
|
|
954
|
+
while (q = q.next);
|
|
955
|
+
}
|
|
956
|
+
quad.value = strength2;
|
|
957
|
+
}
|
|
958
|
+
function apply(quad, x1, _, x22) {
|
|
959
|
+
if (!quad.value)
|
|
960
|
+
return true;
|
|
961
|
+
var x3 = quad.x - node.x, y3 = quad.y - node.y, w = x22 - x1, l = x3 * x3 + y3 * y3;
|
|
962
|
+
if (w * w / theta2 < l) {
|
|
963
|
+
if (l < distanceMax2) {
|
|
964
|
+
if (x3 === 0)
|
|
965
|
+
x3 = jiggle_default(random), l += x3 * x3;
|
|
966
|
+
if (y3 === 0)
|
|
967
|
+
y3 = jiggle_default(random), l += y3 * y3;
|
|
968
|
+
if (l < distanceMin2)
|
|
969
|
+
l = Math.sqrt(distanceMin2 * l);
|
|
970
|
+
node.vx += x3 * quad.value * alpha / l;
|
|
971
|
+
node.vy += y3 * quad.value * alpha / l;
|
|
972
|
+
}
|
|
973
|
+
return true;
|
|
974
|
+
} else if (quad.length || l >= distanceMax2)
|
|
975
|
+
return;
|
|
976
|
+
if (quad.data !== node || quad.next) {
|
|
977
|
+
if (x3 === 0)
|
|
978
|
+
x3 = jiggle_default(random), l += x3 * x3;
|
|
979
|
+
if (y3 === 0)
|
|
980
|
+
y3 = jiggle_default(random), l += y3 * y3;
|
|
981
|
+
if (l < distanceMin2)
|
|
982
|
+
l = Math.sqrt(distanceMin2 * l);
|
|
983
|
+
}
|
|
984
|
+
do
|
|
985
|
+
if (quad.data !== node) {
|
|
986
|
+
w = strengths[quad.data.index] * alpha / l;
|
|
987
|
+
node.vx += x3 * w;
|
|
988
|
+
node.vy += y3 * w;
|
|
989
|
+
}
|
|
990
|
+
while (quad = quad.next);
|
|
991
|
+
}
|
|
992
|
+
force.initialize = function(_nodes, _random) {
|
|
993
|
+
nodes = _nodes;
|
|
994
|
+
random = _random;
|
|
995
|
+
initialize();
|
|
996
|
+
};
|
|
997
|
+
force.strength = function(_) {
|
|
998
|
+
return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : strength;
|
|
999
|
+
};
|
|
1000
|
+
force.distanceMin = function(_) {
|
|
1001
|
+
return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2);
|
|
1002
|
+
};
|
|
1003
|
+
force.distanceMax = function(_) {
|
|
1004
|
+
return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2);
|
|
1005
|
+
};
|
|
1006
|
+
force.theta = function(_) {
|
|
1007
|
+
return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2);
|
|
1008
|
+
};
|
|
1009
|
+
return force;
|
|
1010
|
+
}
|
|
1011
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/x.js
|
|
1012
|
+
function x_default2(x3) {
|
|
1013
|
+
var strength = constant_default(0.1), nodes, strengths, xz;
|
|
1014
|
+
if (typeof x3 !== "function")
|
|
1015
|
+
x3 = constant_default(x3 == null ? 0 : +x3);
|
|
1016
|
+
function force(alpha) {
|
|
1017
|
+
for (var i = 0, n = nodes.length, node;i < n; ++i) {
|
|
1018
|
+
node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
function initialize() {
|
|
1022
|
+
if (!nodes)
|
|
1023
|
+
return;
|
|
1024
|
+
var i, n = nodes.length;
|
|
1025
|
+
strengths = new Array(n);
|
|
1026
|
+
xz = new Array(n);
|
|
1027
|
+
for (i = 0;i < n; ++i) {
|
|
1028
|
+
strengths[i] = isNaN(xz[i] = +x3(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
force.initialize = function(_) {
|
|
1032
|
+
nodes = _;
|
|
1033
|
+
initialize();
|
|
1034
|
+
};
|
|
1035
|
+
force.strength = function(_) {
|
|
1036
|
+
return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : strength;
|
|
1037
|
+
};
|
|
1038
|
+
force.x = function(_) {
|
|
1039
|
+
return arguments.length ? (x3 = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : x3;
|
|
1040
|
+
};
|
|
1041
|
+
return force;
|
|
1042
|
+
}
|
|
1043
|
+
// ../../node_modules/.bun/d3-force@3.0.0/node_modules/d3-force/src/y.js
|
|
1044
|
+
function y_default2(y3) {
|
|
1045
|
+
var strength = constant_default(0.1), nodes, strengths, yz;
|
|
1046
|
+
if (typeof y3 !== "function")
|
|
1047
|
+
y3 = constant_default(y3 == null ? 0 : +y3);
|
|
1048
|
+
function force(alpha) {
|
|
1049
|
+
for (var i = 0, n = nodes.length, node;i < n; ++i) {
|
|
1050
|
+
node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
function initialize() {
|
|
1054
|
+
if (!nodes)
|
|
1055
|
+
return;
|
|
1056
|
+
var i, n = nodes.length;
|
|
1057
|
+
strengths = new Array(n);
|
|
1058
|
+
yz = new Array(n);
|
|
1059
|
+
for (i = 0;i < n; ++i) {
|
|
1060
|
+
strengths[i] = isNaN(yz[i] = +y3(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
force.initialize = function(_) {
|
|
1064
|
+
nodes = _;
|
|
1065
|
+
initialize();
|
|
1066
|
+
};
|
|
1067
|
+
force.strength = function(_) {
|
|
1068
|
+
return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : strength;
|
|
1069
|
+
};
|
|
1070
|
+
force.y = function(_) {
|
|
1071
|
+
return arguments.length ? (y3 = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : y3;
|
|
1072
|
+
};
|
|
1073
|
+
return force;
|
|
1074
|
+
}
|
|
1075
|
+
// src/graph/simulation-worker.ts
|
|
1076
|
+
function forceCluster(nodes, strength) {
|
|
1077
|
+
return (alpha) => {
|
|
1078
|
+
const cx = new Map;
|
|
1079
|
+
const cy = new Map;
|
|
1080
|
+
const count = new Map;
|
|
1081
|
+
for (const node of nodes) {
|
|
1082
|
+
if (!node.community)
|
|
1083
|
+
continue;
|
|
1084
|
+
const c2 = node.community;
|
|
1085
|
+
cx.set(c2, (cx.get(c2) ?? 0) + (node.x ?? 0));
|
|
1086
|
+
cy.set(c2, (cy.get(c2) ?? 0) + (node.y ?? 0));
|
|
1087
|
+
count.set(c2, (count.get(c2) ?? 0) + 1);
|
|
1088
|
+
}
|
|
1089
|
+
for (const [c2, n] of count) {
|
|
1090
|
+
cx.set(c2, cx.get(c2) / n);
|
|
1091
|
+
cy.set(c2, cy.get(c2) / n);
|
|
1092
|
+
}
|
|
1093
|
+
const k = strength * alpha;
|
|
1094
|
+
for (const node of nodes) {
|
|
1095
|
+
if (!node.community)
|
|
1096
|
+
continue;
|
|
1097
|
+
const targetX = cx.get(node.community);
|
|
1098
|
+
const targetY = cy.get(node.community);
|
|
1099
|
+
node.vx = (node.vx ?? 0) + (targetX - (node.x ?? 0)) * k;
|
|
1100
|
+
node.vy = (node.vy ?? 0) + (targetY - (node.y ?? 0)) * k;
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
var ctx = self;
|
|
1105
|
+
var simulation = null;
|
|
1106
|
+
var nodeMap = new Map;
|
|
1107
|
+
function post(msg) {
|
|
1108
|
+
ctx.postMessage(msg);
|
|
1109
|
+
}
|
|
1110
|
+
function packPositions(nodes) {
|
|
1111
|
+
return nodes.map((n) => ({
|
|
1112
|
+
id: n.id,
|
|
1113
|
+
x: n.x ?? 0,
|
|
1114
|
+
y: n.y ?? 0
|
|
1115
|
+
}));
|
|
1116
|
+
}
|
|
1117
|
+
ctx.addEventListener("message", (event) => {
|
|
1118
|
+
const msg = event.data;
|
|
1119
|
+
try {
|
|
1120
|
+
switch (msg.type) {
|
|
1121
|
+
case "init": {
|
|
1122
|
+
if (simulation)
|
|
1123
|
+
simulation.stop();
|
|
1124
|
+
const internalNodes = msg.nodes.map((n) => ({
|
|
1125
|
+
id: n.id,
|
|
1126
|
+
x: n.x,
|
|
1127
|
+
y: n.y,
|
|
1128
|
+
radius: n.radius,
|
|
1129
|
+
community: n.community
|
|
1130
|
+
}));
|
|
1131
|
+
nodeMap = new Map(internalNodes.map((n) => [n.id, n]));
|
|
1132
|
+
const { config } = msg;
|
|
1133
|
+
simulation = simulation_default(internalNodes).force("link", link_default(msg.edges.map((e) => ({ ...e }))).id((d) => d.id).distance(config.linkDistance)).force("charge", manyBody_default().strength(config.chargeStrength)).force("center", center_default(0, 0)).force("collide", collide_default().radius((d) => d.radius + 1)).force("gravityX", x_default2(0).strength(0.05)).force("gravityY", y_default2(0).strength(0.05)).alphaDecay(config.alphaDecay).velocityDecay(config.velocityDecay);
|
|
1134
|
+
if (config.clustering) {
|
|
1135
|
+
const clusterFn = forceCluster(internalNodes, config.clustering.strength);
|
|
1136
|
+
simulation.force("cluster", clusterFn);
|
|
1137
|
+
}
|
|
1138
|
+
simulation.on("tick", () => {
|
|
1139
|
+
post({
|
|
1140
|
+
type: "positions",
|
|
1141
|
+
nodes: packPositions(internalNodes),
|
|
1142
|
+
alpha: simulation.alpha()
|
|
1143
|
+
});
|
|
1144
|
+
});
|
|
1145
|
+
simulation.on("end", () => {
|
|
1146
|
+
post({ type: "settled" });
|
|
1147
|
+
});
|
|
1148
|
+
break;
|
|
1149
|
+
}
|
|
1150
|
+
case "reheat": {
|
|
1151
|
+
if (!simulation)
|
|
1152
|
+
break;
|
|
1153
|
+
simulation.alpha(msg.alpha ?? 0.3).restart();
|
|
1154
|
+
break;
|
|
1155
|
+
}
|
|
1156
|
+
case "pin": {
|
|
1157
|
+
const node = nodeMap.get(msg.nodeId);
|
|
1158
|
+
if (node) {
|
|
1159
|
+
node.fx = msg.x;
|
|
1160
|
+
node.fy = msg.y;
|
|
1161
|
+
}
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
case "unpin": {
|
|
1165
|
+
const node = nodeMap.get(msg.nodeId);
|
|
1166
|
+
if (node) {
|
|
1167
|
+
node.fx = null;
|
|
1168
|
+
node.fy = null;
|
|
1169
|
+
}
|
|
1170
|
+
break;
|
|
1171
|
+
}
|
|
1172
|
+
case "drag": {
|
|
1173
|
+
const node = nodeMap.get(msg.nodeId);
|
|
1174
|
+
if (node) {
|
|
1175
|
+
node.fx = msg.x;
|
|
1176
|
+
node.fy = msg.y;
|
|
1177
|
+
}
|
|
1178
|
+
if (simulation && simulation.alpha() < 0.1) {
|
|
1179
|
+
simulation.alpha(0.1).restart();
|
|
1180
|
+
}
|
|
1181
|
+
break;
|
|
1182
|
+
}
|
|
1183
|
+
case "stop": {
|
|
1184
|
+
if (simulation)
|
|
1185
|
+
simulation.stop();
|
|
1186
|
+
break;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
} catch (err) {
|
|
1190
|
+
post({
|
|
1191
|
+
type: "error",
|
|
1192
|
+
message: err instanceof Error ? err.message : String(err)
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
});
|
|
1196
|
+
})();
|