@dxos/react-ui-graph 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33
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 +1069 -289
- 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 +1069 -289
- 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 +17 -8
- 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 +9 -5
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
- package/dist/types/src/components/SVG/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 +11 -9
- package/dist/types/src/components/SVG/Svg.stories.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/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 +14 -9
- 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 +63 -60
- package/src/components/Graph/Graph.tsx +24 -16
- package/src/components/Mesh/Mesh.stories.tsx +9 -9
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Markers.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 +22 -19
- package/src/fx/fx.stories.tsx +17 -15
- 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 +0 -1
- package/src/graph/types.ts +1 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/stories/hooks.stories.tsx +38 -31
- 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-HLAKLUDC.mjs +0 -958
- package/dist/lib/browser/chunk-HLAKLUDC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-O6GWCXDC.mjs +0 -960
- package/dist/lib/node-esm/chunk-O6GWCXDC.mjs.map +0 -7
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EventEmitter,
|
|
3
|
-
FractionUtil,
|
|
4
|
-
GridController,
|
|
5
|
-
SVGContext,
|
|
6
|
-
SVGContextProvider,
|
|
7
|
-
Scale,
|
|
8
|
-
Screen,
|
|
9
|
-
Vector,
|
|
10
|
-
ZoomHandler,
|
|
11
|
-
getCircumferencePoints,
|
|
12
|
-
normal,
|
|
13
|
-
offsetPoints,
|
|
14
2
|
useDynamicRef,
|
|
15
|
-
useGrid,
|
|
16
3
|
useStateRef,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
useZoom
|
|
20
|
-
} from "./chunk-HLAKLUDC.mjs";
|
|
4
|
+
useTimestamp
|
|
5
|
+
} from "./chunk-EASNZZ7B.mjs";
|
|
21
6
|
|
|
22
7
|
// src/components/Graph/Graph.tsx
|
|
23
|
-
import {
|
|
24
|
-
import { effect } from "@preact/signals-core";
|
|
25
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
8
|
+
import React, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo3, useRef as useRef3 } from "react";
|
|
26
9
|
import { combine } from "@dxos/async";
|
|
27
10
|
import { log as log6 } from "@dxos/log";
|
|
28
|
-
import { mx } from "@dxos/
|
|
11
|
+
import { mx } from "@dxos/ui-theme";
|
|
29
12
|
|
|
30
13
|
// src/graph/markers.ts
|
|
31
14
|
import { line, select } from "d3";
|
|
@@ -162,15 +145,7 @@ var createGraphDrag = (context, projector, options = defaultDragOptions) => {
|
|
|
162
145
|
import { invariant } from "@dxos/invariant";
|
|
163
146
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
|
|
164
147
|
var defaultIdAccessor = (node) => {
|
|
165
|
-
invariant(node.id, void 0, {
|
|
166
|
-
F: __dxlog_file,
|
|
167
|
-
L: 18,
|
|
168
|
-
S: void 0,
|
|
169
|
-
A: [
|
|
170
|
-
"node.id",
|
|
171
|
-
""
|
|
172
|
-
]
|
|
173
|
-
});
|
|
148
|
+
invariant(node.id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 10, S: void 0, A: ["node.id", ""] });
|
|
174
149
|
return node.id;
|
|
175
150
|
};
|
|
176
151
|
var emptyGraph = {
|
|
@@ -178,14 +153,577 @@ var emptyGraph = {
|
|
|
178
153
|
edges: []
|
|
179
154
|
};
|
|
180
155
|
|
|
156
|
+
// src/util/events.ts
|
|
157
|
+
var EventEmitter = class {
|
|
158
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
159
|
+
clear() {
|
|
160
|
+
this._listeners.clear();
|
|
161
|
+
}
|
|
162
|
+
on(onEvent) {
|
|
163
|
+
this._listeners.add(onEvent);
|
|
164
|
+
return () => this._listeners.delete(onEvent);
|
|
165
|
+
}
|
|
166
|
+
emit(value) {
|
|
167
|
+
this._listeners.forEach((listener) => listener(value));
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/util/fraction.ts
|
|
172
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
173
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
|
|
174
|
+
var FractionUtil = class _FractionUtil {
|
|
175
|
+
/**
|
|
176
|
+
* Convert number to fraction.
|
|
177
|
+
* @param n
|
|
178
|
+
*/
|
|
179
|
+
static toFraction = (n) => {
|
|
180
|
+
return typeof n === "number" ? [
|
|
181
|
+
n,
|
|
182
|
+
1
|
|
183
|
+
] : n;
|
|
184
|
+
};
|
|
185
|
+
static validate = (...fraction) => {
|
|
186
|
+
fraction.forEach(([n, d]) => {
|
|
187
|
+
if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
|
|
188
|
+
throw new Error(`Invalid fraction: ${n}/${d}`);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
return fraction;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* @param {Fraction}
|
|
195
|
+
* Convert to rounded-sm number.
|
|
196
|
+
*/
|
|
197
|
+
static toNumber = ([n, d]) => {
|
|
198
|
+
_FractionUtil.validate([
|
|
199
|
+
n,
|
|
200
|
+
d
|
|
201
|
+
]);
|
|
202
|
+
return n / d;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Round the number to the nearest fraction.
|
|
206
|
+
* Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
|
|
207
|
+
* @param {Fraction}
|
|
208
|
+
* @param p Precision (e.g., 1/2, 1/4, etc.)
|
|
209
|
+
*/
|
|
210
|
+
static round = ([n, d], p = 1) => {
|
|
211
|
+
_FractionUtil.validate([
|
|
212
|
+
n,
|
|
213
|
+
d
|
|
214
|
+
]);
|
|
215
|
+
const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
|
|
216
|
+
n,
|
|
217
|
+
d
|
|
218
|
+
], [
|
|
219
|
+
1,
|
|
220
|
+
p
|
|
221
|
+
])));
|
|
222
|
+
return _FractionUtil.simplify([
|
|
223
|
+
v,
|
|
224
|
+
p
|
|
225
|
+
]);
|
|
226
|
+
};
|
|
227
|
+
//
|
|
228
|
+
// Boolean.
|
|
229
|
+
//
|
|
230
|
+
/**
|
|
231
|
+
* Tests if equals.
|
|
232
|
+
* @param n1
|
|
233
|
+
* @param n2
|
|
234
|
+
*/
|
|
235
|
+
static equals = (n1, n2) => {
|
|
236
|
+
return n1[0] * n2[1] === n1[1] * n2[0];
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* @param {Fraction}
|
|
240
|
+
* True if zero.
|
|
241
|
+
*/
|
|
242
|
+
static isZero = ([n]) => {
|
|
243
|
+
return n === 0;
|
|
244
|
+
};
|
|
245
|
+
//
|
|
246
|
+
// Normalization.
|
|
247
|
+
//
|
|
248
|
+
/**
|
|
249
|
+
* Simplify fraction finding LCDs.
|
|
250
|
+
* @param n
|
|
251
|
+
* @param d
|
|
252
|
+
*/
|
|
253
|
+
static simplify = ([n, d]) => {
|
|
254
|
+
_FractionUtil.validate([
|
|
255
|
+
n,
|
|
256
|
+
d
|
|
257
|
+
]);
|
|
258
|
+
if (d < 1) {
|
|
259
|
+
const t = n / d;
|
|
260
|
+
if (Math.floor(t) === t) {
|
|
261
|
+
n = t;
|
|
262
|
+
d = 1;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const fn = _FractionUtil.factors(n).reverse();
|
|
266
|
+
const fd = _FractionUtil.factors(d).reverse();
|
|
267
|
+
let c;
|
|
268
|
+
for (let i = 0; i < fn.length; i++) {
|
|
269
|
+
c = fd.find((n2) => n2 === fn[i]);
|
|
270
|
+
if (c) {
|
|
271
|
+
return [
|
|
272
|
+
n / c,
|
|
273
|
+
d / c
|
|
274
|
+
];
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return [
|
|
278
|
+
n,
|
|
279
|
+
d
|
|
280
|
+
];
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Return common factors.
|
|
284
|
+
* @param n
|
|
285
|
+
*/
|
|
286
|
+
static factors = (n) => {
|
|
287
|
+
invariant2(Number.isFinite(n), `Invalid number: ${n}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 113, S: this, A: ["Number.isFinite(n)", "`Invalid number: ${n}`"] });
|
|
288
|
+
const factors = [
|
|
289
|
+
1
|
|
290
|
+
];
|
|
291
|
+
if (Number.isSafeInteger(n)) {
|
|
292
|
+
let f = 1;
|
|
293
|
+
do {
|
|
294
|
+
if (n % ++f === 0) {
|
|
295
|
+
factors.push(f);
|
|
296
|
+
}
|
|
297
|
+
} while (n / f > 1 && f < 100);
|
|
298
|
+
}
|
|
299
|
+
return factors;
|
|
300
|
+
};
|
|
301
|
+
//
|
|
302
|
+
// Basic arithmetic.
|
|
303
|
+
//
|
|
304
|
+
/**
|
|
305
|
+
* @param n1
|
|
306
|
+
* @param n2
|
|
307
|
+
*/
|
|
308
|
+
static add = (n1, n2) => {
|
|
309
|
+
_FractionUtil.validate(n1, n2);
|
|
310
|
+
const d = n1[1] * n2[1];
|
|
311
|
+
const n = n1[0] * n2[1] + n2[0] * n1[1];
|
|
312
|
+
return _FractionUtil.simplify([
|
|
313
|
+
n,
|
|
314
|
+
d
|
|
315
|
+
]);
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* @param n1
|
|
319
|
+
* @param n2
|
|
320
|
+
*/
|
|
321
|
+
static subtract = (n1, n2) => {
|
|
322
|
+
_FractionUtil.validate(n1, n2);
|
|
323
|
+
const d = n1[1] * n2[1];
|
|
324
|
+
const n = n1[0] * n2[1] - n2[0] * n1[1];
|
|
325
|
+
return _FractionUtil.simplify([
|
|
326
|
+
n,
|
|
327
|
+
d
|
|
328
|
+
]);
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* @param n1
|
|
332
|
+
* @param n2
|
|
333
|
+
*/
|
|
334
|
+
static multiply = (n1, n2) => {
|
|
335
|
+
_FractionUtil.validate(n1, n2);
|
|
336
|
+
const n = n1[0] * n2[0];
|
|
337
|
+
const d = n1[1] * n2[1];
|
|
338
|
+
return _FractionUtil.simplify([
|
|
339
|
+
n,
|
|
340
|
+
d
|
|
341
|
+
]);
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* @param n1
|
|
345
|
+
* @param n2
|
|
346
|
+
*/
|
|
347
|
+
static divide = (n1, n2) => {
|
|
348
|
+
_FractionUtil.validate(n1, n2);
|
|
349
|
+
const n = n1[0] * n2[1];
|
|
350
|
+
const d = n1[1] * n2[0];
|
|
351
|
+
return _FractionUtil.simplify([
|
|
352
|
+
n,
|
|
353
|
+
d
|
|
354
|
+
]);
|
|
355
|
+
};
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
// src/util/points.ts
|
|
359
|
+
var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
|
|
360
|
+
const [x1, y1] = p1;
|
|
361
|
+
const [x2, y2] = p2;
|
|
362
|
+
const theta = Math.atan2(x2 - x1, y2 - y1);
|
|
363
|
+
return [
|
|
364
|
+
[
|
|
365
|
+
// p1
|
|
366
|
+
x1 + (r1 === 0 ? 0 : r1 * Math.sin(theta)),
|
|
367
|
+
y1 + (r1 === 0 ? 0 : r1 * Math.cos(theta))
|
|
368
|
+
],
|
|
369
|
+
[
|
|
370
|
+
// p2
|
|
371
|
+
x2 - (r2 === 0 ? 0 : r2 * Math.cos(Math.PI / 2 - theta)),
|
|
372
|
+
y2 - (r2 === 0 ? 0 : r2 * Math.sin(Math.PI / 2 - theta))
|
|
373
|
+
]
|
|
374
|
+
];
|
|
375
|
+
};
|
|
376
|
+
var normal = (p1, p2) => {
|
|
377
|
+
const dx = p2[0] - p1[0];
|
|
378
|
+
const dy = p2[1] - p1[1];
|
|
379
|
+
const len = Math.hypot(dx, dy);
|
|
380
|
+
return [
|
|
381
|
+
dy / len,
|
|
382
|
+
-dx / len
|
|
383
|
+
];
|
|
384
|
+
};
|
|
385
|
+
var offsetPoints = (points, distance, closed) => {
|
|
386
|
+
const len = points.length;
|
|
387
|
+
const out = [];
|
|
388
|
+
for (let i = 0; i < len; i++) {
|
|
389
|
+
const p0 = points[(i - 1 + len) % len];
|
|
390
|
+
const p1 = points[i];
|
|
391
|
+
const p2 = points[(i + 1) % len];
|
|
392
|
+
const n1 = normal(p0, p1);
|
|
393
|
+
const n2 = normal(p1, p2);
|
|
394
|
+
const nx = (n1[0] + n2[0]) / 2;
|
|
395
|
+
const ny = (n1[1] + n2[1]) / 2;
|
|
396
|
+
const norm = Math.hypot(nx, ny) || 1;
|
|
397
|
+
out.push([
|
|
398
|
+
p1[0] + distance * nx / norm,
|
|
399
|
+
p1[1] + distance * ny / norm
|
|
400
|
+
]);
|
|
401
|
+
if (!closed && (i === 0 || i === len - 1)) {
|
|
402
|
+
out[i] = [
|
|
403
|
+
p1[0] + distance * normal(p0, p1)[0],
|
|
404
|
+
p1[1] + distance * normal(p0, p1)[1]
|
|
405
|
+
];
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return out;
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
// src/util/scale.ts
|
|
412
|
+
import { zoomIdentity } from "d3";
|
|
413
|
+
var Scale = class {
|
|
414
|
+
_gridSize;
|
|
415
|
+
_transform;
|
|
416
|
+
constructor(_gridSize = 32) {
|
|
417
|
+
this._gridSize = _gridSize;
|
|
418
|
+
}
|
|
419
|
+
get gridSize() {
|
|
420
|
+
return this._gridSize;
|
|
421
|
+
}
|
|
422
|
+
get transform() {
|
|
423
|
+
return this._transform || zoomIdentity;
|
|
424
|
+
}
|
|
425
|
+
setTransform(transform) {
|
|
426
|
+
if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
this._transform = transform;
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Translate a screen point to a logical point.
|
|
434
|
+
* @param point
|
|
435
|
+
*/
|
|
436
|
+
translate(point) {
|
|
437
|
+
const { x, y, k } = this._transform ?? {
|
|
438
|
+
x: 0,
|
|
439
|
+
y: 0,
|
|
440
|
+
k: 1
|
|
441
|
+
};
|
|
442
|
+
return [
|
|
443
|
+
(point[0] - x) / k,
|
|
444
|
+
(point[1] - y) / k
|
|
445
|
+
];
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Map model to screen.
|
|
449
|
+
* Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
|
|
450
|
+
*/
|
|
451
|
+
model = {
|
|
452
|
+
// TODO(burdon): Precision depends on scale.
|
|
453
|
+
snapValues: (array) => array.map((n) => FractionUtil.round(n)),
|
|
454
|
+
snapVertex: ({ x, y }) => {
|
|
455
|
+
const [sx, sy] = this.model.snapValues([
|
|
456
|
+
x,
|
|
457
|
+
y
|
|
458
|
+
]);
|
|
459
|
+
return {
|
|
460
|
+
x: sx,
|
|
461
|
+
y: sy
|
|
462
|
+
};
|
|
463
|
+
},
|
|
464
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
465
|
+
[x, y, width, height] = this.model.snapValues([
|
|
466
|
+
x,
|
|
467
|
+
y,
|
|
468
|
+
width,
|
|
469
|
+
height
|
|
470
|
+
]);
|
|
471
|
+
return {
|
|
472
|
+
x,
|
|
473
|
+
y,
|
|
474
|
+
width,
|
|
475
|
+
height
|
|
476
|
+
};
|
|
477
|
+
},
|
|
478
|
+
toValue: (value) => {
|
|
479
|
+
return Math.round(FractionUtil.toNumber(value) * this._gridSize);
|
|
480
|
+
},
|
|
481
|
+
toValues: (values) => {
|
|
482
|
+
return values.map((value) => Math.round(FractionUtil.toNumber(value) * this._gridSize));
|
|
483
|
+
},
|
|
484
|
+
toPoint: (point) => {
|
|
485
|
+
const [x, y] = this.model.toValues([
|
|
486
|
+
point.x,
|
|
487
|
+
point.y
|
|
488
|
+
]);
|
|
489
|
+
return [
|
|
490
|
+
x,
|
|
491
|
+
y === 0 ? 0 : -y
|
|
492
|
+
];
|
|
493
|
+
},
|
|
494
|
+
toBounds: ({ x, y, width, height }) => {
|
|
495
|
+
const point = this.model.toPoint({
|
|
496
|
+
x,
|
|
497
|
+
y
|
|
498
|
+
});
|
|
499
|
+
const [width2, height2] = this.model.toValues([
|
|
500
|
+
width,
|
|
501
|
+
height
|
|
502
|
+
]);
|
|
503
|
+
return {
|
|
504
|
+
x: point[0],
|
|
505
|
+
y: point[1] - height2,
|
|
506
|
+
width: width2,
|
|
507
|
+
height: height2
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* Map screen to model.
|
|
513
|
+
* Screen points are represented by floating numbers and use translated SVG coordinates (with the y-axis inverted).
|
|
514
|
+
*/
|
|
515
|
+
screen = {
|
|
516
|
+
snapValues: (array) => array.map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
517
|
+
snapPoint: ([x, y]) => [
|
|
518
|
+
x,
|
|
519
|
+
y
|
|
520
|
+
].map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
521
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
522
|
+
[x, y, width, height] = this.screen.snapValues([
|
|
523
|
+
x,
|
|
524
|
+
y,
|
|
525
|
+
width,
|
|
526
|
+
height
|
|
527
|
+
]);
|
|
528
|
+
return {
|
|
529
|
+
x,
|
|
530
|
+
y,
|
|
531
|
+
width,
|
|
532
|
+
height
|
|
533
|
+
};
|
|
534
|
+
},
|
|
535
|
+
toValue: (value) => {
|
|
536
|
+
return FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
537
|
+
this._gridSize,
|
|
538
|
+
1
|
|
539
|
+
]);
|
|
540
|
+
},
|
|
541
|
+
toValues: (values) => {
|
|
542
|
+
return values.map((value) => FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
543
|
+
this._gridSize,
|
|
544
|
+
1
|
|
545
|
+
]));
|
|
546
|
+
},
|
|
547
|
+
toVertex: (point) => {
|
|
548
|
+
const [x, y] = point;
|
|
549
|
+
return {
|
|
550
|
+
x: FractionUtil.toFraction(x / this._gridSize),
|
|
551
|
+
y: FractionUtil.toFraction(-y / this._gridSize)
|
|
552
|
+
};
|
|
553
|
+
},
|
|
554
|
+
toBounds: (bounds) => {
|
|
555
|
+
const { x, y } = this.screen.toVertex([
|
|
556
|
+
bounds.x,
|
|
557
|
+
bounds.y
|
|
558
|
+
]);
|
|
559
|
+
const [width, height] = this.screen.toValues([
|
|
560
|
+
bounds.width,
|
|
561
|
+
bounds.height
|
|
562
|
+
]);
|
|
563
|
+
return {
|
|
564
|
+
x,
|
|
565
|
+
y: FractionUtil.subtract(y, height),
|
|
566
|
+
width,
|
|
567
|
+
height
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
// src/util/screen.ts
|
|
574
|
+
var Screen = class {
|
|
575
|
+
static createBounds = ([x1, y1], [x2, y2], mod = {}) => {
|
|
576
|
+
const { constrain, center } = mod;
|
|
577
|
+
const x = Math.min(x1, x2);
|
|
578
|
+
const y = Math.min(y1, y2);
|
|
579
|
+
let width = Math.abs(x2 - x1);
|
|
580
|
+
let height = Math.abs(y2 - y1);
|
|
581
|
+
if (constrain) {
|
|
582
|
+
width = height = Math.max(width, height);
|
|
583
|
+
}
|
|
584
|
+
if (center) {
|
|
585
|
+
return {
|
|
586
|
+
x: x - width,
|
|
587
|
+
y: y - height,
|
|
588
|
+
width: width * 2,
|
|
589
|
+
height: height * 2
|
|
590
|
+
};
|
|
591
|
+
} else {
|
|
592
|
+
return {
|
|
593
|
+
x,
|
|
594
|
+
y,
|
|
595
|
+
width,
|
|
596
|
+
height
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
static center = ({ x, y, width, height }) => {
|
|
601
|
+
return [
|
|
602
|
+
x + width / 2,
|
|
603
|
+
y + height / 2
|
|
604
|
+
];
|
|
605
|
+
};
|
|
606
|
+
static contains = (bounds, point) => {
|
|
607
|
+
const [x, y] = point;
|
|
608
|
+
if (x < bounds.x || y < bounds.y) {
|
|
609
|
+
return false;
|
|
610
|
+
}
|
|
611
|
+
if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
return true;
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* Distance between two points.
|
|
618
|
+
* @param p1
|
|
619
|
+
* @param p2
|
|
620
|
+
*/
|
|
621
|
+
static len = (p1, p2) => {
|
|
622
|
+
return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
|
|
623
|
+
};
|
|
624
|
+
/**
|
|
625
|
+
* Distance to line segment.
|
|
626
|
+
* https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
|
|
627
|
+
* @param v1
|
|
628
|
+
* @param v2
|
|
629
|
+
* @param p
|
|
630
|
+
*/
|
|
631
|
+
static normal = (v1, v2, p) => {
|
|
632
|
+
const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
|
|
633
|
+
let d;
|
|
634
|
+
const len2 = d2(v1, v2);
|
|
635
|
+
if (len2 === 0) {
|
|
636
|
+
d = d2(p, v1);
|
|
637
|
+
} else {
|
|
638
|
+
let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
|
|
639
|
+
t = Math.max(0, Math.min(1, t));
|
|
640
|
+
d = d2(p, [
|
|
641
|
+
v1[0] + t * (v2[0] - v1[0]),
|
|
642
|
+
v1[1] + t * (v2[1] - v1[1])
|
|
643
|
+
]);
|
|
644
|
+
}
|
|
645
|
+
return Math.sqrt(d);
|
|
646
|
+
};
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
// src/util/vector.ts
|
|
650
|
+
var Vector = class {
|
|
651
|
+
/**
|
|
652
|
+
* Convert to Vertex.
|
|
653
|
+
* @param x
|
|
654
|
+
* @param y
|
|
655
|
+
*/
|
|
656
|
+
static toVertex = ({ x, y }) => ({
|
|
657
|
+
x: FractionUtil.toFraction(x),
|
|
658
|
+
y: FractionUtil.toFraction(y)
|
|
659
|
+
});
|
|
660
|
+
/**
|
|
661
|
+
* Convert to Bounds.
|
|
662
|
+
* @param bounds
|
|
663
|
+
*/
|
|
664
|
+
static toBounds = ({ x, y, width, height }) => ({
|
|
665
|
+
x: FractionUtil.toFraction(x),
|
|
666
|
+
y: FractionUtil.toFraction(y),
|
|
667
|
+
width: FractionUtil.toFraction(width),
|
|
668
|
+
height: FractionUtil.toFraction(height)
|
|
669
|
+
});
|
|
670
|
+
/**
|
|
671
|
+
* Calculate center point.
|
|
672
|
+
* @param bounds
|
|
673
|
+
*/
|
|
674
|
+
static center = ({ x, y, width, height }) => {
|
|
675
|
+
const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
|
|
676
|
+
1,
|
|
677
|
+
2
|
|
678
|
+
]));
|
|
679
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
680
|
+
1,
|
|
681
|
+
2
|
|
682
|
+
]));
|
|
683
|
+
return {
|
|
684
|
+
x: cx,
|
|
685
|
+
y: cy
|
|
686
|
+
};
|
|
687
|
+
};
|
|
688
|
+
/**
|
|
689
|
+
* Calculate centered left edge.
|
|
690
|
+
* @param bounds
|
|
691
|
+
*/
|
|
692
|
+
static left = ({ x, y, height }) => {
|
|
693
|
+
const cx = x;
|
|
694
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
695
|
+
1,
|
|
696
|
+
2
|
|
697
|
+
]));
|
|
698
|
+
return {
|
|
699
|
+
x: cx,
|
|
700
|
+
y: cy
|
|
701
|
+
};
|
|
702
|
+
};
|
|
703
|
+
/**
|
|
704
|
+
* Calculate centered right edge.
|
|
705
|
+
* @param bounds
|
|
706
|
+
*/
|
|
707
|
+
static right = ({ x, y, width, height }) => {
|
|
708
|
+
const cx = FractionUtil.add(x, width);
|
|
709
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
710
|
+
1,
|
|
711
|
+
2
|
|
712
|
+
]));
|
|
713
|
+
return {
|
|
714
|
+
x: cx,
|
|
715
|
+
y: cy
|
|
716
|
+
};
|
|
717
|
+
};
|
|
718
|
+
};
|
|
719
|
+
|
|
181
720
|
// src/graph/projector/projector.ts
|
|
182
721
|
var Projector = class {
|
|
183
722
|
_context;
|
|
184
|
-
updated;
|
|
723
|
+
updated = new EventEmitter();
|
|
185
724
|
_options;
|
|
186
725
|
constructor(_context, options) {
|
|
187
726
|
this._context = _context;
|
|
188
|
-
this.updated = new EventEmitter();
|
|
189
727
|
this._options = Object.assign({
|
|
190
728
|
idAccessor: defaultIdAccessor
|
|
191
729
|
}, options);
|
|
@@ -315,7 +853,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
315
853
|
};
|
|
316
854
|
|
|
317
855
|
// src/graph/projector/graph-force-projector.ts
|
|
318
|
-
var
|
|
856
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
319
857
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
320
858
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
321
859
|
};
|
|
@@ -387,12 +925,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
387
925
|
nodes: graph?.nodes.length,
|
|
388
926
|
edges: graph?.edges.length
|
|
389
927
|
}
|
|
390
|
-
}, {
|
|
391
|
-
F: __dxlog_file2,
|
|
392
|
-
L: 227,
|
|
393
|
-
S: this,
|
|
394
|
-
C: (f, a) => f(...a)
|
|
395
|
-
});
|
|
928
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 89, S: this });
|
|
396
929
|
this._simulation.stop();
|
|
397
930
|
this.mergeData(graph);
|
|
398
931
|
this.updateLayout();
|
|
@@ -442,12 +975,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
442
975
|
updateForces(forces) {
|
|
443
976
|
log("updateForces", {
|
|
444
977
|
forces
|
|
445
|
-
}, {
|
|
446
|
-
F: __dxlog_file2,
|
|
447
|
-
L: 288,
|
|
448
|
-
S: this,
|
|
449
|
-
C: (f, a) => f(...a)
|
|
450
|
-
});
|
|
978
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 148, S: this });
|
|
451
979
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
452
980
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
453
981
|
if (config.distance != null) {
|
|
@@ -516,7 +1044,7 @@ import { log as log3 } from "@dxos/log";
|
|
|
516
1044
|
// src/graph/projector/graph-radial-projector.ts
|
|
517
1045
|
import { easeCubic, timer } from "d3";
|
|
518
1046
|
import { log as log2 } from "@dxos/log";
|
|
519
|
-
var
|
|
1047
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
520
1048
|
var GraphRadialProjector = class extends GraphProjector {
|
|
521
1049
|
_timer;
|
|
522
1050
|
findNode(x, y, radius) {
|
|
@@ -528,12 +1056,7 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
528
1056
|
nodes: graph?.nodes.length,
|
|
529
1057
|
edges: graph?.edges.length
|
|
530
1058
|
}
|
|
531
|
-
}, {
|
|
532
|
-
F: __dxlog_file3,
|
|
533
|
-
L: 32,
|
|
534
|
-
S: this,
|
|
535
|
-
C: (f, a) => f(...a)
|
|
536
|
-
});
|
|
1059
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 13, S: this });
|
|
537
1060
|
this.mergeData(graph);
|
|
538
1061
|
this.doRadialLayout();
|
|
539
1062
|
}
|
|
@@ -629,7 +1152,7 @@ var layoutVertical = (x, y, h, n) => {
|
|
|
629
1152
|
};
|
|
630
1153
|
|
|
631
1154
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
632
|
-
var
|
|
1155
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
633
1156
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
634
1157
|
onUpdate(graph) {
|
|
635
1158
|
log3("onUpdate", {
|
|
@@ -637,15 +1160,10 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
637
1160
|
nodes: graph?.nodes.length,
|
|
638
1161
|
edges: graph?.edges.length
|
|
639
1162
|
},
|
|
640
|
-
selection: this.selection?.
|
|
641
|
-
}, {
|
|
642
|
-
F: __dxlog_file4,
|
|
643
|
-
L: 24,
|
|
644
|
-
S: this,
|
|
645
|
-
C: (f, a) => f(...a)
|
|
646
|
-
});
|
|
1163
|
+
selection: this.selection?.getSelectedIds()
|
|
1164
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 8, S: this });
|
|
647
1165
|
this.mergeData(graph);
|
|
648
|
-
const selected = this.selection?.
|
|
1166
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
649
1167
|
if (selected) {
|
|
650
1168
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
651
1169
|
if (node) {
|
|
@@ -692,7 +1210,7 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
692
1210
|
|
|
693
1211
|
// src/graph/projector/graph-relational-projector.ts
|
|
694
1212
|
import { log as log4 } from "@dxos/log";
|
|
695
|
-
var
|
|
1213
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
696
1214
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
697
1215
|
onUpdate(graph) {
|
|
698
1216
|
log4("onUpdate", {
|
|
@@ -700,15 +1218,10 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
700
1218
|
nodes: graph?.nodes.length,
|
|
701
1219
|
edges: graph?.edges.length
|
|
702
1220
|
},
|
|
703
|
-
selection: this.selection?.
|
|
704
|
-
}, {
|
|
705
|
-
F: __dxlog_file5,
|
|
706
|
-
L: 24,
|
|
707
|
-
S: this,
|
|
708
|
-
C: (f, a) => f(...a)
|
|
709
|
-
});
|
|
1221
|
+
selection: this.selection?.getSelectedIds()
|
|
1222
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 8, S: this });
|
|
710
1223
|
this.mergeData(graph);
|
|
711
|
-
const selected = this.selection?.
|
|
1224
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
712
1225
|
if (selected) {
|
|
713
1226
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
714
1227
|
if (node) {
|
|
@@ -815,8 +1328,8 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
815
1328
|
};
|
|
816
1329
|
|
|
817
1330
|
// src/graph/renderer/renderer.ts
|
|
818
|
-
import { invariant as
|
|
819
|
-
var
|
|
1331
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1332
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
820
1333
|
var Renderer = class {
|
|
821
1334
|
_context;
|
|
822
1335
|
_root;
|
|
@@ -832,15 +1345,7 @@ var Renderer = class {
|
|
|
832
1345
|
return this._context;
|
|
833
1346
|
}
|
|
834
1347
|
get root() {
|
|
835
|
-
|
|
836
|
-
F: __dxlog_file6,
|
|
837
|
-
L: 40,
|
|
838
|
-
S: this,
|
|
839
|
-
A: [
|
|
840
|
-
"this._root.current",
|
|
841
|
-
"'SVG root is not initialized'"
|
|
842
|
-
]
|
|
843
|
-
});
|
|
1348
|
+
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'"] });
|
|
844
1349
|
return this._root.current;
|
|
845
1350
|
}
|
|
846
1351
|
get options() {
|
|
@@ -849,16 +1354,11 @@ var Renderer = class {
|
|
|
849
1354
|
};
|
|
850
1355
|
|
|
851
1356
|
// src/graph/renderer/graph-renderer.ts
|
|
852
|
-
var
|
|
1357
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
853
1358
|
var createLine2 = line2();
|
|
854
1359
|
var GraphRenderer = class extends Renderer {
|
|
855
1360
|
render(layout) {
|
|
856
|
-
log5("render", layout, {
|
|
857
|
-
F: __dxlog_file7,
|
|
858
|
-
L: 63,
|
|
859
|
-
S: this,
|
|
860
|
-
C: (f, a) => f(...a)
|
|
861
|
-
});
|
|
1361
|
+
log5("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 19, S: this });
|
|
862
1362
|
const root = select4(this.root);
|
|
863
1363
|
if (layout.guides) {
|
|
864
1364
|
root.selectAll("g.dx-guides").data([
|
|
@@ -1001,12 +1501,7 @@ var updateNode2 = (group, options) => {
|
|
|
1001
1501
|
} catch (error) {
|
|
1002
1502
|
log5.error("updateNode", {
|
|
1003
1503
|
error: error?.message
|
|
1004
|
-
}, {
|
|
1005
|
-
F: __dxlog_file7,
|
|
1006
|
-
L: 305,
|
|
1007
|
-
S: void 0,
|
|
1008
|
-
C: (f, a) => f(...a)
|
|
1009
|
-
});
|
|
1504
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 194, S: void 0 });
|
|
1010
1505
|
}
|
|
1011
1506
|
}
|
|
1012
1507
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
@@ -1057,12 +1552,7 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1057
1552
|
} catch (error) {
|
|
1058
1553
|
log5.error("updateEdge", {
|
|
1059
1554
|
error: error?.message
|
|
1060
|
-
}, {
|
|
1061
|
-
F: __dxlog_file7,
|
|
1062
|
-
L: 417,
|
|
1063
|
-
S: void 0,
|
|
1064
|
-
C: (f, a) => f(...a)
|
|
1065
|
-
});
|
|
1555
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 260, S: void 0 });
|
|
1066
1556
|
}
|
|
1067
1557
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1068
1558
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
@@ -1140,112 +1630,422 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1140
1630
|
});
|
|
1141
1631
|
};
|
|
1142
1632
|
|
|
1143
|
-
// src/
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
return
|
|
1223
|
-
|
|
1224
|
-
|
|
1633
|
+
// src/hooks/useGrid.ts
|
|
1634
|
+
import { line as line4, range, select as select5 } from "d3";
|
|
1635
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
1636
|
+
|
|
1637
|
+
// src/hooks/useSvgContext.ts
|
|
1638
|
+
import { createContext, useContext } from "react";
|
|
1639
|
+
import { createRef } from "react";
|
|
1640
|
+
import { raise } from "@dxos/debug";
|
|
1641
|
+
var SVGContext = class {
|
|
1642
|
+
_ref = createRef();
|
|
1643
|
+
_scale;
|
|
1644
|
+
_centered;
|
|
1645
|
+
_size;
|
|
1646
|
+
_center;
|
|
1647
|
+
resized = new EventEmitter();
|
|
1648
|
+
constructor({ scale = new Scale(), centered = true }) {
|
|
1649
|
+
this._scale = scale;
|
|
1650
|
+
this._centered = centered;
|
|
1651
|
+
}
|
|
1652
|
+
get ref() {
|
|
1653
|
+
return this._ref;
|
|
1654
|
+
}
|
|
1655
|
+
get svg() {
|
|
1656
|
+
return this._ref.current;
|
|
1657
|
+
}
|
|
1658
|
+
get scale() {
|
|
1659
|
+
return this._scale;
|
|
1660
|
+
}
|
|
1661
|
+
get center() {
|
|
1662
|
+
return this._center;
|
|
1663
|
+
}
|
|
1664
|
+
get size() {
|
|
1665
|
+
return this._size;
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
|
|
1669
|
+
*/
|
|
1670
|
+
get viewBox() {
|
|
1671
|
+
const [x, y] = this.center;
|
|
1672
|
+
return `${x},${y},${this._size.width},${this._size.height}`;
|
|
1673
|
+
}
|
|
1674
|
+
setSize(size) {
|
|
1675
|
+
this._size = {
|
|
1676
|
+
...size
|
|
1677
|
+
};
|
|
1678
|
+
this._center = this._centered ? [
|
|
1679
|
+
-Math.floor(size.width / 2),
|
|
1680
|
+
-Math.floor(size.height / 2)
|
|
1681
|
+
] : [
|
|
1682
|
+
0,
|
|
1683
|
+
0
|
|
1684
|
+
];
|
|
1685
|
+
this.resized.emit(this);
|
|
1686
|
+
}
|
|
1687
|
+
setTransform(transform) {
|
|
1688
|
+
if (this._scale.setTransform(transform)) {
|
|
1689
|
+
this.resized.emit(this);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
|
|
1694
|
+
* @param point
|
|
1695
|
+
*/
|
|
1696
|
+
elementFromPoint(point) {
|
|
1697
|
+
const [x, y] = point;
|
|
1698
|
+
const [cx, cy] = this._center;
|
|
1699
|
+
return document.elementFromPoint(cx + x, cy + y);
|
|
1700
|
+
}
|
|
1701
|
+
};
|
|
1702
|
+
var SVGContextType = createContext(void 0);
|
|
1703
|
+
var SVGContextProvider = SVGContextType.Provider;
|
|
1704
|
+
var useSvgContext = () => {
|
|
1705
|
+
return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
|
|
1706
|
+
};
|
|
1707
|
+
|
|
1708
|
+
// src/hooks/useGrid.ts
|
|
1709
|
+
var createLine4 = line4();
|
|
1710
|
+
var createGrid = (context, options) => {
|
|
1711
|
+
if (!context.size) {
|
|
1712
|
+
return [];
|
|
1713
|
+
}
|
|
1714
|
+
const paths = [];
|
|
1715
|
+
const { width, height } = context.size;
|
|
1716
|
+
const { x, y, k } = context.scale.transform;
|
|
1717
|
+
const s = 1 / k;
|
|
1718
|
+
const w = width * s;
|
|
1719
|
+
const h = height * s;
|
|
1720
|
+
const dx = -(x + width / 2) * s;
|
|
1721
|
+
const dy = -(y + height / 2) * s;
|
|
1722
|
+
if (options.axis) {
|
|
1723
|
+
const axis = [
|
|
1724
|
+
[
|
|
1725
|
+
[
|
|
1726
|
+
0,
|
|
1727
|
+
dy
|
|
1728
|
+
],
|
|
1729
|
+
[
|
|
1730
|
+
0,
|
|
1731
|
+
dy + h
|
|
1732
|
+
]
|
|
1733
|
+
],
|
|
1734
|
+
[
|
|
1735
|
+
[
|
|
1736
|
+
dx,
|
|
1737
|
+
0
|
|
1738
|
+
],
|
|
1739
|
+
[
|
|
1740
|
+
dx + w,
|
|
1741
|
+
0
|
|
1742
|
+
]
|
|
1743
|
+
]
|
|
1744
|
+
];
|
|
1745
|
+
paths.push({
|
|
1746
|
+
id: "axis",
|
|
1747
|
+
class: "dx-axis",
|
|
1748
|
+
path: axis.map((line5) => createLine4(line5)).join()
|
|
1225
1749
|
});
|
|
1226
|
-
} finally {
|
|
1227
|
-
_effect.f();
|
|
1228
1750
|
}
|
|
1751
|
+
if (options.grid) {
|
|
1752
|
+
const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
|
|
1753
|
+
const majorSize = context.scale.gridSize;
|
|
1754
|
+
const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
|
|
1755
|
+
const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
|
|
1756
|
+
const major = [
|
|
1757
|
+
...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
|
|
1758
|
+
[
|
|
1759
|
+
x2,
|
|
1760
|
+
dy
|
|
1761
|
+
],
|
|
1762
|
+
[
|
|
1763
|
+
x2,
|
|
1764
|
+
dy + h
|
|
1765
|
+
]
|
|
1766
|
+
]),
|
|
1767
|
+
...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
|
|
1768
|
+
[
|
|
1769
|
+
dx,
|
|
1770
|
+
y2
|
|
1771
|
+
],
|
|
1772
|
+
[
|
|
1773
|
+
dx + w,
|
|
1774
|
+
y2
|
|
1775
|
+
]
|
|
1776
|
+
])
|
|
1777
|
+
];
|
|
1778
|
+
paths.push({
|
|
1779
|
+
id: "major",
|
|
1780
|
+
class: "dx-major",
|
|
1781
|
+
path: major.map((line5) => createLine4(line5)).join()
|
|
1782
|
+
});
|
|
1783
|
+
const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
|
|
1784
|
+
if (majorSize > minorSize) {
|
|
1785
|
+
const xMinor = range(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
|
|
1786
|
+
const yMinor = range(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
|
|
1787
|
+
const minor = [
|
|
1788
|
+
...xMinor.filter((x2) => xMajor.indexOf(x2) === -1).map((x2) => [
|
|
1789
|
+
[
|
|
1790
|
+
x2,
|
|
1791
|
+
dy
|
|
1792
|
+
],
|
|
1793
|
+
[
|
|
1794
|
+
x2,
|
|
1795
|
+
dy + h
|
|
1796
|
+
]
|
|
1797
|
+
]),
|
|
1798
|
+
...yMinor.filter((y2) => yMajor.indexOf(y2) === -1).map((y2) => [
|
|
1799
|
+
[
|
|
1800
|
+
dx,
|
|
1801
|
+
y2
|
|
1802
|
+
],
|
|
1803
|
+
[
|
|
1804
|
+
dx + w,
|
|
1805
|
+
y2
|
|
1806
|
+
]
|
|
1807
|
+
])
|
|
1808
|
+
];
|
|
1809
|
+
paths.push({
|
|
1810
|
+
id: "minor",
|
|
1811
|
+
class: "dx-minor",
|
|
1812
|
+
path: minor.map((line5) => createLine4(line5)).join()
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return paths;
|
|
1817
|
+
};
|
|
1818
|
+
var defaultGridOptions = {
|
|
1819
|
+
visible: true,
|
|
1820
|
+
axis: true,
|
|
1821
|
+
grid: true
|
|
1822
|
+
};
|
|
1823
|
+
var GridController = class {
|
|
1824
|
+
_ref;
|
|
1825
|
+
_context;
|
|
1826
|
+
_options;
|
|
1827
|
+
_visible = false;
|
|
1828
|
+
constructor(_ref, _context, _options) {
|
|
1829
|
+
this._ref = _ref;
|
|
1830
|
+
this._context = _context;
|
|
1831
|
+
this._options = _options;
|
|
1832
|
+
this._visible = this._options.visible ?? true;
|
|
1833
|
+
}
|
|
1834
|
+
get ref() {
|
|
1835
|
+
return this._ref;
|
|
1836
|
+
}
|
|
1837
|
+
get visible() {
|
|
1838
|
+
return this._visible;
|
|
1839
|
+
}
|
|
1840
|
+
draw() {
|
|
1841
|
+
if (!this._context.size) {
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1844
|
+
const paths = this._visible ? createGrid(this._context, this._options) : [];
|
|
1845
|
+
const root = select5(this._ref.current);
|
|
1846
|
+
root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
|
|
1847
|
+
const transform = this._context.scale.transform;
|
|
1848
|
+
if (transform) {
|
|
1849
|
+
root.attr("transform", transform);
|
|
1850
|
+
root.attr("stroke-width", 1 / transform.k);
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
setVisible(visible) {
|
|
1854
|
+
this._visible = visible;
|
|
1855
|
+
this.draw();
|
|
1856
|
+
return this;
|
|
1857
|
+
}
|
|
1858
|
+
};
|
|
1859
|
+
var useGrid = (options = defaultGridOptions) => {
|
|
1860
|
+
const ref = useRef(null);
|
|
1861
|
+
const context = useSvgContext();
|
|
1862
|
+
const controller = useMemo(() => new GridController(ref, context, options), []);
|
|
1863
|
+
useEffect(() => context.resized.on(() => controller.draw()), [
|
|
1864
|
+
context,
|
|
1865
|
+
controller
|
|
1866
|
+
]);
|
|
1867
|
+
return controller;
|
|
1868
|
+
};
|
|
1869
|
+
|
|
1870
|
+
// src/hooks/useZoom.ts
|
|
1871
|
+
import { select as select6, zoom, zoomIdentity as zoomIdentity2 } from "d3";
|
|
1872
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
1873
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
1874
|
+
var defaultZoomOptions = {
|
|
1875
|
+
enabled: true,
|
|
1876
|
+
extent: [
|
|
1877
|
+
1 / 4,
|
|
1878
|
+
4
|
|
1879
|
+
],
|
|
1880
|
+
onDblClick: (zoom2) => zoom2.reset()
|
|
1881
|
+
};
|
|
1882
|
+
var ZoomHandler = class {
|
|
1883
|
+
_ref;
|
|
1884
|
+
_context;
|
|
1885
|
+
_zoom;
|
|
1886
|
+
_options;
|
|
1887
|
+
_enabled;
|
|
1888
|
+
constructor(_ref, _context, options) {
|
|
1889
|
+
this._ref = _ref;
|
|
1890
|
+
this._context = _context;
|
|
1891
|
+
this._options = defaultsDeep({}, options, defaultZoomOptions);
|
|
1892
|
+
this._enabled = this._options.enabled ?? true;
|
|
1893
|
+
this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Gets the reference which the transform is applied to.
|
|
1897
|
+
*/
|
|
1898
|
+
get ref() {
|
|
1899
|
+
return this._ref;
|
|
1900
|
+
}
|
|
1901
|
+
get zoom() {
|
|
1902
|
+
return this._zoom;
|
|
1903
|
+
}
|
|
1904
|
+
init() {
|
|
1905
|
+
this.setEnabled(this._enabled);
|
|
1906
|
+
this.reset(0);
|
|
1907
|
+
return this;
|
|
1908
|
+
}
|
|
1909
|
+
setEnabled(enable) {
|
|
1910
|
+
if (enable) {
|
|
1911
|
+
select6(this._context.svg).call(this._zoom).on(
|
|
1912
|
+
"dblclick.zoom",
|
|
1913
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1914
|
+
// @ts-ignore
|
|
1915
|
+
this._options?.onDblClick ? () => {
|
|
1916
|
+
this._options?.onDblClick(this);
|
|
1917
|
+
} : null
|
|
1918
|
+
);
|
|
1919
|
+
} else {
|
|
1920
|
+
select6(this._context.svg).on(".zoom", null);
|
|
1921
|
+
}
|
|
1922
|
+
this._enabled = enable;
|
|
1923
|
+
return this;
|
|
1924
|
+
}
|
|
1925
|
+
reset(duration = 500) {
|
|
1926
|
+
const scale = 1;
|
|
1927
|
+
const transform = zoomIdentity2.scale(scale);
|
|
1928
|
+
select6(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
|
|
1929
|
+
return this;
|
|
1930
|
+
}
|
|
1931
|
+
};
|
|
1932
|
+
var useZoom = (options = defaultZoomOptions) => {
|
|
1933
|
+
const context = useSvgContext();
|
|
1934
|
+
const ref = useRef2(null);
|
|
1935
|
+
const handler = useMemo2(() => new ZoomHandler(ref, context, options), [
|
|
1936
|
+
context,
|
|
1937
|
+
options
|
|
1938
|
+
]);
|
|
1939
|
+
useEffect2(() => {
|
|
1940
|
+
handler.zoom.on("zoom", ({ transform }) => {
|
|
1941
|
+
context.setTransform(transform);
|
|
1942
|
+
select6(ref.current).attr("transform", transform);
|
|
1943
|
+
});
|
|
1944
|
+
handler.init();
|
|
1945
|
+
}, [
|
|
1946
|
+
handler
|
|
1947
|
+
]);
|
|
1948
|
+
return handler;
|
|
1949
|
+
};
|
|
1950
|
+
|
|
1951
|
+
// src/components/Graph/Graph.tsx
|
|
1952
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
1953
|
+
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
1954
|
+
const context = useSvgContext();
|
|
1955
|
+
const graphRef = useRef3(null);
|
|
1956
|
+
const { projector, renderer } = useMemo3(() => {
|
|
1957
|
+
let projector2 = projectorProp;
|
|
1958
|
+
if (!projector2) {
|
|
1959
|
+
projector2 = new GraphForceProjector(context);
|
|
1960
|
+
}
|
|
1961
|
+
let renderer2 = rendererProp;
|
|
1962
|
+
if (!renderer2) {
|
|
1963
|
+
renderer2 = new GraphRenderer(context, graphRef, {
|
|
1964
|
+
...props,
|
|
1965
|
+
// TODO(burdon): Replace drag when projector is updated.
|
|
1966
|
+
drag: drag2 ? createGraphDrag(context, projector2) : void 0,
|
|
1967
|
+
arrows: {
|
|
1968
|
+
end: arrows
|
|
1969
|
+
},
|
|
1970
|
+
onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
|
|
1971
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
return {
|
|
1975
|
+
projector: projector2,
|
|
1976
|
+
renderer: renderer2
|
|
1977
|
+
};
|
|
1978
|
+
}, [
|
|
1979
|
+
context,
|
|
1980
|
+
projectorProp,
|
|
1981
|
+
rendererProp,
|
|
1982
|
+
drag2
|
|
1983
|
+
]);
|
|
1984
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
1985
|
+
refresh: () => {
|
|
1986
|
+
projector.updateData(model?.graph);
|
|
1987
|
+
},
|
|
1988
|
+
repaint: () => {
|
|
1989
|
+
renderer.render(projector.layout);
|
|
1990
|
+
},
|
|
1991
|
+
findNode: (id) => {
|
|
1992
|
+
return graphRef.current?.querySelector(`g[data-id="${id}"]`);
|
|
1993
|
+
}
|
|
1994
|
+
}), [
|
|
1995
|
+
model,
|
|
1996
|
+
projector,
|
|
1997
|
+
renderer
|
|
1998
|
+
]);
|
|
1999
|
+
useEffect3(() => {
|
|
2000
|
+
projector.updateData(model?.graph);
|
|
2001
|
+
const unsubscribeModel = model ? model.subscribe(() => {
|
|
2002
|
+
projector.updateData(model?.graph);
|
|
2003
|
+
}) : void 0;
|
|
2004
|
+
return combine(unsubscribeModel, projector.updated.on(({ layout }) => {
|
|
2005
|
+
try {
|
|
2006
|
+
renderer.render(layout);
|
|
2007
|
+
} catch (error) {
|
|
2008
|
+
void projector.stop();
|
|
2009
|
+
log6.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 71, S: void 0 });
|
|
2010
|
+
}
|
|
2011
|
+
}));
|
|
2012
|
+
}, [
|
|
2013
|
+
model,
|
|
2014
|
+
projector,
|
|
2015
|
+
renderer
|
|
2016
|
+
]);
|
|
2017
|
+
useEffect3(() => {
|
|
2018
|
+
void projector.start();
|
|
2019
|
+
return () => {
|
|
2020
|
+
void projector.stop();
|
|
2021
|
+
};
|
|
2022
|
+
}, [
|
|
2023
|
+
projector
|
|
2024
|
+
]);
|
|
2025
|
+
return /* @__PURE__ */ React.createElement("g", {
|
|
2026
|
+
ref: graphRef,
|
|
2027
|
+
className: mx("dx-graph", classNames)
|
|
2028
|
+
});
|
|
1229
2029
|
};
|
|
1230
2030
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1231
2031
|
|
|
1232
2032
|
// src/components/Mesh/Mesh.tsx
|
|
1233
|
-
import { geoPath, select as
|
|
1234
|
-
import { useEffect as
|
|
2033
|
+
import { geoPath, select as select7 } from "d3";
|
|
2034
|
+
import { useEffect as useEffect4 } from "react";
|
|
1235
2035
|
import { feature, mesh } from "topojson-client";
|
|
1236
2036
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1237
2037
|
const { svg, size } = useSvgContext();
|
|
1238
|
-
|
|
2038
|
+
useEffect4(() => {
|
|
1239
2039
|
if (size) {
|
|
1240
2040
|
const topology = hexTopology(size, radius, value);
|
|
1241
2041
|
const projection = hexProjection(radius);
|
|
1242
2042
|
const path = geoPath().projection(projection);
|
|
1243
|
-
|
|
1244
|
-
|
|
2043
|
+
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);
|
|
2044
|
+
select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
1245
2045
|
const redraw = (border) => {
|
|
1246
2046
|
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1247
2047
|
};
|
|
1248
|
-
|
|
2048
|
+
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
1249
2049
|
}
|
|
1250
2050
|
}, [
|
|
1251
2051
|
svg,
|
|
@@ -1362,115 +2162,96 @@ var hexProjection = (radius) => {
|
|
|
1362
2162
|
};
|
|
1363
2163
|
|
|
1364
2164
|
// src/components/SVG/Grid.tsx
|
|
1365
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
1366
2165
|
import React2 from "react";
|
|
1367
|
-
import { mx as mx2 } from "@dxos/
|
|
2166
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1368
2167
|
var Grid = ({ classNames, ...props }) => {
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
className: mx2("dx-grid", classNames)
|
|
1375
|
-
});
|
|
1376
|
-
} finally {
|
|
1377
|
-
_effect.f();
|
|
1378
|
-
}
|
|
2168
|
+
const { ref } = useGrid(props);
|
|
2169
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
2170
|
+
ref,
|
|
2171
|
+
className: mx2("dx-grid", classNames)
|
|
2172
|
+
});
|
|
1379
2173
|
};
|
|
1380
2174
|
|
|
1381
2175
|
// src/components/SVG/Markers.tsx
|
|
1382
|
-
import {
|
|
1383
|
-
import {
|
|
1384
|
-
import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
2176
|
+
import { select as select8 } from "d3";
|
|
2177
|
+
import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
1385
2178
|
var Markers = ({ arrowSize, className }) => {
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
className
|
|
1399
|
-
});
|
|
1400
|
-
} finally {
|
|
1401
|
-
_effect.f();
|
|
1402
|
-
}
|
|
2179
|
+
const ref = useRef4(null);
|
|
2180
|
+
useEffect5(() => {
|
|
2181
|
+
select8(ref.current).call(createMarkers({
|
|
2182
|
+
arrowSize
|
|
2183
|
+
}));
|
|
2184
|
+
}, [
|
|
2185
|
+
ref
|
|
2186
|
+
]);
|
|
2187
|
+
return /* @__PURE__ */ React3.createElement("defs", {
|
|
2188
|
+
ref,
|
|
2189
|
+
className
|
|
2190
|
+
});
|
|
1403
2191
|
};
|
|
1404
2192
|
|
|
1405
2193
|
// src/components/SVG/Root.tsx
|
|
1406
|
-
import {
|
|
1407
|
-
import {
|
|
1408
|
-
import React4, { forwardRef as forwardRef2, useEffect as useEffect4, useImperativeHandle as useImperativeHandle2, useMemo as useMemo2 } from "react";
|
|
2194
|
+
import { select as select9 } from "d3";
|
|
2195
|
+
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
|
|
1409
2196
|
import { useResizeDetector } from "react-resize-detector";
|
|
1410
|
-
import { mx as mx3 } from "@dxos/
|
|
1411
|
-
var Root = /* @__PURE__ */ forwardRef2(({
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
2197
|
+
import { composableProps, mx as mx3 } from "@dxos/ui-theme";
|
|
2198
|
+
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
2199
|
+
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
|
|
2200
|
+
refreshRate: 200
|
|
2201
|
+
});
|
|
2202
|
+
const context = useMemo4(() => {
|
|
2203
|
+
return new SVGContext({
|
|
2204
|
+
scale,
|
|
2205
|
+
centered
|
|
1416
2206
|
});
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
} finally {
|
|
1451
|
-
_effect.f();
|
|
1452
|
-
}
|
|
2207
|
+
}, [
|
|
2208
|
+
scale,
|
|
2209
|
+
centered
|
|
2210
|
+
]);
|
|
2211
|
+
useImperativeHandle2(ref, () => context, [
|
|
2212
|
+
context
|
|
2213
|
+
]);
|
|
2214
|
+
useEffect6(() => {
|
|
2215
|
+
if (width && height) {
|
|
2216
|
+
context.setSize({
|
|
2217
|
+
width,
|
|
2218
|
+
height
|
|
2219
|
+
});
|
|
2220
|
+
select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
2221
|
+
}
|
|
2222
|
+
}, [
|
|
2223
|
+
context,
|
|
2224
|
+
width,
|
|
2225
|
+
height
|
|
2226
|
+
]);
|
|
2227
|
+
const ready = width !== 0 && height !== 0;
|
|
2228
|
+
return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
|
|
2229
|
+
value: context
|
|
2230
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
2231
|
+
...composableProps(props, {
|
|
2232
|
+
classNames: "dx-expander"
|
|
2233
|
+
}),
|
|
2234
|
+
ref: containerRef
|
|
2235
|
+
}, /* @__PURE__ */ React4.createElement("svg", {
|
|
2236
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2237
|
+
ref: context.ref,
|
|
2238
|
+
className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
2239
|
+
}, ready && children)));
|
|
1453
2240
|
});
|
|
1454
2241
|
|
|
1455
2242
|
// src/components/SVG/Zoom.tsx
|
|
1456
|
-
import {
|
|
1457
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
2243
|
+
import React5, { memo, useMemo as useMemo5 } from "react";
|
|
1458
2244
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
className
|
|
1470
|
-
}, children);
|
|
1471
|
-
} finally {
|
|
1472
|
-
_effect.f();
|
|
1473
|
-
}
|
|
2245
|
+
const options = useMemo5(() => ({
|
|
2246
|
+
extent
|
|
2247
|
+
}), [
|
|
2248
|
+
JSON.stringify(extent)
|
|
2249
|
+
]);
|
|
2250
|
+
const zoom2 = useZoom(options);
|
|
2251
|
+
return /* @__PURE__ */ React5.createElement("g", {
|
|
2252
|
+
ref: zoom2.ref,
|
|
2253
|
+
className
|
|
2254
|
+
}, children);
|
|
1474
2255
|
});
|
|
1475
2256
|
|
|
1476
2257
|
// src/components/SVG/SVG.tsx
|
|
@@ -1484,7 +2265,7 @@ var SVG = {
|
|
|
1484
2265
|
};
|
|
1485
2266
|
|
|
1486
2267
|
// src/fx/pulsar.ts
|
|
1487
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
2268
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1488
2269
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1489
2270
|
(function(Pulsar2) {
|
|
1490
2271
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1499,10 +2280,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1499
2280
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1500
2281
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1501
2282
|
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() {
|
|
1502
|
-
if (
|
|
1503
|
-
startAnimation(
|
|
2283
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
2284
|
+
startAnimation(select10(this), r, options);
|
|
1504
2285
|
} else {
|
|
1505
|
-
|
|
2286
|
+
select10(this).remove();
|
|
1506
2287
|
}
|
|
1507
2288
|
});
|
|
1508
2289
|
};
|
|
@@ -1513,7 +2294,6 @@ export {
|
|
|
1513
2294
|
Graph,
|
|
1514
2295
|
GraphForceProjector,
|
|
1515
2296
|
GraphHierarchicalProjector,
|
|
1516
|
-
GraphInner,
|
|
1517
2297
|
GraphProjector,
|
|
1518
2298
|
GraphRadialProjector,
|
|
1519
2299
|
GraphRelationalProjector,
|