@dxos/react-ui-graph 0.8.4-main.c1de068 → 0.8.4-main.c351d160a8
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 +1100 -245
- 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 +1100 -245
- 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 +16 -7
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts +9 -5
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Grid.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/components/SVG/Svg.stories.d.ts +10 -8
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Zoom.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +16 -15
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-drag.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +4 -4
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +2 -2
- 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 +2 -2
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/renderer.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/hooks/useZoom.d.ts.map +1 -1
- package/dist/types/src/stories/hooks.stories.d.ts +13 -8
- 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/src/util/screen.d.ts +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -26
- package/src/components/Graph/Graph.stories.tsx +58 -56
- package/src/components/Graph/Graph.tsx +24 -17
- package/src/components/Mesh/Mesh.stories.tsx +11 -9
- package/src/components/Mesh/Mesh.tsx +1 -1
- package/src/components/SVG/Grid.tsx +2 -2
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Root.tsx +14 -7
- package/src/components/SVG/SVG.tsx +14 -4
- package/src/components/SVG/Svg.stories.tsx +23 -18
- package/src/components/SVG/Zoom.tsx +1 -1
- package/src/fx/fx.stories.tsx +15 -11
- package/src/graph/projector/graph-drag.ts +2 -1
- package/src/graph/projector/graph-force-projector.ts +3 -2
- package/src/graph/projector/graph-forces.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +5 -4
- package/src/graph/projector/graph-projector.ts +6 -5
- package/src/graph/projector/graph-radial-projector.ts +4 -3
- package/src/graph/projector/graph-relational-projector.ts +5 -4
- package/src/graph/projector/projector.ts +1 -1
- package/src/graph/renderer/bullets.ts +1 -1
- package/src/graph/renderer/graph-renderer.ts +4 -3
- package/src/graph/renderer/renderer.ts +1 -1
- package/src/graph/types.ts +1 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/hooks/useZoom.ts +1 -1
- package/src/stories/hooks.stories.tsx +42 -35
- package/src/testing/data.ts +5 -5
- package/src/testing/hooks.ts +4 -3
- package/src/testing/model.ts +3 -3
- package/src/util/fraction.ts +1 -1
- package/src/util/screen.test.ts +1 -1
- package/src/util/screen.ts +1 -1
- package/src/util/vector.ts +1 -1
- package/styles/graph.css +292 -43
- package/dist/lib/browser/chunk-MGVY54T5.mjs +0 -979
- package/dist/lib/browser/chunk-MGVY54T5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-X5YVOSXZ.mjs +0 -981
- package/dist/lib/node-esm/chunk-X5YVOSXZ.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-X5YVOSXZ.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,11 +162,585 @@ var emptyGraph = {
|
|
|
179
162
|
edges: []
|
|
180
163
|
};
|
|
181
164
|
|
|
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-sm 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
|
+
]
|
|
304
|
+
});
|
|
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
|
+
}
|
|
424
|
+
}
|
|
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
|
+
|
|
182
737
|
// src/graph/projector/projector.ts
|
|
183
738
|
var Projector = class {
|
|
739
|
+
_context;
|
|
740
|
+
updated = new EventEmitter();
|
|
741
|
+
_options;
|
|
184
742
|
constructor(_context, options) {
|
|
185
743
|
this._context = _context;
|
|
186
|
-
this.updated = new EventEmitter();
|
|
187
744
|
this._options = Object.assign({
|
|
188
745
|
idAccessor: defaultIdAccessor
|
|
189
746
|
}, options);
|
|
@@ -228,6 +785,8 @@ var Projector = class {
|
|
|
228
785
|
|
|
229
786
|
// src/graph/projector/graph-projector.ts
|
|
230
787
|
var GraphProjector = class extends Projector {
|
|
788
|
+
_selection;
|
|
789
|
+
_layout;
|
|
231
790
|
// TODO(burdon): Change to object props.
|
|
232
791
|
constructor(context, options, _selection, layout) {
|
|
233
792
|
super(context, options), this._selection = _selection;
|
|
@@ -311,7 +870,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
311
870
|
};
|
|
312
871
|
|
|
313
872
|
// src/graph/projector/graph-force-projector.ts
|
|
314
|
-
var
|
|
873
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
315
874
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
316
875
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
317
876
|
};
|
|
@@ -328,11 +887,9 @@ var defaultForceOptions = {
|
|
|
328
887
|
point: true
|
|
329
888
|
};
|
|
330
889
|
var GraphForceProjector = class extends GraphProjector {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this._simulation = forceSimulation();
|
|
335
|
-
}
|
|
890
|
+
// https://github.com/d3/d3-force
|
|
891
|
+
_simulation = forceSimulation();
|
|
892
|
+
_timeout;
|
|
336
893
|
get forces() {
|
|
337
894
|
return this.options.forces ?? defaultForceOptions;
|
|
338
895
|
}
|
|
@@ -386,8 +943,8 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
386
943
|
edges: graph?.edges.length
|
|
387
944
|
}
|
|
388
945
|
}, {
|
|
389
|
-
F:
|
|
390
|
-
L:
|
|
946
|
+
F: __dxlog_file3,
|
|
947
|
+
L: 227,
|
|
391
948
|
S: this,
|
|
392
949
|
C: (f, a) => f(...a)
|
|
393
950
|
});
|
|
@@ -441,8 +998,8 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
441
998
|
log("updateForces", {
|
|
442
999
|
forces
|
|
443
1000
|
}, {
|
|
444
|
-
F:
|
|
445
|
-
L:
|
|
1001
|
+
F: __dxlog_file3,
|
|
1002
|
+
L: 288,
|
|
446
1003
|
S: this,
|
|
447
1004
|
C: (f, a) => f(...a)
|
|
448
1005
|
});
|
|
@@ -514,8 +1071,9 @@ import { log as log3 } from "@dxos/log";
|
|
|
514
1071
|
// src/graph/projector/graph-radial-projector.ts
|
|
515
1072
|
import { easeCubic, timer } from "d3";
|
|
516
1073
|
import { log as log2 } from "@dxos/log";
|
|
517
|
-
var
|
|
1074
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
518
1075
|
var GraphRadialProjector = class extends GraphProjector {
|
|
1076
|
+
_timer;
|
|
519
1077
|
findNode(x, y, radius) {
|
|
520
1078
|
return void 0;
|
|
521
1079
|
}
|
|
@@ -526,8 +1084,8 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
526
1084
|
edges: graph?.edges.length
|
|
527
1085
|
}
|
|
528
1086
|
}, {
|
|
529
|
-
F:
|
|
530
|
-
L:
|
|
1087
|
+
F: __dxlog_file4,
|
|
1088
|
+
L: 32,
|
|
531
1089
|
S: this,
|
|
532
1090
|
C: (f, a) => f(...a)
|
|
533
1091
|
});
|
|
@@ -626,7 +1184,7 @@ var layoutVertical = (x, y, h, n) => {
|
|
|
626
1184
|
};
|
|
627
1185
|
|
|
628
1186
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
629
|
-
var
|
|
1187
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
630
1188
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
631
1189
|
onUpdate(graph) {
|
|
632
1190
|
log3("onUpdate", {
|
|
@@ -634,15 +1192,15 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
634
1192
|
nodes: graph?.nodes.length,
|
|
635
1193
|
edges: graph?.edges.length
|
|
636
1194
|
},
|
|
637
|
-
selection: this.selection?.
|
|
1195
|
+
selection: this.selection?.getSelectedIds()
|
|
638
1196
|
}, {
|
|
639
|
-
F:
|
|
640
|
-
L:
|
|
1197
|
+
F: __dxlog_file5,
|
|
1198
|
+
L: 24,
|
|
641
1199
|
S: this,
|
|
642
1200
|
C: (f, a) => f(...a)
|
|
643
1201
|
});
|
|
644
1202
|
this.mergeData(graph);
|
|
645
|
-
const selected = this.selection?.
|
|
1203
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
646
1204
|
if (selected) {
|
|
647
1205
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
648
1206
|
if (node) {
|
|
@@ -689,7 +1247,7 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
689
1247
|
|
|
690
1248
|
// src/graph/projector/graph-relational-projector.ts
|
|
691
1249
|
import { log as log4 } from "@dxos/log";
|
|
692
|
-
var
|
|
1250
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
693
1251
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
694
1252
|
onUpdate(graph) {
|
|
695
1253
|
log4("onUpdate", {
|
|
@@ -697,15 +1255,15 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
697
1255
|
nodes: graph?.nodes.length,
|
|
698
1256
|
edges: graph?.edges.length
|
|
699
1257
|
},
|
|
700
|
-
selection: this.selection?.
|
|
1258
|
+
selection: this.selection?.getSelectedIds()
|
|
701
1259
|
}, {
|
|
702
|
-
F:
|
|
703
|
-
L:
|
|
1260
|
+
F: __dxlog_file6,
|
|
1261
|
+
L: 24,
|
|
704
1262
|
S: this,
|
|
705
1263
|
C: (f, a) => f(...a)
|
|
706
1264
|
});
|
|
707
1265
|
this.mergeData(graph);
|
|
708
|
-
const selected = this.selection?.
|
|
1266
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
709
1267
|
if (selected) {
|
|
710
1268
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
711
1269
|
if (node) {
|
|
@@ -777,7 +1335,7 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
777
1335
|
};
|
|
778
1336
|
|
|
779
1337
|
// src/graph/renderer/graph-renderer.ts
|
|
780
|
-
import { line as line2, select as select4
|
|
1338
|
+
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
781
1339
|
import * as Clipper from "js-clipper";
|
|
782
1340
|
import { log as log5 } from "@dxos/log";
|
|
783
1341
|
|
|
@@ -812,9 +1370,12 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
812
1370
|
};
|
|
813
1371
|
|
|
814
1372
|
// src/graph/renderer/renderer.ts
|
|
815
|
-
import { invariant as
|
|
816
|
-
var
|
|
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";
|
|
817
1375
|
var Renderer = class {
|
|
1376
|
+
_context;
|
|
1377
|
+
_root;
|
|
1378
|
+
_options;
|
|
818
1379
|
constructor(_context, _root, options) {
|
|
819
1380
|
this._context = _context;
|
|
820
1381
|
this._root = _root;
|
|
@@ -826,8 +1387,8 @@ var Renderer = class {
|
|
|
826
1387
|
return this._context;
|
|
827
1388
|
}
|
|
828
1389
|
get root() {
|
|
829
|
-
|
|
830
|
-
F:
|
|
1390
|
+
invariant3(this._root.current, "SVG root is not initialized", {
|
|
1391
|
+
F: __dxlog_file7,
|
|
831
1392
|
L: 40,
|
|
832
1393
|
S: this,
|
|
833
1394
|
A: [
|
|
@@ -843,13 +1404,13 @@ var Renderer = class {
|
|
|
843
1404
|
};
|
|
844
1405
|
|
|
845
1406
|
// src/graph/renderer/graph-renderer.ts
|
|
846
|
-
var
|
|
1407
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
847
1408
|
var createLine2 = line2();
|
|
848
1409
|
var GraphRenderer = class extends Renderer {
|
|
849
1410
|
render(layout) {
|
|
850
1411
|
log5("render", layout, {
|
|
851
|
-
F:
|
|
852
|
-
L:
|
|
1412
|
+
F: __dxlog_file8,
|
|
1413
|
+
L: 63,
|
|
853
1414
|
S: this,
|
|
854
1415
|
C: (f, a) => f(...a)
|
|
855
1416
|
});
|
|
@@ -996,8 +1557,8 @@ var updateNode2 = (group, options) => {
|
|
|
996
1557
|
log5.error("updateNode", {
|
|
997
1558
|
error: error?.message
|
|
998
1559
|
}, {
|
|
999
|
-
F:
|
|
1000
|
-
L:
|
|
1560
|
+
F: __dxlog_file8,
|
|
1561
|
+
L: 305,
|
|
1001
1562
|
S: void 0,
|
|
1002
1563
|
C: (f, a) => f(...a)
|
|
1003
1564
|
});
|
|
@@ -1052,8 +1613,8 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1052
1613
|
log5.error("updateEdge", {
|
|
1053
1614
|
error: error?.message
|
|
1054
1615
|
}, {
|
|
1055
|
-
F:
|
|
1056
|
-
L:
|
|
1616
|
+
F: __dxlog_file8,
|
|
1617
|
+
L: 417,
|
|
1057
1618
|
S: void 0,
|
|
1058
1619
|
C: (f, a) => f(...a)
|
|
1059
1620
|
});
|
|
@@ -1134,112 +1695,427 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1134
1695
|
});
|
|
1135
1696
|
};
|
|
1136
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
|
+
|
|
1137
2016
|
// src/components/Graph/Graph.tsx
|
|
1138
|
-
var
|
|
1139
|
-
var GraphInner = ({ classNames, model, projector:
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
2017
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
2018
|
+
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
2019
|
+
const context = useSvgContext();
|
|
2020
|
+
const graphRef = useRef3(null);
|
|
2021
|
+
const { projector, renderer } = useMemo3(() => {
|
|
2022
|
+
let projector2 = projectorProp;
|
|
2023
|
+
if (!projector2) {
|
|
2024
|
+
projector2 = new GraphForceProjector(context);
|
|
2025
|
+
}
|
|
2026
|
+
let renderer2 = rendererProp;
|
|
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
|
+
projectorProp,
|
|
2046
|
+
rendererProp,
|
|
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)
|
|
1160
2079
|
});
|
|
1161
2080
|
}
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
return graphRef.current?.querySelector(`g[data-id="${id}"]`);
|
|
1181
|
-
}
|
|
1182
|
-
}), [
|
|
1183
|
-
model,
|
|
1184
|
-
projector,
|
|
1185
|
-
renderer
|
|
1186
|
-
]);
|
|
1187
|
-
useEffect(() => {
|
|
1188
|
-
return combine(effect(() => {
|
|
1189
|
-
projector.updateData(model?.graph);
|
|
1190
|
-
}), projector.updated.on(({ layout }) => {
|
|
1191
|
-
try {
|
|
1192
|
-
renderer.render(layout);
|
|
1193
|
-
} catch (error) {
|
|
1194
|
-
void projector.stop();
|
|
1195
|
-
log6.catch(error, void 0, {
|
|
1196
|
-
F: __dxlog_file8,
|
|
1197
|
-
L: 108,
|
|
1198
|
-
S: void 0,
|
|
1199
|
-
C: (f, a) => f(...a)
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
}));
|
|
1203
|
-
}, [
|
|
1204
|
-
model,
|
|
1205
|
-
projector,
|
|
1206
|
-
renderer
|
|
1207
|
-
]);
|
|
1208
|
-
useEffect(() => {
|
|
1209
|
-
void projector.start();
|
|
1210
|
-
return () => {
|
|
1211
|
-
void projector.stop();
|
|
1212
|
-
};
|
|
1213
|
-
}, [
|
|
1214
|
-
projector
|
|
1215
|
-
]);
|
|
1216
|
-
return /* @__PURE__ */ React.createElement("g", {
|
|
1217
|
-
ref: graphRef,
|
|
1218
|
-
className: mx("dx-graph", classNames)
|
|
1219
|
-
});
|
|
1220
|
-
} finally {
|
|
1221
|
-
_effect.f();
|
|
1222
|
-
}
|
|
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
|
+
});
|
|
1223
2099
|
};
|
|
1224
2100
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1225
2101
|
|
|
1226
2102
|
// src/components/Mesh/Mesh.tsx
|
|
1227
|
-
import { geoPath, select as
|
|
1228
|
-
import { useEffect as
|
|
2103
|
+
import { geoPath, select as select7 } from "d3";
|
|
2104
|
+
import { useEffect as useEffect4 } from "react";
|
|
1229
2105
|
import { feature, mesh } from "topojson-client";
|
|
1230
2106
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1231
2107
|
const { svg, size } = useSvgContext();
|
|
1232
|
-
|
|
2108
|
+
useEffect4(() => {
|
|
1233
2109
|
if (size) {
|
|
1234
2110
|
const topology = hexTopology(size, radius, value);
|
|
1235
2111
|
const projection = hexProjection(radius);
|
|
1236
2112
|
const path = geoPath().projection(projection);
|
|
1237
|
-
|
|
1238
|
-
|
|
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);
|
|
1239
2115
|
const redraw = (border) => {
|
|
1240
2116
|
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1241
2117
|
};
|
|
1242
|
-
|
|
2118
|
+
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
1243
2119
|
}
|
|
1244
2120
|
}, [
|
|
1245
2121
|
svg,
|
|
@@ -1356,115 +2232,95 @@ var hexProjection = (radius) => {
|
|
|
1356
2232
|
};
|
|
1357
2233
|
|
|
1358
2234
|
// src/components/SVG/Grid.tsx
|
|
1359
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
1360
2235
|
import React2 from "react";
|
|
1361
|
-
import { mx as mx2 } from "@dxos/
|
|
2236
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1362
2237
|
var Grid = ({ classNames, ...props }) => {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
className: mx2("dx-grid", classNames)
|
|
1369
|
-
});
|
|
1370
|
-
} finally {
|
|
1371
|
-
_effect.f();
|
|
1372
|
-
}
|
|
2238
|
+
const { ref } = useGrid(props);
|
|
2239
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
2240
|
+
ref,
|
|
2241
|
+
className: mx2("dx-grid", classNames)
|
|
2242
|
+
});
|
|
1373
2243
|
};
|
|
1374
2244
|
|
|
1375
2245
|
// src/components/SVG/Markers.tsx
|
|
1376
|
-
import {
|
|
1377
|
-
import {
|
|
1378
|
-
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";
|
|
1379
2248
|
var Markers = ({ arrowSize, className }) => {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
className
|
|
1393
|
-
});
|
|
1394
|
-
} finally {
|
|
1395
|
-
_effect.f();
|
|
1396
|
-
}
|
|
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
|
+
});
|
|
1397
2261
|
};
|
|
1398
2262
|
|
|
1399
2263
|
// src/components/SVG/Root.tsx
|
|
1400
|
-
import {
|
|
1401
|
-
import {
|
|
1402
|
-
import React4, { forwardRef as forwardRef2, useEffect as useEffect4, useMemo as useMemo2, useImperativeHandle as useImperativeHandle2 } 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";
|
|
1403
2266
|
import { useResizeDetector } from "react-resize-detector";
|
|
1404
|
-
import { mx as mx3 } from "@dxos/
|
|
1405
|
-
var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, ...props }, ref) => {
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
2267
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
2268
|
+
var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, scale, centered, ...props }, ref) => {
|
|
2269
|
+
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
|
|
2270
|
+
refreshRate: 200
|
|
2271
|
+
});
|
|
2272
|
+
const context = useMemo4(() => {
|
|
2273
|
+
return new SVGContext({
|
|
2274
|
+
scale,
|
|
2275
|
+
centered
|
|
1410
2276
|
});
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
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
|
-
}, ready && children)));
|
|
1444
|
-
} finally {
|
|
1445
|
-
_effect.f();
|
|
1446
|
-
}
|
|
2277
|
+
}, [
|
|
2278
|
+
scale,
|
|
2279
|
+
centered
|
|
2280
|
+
]);
|
|
2281
|
+
useImperativeHandle2(ref, () => context, [
|
|
2282
|
+
context
|
|
2283
|
+
]);
|
|
2284
|
+
useEffect6(() => {
|
|
2285
|
+
if (width && height) {
|
|
2286
|
+
context.setSize({
|
|
2287
|
+
width,
|
|
2288
|
+
height
|
|
2289
|
+
});
|
|
2290
|
+
select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
2291
|
+
}
|
|
2292
|
+
}, [
|
|
2293
|
+
context,
|
|
2294
|
+
width,
|
|
2295
|
+
height
|
|
2296
|
+
]);
|
|
2297
|
+
const ready = width !== 0 && height !== 0;
|
|
2298
|
+
return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
|
|
2299
|
+
value: context
|
|
2300
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
2301
|
+
...props,
|
|
2302
|
+
ref: containerRef,
|
|
2303
|
+
className: mx3("grid grow overflow-hidden", classNames)
|
|
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)));
|
|
1447
2309
|
});
|
|
1448
2310
|
|
|
1449
2311
|
// src/components/SVG/Zoom.tsx
|
|
1450
|
-
import {
|
|
1451
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
2312
|
+
import React5, { memo, useMemo as useMemo5 } from "react";
|
|
1452
2313
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
className
|
|
1464
|
-
}, children);
|
|
1465
|
-
} finally {
|
|
1466
|
-
_effect.f();
|
|
1467
|
-
}
|
|
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);
|
|
1468
2324
|
});
|
|
1469
2325
|
|
|
1470
2326
|
// src/components/SVG/SVG.tsx
|
|
@@ -1478,7 +2334,7 @@ var SVG = {
|
|
|
1478
2334
|
};
|
|
1479
2335
|
|
|
1480
2336
|
// src/fx/pulsar.ts
|
|
1481
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
2337
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1482
2338
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1483
2339
|
(function(Pulsar2) {
|
|
1484
2340
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1493,10 +2349,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1493
2349
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1494
2350
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1495
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() {
|
|
1496
|
-
if (
|
|
1497
|
-
startAnimation(
|
|
2352
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
2353
|
+
startAnimation(select10(this), r, options);
|
|
1498
2354
|
} else {
|
|
1499
|
-
|
|
2355
|
+
select10(this).remove();
|
|
1500
2356
|
}
|
|
1501
2357
|
});
|
|
1502
2358
|
};
|
|
@@ -1507,7 +2363,6 @@ export {
|
|
|
1507
2363
|
Graph,
|
|
1508
2364
|
GraphForceProjector,
|
|
1509
2365
|
GraphHierarchicalProjector,
|
|
1510
|
-
GraphInner,
|
|
1511
2366
|
GraphProjector,
|
|
1512
2367
|
GraphRadialProjector,
|
|
1513
2368
|
GraphRelationalProjector,
|