@dxos/react-ui-graph 0.8.4-main.406dc2a → 0.8.4-main.52d7546f51
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/lib/browser/chunk-LKC455GK.mjs +52 -0
- package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1113 -335
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -3
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-JE4KZCUF.mjs +54 -0
- package/dist/lib/node-esm/chunk-JE4KZCUF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1113 -335
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +3 -3
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/components/Graph/Graph.d.ts +4 -5
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +14 -17
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +1 -1
- package/dist/types/src/graph/types.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts +3 -2
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +4 -4
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts +2 -16
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/testing/model.d.ts +4 -8
- package/dist/types/src/testing/model.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -26
- package/src/components/Graph/Graph.stories.tsx +33 -29
- package/src/components/Graph/Graph.tsx +17 -10
- package/src/components/Mesh/Mesh.stories.tsx +1 -1
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Root.tsx +1 -1
- package/src/components/SVG/SVG.tsx +10 -1
- package/src/components/SVG/Svg.stories.tsx +1 -1
- package/src/fx/fx.stories.tsx +1 -1
- package/src/graph/projector/graph-force-projector.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +3 -3
- package/src/graph/projector/graph-projector.ts +2 -2
- package/src/graph/projector/graph-radial-projector.ts +1 -1
- package/src/graph/projector/graph-relational-projector.ts +3 -3
- package/src/graph/types.ts +1 -1
- package/src/stories/hooks.stories.tsx +12 -6
- package/src/testing/data.ts +5 -5
- package/src/testing/hooks.ts +1 -1
- package/src/testing/model.ts +3 -3
- package/dist/lib/browser/chunk-EX2Q43O6.mjs +0 -966
- package/dist/lib/browser/chunk-EX2Q43O6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SWA6OT3W.mjs +0 -968
- package/dist/lib/node-esm/chunk-SWA6OT3W.mjs.map +0 -7
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
EventEmitter,
|
|
4
|
-
FractionUtil,
|
|
5
|
-
GridController,
|
|
6
|
-
SVGContext,
|
|
7
|
-
SVGContextProvider,
|
|
8
|
-
Scale,
|
|
9
|
-
Screen,
|
|
10
|
-
Vector,
|
|
11
|
-
ZoomHandler,
|
|
12
|
-
getCircumferencePoints,
|
|
13
|
-
normal,
|
|
14
|
-
offsetPoints,
|
|
15
3
|
useDynamicRef,
|
|
16
|
-
useGrid,
|
|
17
4
|
useStateRef,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
useZoom
|
|
21
|
-
} from "./chunk-SWA6OT3W.mjs";
|
|
5
|
+
useTimestamp
|
|
6
|
+
} from "./chunk-JE4KZCUF.mjs";
|
|
22
7
|
|
|
23
8
|
// src/components/Graph/Graph.tsx
|
|
24
|
-
import {
|
|
25
|
-
import { effect } from "@preact/signals-core";
|
|
26
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
9
|
+
import React, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo3, useRef as useRef3 } from "react";
|
|
27
10
|
import { combine } from "@dxos/async";
|
|
28
11
|
import { log as log6 } from "@dxos/log";
|
|
29
|
-
import { mx } from "@dxos/
|
|
12
|
+
import { mx } from "@dxos/ui-theme";
|
|
30
13
|
|
|
31
14
|
// src/graph/markers.ts
|
|
32
15
|
import { line, select } from "d3";
|
|
@@ -179,21 +162,589 @@ var emptyGraph = {
|
|
|
179
162
|
edges: []
|
|
180
163
|
};
|
|
181
164
|
|
|
182
|
-
// src/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
165
|
+
// src/util/events.ts
|
|
166
|
+
var EventEmitter = class {
|
|
167
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
168
|
+
clear() {
|
|
169
|
+
this._listeners.clear();
|
|
170
|
+
}
|
|
171
|
+
on(onEvent) {
|
|
172
|
+
this._listeners.add(onEvent);
|
|
173
|
+
return () => this._listeners.delete(onEvent);
|
|
174
|
+
}
|
|
175
|
+
emit(value) {
|
|
176
|
+
this._listeners.forEach((listener) => listener(value));
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// src/util/fraction.ts
|
|
181
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
182
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
|
|
183
|
+
var FractionUtil = class _FractionUtil {
|
|
184
|
+
/**
|
|
185
|
+
* Convert number to fraction.
|
|
186
|
+
* @param n
|
|
187
|
+
*/
|
|
188
|
+
static toFraction = (n) => {
|
|
189
|
+
return typeof n === "number" ? [
|
|
190
|
+
n,
|
|
191
|
+
1
|
|
192
|
+
] : n;
|
|
193
|
+
};
|
|
194
|
+
static validate = (...fraction) => {
|
|
195
|
+
fraction.forEach(([n, d]) => {
|
|
196
|
+
if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
|
|
197
|
+
throw new Error(`Invalid fraction: ${n}/${d}`);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
return fraction;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* @param {Fraction}
|
|
204
|
+
* Convert to rounded number.
|
|
205
|
+
*/
|
|
206
|
+
static toNumber = ([n, d]) => {
|
|
207
|
+
_FractionUtil.validate([
|
|
208
|
+
n,
|
|
209
|
+
d
|
|
210
|
+
]);
|
|
211
|
+
return n / d;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Round the number to the nearest fraction.
|
|
215
|
+
* Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
|
|
216
|
+
* @param {Fraction}
|
|
217
|
+
* @param p Precision (e.g., 1/2, 1/4, etc.)
|
|
218
|
+
*/
|
|
219
|
+
static round = ([n, d], p = 1) => {
|
|
220
|
+
_FractionUtil.validate([
|
|
221
|
+
n,
|
|
222
|
+
d
|
|
223
|
+
]);
|
|
224
|
+
const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
|
|
225
|
+
n,
|
|
226
|
+
d
|
|
227
|
+
], [
|
|
228
|
+
1,
|
|
229
|
+
p
|
|
230
|
+
])));
|
|
231
|
+
return _FractionUtil.simplify([
|
|
232
|
+
v,
|
|
233
|
+
p
|
|
234
|
+
]);
|
|
235
|
+
};
|
|
236
|
+
//
|
|
237
|
+
// Boolean.
|
|
238
|
+
//
|
|
239
|
+
/**
|
|
240
|
+
* Tests if equals.
|
|
241
|
+
* @param n1
|
|
242
|
+
* @param n2
|
|
243
|
+
*/
|
|
244
|
+
static equals = (n1, n2) => {
|
|
245
|
+
return n1[0] * n2[1] === n1[1] * n2[0];
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* @param {Fraction}
|
|
249
|
+
* True if zero.
|
|
250
|
+
*/
|
|
251
|
+
static isZero = ([n]) => {
|
|
252
|
+
return n === 0;
|
|
253
|
+
};
|
|
254
|
+
//
|
|
255
|
+
// Normalization.
|
|
256
|
+
//
|
|
257
|
+
/**
|
|
258
|
+
* Simplify fraction finding LCDs.
|
|
259
|
+
* @param n
|
|
260
|
+
* @param d
|
|
261
|
+
*/
|
|
262
|
+
static simplify = ([n, d]) => {
|
|
263
|
+
_FractionUtil.validate([
|
|
264
|
+
n,
|
|
265
|
+
d
|
|
266
|
+
]);
|
|
267
|
+
if (d < 1) {
|
|
268
|
+
const t = n / d;
|
|
269
|
+
if (Math.floor(t) === t) {
|
|
270
|
+
n = t;
|
|
271
|
+
d = 1;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const fn = _FractionUtil.factors(n).reverse();
|
|
275
|
+
const fd = _FractionUtil.factors(d).reverse();
|
|
276
|
+
let c;
|
|
277
|
+
for (let i = 0; i < fn.length; i++) {
|
|
278
|
+
c = fd.find((n2) => n2 === fn[i]);
|
|
279
|
+
if (c) {
|
|
280
|
+
return [
|
|
281
|
+
n / c,
|
|
282
|
+
d / c
|
|
283
|
+
];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return [
|
|
287
|
+
n,
|
|
288
|
+
d
|
|
289
|
+
];
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Return common factors.
|
|
293
|
+
* @param n
|
|
294
|
+
*/
|
|
295
|
+
static factors = (n) => {
|
|
296
|
+
invariant2(Number.isFinite(n), `Invalid number: ${n}`, {
|
|
297
|
+
F: __dxlog_file2,
|
|
298
|
+
L: 113,
|
|
299
|
+
S: this,
|
|
300
|
+
A: [
|
|
301
|
+
"Number.isFinite(n)",
|
|
302
|
+
"`Invalid number: ${n}`"
|
|
303
|
+
]
|
|
190
304
|
});
|
|
191
|
-
|
|
192
|
-
|
|
305
|
+
const factors = [
|
|
306
|
+
1
|
|
307
|
+
];
|
|
308
|
+
if (Number.isSafeInteger(n)) {
|
|
309
|
+
let f = 1;
|
|
310
|
+
do {
|
|
311
|
+
if (n % ++f === 0) {
|
|
312
|
+
factors.push(f);
|
|
313
|
+
}
|
|
314
|
+
} while (n / f > 1 && f < 100);
|
|
315
|
+
}
|
|
316
|
+
return factors;
|
|
317
|
+
};
|
|
318
|
+
//
|
|
319
|
+
// Basic arithmetic.
|
|
320
|
+
//
|
|
321
|
+
/**
|
|
322
|
+
* @param n1
|
|
323
|
+
* @param n2
|
|
324
|
+
*/
|
|
325
|
+
static add = (n1, n2) => {
|
|
326
|
+
_FractionUtil.validate(n1, n2);
|
|
327
|
+
const d = n1[1] * n2[1];
|
|
328
|
+
const n = n1[0] * n2[1] + n2[0] * n1[1];
|
|
329
|
+
return _FractionUtil.simplify([
|
|
330
|
+
n,
|
|
331
|
+
d
|
|
332
|
+
]);
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* @param n1
|
|
336
|
+
* @param n2
|
|
337
|
+
*/
|
|
338
|
+
static subtract = (n1, n2) => {
|
|
339
|
+
_FractionUtil.validate(n1, n2);
|
|
340
|
+
const d = n1[1] * n2[1];
|
|
341
|
+
const n = n1[0] * n2[1] - n2[0] * n1[1];
|
|
342
|
+
return _FractionUtil.simplify([
|
|
343
|
+
n,
|
|
344
|
+
d
|
|
345
|
+
]);
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* @param n1
|
|
349
|
+
* @param n2
|
|
350
|
+
*/
|
|
351
|
+
static multiply = (n1, n2) => {
|
|
352
|
+
_FractionUtil.validate(n1, n2);
|
|
353
|
+
const n = n1[0] * n2[0];
|
|
354
|
+
const d = n1[1] * n2[1];
|
|
355
|
+
return _FractionUtil.simplify([
|
|
356
|
+
n,
|
|
357
|
+
d
|
|
358
|
+
]);
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* @param n1
|
|
362
|
+
* @param n2
|
|
363
|
+
*/
|
|
364
|
+
static divide = (n1, n2) => {
|
|
365
|
+
_FractionUtil.validate(n1, n2);
|
|
366
|
+
const n = n1[0] * n2[1];
|
|
367
|
+
const d = n1[1] * n2[0];
|
|
368
|
+
return _FractionUtil.simplify([
|
|
369
|
+
n,
|
|
370
|
+
d
|
|
371
|
+
]);
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// src/util/points.ts
|
|
376
|
+
var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
|
|
377
|
+
const [x1, y1] = p1;
|
|
378
|
+
const [x2, y2] = p2;
|
|
379
|
+
const theta = Math.atan2(x2 - x1, y2 - y1);
|
|
380
|
+
return [
|
|
381
|
+
[
|
|
382
|
+
// p1
|
|
383
|
+
x1 + (r1 === 0 ? 0 : r1 * Math.sin(theta)),
|
|
384
|
+
y1 + (r1 === 0 ? 0 : r1 * Math.cos(theta))
|
|
385
|
+
],
|
|
386
|
+
[
|
|
387
|
+
// p2
|
|
388
|
+
x2 - (r2 === 0 ? 0 : r2 * Math.cos(Math.PI / 2 - theta)),
|
|
389
|
+
y2 - (r2 === 0 ? 0 : r2 * Math.sin(Math.PI / 2 - theta))
|
|
390
|
+
]
|
|
391
|
+
];
|
|
392
|
+
};
|
|
393
|
+
var normal = (p1, p2) => {
|
|
394
|
+
const dx = p2[0] - p1[0];
|
|
395
|
+
const dy = p2[1] - p1[1];
|
|
396
|
+
const len = Math.hypot(dx, dy);
|
|
397
|
+
return [
|
|
398
|
+
dy / len,
|
|
399
|
+
-dx / len
|
|
400
|
+
];
|
|
401
|
+
};
|
|
402
|
+
var offsetPoints = (points, distance, closed) => {
|
|
403
|
+
const len = points.length;
|
|
404
|
+
const out = [];
|
|
405
|
+
for (let i = 0; i < len; i++) {
|
|
406
|
+
const p0 = points[(i - 1 + len) % len];
|
|
407
|
+
const p1 = points[i];
|
|
408
|
+
const p2 = points[(i + 1) % len];
|
|
409
|
+
const n1 = normal(p0, p1);
|
|
410
|
+
const n2 = normal(p1, p2);
|
|
411
|
+
const nx = (n1[0] + n2[0]) / 2;
|
|
412
|
+
const ny = (n1[1] + n2[1]) / 2;
|
|
413
|
+
const norm = Math.hypot(nx, ny) || 1;
|
|
414
|
+
out.push([
|
|
415
|
+
p1[0] + distance * nx / norm,
|
|
416
|
+
p1[1] + distance * ny / norm
|
|
417
|
+
]);
|
|
418
|
+
if (!closed && (i === 0 || i === len - 1)) {
|
|
419
|
+
out[i] = [
|
|
420
|
+
p1[0] + distance * normal(p0, p1)[0],
|
|
421
|
+
p1[1] + distance * normal(p0, p1)[1]
|
|
422
|
+
];
|
|
423
|
+
}
|
|
193
424
|
}
|
|
194
|
-
return
|
|
195
|
-
}
|
|
425
|
+
return out;
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
// src/util/scale.ts
|
|
429
|
+
import { zoomIdentity } from "d3";
|
|
430
|
+
var Scale = class {
|
|
431
|
+
_gridSize;
|
|
432
|
+
_transform;
|
|
433
|
+
constructor(_gridSize = 32) {
|
|
434
|
+
this._gridSize = _gridSize;
|
|
435
|
+
}
|
|
436
|
+
get gridSize() {
|
|
437
|
+
return this._gridSize;
|
|
438
|
+
}
|
|
439
|
+
get transform() {
|
|
440
|
+
return this._transform || zoomIdentity;
|
|
441
|
+
}
|
|
442
|
+
setTransform(transform) {
|
|
443
|
+
if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
this._transform = transform;
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Translate a screen point to a logical point.
|
|
451
|
+
* @param point
|
|
452
|
+
*/
|
|
453
|
+
translate(point) {
|
|
454
|
+
const { x, y, k } = this._transform ?? {
|
|
455
|
+
x: 0,
|
|
456
|
+
y: 0,
|
|
457
|
+
k: 1
|
|
458
|
+
};
|
|
459
|
+
return [
|
|
460
|
+
(point[0] - x) / k,
|
|
461
|
+
(point[1] - y) / k
|
|
462
|
+
];
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Map model to screen.
|
|
466
|
+
* Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
|
|
467
|
+
*/
|
|
468
|
+
model = {
|
|
469
|
+
// TODO(burdon): Precision depends on scale.
|
|
470
|
+
snapValues: (array) => array.map((n) => FractionUtil.round(n)),
|
|
471
|
+
snapVertex: ({ x, y }) => {
|
|
472
|
+
const [sx, sy] = this.model.snapValues([
|
|
473
|
+
x,
|
|
474
|
+
y
|
|
475
|
+
]);
|
|
476
|
+
return {
|
|
477
|
+
x: sx,
|
|
478
|
+
y: sy
|
|
479
|
+
};
|
|
480
|
+
},
|
|
481
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
482
|
+
[x, y, width, height] = this.model.snapValues([
|
|
483
|
+
x,
|
|
484
|
+
y,
|
|
485
|
+
width,
|
|
486
|
+
height
|
|
487
|
+
]);
|
|
488
|
+
return {
|
|
489
|
+
x,
|
|
490
|
+
y,
|
|
491
|
+
width,
|
|
492
|
+
height
|
|
493
|
+
};
|
|
494
|
+
},
|
|
495
|
+
toValue: (value) => {
|
|
496
|
+
return Math.round(FractionUtil.toNumber(value) * this._gridSize);
|
|
497
|
+
},
|
|
498
|
+
toValues: (values) => {
|
|
499
|
+
return values.map((value) => Math.round(FractionUtil.toNumber(value) * this._gridSize));
|
|
500
|
+
},
|
|
501
|
+
toPoint: (point) => {
|
|
502
|
+
const [x, y] = this.model.toValues([
|
|
503
|
+
point.x,
|
|
504
|
+
point.y
|
|
505
|
+
]);
|
|
506
|
+
return [
|
|
507
|
+
x,
|
|
508
|
+
y === 0 ? 0 : -y
|
|
509
|
+
];
|
|
510
|
+
},
|
|
511
|
+
toBounds: ({ x, y, width, height }) => {
|
|
512
|
+
const point = this.model.toPoint({
|
|
513
|
+
x,
|
|
514
|
+
y
|
|
515
|
+
});
|
|
516
|
+
const [width2, height2] = this.model.toValues([
|
|
517
|
+
width,
|
|
518
|
+
height
|
|
519
|
+
]);
|
|
520
|
+
return {
|
|
521
|
+
x: point[0],
|
|
522
|
+
y: point[1] - height2,
|
|
523
|
+
width: width2,
|
|
524
|
+
height: height2
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* Map screen to model.
|
|
530
|
+
* Screen points are represented by floating numbers and use translated SVG coordinates (with the y-axis inverted).
|
|
531
|
+
*/
|
|
532
|
+
screen = {
|
|
533
|
+
snapValues: (array) => array.map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
534
|
+
snapPoint: ([x, y]) => [
|
|
535
|
+
x,
|
|
536
|
+
y
|
|
537
|
+
].map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
538
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
539
|
+
[x, y, width, height] = this.screen.snapValues([
|
|
540
|
+
x,
|
|
541
|
+
y,
|
|
542
|
+
width,
|
|
543
|
+
height
|
|
544
|
+
]);
|
|
545
|
+
return {
|
|
546
|
+
x,
|
|
547
|
+
y,
|
|
548
|
+
width,
|
|
549
|
+
height
|
|
550
|
+
};
|
|
551
|
+
},
|
|
552
|
+
toValue: (value) => {
|
|
553
|
+
return FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
554
|
+
this._gridSize,
|
|
555
|
+
1
|
|
556
|
+
]);
|
|
557
|
+
},
|
|
558
|
+
toValues: (values) => {
|
|
559
|
+
return values.map((value) => FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
560
|
+
this._gridSize,
|
|
561
|
+
1
|
|
562
|
+
]));
|
|
563
|
+
},
|
|
564
|
+
toVertex: (point) => {
|
|
565
|
+
const [x, y] = point;
|
|
566
|
+
return {
|
|
567
|
+
x: FractionUtil.toFraction(x / this._gridSize),
|
|
568
|
+
y: FractionUtil.toFraction(-y / this._gridSize)
|
|
569
|
+
};
|
|
570
|
+
},
|
|
571
|
+
toBounds: (bounds) => {
|
|
572
|
+
const { x, y } = this.screen.toVertex([
|
|
573
|
+
bounds.x,
|
|
574
|
+
bounds.y
|
|
575
|
+
]);
|
|
576
|
+
const [width, height] = this.screen.toValues([
|
|
577
|
+
bounds.width,
|
|
578
|
+
bounds.height
|
|
579
|
+
]);
|
|
580
|
+
return {
|
|
581
|
+
x,
|
|
582
|
+
y: FractionUtil.subtract(y, height),
|
|
583
|
+
width,
|
|
584
|
+
height
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
// src/util/screen.ts
|
|
591
|
+
var Screen = class {
|
|
592
|
+
static createBounds = ([x1, y1], [x2, y2], mod = {}) => {
|
|
593
|
+
const { constrain, center } = mod;
|
|
594
|
+
const x = Math.min(x1, x2);
|
|
595
|
+
const y = Math.min(y1, y2);
|
|
596
|
+
let width = Math.abs(x2 - x1);
|
|
597
|
+
let height = Math.abs(y2 - y1);
|
|
598
|
+
if (constrain) {
|
|
599
|
+
width = height = Math.max(width, height);
|
|
600
|
+
}
|
|
601
|
+
if (center) {
|
|
602
|
+
return {
|
|
603
|
+
x: x - width,
|
|
604
|
+
y: y - height,
|
|
605
|
+
width: width * 2,
|
|
606
|
+
height: height * 2
|
|
607
|
+
};
|
|
608
|
+
} else {
|
|
609
|
+
return {
|
|
610
|
+
x,
|
|
611
|
+
y,
|
|
612
|
+
width,
|
|
613
|
+
height
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
static center = ({ x, y, width, height }) => {
|
|
618
|
+
return [
|
|
619
|
+
x + width / 2,
|
|
620
|
+
y + height / 2
|
|
621
|
+
];
|
|
622
|
+
};
|
|
623
|
+
static contains = (bounds, point) => {
|
|
624
|
+
const [x, y] = point;
|
|
625
|
+
if (x < bounds.x || y < bounds.y) {
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
|
|
629
|
+
return false;
|
|
630
|
+
}
|
|
631
|
+
return true;
|
|
632
|
+
};
|
|
633
|
+
/**
|
|
634
|
+
* Distance between two points.
|
|
635
|
+
* @param p1
|
|
636
|
+
* @param p2
|
|
637
|
+
*/
|
|
638
|
+
static len = (p1, p2) => {
|
|
639
|
+
return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
|
|
640
|
+
};
|
|
641
|
+
/**
|
|
642
|
+
* Distance to line segment.
|
|
643
|
+
* https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
|
|
644
|
+
* @param v1
|
|
645
|
+
* @param v2
|
|
646
|
+
* @param p
|
|
647
|
+
*/
|
|
648
|
+
static normal = (v1, v2, p) => {
|
|
649
|
+
const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
|
|
650
|
+
let d;
|
|
651
|
+
const len2 = d2(v1, v2);
|
|
652
|
+
if (len2 === 0) {
|
|
653
|
+
d = d2(p, v1);
|
|
654
|
+
} else {
|
|
655
|
+
let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
|
|
656
|
+
t = Math.max(0, Math.min(1, t));
|
|
657
|
+
d = d2(p, [
|
|
658
|
+
v1[0] + t * (v2[0] - v1[0]),
|
|
659
|
+
v1[1] + t * (v2[1] - v1[1])
|
|
660
|
+
]);
|
|
661
|
+
}
|
|
662
|
+
return Math.sqrt(d);
|
|
663
|
+
};
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
// src/util/vector.ts
|
|
667
|
+
var Vector = class {
|
|
668
|
+
/**
|
|
669
|
+
* Convert to Vertex.
|
|
670
|
+
* @param x
|
|
671
|
+
* @param y
|
|
672
|
+
*/
|
|
673
|
+
static toVertex = ({ x, y }) => ({
|
|
674
|
+
x: FractionUtil.toFraction(x),
|
|
675
|
+
y: FractionUtil.toFraction(y)
|
|
676
|
+
});
|
|
677
|
+
/**
|
|
678
|
+
* Convert to Bounds.
|
|
679
|
+
* @param bounds
|
|
680
|
+
*/
|
|
681
|
+
static toBounds = ({ x, y, width, height }) => ({
|
|
682
|
+
x: FractionUtil.toFraction(x),
|
|
683
|
+
y: FractionUtil.toFraction(y),
|
|
684
|
+
width: FractionUtil.toFraction(width),
|
|
685
|
+
height: FractionUtil.toFraction(height)
|
|
686
|
+
});
|
|
687
|
+
/**
|
|
688
|
+
* Calculate center point.
|
|
689
|
+
* @param bounds
|
|
690
|
+
*/
|
|
691
|
+
static center = ({ x, y, width, height }) => {
|
|
692
|
+
const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
|
|
693
|
+
1,
|
|
694
|
+
2
|
|
695
|
+
]));
|
|
696
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
697
|
+
1,
|
|
698
|
+
2
|
|
699
|
+
]));
|
|
700
|
+
return {
|
|
701
|
+
x: cx,
|
|
702
|
+
y: cy
|
|
703
|
+
};
|
|
704
|
+
};
|
|
705
|
+
/**
|
|
706
|
+
* Calculate centered left edge.
|
|
707
|
+
* @param bounds
|
|
708
|
+
*/
|
|
709
|
+
static left = ({ x, y, height }) => {
|
|
710
|
+
const cx = x;
|
|
711
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
712
|
+
1,
|
|
713
|
+
2
|
|
714
|
+
]));
|
|
715
|
+
return {
|
|
716
|
+
x: cx,
|
|
717
|
+
y: cy
|
|
718
|
+
};
|
|
719
|
+
};
|
|
720
|
+
/**
|
|
721
|
+
* Calculate centered right edge.
|
|
722
|
+
* @param bounds
|
|
723
|
+
*/
|
|
724
|
+
static right = ({ x, y, width, height }) => {
|
|
725
|
+
const cx = FractionUtil.add(x, width);
|
|
726
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
727
|
+
1,
|
|
728
|
+
2
|
|
729
|
+
]));
|
|
730
|
+
return {
|
|
731
|
+
x: cx,
|
|
732
|
+
y: cy
|
|
733
|
+
};
|
|
734
|
+
};
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
// src/graph/projector/projector.ts
|
|
196
738
|
var Projector = class {
|
|
739
|
+
_context;
|
|
740
|
+
updated = new EventEmitter();
|
|
741
|
+
_options;
|
|
742
|
+
constructor(_context, options) {
|
|
743
|
+
this._context = _context;
|
|
744
|
+
this._options = Object.assign({
|
|
745
|
+
idAccessor: defaultIdAccessor
|
|
746
|
+
}, options);
|
|
747
|
+
}
|
|
197
748
|
get context() {
|
|
198
749
|
return this._context;
|
|
199
750
|
}
|
|
@@ -230,33 +781,27 @@ var Projector = class {
|
|
|
230
781
|
}
|
|
231
782
|
async onStop() {
|
|
232
783
|
}
|
|
233
|
-
constructor(_context, options) {
|
|
234
|
-
_define_property(this, "_context", void 0);
|
|
235
|
-
_define_property(this, "updated", void 0);
|
|
236
|
-
_define_property(this, "_options", void 0);
|
|
237
|
-
this._context = _context;
|
|
238
|
-
this.updated = new EventEmitter();
|
|
239
|
-
this._options = Object.assign({
|
|
240
|
-
idAccessor: defaultIdAccessor
|
|
241
|
-
}, options);
|
|
242
|
-
}
|
|
243
784
|
};
|
|
244
785
|
|
|
245
786
|
// src/graph/projector/graph-projector.ts
|
|
246
|
-
function _define_property2(obj, key, value) {
|
|
247
|
-
if (key in obj) {
|
|
248
|
-
Object.defineProperty(obj, key, {
|
|
249
|
-
value,
|
|
250
|
-
enumerable: true,
|
|
251
|
-
configurable: true,
|
|
252
|
-
writable: true
|
|
253
|
-
});
|
|
254
|
-
} else {
|
|
255
|
-
obj[key] = value;
|
|
256
|
-
}
|
|
257
|
-
return obj;
|
|
258
|
-
}
|
|
259
787
|
var GraphProjector = class extends Projector {
|
|
788
|
+
_selection;
|
|
789
|
+
_layout;
|
|
790
|
+
// TODO(burdon): Change to object props.
|
|
791
|
+
constructor(context, options, _selection, layout) {
|
|
792
|
+
super(context, options), this._selection = _selection;
|
|
793
|
+
this._layout = {
|
|
794
|
+
id: (Math.random() * 10).toString().slice(8),
|
|
795
|
+
graph: {
|
|
796
|
+
nodes: [
|
|
797
|
+
...layout?.graph.nodes ?? []
|
|
798
|
+
],
|
|
799
|
+
edges: [
|
|
800
|
+
...layout?.graph.edges ?? []
|
|
801
|
+
]
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
}
|
|
260
805
|
get layout() {
|
|
261
806
|
return this._layout;
|
|
262
807
|
}
|
|
@@ -302,21 +847,6 @@ var GraphProjector = class extends Projector {
|
|
|
302
847
|
async onClear() {
|
|
303
848
|
this.reset();
|
|
304
849
|
}
|
|
305
|
-
// TODO(burdon): Change to object props.
|
|
306
|
-
constructor(context, options, _selection, layout) {
|
|
307
|
-
super(context, options), _define_property2(this, "_selection", void 0), _define_property2(this, "_layout", void 0), this._selection = _selection;
|
|
308
|
-
this._layout = {
|
|
309
|
-
id: (Math.random() * 10).toString().slice(8),
|
|
310
|
-
graph: {
|
|
311
|
-
nodes: [
|
|
312
|
-
...layout?.graph.nodes ?? []
|
|
313
|
-
],
|
|
314
|
-
edges: [
|
|
315
|
-
...layout?.graph.edges ?? []
|
|
316
|
-
]
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
850
|
};
|
|
321
851
|
|
|
322
852
|
// src/graph/projector/graph-force-projector.ts
|
|
@@ -340,20 +870,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
340
870
|
};
|
|
341
871
|
|
|
342
872
|
// src/graph/projector/graph-force-projector.ts
|
|
343
|
-
|
|
344
|
-
if (key in obj) {
|
|
345
|
-
Object.defineProperty(obj, key, {
|
|
346
|
-
value,
|
|
347
|
-
enumerable: true,
|
|
348
|
-
configurable: true,
|
|
349
|
-
writable: true
|
|
350
|
-
});
|
|
351
|
-
} else {
|
|
352
|
-
obj[key] = value;
|
|
353
|
-
}
|
|
354
|
-
return obj;
|
|
355
|
-
}
|
|
356
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
873
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
357
874
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
358
875
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
359
876
|
};
|
|
@@ -370,6 +887,9 @@ var defaultForceOptions = {
|
|
|
370
887
|
point: true
|
|
371
888
|
};
|
|
372
889
|
var GraphForceProjector = class extends GraphProjector {
|
|
890
|
+
// https://github.com/d3/d3-force
|
|
891
|
+
_simulation = forceSimulation();
|
|
892
|
+
_timeout;
|
|
373
893
|
get forces() {
|
|
374
894
|
return this.options.forces ?? defaultForceOptions;
|
|
375
895
|
}
|
|
@@ -423,7 +943,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
423
943
|
edges: graph?.edges.length
|
|
424
944
|
}
|
|
425
945
|
}, {
|
|
426
|
-
F:
|
|
946
|
+
F: __dxlog_file3,
|
|
427
947
|
L: 227,
|
|
428
948
|
S: this,
|
|
429
949
|
C: (f, a) => f(...a)
|
|
@@ -478,7 +998,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
478
998
|
log("updateForces", {
|
|
479
999
|
forces
|
|
480
1000
|
}, {
|
|
481
|
-
F:
|
|
1001
|
+
F: __dxlog_file3,
|
|
482
1002
|
L: 288,
|
|
483
1003
|
S: this,
|
|
484
1004
|
C: (f, a) => f(...a)
|
|
@@ -543,10 +1063,6 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
543
1063
|
return force;
|
|
544
1064
|
}));
|
|
545
1065
|
}
|
|
546
|
-
constructor(...args) {
|
|
547
|
-
super(...args), // https://github.com/d3/d3-force
|
|
548
|
-
_define_property3(this, "_simulation", forceSimulation()), _define_property3(this, "_timeout", void 0);
|
|
549
|
-
}
|
|
550
1066
|
};
|
|
551
1067
|
|
|
552
1068
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
@@ -555,21 +1071,9 @@ import { log as log3 } from "@dxos/log";
|
|
|
555
1071
|
// src/graph/projector/graph-radial-projector.ts
|
|
556
1072
|
import { easeCubic, timer } from "d3";
|
|
557
1073
|
import { log as log2 } from "@dxos/log";
|
|
558
|
-
|
|
559
|
-
if (key in obj) {
|
|
560
|
-
Object.defineProperty(obj, key, {
|
|
561
|
-
value,
|
|
562
|
-
enumerable: true,
|
|
563
|
-
configurable: true,
|
|
564
|
-
writable: true
|
|
565
|
-
});
|
|
566
|
-
} else {
|
|
567
|
-
obj[key] = value;
|
|
568
|
-
}
|
|
569
|
-
return obj;
|
|
570
|
-
}
|
|
571
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
1074
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
572
1075
|
var GraphRadialProjector = class extends GraphProjector {
|
|
1076
|
+
_timer;
|
|
573
1077
|
findNode(x, y, radius) {
|
|
574
1078
|
return void 0;
|
|
575
1079
|
}
|
|
@@ -580,7 +1084,7 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
580
1084
|
edges: graph?.edges.length
|
|
581
1085
|
}
|
|
582
1086
|
}, {
|
|
583
|
-
F:
|
|
1087
|
+
F: __dxlog_file4,
|
|
584
1088
|
L: 32,
|
|
585
1089
|
S: this,
|
|
586
1090
|
C: (f, a) => f(...a)
|
|
@@ -627,9 +1131,6 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
627
1131
|
});
|
|
628
1132
|
this.animate();
|
|
629
1133
|
}
|
|
630
|
-
constructor(...args) {
|
|
631
|
-
super(...args), _define_property4(this, "_timer", void 0);
|
|
632
|
-
}
|
|
633
1134
|
};
|
|
634
1135
|
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
635
1136
|
const sx = node.x ?? tx;
|
|
@@ -683,7 +1184,7 @@ var layoutVertical = (x, y, h, n) => {
|
|
|
683
1184
|
};
|
|
684
1185
|
|
|
685
1186
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
686
|
-
var
|
|
1187
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
687
1188
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
688
1189
|
onUpdate(graph) {
|
|
689
1190
|
log3("onUpdate", {
|
|
@@ -691,15 +1192,15 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
691
1192
|
nodes: graph?.nodes.length,
|
|
692
1193
|
edges: graph?.edges.length
|
|
693
1194
|
},
|
|
694
|
-
selection: this.selection?.
|
|
1195
|
+
selection: this.selection?.getSelectedIds()
|
|
695
1196
|
}, {
|
|
696
|
-
F:
|
|
1197
|
+
F: __dxlog_file5,
|
|
697
1198
|
L: 24,
|
|
698
1199
|
S: this,
|
|
699
1200
|
C: (f, a) => f(...a)
|
|
700
1201
|
});
|
|
701
1202
|
this.mergeData(graph);
|
|
702
|
-
const selected = this.selection?.
|
|
1203
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
703
1204
|
if (selected) {
|
|
704
1205
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
705
1206
|
if (node) {
|
|
@@ -746,7 +1247,7 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
746
1247
|
|
|
747
1248
|
// src/graph/projector/graph-relational-projector.ts
|
|
748
1249
|
import { log as log4 } from "@dxos/log";
|
|
749
|
-
var
|
|
1250
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
750
1251
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
751
1252
|
onUpdate(graph) {
|
|
752
1253
|
log4("onUpdate", {
|
|
@@ -754,15 +1255,15 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
754
1255
|
nodes: graph?.nodes.length,
|
|
755
1256
|
edges: graph?.edges.length
|
|
756
1257
|
},
|
|
757
|
-
selection: this.selection?.
|
|
1258
|
+
selection: this.selection?.getSelectedIds()
|
|
758
1259
|
}, {
|
|
759
|
-
F:
|
|
1260
|
+
F: __dxlog_file6,
|
|
760
1261
|
L: 24,
|
|
761
1262
|
S: this,
|
|
762
1263
|
C: (f, a) => f(...a)
|
|
763
1264
|
});
|
|
764
1265
|
this.mergeData(graph);
|
|
765
|
-
const selected = this.selection?.
|
|
1266
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
766
1267
|
if (selected) {
|
|
767
1268
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
768
1269
|
if (node) {
|
|
@@ -869,28 +1370,25 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
869
1370
|
};
|
|
870
1371
|
|
|
871
1372
|
// src/graph/renderer/renderer.ts
|
|
872
|
-
import { invariant as
|
|
873
|
-
|
|
874
|
-
if (key in obj) {
|
|
875
|
-
Object.defineProperty(obj, key, {
|
|
876
|
-
value,
|
|
877
|
-
enumerable: true,
|
|
878
|
-
configurable: true,
|
|
879
|
-
writable: true
|
|
880
|
-
});
|
|
881
|
-
} else {
|
|
882
|
-
obj[key] = value;
|
|
883
|
-
}
|
|
884
|
-
return obj;
|
|
885
|
-
}
|
|
886
|
-
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
1373
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1374
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
887
1375
|
var Renderer = class {
|
|
1376
|
+
_context;
|
|
1377
|
+
_root;
|
|
1378
|
+
_options;
|
|
1379
|
+
constructor(_context, _root, options) {
|
|
1380
|
+
this._context = _context;
|
|
1381
|
+
this._root = _root;
|
|
1382
|
+
this._options = Object.assign({
|
|
1383
|
+
idAccessor: defaultIdAccessor
|
|
1384
|
+
}, options);
|
|
1385
|
+
}
|
|
888
1386
|
get context() {
|
|
889
1387
|
return this._context;
|
|
890
1388
|
}
|
|
891
1389
|
get root() {
|
|
892
|
-
|
|
893
|
-
F:
|
|
1390
|
+
invariant3(this._root.current, "SVG root is not initialized", {
|
|
1391
|
+
F: __dxlog_file7,
|
|
894
1392
|
L: 40,
|
|
895
1393
|
S: this,
|
|
896
1394
|
A: [
|
|
@@ -903,25 +1401,15 @@ var Renderer = class {
|
|
|
903
1401
|
get options() {
|
|
904
1402
|
return this._options;
|
|
905
1403
|
}
|
|
906
|
-
constructor(_context, _root, options) {
|
|
907
|
-
_define_property5(this, "_context", void 0);
|
|
908
|
-
_define_property5(this, "_root", void 0);
|
|
909
|
-
_define_property5(this, "_options", void 0);
|
|
910
|
-
this._context = _context;
|
|
911
|
-
this._root = _root;
|
|
912
|
-
this._options = Object.assign({
|
|
913
|
-
idAccessor: defaultIdAccessor
|
|
914
|
-
}, options);
|
|
915
|
-
}
|
|
916
1404
|
};
|
|
917
1405
|
|
|
918
1406
|
// src/graph/renderer/graph-renderer.ts
|
|
919
|
-
var
|
|
1407
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
920
1408
|
var createLine2 = line2();
|
|
921
1409
|
var GraphRenderer = class extends Renderer {
|
|
922
1410
|
render(layout) {
|
|
923
1411
|
log5("render", layout, {
|
|
924
|
-
F:
|
|
1412
|
+
F: __dxlog_file8,
|
|
925
1413
|
L: 63,
|
|
926
1414
|
S: this,
|
|
927
1415
|
C: (f, a) => f(...a)
|
|
@@ -1069,7 +1557,7 @@ var updateNode2 = (group, options) => {
|
|
|
1069
1557
|
log5.error("updateNode", {
|
|
1070
1558
|
error: error?.message
|
|
1071
1559
|
}, {
|
|
1072
|
-
F:
|
|
1560
|
+
F: __dxlog_file8,
|
|
1073
1561
|
L: 305,
|
|
1074
1562
|
S: void 0,
|
|
1075
1563
|
C: (f, a) => f(...a)
|
|
@@ -1125,7 +1613,7 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1125
1613
|
log5.error("updateEdge", {
|
|
1126
1614
|
error: error?.message
|
|
1127
1615
|
}, {
|
|
1128
|
-
F:
|
|
1616
|
+
F: __dxlog_file8,
|
|
1129
1617
|
L: 417,
|
|
1130
1618
|
S: void 0,
|
|
1131
1619
|
C: (f, a) => f(...a)
|
|
@@ -1207,112 +1695,427 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1207
1695
|
});
|
|
1208
1696
|
};
|
|
1209
1697
|
|
|
1698
|
+
// src/hooks/useGrid.ts
|
|
1699
|
+
import { line as line4, range, select as select5 } from "d3";
|
|
1700
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
1701
|
+
|
|
1702
|
+
// src/hooks/useSvgContext.ts
|
|
1703
|
+
import { createContext, useContext } from "react";
|
|
1704
|
+
import { createRef } from "react";
|
|
1705
|
+
import { raise } from "@dxos/debug";
|
|
1706
|
+
var SVGContext = class {
|
|
1707
|
+
_ref = createRef();
|
|
1708
|
+
_scale;
|
|
1709
|
+
_centered;
|
|
1710
|
+
_size;
|
|
1711
|
+
_center;
|
|
1712
|
+
resized = new EventEmitter();
|
|
1713
|
+
constructor({ scale = new Scale(), centered = true }) {
|
|
1714
|
+
this._scale = scale;
|
|
1715
|
+
this._centered = centered;
|
|
1716
|
+
}
|
|
1717
|
+
get ref() {
|
|
1718
|
+
return this._ref;
|
|
1719
|
+
}
|
|
1720
|
+
get svg() {
|
|
1721
|
+
return this._ref.current;
|
|
1722
|
+
}
|
|
1723
|
+
get scale() {
|
|
1724
|
+
return this._scale;
|
|
1725
|
+
}
|
|
1726
|
+
get center() {
|
|
1727
|
+
return this._center;
|
|
1728
|
+
}
|
|
1729
|
+
get size() {
|
|
1730
|
+
return this._size;
|
|
1731
|
+
}
|
|
1732
|
+
/**
|
|
1733
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
|
|
1734
|
+
*/
|
|
1735
|
+
get viewBox() {
|
|
1736
|
+
const [x, y] = this.center;
|
|
1737
|
+
return `${x},${y},${this._size.width},${this._size.height}`;
|
|
1738
|
+
}
|
|
1739
|
+
setSize(size) {
|
|
1740
|
+
this._size = {
|
|
1741
|
+
...size
|
|
1742
|
+
};
|
|
1743
|
+
this._center = this._centered ? [
|
|
1744
|
+
-Math.floor(size.width / 2),
|
|
1745
|
+
-Math.floor(size.height / 2)
|
|
1746
|
+
] : [
|
|
1747
|
+
0,
|
|
1748
|
+
0
|
|
1749
|
+
];
|
|
1750
|
+
this.resized.emit(this);
|
|
1751
|
+
}
|
|
1752
|
+
setTransform(transform) {
|
|
1753
|
+
if (this._scale.setTransform(transform)) {
|
|
1754
|
+
this.resized.emit(this);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
|
|
1759
|
+
* @param point
|
|
1760
|
+
*/
|
|
1761
|
+
elementFromPoint(point) {
|
|
1762
|
+
const [x, y] = point;
|
|
1763
|
+
const [cx, cy] = this._center;
|
|
1764
|
+
return document.elementFromPoint(cx + x, cy + y);
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
var SVGContextType = createContext(void 0);
|
|
1768
|
+
var SVGContextProvider = SVGContextType.Provider;
|
|
1769
|
+
var useSvgContext = () => {
|
|
1770
|
+
return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
|
|
1771
|
+
};
|
|
1772
|
+
|
|
1773
|
+
// src/hooks/useGrid.ts
|
|
1774
|
+
var createLine4 = line4();
|
|
1775
|
+
var createGrid = (context, options) => {
|
|
1776
|
+
if (!context.size) {
|
|
1777
|
+
return [];
|
|
1778
|
+
}
|
|
1779
|
+
const paths = [];
|
|
1780
|
+
const { width, height } = context.size;
|
|
1781
|
+
const { x, y, k } = context.scale.transform;
|
|
1782
|
+
const s = 1 / k;
|
|
1783
|
+
const w = width * s;
|
|
1784
|
+
const h = height * s;
|
|
1785
|
+
const dx = -(x + width / 2) * s;
|
|
1786
|
+
const dy = -(y + height / 2) * s;
|
|
1787
|
+
if (options.axis) {
|
|
1788
|
+
const axis = [
|
|
1789
|
+
[
|
|
1790
|
+
[
|
|
1791
|
+
0,
|
|
1792
|
+
dy
|
|
1793
|
+
],
|
|
1794
|
+
[
|
|
1795
|
+
0,
|
|
1796
|
+
dy + h
|
|
1797
|
+
]
|
|
1798
|
+
],
|
|
1799
|
+
[
|
|
1800
|
+
[
|
|
1801
|
+
dx,
|
|
1802
|
+
0
|
|
1803
|
+
],
|
|
1804
|
+
[
|
|
1805
|
+
dx + w,
|
|
1806
|
+
0
|
|
1807
|
+
]
|
|
1808
|
+
]
|
|
1809
|
+
];
|
|
1810
|
+
paths.push({
|
|
1811
|
+
id: "axis",
|
|
1812
|
+
class: "dx-axis",
|
|
1813
|
+
path: axis.map((line5) => createLine4(line5)).join()
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
if (options.grid) {
|
|
1817
|
+
const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
|
|
1818
|
+
const majorSize = context.scale.gridSize;
|
|
1819
|
+
const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
|
|
1820
|
+
const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
|
|
1821
|
+
const major = [
|
|
1822
|
+
...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
|
|
1823
|
+
[
|
|
1824
|
+
x2,
|
|
1825
|
+
dy
|
|
1826
|
+
],
|
|
1827
|
+
[
|
|
1828
|
+
x2,
|
|
1829
|
+
dy + h
|
|
1830
|
+
]
|
|
1831
|
+
]),
|
|
1832
|
+
...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
|
|
1833
|
+
[
|
|
1834
|
+
dx,
|
|
1835
|
+
y2
|
|
1836
|
+
],
|
|
1837
|
+
[
|
|
1838
|
+
dx + w,
|
|
1839
|
+
y2
|
|
1840
|
+
]
|
|
1841
|
+
])
|
|
1842
|
+
];
|
|
1843
|
+
paths.push({
|
|
1844
|
+
id: "major",
|
|
1845
|
+
class: "dx-major",
|
|
1846
|
+
path: major.map((line5) => createLine4(line5)).join()
|
|
1847
|
+
});
|
|
1848
|
+
const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
|
|
1849
|
+
if (majorSize > minorSize) {
|
|
1850
|
+
const xMinor = range(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
|
|
1851
|
+
const yMinor = range(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
|
|
1852
|
+
const minor = [
|
|
1853
|
+
...xMinor.filter((x2) => xMajor.indexOf(x2) === -1).map((x2) => [
|
|
1854
|
+
[
|
|
1855
|
+
x2,
|
|
1856
|
+
dy
|
|
1857
|
+
],
|
|
1858
|
+
[
|
|
1859
|
+
x2,
|
|
1860
|
+
dy + h
|
|
1861
|
+
]
|
|
1862
|
+
]),
|
|
1863
|
+
...yMinor.filter((y2) => yMajor.indexOf(y2) === -1).map((y2) => [
|
|
1864
|
+
[
|
|
1865
|
+
dx,
|
|
1866
|
+
y2
|
|
1867
|
+
],
|
|
1868
|
+
[
|
|
1869
|
+
dx + w,
|
|
1870
|
+
y2
|
|
1871
|
+
]
|
|
1872
|
+
])
|
|
1873
|
+
];
|
|
1874
|
+
paths.push({
|
|
1875
|
+
id: "minor",
|
|
1876
|
+
class: "dx-minor",
|
|
1877
|
+
path: minor.map((line5) => createLine4(line5)).join()
|
|
1878
|
+
});
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
return paths;
|
|
1882
|
+
};
|
|
1883
|
+
var defaultGridOptions = {
|
|
1884
|
+
visible: true,
|
|
1885
|
+
axis: true,
|
|
1886
|
+
grid: true
|
|
1887
|
+
};
|
|
1888
|
+
var GridController = class {
|
|
1889
|
+
_ref;
|
|
1890
|
+
_context;
|
|
1891
|
+
_options;
|
|
1892
|
+
_visible = false;
|
|
1893
|
+
constructor(_ref, _context, _options) {
|
|
1894
|
+
this._ref = _ref;
|
|
1895
|
+
this._context = _context;
|
|
1896
|
+
this._options = _options;
|
|
1897
|
+
this._visible = this._options.visible ?? true;
|
|
1898
|
+
}
|
|
1899
|
+
get ref() {
|
|
1900
|
+
return this._ref;
|
|
1901
|
+
}
|
|
1902
|
+
get visible() {
|
|
1903
|
+
return this._visible;
|
|
1904
|
+
}
|
|
1905
|
+
draw() {
|
|
1906
|
+
if (!this._context.size) {
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
const paths = this._visible ? createGrid(this._context, this._options) : [];
|
|
1910
|
+
const root = select5(this._ref.current);
|
|
1911
|
+
root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
|
|
1912
|
+
const transform = this._context.scale.transform;
|
|
1913
|
+
if (transform) {
|
|
1914
|
+
root.attr("transform", transform);
|
|
1915
|
+
root.attr("stroke-width", 1 / transform.k);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
setVisible(visible) {
|
|
1919
|
+
this._visible = visible;
|
|
1920
|
+
this.draw();
|
|
1921
|
+
return this;
|
|
1922
|
+
}
|
|
1923
|
+
};
|
|
1924
|
+
var useGrid = (options = defaultGridOptions) => {
|
|
1925
|
+
const ref = useRef(null);
|
|
1926
|
+
const context = useSvgContext();
|
|
1927
|
+
const controller = useMemo(() => new GridController(ref, context, options), []);
|
|
1928
|
+
useEffect(() => context.resized.on(() => controller.draw()), [
|
|
1929
|
+
context,
|
|
1930
|
+
controller
|
|
1931
|
+
]);
|
|
1932
|
+
return controller;
|
|
1933
|
+
};
|
|
1934
|
+
|
|
1935
|
+
// src/hooks/useZoom.ts
|
|
1936
|
+
import { select as select6, zoom, zoomIdentity as zoomIdentity2 } from "d3";
|
|
1937
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
1938
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
1939
|
+
var defaultZoomOptions = {
|
|
1940
|
+
enabled: true,
|
|
1941
|
+
extent: [
|
|
1942
|
+
1 / 4,
|
|
1943
|
+
4
|
|
1944
|
+
],
|
|
1945
|
+
onDblClick: (zoom2) => zoom2.reset()
|
|
1946
|
+
};
|
|
1947
|
+
var ZoomHandler = class {
|
|
1948
|
+
_ref;
|
|
1949
|
+
_context;
|
|
1950
|
+
_zoom;
|
|
1951
|
+
_options;
|
|
1952
|
+
_enabled;
|
|
1953
|
+
constructor(_ref, _context, options) {
|
|
1954
|
+
this._ref = _ref;
|
|
1955
|
+
this._context = _context;
|
|
1956
|
+
this._options = defaultsDeep({}, options, defaultZoomOptions);
|
|
1957
|
+
this._enabled = this._options.enabled ?? true;
|
|
1958
|
+
this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
|
|
1959
|
+
}
|
|
1960
|
+
/**
|
|
1961
|
+
* Gets the reference which the transform is applied to.
|
|
1962
|
+
*/
|
|
1963
|
+
get ref() {
|
|
1964
|
+
return this._ref;
|
|
1965
|
+
}
|
|
1966
|
+
get zoom() {
|
|
1967
|
+
return this._zoom;
|
|
1968
|
+
}
|
|
1969
|
+
init() {
|
|
1970
|
+
this.setEnabled(this._enabled);
|
|
1971
|
+
this.reset(0);
|
|
1972
|
+
return this;
|
|
1973
|
+
}
|
|
1974
|
+
setEnabled(enable) {
|
|
1975
|
+
if (enable) {
|
|
1976
|
+
select6(this._context.svg).call(this._zoom).on(
|
|
1977
|
+
"dblclick.zoom",
|
|
1978
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1979
|
+
// @ts-ignore
|
|
1980
|
+
this._options?.onDblClick ? () => {
|
|
1981
|
+
this._options?.onDblClick(this);
|
|
1982
|
+
} : null
|
|
1983
|
+
);
|
|
1984
|
+
} else {
|
|
1985
|
+
select6(this._context.svg).on(".zoom", null);
|
|
1986
|
+
}
|
|
1987
|
+
this._enabled = enable;
|
|
1988
|
+
return this;
|
|
1989
|
+
}
|
|
1990
|
+
reset(duration = 500) {
|
|
1991
|
+
const scale = 1;
|
|
1992
|
+
const transform = zoomIdentity2.scale(scale);
|
|
1993
|
+
select6(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
|
|
1994
|
+
return this;
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
var useZoom = (options = defaultZoomOptions) => {
|
|
1998
|
+
const context = useSvgContext();
|
|
1999
|
+
const ref = useRef2(null);
|
|
2000
|
+
const handler = useMemo2(() => new ZoomHandler(ref, context, options), [
|
|
2001
|
+
context,
|
|
2002
|
+
options
|
|
2003
|
+
]);
|
|
2004
|
+
useEffect2(() => {
|
|
2005
|
+
handler.zoom.on("zoom", ({ transform }) => {
|
|
2006
|
+
context.setTransform(transform);
|
|
2007
|
+
select6(ref.current).attr("transform", transform);
|
|
2008
|
+
});
|
|
2009
|
+
handler.init();
|
|
2010
|
+
}, [
|
|
2011
|
+
handler
|
|
2012
|
+
]);
|
|
2013
|
+
return handler;
|
|
2014
|
+
};
|
|
2015
|
+
|
|
1210
2016
|
// src/components/Graph/Graph.tsx
|
|
1211
|
-
var
|
|
2017
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
1212
2018
|
var GraphInner = ({ classNames, model, projector: _projector, renderer: _renderer, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
2019
|
+
const context = useSvgContext();
|
|
2020
|
+
const graphRef = useRef3(null);
|
|
2021
|
+
const { projector, renderer } = useMemo3(() => {
|
|
2022
|
+
let projector2 = _projector;
|
|
2023
|
+
if (!projector2) {
|
|
2024
|
+
projector2 = new GraphForceProjector(context);
|
|
2025
|
+
}
|
|
2026
|
+
let renderer2 = _renderer;
|
|
2027
|
+
if (!renderer2) {
|
|
2028
|
+
renderer2 = new GraphRenderer(context, graphRef, {
|
|
2029
|
+
...props,
|
|
2030
|
+
// TODO(burdon): Replace drag when projector is updated.
|
|
2031
|
+
drag: drag2 ? createGraphDrag(context, projector2) : void 0,
|
|
2032
|
+
arrows: {
|
|
2033
|
+
end: arrows
|
|
2034
|
+
},
|
|
2035
|
+
onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
|
|
2036
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
return {
|
|
2040
|
+
projector: projector2,
|
|
2041
|
+
renderer: renderer2
|
|
2042
|
+
};
|
|
2043
|
+
}, [
|
|
2044
|
+
context,
|
|
2045
|
+
_projector,
|
|
2046
|
+
_renderer,
|
|
2047
|
+
drag2
|
|
2048
|
+
]);
|
|
2049
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
2050
|
+
refresh: () => {
|
|
2051
|
+
projector.updateData(model?.graph);
|
|
2052
|
+
},
|
|
2053
|
+
repaint: () => {
|
|
2054
|
+
renderer.render(projector.layout);
|
|
2055
|
+
},
|
|
2056
|
+
findNode: (id) => {
|
|
2057
|
+
return graphRef.current?.querySelector(`g[data-id="${id}"]`);
|
|
2058
|
+
}
|
|
2059
|
+
}), [
|
|
2060
|
+
model,
|
|
2061
|
+
projector,
|
|
2062
|
+
renderer
|
|
2063
|
+
]);
|
|
2064
|
+
useEffect3(() => {
|
|
2065
|
+
projector.updateData(model?.graph);
|
|
2066
|
+
const unsubscribeModel = model && "subscribe" in model ? model.subscribe(() => {
|
|
2067
|
+
projector.updateData(model?.graph);
|
|
2068
|
+
}) : void 0;
|
|
2069
|
+
return combine(unsubscribeModel, projector.updated.on(({ layout }) => {
|
|
2070
|
+
try {
|
|
2071
|
+
renderer.render(layout);
|
|
2072
|
+
} catch (error) {
|
|
2073
|
+
void projector.stop();
|
|
2074
|
+
log6.catch(error, void 0, {
|
|
2075
|
+
F: __dxlog_file9,
|
|
2076
|
+
L: 115,
|
|
2077
|
+
S: void 0,
|
|
2078
|
+
C: (f, a) => f(...a)
|
|
1233
2079
|
});
|
|
1234
2080
|
}
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
return graphRef.current?.querySelector(`g[data-id="${id}"]`);
|
|
1254
|
-
}
|
|
1255
|
-
}), [
|
|
1256
|
-
model,
|
|
1257
|
-
projector,
|
|
1258
|
-
renderer
|
|
1259
|
-
]);
|
|
1260
|
-
useEffect(() => {
|
|
1261
|
-
return combine(effect(() => {
|
|
1262
|
-
projector.updateData(model?.graph);
|
|
1263
|
-
}), projector.updated.on(({ layout }) => {
|
|
1264
|
-
try {
|
|
1265
|
-
renderer.render(layout);
|
|
1266
|
-
} catch (error) {
|
|
1267
|
-
void projector.stop();
|
|
1268
|
-
log6.catch(error, void 0, {
|
|
1269
|
-
F: __dxlog_file8,
|
|
1270
|
-
L: 108,
|
|
1271
|
-
S: void 0,
|
|
1272
|
-
C: (f, a) => f(...a)
|
|
1273
|
-
});
|
|
1274
|
-
}
|
|
1275
|
-
}));
|
|
1276
|
-
}, [
|
|
1277
|
-
model,
|
|
1278
|
-
projector,
|
|
1279
|
-
renderer
|
|
1280
|
-
]);
|
|
1281
|
-
useEffect(() => {
|
|
1282
|
-
void projector.start();
|
|
1283
|
-
return () => {
|
|
1284
|
-
void projector.stop();
|
|
1285
|
-
};
|
|
1286
|
-
}, [
|
|
1287
|
-
projector
|
|
1288
|
-
]);
|
|
1289
|
-
return /* @__PURE__ */ React.createElement("g", {
|
|
1290
|
-
ref: graphRef,
|
|
1291
|
-
className: mx("dx-graph", classNames)
|
|
1292
|
-
});
|
|
1293
|
-
} finally {
|
|
1294
|
-
_effect.f();
|
|
1295
|
-
}
|
|
2081
|
+
}));
|
|
2082
|
+
}, [
|
|
2083
|
+
model,
|
|
2084
|
+
projector,
|
|
2085
|
+
renderer
|
|
2086
|
+
]);
|
|
2087
|
+
useEffect3(() => {
|
|
2088
|
+
void projector.start();
|
|
2089
|
+
return () => {
|
|
2090
|
+
void projector.stop();
|
|
2091
|
+
};
|
|
2092
|
+
}, [
|
|
2093
|
+
projector
|
|
2094
|
+
]);
|
|
2095
|
+
return /* @__PURE__ */ React.createElement("g", {
|
|
2096
|
+
ref: graphRef,
|
|
2097
|
+
className: mx("dx-graph", classNames)
|
|
2098
|
+
});
|
|
1296
2099
|
};
|
|
1297
2100
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1298
2101
|
|
|
1299
2102
|
// src/components/Mesh/Mesh.tsx
|
|
1300
|
-
import { geoPath, select as
|
|
1301
|
-
import { useEffect as
|
|
2103
|
+
import { geoPath, select as select7 } from "d3";
|
|
2104
|
+
import { useEffect as useEffect4 } from "react";
|
|
1302
2105
|
import { feature, mesh } from "topojson-client";
|
|
1303
2106
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1304
2107
|
const { svg, size } = useSvgContext();
|
|
1305
|
-
|
|
2108
|
+
useEffect4(() => {
|
|
1306
2109
|
if (size) {
|
|
1307
2110
|
const topology = hexTopology(size, radius, value);
|
|
1308
2111
|
const projection = hexProjection(radius);
|
|
1309
2112
|
const path = geoPath().projection(projection);
|
|
1310
|
-
|
|
1311
|
-
|
|
2113
|
+
select7(svg).append("g").attr("class", "hexagon").selectAll("path").data(topology.objects.hexagons.geometries).enter().append("path").attr("d", (d) => path(feature(topology, d))).attr("class", (d) => d.properties?.fill ? "fill" : null);
|
|
2114
|
+
select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
1312
2115
|
const redraw = (border) => {
|
|
1313
2116
|
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1314
2117
|
};
|
|
1315
|
-
|
|
2118
|
+
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
1316
2119
|
}
|
|
1317
2120
|
}, [
|
|
1318
2121
|
svg,
|
|
@@ -1429,115 +2232,91 @@ var hexProjection = (radius) => {
|
|
|
1429
2232
|
};
|
|
1430
2233
|
|
|
1431
2234
|
// src/components/SVG/Grid.tsx
|
|
1432
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
1433
2235
|
import React2 from "react";
|
|
1434
|
-
import { mx as mx2 } from "@dxos/
|
|
2236
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1435
2237
|
var Grid = ({ classNames, ...props }) => {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
className: mx2("dx-grid", classNames)
|
|
1442
|
-
});
|
|
1443
|
-
} finally {
|
|
1444
|
-
_effect.f();
|
|
1445
|
-
}
|
|
2238
|
+
const { ref } = useGrid(props);
|
|
2239
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
2240
|
+
ref,
|
|
2241
|
+
className: mx2("dx-grid", classNames)
|
|
2242
|
+
});
|
|
1446
2243
|
};
|
|
1447
2244
|
|
|
1448
2245
|
// src/components/SVG/Markers.tsx
|
|
1449
|
-
import {
|
|
1450
|
-
import {
|
|
1451
|
-
import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
2246
|
+
import { select as select8 } from "d3";
|
|
2247
|
+
import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
1452
2248
|
var Markers = ({ arrowSize, className }) => {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
className
|
|
1466
|
-
});
|
|
1467
|
-
} finally {
|
|
1468
|
-
_effect.f();
|
|
1469
|
-
}
|
|
2249
|
+
const ref = useRef4(null);
|
|
2250
|
+
useEffect5(() => {
|
|
2251
|
+
select8(ref.current).call(createMarkers({
|
|
2252
|
+
arrowSize
|
|
2253
|
+
}));
|
|
2254
|
+
}, [
|
|
2255
|
+
ref
|
|
2256
|
+
]);
|
|
2257
|
+
return /* @__PURE__ */ React3.createElement("defs", {
|
|
2258
|
+
ref,
|
|
2259
|
+
className
|
|
2260
|
+
});
|
|
1470
2261
|
};
|
|
1471
2262
|
|
|
1472
2263
|
// src/components/SVG/Root.tsx
|
|
1473
|
-
import {
|
|
1474
|
-
import {
|
|
1475
|
-
import React4, { forwardRef as forwardRef2, useEffect as useEffect4, useImperativeHandle as useImperativeHandle2, useMemo as useMemo2 } from "react";
|
|
2264
|
+
import { select as select9 } from "d3";
|
|
2265
|
+
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
|
|
1476
2266
|
import { useResizeDetector } from "react-resize-detector";
|
|
1477
|
-
import { mx as mx3 } from "@dxos/
|
|
2267
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
1478
2268
|
var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, ...props }, ref) => {
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
1516
|
-
}, ready && children)));
|
|
1517
|
-
} finally {
|
|
1518
|
-
_effect.f();
|
|
1519
|
-
}
|
|
2269
|
+
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
|
|
2270
|
+
refreshRate: 200
|
|
2271
|
+
});
|
|
2272
|
+
const context = useMemo4(() => {
|
|
2273
|
+
return new SVGContext(props);
|
|
2274
|
+
}, [
|
|
2275
|
+
props.scale,
|
|
2276
|
+
props.centered
|
|
2277
|
+
]);
|
|
2278
|
+
useImperativeHandle2(ref, () => context, [
|
|
2279
|
+
context
|
|
2280
|
+
]);
|
|
2281
|
+
useEffect6(() => {
|
|
2282
|
+
if (width && height) {
|
|
2283
|
+
context.setSize({
|
|
2284
|
+
width,
|
|
2285
|
+
height
|
|
2286
|
+
});
|
|
2287
|
+
select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
2288
|
+
}
|
|
2289
|
+
}, [
|
|
2290
|
+
context,
|
|
2291
|
+
width,
|
|
2292
|
+
height
|
|
2293
|
+
]);
|
|
2294
|
+
const ready = width !== 0 && height !== 0;
|
|
2295
|
+
return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
|
|
2296
|
+
value: context
|
|
2297
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
2298
|
+
ref: containerRef,
|
|
2299
|
+
className: mx3("grid grow overflow-hidden", classNames)
|
|
2300
|
+
}, /* @__PURE__ */ React4.createElement("svg", {
|
|
2301
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2302
|
+
ref: context.ref,
|
|
2303
|
+
className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
2304
|
+
}, ready && children)));
|
|
1520
2305
|
});
|
|
1521
2306
|
|
|
1522
2307
|
// src/components/SVG/Zoom.tsx
|
|
1523
|
-
import {
|
|
1524
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
2308
|
+
import React5, { memo, useMemo as useMemo5 } from "react";
|
|
1525
2309
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
className
|
|
1537
|
-
}, children);
|
|
1538
|
-
} finally {
|
|
1539
|
-
_effect.f();
|
|
1540
|
-
}
|
|
2310
|
+
const options = useMemo5(() => ({
|
|
2311
|
+
extent
|
|
2312
|
+
}), [
|
|
2313
|
+
JSON.stringify(extent)
|
|
2314
|
+
]);
|
|
2315
|
+
const zoom2 = useZoom(options);
|
|
2316
|
+
return /* @__PURE__ */ React5.createElement("g", {
|
|
2317
|
+
ref: zoom2.ref,
|
|
2318
|
+
className
|
|
2319
|
+
}, children);
|
|
1541
2320
|
});
|
|
1542
2321
|
|
|
1543
2322
|
// src/components/SVG/SVG.tsx
|
|
@@ -1551,7 +2330,7 @@ var SVG = {
|
|
|
1551
2330
|
};
|
|
1552
2331
|
|
|
1553
2332
|
// src/fx/pulsar.ts
|
|
1554
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
2333
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1555
2334
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1556
2335
|
(function(Pulsar2) {
|
|
1557
2336
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1566,10 +2345,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1566
2345
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1567
2346
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1568
2347
|
return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(easeCubicOut2).attr("r", r * ratio).attr("opacity", -0.1).on("end", function() {
|
|
1569
|
-
if (
|
|
1570
|
-
startAnimation(
|
|
2348
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
2349
|
+
startAnimation(select10(this), r, options);
|
|
1571
2350
|
} else {
|
|
1572
|
-
|
|
2351
|
+
select10(this).remove();
|
|
1573
2352
|
}
|
|
1574
2353
|
});
|
|
1575
2354
|
};
|
|
@@ -1580,7 +2359,6 @@ export {
|
|
|
1580
2359
|
Graph,
|
|
1581
2360
|
GraphForceProjector,
|
|
1582
2361
|
GraphHierarchicalProjector,
|
|
1583
|
-
GraphInner,
|
|
1584
2362
|
GraphProjector,
|
|
1585
2363
|
GraphRadialProjector,
|
|
1586
2364
|
GraphRelationalProjector,
|