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