@dxos/react-ui-graph 0.8.3 → 0.8.4-main.1068cf700f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-LKC455GK.mjs +52 -0
- package/dist/lib/browser/chunk-LKC455GK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1122 -271
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +6 -6
- 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 +1122 -271
- 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 +6 -6
- 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 +17 -8
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts +10 -6
- 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 +1 -1
- 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 +14 -9
- 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/index.d.ts +2 -2
- package/dist/types/src/util/index.d.ts.map +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 +19 -12
- 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 +2 -2
- 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 +4 -3
- 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/index.ts +2 -2
- package/src/util/screen.test.ts +1 -1
- package/src/util/screen.ts +1 -1
- package/src/util/vector.ts +1 -1
- package/dist/lib/browser/chunk-2YMRPQU7.mjs +0 -979
- package/dist/lib/browser/chunk-2YMRPQU7.mjs.map +0 -7
- package/dist/lib/node/chunk-WFHWEMPB.cjs +0 -919
- package/dist/lib/node/chunk-WFHWEMPB.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -1547
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -214
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs +0 -981
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs.map +0 -7
|
@@ -1,33 +1,16 @@
|
|
|
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-2YMRPQU7.mjs";
|
|
4
|
+
useTimestamp
|
|
5
|
+
} from "./chunk-LKC455GK.mjs";
|
|
21
6
|
|
|
22
|
-
//
|
|
23
|
-
import {
|
|
24
|
-
import { effect } from "@preact/signals-core";
|
|
25
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
7
|
+
// src/components/Graph/Graph.tsx
|
|
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";
|
|
32
15
|
var createLine = line();
|
|
33
16
|
var createArrow = (length, offset, start) => (el) => {
|
|
@@ -78,7 +61,7 @@ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
|
|
|
78
61
|
});
|
|
79
62
|
};
|
|
80
63
|
|
|
81
|
-
//
|
|
64
|
+
// src/graph/projector/graph-drag.ts
|
|
82
65
|
import { drag, pointer, select as select2 } from "d3";
|
|
83
66
|
var defaultDragOptions = {
|
|
84
67
|
linkMod: "metaKey",
|
|
@@ -158,9 +141,9 @@ var createGraphDrag = (context, projector, options = defaultDragOptions) => {
|
|
|
158
141
|
});
|
|
159
142
|
};
|
|
160
143
|
|
|
161
|
-
//
|
|
144
|
+
// src/graph/types.ts
|
|
162
145
|
import { invariant } from "@dxos/invariant";
|
|
163
|
-
var __dxlog_file = "/
|
|
146
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
|
|
164
147
|
var defaultIdAccessor = (node) => {
|
|
165
148
|
invariant(node.id, void 0, {
|
|
166
149
|
F: __dxlog_file,
|
|
@@ -178,11 +161,585 @@ var emptyGraph = {
|
|
|
178
161
|
edges: []
|
|
179
162
|
};
|
|
180
163
|
|
|
181
|
-
//
|
|
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 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
|
+
|
|
736
|
+
// src/graph/projector/projector.ts
|
|
182
737
|
var Projector = class {
|
|
738
|
+
_context;
|
|
739
|
+
updated = new EventEmitter();
|
|
740
|
+
_options;
|
|
183
741
|
constructor(_context, options) {
|
|
184
742
|
this._context = _context;
|
|
185
|
-
this.updated = new EventEmitter();
|
|
186
743
|
this._options = Object.assign({
|
|
187
744
|
idAccessor: defaultIdAccessor
|
|
188
745
|
}, options);
|
|
@@ -225,8 +782,10 @@ var Projector = class {
|
|
|
225
782
|
}
|
|
226
783
|
};
|
|
227
784
|
|
|
228
|
-
//
|
|
785
|
+
// src/graph/projector/graph-projector.ts
|
|
229
786
|
var GraphProjector = class extends Projector {
|
|
787
|
+
_selection;
|
|
788
|
+
_layout;
|
|
230
789
|
// TODO(burdon): Change to object props.
|
|
231
790
|
constructor(context, options, _selection, layout) {
|
|
232
791
|
super(context, options), this._selection = _selection;
|
|
@@ -289,11 +848,11 @@ var GraphProjector = class extends Projector {
|
|
|
289
848
|
}
|
|
290
849
|
};
|
|
291
850
|
|
|
292
|
-
//
|
|
851
|
+
// src/graph/projector/graph-force-projector.ts
|
|
293
852
|
import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
|
|
294
853
|
import { log } from "@dxos/log";
|
|
295
854
|
|
|
296
|
-
//
|
|
855
|
+
// src/graph/projector/graph-forces.ts
|
|
297
856
|
import { forceX, forceY } from "d3";
|
|
298
857
|
var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
299
858
|
const fx = x != null ? forceX(x).strength(strength) : void 0;
|
|
@@ -309,8 +868,8 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
309
868
|
return force;
|
|
310
869
|
};
|
|
311
870
|
|
|
312
|
-
//
|
|
313
|
-
var
|
|
871
|
+
// src/graph/projector/graph-force-projector.ts
|
|
872
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
314
873
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
315
874
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
316
875
|
};
|
|
@@ -327,11 +886,9 @@ var defaultForceOptions = {
|
|
|
327
886
|
point: true
|
|
328
887
|
};
|
|
329
888
|
var GraphForceProjector = class extends GraphProjector {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
this._simulation = forceSimulation();
|
|
334
|
-
}
|
|
889
|
+
// https://github.com/d3/d3-force
|
|
890
|
+
_simulation = forceSimulation();
|
|
891
|
+
_timeout;
|
|
335
892
|
get forces() {
|
|
336
893
|
return this.options.forces ?? defaultForceOptions;
|
|
337
894
|
}
|
|
@@ -385,8 +942,8 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
385
942
|
edges: graph?.edges.length
|
|
386
943
|
}
|
|
387
944
|
}, {
|
|
388
|
-
F:
|
|
389
|
-
L:
|
|
945
|
+
F: __dxlog_file3,
|
|
946
|
+
L: 227,
|
|
390
947
|
S: this,
|
|
391
948
|
C: (f, a) => f(...a)
|
|
392
949
|
});
|
|
@@ -440,8 +997,8 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
440
997
|
log("updateForces", {
|
|
441
998
|
forces
|
|
442
999
|
}, {
|
|
443
|
-
F:
|
|
444
|
-
L:
|
|
1000
|
+
F: __dxlog_file3,
|
|
1001
|
+
L: 288,
|
|
445
1002
|
S: this,
|
|
446
1003
|
C: (f, a) => f(...a)
|
|
447
1004
|
});
|
|
@@ -507,14 +1064,15 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
507
1064
|
}
|
|
508
1065
|
};
|
|
509
1066
|
|
|
510
|
-
//
|
|
1067
|
+
// src/graph/projector/graph-hierarchical-projector.ts
|
|
511
1068
|
import { log as log3 } from "@dxos/log";
|
|
512
1069
|
|
|
513
|
-
//
|
|
1070
|
+
// src/graph/projector/graph-radial-projector.ts
|
|
514
1071
|
import { easeCubic, timer } from "d3";
|
|
515
1072
|
import { log as log2 } from "@dxos/log";
|
|
516
|
-
var
|
|
1073
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
517
1074
|
var GraphRadialProjector = class extends GraphProjector {
|
|
1075
|
+
_timer;
|
|
518
1076
|
findNode(x, y, radius) {
|
|
519
1077
|
return void 0;
|
|
520
1078
|
}
|
|
@@ -525,8 +1083,8 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
525
1083
|
edges: graph?.edges.length
|
|
526
1084
|
}
|
|
527
1085
|
}, {
|
|
528
|
-
F:
|
|
529
|
-
L:
|
|
1086
|
+
F: __dxlog_file4,
|
|
1087
|
+
L: 32,
|
|
530
1088
|
S: this,
|
|
531
1089
|
C: (f, a) => f(...a)
|
|
532
1090
|
});
|
|
@@ -624,8 +1182,8 @@ var layoutVertical = (x, y, h, n) => {
|
|
|
624
1182
|
};
|
|
625
1183
|
};
|
|
626
1184
|
|
|
627
|
-
//
|
|
628
|
-
var
|
|
1185
|
+
// src/graph/projector/graph-hierarchical-projector.ts
|
|
1186
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
629
1187
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
630
1188
|
onUpdate(graph) {
|
|
631
1189
|
log3("onUpdate", {
|
|
@@ -633,15 +1191,15 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
633
1191
|
nodes: graph?.nodes.length,
|
|
634
1192
|
edges: graph?.edges.length
|
|
635
1193
|
},
|
|
636
|
-
selection: this.selection?.
|
|
1194
|
+
selection: this.selection?.getSelectedIds()
|
|
637
1195
|
}, {
|
|
638
|
-
F:
|
|
639
|
-
L:
|
|
1196
|
+
F: __dxlog_file5,
|
|
1197
|
+
L: 24,
|
|
640
1198
|
S: this,
|
|
641
1199
|
C: (f, a) => f(...a)
|
|
642
1200
|
});
|
|
643
1201
|
this.mergeData(graph);
|
|
644
|
-
const selected = this.selection?.
|
|
1202
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
645
1203
|
if (selected) {
|
|
646
1204
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
647
1205
|
if (node) {
|
|
@@ -686,9 +1244,9 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
686
1244
|
}
|
|
687
1245
|
};
|
|
688
1246
|
|
|
689
|
-
//
|
|
1247
|
+
// src/graph/projector/graph-relational-projector.ts
|
|
690
1248
|
import { log as log4 } from "@dxos/log";
|
|
691
|
-
var
|
|
1249
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
692
1250
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
693
1251
|
onUpdate(graph) {
|
|
694
1252
|
log4("onUpdate", {
|
|
@@ -696,15 +1254,15 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
696
1254
|
nodes: graph?.nodes.length,
|
|
697
1255
|
edges: graph?.edges.length
|
|
698
1256
|
},
|
|
699
|
-
selection: this.selection?.
|
|
1257
|
+
selection: this.selection?.getSelectedIds()
|
|
700
1258
|
}, {
|
|
701
|
-
F:
|
|
702
|
-
L:
|
|
1259
|
+
F: __dxlog_file6,
|
|
1260
|
+
L: 24,
|
|
703
1261
|
S: this,
|
|
704
1262
|
C: (f, a) => f(...a)
|
|
705
1263
|
});
|
|
706
1264
|
this.mergeData(graph);
|
|
707
|
-
const selected = this.selection?.
|
|
1265
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
708
1266
|
if (selected) {
|
|
709
1267
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
710
1268
|
if (node) {
|
|
@@ -775,12 +1333,12 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
775
1333
|
}
|
|
776
1334
|
};
|
|
777
1335
|
|
|
778
|
-
//
|
|
779
|
-
import { line as line2, select as select4
|
|
1336
|
+
// src/graph/renderer/graph-renderer.ts
|
|
1337
|
+
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
780
1338
|
import * as Clipper from "js-clipper";
|
|
781
1339
|
import { log as log5 } from "@dxos/log";
|
|
782
1340
|
|
|
783
|
-
//
|
|
1341
|
+
// src/graph/renderer/bullets.ts
|
|
784
1342
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
785
1343
|
var createBullets = (group, nodeId, options = {}) => {
|
|
786
1344
|
return (selection) => {
|
|
@@ -810,10 +1368,13 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
810
1368
|
};
|
|
811
1369
|
};
|
|
812
1370
|
|
|
813
|
-
//
|
|
814
|
-
import { invariant as
|
|
815
|
-
var
|
|
1371
|
+
// src/graph/renderer/renderer.ts
|
|
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";
|
|
816
1374
|
var Renderer = class {
|
|
1375
|
+
_context;
|
|
1376
|
+
_root;
|
|
1377
|
+
_options;
|
|
817
1378
|
constructor(_context, _root, options) {
|
|
818
1379
|
this._context = _context;
|
|
819
1380
|
this._root = _root;
|
|
@@ -825,8 +1386,8 @@ var Renderer = class {
|
|
|
825
1386
|
return this._context;
|
|
826
1387
|
}
|
|
827
1388
|
get root() {
|
|
828
|
-
|
|
829
|
-
F:
|
|
1389
|
+
invariant3(this._root.current, "SVG root is not initialized", {
|
|
1390
|
+
F: __dxlog_file7,
|
|
830
1391
|
L: 40,
|
|
831
1392
|
S: this,
|
|
832
1393
|
A: [
|
|
@@ -841,14 +1402,14 @@ var Renderer = class {
|
|
|
841
1402
|
}
|
|
842
1403
|
};
|
|
843
1404
|
|
|
844
|
-
//
|
|
845
|
-
var
|
|
1405
|
+
// src/graph/renderer/graph-renderer.ts
|
|
1406
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
846
1407
|
var createLine2 = line2();
|
|
847
1408
|
var GraphRenderer = class extends Renderer {
|
|
848
1409
|
render(layout) {
|
|
849
1410
|
log5("render", layout, {
|
|
850
|
-
F:
|
|
851
|
-
L:
|
|
1411
|
+
F: __dxlog_file8,
|
|
1412
|
+
L: 63,
|
|
852
1413
|
S: this,
|
|
853
1414
|
C: (f, a) => f(...a)
|
|
854
1415
|
});
|
|
@@ -995,8 +1556,8 @@ var updateNode2 = (group, options) => {
|
|
|
995
1556
|
log5.error("updateNode", {
|
|
996
1557
|
error: error?.message
|
|
997
1558
|
}, {
|
|
998
|
-
F:
|
|
999
|
-
L:
|
|
1559
|
+
F: __dxlog_file8,
|
|
1560
|
+
L: 305,
|
|
1000
1561
|
S: void 0,
|
|
1001
1562
|
C: (f, a) => f(...a)
|
|
1002
1563
|
});
|
|
@@ -1051,8 +1612,8 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1051
1612
|
log5.error("updateEdge", {
|
|
1052
1613
|
error: error?.message
|
|
1053
1614
|
}, {
|
|
1054
|
-
F:
|
|
1055
|
-
L:
|
|
1615
|
+
F: __dxlog_file8,
|
|
1616
|
+
L: 417,
|
|
1056
1617
|
S: void 0,
|
|
1057
1618
|
C: (f, a) => f(...a)
|
|
1058
1619
|
});
|
|
@@ -1110,7 +1671,7 @@ var findConnectedComponents = (graph) => {
|
|
|
1110
1671
|
return components;
|
|
1111
1672
|
};
|
|
1112
1673
|
|
|
1113
|
-
//
|
|
1674
|
+
// src/graph/renderer/linker.ts
|
|
1114
1675
|
import { line as line3 } from "d3";
|
|
1115
1676
|
var createLine3 = line3();
|
|
1116
1677
|
var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
@@ -1133,112 +1694,427 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1133
1694
|
});
|
|
1134
1695
|
};
|
|
1135
1696
|
|
|
1136
|
-
//
|
|
1137
|
-
|
|
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
|
+
|
|
2015
|
+
// src/components/Graph/Graph.tsx
|
|
2016
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
1138
2017
|
var GraphInner = ({ classNames, model, projector: _projector, renderer: _renderer, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
2018
|
+
const context = useSvgContext();
|
|
2019
|
+
const graphRef = useRef3(null);
|
|
2020
|
+
const { projector, renderer } = useMemo3(() => {
|
|
2021
|
+
let projector2 = _projector;
|
|
2022
|
+
if (!projector2) {
|
|
2023
|
+
projector2 = new GraphForceProjector(context);
|
|
2024
|
+
}
|
|
2025
|
+
let renderer2 = _renderer;
|
|
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
|
+
_projector,
|
|
2045
|
+
_renderer,
|
|
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 && "subscribe" in 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: 115,
|
|
2076
|
+
S: void 0,
|
|
2077
|
+
C: (f, a) => f(...a)
|
|
1159
2078
|
});
|
|
1160
2079
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
return graphRef.current?.querySelector(`g[data-id="${id}"]`);
|
|
1180
|
-
}
|
|
1181
|
-
}), [
|
|
1182
|
-
model,
|
|
1183
|
-
projector,
|
|
1184
|
-
renderer
|
|
1185
|
-
]);
|
|
1186
|
-
useEffect(() => {
|
|
1187
|
-
return combine(effect(() => {
|
|
1188
|
-
projector.updateData(model?.graph);
|
|
1189
|
-
}), projector.updated.on(({ layout }) => {
|
|
1190
|
-
try {
|
|
1191
|
-
renderer.render(layout);
|
|
1192
|
-
} catch (error) {
|
|
1193
|
-
void projector.stop();
|
|
1194
|
-
log6.catch(error, void 0, {
|
|
1195
|
-
F: __dxlog_file8,
|
|
1196
|
-
L: 108,
|
|
1197
|
-
S: void 0,
|
|
1198
|
-
C: (f, a) => f(...a)
|
|
1199
|
-
});
|
|
1200
|
-
}
|
|
1201
|
-
}));
|
|
1202
|
-
}, [
|
|
1203
|
-
model,
|
|
1204
|
-
projector,
|
|
1205
|
-
renderer
|
|
1206
|
-
]);
|
|
1207
|
-
useEffect(() => {
|
|
1208
|
-
void projector.start();
|
|
1209
|
-
return () => {
|
|
1210
|
-
void projector.stop();
|
|
1211
|
-
};
|
|
1212
|
-
}, [
|
|
1213
|
-
projector
|
|
1214
|
-
]);
|
|
1215
|
-
return /* @__PURE__ */ React.createElement("g", {
|
|
1216
|
-
ref: graphRef,
|
|
1217
|
-
className: mx("dx-graph", classNames)
|
|
1218
|
-
});
|
|
1219
|
-
} finally {
|
|
1220
|
-
_effect.f();
|
|
1221
|
-
}
|
|
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
|
+
});
|
|
1222
2098
|
};
|
|
1223
2099
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1224
2100
|
|
|
1225
|
-
//
|
|
1226
|
-
import { geoPath, select as
|
|
1227
|
-
import { useEffect as
|
|
2101
|
+
// src/components/Mesh/Mesh.tsx
|
|
2102
|
+
import { geoPath, select as select7 } from "d3";
|
|
2103
|
+
import { useEffect as useEffect4 } from "react";
|
|
1228
2104
|
import { feature, mesh } from "topojson-client";
|
|
1229
2105
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1230
2106
|
const { svg, size } = useSvgContext();
|
|
1231
|
-
|
|
2107
|
+
useEffect4(() => {
|
|
1232
2108
|
if (size) {
|
|
1233
2109
|
const topology = hexTopology(size, radius, value);
|
|
1234
2110
|
const projection = hexProjection(radius);
|
|
1235
2111
|
const path = geoPath().projection(projection);
|
|
1236
|
-
|
|
1237
|
-
|
|
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);
|
|
1238
2114
|
const redraw = (border) => {
|
|
1239
2115
|
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1240
2116
|
};
|
|
1241
|
-
|
|
2117
|
+
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
1242
2118
|
}
|
|
1243
2119
|
}, [
|
|
1244
2120
|
svg,
|
|
@@ -1354,119 +2230,95 @@ var hexProjection = (radius) => {
|
|
|
1354
2230
|
};
|
|
1355
2231
|
};
|
|
1356
2232
|
|
|
1357
|
-
//
|
|
1358
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
2233
|
+
// src/components/SVG/Grid.tsx
|
|
1359
2234
|
import React2 from "react";
|
|
1360
|
-
import { mx as mx2 } from "@dxos/
|
|
2235
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1361
2236
|
var Grid = ({ classNames, ...props }) => {
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
className: mx2("dx-grid", classNames)
|
|
1368
|
-
});
|
|
1369
|
-
} finally {
|
|
1370
|
-
_effect.f();
|
|
1371
|
-
}
|
|
2237
|
+
const { ref } = useGrid(props);
|
|
2238
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
2239
|
+
ref,
|
|
2240
|
+
className: mx2("dx-grid", classNames)
|
|
2241
|
+
});
|
|
1372
2242
|
};
|
|
1373
2243
|
|
|
1374
|
-
//
|
|
1375
|
-
import {
|
|
1376
|
-
import {
|
|
1377
|
-
import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
2244
|
+
// src/components/SVG/Markers.tsx
|
|
2245
|
+
import { select as select8 } from "d3";
|
|
2246
|
+
import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
1378
2247
|
var Markers = ({ arrowSize, className }) => {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
className
|
|
1392
|
-
});
|
|
1393
|
-
} finally {
|
|
1394
|
-
_effect.f();
|
|
1395
|
-
}
|
|
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
|
+
});
|
|
1396
2260
|
};
|
|
1397
2261
|
|
|
1398
|
-
//
|
|
1399
|
-
import {
|
|
1400
|
-
import {
|
|
1401
|
-
import React4, { forwardRef as forwardRef2, useEffect as useEffect4, useMemo as useMemo2, useImperativeHandle as useImperativeHandle2 } from "react";
|
|
2262
|
+
// src/components/SVG/Root.tsx
|
|
2263
|
+
import { select as select9 } from "d3";
|
|
2264
|
+
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
|
|
1402
2265
|
import { useResizeDetector } from "react-resize-detector";
|
|
1403
|
-
import { mx as mx3 } from "@dxos/
|
|
2266
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
1404
2267
|
var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, ...props }, ref) => {
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
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
|
-
className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
1442
|
-
}, ready && children)));
|
|
1443
|
-
} finally {
|
|
1444
|
-
_effect.f();
|
|
1445
|
-
}
|
|
2268
|
+
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
|
|
2269
|
+
refreshRate: 200
|
|
2270
|
+
});
|
|
2271
|
+
const context = useMemo4(() => {
|
|
2272
|
+
return new SVGContext(props);
|
|
2273
|
+
}, [
|
|
2274
|
+
props.scale,
|
|
2275
|
+
props.centered
|
|
2276
|
+
]);
|
|
2277
|
+
useImperativeHandle2(ref, () => context, [
|
|
2278
|
+
context
|
|
2279
|
+
]);
|
|
2280
|
+
useEffect6(() => {
|
|
2281
|
+
if (width && height) {
|
|
2282
|
+
context.setSize({
|
|
2283
|
+
width,
|
|
2284
|
+
height
|
|
2285
|
+
});
|
|
2286
|
+
select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
2287
|
+
}
|
|
2288
|
+
}, [
|
|
2289
|
+
context,
|
|
2290
|
+
width,
|
|
2291
|
+
height
|
|
2292
|
+
]);
|
|
2293
|
+
const ready = width !== 0 && height !== 0;
|
|
2294
|
+
return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
|
|
2295
|
+
value: context
|
|
2296
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
2297
|
+
ref: containerRef,
|
|
2298
|
+
className: mx3("grid grow overflow-hidden", classNames)
|
|
2299
|
+
}, /* @__PURE__ */ React4.createElement("svg", {
|
|
2300
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2301
|
+
ref: context.ref,
|
|
2302
|
+
className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
2303
|
+
}, ready && children)));
|
|
1446
2304
|
});
|
|
1447
2305
|
|
|
1448
|
-
//
|
|
1449
|
-
import {
|
|
1450
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
2306
|
+
// src/components/SVG/Zoom.tsx
|
|
2307
|
+
import React5, { memo, useMemo as useMemo5 } from "react";
|
|
1451
2308
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
className
|
|
1463
|
-
}, children);
|
|
1464
|
-
} finally {
|
|
1465
|
-
_effect.f();
|
|
1466
|
-
}
|
|
2309
|
+
const options = useMemo5(() => ({
|
|
2310
|
+
extent
|
|
2311
|
+
}), [
|
|
2312
|
+
JSON.stringify(extent)
|
|
2313
|
+
]);
|
|
2314
|
+
const zoom2 = useZoom(options);
|
|
2315
|
+
return /* @__PURE__ */ React5.createElement("g", {
|
|
2316
|
+
ref: zoom2.ref,
|
|
2317
|
+
className
|
|
2318
|
+
}, children);
|
|
1467
2319
|
});
|
|
1468
2320
|
|
|
1469
|
-
//
|
|
2321
|
+
// src/components/SVG/SVG.tsx
|
|
1470
2322
|
var SVG = {
|
|
1471
2323
|
Root,
|
|
1472
2324
|
Grid,
|
|
@@ -1476,8 +2328,8 @@ var SVG = {
|
|
|
1476
2328
|
Graph
|
|
1477
2329
|
};
|
|
1478
2330
|
|
|
1479
|
-
//
|
|
1480
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
2331
|
+
// src/fx/pulsar.ts
|
|
2332
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1481
2333
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1482
2334
|
(function(Pulsar2) {
|
|
1483
2335
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1492,10 +2344,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1492
2344
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1493
2345
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1494
2346
|
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() {
|
|
1495
|
-
if (
|
|
1496
|
-
startAnimation(
|
|
2347
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
2348
|
+
startAnimation(select10(this), r, options);
|
|
1497
2349
|
} else {
|
|
1498
|
-
|
|
2350
|
+
select10(this).remove();
|
|
1499
2351
|
}
|
|
1500
2352
|
});
|
|
1501
2353
|
};
|
|
@@ -1506,7 +2358,6 @@ export {
|
|
|
1506
2358
|
Graph,
|
|
1507
2359
|
GraphForceProjector,
|
|
1508
2360
|
GraphHierarchicalProjector,
|
|
1509
|
-
GraphInner,
|
|
1510
2361
|
GraphProjector,
|
|
1511
2362
|
GraphRadialProjector,
|
|
1512
2363
|
GraphRelationalProjector,
|