@dxos/react-ui-graph 0.8.4-main.c4373fc → 0.8.4-main.cb12b3f963
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-EASNZZ7B.mjs +52 -0
- package/dist/lib/browser/chunk-EASNZZ7B.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1110 -396
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +16 -16
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs +54 -0
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1110 -396
- 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 +16 -16
- 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 +4 -4
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
- 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/Markers.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 +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +3 -3
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/fx/pulsar.d.ts.map +1 -1
- package/dist/types/src/graph/markers.d.ts.map +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 +1 -1
- 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 +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/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.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/useGrid.d.ts.map +1 -1
- package/dist/types/src/hooks/useStateRef.d.ts.map +1 -1
- package/dist/types/src/hooks/useSvgContext.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 +4 -3
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +5 -5
- 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/events.d.ts.map +1 -1
- package/dist/types/src/util/fraction.d.ts +1 -1
- package/dist/types/src/util/fraction.d.ts.map +1 -1
- package/dist/types/src/util/points.d.ts.map +1 -1
- package/dist/types/src/util/scale.d.ts.map +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -34
- package/src/components/Graph/Graph.stories.tsx +48 -42
- package/src/components/Graph/Graph.tsx +23 -15
- package/src/components/Mesh/Mesh.stories.tsx +2 -3
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Root.tsx +14 -7
- package/src/components/SVG/SVG.tsx +10 -2
- package/src/components/SVG/Svg.stories.tsx +4 -5
- package/src/fx/fx.stories.tsx +7 -8
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +1 -2
- package/src/graph/projector/graph-hierarchical-projector.ts +3 -4
- package/src/graph/projector/graph-projector.ts +2 -3
- package/src/graph/projector/graph-radial-projector.ts +1 -2
- package/src/graph/projector/graph-relational-projector.ts +3 -4
- package/src/graph/renderer/graph-renderer.ts +9 -4
- package/src/graph/types.ts +1 -1
- package/src/stories/hooks.stories.tsx +15 -9
- package/src/testing/data.ts +14 -14
- package/src/testing/hooks.ts +3 -4
- package/src/testing/model.ts +6 -6
- package/src/util/fraction.ts +1 -1
- package/styles/graph.css +292 -43
- package/dist/lib/browser/chunk-EX2Q43O6.mjs +0 -966
- package/dist/lib/browser/chunk-EX2Q43O6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SWA6OT3W.mjs +0 -968
- package/dist/lib/node-esm/chunk-SWA6OT3W.mjs.map +0 -7
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
EventEmitter,
|
|
4
|
-
FractionUtil,
|
|
5
|
-
GridController,
|
|
6
|
-
SVGContext,
|
|
7
|
-
SVGContextProvider,
|
|
8
|
-
Scale,
|
|
9
|
-
Screen,
|
|
10
|
-
Vector,
|
|
11
|
-
ZoomHandler,
|
|
12
|
-
getCircumferencePoints,
|
|
13
|
-
normal,
|
|
14
|
-
offsetPoints,
|
|
15
3
|
useDynamicRef,
|
|
16
|
-
useGrid,
|
|
17
4
|
useStateRef,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
useZoom
|
|
21
|
-
} from "./chunk-SWA6OT3W.mjs";
|
|
5
|
+
useTimestamp
|
|
6
|
+
} from "./chunk-JSE2X4ML.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";
|
|
@@ -163,15 +146,7 @@ var createGraphDrag = (context, projector, options = defaultDragOptions) => {
|
|
|
163
146
|
import { invariant } from "@dxos/invariant";
|
|
164
147
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
|
|
165
148
|
var defaultIdAccessor = (node) => {
|
|
166
|
-
invariant(node.id, void 0, {
|
|
167
|
-
F: __dxlog_file,
|
|
168
|
-
L: 18,
|
|
169
|
-
S: void 0,
|
|
170
|
-
A: [
|
|
171
|
-
"node.id",
|
|
172
|
-
""
|
|
173
|
-
]
|
|
174
|
-
});
|
|
149
|
+
invariant(node.id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 10, S: void 0, A: ["node.id", ""] });
|
|
175
150
|
return node.id;
|
|
176
151
|
};
|
|
177
152
|
var emptyGraph = {
|
|
@@ -179,21 +154,581 @@ var emptyGraph = {
|
|
|
179
154
|
edges: []
|
|
180
155
|
};
|
|
181
156
|
|
|
182
|
-
// src/
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
157
|
+
// src/util/events.ts
|
|
158
|
+
var EventEmitter = class {
|
|
159
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
160
|
+
clear() {
|
|
161
|
+
this._listeners.clear();
|
|
162
|
+
}
|
|
163
|
+
on(onEvent) {
|
|
164
|
+
this._listeners.add(onEvent);
|
|
165
|
+
return () => this._listeners.delete(onEvent);
|
|
166
|
+
}
|
|
167
|
+
emit(value) {
|
|
168
|
+
this._listeners.forEach((listener) => listener(value));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// src/util/fraction.ts
|
|
173
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
174
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
|
|
175
|
+
var FractionUtil = class _FractionUtil {
|
|
176
|
+
/**
|
|
177
|
+
* Convert number to fraction.
|
|
178
|
+
* @param n
|
|
179
|
+
*/
|
|
180
|
+
static toFraction = (n) => {
|
|
181
|
+
return typeof n === "number" ? [
|
|
182
|
+
n,
|
|
183
|
+
1
|
|
184
|
+
] : n;
|
|
185
|
+
};
|
|
186
|
+
static validate = (...fraction) => {
|
|
187
|
+
fraction.forEach(([n, d]) => {
|
|
188
|
+
if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
|
|
189
|
+
throw new Error(`Invalid fraction: ${n}/${d}`);
|
|
190
|
+
}
|
|
190
191
|
});
|
|
191
|
-
|
|
192
|
-
|
|
192
|
+
return fraction;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* @param {Fraction}
|
|
196
|
+
* Convert to rounded-sm number.
|
|
197
|
+
*/
|
|
198
|
+
static toNumber = ([n, d]) => {
|
|
199
|
+
_FractionUtil.validate([
|
|
200
|
+
n,
|
|
201
|
+
d
|
|
202
|
+
]);
|
|
203
|
+
return n / d;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Round the number to the nearest fraction.
|
|
207
|
+
* Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
|
|
208
|
+
* @param {Fraction}
|
|
209
|
+
* @param p Precision (e.g., 1/2, 1/4, etc.)
|
|
210
|
+
*/
|
|
211
|
+
static round = ([n, d], p = 1) => {
|
|
212
|
+
_FractionUtil.validate([
|
|
213
|
+
n,
|
|
214
|
+
d
|
|
215
|
+
]);
|
|
216
|
+
const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
|
|
217
|
+
n,
|
|
218
|
+
d
|
|
219
|
+
], [
|
|
220
|
+
1,
|
|
221
|
+
p
|
|
222
|
+
])));
|
|
223
|
+
return _FractionUtil.simplify([
|
|
224
|
+
v,
|
|
225
|
+
p
|
|
226
|
+
]);
|
|
227
|
+
};
|
|
228
|
+
//
|
|
229
|
+
// Boolean.
|
|
230
|
+
//
|
|
231
|
+
/**
|
|
232
|
+
* Tests if equals.
|
|
233
|
+
* @param n1
|
|
234
|
+
* @param n2
|
|
235
|
+
*/
|
|
236
|
+
static equals = (n1, n2) => {
|
|
237
|
+
return n1[0] * n2[1] === n1[1] * n2[0];
|
|
238
|
+
};
|
|
239
|
+
/**
|
|
240
|
+
* @param {Fraction}
|
|
241
|
+
* True if zero.
|
|
242
|
+
*/
|
|
243
|
+
static isZero = ([n]) => {
|
|
244
|
+
return n === 0;
|
|
245
|
+
};
|
|
246
|
+
//
|
|
247
|
+
// Normalization.
|
|
248
|
+
//
|
|
249
|
+
/**
|
|
250
|
+
* Simplify fraction finding LCDs.
|
|
251
|
+
* @param n
|
|
252
|
+
* @param d
|
|
253
|
+
*/
|
|
254
|
+
static simplify = ([n, d]) => {
|
|
255
|
+
_FractionUtil.validate([
|
|
256
|
+
n,
|
|
257
|
+
d
|
|
258
|
+
]);
|
|
259
|
+
if (d < 1) {
|
|
260
|
+
const t = n / d;
|
|
261
|
+
if (Math.floor(t) === t) {
|
|
262
|
+
n = t;
|
|
263
|
+
d = 1;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const fn = _FractionUtil.factors(n).reverse();
|
|
267
|
+
const fd = _FractionUtil.factors(d).reverse();
|
|
268
|
+
let c;
|
|
269
|
+
for (let i = 0; i < fn.length; i++) {
|
|
270
|
+
c = fd.find((n2) => n2 === fn[i]);
|
|
271
|
+
if (c) {
|
|
272
|
+
return [
|
|
273
|
+
n / c,
|
|
274
|
+
d / c
|
|
275
|
+
];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return [
|
|
279
|
+
n,
|
|
280
|
+
d
|
|
281
|
+
];
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Return common factors.
|
|
285
|
+
* @param n
|
|
286
|
+
*/
|
|
287
|
+
static factors = (n) => {
|
|
288
|
+
invariant2(Number.isFinite(n), `Invalid number: ${n}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 113, S: this, A: ["Number.isFinite(n)", "`Invalid number: ${n}`"] });
|
|
289
|
+
const factors = [
|
|
290
|
+
1
|
|
291
|
+
];
|
|
292
|
+
if (Number.isSafeInteger(n)) {
|
|
293
|
+
let f = 1;
|
|
294
|
+
do {
|
|
295
|
+
if (n % ++f === 0) {
|
|
296
|
+
factors.push(f);
|
|
297
|
+
}
|
|
298
|
+
} while (n / f > 1 && f < 100);
|
|
299
|
+
}
|
|
300
|
+
return factors;
|
|
301
|
+
};
|
|
302
|
+
//
|
|
303
|
+
// Basic arithmetic.
|
|
304
|
+
//
|
|
305
|
+
/**
|
|
306
|
+
* @param n1
|
|
307
|
+
* @param n2
|
|
308
|
+
*/
|
|
309
|
+
static add = (n1, n2) => {
|
|
310
|
+
_FractionUtil.validate(n1, n2);
|
|
311
|
+
const d = n1[1] * n2[1];
|
|
312
|
+
const n = n1[0] * n2[1] + n2[0] * n1[1];
|
|
313
|
+
return _FractionUtil.simplify([
|
|
314
|
+
n,
|
|
315
|
+
d
|
|
316
|
+
]);
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* @param n1
|
|
320
|
+
* @param n2
|
|
321
|
+
*/
|
|
322
|
+
static subtract = (n1, n2) => {
|
|
323
|
+
_FractionUtil.validate(n1, n2);
|
|
324
|
+
const d = n1[1] * n2[1];
|
|
325
|
+
const n = n1[0] * n2[1] - n2[0] * n1[1];
|
|
326
|
+
return _FractionUtil.simplify([
|
|
327
|
+
n,
|
|
328
|
+
d
|
|
329
|
+
]);
|
|
330
|
+
};
|
|
331
|
+
/**
|
|
332
|
+
* @param n1
|
|
333
|
+
* @param n2
|
|
334
|
+
*/
|
|
335
|
+
static multiply = (n1, n2) => {
|
|
336
|
+
_FractionUtil.validate(n1, n2);
|
|
337
|
+
const n = n1[0] * n2[0];
|
|
338
|
+
const d = n1[1] * n2[1];
|
|
339
|
+
return _FractionUtil.simplify([
|
|
340
|
+
n,
|
|
341
|
+
d
|
|
342
|
+
]);
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* @param n1
|
|
346
|
+
* @param n2
|
|
347
|
+
*/
|
|
348
|
+
static divide = (n1, n2) => {
|
|
349
|
+
_FractionUtil.validate(n1, n2);
|
|
350
|
+
const n = n1[0] * n2[1];
|
|
351
|
+
const d = n1[1] * n2[0];
|
|
352
|
+
return _FractionUtil.simplify([
|
|
353
|
+
n,
|
|
354
|
+
d
|
|
355
|
+
]);
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// src/util/points.ts
|
|
360
|
+
var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
|
|
361
|
+
const [x1, y1] = p1;
|
|
362
|
+
const [x2, y2] = p2;
|
|
363
|
+
const theta = Math.atan2(x2 - x1, y2 - y1);
|
|
364
|
+
return [
|
|
365
|
+
[
|
|
366
|
+
// p1
|
|
367
|
+
x1 + (r1 === 0 ? 0 : r1 * Math.sin(theta)),
|
|
368
|
+
y1 + (r1 === 0 ? 0 : r1 * Math.cos(theta))
|
|
369
|
+
],
|
|
370
|
+
[
|
|
371
|
+
// p2
|
|
372
|
+
x2 - (r2 === 0 ? 0 : r2 * Math.cos(Math.PI / 2 - theta)),
|
|
373
|
+
y2 - (r2 === 0 ? 0 : r2 * Math.sin(Math.PI / 2 - theta))
|
|
374
|
+
]
|
|
375
|
+
];
|
|
376
|
+
};
|
|
377
|
+
var normal = (p1, p2) => {
|
|
378
|
+
const dx = p2[0] - p1[0];
|
|
379
|
+
const dy = p2[1] - p1[1];
|
|
380
|
+
const len = Math.hypot(dx, dy);
|
|
381
|
+
return [
|
|
382
|
+
dy / len,
|
|
383
|
+
-dx / len
|
|
384
|
+
];
|
|
385
|
+
};
|
|
386
|
+
var offsetPoints = (points, distance, closed) => {
|
|
387
|
+
const len = points.length;
|
|
388
|
+
const out = [];
|
|
389
|
+
for (let i = 0; i < len; i++) {
|
|
390
|
+
const p0 = points[(i - 1 + len) % len];
|
|
391
|
+
const p1 = points[i];
|
|
392
|
+
const p2 = points[(i + 1) % len];
|
|
393
|
+
const n1 = normal(p0, p1);
|
|
394
|
+
const n2 = normal(p1, p2);
|
|
395
|
+
const nx = (n1[0] + n2[0]) / 2;
|
|
396
|
+
const ny = (n1[1] + n2[1]) / 2;
|
|
397
|
+
const norm = Math.hypot(nx, ny) || 1;
|
|
398
|
+
out.push([
|
|
399
|
+
p1[0] + distance * nx / norm,
|
|
400
|
+
p1[1] + distance * ny / norm
|
|
401
|
+
]);
|
|
402
|
+
if (!closed && (i === 0 || i === len - 1)) {
|
|
403
|
+
out[i] = [
|
|
404
|
+
p1[0] + distance * normal(p0, p1)[0],
|
|
405
|
+
p1[1] + distance * normal(p0, p1)[1]
|
|
406
|
+
];
|
|
407
|
+
}
|
|
193
408
|
}
|
|
194
|
-
return
|
|
195
|
-
}
|
|
409
|
+
return out;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// src/util/scale.ts
|
|
413
|
+
import { zoomIdentity } from "d3";
|
|
414
|
+
var Scale = class {
|
|
415
|
+
_gridSize;
|
|
416
|
+
_transform;
|
|
417
|
+
constructor(_gridSize = 32) {
|
|
418
|
+
this._gridSize = _gridSize;
|
|
419
|
+
}
|
|
420
|
+
get gridSize() {
|
|
421
|
+
return this._gridSize;
|
|
422
|
+
}
|
|
423
|
+
get transform() {
|
|
424
|
+
return this._transform || zoomIdentity;
|
|
425
|
+
}
|
|
426
|
+
setTransform(transform) {
|
|
427
|
+
if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
this._transform = transform;
|
|
431
|
+
return true;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Translate a screen point to a logical point.
|
|
435
|
+
* @param point
|
|
436
|
+
*/
|
|
437
|
+
translate(point) {
|
|
438
|
+
const { x, y, k } = this._transform ?? {
|
|
439
|
+
x: 0,
|
|
440
|
+
y: 0,
|
|
441
|
+
k: 1
|
|
442
|
+
};
|
|
443
|
+
return [
|
|
444
|
+
(point[0] - x) / k,
|
|
445
|
+
(point[1] - y) / k
|
|
446
|
+
];
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Map model to screen.
|
|
450
|
+
* Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
|
|
451
|
+
*/
|
|
452
|
+
model = {
|
|
453
|
+
// TODO(burdon): Precision depends on scale.
|
|
454
|
+
snapValues: (array) => array.map((n) => FractionUtil.round(n)),
|
|
455
|
+
snapVertex: ({ x, y }) => {
|
|
456
|
+
const [sx, sy] = this.model.snapValues([
|
|
457
|
+
x,
|
|
458
|
+
y
|
|
459
|
+
]);
|
|
460
|
+
return {
|
|
461
|
+
x: sx,
|
|
462
|
+
y: sy
|
|
463
|
+
};
|
|
464
|
+
},
|
|
465
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
466
|
+
[x, y, width, height] = this.model.snapValues([
|
|
467
|
+
x,
|
|
468
|
+
y,
|
|
469
|
+
width,
|
|
470
|
+
height
|
|
471
|
+
]);
|
|
472
|
+
return {
|
|
473
|
+
x,
|
|
474
|
+
y,
|
|
475
|
+
width,
|
|
476
|
+
height
|
|
477
|
+
};
|
|
478
|
+
},
|
|
479
|
+
toValue: (value) => {
|
|
480
|
+
return Math.round(FractionUtil.toNumber(value) * this._gridSize);
|
|
481
|
+
},
|
|
482
|
+
toValues: (values) => {
|
|
483
|
+
return values.map((value) => Math.round(FractionUtil.toNumber(value) * this._gridSize));
|
|
484
|
+
},
|
|
485
|
+
toPoint: (point) => {
|
|
486
|
+
const [x, y] = this.model.toValues([
|
|
487
|
+
point.x,
|
|
488
|
+
point.y
|
|
489
|
+
]);
|
|
490
|
+
return [
|
|
491
|
+
x,
|
|
492
|
+
y === 0 ? 0 : -y
|
|
493
|
+
];
|
|
494
|
+
},
|
|
495
|
+
toBounds: ({ x, y, width, height }) => {
|
|
496
|
+
const point = this.model.toPoint({
|
|
497
|
+
x,
|
|
498
|
+
y
|
|
499
|
+
});
|
|
500
|
+
const [width2, height2] = this.model.toValues([
|
|
501
|
+
width,
|
|
502
|
+
height
|
|
503
|
+
]);
|
|
504
|
+
return {
|
|
505
|
+
x: point[0],
|
|
506
|
+
y: point[1] - height2,
|
|
507
|
+
width: width2,
|
|
508
|
+
height: height2
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
/**
|
|
513
|
+
* Map screen to model.
|
|
514
|
+
* Screen points are represented by floating numbers and use translated SVG coordinates (with the y-axis inverted).
|
|
515
|
+
*/
|
|
516
|
+
screen = {
|
|
517
|
+
snapValues: (array) => array.map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
518
|
+
snapPoint: ([x, y]) => [
|
|
519
|
+
x,
|
|
520
|
+
y
|
|
521
|
+
].map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
522
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
523
|
+
[x, y, width, height] = this.screen.snapValues([
|
|
524
|
+
x,
|
|
525
|
+
y,
|
|
526
|
+
width,
|
|
527
|
+
height
|
|
528
|
+
]);
|
|
529
|
+
return {
|
|
530
|
+
x,
|
|
531
|
+
y,
|
|
532
|
+
width,
|
|
533
|
+
height
|
|
534
|
+
};
|
|
535
|
+
},
|
|
536
|
+
toValue: (value) => {
|
|
537
|
+
return FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
538
|
+
this._gridSize,
|
|
539
|
+
1
|
|
540
|
+
]);
|
|
541
|
+
},
|
|
542
|
+
toValues: (values) => {
|
|
543
|
+
return values.map((value) => FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
544
|
+
this._gridSize,
|
|
545
|
+
1
|
|
546
|
+
]));
|
|
547
|
+
},
|
|
548
|
+
toVertex: (point) => {
|
|
549
|
+
const [x, y] = point;
|
|
550
|
+
return {
|
|
551
|
+
x: FractionUtil.toFraction(x / this._gridSize),
|
|
552
|
+
y: FractionUtil.toFraction(-y / this._gridSize)
|
|
553
|
+
};
|
|
554
|
+
},
|
|
555
|
+
toBounds: (bounds) => {
|
|
556
|
+
const { x, y } = this.screen.toVertex([
|
|
557
|
+
bounds.x,
|
|
558
|
+
bounds.y
|
|
559
|
+
]);
|
|
560
|
+
const [width, height] = this.screen.toValues([
|
|
561
|
+
bounds.width,
|
|
562
|
+
bounds.height
|
|
563
|
+
]);
|
|
564
|
+
return {
|
|
565
|
+
x,
|
|
566
|
+
y: FractionUtil.subtract(y, height),
|
|
567
|
+
width,
|
|
568
|
+
height
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
// src/util/screen.ts
|
|
575
|
+
var Screen = class {
|
|
576
|
+
static createBounds = ([x1, y1], [x2, y2], mod = {}) => {
|
|
577
|
+
const { constrain, center } = mod;
|
|
578
|
+
const x = Math.min(x1, x2);
|
|
579
|
+
const y = Math.min(y1, y2);
|
|
580
|
+
let width = Math.abs(x2 - x1);
|
|
581
|
+
let height = Math.abs(y2 - y1);
|
|
582
|
+
if (constrain) {
|
|
583
|
+
width = height = Math.max(width, height);
|
|
584
|
+
}
|
|
585
|
+
if (center) {
|
|
586
|
+
return {
|
|
587
|
+
x: x - width,
|
|
588
|
+
y: y - height,
|
|
589
|
+
width: width * 2,
|
|
590
|
+
height: height * 2
|
|
591
|
+
};
|
|
592
|
+
} else {
|
|
593
|
+
return {
|
|
594
|
+
x,
|
|
595
|
+
y,
|
|
596
|
+
width,
|
|
597
|
+
height
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
static center = ({ x, y, width, height }) => {
|
|
602
|
+
return [
|
|
603
|
+
x + width / 2,
|
|
604
|
+
y + height / 2
|
|
605
|
+
];
|
|
606
|
+
};
|
|
607
|
+
static contains = (bounds, point) => {
|
|
608
|
+
const [x, y] = point;
|
|
609
|
+
if (x < bounds.x || y < bounds.y) {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
return true;
|
|
616
|
+
};
|
|
617
|
+
/**
|
|
618
|
+
* Distance between two points.
|
|
619
|
+
* @param p1
|
|
620
|
+
* @param p2
|
|
621
|
+
*/
|
|
622
|
+
static len = (p1, p2) => {
|
|
623
|
+
return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* Distance to line segment.
|
|
627
|
+
* https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
|
|
628
|
+
* @param v1
|
|
629
|
+
* @param v2
|
|
630
|
+
* @param p
|
|
631
|
+
*/
|
|
632
|
+
static normal = (v1, v2, p) => {
|
|
633
|
+
const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
|
|
634
|
+
let d;
|
|
635
|
+
const len2 = d2(v1, v2);
|
|
636
|
+
if (len2 === 0) {
|
|
637
|
+
d = d2(p, v1);
|
|
638
|
+
} else {
|
|
639
|
+
let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
|
|
640
|
+
t = Math.max(0, Math.min(1, t));
|
|
641
|
+
d = d2(p, [
|
|
642
|
+
v1[0] + t * (v2[0] - v1[0]),
|
|
643
|
+
v1[1] + t * (v2[1] - v1[1])
|
|
644
|
+
]);
|
|
645
|
+
}
|
|
646
|
+
return Math.sqrt(d);
|
|
647
|
+
};
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
// src/util/vector.ts
|
|
651
|
+
var Vector = class {
|
|
652
|
+
/**
|
|
653
|
+
* Convert to Vertex.
|
|
654
|
+
* @param x
|
|
655
|
+
* @param y
|
|
656
|
+
*/
|
|
657
|
+
static toVertex = ({ x, y }) => ({
|
|
658
|
+
x: FractionUtil.toFraction(x),
|
|
659
|
+
y: FractionUtil.toFraction(y)
|
|
660
|
+
});
|
|
661
|
+
/**
|
|
662
|
+
* Convert to Bounds.
|
|
663
|
+
* @param bounds
|
|
664
|
+
*/
|
|
665
|
+
static toBounds = ({ x, y, width, height }) => ({
|
|
666
|
+
x: FractionUtil.toFraction(x),
|
|
667
|
+
y: FractionUtil.toFraction(y),
|
|
668
|
+
width: FractionUtil.toFraction(width),
|
|
669
|
+
height: FractionUtil.toFraction(height)
|
|
670
|
+
});
|
|
671
|
+
/**
|
|
672
|
+
* Calculate center point.
|
|
673
|
+
* @param bounds
|
|
674
|
+
*/
|
|
675
|
+
static center = ({ x, y, width, height }) => {
|
|
676
|
+
const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
|
|
677
|
+
1,
|
|
678
|
+
2
|
|
679
|
+
]));
|
|
680
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
681
|
+
1,
|
|
682
|
+
2
|
|
683
|
+
]));
|
|
684
|
+
return {
|
|
685
|
+
x: cx,
|
|
686
|
+
y: cy
|
|
687
|
+
};
|
|
688
|
+
};
|
|
689
|
+
/**
|
|
690
|
+
* Calculate centered left edge.
|
|
691
|
+
* @param bounds
|
|
692
|
+
*/
|
|
693
|
+
static left = ({ x, y, height }) => {
|
|
694
|
+
const cx = x;
|
|
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 right edge.
|
|
706
|
+
* @param bounds
|
|
707
|
+
*/
|
|
708
|
+
static right = ({ x, y, width, height }) => {
|
|
709
|
+
const cx = FractionUtil.add(x, width);
|
|
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
|
+
|
|
721
|
+
// src/graph/projector/projector.ts
|
|
196
722
|
var Projector = class {
|
|
723
|
+
_context;
|
|
724
|
+
updated = new EventEmitter();
|
|
725
|
+
_options;
|
|
726
|
+
constructor(_context, options) {
|
|
727
|
+
this._context = _context;
|
|
728
|
+
this._options = Object.assign({
|
|
729
|
+
idAccessor: defaultIdAccessor
|
|
730
|
+
}, options);
|
|
731
|
+
}
|
|
197
732
|
get context() {
|
|
198
733
|
return this._context;
|
|
199
734
|
}
|
|
@@ -230,33 +765,27 @@ var Projector = class {
|
|
|
230
765
|
}
|
|
231
766
|
async onStop() {
|
|
232
767
|
}
|
|
233
|
-
constructor(_context, options) {
|
|
234
|
-
_define_property(this, "_context", void 0);
|
|
235
|
-
_define_property(this, "updated", void 0);
|
|
236
|
-
_define_property(this, "_options", void 0);
|
|
237
|
-
this._context = _context;
|
|
238
|
-
this.updated = new EventEmitter();
|
|
239
|
-
this._options = Object.assign({
|
|
240
|
-
idAccessor: defaultIdAccessor
|
|
241
|
-
}, options);
|
|
242
|
-
}
|
|
243
768
|
};
|
|
244
769
|
|
|
245
770
|
// src/graph/projector/graph-projector.ts
|
|
246
|
-
function _define_property2(obj, key, value) {
|
|
247
|
-
if (key in obj) {
|
|
248
|
-
Object.defineProperty(obj, key, {
|
|
249
|
-
value,
|
|
250
|
-
enumerable: true,
|
|
251
|
-
configurable: true,
|
|
252
|
-
writable: true
|
|
253
|
-
});
|
|
254
|
-
} else {
|
|
255
|
-
obj[key] = value;
|
|
256
|
-
}
|
|
257
|
-
return obj;
|
|
258
|
-
}
|
|
259
771
|
var GraphProjector = class extends Projector {
|
|
772
|
+
_selection;
|
|
773
|
+
_layout;
|
|
774
|
+
// TODO(burdon): Change to object props.
|
|
775
|
+
constructor(context, options, _selection, layout) {
|
|
776
|
+
super(context, options), this._selection = _selection;
|
|
777
|
+
this._layout = {
|
|
778
|
+
id: (Math.random() * 10).toString().slice(8),
|
|
779
|
+
graph: {
|
|
780
|
+
nodes: [
|
|
781
|
+
...layout?.graph.nodes ?? []
|
|
782
|
+
],
|
|
783
|
+
edges: [
|
|
784
|
+
...layout?.graph.edges ?? []
|
|
785
|
+
]
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
}
|
|
260
789
|
get layout() {
|
|
261
790
|
return this._layout;
|
|
262
791
|
}
|
|
@@ -302,21 +831,6 @@ var GraphProjector = class extends Projector {
|
|
|
302
831
|
async onClear() {
|
|
303
832
|
this.reset();
|
|
304
833
|
}
|
|
305
|
-
// TODO(burdon): Change to object props.
|
|
306
|
-
constructor(context, options, _selection, layout) {
|
|
307
|
-
super(context, options), _define_property2(this, "_selection", void 0), _define_property2(this, "_layout", void 0), this._selection = _selection;
|
|
308
|
-
this._layout = {
|
|
309
|
-
id: (Math.random() * 10).toString().slice(8),
|
|
310
|
-
graph: {
|
|
311
|
-
nodes: [
|
|
312
|
-
...layout?.graph.nodes ?? []
|
|
313
|
-
],
|
|
314
|
-
edges: [
|
|
315
|
-
...layout?.graph.edges ?? []
|
|
316
|
-
]
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
834
|
};
|
|
321
835
|
|
|
322
836
|
// src/graph/projector/graph-force-projector.ts
|
|
@@ -340,20 +854,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
340
854
|
};
|
|
341
855
|
|
|
342
856
|
// src/graph/projector/graph-force-projector.ts
|
|
343
|
-
|
|
344
|
-
if (key in obj) {
|
|
345
|
-
Object.defineProperty(obj, key, {
|
|
346
|
-
value,
|
|
347
|
-
enumerable: true,
|
|
348
|
-
configurable: true,
|
|
349
|
-
writable: true
|
|
350
|
-
});
|
|
351
|
-
} else {
|
|
352
|
-
obj[key] = value;
|
|
353
|
-
}
|
|
354
|
-
return obj;
|
|
355
|
-
}
|
|
356
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
857
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
357
858
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
358
859
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
359
860
|
};
|
|
@@ -370,6 +871,9 @@ var defaultForceOptions = {
|
|
|
370
871
|
point: true
|
|
371
872
|
};
|
|
372
873
|
var GraphForceProjector = class extends GraphProjector {
|
|
874
|
+
// https://github.com/d3/d3-force
|
|
875
|
+
_simulation = forceSimulation();
|
|
876
|
+
_timeout;
|
|
373
877
|
get forces() {
|
|
374
878
|
return this.options.forces ?? defaultForceOptions;
|
|
375
879
|
}
|
|
@@ -422,12 +926,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
422
926
|
nodes: graph?.nodes.length,
|
|
423
927
|
edges: graph?.edges.length
|
|
424
928
|
}
|
|
425
|
-
}, {
|
|
426
|
-
F: __dxlog_file2,
|
|
427
|
-
L: 227,
|
|
428
|
-
S: this,
|
|
429
|
-
C: (f, a) => f(...a)
|
|
430
|
-
});
|
|
929
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 89, S: this });
|
|
431
930
|
this._simulation.stop();
|
|
432
931
|
this.mergeData(graph);
|
|
433
932
|
this.updateLayout();
|
|
@@ -477,12 +976,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
477
976
|
updateForces(forces) {
|
|
478
977
|
log("updateForces", {
|
|
479
978
|
forces
|
|
480
|
-
}, {
|
|
481
|
-
F: __dxlog_file2,
|
|
482
|
-
L: 288,
|
|
483
|
-
S: this,
|
|
484
|
-
C: (f, a) => f(...a)
|
|
485
|
-
});
|
|
979
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 148, S: this });
|
|
486
980
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
487
981
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
488
982
|
if (config.distance != null) {
|
|
@@ -543,10 +1037,6 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
543
1037
|
return force;
|
|
544
1038
|
}));
|
|
545
1039
|
}
|
|
546
|
-
constructor(...args) {
|
|
547
|
-
super(...args), // https://github.com/d3/d3-force
|
|
548
|
-
_define_property3(this, "_simulation", forceSimulation()), _define_property3(this, "_timeout", void 0);
|
|
549
|
-
}
|
|
550
1040
|
};
|
|
551
1041
|
|
|
552
1042
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
@@ -555,21 +1045,9 @@ import { log as log3 } from "@dxos/log";
|
|
|
555
1045
|
// src/graph/projector/graph-radial-projector.ts
|
|
556
1046
|
import { easeCubic, timer } from "d3";
|
|
557
1047
|
import { log as log2 } from "@dxos/log";
|
|
558
|
-
|
|
559
|
-
if (key in obj) {
|
|
560
|
-
Object.defineProperty(obj, key, {
|
|
561
|
-
value,
|
|
562
|
-
enumerable: true,
|
|
563
|
-
configurable: true,
|
|
564
|
-
writable: true
|
|
565
|
-
});
|
|
566
|
-
} else {
|
|
567
|
-
obj[key] = value;
|
|
568
|
-
}
|
|
569
|
-
return obj;
|
|
570
|
-
}
|
|
571
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
1048
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
572
1049
|
var GraphRadialProjector = class extends GraphProjector {
|
|
1050
|
+
_timer;
|
|
573
1051
|
findNode(x, y, radius) {
|
|
574
1052
|
return void 0;
|
|
575
1053
|
}
|
|
@@ -579,12 +1057,7 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
579
1057
|
nodes: graph?.nodes.length,
|
|
580
1058
|
edges: graph?.edges.length
|
|
581
1059
|
}
|
|
582
|
-
}, {
|
|
583
|
-
F: __dxlog_file3,
|
|
584
|
-
L: 32,
|
|
585
|
-
S: this,
|
|
586
|
-
C: (f, a) => f(...a)
|
|
587
|
-
});
|
|
1060
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 13, S: this });
|
|
588
1061
|
this.mergeData(graph);
|
|
589
1062
|
this.doRadialLayout();
|
|
590
1063
|
}
|
|
@@ -627,9 +1100,6 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
627
1100
|
});
|
|
628
1101
|
this.animate();
|
|
629
1102
|
}
|
|
630
|
-
constructor(...args) {
|
|
631
|
-
super(...args), _define_property4(this, "_timer", void 0);
|
|
632
|
-
}
|
|
633
1103
|
};
|
|
634
1104
|
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
635
1105
|
const sx = node.x ?? tx;
|
|
@@ -683,7 +1153,7 @@ var layoutVertical = (x, y, h, n) => {
|
|
|
683
1153
|
};
|
|
684
1154
|
|
|
685
1155
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
686
|
-
var
|
|
1156
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
687
1157
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
688
1158
|
onUpdate(graph) {
|
|
689
1159
|
log3("onUpdate", {
|
|
@@ -691,15 +1161,10 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
691
1161
|
nodes: graph?.nodes.length,
|
|
692
1162
|
edges: graph?.edges.length
|
|
693
1163
|
},
|
|
694
|
-
selection: this.selection?.
|
|
695
|
-
}, {
|
|
696
|
-
F: __dxlog_file4,
|
|
697
|
-
L: 24,
|
|
698
|
-
S: this,
|
|
699
|
-
C: (f, a) => f(...a)
|
|
700
|
-
});
|
|
1164
|
+
selection: this.selection?.getSelectedIds()
|
|
1165
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 8, S: this });
|
|
701
1166
|
this.mergeData(graph);
|
|
702
|
-
const selected = this.selection?.
|
|
1167
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
703
1168
|
if (selected) {
|
|
704
1169
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
705
1170
|
if (node) {
|
|
@@ -746,7 +1211,7 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
746
1211
|
|
|
747
1212
|
// src/graph/projector/graph-relational-projector.ts
|
|
748
1213
|
import { log as log4 } from "@dxos/log";
|
|
749
|
-
var
|
|
1214
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
750
1215
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
751
1216
|
onUpdate(graph) {
|
|
752
1217
|
log4("onUpdate", {
|
|
@@ -754,15 +1219,10 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
754
1219
|
nodes: graph?.nodes.length,
|
|
755
1220
|
edges: graph?.edges.length
|
|
756
1221
|
},
|
|
757
|
-
selection: this.selection?.
|
|
758
|
-
}, {
|
|
759
|
-
F: __dxlog_file5,
|
|
760
|
-
L: 24,
|
|
761
|
-
S: this,
|
|
762
|
-
C: (f, a) => f(...a)
|
|
763
|
-
});
|
|
1222
|
+
selection: this.selection?.getSelectedIds()
|
|
1223
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 8, S: this });
|
|
764
1224
|
this.mergeData(graph);
|
|
765
|
-
const selected = this.selection?.
|
|
1225
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
766
1226
|
if (selected) {
|
|
767
1227
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
768
1228
|
if (node) {
|
|
@@ -869,63 +1329,37 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
869
1329
|
};
|
|
870
1330
|
|
|
871
1331
|
// src/graph/renderer/renderer.ts
|
|
872
|
-
import { invariant as
|
|
873
|
-
|
|
874
|
-
if (key in obj) {
|
|
875
|
-
Object.defineProperty(obj, key, {
|
|
876
|
-
value,
|
|
877
|
-
enumerable: true,
|
|
878
|
-
configurable: true,
|
|
879
|
-
writable: true
|
|
880
|
-
});
|
|
881
|
-
} else {
|
|
882
|
-
obj[key] = value;
|
|
883
|
-
}
|
|
884
|
-
return obj;
|
|
885
|
-
}
|
|
886
|
-
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
1332
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1333
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
887
1334
|
var Renderer = class {
|
|
1335
|
+
_context;
|
|
1336
|
+
_root;
|
|
1337
|
+
_options;
|
|
1338
|
+
constructor(_context, _root, options) {
|
|
1339
|
+
this._context = _context;
|
|
1340
|
+
this._root = _root;
|
|
1341
|
+
this._options = Object.assign({
|
|
1342
|
+
idAccessor: defaultIdAccessor
|
|
1343
|
+
}, options);
|
|
1344
|
+
}
|
|
888
1345
|
get context() {
|
|
889
1346
|
return this._context;
|
|
890
1347
|
}
|
|
891
1348
|
get root() {
|
|
892
|
-
|
|
893
|
-
F: __dxlog_file6,
|
|
894
|
-
L: 40,
|
|
895
|
-
S: this,
|
|
896
|
-
A: [
|
|
897
|
-
"this._root.current",
|
|
898
|
-
"'SVG root is not initialized'"
|
|
899
|
-
]
|
|
900
|
-
});
|
|
1349
|
+
invariant3(this._root.current, "SVG root is not initialized", { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 23, S: this, A: ["this._root.current", "'SVG root is not initialized'"] });
|
|
901
1350
|
return this._root.current;
|
|
902
1351
|
}
|
|
903
1352
|
get options() {
|
|
904
1353
|
return this._options;
|
|
905
1354
|
}
|
|
906
|
-
constructor(_context, _root, options) {
|
|
907
|
-
_define_property5(this, "_context", void 0);
|
|
908
|
-
_define_property5(this, "_root", void 0);
|
|
909
|
-
_define_property5(this, "_options", void 0);
|
|
910
|
-
this._context = _context;
|
|
911
|
-
this._root = _root;
|
|
912
|
-
this._options = Object.assign({
|
|
913
|
-
idAccessor: defaultIdAccessor
|
|
914
|
-
}, options);
|
|
915
|
-
}
|
|
916
1355
|
};
|
|
917
1356
|
|
|
918
1357
|
// src/graph/renderer/graph-renderer.ts
|
|
919
|
-
var
|
|
1358
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
920
1359
|
var createLine2 = line2();
|
|
921
1360
|
var GraphRenderer = class extends Renderer {
|
|
922
1361
|
render(layout) {
|
|
923
|
-
log5("render", layout, {
|
|
924
|
-
F: __dxlog_file7,
|
|
925
|
-
L: 63,
|
|
926
|
-
S: this,
|
|
927
|
-
C: (f, a) => f(...a)
|
|
928
|
-
});
|
|
1362
|
+
log5("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 19, S: this });
|
|
929
1363
|
const root = select4(this.root);
|
|
930
1364
|
if (layout.guides) {
|
|
931
1365
|
root.selectAll("g.dx-guides").data([
|
|
@@ -1032,14 +1466,14 @@ var createNode = (group, options) => {
|
|
|
1032
1466
|
circle.on("pointerenter", function() {
|
|
1033
1467
|
select4(this.closest("g.dx-node")).raise();
|
|
1034
1468
|
if (options.labels) {
|
|
1035
|
-
select4(this.parentElement).classed("dx-active", true).classed("dx-highlight", true);
|
|
1469
|
+
select4(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
|
|
1036
1470
|
}
|
|
1037
1471
|
});
|
|
1038
1472
|
group.on("pointerleave", function() {
|
|
1039
1473
|
if (options.labels) {
|
|
1040
|
-
select4(this).classed("dx-active", false);
|
|
1474
|
+
select4(this).classed("dx-node-active", false);
|
|
1041
1475
|
setTimeout(() => {
|
|
1042
|
-
if (!select4(this).classed("dx-active")) {
|
|
1476
|
+
if (!select4(this).classed("dx-node-active")) {
|
|
1043
1477
|
select4(this).classed("dx-highlight", false);
|
|
1044
1478
|
}
|
|
1045
1479
|
}, 300);
|
|
@@ -1068,12 +1502,7 @@ var updateNode2 = (group, options) => {
|
|
|
1068
1502
|
} catch (error) {
|
|
1069
1503
|
log5.error("updateNode", {
|
|
1070
1504
|
error: error?.message
|
|
1071
|
-
}, {
|
|
1072
|
-
F: __dxlog_file7,
|
|
1073
|
-
L: 305,
|
|
1074
|
-
S: void 0,
|
|
1075
|
-
C: (f, a) => f(...a)
|
|
1076
|
-
});
|
|
1505
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 200, S: void 0 });
|
|
1077
1506
|
}
|
|
1078
1507
|
}
|
|
1079
1508
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
@@ -1124,12 +1553,7 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1124
1553
|
} catch (error) {
|
|
1125
1554
|
log5.error("updateEdge", {
|
|
1126
1555
|
error: error?.message
|
|
1127
|
-
}, {
|
|
1128
|
-
F: __dxlog_file7,
|
|
1129
|
-
L: 417,
|
|
1130
|
-
S: void 0,
|
|
1131
|
-
C: (f, a) => f(...a)
|
|
1132
|
-
});
|
|
1556
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 266, S: void 0 });
|
|
1133
1557
|
}
|
|
1134
1558
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1135
1559
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
@@ -1207,112 +1631,422 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1207
1631
|
});
|
|
1208
1632
|
};
|
|
1209
1633
|
|
|
1210
|
-
// src/
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
return
|
|
1290
|
-
|
|
1291
|
-
|
|
1634
|
+
// src/hooks/useGrid.ts
|
|
1635
|
+
import { line as line4, range, select as select5 } from "d3";
|
|
1636
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
1637
|
+
|
|
1638
|
+
// src/hooks/useSvgContext.ts
|
|
1639
|
+
import { createContext, useContext } from "react";
|
|
1640
|
+
import { createRef } from "react";
|
|
1641
|
+
import { raise } from "@dxos/debug";
|
|
1642
|
+
var SVGContext = class {
|
|
1643
|
+
_ref = createRef();
|
|
1644
|
+
_scale;
|
|
1645
|
+
_centered;
|
|
1646
|
+
_size;
|
|
1647
|
+
_center;
|
|
1648
|
+
resized = new EventEmitter();
|
|
1649
|
+
constructor({ scale = new Scale(), centered = true }) {
|
|
1650
|
+
this._scale = scale;
|
|
1651
|
+
this._centered = centered;
|
|
1652
|
+
}
|
|
1653
|
+
get ref() {
|
|
1654
|
+
return this._ref;
|
|
1655
|
+
}
|
|
1656
|
+
get svg() {
|
|
1657
|
+
return this._ref.current;
|
|
1658
|
+
}
|
|
1659
|
+
get scale() {
|
|
1660
|
+
return this._scale;
|
|
1661
|
+
}
|
|
1662
|
+
get center() {
|
|
1663
|
+
return this._center;
|
|
1664
|
+
}
|
|
1665
|
+
get size() {
|
|
1666
|
+
return this._size;
|
|
1667
|
+
}
|
|
1668
|
+
/**
|
|
1669
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
|
|
1670
|
+
*/
|
|
1671
|
+
get viewBox() {
|
|
1672
|
+
const [x, y] = this.center;
|
|
1673
|
+
return `${x},${y},${this._size.width},${this._size.height}`;
|
|
1674
|
+
}
|
|
1675
|
+
setSize(size) {
|
|
1676
|
+
this._size = {
|
|
1677
|
+
...size
|
|
1678
|
+
};
|
|
1679
|
+
this._center = this._centered ? [
|
|
1680
|
+
-Math.floor(size.width / 2),
|
|
1681
|
+
-Math.floor(size.height / 2)
|
|
1682
|
+
] : [
|
|
1683
|
+
0,
|
|
1684
|
+
0
|
|
1685
|
+
];
|
|
1686
|
+
this.resized.emit(this);
|
|
1687
|
+
}
|
|
1688
|
+
setTransform(transform) {
|
|
1689
|
+
if (this._scale.setTransform(transform)) {
|
|
1690
|
+
this.resized.emit(this);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
/**
|
|
1694
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
|
|
1695
|
+
* @param point
|
|
1696
|
+
*/
|
|
1697
|
+
elementFromPoint(point) {
|
|
1698
|
+
const [x, y] = point;
|
|
1699
|
+
const [cx, cy] = this._center;
|
|
1700
|
+
return document.elementFromPoint(cx + x, cy + y);
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
var SVGContextType = createContext(void 0);
|
|
1704
|
+
var SVGContextProvider = SVGContextType.Provider;
|
|
1705
|
+
var useSvgContext = () => {
|
|
1706
|
+
return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
// src/hooks/useGrid.ts
|
|
1710
|
+
var createLine4 = line4();
|
|
1711
|
+
var createGrid = (context, options) => {
|
|
1712
|
+
if (!context.size) {
|
|
1713
|
+
return [];
|
|
1714
|
+
}
|
|
1715
|
+
const paths = [];
|
|
1716
|
+
const { width, height } = context.size;
|
|
1717
|
+
const { x, y, k } = context.scale.transform;
|
|
1718
|
+
const s = 1 / k;
|
|
1719
|
+
const w = width * s;
|
|
1720
|
+
const h = height * s;
|
|
1721
|
+
const dx = -(x + width / 2) * s;
|
|
1722
|
+
const dy = -(y + height / 2) * s;
|
|
1723
|
+
if (options.axis) {
|
|
1724
|
+
const axis = [
|
|
1725
|
+
[
|
|
1726
|
+
[
|
|
1727
|
+
0,
|
|
1728
|
+
dy
|
|
1729
|
+
],
|
|
1730
|
+
[
|
|
1731
|
+
0,
|
|
1732
|
+
dy + h
|
|
1733
|
+
]
|
|
1734
|
+
],
|
|
1735
|
+
[
|
|
1736
|
+
[
|
|
1737
|
+
dx,
|
|
1738
|
+
0
|
|
1739
|
+
],
|
|
1740
|
+
[
|
|
1741
|
+
dx + w,
|
|
1742
|
+
0
|
|
1743
|
+
]
|
|
1744
|
+
]
|
|
1745
|
+
];
|
|
1746
|
+
paths.push({
|
|
1747
|
+
id: "axis",
|
|
1748
|
+
class: "dx-axis",
|
|
1749
|
+
path: axis.map((line5) => createLine4(line5)).join()
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
if (options.grid) {
|
|
1753
|
+
const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
|
|
1754
|
+
const majorSize = context.scale.gridSize;
|
|
1755
|
+
const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
|
|
1756
|
+
const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
|
|
1757
|
+
const major = [
|
|
1758
|
+
...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
|
|
1759
|
+
[
|
|
1760
|
+
x2,
|
|
1761
|
+
dy
|
|
1762
|
+
],
|
|
1763
|
+
[
|
|
1764
|
+
x2,
|
|
1765
|
+
dy + h
|
|
1766
|
+
]
|
|
1767
|
+
]),
|
|
1768
|
+
...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
|
|
1769
|
+
[
|
|
1770
|
+
dx,
|
|
1771
|
+
y2
|
|
1772
|
+
],
|
|
1773
|
+
[
|
|
1774
|
+
dx + w,
|
|
1775
|
+
y2
|
|
1776
|
+
]
|
|
1777
|
+
])
|
|
1778
|
+
];
|
|
1779
|
+
paths.push({
|
|
1780
|
+
id: "major",
|
|
1781
|
+
class: "dx-major",
|
|
1782
|
+
path: major.map((line5) => createLine4(line5)).join()
|
|
1292
1783
|
});
|
|
1293
|
-
|
|
1294
|
-
|
|
1784
|
+
const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
|
|
1785
|
+
if (majorSize > minorSize) {
|
|
1786
|
+
const xMinor = range(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
|
|
1787
|
+
const yMinor = range(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
|
|
1788
|
+
const minor = [
|
|
1789
|
+
...xMinor.filter((x2) => xMajor.indexOf(x2) === -1).map((x2) => [
|
|
1790
|
+
[
|
|
1791
|
+
x2,
|
|
1792
|
+
dy
|
|
1793
|
+
],
|
|
1794
|
+
[
|
|
1795
|
+
x2,
|
|
1796
|
+
dy + h
|
|
1797
|
+
]
|
|
1798
|
+
]),
|
|
1799
|
+
...yMinor.filter((y2) => yMajor.indexOf(y2) === -1).map((y2) => [
|
|
1800
|
+
[
|
|
1801
|
+
dx,
|
|
1802
|
+
y2
|
|
1803
|
+
],
|
|
1804
|
+
[
|
|
1805
|
+
dx + w,
|
|
1806
|
+
y2
|
|
1807
|
+
]
|
|
1808
|
+
])
|
|
1809
|
+
];
|
|
1810
|
+
paths.push({
|
|
1811
|
+
id: "minor",
|
|
1812
|
+
class: "dx-minor",
|
|
1813
|
+
path: minor.map((line5) => createLine4(line5)).join()
|
|
1814
|
+
});
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
return paths;
|
|
1818
|
+
};
|
|
1819
|
+
var defaultGridOptions = {
|
|
1820
|
+
visible: true,
|
|
1821
|
+
axis: true,
|
|
1822
|
+
grid: true
|
|
1823
|
+
};
|
|
1824
|
+
var GridController = class {
|
|
1825
|
+
_ref;
|
|
1826
|
+
_context;
|
|
1827
|
+
_options;
|
|
1828
|
+
_visible = false;
|
|
1829
|
+
constructor(_ref, _context, _options) {
|
|
1830
|
+
this._ref = _ref;
|
|
1831
|
+
this._context = _context;
|
|
1832
|
+
this._options = _options;
|
|
1833
|
+
this._visible = this._options.visible ?? true;
|
|
1295
1834
|
}
|
|
1835
|
+
get ref() {
|
|
1836
|
+
return this._ref;
|
|
1837
|
+
}
|
|
1838
|
+
get visible() {
|
|
1839
|
+
return this._visible;
|
|
1840
|
+
}
|
|
1841
|
+
draw() {
|
|
1842
|
+
if (!this._context.size) {
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
const paths = this._visible ? createGrid(this._context, this._options) : [];
|
|
1846
|
+
const root = select5(this._ref.current);
|
|
1847
|
+
root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
|
|
1848
|
+
const transform = this._context.scale.transform;
|
|
1849
|
+
if (transform) {
|
|
1850
|
+
root.attr("transform", transform);
|
|
1851
|
+
root.attr("stroke-width", 1 / transform.k);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
setVisible(visible) {
|
|
1855
|
+
this._visible = visible;
|
|
1856
|
+
this.draw();
|
|
1857
|
+
return this;
|
|
1858
|
+
}
|
|
1859
|
+
};
|
|
1860
|
+
var useGrid = (options = defaultGridOptions) => {
|
|
1861
|
+
const ref = useRef(null);
|
|
1862
|
+
const context = useSvgContext();
|
|
1863
|
+
const controller = useMemo(() => new GridController(ref, context, options), []);
|
|
1864
|
+
useEffect(() => context.resized.on(() => controller.draw()), [
|
|
1865
|
+
context,
|
|
1866
|
+
controller
|
|
1867
|
+
]);
|
|
1868
|
+
return controller;
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
// src/hooks/useZoom.ts
|
|
1872
|
+
import { select as select6, zoom, zoomIdentity as zoomIdentity2 } from "d3";
|
|
1873
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
1874
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
1875
|
+
var defaultZoomOptions = {
|
|
1876
|
+
enabled: true,
|
|
1877
|
+
extent: [
|
|
1878
|
+
1 / 4,
|
|
1879
|
+
4
|
|
1880
|
+
],
|
|
1881
|
+
onDblClick: (zoom2) => zoom2.reset()
|
|
1882
|
+
};
|
|
1883
|
+
var ZoomHandler = class {
|
|
1884
|
+
_ref;
|
|
1885
|
+
_context;
|
|
1886
|
+
_zoom;
|
|
1887
|
+
_options;
|
|
1888
|
+
_enabled;
|
|
1889
|
+
constructor(_ref, _context, options) {
|
|
1890
|
+
this._ref = _ref;
|
|
1891
|
+
this._context = _context;
|
|
1892
|
+
this._options = defaultsDeep({}, options, defaultZoomOptions);
|
|
1893
|
+
this._enabled = this._options.enabled ?? true;
|
|
1894
|
+
this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
|
|
1895
|
+
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Gets the reference which the transform is applied to.
|
|
1898
|
+
*/
|
|
1899
|
+
get ref() {
|
|
1900
|
+
return this._ref;
|
|
1901
|
+
}
|
|
1902
|
+
get zoom() {
|
|
1903
|
+
return this._zoom;
|
|
1904
|
+
}
|
|
1905
|
+
init() {
|
|
1906
|
+
this.setEnabled(this._enabled);
|
|
1907
|
+
this.reset(0);
|
|
1908
|
+
return this;
|
|
1909
|
+
}
|
|
1910
|
+
setEnabled(enable) {
|
|
1911
|
+
if (enable) {
|
|
1912
|
+
select6(this._context.svg).call(this._zoom).on(
|
|
1913
|
+
"dblclick.zoom",
|
|
1914
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1915
|
+
// @ts-ignore
|
|
1916
|
+
this._options?.onDblClick ? () => {
|
|
1917
|
+
this._options?.onDblClick(this);
|
|
1918
|
+
} : null
|
|
1919
|
+
);
|
|
1920
|
+
} else {
|
|
1921
|
+
select6(this._context.svg).on(".zoom", null);
|
|
1922
|
+
}
|
|
1923
|
+
this._enabled = enable;
|
|
1924
|
+
return this;
|
|
1925
|
+
}
|
|
1926
|
+
reset(duration = 500) {
|
|
1927
|
+
const scale = 1;
|
|
1928
|
+
const transform = zoomIdentity2.scale(scale);
|
|
1929
|
+
select6(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
|
|
1930
|
+
return this;
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
var useZoom = (options = defaultZoomOptions) => {
|
|
1934
|
+
const context = useSvgContext();
|
|
1935
|
+
const ref = useRef2(null);
|
|
1936
|
+
const handler = useMemo2(() => new ZoomHandler(ref, context, options), [
|
|
1937
|
+
context,
|
|
1938
|
+
options
|
|
1939
|
+
]);
|
|
1940
|
+
useEffect2(() => {
|
|
1941
|
+
handler.zoom.on("zoom", ({ transform }) => {
|
|
1942
|
+
context.setTransform(transform);
|
|
1943
|
+
select6(ref.current).attr("transform", transform);
|
|
1944
|
+
});
|
|
1945
|
+
handler.init();
|
|
1946
|
+
}, [
|
|
1947
|
+
handler
|
|
1948
|
+
]);
|
|
1949
|
+
return handler;
|
|
1950
|
+
};
|
|
1951
|
+
|
|
1952
|
+
// src/components/Graph/Graph.tsx
|
|
1953
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
1954
|
+
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
1955
|
+
const context = useSvgContext();
|
|
1956
|
+
const graphRef = useRef3(null);
|
|
1957
|
+
const { projector, renderer } = useMemo3(() => {
|
|
1958
|
+
let projector2 = projectorProp;
|
|
1959
|
+
if (!projector2) {
|
|
1960
|
+
projector2 = new GraphForceProjector(context);
|
|
1961
|
+
}
|
|
1962
|
+
let renderer2 = rendererProp;
|
|
1963
|
+
if (!renderer2) {
|
|
1964
|
+
renderer2 = new GraphRenderer(context, graphRef, {
|
|
1965
|
+
...props,
|
|
1966
|
+
// TODO(burdon): Replace drag when projector is updated.
|
|
1967
|
+
drag: drag2 ? createGraphDrag(context, projector2) : void 0,
|
|
1968
|
+
arrows: {
|
|
1969
|
+
end: arrows
|
|
1970
|
+
},
|
|
1971
|
+
onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
|
|
1972
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
return {
|
|
1976
|
+
projector: projector2,
|
|
1977
|
+
renderer: renderer2
|
|
1978
|
+
};
|
|
1979
|
+
}, [
|
|
1980
|
+
context,
|
|
1981
|
+
projectorProp,
|
|
1982
|
+
rendererProp,
|
|
1983
|
+
drag2
|
|
1984
|
+
]);
|
|
1985
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
1986
|
+
refresh: () => {
|
|
1987
|
+
projector.updateData(model?.graph);
|
|
1988
|
+
},
|
|
1989
|
+
repaint: () => {
|
|
1990
|
+
renderer.render(projector.layout);
|
|
1991
|
+
},
|
|
1992
|
+
findNode: (id) => {
|
|
1993
|
+
return graphRef.current?.querySelector(`g[data-id="${id}"]`);
|
|
1994
|
+
}
|
|
1995
|
+
}), [
|
|
1996
|
+
model,
|
|
1997
|
+
projector,
|
|
1998
|
+
renderer
|
|
1999
|
+
]);
|
|
2000
|
+
useEffect3(() => {
|
|
2001
|
+
projector.updateData(model?.graph);
|
|
2002
|
+
const unsubscribeModel = model ? model.subscribe(() => {
|
|
2003
|
+
projector.updateData(model?.graph);
|
|
2004
|
+
}) : void 0;
|
|
2005
|
+
return combine(unsubscribeModel, projector.updated.on(({ layout }) => {
|
|
2006
|
+
try {
|
|
2007
|
+
renderer.render(layout);
|
|
2008
|
+
} catch (error) {
|
|
2009
|
+
void projector.stop();
|
|
2010
|
+
log6.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 71, S: void 0 });
|
|
2011
|
+
}
|
|
2012
|
+
}));
|
|
2013
|
+
}, [
|
|
2014
|
+
model,
|
|
2015
|
+
projector,
|
|
2016
|
+
renderer
|
|
2017
|
+
]);
|
|
2018
|
+
useEffect3(() => {
|
|
2019
|
+
void projector.start();
|
|
2020
|
+
return () => {
|
|
2021
|
+
void projector.stop();
|
|
2022
|
+
};
|
|
2023
|
+
}, [
|
|
2024
|
+
projector
|
|
2025
|
+
]);
|
|
2026
|
+
return /* @__PURE__ */ React.createElement("g", {
|
|
2027
|
+
ref: graphRef,
|
|
2028
|
+
className: mx("dx-graph", classNames)
|
|
2029
|
+
});
|
|
1296
2030
|
};
|
|
1297
2031
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1298
2032
|
|
|
1299
2033
|
// src/components/Mesh/Mesh.tsx
|
|
1300
|
-
import { geoPath, select as
|
|
1301
|
-
import { useEffect as
|
|
2034
|
+
import { geoPath, select as select7 } from "d3";
|
|
2035
|
+
import { useEffect as useEffect4 } from "react";
|
|
1302
2036
|
import { feature, mesh } from "topojson-client";
|
|
1303
2037
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1304
2038
|
const { svg, size } = useSvgContext();
|
|
1305
|
-
|
|
2039
|
+
useEffect4(() => {
|
|
1306
2040
|
if (size) {
|
|
1307
2041
|
const topology = hexTopology(size, radius, value);
|
|
1308
2042
|
const projection = hexProjection(radius);
|
|
1309
2043
|
const path = geoPath().projection(projection);
|
|
1310
|
-
|
|
1311
|
-
|
|
2044
|
+
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);
|
|
2045
|
+
select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
1312
2046
|
const redraw = (border) => {
|
|
1313
2047
|
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1314
2048
|
};
|
|
1315
|
-
|
|
2049
|
+
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
1316
2050
|
}
|
|
1317
2051
|
}, [
|
|
1318
2052
|
svg,
|
|
@@ -1429,115 +2163,96 @@ var hexProjection = (radius) => {
|
|
|
1429
2163
|
};
|
|
1430
2164
|
|
|
1431
2165
|
// src/components/SVG/Grid.tsx
|
|
1432
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
1433
2166
|
import React2 from "react";
|
|
1434
|
-
import { mx as mx2 } from "@dxos/
|
|
2167
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1435
2168
|
var Grid = ({ classNames, ...props }) => {
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
className: mx2("dx-grid", classNames)
|
|
1442
|
-
});
|
|
1443
|
-
} finally {
|
|
1444
|
-
_effect.f();
|
|
1445
|
-
}
|
|
2169
|
+
const { ref } = useGrid(props);
|
|
2170
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
2171
|
+
ref,
|
|
2172
|
+
className: mx2("dx-grid", classNames)
|
|
2173
|
+
});
|
|
1446
2174
|
};
|
|
1447
2175
|
|
|
1448
2176
|
// src/components/SVG/Markers.tsx
|
|
1449
|
-
import {
|
|
1450
|
-
import {
|
|
1451
|
-
import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
2177
|
+
import { select as select8 } from "d3";
|
|
2178
|
+
import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
1452
2179
|
var Markers = ({ arrowSize, className }) => {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
className
|
|
1466
|
-
});
|
|
1467
|
-
} finally {
|
|
1468
|
-
_effect.f();
|
|
1469
|
-
}
|
|
2180
|
+
const ref = useRef4(null);
|
|
2181
|
+
useEffect5(() => {
|
|
2182
|
+
select8(ref.current).call(createMarkers({
|
|
2183
|
+
arrowSize
|
|
2184
|
+
}));
|
|
2185
|
+
}, [
|
|
2186
|
+
ref
|
|
2187
|
+
]);
|
|
2188
|
+
return /* @__PURE__ */ React3.createElement("defs", {
|
|
2189
|
+
ref,
|
|
2190
|
+
className
|
|
2191
|
+
});
|
|
1470
2192
|
};
|
|
1471
2193
|
|
|
1472
2194
|
// src/components/SVG/Root.tsx
|
|
1473
|
-
import {
|
|
1474
|
-
import {
|
|
1475
|
-
import React4, { forwardRef as forwardRef2, useEffect as useEffect4, useImperativeHandle as useImperativeHandle2, useMemo as useMemo2 } from "react";
|
|
2195
|
+
import { select as select9 } from "d3";
|
|
2196
|
+
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
|
|
1476
2197
|
import { useResizeDetector } from "react-resize-detector";
|
|
1477
|
-
import { mx as mx3 } from "@dxos/
|
|
1478
|
-
var Root = /* @__PURE__ */ forwardRef2(({
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
2198
|
+
import { composableProps, mx as mx3 } from "@dxos/ui-theme";
|
|
2199
|
+
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
2200
|
+
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
|
|
2201
|
+
refreshRate: 200
|
|
2202
|
+
});
|
|
2203
|
+
const context = useMemo4(() => {
|
|
2204
|
+
return new SVGContext({
|
|
2205
|
+
scale,
|
|
2206
|
+
centered
|
|
1483
2207
|
});
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
} finally {
|
|
1518
|
-
_effect.f();
|
|
1519
|
-
}
|
|
2208
|
+
}, [
|
|
2209
|
+
scale,
|
|
2210
|
+
centered
|
|
2211
|
+
]);
|
|
2212
|
+
useImperativeHandle2(ref, () => context, [
|
|
2213
|
+
context
|
|
2214
|
+
]);
|
|
2215
|
+
useEffect6(() => {
|
|
2216
|
+
if (width && height) {
|
|
2217
|
+
context.setSize({
|
|
2218
|
+
width,
|
|
2219
|
+
height
|
|
2220
|
+
});
|
|
2221
|
+
select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
2222
|
+
}
|
|
2223
|
+
}, [
|
|
2224
|
+
context,
|
|
2225
|
+
width,
|
|
2226
|
+
height
|
|
2227
|
+
]);
|
|
2228
|
+
const ready = width !== 0 && height !== 0;
|
|
2229
|
+
return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
|
|
2230
|
+
value: context
|
|
2231
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
2232
|
+
...composableProps(props, {
|
|
2233
|
+
classNames: "dx-expander"
|
|
2234
|
+
}),
|
|
2235
|
+
ref: containerRef
|
|
2236
|
+
}, /* @__PURE__ */ React4.createElement("svg", {
|
|
2237
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2238
|
+
ref: context.ref,
|
|
2239
|
+
className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
2240
|
+
}, ready && children)));
|
|
1520
2241
|
});
|
|
1521
2242
|
|
|
1522
2243
|
// src/components/SVG/Zoom.tsx
|
|
1523
|
-
import {
|
|
1524
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
2244
|
+
import React5, { memo, useMemo as useMemo5 } from "react";
|
|
1525
2245
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
className
|
|
1537
|
-
}, children);
|
|
1538
|
-
} finally {
|
|
1539
|
-
_effect.f();
|
|
1540
|
-
}
|
|
2246
|
+
const options = useMemo5(() => ({
|
|
2247
|
+
extent
|
|
2248
|
+
}), [
|
|
2249
|
+
JSON.stringify(extent)
|
|
2250
|
+
]);
|
|
2251
|
+
const zoom2 = useZoom(options);
|
|
2252
|
+
return /* @__PURE__ */ React5.createElement("g", {
|
|
2253
|
+
ref: zoom2.ref,
|
|
2254
|
+
className
|
|
2255
|
+
}, children);
|
|
1541
2256
|
});
|
|
1542
2257
|
|
|
1543
2258
|
// src/components/SVG/SVG.tsx
|
|
@@ -1551,7 +2266,7 @@ var SVG = {
|
|
|
1551
2266
|
};
|
|
1552
2267
|
|
|
1553
2268
|
// src/fx/pulsar.ts
|
|
1554
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
2269
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1555
2270
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1556
2271
|
(function(Pulsar2) {
|
|
1557
2272
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1566,10 +2281,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1566
2281
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1567
2282
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1568
2283
|
return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(easeCubicOut2).attr("r", r * ratio).attr("opacity", -0.1).on("end", function() {
|
|
1569
|
-
if (
|
|
1570
|
-
startAnimation(
|
|
2284
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
2285
|
+
startAnimation(select10(this), r, options);
|
|
1571
2286
|
} else {
|
|
1572
|
-
|
|
2287
|
+
select10(this).remove();
|
|
1573
2288
|
}
|
|
1574
2289
|
});
|
|
1575
2290
|
};
|
|
@@ -1580,7 +2295,6 @@ export {
|
|
|
1580
2295
|
Graph,
|
|
1581
2296
|
GraphForceProjector,
|
|
1582
2297
|
GraphHierarchicalProjector,
|
|
1583
|
-
GraphInner,
|
|
1584
2298
|
GraphProjector,
|
|
1585
2299
|
GraphRadialProjector,
|
|
1586
2300
|
GraphRelationalProjector,
|