@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,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-O6GWCXDC.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,14 +154,577 @@ var emptyGraph = {
|
|
|
179
154
|
edges: []
|
|
180
155
|
};
|
|
181
156
|
|
|
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
|
+
}
|
|
191
|
+
});
|
|
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
|
+
}
|
|
408
|
+
}
|
|
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
|
+
|
|
182
721
|
// src/graph/projector/projector.ts
|
|
183
722
|
var Projector = class {
|
|
184
723
|
_context;
|
|
185
|
-
updated;
|
|
724
|
+
updated = new EventEmitter();
|
|
186
725
|
_options;
|
|
187
726
|
constructor(_context, options) {
|
|
188
727
|
this._context = _context;
|
|
189
|
-
this.updated = new EventEmitter();
|
|
190
728
|
this._options = Object.assign({
|
|
191
729
|
idAccessor: defaultIdAccessor
|
|
192
730
|
}, options);
|
|
@@ -316,7 +854,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
316
854
|
};
|
|
317
855
|
|
|
318
856
|
// src/graph/projector/graph-force-projector.ts
|
|
319
|
-
var
|
|
857
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
320
858
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
321
859
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
322
860
|
};
|
|
@@ -388,12 +926,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
388
926
|
nodes: graph?.nodes.length,
|
|
389
927
|
edges: graph?.edges.length
|
|
390
928
|
}
|
|
391
|
-
}, {
|
|
392
|
-
F: __dxlog_file2,
|
|
393
|
-
L: 227,
|
|
394
|
-
S: this,
|
|
395
|
-
C: (f, a) => f(...a)
|
|
396
|
-
});
|
|
929
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 89, S: this });
|
|
397
930
|
this._simulation.stop();
|
|
398
931
|
this.mergeData(graph);
|
|
399
932
|
this.updateLayout();
|
|
@@ -443,12 +976,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
443
976
|
updateForces(forces) {
|
|
444
977
|
log("updateForces", {
|
|
445
978
|
forces
|
|
446
|
-
}, {
|
|
447
|
-
F: __dxlog_file2,
|
|
448
|
-
L: 288,
|
|
449
|
-
S: this,
|
|
450
|
-
C: (f, a) => f(...a)
|
|
451
|
-
});
|
|
979
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 148, S: this });
|
|
452
980
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
453
981
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
454
982
|
if (config.distance != null) {
|
|
@@ -517,7 +1045,7 @@ import { log as log3 } from "@dxos/log";
|
|
|
517
1045
|
// src/graph/projector/graph-radial-projector.ts
|
|
518
1046
|
import { easeCubic, timer } from "d3";
|
|
519
1047
|
import { log as log2 } from "@dxos/log";
|
|
520
|
-
var
|
|
1048
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
521
1049
|
var GraphRadialProjector = class extends GraphProjector {
|
|
522
1050
|
_timer;
|
|
523
1051
|
findNode(x, y, radius) {
|
|
@@ -529,12 +1057,7 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
529
1057
|
nodes: graph?.nodes.length,
|
|
530
1058
|
edges: graph?.edges.length
|
|
531
1059
|
}
|
|
532
|
-
}, {
|
|
533
|
-
F: __dxlog_file3,
|
|
534
|
-
L: 32,
|
|
535
|
-
S: this,
|
|
536
|
-
C: (f, a) => f(...a)
|
|
537
|
-
});
|
|
1060
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 13, S: this });
|
|
538
1061
|
this.mergeData(graph);
|
|
539
1062
|
this.doRadialLayout();
|
|
540
1063
|
}
|
|
@@ -630,7 +1153,7 @@ var layoutVertical = (x, y, h, n) => {
|
|
|
630
1153
|
};
|
|
631
1154
|
|
|
632
1155
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
633
|
-
var
|
|
1156
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
634
1157
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
635
1158
|
onUpdate(graph) {
|
|
636
1159
|
log3("onUpdate", {
|
|
@@ -638,15 +1161,10 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
638
1161
|
nodes: graph?.nodes.length,
|
|
639
1162
|
edges: graph?.edges.length
|
|
640
1163
|
},
|
|
641
|
-
selection: this.selection?.
|
|
642
|
-
}, {
|
|
643
|
-
F: __dxlog_file4,
|
|
644
|
-
L: 24,
|
|
645
|
-
S: this,
|
|
646
|
-
C: (f, a) => f(...a)
|
|
647
|
-
});
|
|
1164
|
+
selection: this.selection?.getSelectedIds()
|
|
1165
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 8, S: this });
|
|
648
1166
|
this.mergeData(graph);
|
|
649
|
-
const selected = this.selection?.
|
|
1167
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
650
1168
|
if (selected) {
|
|
651
1169
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
652
1170
|
if (node) {
|
|
@@ -693,7 +1211,7 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
693
1211
|
|
|
694
1212
|
// src/graph/projector/graph-relational-projector.ts
|
|
695
1213
|
import { log as log4 } from "@dxos/log";
|
|
696
|
-
var
|
|
1214
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
697
1215
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
698
1216
|
onUpdate(graph) {
|
|
699
1217
|
log4("onUpdate", {
|
|
@@ -701,15 +1219,10 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
701
1219
|
nodes: graph?.nodes.length,
|
|
702
1220
|
edges: graph?.edges.length
|
|
703
1221
|
},
|
|
704
|
-
selection: this.selection?.
|
|
705
|
-
}, {
|
|
706
|
-
F: __dxlog_file5,
|
|
707
|
-
L: 24,
|
|
708
|
-
S: this,
|
|
709
|
-
C: (f, a) => f(...a)
|
|
710
|
-
});
|
|
1222
|
+
selection: this.selection?.getSelectedIds()
|
|
1223
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 8, S: this });
|
|
711
1224
|
this.mergeData(graph);
|
|
712
|
-
const selected = this.selection?.
|
|
1225
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
713
1226
|
if (selected) {
|
|
714
1227
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
715
1228
|
if (node) {
|
|
@@ -816,8 +1329,8 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
816
1329
|
};
|
|
817
1330
|
|
|
818
1331
|
// src/graph/renderer/renderer.ts
|
|
819
|
-
import { invariant as
|
|
820
|
-
var
|
|
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";
|
|
821
1334
|
var Renderer = class {
|
|
822
1335
|
_context;
|
|
823
1336
|
_root;
|
|
@@ -833,15 +1346,7 @@ var Renderer = class {
|
|
|
833
1346
|
return this._context;
|
|
834
1347
|
}
|
|
835
1348
|
get root() {
|
|
836
|
-
|
|
837
|
-
F: __dxlog_file6,
|
|
838
|
-
L: 40,
|
|
839
|
-
S: this,
|
|
840
|
-
A: [
|
|
841
|
-
"this._root.current",
|
|
842
|
-
"'SVG root is not initialized'"
|
|
843
|
-
]
|
|
844
|
-
});
|
|
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'"] });
|
|
845
1350
|
return this._root.current;
|
|
846
1351
|
}
|
|
847
1352
|
get options() {
|
|
@@ -850,16 +1355,11 @@ var Renderer = class {
|
|
|
850
1355
|
};
|
|
851
1356
|
|
|
852
1357
|
// src/graph/renderer/graph-renderer.ts
|
|
853
|
-
var
|
|
1358
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
854
1359
|
var createLine2 = line2();
|
|
855
1360
|
var GraphRenderer = class extends Renderer {
|
|
856
1361
|
render(layout) {
|
|
857
|
-
log5("render", layout, {
|
|
858
|
-
F: __dxlog_file7,
|
|
859
|
-
L: 63,
|
|
860
|
-
S: this,
|
|
861
|
-
C: (f, a) => f(...a)
|
|
862
|
-
});
|
|
1362
|
+
log5("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 19, S: this });
|
|
863
1363
|
const root = select4(this.root);
|
|
864
1364
|
if (layout.guides) {
|
|
865
1365
|
root.selectAll("g.dx-guides").data([
|
|
@@ -1002,12 +1502,7 @@ var updateNode2 = (group, options) => {
|
|
|
1002
1502
|
} catch (error) {
|
|
1003
1503
|
log5.error("updateNode", {
|
|
1004
1504
|
error: error?.message
|
|
1005
|
-
}, {
|
|
1006
|
-
F: __dxlog_file7,
|
|
1007
|
-
L: 305,
|
|
1008
|
-
S: void 0,
|
|
1009
|
-
C: (f, a) => f(...a)
|
|
1010
|
-
});
|
|
1505
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 194, S: void 0 });
|
|
1011
1506
|
}
|
|
1012
1507
|
}
|
|
1013
1508
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
@@ -1058,12 +1553,7 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1058
1553
|
} catch (error) {
|
|
1059
1554
|
log5.error("updateEdge", {
|
|
1060
1555
|
error: error?.message
|
|
1061
|
-
}, {
|
|
1062
|
-
F: __dxlog_file7,
|
|
1063
|
-
L: 417,
|
|
1064
|
-
S: void 0,
|
|
1065
|
-
C: (f, a) => f(...a)
|
|
1066
|
-
});
|
|
1556
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 260, S: void 0 });
|
|
1067
1557
|
}
|
|
1068
1558
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1069
1559
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
@@ -1141,112 +1631,422 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1141
1631
|
});
|
|
1142
1632
|
};
|
|
1143
1633
|
|
|
1144
|
-
// src/
|
|
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
|
-
|
|
1223
|
-
return
|
|
1224
|
-
|
|
1225
|
-
|
|
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()
|
|
1226
1750
|
});
|
|
1227
|
-
} finally {
|
|
1228
|
-
_effect.f();
|
|
1229
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()
|
|
1783
|
+
});
|
|
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;
|
|
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
|
+
});
|
|
1230
2030
|
};
|
|
1231
2031
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1232
2032
|
|
|
1233
2033
|
// src/components/Mesh/Mesh.tsx
|
|
1234
|
-
import { geoPath, select as
|
|
1235
|
-
import { useEffect as
|
|
2034
|
+
import { geoPath, select as select7 } from "d3";
|
|
2035
|
+
import { useEffect as useEffect4 } from "react";
|
|
1236
2036
|
import { feature, mesh } from "topojson-client";
|
|
1237
2037
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1238
2038
|
const { svg, size } = useSvgContext();
|
|
1239
|
-
|
|
2039
|
+
useEffect4(() => {
|
|
1240
2040
|
if (size) {
|
|
1241
2041
|
const topology = hexTopology(size, radius, value);
|
|
1242
2042
|
const projection = hexProjection(radius);
|
|
1243
2043
|
const path = geoPath().projection(projection);
|
|
1244
|
-
|
|
1245
|
-
|
|
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);
|
|
1246
2046
|
const redraw = (border) => {
|
|
1247
2047
|
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1248
2048
|
};
|
|
1249
|
-
|
|
2049
|
+
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
1250
2050
|
}
|
|
1251
2051
|
}, [
|
|
1252
2052
|
svg,
|
|
@@ -1363,115 +2163,96 @@ var hexProjection = (radius) => {
|
|
|
1363
2163
|
};
|
|
1364
2164
|
|
|
1365
2165
|
// src/components/SVG/Grid.tsx
|
|
1366
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
1367
2166
|
import React2 from "react";
|
|
1368
|
-
import { mx as mx2 } from "@dxos/
|
|
2167
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1369
2168
|
var Grid = ({ classNames, ...props }) => {
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
className: mx2("dx-grid", classNames)
|
|
1376
|
-
});
|
|
1377
|
-
} finally {
|
|
1378
|
-
_effect.f();
|
|
1379
|
-
}
|
|
2169
|
+
const { ref } = useGrid(props);
|
|
2170
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
2171
|
+
ref,
|
|
2172
|
+
className: mx2("dx-grid", classNames)
|
|
2173
|
+
});
|
|
1380
2174
|
};
|
|
1381
2175
|
|
|
1382
2176
|
// src/components/SVG/Markers.tsx
|
|
1383
|
-
import {
|
|
1384
|
-
import {
|
|
1385
|
-
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";
|
|
1386
2179
|
var Markers = ({ arrowSize, className }) => {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
className
|
|
1400
|
-
});
|
|
1401
|
-
} finally {
|
|
1402
|
-
_effect.f();
|
|
1403
|
-
}
|
|
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
|
+
});
|
|
1404
2192
|
};
|
|
1405
2193
|
|
|
1406
2194
|
// src/components/SVG/Root.tsx
|
|
1407
|
-
import {
|
|
1408
|
-
import {
|
|
1409
|
-
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";
|
|
1410
2197
|
import { useResizeDetector } from "react-resize-detector";
|
|
1411
|
-
import { mx as mx3 } from "@dxos/
|
|
1412
|
-
var Root = /* @__PURE__ */ forwardRef2(({
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
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
|
|
1417
2207
|
});
|
|
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
|
-
|
|
1451
|
-
} finally {
|
|
1452
|
-
_effect.f();
|
|
1453
|
-
}
|
|
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)));
|
|
1454
2241
|
});
|
|
1455
2242
|
|
|
1456
2243
|
// src/components/SVG/Zoom.tsx
|
|
1457
|
-
import {
|
|
1458
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
2244
|
+
import React5, { memo, useMemo as useMemo5 } from "react";
|
|
1459
2245
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
className
|
|
1471
|
-
}, children);
|
|
1472
|
-
} finally {
|
|
1473
|
-
_effect.f();
|
|
1474
|
-
}
|
|
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);
|
|
1475
2256
|
});
|
|
1476
2257
|
|
|
1477
2258
|
// src/components/SVG/SVG.tsx
|
|
@@ -1485,7 +2266,7 @@ var SVG = {
|
|
|
1485
2266
|
};
|
|
1486
2267
|
|
|
1487
2268
|
// src/fx/pulsar.ts
|
|
1488
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
2269
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1489
2270
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1490
2271
|
(function(Pulsar2) {
|
|
1491
2272
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1500,10 +2281,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1500
2281
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1501
2282
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1502
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() {
|
|
1503
|
-
if (
|
|
1504
|
-
startAnimation(
|
|
2284
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
2285
|
+
startAnimation(select10(this), r, options);
|
|
1505
2286
|
} else {
|
|
1506
|
-
|
|
2287
|
+
select10(this).remove();
|
|
1507
2288
|
}
|
|
1508
2289
|
});
|
|
1509
2290
|
};
|
|
@@ -1514,7 +2295,6 @@ export {
|
|
|
1514
2295
|
Graph,
|
|
1515
2296
|
GraphForceProjector,
|
|
1516
2297
|
GraphHierarchicalProjector,
|
|
1517
|
-
GraphInner,
|
|
1518
2298
|
GraphProjector,
|
|
1519
2299
|
GraphRadialProjector,
|
|
1520
2300
|
GraphRelationalProjector,
|