mdld-parse 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +250 -82
- package/dist/crawl.js +660 -0
- package/dist/{index.js → mdld-parse.js} +21 -16
- package/dist/quad-graph.js +1219 -0
- package/package.json +8 -4
|
@@ -0,0 +1,1219 @@
|
|
|
1
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
|
|
2
|
+
function _typeof(o) {
|
|
3
|
+
"@babel/helpers - typeof";
|
|
4
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
5
|
+
return typeof o;
|
|
6
|
+
} : function(o) {
|
|
7
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
8
|
+
}, _typeof(o);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
|
|
12
|
+
function toPrimitive(t, r) {
|
|
13
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
14
|
+
var e = t[Symbol.toPrimitive];
|
|
15
|
+
if (void 0 !== e) {
|
|
16
|
+
var i = e.call(t, r || "default");
|
|
17
|
+
if ("object" != _typeof(i)) return i;
|
|
18
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
19
|
+
}
|
|
20
|
+
return ("string" === r ? String : Number)(t);
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
|
|
24
|
+
function toPropertyKey(t) {
|
|
25
|
+
var i = toPrimitive(t, "string");
|
|
26
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
|
|
30
|
+
function _defineProperty(e, r, t) {
|
|
31
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
32
|
+
value: t,
|
|
33
|
+
enumerable: !0,
|
|
34
|
+
configurable: !0,
|
|
35
|
+
writable: !0
|
|
36
|
+
}) : e[r] = t, e;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/graph.js
|
|
40
|
+
/**
|
|
41
|
+
* <quad-graph> — zero-dependency RDF quad graph renderer (ESM, Canvas2D, ~650 LOC).
|
|
42
|
+
*
|
|
43
|
+
* import './quad-graph.js'
|
|
44
|
+
* const element = document.createElement('quad-graph');
|
|
45
|
+
* document.body.appendChild(element);
|
|
46
|
+
* g.context = { ex: 'http://example.org/' } // optional prefixes (CURIE labels)
|
|
47
|
+
* g.quads = [...rdfjsQuads] // RDF/JS quads; re-assign any time, updates instantly
|
|
48
|
+
*
|
|
49
|
+
* Attributes: height, charge (repulsion, default 40), link-dist (default 45), labels="off"
|
|
50
|
+
* Methods: focus(iri) select(iri|null) fit() pin(iri,on) reheat() getNode(iri)
|
|
51
|
+
* Props: quads, context, positions ({iri:[x,y]} get/set — persist & restore layouts)
|
|
52
|
+
* Events: node-click (detail = iri) · node-select (iri|null) · node-hover (iri|null) · settled
|
|
53
|
+
* Input: wheel/pinch zoom, drag background = pan, drag node = move, dblclick node = pin/unpin
|
|
54
|
+
* Theming: labels use the CSS `color` of the element; background is transparent.
|
|
55
|
+
*
|
|
56
|
+
* Design: typed-array Barnes-Hut quadtree, time-sliced across frames (never blocks > ~8ms),
|
|
57
|
+
* degree-aware link lengths/strengths, BFS/phyllotaxis warm start, batched canvas paths with
|
|
58
|
+
* viewport culling, density-adaptive alpha, greedy collision-free label placement.
|
|
59
|
+
* Limits: < ~1M nodes, < 4096 distinct predicates (dedupe key).
|
|
60
|
+
*/
|
|
61
|
+
var RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
|
|
62
|
+
var LABEL_RANK = new Map([
|
|
63
|
+
"http://www.w3.org/2000/01/rdf-schema#label",
|
|
64
|
+
"http://www.w3.org/2004/02/skos/core#prefLabel",
|
|
65
|
+
"http://schema.org/name",
|
|
66
|
+
"https://schema.org/name",
|
|
67
|
+
"http://xmlns.com/foaf/0.1/name",
|
|
68
|
+
"http://purl.org/dc/terms/title",
|
|
69
|
+
"http://purl.org/dc/elements/1.1/title"
|
|
70
|
+
].map((p, i) => [p, i]));
|
|
71
|
+
var MAX_LIT = 6;
|
|
72
|
+
var TAU = 6.2832;
|
|
73
|
+
var GOLD = 2.39996;
|
|
74
|
+
var MIN_D2 = 25;
|
|
75
|
+
var MAX_V = 60;
|
|
76
|
+
var Base = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
|
|
77
|
+
var hash = (s) => {
|
|
78
|
+
let h = 2166136261;
|
|
79
|
+
for (let i = 0; i < s.length; i++) {
|
|
80
|
+
h ^= s.charCodeAt(i);
|
|
81
|
+
h = Math.imul(h, 16777619);
|
|
82
|
+
}
|
|
83
|
+
h ^= h >>> 15;
|
|
84
|
+
h = Math.imul(h, 2246822507);
|
|
85
|
+
h ^= h >>> 13;
|
|
86
|
+
return h >>> 0;
|
|
87
|
+
};
|
|
88
|
+
var clamp = (v, a, b) => v < a ? a : v > b ? b : v;
|
|
89
|
+
/** Counting sort of indices 0..keys.length-1 by key → [offsets(K+1), list] */
|
|
90
|
+
var group = (keys, K) => {
|
|
91
|
+
const off = new Int32Array(K + 1), list = new Int32Array(keys.length);
|
|
92
|
+
for (let i = 0; i < keys.length; i++) off[keys[i] + 1]++;
|
|
93
|
+
for (let i = 0; i < K; i++) off[i + 1] += off[i];
|
|
94
|
+
const cur = off.slice(0, K);
|
|
95
|
+
for (let i = 0; i < keys.length; i++) list[cur[keys[i]]++] = i;
|
|
96
|
+
return [off, list];
|
|
97
|
+
};
|
|
98
|
+
var Layout = class {
|
|
99
|
+
constructor() {
|
|
100
|
+
this.n = 0;
|
|
101
|
+
this.alpha = 0;
|
|
102
|
+
this.target = 0;
|
|
103
|
+
this.iter = 0;
|
|
104
|
+
this.charge = 40;
|
|
105
|
+
this.linkDist = 45;
|
|
106
|
+
this.gravity = .03;
|
|
107
|
+
this.x = this.y = /* @__PURE__ */ new Float64Array(0);
|
|
108
|
+
this.ls = this.lt = /* @__PURE__ */ new Int32Array(0);
|
|
109
|
+
this._ph = 0;
|
|
110
|
+
this._cur = 0;
|
|
111
|
+
this._cap = 0;
|
|
112
|
+
this._stk = /* @__PURE__ */ new Int32Array(256);
|
|
113
|
+
}
|
|
114
|
+
get active() {
|
|
115
|
+
return this.n > 0 && (this.alpha >= .001 || this.target > 0);
|
|
116
|
+
}
|
|
117
|
+
load(x, y, ls, lt, deg, r, mass, pin) {
|
|
118
|
+
const n = x.length;
|
|
119
|
+
Object.assign(this, {
|
|
120
|
+
n,
|
|
121
|
+
x,
|
|
122
|
+
y,
|
|
123
|
+
ls,
|
|
124
|
+
lt,
|
|
125
|
+
deg,
|
|
126
|
+
r,
|
|
127
|
+
mass,
|
|
128
|
+
pin,
|
|
129
|
+
vx: new Float64Array(n),
|
|
130
|
+
vy: new Float64Array(n),
|
|
131
|
+
alpha: 1,
|
|
132
|
+
_ph: 0
|
|
133
|
+
});
|
|
134
|
+
this.decay = 1 - Math.pow(.001, 1 / (n > 5e4 ? 120 : n > 2e4 ? 180 : 300));
|
|
135
|
+
this.theta = n > 5e4 ? 1.2 : n > 5e3 ? 1 : .85;
|
|
136
|
+
this.relink();
|
|
137
|
+
}
|
|
138
|
+
/** Hubs get longer links (room for their leaves) and weaker springs (d3-style 1/min(deg)). */
|
|
139
|
+
relink() {
|
|
140
|
+
const { ls, lt, deg, linkDist } = this, m = ls.length;
|
|
141
|
+
this.len = new Float32Array(m);
|
|
142
|
+
this.str = new Float32Array(m);
|
|
143
|
+
this.bias = new Float32Array(m);
|
|
144
|
+
for (let e = 0; e < m; e++) {
|
|
145
|
+
const a = deg[ls[e]], b = deg[lt[e]];
|
|
146
|
+
this.len[e] = linkDist * (.7 + .4 * Math.log2(1 + Math.max(a, b)));
|
|
147
|
+
this.str[e] = 1 / Math.min(a, b);
|
|
148
|
+
this.bias[e] = a / (a + b);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
reheat(a = .6) {
|
|
152
|
+
this.alpha = Math.max(this.alpha, a);
|
|
153
|
+
}
|
|
154
|
+
/** Run ticks until `ms` elapsed or `maxTicks` done. A tick may span several calls on huge graphs. */
|
|
155
|
+
step(ms, maxTicks = 1) {
|
|
156
|
+
const t0 = performance.now();
|
|
157
|
+
let ticks = 0;
|
|
158
|
+
while (this.active) {
|
|
159
|
+
if (this._ph === 0) {
|
|
160
|
+
this._build();
|
|
161
|
+
this._cur = 0;
|
|
162
|
+
this._ph = 1;
|
|
163
|
+
}
|
|
164
|
+
if (this._ph === 1) {
|
|
165
|
+
if (!this._repel(t0 + ms)) return true;
|
|
166
|
+
this._ph = 2;
|
|
167
|
+
}
|
|
168
|
+
this._integrate();
|
|
169
|
+
this._ph = 0;
|
|
170
|
+
if (++ticks >= maxTicks || performance.now() - t0 > ms) break;
|
|
171
|
+
}
|
|
172
|
+
return this.active;
|
|
173
|
+
}
|
|
174
|
+
_alloc(cap) {
|
|
175
|
+
const grow = (A, n) => {
|
|
176
|
+
const B = new A.constructor(n);
|
|
177
|
+
B.set(A);
|
|
178
|
+
return B;
|
|
179
|
+
};
|
|
180
|
+
if (!this.nm) Object.assign(this, {
|
|
181
|
+
nm: new Float64Array(cap),
|
|
182
|
+
nsx: new Float64Array(cap),
|
|
183
|
+
nsy: new Float64Array(cap),
|
|
184
|
+
nw: new Float64Array(cap),
|
|
185
|
+
nb: new Int32Array(cap),
|
|
186
|
+
ch: new Int32Array(cap * 4)
|
|
187
|
+
});
|
|
188
|
+
else {
|
|
189
|
+
for (const k of [
|
|
190
|
+
"nm",
|
|
191
|
+
"nsx",
|
|
192
|
+
"nsy",
|
|
193
|
+
"nw"
|
|
194
|
+
]) this[k] = grow(this[k], cap);
|
|
195
|
+
this.nb = grow(this.nb, cap);
|
|
196
|
+
this.ch = grow(this.ch, cap * 4);
|
|
197
|
+
}
|
|
198
|
+
this._cap = cap;
|
|
199
|
+
}
|
|
200
|
+
_new(w) {
|
|
201
|
+
const c = this._cnt++;
|
|
202
|
+
this.nm[c] = this.nsx[c] = this.nsy[c] = 0;
|
|
203
|
+
this.nb[c] = -2;
|
|
204
|
+
this.nw[c] = w;
|
|
205
|
+
this.ch.fill(0, c * 4, c * 4 + 4);
|
|
206
|
+
return c;
|
|
207
|
+
}
|
|
208
|
+
/** Rebuild Barnes-Hut quadtree. nb: -2 empty leaf, -1 internal, >=0 leaf body. */
|
|
209
|
+
_build() {
|
|
210
|
+
const { x, y, n } = this;
|
|
211
|
+
let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
|
|
212
|
+
for (let i = 0; i < n; i++) {
|
|
213
|
+
const a = x[i], b = y[i];
|
|
214
|
+
if (a < x0) x0 = a;
|
|
215
|
+
if (a > x1) x1 = a;
|
|
216
|
+
if (b < y0) y0 = b;
|
|
217
|
+
if (b > y1) y1 = b;
|
|
218
|
+
}
|
|
219
|
+
const w = Math.max(x1 - x0, y1 - y0, 1) * 1.001;
|
|
220
|
+
this._cx = (x0 + x1) / 2;
|
|
221
|
+
this._cy = (y0 + y1) / 2;
|
|
222
|
+
this._hw = w / 2;
|
|
223
|
+
if (this._cap < 2 * n + 80) this._alloc(2 * n + 80);
|
|
224
|
+
this._cnt = 0;
|
|
225
|
+
this._new(w);
|
|
226
|
+
for (let i = 0; i < n; i++) {
|
|
227
|
+
if (this._cnt + 70 > this._cap) this._alloc(this._cap * 2);
|
|
228
|
+
this._insert(i);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
_insert(i) {
|
|
232
|
+
const { x, y, mass, nm, nsx, nsy, nb, ch } = this, px = x[i], py = y[i], m = mass[i];
|
|
233
|
+
let nd = 0, cx = this._cx, cy = this._cy, hw = this._hw, depth = 0;
|
|
234
|
+
for (;;) {
|
|
235
|
+
nm[nd] += m;
|
|
236
|
+
nsx[nd] += px * m;
|
|
237
|
+
nsy[nd] += py * m;
|
|
238
|
+
const b = nb[nd];
|
|
239
|
+
if (b === -2) {
|
|
240
|
+
nb[nd] = i;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (b >= 0) {
|
|
244
|
+
if (depth >= 28) return;
|
|
245
|
+
nb[nd] = -1;
|
|
246
|
+
const c = this._new(hw), q = (x[b] > cx ? 1 : 0) | (y[b] > cy ? 2 : 0);
|
|
247
|
+
ch[nd * 4 + q] = c;
|
|
248
|
+
nb[c] = b;
|
|
249
|
+
nm[c] = mass[b];
|
|
250
|
+
nsx[c] = x[b] * mass[b];
|
|
251
|
+
nsy[c] = y[b] * mass[b];
|
|
252
|
+
}
|
|
253
|
+
const q = (px > cx ? 1 : 0) | (py > cy ? 2 : 0);
|
|
254
|
+
hw *= .5;
|
|
255
|
+
cx += q & 1 ? hw : -hw;
|
|
256
|
+
cy += q & 2 ? hw : -hw;
|
|
257
|
+
let c = ch[nd * 4 + q];
|
|
258
|
+
if (!c) {
|
|
259
|
+
c = this._new(hw * 2);
|
|
260
|
+
ch[nd * 4 + q] = c;
|
|
261
|
+
}
|
|
262
|
+
nd = c;
|
|
263
|
+
depth++;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/** Many-body repulsion + node collision, chunked against a deadline. Returns true when all nodes done. */
|
|
267
|
+
_repel(deadline) {
|
|
268
|
+
const { x, y, vx, vy, r, n, nm, nsx, nsy, nw, nb, ch, _stk: stk } = this;
|
|
269
|
+
const k = this.charge * this.alpha, th2 = this.theta * this.theta;
|
|
270
|
+
for (let i = this._cur; i < n; i++) {
|
|
271
|
+
if ((i & 63) === 63 && performance.now() > deadline) {
|
|
272
|
+
this._cur = i;
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
const xi = x[i], yi = y[i], ri = r[i];
|
|
276
|
+
let fx = 0, fy = 0, sp = 0;
|
|
277
|
+
stk[sp++] = 0;
|
|
278
|
+
while (sp) {
|
|
279
|
+
const nd = stk[--sp], m = nm[nd];
|
|
280
|
+
if (m === 0) continue;
|
|
281
|
+
const b = nb[nd];
|
|
282
|
+
let dx = nsx[nd] / m - xi, dy = nsy[nd] / m - yi, d2 = dx * dx + dy * dy;
|
|
283
|
+
if (b >= 0) {
|
|
284
|
+
if (b === i) continue;
|
|
285
|
+
if (d2 < 1e-6) {
|
|
286
|
+
dx = Math.random() - .5;
|
|
287
|
+
dy = Math.random() - .5;
|
|
288
|
+
d2 = dx * dx + dy * dy + 1e-6;
|
|
289
|
+
}
|
|
290
|
+
const rr = ri + r[b] + 3;
|
|
291
|
+
let w = k * m / Math.max(d2, MIN_D2);
|
|
292
|
+
if (d2 < rr * rr) {
|
|
293
|
+
const d = Math.sqrt(d2);
|
|
294
|
+
w += (rr - d) / d * .35;
|
|
295
|
+
}
|
|
296
|
+
fx -= dx * w;
|
|
297
|
+
fy -= dy * w;
|
|
298
|
+
} else if (nw[nd] * nw[nd] < th2 * d2) {
|
|
299
|
+
const w = k * m / Math.max(d2, MIN_D2);
|
|
300
|
+
fx -= dx * w;
|
|
301
|
+
fy -= dy * w;
|
|
302
|
+
} else {
|
|
303
|
+
const o = nd * 4;
|
|
304
|
+
for (let q = 0; q < 4; q++) {
|
|
305
|
+
const c = ch[o + q];
|
|
306
|
+
if (c) stk[sp++] = c;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
vx[i] += fx;
|
|
311
|
+
vy[i] += fy;
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
_integrate() {
|
|
316
|
+
const { x, y, vx, vy, ls, lt, len, str, bias, n, alpha, pin } = this;
|
|
317
|
+
for (let e = 0; e < ls.length; e++) {
|
|
318
|
+
const s = ls[e], t = lt[e];
|
|
319
|
+
let dx = x[t] + vx[t] - x[s] - vx[s], dy = y[t] + vy[t] - y[s] - vy[s];
|
|
320
|
+
const d = Math.sqrt(dx * dx + dy * dy) || 1e-6, l = (d - len[e]) / d * alpha * str[e], b = bias[e];
|
|
321
|
+
dx *= l;
|
|
322
|
+
dy *= l;
|
|
323
|
+
vx[t] -= dx * b;
|
|
324
|
+
vy[t] -= dy * b;
|
|
325
|
+
vx[s] += dx * (1 - b);
|
|
326
|
+
vy[s] += dy * (1 - b);
|
|
327
|
+
}
|
|
328
|
+
const g = this.gravity * alpha;
|
|
329
|
+
for (let i = 0; i < n; i++) {
|
|
330
|
+
if (pin[i]) {
|
|
331
|
+
vx[i] = vy[i] = 0;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
vx[i] = (vx[i] - x[i] * g) * .6;
|
|
335
|
+
vy[i] = (vy[i] - y[i] * g) * .6;
|
|
336
|
+
const v2 = vx[i] * vx[i] + vy[i] * vy[i];
|
|
337
|
+
if (v2 > 3600) {
|
|
338
|
+
const s = MAX_V / Math.sqrt(v2);
|
|
339
|
+
vx[i] *= s;
|
|
340
|
+
vy[i] *= s;
|
|
341
|
+
}
|
|
342
|
+
if (v2 !== v2) {
|
|
343
|
+
vx[i] = vy[i] = 0;
|
|
344
|
+
x[i] = y[i] = 0;
|
|
345
|
+
}
|
|
346
|
+
x[i] += vx[i];
|
|
347
|
+
y[i] += vy[i];
|
|
348
|
+
}
|
|
349
|
+
this.alpha += (this.target - this.alpha) * this.decay;
|
|
350
|
+
this.iter++;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
/** Warm start: BFS outward from already-placed nodes; new components on a phyllotaxis spiral (biggest first). */
|
|
354
|
+
function seedLayout(n, ls, lt, off, adj, order, x, y, placed, L) {
|
|
355
|
+
const q = new Int32Array(n), kids = new Int32Array(n);
|
|
356
|
+
let h = 0, t = 0, comp = 0;
|
|
357
|
+
for (let i = 0; i < n; i++) if (placed[i]) q[t++] = i;
|
|
358
|
+
const bfs = () => {
|
|
359
|
+
while (h < t) {
|
|
360
|
+
const u = q[h++];
|
|
361
|
+
for (let a = off[u]; a < off[u + 1]; a++) {
|
|
362
|
+
const e = adj[a], v = ls[e] === u ? lt[e] : ls[e];
|
|
363
|
+
if (placed[v]) continue;
|
|
364
|
+
const k = kids[u]++, ang = k * GOLD + u, rad = L * (.8 + .3 * Math.sqrt(k));
|
|
365
|
+
x[v] = x[u] + Math.cos(ang) * rad;
|
|
366
|
+
y[v] = y[u] + Math.sin(ang) * rad;
|
|
367
|
+
placed[v] = 1;
|
|
368
|
+
q[t++] = v;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
bfs();
|
|
373
|
+
for (let j = 0; j < n; j++) {
|
|
374
|
+
const i = order[j];
|
|
375
|
+
if (placed[i]) continue;
|
|
376
|
+
const a = comp * GOLD, r = L * 1.6 * Math.sqrt(++comp);
|
|
377
|
+
x[i] = Math.cos(a) * r;
|
|
378
|
+
y[i] = Math.sin(a) * r;
|
|
379
|
+
placed[i] = 1;
|
|
380
|
+
q[t++] = i;
|
|
381
|
+
bfs();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
var CSS = `:host{display:block;position:relative;height:480px;overflow:hidden;color:#eee;touch-action:none;user-select:none;-webkit-user-select:none;background:#1a1a1a}
|
|
385
|
+
canvas{position:absolute;inset:0;width:100%;height:100%;display:block;cursor:grab;background:#1a1a1a}
|
|
386
|
+
.hud{position:absolute;left:8px;top:6px;font:11px/1.2 system-ui,sans-serif;opacity:.6;pointer-events:none;display:flex;gap:8px;align-items:center;color:#ccc}
|
|
387
|
+
.bar{width:44px;height:3px;border-radius:2px;background:#444;overflow:hidden}.bar i{display:block;height:100%;width:0;background:#1D9E75}
|
|
388
|
+
.tip{position:absolute;left:0;top:0;pointer-events:none;max-width:320px;padding:6px 9px;border-radius:7px;font:12px/1.4 system-ui,sans-serif;background:#2a2a2a;color:#eee;border:1px solid #444;box-shadow:0 4px 16px #0003;display:none;z-index:2;overflow-wrap:anywhere}
|
|
389
|
+
.tip b{display:block}.tip small{display:block;opacity:.6}`;
|
|
390
|
+
var QuadGraph = class extends Base {
|
|
391
|
+
constructor() {
|
|
392
|
+
super();
|
|
393
|
+
const root = this.attachShadow({ mode: "open" });
|
|
394
|
+
root.innerHTML = `<style>${CSS}</style><canvas></canvas><div class="hud"><span></span><div class="bar"><i></i></div></div><div class="tip"></div>`;
|
|
395
|
+
this._cv = root.querySelector("canvas");
|
|
396
|
+
this._g2 = this._cv.getContext("2d");
|
|
397
|
+
this._stat = root.querySelector(".hud span");
|
|
398
|
+
this._bar = root.querySelector(".bar i");
|
|
399
|
+
this._tip = root.querySelector(".tip");
|
|
400
|
+
this._quads = [];
|
|
401
|
+
this._pfx = [];
|
|
402
|
+
this._L = new Layout();
|
|
403
|
+
this._ids = null;
|
|
404
|
+
this._names = [];
|
|
405
|
+
this._typ = /* @__PURE__ */ new Int32Array(0);
|
|
406
|
+
this._classes = [null];
|
|
407
|
+
this._lits = /* @__PURE__ */ new Map();
|
|
408
|
+
this._lab = /* @__PURE__ */ new Map();
|
|
409
|
+
this._lc = [];
|
|
410
|
+
this._plc = [];
|
|
411
|
+
this._v = {
|
|
412
|
+
k: 1,
|
|
413
|
+
x: 0,
|
|
414
|
+
y: 0
|
|
415
|
+
};
|
|
416
|
+
this._w = 600;
|
|
417
|
+
this._h = 480;
|
|
418
|
+
this._dpr = 1;
|
|
419
|
+
this._fg = "#888";
|
|
420
|
+
this._halo = "rgba(255,255,255,.8)";
|
|
421
|
+
this._tt = -1e9;
|
|
422
|
+
this._sel = -1;
|
|
423
|
+
this._hov = -1;
|
|
424
|
+
this._nl = [];
|
|
425
|
+
this._el = [];
|
|
426
|
+
this._auto = true;
|
|
427
|
+
this._fc = 0;
|
|
428
|
+
this._ht = 0;
|
|
429
|
+
this._st = "";
|
|
430
|
+
this._occ = /* @__PURE__ */ new Uint8Array(0);
|
|
431
|
+
this._oc = 1;
|
|
432
|
+
this._or = 1;
|
|
433
|
+
this._ptrs = /* @__PURE__ */ new Map();
|
|
434
|
+
this._gs = null;
|
|
435
|
+
this._bend = /* @__PURE__ */ new Float32Array(0);
|
|
436
|
+
this._lp = /* @__PURE__ */ new Int32Array(0);
|
|
437
|
+
this._pc = [];
|
|
438
|
+
this._fill = [];
|
|
439
|
+
this._ring = [];
|
|
440
|
+
this._pOff = this._pList = this._cOff = this._cList = this._order = this._off = this._adj = /* @__PURE__ */ new Int32Array(0);
|
|
441
|
+
this._bind();
|
|
442
|
+
}
|
|
443
|
+
connectedCallback() {
|
|
444
|
+
this._ro = new ResizeObserver(() => this._resize());
|
|
445
|
+
this._ro.observe(this);
|
|
446
|
+
this._mq = typeof matchMedia !== "undefined" ? matchMedia("(prefers-color-scheme: dark)") : null;
|
|
447
|
+
this._onTheme = () => {
|
|
448
|
+
this._tt = -1e9;
|
|
449
|
+
this._dirty = true;
|
|
450
|
+
this._wake();
|
|
451
|
+
};
|
|
452
|
+
this._mq?.addEventListener("change", this._onTheme);
|
|
453
|
+
this._resize();
|
|
454
|
+
if (this._quads.length && !this._ids) this._queue();
|
|
455
|
+
this._wake();
|
|
456
|
+
}
|
|
457
|
+
disconnectedCallback() {
|
|
458
|
+
cancelAnimationFrame(this._raf);
|
|
459
|
+
this._raf = 0;
|
|
460
|
+
this._ro?.disconnect();
|
|
461
|
+
this._mq?.removeEventListener("change", this._onTheme);
|
|
462
|
+
}
|
|
463
|
+
attributeChangedCallback(name, _, v) {
|
|
464
|
+
const L = this._L;
|
|
465
|
+
if (name === "height") this.style.height = /^\d+$/.test(v) ? v + "px" : v || "";
|
|
466
|
+
else if (name === "charge") {
|
|
467
|
+
L.charge = Math.abs(parseFloat(v)) || 40;
|
|
468
|
+
this.reheat(.5);
|
|
469
|
+
} else if (name === "link-dist") {
|
|
470
|
+
L.linkDist = parseFloat(v) || 45;
|
|
471
|
+
if (L.n) L.relink();
|
|
472
|
+
this.reheat(.6);
|
|
473
|
+
} else {
|
|
474
|
+
this._dirty = true;
|
|
475
|
+
this._wake();
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
get quads() {
|
|
479
|
+
return this._quads;
|
|
480
|
+
}
|
|
481
|
+
set quads(q) {
|
|
482
|
+
this._quads = q || [];
|
|
483
|
+
this._queue();
|
|
484
|
+
}
|
|
485
|
+
get context() {
|
|
486
|
+
return this._ctxObj;
|
|
487
|
+
}
|
|
488
|
+
set context(c) {
|
|
489
|
+
this._ctxObj = c || {};
|
|
490
|
+
this._pfx = Object.entries(this._ctxObj).map(([p, v]) => [p, typeof v === "string" ? v : v?.["@id"]]).filter(([p, v]) => v && p[0] !== "@").sort((a, b) => b[1].length - a[1].length);
|
|
491
|
+
this._queue();
|
|
492
|
+
}
|
|
493
|
+
get positions() {
|
|
494
|
+
const o = {}, L = this._L;
|
|
495
|
+
for (let i = 0; i < L.n; i++) o[this._names[i]] = [L.x[i], L.y[i]];
|
|
496
|
+
return o;
|
|
497
|
+
}
|
|
498
|
+
set positions(o) {
|
|
499
|
+
this._seed = o;
|
|
500
|
+
this._queue();
|
|
501
|
+
}
|
|
502
|
+
reheat(a = .6) {
|
|
503
|
+
this._L.reheat(a);
|
|
504
|
+
this._wake();
|
|
505
|
+
}
|
|
506
|
+
fit() {
|
|
507
|
+
this._auto = false;
|
|
508
|
+
this._anim = this._fitTarget();
|
|
509
|
+
this._wake();
|
|
510
|
+
}
|
|
511
|
+
select(iri) {
|
|
512
|
+
const i = iri == null ? -1 : this._ids?.get(iri);
|
|
513
|
+
this._select(i === void 0 ? -1 : i);
|
|
514
|
+
}
|
|
515
|
+
focus(iri, { zoom = 1.5 } = {}) {
|
|
516
|
+
const i = this._ids?.get(iri);
|
|
517
|
+
if (i === void 0) return false;
|
|
518
|
+
this._select(i);
|
|
519
|
+
const k = Math.max(this._v.k, zoom);
|
|
520
|
+
this._auto = false;
|
|
521
|
+
this._anim = {
|
|
522
|
+
k,
|
|
523
|
+
x: this._w / 2 - this._L.x[i] * k,
|
|
524
|
+
y: this._h / 2 - this._L.y[i] * k
|
|
525
|
+
};
|
|
526
|
+
this._wake();
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
pin(iri, on = true) {
|
|
530
|
+
const i = this._ids?.get(iri);
|
|
531
|
+
if (i === void 0) return;
|
|
532
|
+
this._L.pin[i] = on ? 1 : 0;
|
|
533
|
+
this._dirty = true;
|
|
534
|
+
this._wake();
|
|
535
|
+
}
|
|
536
|
+
getNode(iri) {
|
|
537
|
+
const i = this._ids?.get(iri);
|
|
538
|
+
if (i === void 0) return null;
|
|
539
|
+
const L = this._L, c = this._typ[i];
|
|
540
|
+
return {
|
|
541
|
+
id: iri,
|
|
542
|
+
label: this._label(i),
|
|
543
|
+
x: L.x[i],
|
|
544
|
+
y: L.y[i],
|
|
545
|
+
degree: L.deg[i],
|
|
546
|
+
pinned: !!(L.pin[i] & 1),
|
|
547
|
+
type: c ? this._classes[c] : null,
|
|
548
|
+
literals: (this._lits.get(i) || []).map(([predicate, value]) => ({
|
|
549
|
+
predicate,
|
|
550
|
+
value
|
|
551
|
+
}))
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
_queue() {
|
|
555
|
+
if (this._pend) return;
|
|
556
|
+
this._pend = true;
|
|
557
|
+
queueMicrotask(() => {
|
|
558
|
+
this._pend = false;
|
|
559
|
+
this._ingest();
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
_ingest() {
|
|
563
|
+
const ids = /* @__PURE__ */ new Map(), names = [], litN = [], typ = [], ls = [], lt = [], lp = [], lab = /* @__PURE__ */ new Map(), lits = /* @__PURE__ */ new Map();
|
|
564
|
+
const classes = [null], classIdx = /* @__PURE__ */ new Map(), preds = [], predIdx = /* @__PURE__ */ new Map(), seen = /* @__PURE__ */ new Set();
|
|
565
|
+
const idOf = (t) => t.termType === "BlankNode" ? "_:" + t.value : t.value;
|
|
566
|
+
const node = (id) => {
|
|
567
|
+
let i = ids.get(id);
|
|
568
|
+
if (i === void 0) {
|
|
569
|
+
i = names.length;
|
|
570
|
+
ids.set(id, i);
|
|
571
|
+
names.push(id);
|
|
572
|
+
litN.push(0);
|
|
573
|
+
typ.push(0);
|
|
574
|
+
}
|
|
575
|
+
return i;
|
|
576
|
+
};
|
|
577
|
+
for (const q of this._quads) {
|
|
578
|
+
if (!q || !q.subject || !q.predicate || !q.object) continue;
|
|
579
|
+
const o = q.object, p = q.predicate.value, sid = idOf(q.subject), si = node(sid);
|
|
580
|
+
if (o.termType === "Literal") {
|
|
581
|
+
litN[si]++;
|
|
582
|
+
const lr = LABEL_RANK.get(p);
|
|
583
|
+
if (lr !== void 0) {
|
|
584
|
+
const c = lab.get(sid);
|
|
585
|
+
if (!c || lr < c[1]) lab.set(sid, [o.value, lr]);
|
|
586
|
+
}
|
|
587
|
+
let a = lits.get(si);
|
|
588
|
+
if (!a) lits.set(si, a = []);
|
|
589
|
+
if (a.length < MAX_LIT) a.push([p, o.value]);
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (o.termType !== "NamedNode" && o.termType !== "BlankNode") continue;
|
|
593
|
+
const ti = node(idOf(o));
|
|
594
|
+
if (si === ti) continue;
|
|
595
|
+
let pi = predIdx.get(p);
|
|
596
|
+
if (pi === void 0) {
|
|
597
|
+
pi = preds.length;
|
|
598
|
+
predIdx.set(p, pi);
|
|
599
|
+
preds.push(p);
|
|
600
|
+
}
|
|
601
|
+
const key = (si * 1048576 + ti) * 4096 + (pi & 4095);
|
|
602
|
+
if (seen.has(key)) continue;
|
|
603
|
+
seen.add(key);
|
|
604
|
+
ls.push(si);
|
|
605
|
+
lt.push(ti);
|
|
606
|
+
lp.push(pi);
|
|
607
|
+
if (p === RDF_TYPE && o.termType === "NamedNode" && !typ[si]) {
|
|
608
|
+
let c = classIdx.get(o.value);
|
|
609
|
+
if (c === void 0) {
|
|
610
|
+
c = classes.length;
|
|
611
|
+
classIdx.set(o.value, c);
|
|
612
|
+
classes.push(o.value);
|
|
613
|
+
}
|
|
614
|
+
typ[si] = c;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
for (let c = 1; c < classes.length; c++) {
|
|
618
|
+
const i = ids.get(classes[c]);
|
|
619
|
+
if (!typ[i]) typ[i] = c;
|
|
620
|
+
}
|
|
621
|
+
const n = names.length, m = ls.length, LS = Int32Array.from(ls), LT = Int32Array.from(lt), LP = Int32Array.from(lp);
|
|
622
|
+
const off = new Int32Array(n + 1);
|
|
623
|
+
for (let e = 0; e < m; e++) {
|
|
624
|
+
off[LS[e] + 1]++;
|
|
625
|
+
off[LT[e] + 1]++;
|
|
626
|
+
}
|
|
627
|
+
for (let i = 0; i < n; i++) off[i + 1] += off[i];
|
|
628
|
+
const cur = off.slice(0, n), adj = new Int32Array(2 * m), deg = new Int32Array(n);
|
|
629
|
+
for (let e = 0; e < m; e++) {
|
|
630
|
+
adj[cur[LS[e]]++] = e;
|
|
631
|
+
adj[cur[LT[e]]++] = e;
|
|
632
|
+
}
|
|
633
|
+
const r = new Float64Array(n), mass = new Float64Array(n);
|
|
634
|
+
for (let i = 0; i < n; i++) {
|
|
635
|
+
deg[i] = off[i + 1] - off[i];
|
|
636
|
+
r[i] = Math.min(18, 3 + 1.6 * Math.sqrt(deg[i] + .5 * litN[i]));
|
|
637
|
+
mass[i] = 1 + .5 * Math.sqrt(deg[i]);
|
|
638
|
+
}
|
|
639
|
+
const pairs = /* @__PURE__ */ new Map(), bend = new Float32Array(m), pk = (e) => Math.min(LS[e], LT[e]) * 1048576 + Math.max(LS[e], LT[e]);
|
|
640
|
+
for (let e = 0; e < m; e++) pairs.set(pk(e), (pairs.get(pk(e)) || 0) + 1);
|
|
641
|
+
const run = /* @__PURE__ */ new Map();
|
|
642
|
+
for (let e = 0; e < m; e++) {
|
|
643
|
+
const k = pk(e), c = pairs.get(k);
|
|
644
|
+
if (c < 2) continue;
|
|
645
|
+
const j = run.get(k) || 0;
|
|
646
|
+
run.set(k, j + 1);
|
|
647
|
+
bend[e] = (j - (c - 1) / 2) * 16 * (LS[e] < LT[e] ? 1 : -1);
|
|
648
|
+
}
|
|
649
|
+
const old = this._ids, oL = this._L, ox = oL.x, oy = oL.y, opin = oL.pin, seed = this._seed;
|
|
650
|
+
this._seed = null;
|
|
651
|
+
const x = new Float64Array(n), y = new Float64Array(n), placed = new Uint8Array(n), pin = new Uint8Array(n);
|
|
652
|
+
for (let i = 0; i < n; i++) {
|
|
653
|
+
const s = seed?.[names[i]], j = old?.get(names[i]);
|
|
654
|
+
if (s) {
|
|
655
|
+
x[i] = s[0];
|
|
656
|
+
y[i] = s[1];
|
|
657
|
+
placed[i] = 1;
|
|
658
|
+
} else if (j !== void 0) {
|
|
659
|
+
x[i] = ox[j];
|
|
660
|
+
y[i] = oy[j];
|
|
661
|
+
placed[i] = 1;
|
|
662
|
+
pin[i] = opin[j] & 1;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
const hadOld = old && old.size > 0 && placed.some((v) => v);
|
|
666
|
+
const order = Int32Array.from({ length: n }, (_, i) => i).sort((a, b) => deg[b] - deg[a]);
|
|
667
|
+
seedLayout(n, LS, LT, off, adj, order, x, y, placed, oL.linkDist);
|
|
668
|
+
const [pOff, pList] = group(LP, preds.length), [cOff, cList] = group(typ, classes.length);
|
|
669
|
+
this._pc = preds.map((p) => p === RDF_TYPE ? "hsl(220 8% 55%)" : `hsl(${hash(p) % 360} 50% 55%)`);
|
|
670
|
+
this._fill = classes.map((c, i) => i ? `hsl(${hash(c) % 360} 70% 56%)` : "hsl(215 12% 62%)");
|
|
671
|
+
this._ring = classes.map((c, i) => i ? `hsl(${hash(c) % 360} 70% 36%)` : "hsl(215 12% 42%)");
|
|
672
|
+
Object.assign(this, {
|
|
673
|
+
_ids: ids,
|
|
674
|
+
_names: names,
|
|
675
|
+
_typ: Int32Array.from(typ),
|
|
676
|
+
_classes: classes,
|
|
677
|
+
_lits: lits,
|
|
678
|
+
_lab: lab,
|
|
679
|
+
_lc: [],
|
|
680
|
+
_plc: [],
|
|
681
|
+
_preds: preds,
|
|
682
|
+
_bend: bend,
|
|
683
|
+
_lp: LP,
|
|
684
|
+
_pOff: pOff,
|
|
685
|
+
_pList: pList,
|
|
686
|
+
_cOff: cOff,
|
|
687
|
+
_cList: cList,
|
|
688
|
+
_order: order,
|
|
689
|
+
_off: off,
|
|
690
|
+
_adj: adj
|
|
691
|
+
});
|
|
692
|
+
const L = this._L;
|
|
693
|
+
L.charge = Math.abs(parseFloat(this.getAttribute("charge"))) || 40;
|
|
694
|
+
L.linkDist = parseFloat(this.getAttribute("link-dist")) || 45;
|
|
695
|
+
L.load(x, y, LS, LT, deg, r, mass, pin);
|
|
696
|
+
if (hadOld) L.alpha = .5;
|
|
697
|
+
this._sel = -1;
|
|
698
|
+
this._hov = -1;
|
|
699
|
+
this._nl = [];
|
|
700
|
+
this._el = [];
|
|
701
|
+
this._tip.style.display = "none";
|
|
702
|
+
if (!hadOld) {
|
|
703
|
+
this._auto = true;
|
|
704
|
+
if (n) Object.assign(this._v, this._fitTarget());
|
|
705
|
+
}
|
|
706
|
+
this._theme();
|
|
707
|
+
this._dirty = true;
|
|
708
|
+
this._wake();
|
|
709
|
+
}
|
|
710
|
+
_curie(iri) {
|
|
711
|
+
for (const [p, ns] of this._pfx) if (iri.length > ns.length && iri.startsWith(ns)) return p + ":" + iri.slice(ns.length);
|
|
712
|
+
const m = iri.match(/[#/:]([^#/:]+)\/?$/);
|
|
713
|
+
let s = m ? m[1] : iri;
|
|
714
|
+
try {
|
|
715
|
+
s = decodeURIComponent(s);
|
|
716
|
+
} catch {}
|
|
717
|
+
return s;
|
|
718
|
+
}
|
|
719
|
+
_label(i) {
|
|
720
|
+
var _this$_lc;
|
|
721
|
+
return (_this$_lc = this._lc)[i] ?? (_this$_lc[i] = this._lab.get(this._names[i])?.[0] ?? this._curie(this._names[i]));
|
|
722
|
+
}
|
|
723
|
+
_plabel(p) {
|
|
724
|
+
var _this$_plc;
|
|
725
|
+
return (_this$_plc = this._plc)[p] ?? (_this$_plc[p] = this._lab.get(this._preds[p])?.[0] ?? this._curie(this._preds[p]));
|
|
726
|
+
}
|
|
727
|
+
_theme() {
|
|
728
|
+
this._tt = performance.now();
|
|
729
|
+
this._fg = "#eee";
|
|
730
|
+
this._halo = "rgba(0,0,0,.8)";
|
|
731
|
+
}
|
|
732
|
+
_resize() {
|
|
733
|
+
const w = this.clientWidth || 600, h = this.clientHeight || 480, d = Math.min(globalThis.devicePixelRatio || 1, this._L.n > 5e4 ? 1.5 : 2);
|
|
734
|
+
Object.assign(this, {
|
|
735
|
+
_w: w,
|
|
736
|
+
_h: h,
|
|
737
|
+
_dpr: d,
|
|
738
|
+
_oc: Math.ceil(w / 12) + 1,
|
|
739
|
+
_or: Math.ceil(h / 12) + 1
|
|
740
|
+
});
|
|
741
|
+
this._cv.width = Math.round(w * d);
|
|
742
|
+
this._cv.height = Math.round(h * d);
|
|
743
|
+
this._occ = new Uint8Array(this._oc * this._or);
|
|
744
|
+
if (this._auto && this._L.n) Object.assign(this._v, this._fitTarget());
|
|
745
|
+
this._dirty = true;
|
|
746
|
+
this._wake();
|
|
747
|
+
}
|
|
748
|
+
/** Robust bounds (mean ± 3σ so flung-out strays don't wreck the zoom) → view transform. */
|
|
749
|
+
_fitTarget() {
|
|
750
|
+
const { x, y, n } = this._L, W = this._w, H = this._h;
|
|
751
|
+
if (!n) return {
|
|
752
|
+
k: 1,
|
|
753
|
+
x: W / 2,
|
|
754
|
+
y: H / 2
|
|
755
|
+
};
|
|
756
|
+
let mx = 0, my = 0;
|
|
757
|
+
for (let i = 0; i < n; i++) {
|
|
758
|
+
mx += x[i];
|
|
759
|
+
my += y[i];
|
|
760
|
+
}
|
|
761
|
+
mx /= n;
|
|
762
|
+
my /= n;
|
|
763
|
+
let vx = 0, vy = 0;
|
|
764
|
+
for (let i = 0; i < n; i++) {
|
|
765
|
+
vx += (x[i] - mx) ** 2;
|
|
766
|
+
vy += (y[i] - my) ** 2;
|
|
767
|
+
}
|
|
768
|
+
const lx = 3 * Math.sqrt(vx / n) + 20, ly = 3 * Math.sqrt(vy / n) + 20;
|
|
769
|
+
let a = Infinity, b = Infinity, c = -Infinity, d = -Infinity;
|
|
770
|
+
for (let i = 0; i < n; i++) if (Math.abs(x[i] - mx) <= lx && Math.abs(y[i] - my) <= ly) {
|
|
771
|
+
if (x[i] < a) a = x[i];
|
|
772
|
+
if (x[i] > c) c = x[i];
|
|
773
|
+
if (y[i] < b) b = y[i];
|
|
774
|
+
if (y[i] > d) d = y[i];
|
|
775
|
+
}
|
|
776
|
+
const k = clamp(Math.min((W - 100) / (c - a || 1), (H - 100) / (d - b || 1)), .005, 1.5);
|
|
777
|
+
return {
|
|
778
|
+
k,
|
|
779
|
+
x: W / 2 - k * (a + c) / 2,
|
|
780
|
+
y: H / 2 - k * (b + d) / 2
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
_zoomAt(px, py, f) {
|
|
784
|
+
const v = this._v, nk = clamp(v.k * f, .005, 60);
|
|
785
|
+
f = nk / v.k;
|
|
786
|
+
v.x = px - (px - v.x) * f;
|
|
787
|
+
v.y = py - (py - v.y) * f;
|
|
788
|
+
v.k = nk;
|
|
789
|
+
this._dirty = true;
|
|
790
|
+
this._wake();
|
|
791
|
+
}
|
|
792
|
+
_wake() {
|
|
793
|
+
if (!this._raf) this._raf = requestAnimationFrame(() => {
|
|
794
|
+
this._raf = 0;
|
|
795
|
+
this._frame();
|
|
796
|
+
});
|
|
797
|
+
}
|
|
798
|
+
_frame() {
|
|
799
|
+
const L = this._L, was = L.active;
|
|
800
|
+
let more = false;
|
|
801
|
+
if (was) {
|
|
802
|
+
const it = L.iter;
|
|
803
|
+
L.step(L.n > 2e4 ? 8 : 5, L.n > 3e3 ? 1 : 2);
|
|
804
|
+
if (L.iter !== it) this._dirty = true;
|
|
805
|
+
more = L.active;
|
|
806
|
+
}
|
|
807
|
+
if (this._auto && L.n && (more ? ++this._fc % 6 === 0 : was)) this._anim = this._fitTarget();
|
|
808
|
+
if (was && !more) {
|
|
809
|
+
this._auto = false;
|
|
810
|
+
this.dispatchEvent(new CustomEvent("settled"));
|
|
811
|
+
}
|
|
812
|
+
if (this._anim) {
|
|
813
|
+
const a = this._anim, v = this._v;
|
|
814
|
+
v.k += (a.k - v.k) * .2;
|
|
815
|
+
v.x += (a.x - v.x) * .2;
|
|
816
|
+
v.y += (a.y - v.y) * .2;
|
|
817
|
+
this._dirty = true;
|
|
818
|
+
if (Math.abs(a.k - v.k) < a.k * .001 && Math.abs(a.x - v.x) < .5 && Math.abs(a.y - v.y) < .5) {
|
|
819
|
+
Object.assign(v, a);
|
|
820
|
+
this._anim = null;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
if (this._dirty) {
|
|
824
|
+
this._dirty = false;
|
|
825
|
+
this._draw();
|
|
826
|
+
}
|
|
827
|
+
const now = performance.now();
|
|
828
|
+
if (now - this._ht > 150 || !more) {
|
|
829
|
+
this._ht = now;
|
|
830
|
+
const s = `${L.n.toLocaleString()} nodes · ${L.ls.length.toLocaleString()} links`;
|
|
831
|
+
if (s !== this._st) this._stat.textContent = this._st = s;
|
|
832
|
+
this._bar.style.width = (more ? Math.min(1, L.alpha) * 100 : 0) + "%";
|
|
833
|
+
}
|
|
834
|
+
if (more || this._anim) this._wake();
|
|
835
|
+
}
|
|
836
|
+
_draw() {
|
|
837
|
+
const L = this._L, c = this._cv, g = this._g2, d = this._dpr, v = this._v, W = this._w, H = this._h;
|
|
838
|
+
g.setTransform(1, 0, 0, 1, 0, 0);
|
|
839
|
+
g.clearRect(0, 0, c.width, c.height);
|
|
840
|
+
if (!L.n) return;
|
|
841
|
+
if (performance.now() - this._tt > 1e3) this._theme();
|
|
842
|
+
const { x, y, r, ls, lt } = L, k = v.k, inv = 1 / k, E = ls.length, sel = this._sel, bend = this._bend;
|
|
843
|
+
const x0 = -v.x * inv, y0 = -v.y * inv, x1 = (W - v.x) * inv, y1 = (H - v.y) * inv;
|
|
844
|
+
g.setTransform(d * k, 0, 0, d * k, d * v.x, d * v.y);
|
|
845
|
+
g.lineCap = "round";
|
|
846
|
+
const addEdge = (e, ap) => {
|
|
847
|
+
const s = ls[e], t = lt[e], sx = x[s], sy = y[s], tx = x[t], ty = y[t];
|
|
848
|
+
if (sx < x0 && tx < x0 || sx > x1 && tx > x1 || sy < y0 && ty < y0 || sy > y1 && ty > y1) return;
|
|
849
|
+
const dx = tx - sx, dy = ty - sy, len = Math.sqrt(dx * dx + dy * dy) || 1e-6, ux = dx / len, uy = dy / len;
|
|
850
|
+
const ax = sx + ux * r[s], ay = sy + uy * r[s], bx = tx - ux * (r[t] + 1), by = ty - uy * (r[t] + 1), b = bend[e];
|
|
851
|
+
g.moveTo(ax, ay);
|
|
852
|
+
if (b) g.quadraticCurveTo((ax + bx) / 2 - uy * b * 2, (ay + by) / 2 + ux * b * 2, bx, by);
|
|
853
|
+
else g.lineTo(bx, by);
|
|
854
|
+
if (ap && len * k > 18) {
|
|
855
|
+
const z = 6 * inv, ex = bx - ux * z, ey = by - uy * z;
|
|
856
|
+
ap.moveTo(bx, by);
|
|
857
|
+
ap.lineTo(ex - uy * z * .45, ey + ux * z * .45);
|
|
858
|
+
ap.lineTo(ex + uy * z * .45, ey - ux * z * .45);
|
|
859
|
+
ap.closePath();
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
const arrows = k > .45 && E < 4e4, base = (E > 1e5 ? .2 : E > 2e4 ? .3 : E > 3e3 ? .45 : .65) * (sel >= 0 ? .25 : 1);
|
|
863
|
+
g.lineWidth = (E > 5e4 ? .7 : 1) * inv;
|
|
864
|
+
for (let p = 0; p < this._pc.length; p++) {
|
|
865
|
+
const ap = arrows ? new Path2D() : null;
|
|
866
|
+
g.beginPath();
|
|
867
|
+
for (let a = this._pOff[p]; a < this._pOff[p + 1]; a++) addEdge(this._pList[a], ap);
|
|
868
|
+
g.globalAlpha = base;
|
|
869
|
+
g.strokeStyle = this._pc[p];
|
|
870
|
+
g.stroke();
|
|
871
|
+
if (ap) {
|
|
872
|
+
g.globalAlpha = Math.min(1, base * 1.5);
|
|
873
|
+
g.fillStyle = this._pc[p];
|
|
874
|
+
g.fill(ap);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
const ring = k > .65 && (L.n < 3e4 || k > 2);
|
|
878
|
+
g.lineWidth = 1.4 * inv;
|
|
879
|
+
g.globalAlpha = sel >= 0 ? .28 : 1;
|
|
880
|
+
for (let cl = 0; cl < this._fill.length; cl++) {
|
|
881
|
+
g.beginPath();
|
|
882
|
+
for (let a = this._cOff[cl]; a < this._cOff[cl + 1]; a++) {
|
|
883
|
+
const i = this._cList[a], px = x[i], py = y[i], ri = r[i];
|
|
884
|
+
if (px + ri < x0 || px - ri > x1 || py + ri < y0 || py - ri > y1) continue;
|
|
885
|
+
if (ri * k < 1) {
|
|
886
|
+
const h = .9 * inv;
|
|
887
|
+
g.rect(px - h, py - h, 2 * h, 2 * h);
|
|
888
|
+
} else {
|
|
889
|
+
g.moveTo(px + ri, py);
|
|
890
|
+
g.arc(px, py, ri, 0, TAU);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
g.fillStyle = this._fill[cl];
|
|
894
|
+
g.fill();
|
|
895
|
+
if (ring) {
|
|
896
|
+
g.strokeStyle = this._ring[cl];
|
|
897
|
+
g.stroke();
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
g.globalAlpha = 1;
|
|
901
|
+
const dot = (i, strong) => {
|
|
902
|
+
const cl = this._typ[i];
|
|
903
|
+
g.beginPath();
|
|
904
|
+
g.arc(x[i], y[i], r[i], 0, TAU);
|
|
905
|
+
g.fillStyle = this._fill[cl];
|
|
906
|
+
g.fill();
|
|
907
|
+
g.lineWidth = (strong ? 2.5 : 1.4) * inv;
|
|
908
|
+
g.strokeStyle = strong ? this._fg : this._ring[cl];
|
|
909
|
+
g.stroke();
|
|
910
|
+
};
|
|
911
|
+
if (sel >= 0) {
|
|
912
|
+
g.lineWidth = 1.6 * inv;
|
|
913
|
+
g.globalAlpha = .9;
|
|
914
|
+
for (const e of this._el) {
|
|
915
|
+
const ap = new Path2D(), col = this._pc[this._lp[e]];
|
|
916
|
+
g.beginPath();
|
|
917
|
+
addEdge(e, ap);
|
|
918
|
+
g.strokeStyle = g.fillStyle = col;
|
|
919
|
+
g.stroke();
|
|
920
|
+
g.fill(ap);
|
|
921
|
+
}
|
|
922
|
+
g.globalAlpha = 1;
|
|
923
|
+
for (const i of this._nl) dot(i, false);
|
|
924
|
+
dot(sel, true);
|
|
925
|
+
}
|
|
926
|
+
if (this._hov >= 0 && this._hov !== sel) dot(this._hov, true);
|
|
927
|
+
g.lineWidth = 1.2 * inv;
|
|
928
|
+
g.strokeStyle = this._fg;
|
|
929
|
+
g.setLineDash([3 * inv, 3 * inv]);
|
|
930
|
+
for (let i = 0; i < L.n; i++) if (L.pin[i] & 1) {
|
|
931
|
+
g.beginPath();
|
|
932
|
+
g.arc(x[i], y[i], r[i] + 3 * inv, 0, TAU);
|
|
933
|
+
g.stroke();
|
|
934
|
+
}
|
|
935
|
+
g.setLineDash([]);
|
|
936
|
+
if (this.getAttribute("labels") !== "off") this._drawLabels(g, d);
|
|
937
|
+
g.globalAlpha = 1;
|
|
938
|
+
}
|
|
939
|
+
_drawLabels(g, d) {
|
|
940
|
+
const L = this._L, { x, y, r, ls, lt } = L, v = this._v, k = v.k, W = this._w, H = this._h, sel = this._sel, oc = this._occ, cols = this._oc, C = 12;
|
|
941
|
+
g.setTransform(d, 0, 0, d, 0, 0);
|
|
942
|
+
oc.fill(0);
|
|
943
|
+
g.font = "11px system-ui,sans-serif";
|
|
944
|
+
g.textAlign = "center";
|
|
945
|
+
g.textBaseline = "middle";
|
|
946
|
+
g.lineJoin = "round";
|
|
947
|
+
g.lineWidth = 1.5;
|
|
948
|
+
const reserve = (cx, cy, w, h, force) => {
|
|
949
|
+
const a = Math.max(0, (cx - w / 2) / C | 0), b = Math.max(0, (cy - h / 2) / C | 0), a2 = Math.min(cols - 1, (cx + w / 2) / C | 0), b2 = Math.min(this._or - 1, (cy + h / 2) / C | 0);
|
|
950
|
+
if (!force) {
|
|
951
|
+
for (let j = b; j <= b2; j++) for (let i = a; i <= a2; i++) if (oc[j * cols + i]) return false;
|
|
952
|
+
}
|
|
953
|
+
for (let j = b; j <= b2; j++) for (let i = a; i <= a2; i++) oc[j * cols + i] = 1;
|
|
954
|
+
return true;
|
|
955
|
+
};
|
|
956
|
+
const put = (i, force) => {
|
|
957
|
+
const sx = x[i] * k + v.x, sy = y[i] * k + v.y, rs = r[i] * k;
|
|
958
|
+
if (sx < -60 || sx > W + 60 || sy < -10 || sy > H + 30) return -1;
|
|
959
|
+
if (!force && rs < 2) return 0;
|
|
960
|
+
const t = this._label(i), w = t.length * 6.1 + 6, ty = sy - rs - 8;
|
|
961
|
+
if (!reserve(sx, ty, w, 14, force)) return 0;
|
|
962
|
+
g.globalAlpha = sel >= 0 && !force ? .35 : 1;
|
|
963
|
+
g.strokeStyle = this._halo;
|
|
964
|
+
g.strokeText(t, sx, ty);
|
|
965
|
+
g.fillStyle = this._fg;
|
|
966
|
+
g.fillText(t, sx, ty);
|
|
967
|
+
return 1;
|
|
968
|
+
};
|
|
969
|
+
if (sel >= 0) {
|
|
970
|
+
put(sel, true);
|
|
971
|
+
for (const i of this._nl) put(i, true);
|
|
972
|
+
}
|
|
973
|
+
if (this._hov >= 0) put(this._hov, true);
|
|
974
|
+
for (let a = 0, seen = 0, drawn = 0; a < L.n && drawn < 700 && seen < 6e3; a++) {
|
|
975
|
+
const s = put(this._order[a], false);
|
|
976
|
+
if (s >= 0) seen++;
|
|
977
|
+
if (s > 0) drawn++;
|
|
978
|
+
}
|
|
979
|
+
if (k < .5 || !ls.length) return;
|
|
980
|
+
g.font = "9px system-ui,sans-serif";
|
|
981
|
+
g.globalAlpha = .9;
|
|
982
|
+
g.lineWidth = 1;
|
|
983
|
+
for (let e = 0, cnt = 0; e < ls.length && cnt < 150; e++) {
|
|
984
|
+
const s = ls[e], t = lt[e], dx = (x[t] - x[s]) * k, dy = (y[t] - y[s]) * k, len = Math.sqrt(dx * dx + dy * dy);
|
|
985
|
+
if (len < 70) continue;
|
|
986
|
+
const b = this._bend[e] * k, mx = (x[s] + x[t]) / 2 * k + v.x - dy / len * b, my = (y[s] + y[t]) / 2 * k + v.y + dx / len * b;
|
|
987
|
+
if (mx < 0 || mx > W || my < 0 || my > H) continue;
|
|
988
|
+
const txt = this._plabel(this._lp[e]), tw = txt.length * 5.2;
|
|
989
|
+
if (len < tw + 30) continue;
|
|
990
|
+
const ca = Math.abs(dx / len), sa = Math.abs(dy / len);
|
|
991
|
+
if (!reserve(mx, my, tw * ca + 10 * sa, tw * sa + 10 * ca)) continue;
|
|
992
|
+
let ang = Math.atan2(dy, dx);
|
|
993
|
+
if (ang > Math.PI / 2 || ang < -Math.PI / 2) ang += Math.PI;
|
|
994
|
+
g.save();
|
|
995
|
+
g.translate(mx, my);
|
|
996
|
+
g.rotate(ang);
|
|
997
|
+
g.strokeStyle = this._halo;
|
|
998
|
+
g.strokeText(txt, 0, -5);
|
|
999
|
+
g.fillStyle = this._pc[this._lp[e]];
|
|
1000
|
+
g.fillText(txt, 0, -5);
|
|
1001
|
+
g.restore();
|
|
1002
|
+
cnt++;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
_pick(sx, sy) {
|
|
1006
|
+
const L = this._L, { x, y, r } = L, k = this._v.k, wx = (sx - this._v.x) / k, wy = (sy - this._v.y) / k, minR = 5 / k;
|
|
1007
|
+
let best = -1, bd = 1;
|
|
1008
|
+
for (let i = 0; i < L.n; i++) {
|
|
1009
|
+
const rr = r[i] > minR ? r[i] : minR, dx = x[i] - wx;
|
|
1010
|
+
if (dx > rr || dx < -rr) continue;
|
|
1011
|
+
const dy = y[i] - wy;
|
|
1012
|
+
if (dy > rr || dy < -rr) continue;
|
|
1013
|
+
const q = (dx * dx + dy * dy) / (rr * rr);
|
|
1014
|
+
if (q <= bd) {
|
|
1015
|
+
bd = q;
|
|
1016
|
+
best = i;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
return best;
|
|
1020
|
+
}
|
|
1021
|
+
_select(i) {
|
|
1022
|
+
if (i === this._sel) return;
|
|
1023
|
+
const L = this._L, off = this._off, adj = this._adj;
|
|
1024
|
+
this._sel = i;
|
|
1025
|
+
this._nl = [];
|
|
1026
|
+
this._el = [];
|
|
1027
|
+
if (i >= 0) {
|
|
1028
|
+
const s = /* @__PURE__ */ new Set();
|
|
1029
|
+
for (let a = off[i]; a < off[i + 1]; a++) {
|
|
1030
|
+
const e = adj[a];
|
|
1031
|
+
this._el.push(e);
|
|
1032
|
+
s.add(L.ls[e] === i ? L.lt[e] : L.ls[e]);
|
|
1033
|
+
}
|
|
1034
|
+
this._nl = [...s];
|
|
1035
|
+
}
|
|
1036
|
+
this.dispatchEvent(new CustomEvent("node-select", {
|
|
1037
|
+
detail: i >= 0 ? this._names[i] : null,
|
|
1038
|
+
bubbles: true
|
|
1039
|
+
}));
|
|
1040
|
+
this._dirty = true;
|
|
1041
|
+
this._wake();
|
|
1042
|
+
}
|
|
1043
|
+
_showTip(i, ex, ey) {
|
|
1044
|
+
const t = this._tip;
|
|
1045
|
+
if (i < 0) {
|
|
1046
|
+
t.style.display = "none";
|
|
1047
|
+
return;
|
|
1048
|
+
}
|
|
1049
|
+
if (t._i !== i) {
|
|
1050
|
+
t._i = i;
|
|
1051
|
+
t.replaceChildren();
|
|
1052
|
+
const add = (tag, txt) => {
|
|
1053
|
+
const e = document.createElement(tag);
|
|
1054
|
+
e.textContent = txt;
|
|
1055
|
+
t.append(e);
|
|
1056
|
+
};
|
|
1057
|
+
add("b", this._label(i));
|
|
1058
|
+
add("small", this._names[i]);
|
|
1059
|
+
const c = this._typ[i];
|
|
1060
|
+
if (c && this._classes[c] !== this._names[i]) add("small", "a " + this._curie(this._classes[c]));
|
|
1061
|
+
for (const [p, val] of this._lits.get(i) || []) add("div", this._curie(p) + ": " + (val.length > 80 ? val.slice(0, 80) + "…" : val));
|
|
1062
|
+
add("small", this._L.deg[i] + " links");
|
|
1063
|
+
}
|
|
1064
|
+
t.style.display = "block";
|
|
1065
|
+
const tw = t.offsetWidth, th = t.offsetHeight;
|
|
1066
|
+
t.style.transform = `translate(${ex + 14 + tw > this._w ? Math.max(0, ex - 14 - tw) : ex + 14}px,${Math.max(0, Math.min(ey + 14, this._h - th - 4))}px)`;
|
|
1067
|
+
}
|
|
1068
|
+
_xy(e) {
|
|
1069
|
+
const b = this._cv.getBoundingClientRect();
|
|
1070
|
+
return {
|
|
1071
|
+
x: e.clientX - b.left,
|
|
1072
|
+
y: e.clientY - b.top
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
_release() {
|
|
1076
|
+
const g = this._gs;
|
|
1077
|
+
if (g && g.i >= 0) {
|
|
1078
|
+
this._L.pin[g.i] &= 1;
|
|
1079
|
+
this._L.target = 0;
|
|
1080
|
+
}
|
|
1081
|
+
this._gs = null;
|
|
1082
|
+
}
|
|
1083
|
+
_bind() {
|
|
1084
|
+
const cv = this._cv, P = this._ptrs;
|
|
1085
|
+
cv.addEventListener("pointerdown", (e) => {
|
|
1086
|
+
cv.setPointerCapture(e.pointerId);
|
|
1087
|
+
const p = this._xy(e);
|
|
1088
|
+
P.set(e.pointerId, {
|
|
1089
|
+
x: p.x,
|
|
1090
|
+
y: p.y
|
|
1091
|
+
});
|
|
1092
|
+
this._auto = false;
|
|
1093
|
+
this._anim = null;
|
|
1094
|
+
if (P.size > 1) {
|
|
1095
|
+
this._release();
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
const i = this._pick(p.x, p.y);
|
|
1099
|
+
this._gs = {
|
|
1100
|
+
i,
|
|
1101
|
+
sx: p.x,
|
|
1102
|
+
sy: p.y,
|
|
1103
|
+
moved: false
|
|
1104
|
+
};
|
|
1105
|
+
if (i >= 0) {
|
|
1106
|
+
this._L.pin[i] |= 2;
|
|
1107
|
+
this._L.target = .3;
|
|
1108
|
+
this._L.reheat(.3);
|
|
1109
|
+
cv.style.cursor = "grabbing";
|
|
1110
|
+
this._showTip(-1);
|
|
1111
|
+
this._wake();
|
|
1112
|
+
} else cv.style.cursor = "grabbing";
|
|
1113
|
+
});
|
|
1114
|
+
cv.addEventListener("pointermove", (e) => {
|
|
1115
|
+
const p = this._xy(e), rec = P.get(e.pointerId), L = this._L, v = this._v;
|
|
1116
|
+
if (!rec) {
|
|
1117
|
+
this._mp = p;
|
|
1118
|
+
if (!this._hp) this._hp = requestAnimationFrame(() => {
|
|
1119
|
+
this._hp = 0;
|
|
1120
|
+
const q = this._mp, i = this._pick(q.x, q.y);
|
|
1121
|
+
if (i !== this._hov) {
|
|
1122
|
+
this._hov = i;
|
|
1123
|
+
cv.style.cursor = i >= 0 ? "pointer" : "grab";
|
|
1124
|
+
this._dirty = true;
|
|
1125
|
+
this._wake();
|
|
1126
|
+
this.dispatchEvent(new CustomEvent("node-hover", { detail: i >= 0 ? this._names[i] : null }));
|
|
1127
|
+
}
|
|
1128
|
+
this._showTip(i, q.x, q.y);
|
|
1129
|
+
});
|
|
1130
|
+
return;
|
|
1131
|
+
}
|
|
1132
|
+
if (P.size === 2) {
|
|
1133
|
+
rec.x = p.x;
|
|
1134
|
+
rec.y = p.y;
|
|
1135
|
+
const [a, b] = [...P.values()], dd = Math.hypot(a.x - b.x, a.y - b.y), cx = (a.x + b.x) / 2, cy = (a.y + b.y) / 2, pr = this._pinch;
|
|
1136
|
+
if (pr && pr.d) {
|
|
1137
|
+
this._zoomAt(cx, cy, dd / pr.d);
|
|
1138
|
+
v.x += cx - pr.cx;
|
|
1139
|
+
v.y += cy - pr.cy;
|
|
1140
|
+
}
|
|
1141
|
+
this._pinch = {
|
|
1142
|
+
d: dd,
|
|
1143
|
+
cx,
|
|
1144
|
+
cy
|
|
1145
|
+
};
|
|
1146
|
+
this._dirty = true;
|
|
1147
|
+
this._wake();
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
const gs = this._gs;
|
|
1151
|
+
if (!gs) return;
|
|
1152
|
+
if (Math.hypot(p.x - gs.sx, p.y - gs.sy) > 3) gs.moved = true;
|
|
1153
|
+
if (gs.i >= 0) {
|
|
1154
|
+
L.x[gs.i] = (p.x - v.x) / v.k;
|
|
1155
|
+
L.y[gs.i] = (p.y - v.y) / v.k;
|
|
1156
|
+
L.vx[gs.i] = L.vy[gs.i] = 0;
|
|
1157
|
+
} else if (gs.moved) {
|
|
1158
|
+
v.x += p.x - rec.x;
|
|
1159
|
+
v.y += p.y - rec.y;
|
|
1160
|
+
}
|
|
1161
|
+
rec.x = p.x;
|
|
1162
|
+
rec.y = p.y;
|
|
1163
|
+
this._dirty = true;
|
|
1164
|
+
this._wake();
|
|
1165
|
+
});
|
|
1166
|
+
const up = (e) => {
|
|
1167
|
+
if (!P.delete(e.pointerId)) return;
|
|
1168
|
+
this._pinch = null;
|
|
1169
|
+
const gs = this._gs;
|
|
1170
|
+
if (P.size === 0 && gs) {
|
|
1171
|
+
if (gs.i >= 0 && !gs.moved) {
|
|
1172
|
+
this._select(gs.i);
|
|
1173
|
+
this.dispatchEvent(new CustomEvent("node-click", {
|
|
1174
|
+
detail: this._names[gs.i],
|
|
1175
|
+
bubbles: true
|
|
1176
|
+
}));
|
|
1177
|
+
} else if (gs.i < 0 && !gs.moved) this._select(-1);
|
|
1178
|
+
this._release();
|
|
1179
|
+
cv.style.cursor = this._hov >= 0 ? "pointer" : "grab";
|
|
1180
|
+
this._wake();
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
cv.addEventListener("pointerup", up);
|
|
1184
|
+
cv.addEventListener("pointercancel", up);
|
|
1185
|
+
cv.addEventListener("pointerleave", () => {
|
|
1186
|
+
if (this._hov >= 0 && !P.size) {
|
|
1187
|
+
this._hov = -1;
|
|
1188
|
+
this._dirty = true;
|
|
1189
|
+
this._wake();
|
|
1190
|
+
}
|
|
1191
|
+
this._showTip(-1);
|
|
1192
|
+
});
|
|
1193
|
+
cv.addEventListener("dblclick", (e) => {
|
|
1194
|
+
const p = this._xy(e), i = this._pick(p.x, p.y);
|
|
1195
|
+
if (i >= 0) {
|
|
1196
|
+
this._L.pin[i] ^= 1;
|
|
1197
|
+
this._L.reheat(.2);
|
|
1198
|
+
this._dirty = true;
|
|
1199
|
+
this._wake();
|
|
1200
|
+
} else this.fit();
|
|
1201
|
+
});
|
|
1202
|
+
cv.addEventListener("wheel", (e) => {
|
|
1203
|
+
e.preventDefault();
|
|
1204
|
+
this._auto = false;
|
|
1205
|
+
this._anim = null;
|
|
1206
|
+
const p = this._xy(e);
|
|
1207
|
+
this._zoomAt(p.x, p.y, Math.exp(-e.deltaY * (e.ctrlKey ? .01 : .0015) * (e.deltaMode === 1 ? 16 : 1)));
|
|
1208
|
+
}, { passive: false });
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
_defineProperty(QuadGraph, "observedAttributes", [
|
|
1212
|
+
"height",
|
|
1213
|
+
"charge",
|
|
1214
|
+
"link-dist",
|
|
1215
|
+
"labels"
|
|
1216
|
+
]);
|
|
1217
|
+
if (typeof customElements !== "undefined" && !customElements.get("quad-graph")) customElements.define("quad-graph", QuadGraph);
|
|
1218
|
+
//#endregion
|
|
1219
|
+
export { Layout, QuadGraph, QuadGraph as default };
|