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