@dxos/react-ui-graph 0.8.3 → 0.8.4-main.03d5cd7b56
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 +1109 -319
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -19
- 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 +1109 -319
- 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 +19 -19
- 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 +21 -12
- 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 +10 -6
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
- package/dist/types/src/components/SVG/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/components/SVG/Zoom.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +16 -15
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/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 +1 -1
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-projector.d.ts +4 -4
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +1 -1
- package/dist/types/src/graph/types.d.ts.map +1 -1
- package/dist/types/src/hooks/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 +15 -10
- 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/index.d.ts +2 -2
- package/dist/types/src/util/index.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 +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -34
- package/src/components/Graph/Graph.stories.tsx +73 -69
- package/src/components/Graph/Graph.tsx +25 -20
- package/src/components/Mesh/Mesh.stories.tsx +10 -9
- package/src/components/Mesh/Mesh.tsx +1 -1
- package/src/components/SVG/Grid.tsx +2 -2
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Root.tsx +14 -7
- package/src/components/SVG/SVG.tsx +13 -4
- package/src/components/SVG/Svg.stories.tsx +23 -19
- package/src/components/SVG/Zoom.tsx +1 -1
- package/src/fx/fx.stories.tsx +18 -15
- package/src/graph/projector/graph-drag.ts +1 -1
- package/src/graph/projector/graph-force-projector.ts +3 -3
- package/src/graph/projector/graph-forces.ts +1 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +4 -4
- package/src/graph/projector/graph-projector.ts +5 -5
- package/src/graph/projector/graph-radial-projector.ts +3 -3
- package/src/graph/projector/graph-relational-projector.ts +4 -4
- package/src/graph/projector/projector.ts +1 -1
- package/src/graph/renderer/bullets.ts +1 -1
- package/src/graph/renderer/graph-renderer.ts +7 -7
- package/src/graph/renderer/renderer.ts +1 -1
- package/src/graph/types.ts +1 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/hooks/useZoom.ts +1 -1
- package/src/stories/hooks.stories.tsx +43 -36
- package/src/testing/data.ts +14 -14
- package/src/testing/hooks.ts +5 -5
- package/src/testing/model.ts +6 -6
- package/src/util/fraction.ts +1 -1
- package/src/util/index.ts +2 -2
- package/src/util/screen.test.ts +1 -1
- package/src/util/screen.ts +1 -1
- package/src/util/vector.ts +1 -1
- package/styles/graph.css +292 -43
- package/dist/lib/browser/chunk-2YMRPQU7.mjs +0 -979
- package/dist/lib/browser/chunk-2YMRPQU7.mjs.map +0 -7
- package/dist/lib/node/chunk-WFHWEMPB.cjs +0 -919
- package/dist/lib/node/chunk-WFHWEMPB.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -1547
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -214
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs +0 -981
- package/dist/lib/node-esm/chunk-ITHTKQOY.mjs.map +0 -7
|
@@ -1,34 +1,17 @@
|
|
|
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-ITHTKQOY.mjs";
|
|
5
|
+
useTimestamp
|
|
6
|
+
} from "./chunk-JSE2X4ML.mjs";
|
|
22
7
|
|
|
23
|
-
//
|
|
24
|
-
import {
|
|
25
|
-
import { effect } from "@preact/signals-core";
|
|
26
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
8
|
+
// src/components/Graph/Graph.tsx
|
|
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";
|
|
33
16
|
var createLine = line();
|
|
34
17
|
var createArrow = (length, offset, start) => (el) => {
|
|
@@ -79,7 +62,7 @@ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
|
|
|
79
62
|
});
|
|
80
63
|
};
|
|
81
64
|
|
|
82
|
-
//
|
|
65
|
+
// src/graph/projector/graph-drag.ts
|
|
83
66
|
import { drag, pointer, select as select2 } from "d3";
|
|
84
67
|
var defaultDragOptions = {
|
|
85
68
|
linkMod: "metaKey",
|
|
@@ -159,19 +142,11 @@ var createGraphDrag = (context, projector, options = defaultDragOptions) => {
|
|
|
159
142
|
});
|
|
160
143
|
};
|
|
161
144
|
|
|
162
|
-
//
|
|
145
|
+
// src/graph/types.ts
|
|
163
146
|
import { invariant } from "@dxos/invariant";
|
|
164
|
-
var __dxlog_file = "/
|
|
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,11 +154,577 @@ var emptyGraph = {
|
|
|
179
154
|
edges: []
|
|
180
155
|
};
|
|
181
156
|
|
|
182
|
-
//
|
|
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
|
+
|
|
721
|
+
// src/graph/projector/projector.ts
|
|
183
722
|
var Projector = class {
|
|
723
|
+
_context;
|
|
724
|
+
updated = new EventEmitter();
|
|
725
|
+
_options;
|
|
184
726
|
constructor(_context, options) {
|
|
185
727
|
this._context = _context;
|
|
186
|
-
this.updated = new EventEmitter();
|
|
187
728
|
this._options = Object.assign({
|
|
188
729
|
idAccessor: defaultIdAccessor
|
|
189
730
|
}, options);
|
|
@@ -226,8 +767,10 @@ var Projector = class {
|
|
|
226
767
|
}
|
|
227
768
|
};
|
|
228
769
|
|
|
229
|
-
//
|
|
770
|
+
// src/graph/projector/graph-projector.ts
|
|
230
771
|
var GraphProjector = class extends Projector {
|
|
772
|
+
_selection;
|
|
773
|
+
_layout;
|
|
231
774
|
// TODO(burdon): Change to object props.
|
|
232
775
|
constructor(context, options, _selection, layout) {
|
|
233
776
|
super(context, options), this._selection = _selection;
|
|
@@ -290,11 +833,11 @@ var GraphProjector = class extends Projector {
|
|
|
290
833
|
}
|
|
291
834
|
};
|
|
292
835
|
|
|
293
|
-
//
|
|
836
|
+
// src/graph/projector/graph-force-projector.ts
|
|
294
837
|
import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
|
|
295
838
|
import { log } from "@dxos/log";
|
|
296
839
|
|
|
297
|
-
//
|
|
840
|
+
// src/graph/projector/graph-forces.ts
|
|
298
841
|
import { forceX, forceY } from "d3";
|
|
299
842
|
var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
300
843
|
const fx = x != null ? forceX(x).strength(strength) : void 0;
|
|
@@ -310,8 +853,8 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
310
853
|
return force;
|
|
311
854
|
};
|
|
312
855
|
|
|
313
|
-
//
|
|
314
|
-
var
|
|
856
|
+
// src/graph/projector/graph-force-projector.ts
|
|
857
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
315
858
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
316
859
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
317
860
|
};
|
|
@@ -328,11 +871,9 @@ var defaultForceOptions = {
|
|
|
328
871
|
point: true
|
|
329
872
|
};
|
|
330
873
|
var GraphForceProjector = class extends GraphProjector {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this._simulation = forceSimulation();
|
|
335
|
-
}
|
|
874
|
+
// https://github.com/d3/d3-force
|
|
875
|
+
_simulation = forceSimulation();
|
|
876
|
+
_timeout;
|
|
336
877
|
get forces() {
|
|
337
878
|
return this.options.forces ?? defaultForceOptions;
|
|
338
879
|
}
|
|
@@ -385,12 +926,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
385
926
|
nodes: graph?.nodes.length,
|
|
386
927
|
edges: graph?.edges.length
|
|
387
928
|
}
|
|
388
|
-
}, {
|
|
389
|
-
F: __dxlog_file2,
|
|
390
|
-
L: 226,
|
|
391
|
-
S: this,
|
|
392
|
-
C: (f, a) => f(...a)
|
|
393
|
-
});
|
|
929
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 89, S: this });
|
|
394
930
|
this._simulation.stop();
|
|
395
931
|
this.mergeData(graph);
|
|
396
932
|
this.updateLayout();
|
|
@@ -440,12 +976,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
440
976
|
updateForces(forces) {
|
|
441
977
|
log("updateForces", {
|
|
442
978
|
forces
|
|
443
|
-
}, {
|
|
444
|
-
F: __dxlog_file2,
|
|
445
|
-
L: 287,
|
|
446
|
-
S: this,
|
|
447
|
-
C: (f, a) => f(...a)
|
|
448
|
-
});
|
|
979
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 148, S: this });
|
|
449
980
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
450
981
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
451
982
|
if (config.distance != null) {
|
|
@@ -508,14 +1039,15 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
508
1039
|
}
|
|
509
1040
|
};
|
|
510
1041
|
|
|
511
|
-
//
|
|
1042
|
+
// src/graph/projector/graph-hierarchical-projector.ts
|
|
512
1043
|
import { log as log3 } from "@dxos/log";
|
|
513
1044
|
|
|
514
|
-
//
|
|
1045
|
+
// src/graph/projector/graph-radial-projector.ts
|
|
515
1046
|
import { easeCubic, timer } from "d3";
|
|
516
1047
|
import { log as log2 } from "@dxos/log";
|
|
517
|
-
var
|
|
1048
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
518
1049
|
var GraphRadialProjector = class extends GraphProjector {
|
|
1050
|
+
_timer;
|
|
519
1051
|
findNode(x, y, radius) {
|
|
520
1052
|
return void 0;
|
|
521
1053
|
}
|
|
@@ -525,12 +1057,7 @@ var GraphRadialProjector = class extends GraphProjector {
|
|
|
525
1057
|
nodes: graph?.nodes.length,
|
|
526
1058
|
edges: graph?.edges.length
|
|
527
1059
|
}
|
|
528
|
-
}, {
|
|
529
|
-
F: __dxlog_file3,
|
|
530
|
-
L: 31,
|
|
531
|
-
S: this,
|
|
532
|
-
C: (f, a) => f(...a)
|
|
533
|
-
});
|
|
1060
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 13, S: this });
|
|
534
1061
|
this.mergeData(graph);
|
|
535
1062
|
this.doRadialLayout();
|
|
536
1063
|
}
|
|
@@ -625,8 +1152,8 @@ var layoutVertical = (x, y, h, n) => {
|
|
|
625
1152
|
};
|
|
626
1153
|
};
|
|
627
1154
|
|
|
628
|
-
//
|
|
629
|
-
var
|
|
1155
|
+
// src/graph/projector/graph-hierarchical-projector.ts
|
|
1156
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
630
1157
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
631
1158
|
onUpdate(graph) {
|
|
632
1159
|
log3("onUpdate", {
|
|
@@ -634,15 +1161,10 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
634
1161
|
nodes: graph?.nodes.length,
|
|
635
1162
|
edges: graph?.edges.length
|
|
636
1163
|
},
|
|
637
|
-
selection: this.selection?.
|
|
638
|
-
}, {
|
|
639
|
-
F: __dxlog_file4,
|
|
640
|
-
L: 23,
|
|
641
|
-
S: this,
|
|
642
|
-
C: (f, a) => f(...a)
|
|
643
|
-
});
|
|
1164
|
+
selection: this.selection?.getSelectedIds()
|
|
1165
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 8, S: this });
|
|
644
1166
|
this.mergeData(graph);
|
|
645
|
-
const selected = this.selection?.
|
|
1167
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
646
1168
|
if (selected) {
|
|
647
1169
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
648
1170
|
if (node) {
|
|
@@ -687,9 +1209,9 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
687
1209
|
}
|
|
688
1210
|
};
|
|
689
1211
|
|
|
690
|
-
//
|
|
1212
|
+
// src/graph/projector/graph-relational-projector.ts
|
|
691
1213
|
import { log as log4 } from "@dxos/log";
|
|
692
|
-
var
|
|
1214
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
693
1215
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
694
1216
|
onUpdate(graph) {
|
|
695
1217
|
log4("onUpdate", {
|
|
@@ -697,15 +1219,10 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
697
1219
|
nodes: graph?.nodes.length,
|
|
698
1220
|
edges: graph?.edges.length
|
|
699
1221
|
},
|
|
700
|
-
selection: this.selection?.
|
|
701
|
-
}, {
|
|
702
|
-
F: __dxlog_file5,
|
|
703
|
-
L: 23,
|
|
704
|
-
S: this,
|
|
705
|
-
C: (f, a) => f(...a)
|
|
706
|
-
});
|
|
1222
|
+
selection: this.selection?.getSelectedIds()
|
|
1223
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 8, S: this });
|
|
707
1224
|
this.mergeData(graph);
|
|
708
|
-
const selected = this.selection?.
|
|
1225
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
709
1226
|
if (selected) {
|
|
710
1227
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
711
1228
|
if (node) {
|
|
@@ -776,12 +1293,12 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
776
1293
|
}
|
|
777
1294
|
};
|
|
778
1295
|
|
|
779
|
-
//
|
|
780
|
-
import { line as line2, select as select4
|
|
1296
|
+
// src/graph/renderer/graph-renderer.ts
|
|
1297
|
+
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
781
1298
|
import * as Clipper from "js-clipper";
|
|
782
1299
|
import { log as log5 } from "@dxos/log";
|
|
783
1300
|
|
|
784
|
-
//
|
|
1301
|
+
// src/graph/renderer/bullets.ts
|
|
785
1302
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
786
1303
|
var createBullets = (group, nodeId, options = {}) => {
|
|
787
1304
|
return (selection) => {
|
|
@@ -811,10 +1328,13 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
811
1328
|
};
|
|
812
1329
|
};
|
|
813
1330
|
|
|
814
|
-
//
|
|
815
|
-
import { invariant as
|
|
816
|
-
var
|
|
1331
|
+
// src/graph/renderer/renderer.ts
|
|
1332
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1333
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
817
1334
|
var Renderer = class {
|
|
1335
|
+
_context;
|
|
1336
|
+
_root;
|
|
1337
|
+
_options;
|
|
818
1338
|
constructor(_context, _root, options) {
|
|
819
1339
|
this._context = _context;
|
|
820
1340
|
this._root = _root;
|
|
@@ -826,15 +1346,7 @@ var Renderer = class {
|
|
|
826
1346
|
return this._context;
|
|
827
1347
|
}
|
|
828
1348
|
get root() {
|
|
829
|
-
|
|
830
|
-
F: __dxlog_file6,
|
|
831
|
-
L: 40,
|
|
832
|
-
S: this,
|
|
833
|
-
A: [
|
|
834
|
-
"this._root.current",
|
|
835
|
-
"'SVG root is not initialized'"
|
|
836
|
-
]
|
|
837
|
-
});
|
|
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'"] });
|
|
838
1350
|
return this._root.current;
|
|
839
1351
|
}
|
|
840
1352
|
get options() {
|
|
@@ -842,17 +1354,12 @@ var Renderer = class {
|
|
|
842
1354
|
}
|
|
843
1355
|
};
|
|
844
1356
|
|
|
845
|
-
//
|
|
846
|
-
var
|
|
1357
|
+
// src/graph/renderer/graph-renderer.ts
|
|
1358
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
847
1359
|
var createLine2 = line2();
|
|
848
1360
|
var GraphRenderer = class extends Renderer {
|
|
849
1361
|
render(layout) {
|
|
850
|
-
log5("render", layout, {
|
|
851
|
-
F: __dxlog_file7,
|
|
852
|
-
L: 62,
|
|
853
|
-
S: this,
|
|
854
|
-
C: (f, a) => f(...a)
|
|
855
|
-
});
|
|
1362
|
+
log5("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 19, S: this });
|
|
856
1363
|
const root = select4(this.root);
|
|
857
1364
|
if (layout.guides) {
|
|
858
1365
|
root.selectAll("g.dx-guides").data([
|
|
@@ -959,14 +1466,14 @@ var createNode = (group, options) => {
|
|
|
959
1466
|
circle.on("pointerenter", function() {
|
|
960
1467
|
select4(this.closest("g.dx-node")).raise();
|
|
961
1468
|
if (options.labels) {
|
|
962
|
-
select4(this.parentElement).classed("dx-active", true).classed("dx-highlight", true);
|
|
1469
|
+
select4(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
|
|
963
1470
|
}
|
|
964
1471
|
});
|
|
965
1472
|
group.on("pointerleave", function() {
|
|
966
1473
|
if (options.labels) {
|
|
967
|
-
select4(this).classed("dx-active", false);
|
|
1474
|
+
select4(this).classed("dx-node-active", false);
|
|
968
1475
|
setTimeout(() => {
|
|
969
|
-
if (!select4(this).classed("dx-active")) {
|
|
1476
|
+
if (!select4(this).classed("dx-node-active")) {
|
|
970
1477
|
select4(this).classed("dx-highlight", false);
|
|
971
1478
|
}
|
|
972
1479
|
}, 300);
|
|
@@ -995,12 +1502,7 @@ var updateNode2 = (group, options) => {
|
|
|
995
1502
|
} catch (error) {
|
|
996
1503
|
log5.error("updateNode", {
|
|
997
1504
|
error: error?.message
|
|
998
|
-
}, {
|
|
999
|
-
F: __dxlog_file7,
|
|
1000
|
-
L: 304,
|
|
1001
|
-
S: void 0,
|
|
1002
|
-
C: (f, a) => f(...a)
|
|
1003
|
-
});
|
|
1505
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 194, S: void 0 });
|
|
1004
1506
|
}
|
|
1005
1507
|
}
|
|
1006
1508
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
@@ -1051,12 +1553,7 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1051
1553
|
} catch (error) {
|
|
1052
1554
|
log5.error("updateEdge", {
|
|
1053
1555
|
error: error?.message
|
|
1054
|
-
}, {
|
|
1055
|
-
F: __dxlog_file7,
|
|
1056
|
-
L: 416,
|
|
1057
|
-
S: void 0,
|
|
1058
|
-
C: (f, a) => f(...a)
|
|
1059
|
-
});
|
|
1556
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 260, S: void 0 });
|
|
1060
1557
|
}
|
|
1061
1558
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1062
1559
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
@@ -1111,7 +1608,7 @@ var findConnectedComponents = (graph) => {
|
|
|
1111
1608
|
return components;
|
|
1112
1609
|
};
|
|
1113
1610
|
|
|
1114
|
-
//
|
|
1611
|
+
// src/graph/renderer/linker.ts
|
|
1115
1612
|
import { line as line3 } from "d3";
|
|
1116
1613
|
var createLine3 = line3();
|
|
1117
1614
|
var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
@@ -1134,112 +1631,425 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1134
1631
|
});
|
|
1135
1632
|
};
|
|
1136
1633
|
|
|
1137
|
-
//
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
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
|
-
|
|
1634
|
+
// src/hooks/useGrid.ts
|
|
1635
|
+
import { line as line4, range, select as select5 } from "d3";
|
|
1636
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
1637
|
+
|
|
1638
|
+
// src/hooks/useSvgContext.ts
|
|
1639
|
+
import { createContext, useContext } from "react";
|
|
1640
|
+
import { createRef } from "react";
|
|
1641
|
+
import { raise } from "@dxos/debug";
|
|
1642
|
+
var SVGContext = class {
|
|
1643
|
+
_ref = createRef();
|
|
1644
|
+
_scale;
|
|
1645
|
+
_centered;
|
|
1646
|
+
_size;
|
|
1647
|
+
_center;
|
|
1648
|
+
resized = new EventEmitter();
|
|
1649
|
+
constructor({ scale = new Scale(), centered = true }) {
|
|
1650
|
+
this._scale = scale;
|
|
1651
|
+
this._centered = centered;
|
|
1652
|
+
}
|
|
1653
|
+
get ref() {
|
|
1654
|
+
return this._ref;
|
|
1655
|
+
}
|
|
1656
|
+
get svg() {
|
|
1657
|
+
return this._ref.current;
|
|
1658
|
+
}
|
|
1659
|
+
get scale() {
|
|
1660
|
+
return this._scale;
|
|
1661
|
+
}
|
|
1662
|
+
get center() {
|
|
1663
|
+
return this._center;
|
|
1664
|
+
}
|
|
1665
|
+
get size() {
|
|
1666
|
+
return this._size;
|
|
1667
|
+
}
|
|
1668
|
+
/**
|
|
1669
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
|
|
1670
|
+
*/
|
|
1671
|
+
get viewBox() {
|
|
1672
|
+
const [x, y] = this.center;
|
|
1673
|
+
return `${x},${y},${this._size.width},${this._size.height}`;
|
|
1674
|
+
}
|
|
1675
|
+
setSize(size) {
|
|
1676
|
+
this._size = {
|
|
1677
|
+
...size
|
|
1678
|
+
};
|
|
1679
|
+
this._center = this._centered ? [
|
|
1680
|
+
-Math.floor(size.width / 2),
|
|
1681
|
+
-Math.floor(size.height / 2)
|
|
1682
|
+
] : [
|
|
1683
|
+
0,
|
|
1684
|
+
0
|
|
1685
|
+
];
|
|
1686
|
+
this.resized.emit(this);
|
|
1687
|
+
}
|
|
1688
|
+
setTransform(transform) {
|
|
1689
|
+
if (this._scale.setTransform(transform)) {
|
|
1690
|
+
this.resized.emit(this);
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
/**
|
|
1694
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
|
|
1695
|
+
* @param point
|
|
1696
|
+
*/
|
|
1697
|
+
elementFromPoint(point) {
|
|
1698
|
+
const [x, y] = point;
|
|
1699
|
+
const [cx, cy] = this._center;
|
|
1700
|
+
return document.elementFromPoint(cx + x, cy + y);
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
var SVGContextType = createContext(void 0);
|
|
1704
|
+
var SVGContextProvider = SVGContextType.Provider;
|
|
1705
|
+
var useSvgContext = () => {
|
|
1706
|
+
return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
// src/hooks/useGrid.ts
|
|
1710
|
+
var createLine4 = line4();
|
|
1711
|
+
var createGrid = (context, options) => {
|
|
1712
|
+
if (!context.size) {
|
|
1713
|
+
return [];
|
|
1714
|
+
}
|
|
1715
|
+
const paths = [];
|
|
1716
|
+
const { width, height } = context.size;
|
|
1717
|
+
const { x, y, k } = context.scale.transform;
|
|
1718
|
+
const s = 1 / k;
|
|
1719
|
+
const w = width * s;
|
|
1720
|
+
const h = height * s;
|
|
1721
|
+
const dx = -(x + width / 2) * s;
|
|
1722
|
+
const dy = -(y + height / 2) * s;
|
|
1723
|
+
if (options.axis) {
|
|
1724
|
+
const axis = [
|
|
1725
|
+
[
|
|
1726
|
+
[
|
|
1727
|
+
0,
|
|
1728
|
+
dy
|
|
1729
|
+
],
|
|
1730
|
+
[
|
|
1731
|
+
0,
|
|
1732
|
+
dy + h
|
|
1733
|
+
]
|
|
1734
|
+
],
|
|
1735
|
+
[
|
|
1736
|
+
[
|
|
1737
|
+
dx,
|
|
1738
|
+
0
|
|
1739
|
+
],
|
|
1740
|
+
[
|
|
1741
|
+
dx + w,
|
|
1742
|
+
0
|
|
1743
|
+
]
|
|
1744
|
+
]
|
|
1745
|
+
];
|
|
1746
|
+
paths.push({
|
|
1747
|
+
id: "axis",
|
|
1748
|
+
class: "dx-axis",
|
|
1749
|
+
path: axis.map((line5) => createLine4(line5)).join()
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
if (options.grid) {
|
|
1753
|
+
const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
|
|
1754
|
+
const majorSize = context.scale.gridSize;
|
|
1755
|
+
const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
|
|
1756
|
+
const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
|
|
1757
|
+
const major = [
|
|
1758
|
+
...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
|
|
1759
|
+
[
|
|
1760
|
+
x2,
|
|
1761
|
+
dy
|
|
1762
|
+
],
|
|
1763
|
+
[
|
|
1764
|
+
x2,
|
|
1765
|
+
dy + h
|
|
1766
|
+
]
|
|
1767
|
+
]),
|
|
1768
|
+
...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
|
|
1769
|
+
[
|
|
1770
|
+
dx,
|
|
1771
|
+
y2
|
|
1772
|
+
],
|
|
1773
|
+
[
|
|
1774
|
+
dx + w,
|
|
1775
|
+
y2
|
|
1776
|
+
]
|
|
1777
|
+
])
|
|
1778
|
+
];
|
|
1779
|
+
paths.push({
|
|
1780
|
+
id: "major",
|
|
1781
|
+
class: "dx-major",
|
|
1782
|
+
path: major.map((line5) => createLine4(line5)).join()
|
|
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,
|
|
1972
|
+
onNodePointerEnter: onInspect
|
|
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
|
+
return combine(
|
|
2003
|
+
// Subscribe to model changes if reactive model.
|
|
2004
|
+
model ? model.subscribe(() => {
|
|
1189
2005
|
projector.updateData(model?.graph);
|
|
1190
|
-
})
|
|
2006
|
+
}) : void 0,
|
|
2007
|
+
projector.updated.on(({ layout }) => {
|
|
1191
2008
|
try {
|
|
1192
2009
|
renderer.render(layout);
|
|
1193
2010
|
} catch (error) {
|
|
2011
|
+
log6.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 67, S: void 0 });
|
|
1194
2012
|
void projector.stop();
|
|
1195
|
-
log6.catch(error, void 0, {
|
|
1196
|
-
F: __dxlog_file8,
|
|
1197
|
-
L: 108,
|
|
1198
|
-
S: void 0,
|
|
1199
|
-
C: (f, a) => f(...a)
|
|
1200
|
-
});
|
|
1201
2013
|
}
|
|
1202
|
-
})
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
}
|
|
1221
|
-
_effect.f();
|
|
1222
|
-
}
|
|
2014
|
+
})
|
|
2015
|
+
);
|
|
2016
|
+
}, [
|
|
2017
|
+
model,
|
|
2018
|
+
projector,
|
|
2019
|
+
renderer
|
|
2020
|
+
]);
|
|
2021
|
+
useEffect3(() => {
|
|
2022
|
+
void projector.start();
|
|
2023
|
+
return () => {
|
|
2024
|
+
void projector.stop();
|
|
2025
|
+
};
|
|
2026
|
+
}, [
|
|
2027
|
+
projector
|
|
2028
|
+
]);
|
|
2029
|
+
return /* @__PURE__ */ React.createElement("g", {
|
|
2030
|
+
ref: graphRef,
|
|
2031
|
+
className: mx("dx-graph", classNames)
|
|
2032
|
+
});
|
|
1223
2033
|
};
|
|
1224
2034
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1225
2035
|
|
|
1226
|
-
//
|
|
1227
|
-
import { geoPath, select as
|
|
1228
|
-
import { useEffect as
|
|
2036
|
+
// src/components/Mesh/Mesh.tsx
|
|
2037
|
+
import { geoPath, select as select7 } from "d3";
|
|
2038
|
+
import { useEffect as useEffect4 } from "react";
|
|
1229
2039
|
import { feature, mesh } from "topojson-client";
|
|
1230
2040
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1231
2041
|
const { svg, size } = useSvgContext();
|
|
1232
|
-
|
|
2042
|
+
useEffect4(() => {
|
|
1233
2043
|
if (size) {
|
|
1234
2044
|
const topology = hexTopology(size, radius, value);
|
|
1235
2045
|
const projection = hexProjection(radius);
|
|
1236
2046
|
const path = geoPath().projection(projection);
|
|
1237
|
-
|
|
1238
|
-
|
|
2047
|
+
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);
|
|
2048
|
+
select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
1239
2049
|
const redraw = (border) => {
|
|
1240
2050
|
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1241
2051
|
};
|
|
1242
|
-
|
|
2052
|
+
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
1243
2053
|
}
|
|
1244
2054
|
}, [
|
|
1245
2055
|
svg,
|
|
@@ -1355,119 +2165,100 @@ var hexProjection = (radius) => {
|
|
|
1355
2165
|
};
|
|
1356
2166
|
};
|
|
1357
2167
|
|
|
1358
|
-
//
|
|
1359
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
2168
|
+
// src/components/SVG/Grid.tsx
|
|
1360
2169
|
import React2 from "react";
|
|
1361
|
-
import { mx as mx2 } from "@dxos/
|
|
2170
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1362
2171
|
var Grid = ({ classNames, ...props }) => {
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
className: mx2("dx-grid", classNames)
|
|
1369
|
-
});
|
|
1370
|
-
} finally {
|
|
1371
|
-
_effect.f();
|
|
1372
|
-
}
|
|
2172
|
+
const { ref } = useGrid(props);
|
|
2173
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
2174
|
+
ref,
|
|
2175
|
+
className: mx2("dx-grid", classNames)
|
|
2176
|
+
});
|
|
1373
2177
|
};
|
|
1374
2178
|
|
|
1375
|
-
//
|
|
1376
|
-
import {
|
|
1377
|
-
import {
|
|
1378
|
-
import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
2179
|
+
// src/components/SVG/Markers.tsx
|
|
2180
|
+
import { select as select8 } from "d3";
|
|
2181
|
+
import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
1379
2182
|
var Markers = ({ arrowSize, className }) => {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
className
|
|
1393
|
-
});
|
|
1394
|
-
} finally {
|
|
1395
|
-
_effect.f();
|
|
1396
|
-
}
|
|
2183
|
+
const ref = useRef4(null);
|
|
2184
|
+
useEffect5(() => {
|
|
2185
|
+
select8(ref.current).call(createMarkers({
|
|
2186
|
+
arrowSize
|
|
2187
|
+
}));
|
|
2188
|
+
}, [
|
|
2189
|
+
ref
|
|
2190
|
+
]);
|
|
2191
|
+
return /* @__PURE__ */ React3.createElement("defs", {
|
|
2192
|
+
ref,
|
|
2193
|
+
className
|
|
2194
|
+
});
|
|
1397
2195
|
};
|
|
1398
2196
|
|
|
1399
|
-
//
|
|
1400
|
-
import {
|
|
1401
|
-
import {
|
|
1402
|
-
import React4, { forwardRef as forwardRef2, useEffect as useEffect4, useMemo as useMemo2, useImperativeHandle as useImperativeHandle2 } from "react";
|
|
2197
|
+
// src/components/SVG/Root.tsx
|
|
2198
|
+
import { select as select9 } from "d3";
|
|
2199
|
+
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
|
|
1403
2200
|
import { useResizeDetector } from "react-resize-detector";
|
|
1404
|
-
import { mx as mx3 } from "@dxos/
|
|
1405
|
-
var Root = /* @__PURE__ */ forwardRef2(({
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
2201
|
+
import { composableProps, mx as mx3 } from "@dxos/ui-theme";
|
|
2202
|
+
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
2203
|
+
const { ref: containerRef, width = 0, height = 0 } = useResizeDetector({
|
|
2204
|
+
refreshRate: 200
|
|
2205
|
+
});
|
|
2206
|
+
const context = useMemo4(() => {
|
|
2207
|
+
return new SVGContext({
|
|
2208
|
+
scale,
|
|
2209
|
+
centered
|
|
1410
2210
|
});
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
} finally {
|
|
1445
|
-
_effect.f();
|
|
1446
|
-
}
|
|
2211
|
+
}, [
|
|
2212
|
+
scale,
|
|
2213
|
+
centered
|
|
2214
|
+
]);
|
|
2215
|
+
useImperativeHandle2(ref, () => context, [
|
|
2216
|
+
context
|
|
2217
|
+
]);
|
|
2218
|
+
useEffect6(() => {
|
|
2219
|
+
if (width && height) {
|
|
2220
|
+
context.setSize({
|
|
2221
|
+
width,
|
|
2222
|
+
height
|
|
2223
|
+
});
|
|
2224
|
+
select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
2225
|
+
}
|
|
2226
|
+
}, [
|
|
2227
|
+
context,
|
|
2228
|
+
width,
|
|
2229
|
+
height
|
|
2230
|
+
]);
|
|
2231
|
+
const ready = width !== 0 && height !== 0;
|
|
2232
|
+
return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
|
|
2233
|
+
value: context
|
|
2234
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
2235
|
+
...composableProps(props, {
|
|
2236
|
+
classNames: "dx-expander"
|
|
2237
|
+
}),
|
|
2238
|
+
ref: containerRef
|
|
2239
|
+
}, /* @__PURE__ */ React4.createElement("svg", {
|
|
2240
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2241
|
+
ref: context.ref,
|
|
2242
|
+
className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
2243
|
+
}, ready && children)));
|
|
1447
2244
|
});
|
|
1448
2245
|
|
|
1449
|
-
//
|
|
1450
|
-
import {
|
|
1451
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
2246
|
+
// src/components/SVG/Zoom.tsx
|
|
2247
|
+
import React5, { memo, useMemo as useMemo5 } from "react";
|
|
1452
2248
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
className
|
|
1464
|
-
}, children);
|
|
1465
|
-
} finally {
|
|
1466
|
-
_effect.f();
|
|
1467
|
-
}
|
|
2249
|
+
const options = useMemo5(() => ({
|
|
2250
|
+
extent
|
|
2251
|
+
}), [
|
|
2252
|
+
JSON.stringify(extent)
|
|
2253
|
+
]);
|
|
2254
|
+
const zoom2 = useZoom(options);
|
|
2255
|
+
return /* @__PURE__ */ React5.createElement("g", {
|
|
2256
|
+
ref: zoom2.ref,
|
|
2257
|
+
className
|
|
2258
|
+
}, children);
|
|
1468
2259
|
});
|
|
1469
2260
|
|
|
1470
|
-
//
|
|
2261
|
+
// src/components/SVG/SVG.tsx
|
|
1471
2262
|
var SVG = {
|
|
1472
2263
|
Root,
|
|
1473
2264
|
Grid,
|
|
@@ -1477,8 +2268,8 @@ var SVG = {
|
|
|
1477
2268
|
Graph
|
|
1478
2269
|
};
|
|
1479
2270
|
|
|
1480
|
-
//
|
|
1481
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
2271
|
+
// src/fx/pulsar.ts
|
|
2272
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1482
2273
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1483
2274
|
(function(Pulsar2) {
|
|
1484
2275
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1493,10 +2284,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1493
2284
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1494
2285
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1495
2286
|
return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(easeCubicOut2).attr("r", r * ratio).attr("opacity", -0.1).on("end", function() {
|
|
1496
|
-
if (
|
|
1497
|
-
startAnimation(
|
|
2287
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
2288
|
+
startAnimation(select10(this), r, options);
|
|
1498
2289
|
} else {
|
|
1499
|
-
|
|
2290
|
+
select10(this).remove();
|
|
1500
2291
|
}
|
|
1501
2292
|
});
|
|
1502
2293
|
};
|
|
@@ -1507,7 +2298,6 @@ export {
|
|
|
1507
2298
|
Graph,
|
|
1508
2299
|
GraphForceProjector,
|
|
1509
2300
|
GraphHierarchicalProjector,
|
|
1510
|
-
GraphInner,
|
|
1511
2301
|
GraphProjector,
|
|
1512
2302
|
GraphRadialProjector,
|
|
1513
2303
|
GraphRelationalProjector,
|