@dxos/react-ui-graph 0.8.3 → 0.8.4-main.28f8d3d

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.
Files changed (92) hide show
  1. package/dist/lib/browser/{chunk-2YMRPQU7.mjs → chunk-HLAKLUDC.mjs} +362 -383
  2. package/dist/lib/browser/{chunk-2YMRPQU7.mjs.map → chunk-HLAKLUDC.mjs.map} +3 -3
  3. package/dist/lib/browser/index.mjs +57 -50
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +4 -4
  7. package/dist/lib/browser/testing/index.mjs.map +2 -2
  8. package/dist/lib/node-esm/{chunk-ITHTKQOY.mjs → chunk-O6GWCXDC.mjs} +362 -383
  9. package/dist/lib/node-esm/{chunk-ITHTKQOY.mjs.map → chunk-O6GWCXDC.mjs.map} +3 -3
  10. package/dist/lib/node-esm/index.mjs +57 -50
  11. package/dist/lib/node-esm/index.mjs.map +3 -3
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +4 -4
  14. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  15. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  16. package/dist/types/src/components/Graph/Graph.stories.d.ts +2 -2
  17. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  18. package/dist/types/src/components/Mesh/Mesh.stories.d.ts +1 -1
  19. package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
  21. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  22. package/dist/types/src/components/SVG/SVG.d.ts +2 -2
  23. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  24. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  25. package/dist/types/src/components/SVG/Zoom.d.ts.map +1 -1
  26. package/dist/types/src/fx/fx.stories.d.ts +1 -1
  27. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  28. package/dist/types/src/graph/projector/graph-drag.d.ts +1 -1
  29. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  30. package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
  31. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  32. package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
  33. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
  34. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  35. package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
  36. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  37. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +1 -1
  38. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  39. package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
  40. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  41. package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
  42. package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
  43. package/dist/types/src/graph/renderer/graph-renderer.d.ts +1 -1
  44. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  45. package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
  46. package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
  47. package/dist/types/src/stories/hooks.stories.d.ts +1 -1
  48. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  49. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  50. package/dist/types/src/util/index.d.ts +2 -2
  51. package/dist/types/src/util/index.d.ts.map +1 -1
  52. package/dist/types/src/util/screen.d.ts +1 -1
  53. package/dist/types/src/util/screen.d.ts.map +1 -1
  54. package/dist/types/src/util/vector.d.ts +1 -1
  55. package/dist/types/src/util/vector.d.ts.map +1 -1
  56. package/dist/types/tsconfig.tsbuildinfo +1 -1
  57. package/package.json +17 -17
  58. package/src/components/Graph/Graph.stories.tsx +10 -9
  59. package/src/components/Graph/Graph.tsx +1 -1
  60. package/src/components/Mesh/Mesh.stories.tsx +3 -2
  61. package/src/components/Mesh/Mesh.tsx +1 -1
  62. package/src/components/SVG/Grid.tsx +1 -1
  63. package/src/components/SVG/Root.tsx +1 -1
  64. package/src/components/SVG/SVG.tsx +4 -3
  65. package/src/components/SVG/Svg.stories.tsx +2 -1
  66. package/src/components/SVG/Zoom.tsx +1 -1
  67. package/src/fx/fx.stories.tsx +3 -2
  68. package/src/graph/projector/graph-drag.ts +2 -1
  69. package/src/graph/projector/graph-force-projector.ts +3 -2
  70. package/src/graph/projector/graph-forces.ts +1 -1
  71. package/src/graph/projector/graph-hierarchical-projector.ts +2 -1
  72. package/src/graph/projector/graph-projector.ts +4 -3
  73. package/src/graph/projector/graph-radial-projector.ts +3 -2
  74. package/src/graph/projector/graph-relational-projector.ts +2 -1
  75. package/src/graph/projector/projector.ts +1 -1
  76. package/src/graph/renderer/bullets.ts +1 -1
  77. package/src/graph/renderer/graph-renderer.ts +4 -3
  78. package/src/graph/renderer/renderer.ts +1 -1
  79. package/src/hooks/useZoom.ts +1 -1
  80. package/src/stories/hooks.stories.tsx +6 -6
  81. package/src/testing/hooks.ts +3 -2
  82. package/src/util/index.ts +2 -2
  83. package/src/util/screen.test.ts +1 -1
  84. package/src/util/screen.ts +1 -1
  85. package/src/util/vector.ts +1 -1
  86. package/dist/lib/node/chunk-WFHWEMPB.cjs +0 -919
  87. package/dist/lib/node/chunk-WFHWEMPB.cjs.map +0 -7
  88. package/dist/lib/node/index.cjs +0 -1547
  89. package/dist/lib/node/index.cjs.map +0 -7
  90. package/dist/lib/node/meta.json +0 -1
  91. package/dist/lib/node/testing/index.cjs +0 -214
  92. package/dist/lib/node/testing/index.cjs.map +0 -7
@@ -1,1547 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var node_exports = {};
29
- __export(node_exports, {
30
- EventEmitter: () => import_chunk_WFHWEMPB.EventEmitter,
31
- FractionUtil: () => import_chunk_WFHWEMPB.FractionUtil,
32
- Graph: () => Graph,
33
- GraphForceProjector: () => GraphForceProjector,
34
- GraphHierarchicalProjector: () => GraphHierarchicalProjector,
35
- GraphInner: () => GraphInner,
36
- GraphProjector: () => GraphProjector,
37
- GraphRadialProjector: () => GraphRadialProjector,
38
- GraphRelationalProjector: () => GraphRelationalProjector,
39
- GraphRenderer: () => GraphRenderer,
40
- GridController: () => import_chunk_WFHWEMPB.GridController,
41
- Mesh: () => Mesh,
42
- Projector: () => Projector,
43
- Pulsar: () => Pulsar,
44
- Renderer: () => Renderer,
45
- SVG: () => SVG,
46
- SVGContext: () => import_chunk_WFHWEMPB.SVGContext,
47
- SVGContextProvider: () => import_chunk_WFHWEMPB.SVGContextProvider,
48
- Scale: () => import_chunk_WFHWEMPB.Scale,
49
- Screen: () => import_chunk_WFHWEMPB.Screen,
50
- Vector: () => import_chunk_WFHWEMPB.Vector,
51
- ZoomHandler: () => import_chunk_WFHWEMPB.ZoomHandler,
52
- createGraphDrag: () => createGraphDrag,
53
- createMarkers: () => createMarkers,
54
- defaultForceOptions: () => defaultForceOptions,
55
- defaultIdAccessor: () => defaultIdAccessor,
56
- emptyGraph: () => emptyGraph,
57
- getCircumferencePoints: () => import_chunk_WFHWEMPB.getCircumferencePoints,
58
- layoutHorizontal: () => layoutHorizontal,
59
- layoutRadial: () => layoutRadial,
60
- layoutVertical: () => layoutVertical,
61
- linkerRenderer: () => linkerRenderer,
62
- normal: () => import_chunk_WFHWEMPB.normal,
63
- offsetPoints: () => import_chunk_WFHWEMPB.offsetPoints,
64
- updateNode: () => updateNode,
65
- useDynamicRef: () => import_chunk_WFHWEMPB.useDynamicRef,
66
- useGrid: () => import_chunk_WFHWEMPB.useGrid,
67
- useStateRef: () => import_chunk_WFHWEMPB.useStateRef,
68
- useSvgContext: () => import_chunk_WFHWEMPB.useSvgContext,
69
- useTimestamp: () => import_chunk_WFHWEMPB.useTimestamp,
70
- useZoom: () => import_chunk_WFHWEMPB.useZoom
71
- });
72
- module.exports = __toCommonJS(node_exports);
73
- var import_chunk_WFHWEMPB = require("./chunk-WFHWEMPB.cjs");
74
- var import_tracking = require("@preact-signals/safe-react/tracking");
75
- var import_signals_core = require("@preact/signals-core");
76
- var import_react = __toESM(require("react"));
77
- var import_async = require("@dxos/async");
78
- var import_log = require("@dxos/log");
79
- var import_react_ui_theme = require("@dxos/react-ui-theme");
80
- var import_d3 = require("d3");
81
- var import_d32 = require("d3");
82
- var import_invariant = require("@dxos/invariant");
83
- var import_d33 = require("d3");
84
- var import_log2 = require("@dxos/log");
85
- var import_d34 = require("d3");
86
- var import_log3 = require("@dxos/log");
87
- var import_d35 = require("d3");
88
- var import_log4 = require("@dxos/log");
89
- var import_log5 = require("@dxos/log");
90
- var import_d36 = require("d3");
91
- var Clipper = __toESM(require("js-clipper"));
92
- var import_log6 = require("@dxos/log");
93
- var import_d37 = require("d3");
94
- var import_invariant2 = require("@dxos/invariant");
95
- var import_d38 = require("d3");
96
- var import_d39 = require("d3");
97
- var import_react2 = require("react");
98
- var import_topojson_client = require("topojson-client");
99
- var import_tracking2 = require("@preact-signals/safe-react/tracking");
100
- var import_react3 = __toESM(require("react"));
101
- var import_react_ui_theme2 = require("@dxos/react-ui-theme");
102
- var import_tracking3 = require("@preact-signals/safe-react/tracking");
103
- var import_d310 = require("d3");
104
- var import_react4 = __toESM(require("react"));
105
- var import_tracking4 = require("@preact-signals/safe-react/tracking");
106
- var import_d311 = require("d3");
107
- var import_react5 = __toESM(require("react"));
108
- var import_react_resize_detector = require("react-resize-detector");
109
- var import_react_ui_theme3 = require("@dxos/react-ui-theme");
110
- var import_tracking5 = require("@preact-signals/safe-react/tracking");
111
- var import_react6 = __toESM(require("react"));
112
- var import_d312 = require("d3");
113
- var createLine = (0, import_d3.line)();
114
- var createArrow = (length, offset, start) => (el) => {
115
- const height = length * 0.5;
116
- el.attr("markerWidth", length * 2).attr("markerHeight", height * 2).attr("viewBox", `-${length},-${height},${length * 2},${height * 2}`).attr("orient", "auto").attr("refX", offset).append("path").attr("fill", "none").attr("stroke", "context-stroke").attr("d", createLine([
117
- start ? [
118
- length,
119
- height
120
- ] : [
121
- -length,
122
- -height
123
- ],
124
- [
125
- 0,
126
- 0
127
- ],
128
- start ? [
129
- length,
130
- -height
131
- ] : [
132
- -length,
133
- height
134
- ]
135
- ]));
136
- };
137
- var createDot = (size) => (el) => {
138
- el.attr("markerWidth", size * 2).attr("markerHeight", size * 2).attr("viewBox", `-${size},-${size},${size * 2},${size * 2}`).attr("orient", "auto").append("circle").attr("fill", "context-stroke").attr("r", size / 2 - 1);
139
- };
140
- var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
141
- return group.selectAll("marker").data([
142
- {
143
- id: "marker-arrow-start",
144
- generator: createArrow(arrowSize, -0.5, true),
145
- className: "dx-arrow"
146
- },
147
- {
148
- id: "marker-arrow-end",
149
- generator: createArrow(arrowSize, 0.5, false),
150
- className: "dx-arrow"
151
- },
152
- {
153
- id: "marker-dot",
154
- generator: createDot(6),
155
- className: "dx-dot"
156
- }
157
- ]).join("marker").attr("id", (d) => d.id).attr("markerUnits", "strokeWidth").attr("class", (d) => d.className).each((d, i, nodes) => {
158
- (0, import_d3.select)(nodes[i]).call(d.generator);
159
- });
160
- };
161
- var defaultDragOptions = {
162
- linkMod: "metaKey",
163
- freezeMod: "shiftKey"
164
- };
165
- var createGraphDrag = (context, projector, options = defaultDragOptions) => {
166
- let mode;
167
- let source;
168
- let target;
169
- let offset;
170
- let moved = false;
171
- const keyMod = (event, key) => {
172
- const modKey = options?.[key] ?? defaultDragOptions[key];
173
- return modKey === void 0 || event[modKey];
174
- };
175
- return (0, import_d32.drag)().filter((event) => !event.ctrlKey).on("start", function(event, d) {
176
- source = d;
177
- offset = (0, import_d32.pointer)(event, this.parentElement);
178
- if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) {
179
- mode = 1;
180
- } else if (keyMod(event.sourceEvent, "dragMod")) {
181
- mode = 0;
182
- }
183
- }).on("drag", function(event, d) {
184
- const parent = this.closest("g.node");
185
- (0, import_d32.select)(parent).classed("dragging", true).raise();
186
- const [dx, dy] = (0, import_d32.pointer)(event, this.parentElement);
187
- const x = d.x + dx - offset[0];
188
- const y = d.y + dy - offset[1];
189
- const point = [
190
- x,
191
- y
192
- ];
193
- switch (mode) {
194
- case 0: {
195
- (0, import_d32.select)(context.svg).attr("cursor", "grabbing");
196
- event.subject.x = event.subject.fx = point[0];
197
- event.subject.y = event.subject.fy = point[1];
198
- projector.refresh(true);
199
- moved = true;
200
- break;
201
- }
202
- case 1: {
203
- if (options?.onDrag) {
204
- target = projector.findNode(event.x, event.y, 16);
205
- if (source === target) {
206
- (0, import_d32.select)(context.svg).attr("cursor", void 0);
207
- options?.onDrag?.();
208
- } else {
209
- (0, import_d32.select)(context.svg).attr("cursor", target ? "alias" : "cell");
210
- options?.onDrag?.(source, target, point);
211
- }
212
- }
213
- }
214
- }
215
- }).on("end", function(event) {
216
- (0, import_d32.select)(context.svg).attr("cursor", void 0);
217
- (0, import_d32.select)(this.parentElement).classed("dragging", false);
218
- switch (mode) {
219
- case 1: {
220
- options?.onDrop?.(source, target);
221
- break;
222
- }
223
- }
224
- if (!keyMod(event.sourceEvent, "freezeMod")) {
225
- event.subject.fx = null;
226
- event.subject.fy = null;
227
- }
228
- mode = void 0;
229
- source = void 0;
230
- target = void 0;
231
- offset = void 0;
232
- if (moved) {
233
- projector.refresh(false);
234
- moved = false;
235
- }
236
- });
237
- };
238
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
239
- var defaultIdAccessor = (node) => {
240
- (0, import_invariant.invariant)(node.id, void 0, {
241
- F: __dxlog_file,
242
- L: 18,
243
- S: void 0,
244
- A: [
245
- "node.id",
246
- ""
247
- ]
248
- });
249
- return node.id;
250
- };
251
- var emptyGraph = {
252
- nodes: [],
253
- edges: []
254
- };
255
- var Projector = class {
256
- constructor(_context, options) {
257
- this._context = _context;
258
- this.updated = new import_chunk_WFHWEMPB.EventEmitter();
259
- this._options = Object.assign({
260
- idAccessor: defaultIdAccessor
261
- }, options);
262
- }
263
- get context() {
264
- return this._context;
265
- }
266
- get options() {
267
- return this._options;
268
- }
269
- refresh(dragging = false) {
270
- this.onRefresh(dragging);
271
- }
272
- updateData(data) {
273
- this.onUpdate(data);
274
- }
275
- emitUpdate() {
276
- this.updated.emit({
277
- layout: this.layout
278
- });
279
- }
280
- async clear() {
281
- await this.onClear();
282
- }
283
- async start() {
284
- await this.onStart();
285
- }
286
- async stop() {
287
- await this.onStop();
288
- }
289
- onRefresh(dragging = false) {
290
- }
291
- onUpdate(data) {
292
- }
293
- async onClear() {
294
- }
295
- async onStart() {
296
- }
297
- async onStop() {
298
- }
299
- };
300
- var GraphProjector = class extends Projector {
301
- // TODO(burdon): Change to object props.
302
- constructor(context, options, _selection, layout) {
303
- super(context, options), this._selection = _selection;
304
- this._layout = {
305
- id: (Math.random() * 10).toString().slice(8),
306
- graph: {
307
- nodes: [
308
- ...layout?.graph.nodes ?? []
309
- ],
310
- edges: [
311
- ...layout?.graph.edges ?? []
312
- ]
313
- }
314
- };
315
- }
316
- get layout() {
317
- return this._layout;
318
- }
319
- get selection() {
320
- return this._selection;
321
- }
322
- numChildren(node) {
323
- return this._layout.graph.edges.filter((edge) => edge.source.id === this.options.idAccessor(node)).length;
324
- }
325
- reset() {
326
- this._layout.graph.nodes = [];
327
- this._layout.graph.edges = [];
328
- this.emitUpdate();
329
- }
330
- /**
331
- * Merge external data with internal representation (e.g., so force properties like position are preserved).
332
- * @param data
333
- */
334
- mergeData(data = emptyGraph) {
335
- const nodes = data.nodes.map((node) => {
336
- let current = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
337
- if (!current) {
338
- current = {
339
- id: this.options.idAccessor(node)
340
- };
341
- }
342
- current.data = node;
343
- return current;
344
- });
345
- const edges = data.edges.map((edge) => ({
346
- id: edge.id,
347
- source: nodes.find((n) => n.id === edge.source),
348
- target: nodes.find((n) => n.id === edge.target),
349
- data: edge.data
350
- })).filter((edge) => edge.source && edge.target);
351
- Object.assign(this._layout, {
352
- graph: {
353
- nodes,
354
- edges
355
- }
356
- });
357
- }
358
- async onClear() {
359
- this.reset();
360
- }
361
- };
362
- var forcePoint = ({ x, y, strength = 0.01 }) => {
363
- const fx = x != null ? (0, import_d34.forceX)(x).strength(strength) : void 0;
364
- const fy = y != null ? (0, import_d34.forceY)(y).strength(strength) : void 0;
365
- const force = (alpha) => {
366
- fx?.(alpha);
367
- fy?.(alpha);
368
- };
369
- force.initialize = (nodes, random) => {
370
- fx?.initialize(nodes, random);
371
- fy?.initialize(nodes, random);
372
- };
373
- return force;
374
- };
375
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
376
- var getValue = (valueOrFunction, invoker, defaultValue) => {
377
- return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
378
- };
379
- var maybeForce = (options, cb, defaultValue = void 0) => {
380
- const value = typeof options === "boolean" ? options ? {} : void 0 : options ?? defaultValue;
381
- if (value) {
382
- return cb(value);
383
- }
384
- };
385
- var defaultForceOptions = {
386
- link: true,
387
- manyBody: true,
388
- // center: true,
389
- point: true
390
- };
391
- var GraphForceProjector = class extends GraphProjector {
392
- constructor() {
393
- super(...arguments);
394
- this._simulation = (0, import_d33.forceSimulation)();
395
- }
396
- get forces() {
397
- return this.options.forces ?? defaultForceOptions;
398
- }
399
- get simulation() {
400
- return this._simulation;
401
- }
402
- restart() {
403
- this._simulation.alpha(1).restart();
404
- }
405
- findNode(x, y, radius) {
406
- return this._simulation.find(x, y, radius);
407
- }
408
- async onStart() {
409
- clearTimeout(this._timeout);
410
- let propagating = true;
411
- const { radial, ...forces } = this.forces;
412
- const delay = typeof radial === "object" ? radial.delay : void 0;
413
- if (delay) {
414
- propagating = false;
415
- this.updateForces(forces);
416
- this._timeout = setTimeout(() => {
417
- this.updateForces(this.forces);
418
- this.restart();
419
- this._timeout = setTimeout(() => {
420
- propagating = true;
421
- }, delay);
422
- }, delay);
423
- } else {
424
- this.updateForces(this.forces);
425
- }
426
- this._simulation.on("tick", () => propagating && this.emitUpdate()).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
427
- }
428
- async onStop() {
429
- clearTimeout(this._timeout);
430
- this._simulation.stop();
431
- }
432
- onRefresh(dragging = false) {
433
- if (this.forces.center) {
434
- if (dragging) {
435
- this._simulation.force("center", null);
436
- } else {
437
- this.updateForces(this.forces);
438
- }
439
- }
440
- this.restart();
441
- }
442
- onUpdate(graph) {
443
- (0, import_log2.log)("onUpdate", {
444
- graph: {
445
- nodes: graph?.nodes.length,
446
- edges: graph?.edges.length
447
- }
448
- }, {
449
- F: __dxlog_file2,
450
- L: 226,
451
- S: this,
452
- C: (f, a) => f(...a)
453
- });
454
- this._simulation.stop();
455
- this.mergeData(graph);
456
- this.updateLayout();
457
- this.updateForces(this.forces);
458
- this.restart();
459
- }
460
- updateLayout() {
461
- this.layout.guides = this.options.guides ? [
462
- {
463
- id: "g-1",
464
- type: "circle",
465
- cx: 0,
466
- cy: 0,
467
- r: this.context.scale.model.toValue([
468
- 10,
469
- 1
470
- ])
471
- }
472
- ] : void 0;
473
- this.layout.graph.nodes.forEach((node) => {
474
- if (!node.initialized) {
475
- const a = 2 * Math.PI * Math.random();
476
- const r = this.options.radius ?? 200;
477
- Object.assign(node, {
478
- initialized: true,
479
- // TODO(burdon): Only when new nodes added to initial layout.
480
- // Position around center or parent; must have delta to avoid spike.
481
- // x: edge?.source?.x ?? Math.cos(a) * r,
482
- // y: edge?.source?.y ?? Math.sin(a) * r,
483
- x: Math.cos(a) * r,
484
- y: Math.sin(a) * r
485
- });
486
- }
487
- Object.assign(node, {
488
- r: getValue(this.options?.attributes?.radius, (fn) => fn(node, this.numChildren(node)), 6)
489
- });
490
- });
491
- this.layout.graph.edges.forEach((edge) => {
492
- Object.assign(edge, {
493
- linkForce: getValue(this.options.attributes?.linkForce, (fn) => fn(edge), true)
494
- });
495
- });
496
- }
497
- /**
498
- * Update all forces.
499
- */
500
- updateForces(forces) {
501
- (0, import_log2.log)("updateForces", {
502
- forces
503
- }, {
504
- F: __dxlog_file2,
505
- L: 287,
506
- S: this,
507
- C: (f, a) => f(...a)
508
- });
509
- this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
510
- const force = (0, import_d33.forceLink)().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
511
- if (config.distance != null) {
512
- force.distance(config.distance);
513
- }
514
- if (config.strength != null) {
515
- force.strength(config.strength);
516
- }
517
- if (config.iterations != null) {
518
- force.iterations(config.iterations);
519
- }
520
- return force;
521
- }, forces?.link === false ? void 0 : {})).force("manyBody", maybeForce(forces?.manyBody, (config) => {
522
- const force = (0, import_d33.forceManyBody)();
523
- if (config.distanceMax != null) {
524
- force.distanceMax(config.distanceMax);
525
- }
526
- if (config.strength != null) {
527
- force.strength(config.strength);
528
- }
529
- return force;
530
- }, forces?.manyBody === false ? void 0 : {})).force("collide", maybeForce(forces?.collide, (config) => {
531
- const force = (0, import_d33.forceCollide)();
532
- force.radius(config.radius ?? 8);
533
- if (config.strength != null) {
534
- force.strength(config.strength);
535
- }
536
- return force;
537
- })).force("radial", maybeForce(forces?.radial, (config) => {
538
- const force = (0, import_d33.forceRadial)(config.radius ?? 100, config.x ?? 0, config.y ?? 0);
539
- if (config.strength != null) {
540
- force.strength(config.strength);
541
- }
542
- return force;
543
- })).force("center", maybeForce(forces?.center, (config) => {
544
- const force = (0, import_d33.forceCenter)().x(config.x ?? 0).y(config.y ?? 0);
545
- if (config.strength != null) {
546
- force.strength(config.strength);
547
- }
548
- return force;
549
- })).force("point", maybeForce(forces?.point, ({ x = 0, y = 0, strength }) => {
550
- return forcePoint({
551
- x,
552
- y,
553
- strength
554
- });
555
- })).force("x", maybeForce(forces?.x, (config) => {
556
- const force = (0, import_d33.forceX)(config.x ?? 0);
557
- if (config.strength != null) {
558
- force.strength(config.strength);
559
- }
560
- return force;
561
- })).force("y", maybeForce(forces?.y, (config) => {
562
- const force = (0, import_d33.forceY)(config.y ?? 0);
563
- if (config.strength != null) {
564
- force.strength(config.strength);
565
- }
566
- return force;
567
- }));
568
- }
569
- };
570
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
571
- var GraphRadialProjector = class extends GraphProjector {
572
- findNode(x, y, radius) {
573
- return void 0;
574
- }
575
- onUpdate(graph) {
576
- (0, import_log4.log)("onUpdate", {
577
- graph: {
578
- nodes: graph?.nodes.length,
579
- edges: graph?.edges.length
580
- }
581
- }, {
582
- F: __dxlog_file3,
583
- L: 31,
584
- S: this,
585
- C: (f, a) => f(...a)
586
- });
587
- this.mergeData(graph);
588
- this.doRadialLayout();
589
- }
590
- animate() {
591
- const start = Date.now();
592
- if (this.options.duration) {
593
- this._timer = (0, import_d35.timer)(() => {
594
- const t = Math.min(1, (Date.now() - start) / this.options.duration);
595
- const d = (0, import_d35.easeCubic)(t);
596
- this.layout.graph.nodes.forEach((node) => {
597
- node.x = node.sx + (node.tx - node.sx) * d;
598
- node.y = node.sy + (node.ty - node.sy) * d;
599
- node.r = node.sr + (node.tr - node.sr) * d;
600
- });
601
- this.emitUpdate();
602
- if (t >= 1) {
603
- this._timer.stop();
604
- this._timer = void 0;
605
- }
606
- });
607
- } else {
608
- this.emitUpdate();
609
- }
610
- }
611
- async onStop() {
612
- this._timer?.stop();
613
- this._timer = void 0;
614
- }
615
- doRadialLayout() {
616
- if (!this.context.size) {
617
- return;
618
- }
619
- const radial = layoutRadial(0, 0, this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80), this.layout.graph.nodes.length);
620
- this.layout.graph.nodes.forEach((node, i) => {
621
- const [tx, ty] = radial(i);
622
- updateNode(node, [
623
- tx,
624
- ty
625
- ]);
626
- });
627
- this.animate();
628
- }
629
- };
630
- var updateNode = (node, [tx, ty], tr = 8) => {
631
- const sx = node.x ?? tx;
632
- const sy = node.y ?? ty;
633
- const sr = node.r ?? tr;
634
- Object.assign(node, {
635
- initialized: true,
636
- // Start.
637
- sx,
638
- sy,
639
- sr,
640
- // Target.
641
- tx,
642
- ty,
643
- tr,
644
- // Current.
645
- x: sx,
646
- y: sy,
647
- r: sr
648
- });
649
- };
650
- var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
651
- const da = 2 * Math.PI / n;
652
- return (i) => {
653
- const a = start + i * da;
654
- return [
655
- x + Math.cos(a) * r,
656
- y + Math.sin(a) * r
657
- ];
658
- };
659
- };
660
- var layoutHorizontal = (x, y, w, n) => {
661
- const dx = n > 1 ? w / (n - 1) : 0;
662
- const sx = x - (n - 1) * dx / 2;
663
- return (i) => {
664
- return [
665
- sx + i * dx,
666
- y
667
- ];
668
- };
669
- };
670
- var layoutVertical = (x, y, h, n) => {
671
- const dy = n > 1 ? h / (n - 1) : 0;
672
- const sy = y - (n - 1) * dy / 2;
673
- return (i) => {
674
- return [
675
- x,
676
- sy + i * dy
677
- ];
678
- };
679
- };
680
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
681
- var GraphHierarchicalProjector = class extends GraphRadialProjector {
682
- onUpdate(graph) {
683
- (0, import_log3.log)("onUpdate", {
684
- graph: {
685
- nodes: graph?.nodes.length,
686
- edges: graph?.edges.length
687
- },
688
- selection: this.selection?.selected.value
689
- }, {
690
- F: __dxlog_file4,
691
- L: 23,
692
- S: this,
693
- C: (f, a) => f(...a)
694
- });
695
- this.mergeData(graph);
696
- const selected = this.selection?.selected.value?.[0];
697
- if (selected) {
698
- const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
699
- if (node) {
700
- this.doHierarchicalLayout(node);
701
- return;
702
- }
703
- }
704
- this.doRadialLayout();
705
- }
706
- doHierarchicalLayout(selected) {
707
- if (!this.context.size) {
708
- return;
709
- }
710
- const r2 = this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80);
711
- const r1 = r2 / 2;
712
- const children = this.layout.graph.edges.filter((edge) => edge.source.id === selected.id).map((edge) => edge.target);
713
- updateNode(selected, [
714
- 0,
715
- 0
716
- ], 20);
717
- {
718
- const radial = layoutRadial(0, 0, r1, children.length);
719
- children.forEach((node, i) => {
720
- const [tx, ty] = radial(i);
721
- updateNode(node, [
722
- tx,
723
- ty
724
- ]);
725
- });
726
- }
727
- {
728
- const radial = layoutRadial(0, 0, r2, this.layout.graph.nodes.length - 1 - children.length);
729
- this.layout.graph.nodes.filter((node) => node.id !== selected.id && !children.includes(node)).forEach((node, i) => {
730
- const [tx, ty] = radial(i);
731
- updateNode(node, [
732
- tx,
733
- ty
734
- ]);
735
- });
736
- }
737
- this.animate();
738
- }
739
- };
740
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
741
- var GraphRelationalProjector = class extends GraphRadialProjector {
742
- onUpdate(graph) {
743
- (0, import_log5.log)("onUpdate", {
744
- graph: {
745
- nodes: graph?.nodes.length,
746
- edges: graph?.edges.length
747
- },
748
- selection: this.selection?.selected.value
749
- }, {
750
- F: __dxlog_file5,
751
- L: 23,
752
- S: this,
753
- C: (f, a) => f(...a)
754
- });
755
- this.mergeData(graph);
756
- const selected = this.selection?.selected.value?.[0];
757
- if (selected) {
758
- const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
759
- if (node) {
760
- this.doRelationalLayout(node);
761
- return;
762
- }
763
- }
764
- this.doRadialLayout();
765
- }
766
- doRelationalLayout(selected) {
767
- if (!this.context.size) {
768
- return;
769
- }
770
- const r2 = this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80);
771
- const r1 = r2 * 0.5;
772
- this.layout.graph.nodes.forEach((node) => node.type = void 0);
773
- this.layout.graph.edges.forEach((edge) => {
774
- edge.order = 0;
775
- edge.type = void 0;
776
- });
777
- const children = this.layout.graph.edges.filter((edge) => edge.source.id === selected.id).map((edge) => {
778
- edge.order = 1;
779
- edge.type = "1";
780
- edge.target.type = "1";
781
- return edge.target;
782
- });
783
- const parents = this.layout.graph.edges.filter((edge) => edge.target.id === selected.id).map((edge) => {
784
- edge.order = 2;
785
- edge.type = "2";
786
- edge.source.type = "2";
787
- return edge.source;
788
- });
789
- updateNode(selected, [
790
- 0,
791
- 0
792
- ], 30);
793
- {
794
- const vertical = layoutHorizontal(0, r1, r1 * 2, children.length);
795
- children.forEach((node, i) => {
796
- const [tx, ty] = vertical(i);
797
- updateNode(node, [
798
- tx,
799
- ty
800
- ], 20);
801
- });
802
- }
803
- {
804
- const vertical = layoutHorizontal(0, -r1, r1, parents.length);
805
- parents.forEach((node, i) => {
806
- const [tx, ty] = vertical(i);
807
- updateNode(node, [
808
- tx,
809
- ty
810
- ], 20);
811
- });
812
- }
813
- {
814
- const radial = layoutRadial(0, 0, r2, this.layout.graph.nodes.length - 1 - children.length - parents.length);
815
- this.layout.graph.nodes.filter((node) => node.id !== selected.id && !children.includes(node) && !parents.includes(node)).forEach((node, i) => {
816
- const [tx, ty] = radial(i);
817
- updateNode(node, [
818
- tx,
819
- ty
820
- ]);
821
- });
822
- }
823
- this.animate();
824
- }
825
- };
826
- var createBullets = (group, nodeId, options = {}) => {
827
- return (selection) => {
828
- const { max = 32, radius = 3, delay = 50, minDuration = 100, maxDuration = 500 } = options;
829
- selection.each(function(d, i, edges) {
830
- const { source, target } = d;
831
- if (source.id === nodeId) {
832
- const path = (0, import_d37.select)(edges[i]);
833
- const p = path.node().getPointAtLength(0);
834
- const bullet = (0, import_d37.select)(group).append("circle").attr("class", "dx-bullet").attr("cx", p.x).attr("cy", p.y).attr("r", radius);
835
- bullet.transition().delay(delay).duration(minDuration + Math.random() * maxDuration).ease(import_d37.easeLinear).tween("pathTween", function() {
836
- const length = path.node().getTotalLength();
837
- const r = (0, import_d37.interpolate)(0, length);
838
- return (t) => {
839
- const point = path.node().getPointAtLength(r(t));
840
- (0, import_d37.select)(this).attr("cx", point.x).attr("cy", point.y);
841
- };
842
- }).on("end", function() {
843
- (0, import_d37.select)(this).remove();
844
- const num = (0, import_d37.select)(group).selectAll("circle.dx-bullet").size();
845
- if (num < max) {
846
- selection.call(createBullets(group, target.id));
847
- }
848
- });
849
- }
850
- });
851
- };
852
- };
853
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
854
- var Renderer = class {
855
- constructor(_context, _root, options) {
856
- this._context = _context;
857
- this._root = _root;
858
- this._options = Object.assign({
859
- idAccessor: defaultIdAccessor
860
- }, options);
861
- }
862
- get context() {
863
- return this._context;
864
- }
865
- get root() {
866
- (0, import_invariant2.invariant)(this._root.current, "SVG root is not initialized", {
867
- F: __dxlog_file6,
868
- L: 40,
869
- S: this,
870
- A: [
871
- "this._root.current",
872
- "'SVG root is not initialized'"
873
- ]
874
- });
875
- return this._root.current;
876
- }
877
- get options() {
878
- return this._options;
879
- }
880
- };
881
- var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
882
- var createLine2 = (0, import_d36.line)();
883
- var GraphRenderer = class extends Renderer {
884
- render(layout) {
885
- (0, import_log6.log)("render", layout, {
886
- F: __dxlog_file7,
887
- L: 62,
888
- S: this,
889
- C: (f, a) => f(...a)
890
- });
891
- const root = (0, import_d36.select)(this.root);
892
- if (layout.guides) {
893
- root.selectAll("g.dx-guides").data([
894
- {
895
- id: "guides"
896
- }
897
- ]).join("g").classed("dx-guides", true).selectAll("circle").data(layout.guides ?? []).join((enter) => enter.append("circle").attr("r", 0), (update) => update, (exit) => exit.transition().duration(500).attr("r", 0).remove()).attr("cx", (d) => d.cx).attr("cy", (d) => d.cy).attr("r", (d) => d.r);
898
- }
899
- const scale = 100;
900
- const offsetDistance = 24 * scale;
901
- if (this._options.subgraphs) {
902
- const components = this._options.subgraphs ? findConnectedComponents({
903
- nodes: layout.graph?.nodes ?? [],
904
- edges: (layout.graph?.edges ?? []).map(({ source, target }) => ({
905
- source: source.id,
906
- target: target.id
907
- }))
908
- }).filter((component) => component.length > 2).map((component, i) => ({
909
- id: `subgraph-${i}`,
910
- component
911
- })) : [];
912
- root.selectAll("g.dx-subgraphs").data([
913
- {
914
- id: "subgraphs"
915
- }
916
- ]).join("g").classed("dx-subgraphs", true).selectAll("path").data(components).join((enter) => enter.append("path").classed("dx-subgraph", true), (update) => {
917
- return update.attr("d", ({ component }) => {
918
- const points = layout.graph?.nodes.filter((node) => component.includes(node.id)).map((node) => [
919
- node.x,
920
- node.y
921
- ]) ?? [];
922
- const hullPoints = (0, import_d36.polygonHull)(points);
923
- const co = new Clipper.ClipperOffset();
924
- const solution = [];
925
- const clipperPath = hullPoints.map(([x, y]) => ({
926
- X: x * scale,
927
- Y: y * scale
928
- }));
929
- co.AddPath(clipperPath, Clipper.JoinType.jtRound, Clipper.EndType.etClosedPolygon);
930
- co.Execute(solution, offsetDistance);
931
- if (solution.length > 0) {
932
- const offset = solution[0].map(({ X, Y }) => [
933
- X / scale,
934
- Y / scale
935
- ]);
936
- return createLine2([
937
- ...offset,
938
- offset[0]
939
- ]);
940
- }
941
- });
942
- });
943
- }
944
- const edgeGroup = root.selectAll("g.dx-edges").data([
945
- {
946
- id: "edges"
947
- }
948
- ], (d) => d.id).join("g").classed("dx-edges", true);
949
- const nodeGroup = root.selectAll("g.dx-nodes").data([
950
- {
951
- id: "nodes"
952
- }
953
- ], (d) => d.id).join("g").classed("dx-nodes", true);
954
- nodeGroup.selectAll("g.dx-node").data(layout.graph?.nodes ?? [], (d) => d.id).join((enter) => enter.append("g").attr("data-id", (d) => d.id).attr("opacity", 1).classed("dx-node", true).call(createNode, this.options), (update) => update.call(updateNode2, this.options), (exit) => {
955
- return exit.transition().ease(import_d36.easeCubicOut).duration(300).attr("opacity", 0).on("end", function(d) {
956
- (0, import_d36.select)(this).remove();
957
- });
958
- }).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
959
- edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join((enter) => enter.append("g").attr("data-id", (d) => d.id).classed("dx-edge", true).call(createEdge, this.options), (update) => update.call(updateEdge, this.options, nodeGroup).each((d) => {
960
- }), (exit) => exit.remove()).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
961
- }
962
- /**
963
- * Trigger path bullets.
964
- * @param node
965
- */
966
- fireBullet(node) {
967
- (0, import_d36.select)(this.root).selectAll("g.dx-edges").selectAll("path").call(createBullets(this.root, node.id));
968
- }
969
- };
970
- var createNode = (group, options) => {
971
- const circle = group.append("circle");
972
- if (options.drag) {
973
- circle.call(options.drag);
974
- }
975
- if (options.onNodeClick) {
976
- group.on("click", (event) => {
977
- const node = (0, import_d36.select)(event.target).datum();
978
- options.onNodeClick(node, event);
979
- });
980
- }
981
- if (options.labels && !options.onNodePointerEnter) {
982
- const g = group.append("g").classed("dx-label", true);
983
- g.append("line");
984
- g.append("rect");
985
- g.append("text").style("dominant-baseline", "middle");
986
- }
987
- if (options.onNodePointerEnter) {
988
- circle.on("pointerenter", function(event) {
989
- const node = (0, import_d36.select)(this.parentElement).datum();
990
- options.onNodePointerEnter(node, event);
991
- });
992
- group.attr("data-hover", "handled");
993
- } else if (options.highlight !== false) {
994
- circle.on("pointerenter", function() {
995
- (0, import_d36.select)(this.closest("g.dx-node")).raise();
996
- if (options.labels) {
997
- (0, import_d36.select)(this.parentElement).classed("dx-active", true).classed("dx-highlight", true);
998
- }
999
- });
1000
- group.on("pointerleave", function() {
1001
- if (options.labels) {
1002
- (0, import_d36.select)(this).classed("dx-active", false);
1003
- setTimeout(() => {
1004
- if (!(0, import_d36.select)(this).classed("dx-active")) {
1005
- (0, import_d36.select)(this).classed("dx-highlight", false);
1006
- }
1007
- }, 300);
1008
- }
1009
- });
1010
- }
1011
- };
1012
- var updateNode2 = (group, options) => {
1013
- group.attr("transform", (d) => {
1014
- return d.x != null && d.y != null ? `translate(${d.x},${d.y})` : void 0;
1015
- });
1016
- if (options.attributes?.node) {
1017
- try {
1018
- group.each((d, i, nodes) => {
1019
- const node = (0, import_d36.select)(nodes[i]);
1020
- const { classes, data } = options.attributes?.node?.(d) ?? {};
1021
- if (classes) {
1022
- applyClasses(node, classes);
1023
- }
1024
- if (data) {
1025
- Object.entries(data).forEach(([key, value]) => {
1026
- node.attr(`data-${key}`, value);
1027
- });
1028
- }
1029
- });
1030
- } catch (error) {
1031
- import_log6.log.error("updateNode", {
1032
- error: error?.message
1033
- }, {
1034
- F: __dxlog_file7,
1035
- L: 304,
1036
- S: void 0,
1037
- C: (f, a) => f(...a)
1038
- });
1039
- }
1040
- }
1041
- const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
1042
- groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
1043
- if (options.labels) {
1044
- const bx = 1;
1045
- const px = 4;
1046
- const py = 2;
1047
- const offset = 16;
1048
- const dx = (d, offset2 = 0) => (offset2 + (d.r ?? 0)) * (d.x > 0 ? 1 : -1);
1049
- groupOrTransition.select("text").text((d) => options.labels.text(d)).style("text-anchor", (d) => d.x > 0 ? "start" : "end").attr("dx", (d) => dx(d, offset)).attr("dy", 1).text((d) => options.labels.text(d)).each(function(d) {
1050
- let bbox = d.bbox;
1051
- if (!bbox) {
1052
- bbox = this.getBBox();
1053
- d.bbox = bbox;
1054
- }
1055
- const width = bbox.width + (bx + px) * 2;
1056
- const height = bbox.height + py * 2;
1057
- (0, import_d36.select)(this.parentElement).select("rect").attr("x", dx(d, offset - (bx + px)) + (d.x > 0 ? 0 : -1) * width).attr("y", -height / 2).attr("width", width).attr("height", height).attr("rx", 4);
1058
- (0, import_d36.select)(this.parentElement).select("line").attr("x1", dx(d, 1)).attr("y1", 0).attr("x2", dx(d, offset - (bx + px))).attr("y2", 0);
1059
- });
1060
- }
1061
- };
1062
- var createEdge = (group, options) => {
1063
- if (options.onLinkClick) {
1064
- group.append("path").classed("dx-click", true).on("click", (event) => {
1065
- const edge = (0, import_d36.select)(event.target).datum();
1066
- options.onLinkClick(edge, event);
1067
- });
1068
- }
1069
- group.append("path").attr("pointer-events", "none").attr("marker-start", () => options.arrows?.start ? "url(#marker-arrow-start)" : void 0).attr("marker-end", () => options.arrows?.end ? "url(#marker-arrow-end)" : void 0);
1070
- };
1071
- var updateEdge = (group, options, nodeGroup) => {
1072
- try {
1073
- group.each((d, i, edges) => {
1074
- const edge = (0, import_d36.select)(edges[i]);
1075
- edge.classed("dx-dashed", d.linkForce === false);
1076
- const { classes, data } = options.attributes?.edge?.(d) ?? {};
1077
- if (classes) {
1078
- applyClasses(edge, classes);
1079
- }
1080
- if (data) {
1081
- Object.entries(data).forEach(([key, value]) => {
1082
- edge.attr(`data-${key}`, value);
1083
- });
1084
- }
1085
- });
1086
- } catch (error) {
1087
- import_log6.log.error("updateEdge", {
1088
- error: error?.message
1089
- }, {
1090
- F: __dxlog_file7,
1091
- L: 416,
1092
- S: void 0,
1093
- C: (f, a) => f(...a)
1094
- });
1095
- }
1096
- const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
1097
- groupOrTransition.selectAll("path").attr("d", function() {
1098
- const { source, target } = (0, import_d36.select)(this.parentElement).datum();
1099
- if (!source.initialized || !target.initialized) {
1100
- return;
1101
- }
1102
- return createLine2((0, import_chunk_WFHWEMPB.getCircumferencePoints)([
1103
- source.x,
1104
- source.y
1105
- ], [
1106
- target.x,
1107
- target.y
1108
- ], source.r, target.r));
1109
- });
1110
- };
1111
- var applyClasses = (el, classes) => {
1112
- for (const [className, value] of Object.entries(classes)) {
1113
- el.classed(className, value);
1114
- }
1115
- };
1116
- var findConnectedComponents = (graph) => {
1117
- const adj = {};
1118
- for (const node of graph.nodes) {
1119
- adj[node.id] = [];
1120
- }
1121
- for (const { source, target } of graph.edges) {
1122
- adj[source].push(target);
1123
- adj[target].push(source);
1124
- }
1125
- const visited = /* @__PURE__ */ new Set();
1126
- const components = [];
1127
- for (const node of graph.nodes) {
1128
- if (visited.has(node.id)) {
1129
- continue;
1130
- }
1131
- const stack = [
1132
- node.id
1133
- ];
1134
- const componentIds = [];
1135
- while (stack.length) {
1136
- const current = stack.pop();
1137
- if (visited.has(current)) {
1138
- continue;
1139
- }
1140
- visited.add(current);
1141
- componentIds.push(current);
1142
- stack.push(...adj[current]);
1143
- }
1144
- components.push(componentIds);
1145
- }
1146
- return components;
1147
- };
1148
- var createLine3 = (0, import_d38.line)();
1149
- var linkerRenderer = (root, { source, target, point } = {}) => {
1150
- root.selectAll("g.dx-linker").data([
1151
- {
1152
- id: "linker"
1153
- }
1154
- ]).join("g").attr("class", "dx-linker").selectAll("path").data(source ? [
1155
- {
1156
- id: "edge"
1157
- }
1158
- ] : []).join("path").attr("marker-end", () => target ? "url(#marker-arrow-end)" : "url(#marker-dot)").attr("d", () => {
1159
- return createLine3((0, import_chunk_WFHWEMPB.getCircumferencePoints)([
1160
- source.x,
1161
- source.y
1162
- ], target ? [
1163
- target.x,
1164
- target.y
1165
- ] : point, source.r, target ? target.r : 0));
1166
- });
1167
- };
1168
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
1169
- var GraphInner = ({ classNames, model, projector: _projector, renderer: _renderer, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
1170
- var _effect = (0, import_tracking.useSignals)();
1171
- try {
1172
- const context = (0, import_chunk_WFHWEMPB.useSvgContext)();
1173
- const graphRef = (0, import_react.useRef)();
1174
- const { projector, renderer } = (0, import_react.useMemo)(() => {
1175
- let projector2 = _projector;
1176
- if (!projector2) {
1177
- projector2 = new GraphForceProjector(context);
1178
- }
1179
- let renderer2 = _renderer;
1180
- if (!renderer2) {
1181
- renderer2 = new GraphRenderer(context, graphRef, {
1182
- ...props,
1183
- // TODO(burdon): Replace drag when projector is updated.
1184
- drag: drag2 ? createGraphDrag(context, projector2) : void 0,
1185
- arrows: {
1186
- end: arrows
1187
- },
1188
- onNodeClick: onSelect ? (node, event) => onSelect(node, event) : void 0,
1189
- onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
1190
- });
1191
- }
1192
- return {
1193
- projector: projector2,
1194
- renderer: renderer2
1195
- };
1196
- }, [
1197
- context,
1198
- _projector,
1199
- _renderer,
1200
- drag2
1201
- ]);
1202
- (0, import_react.useImperativeHandle)(forwardedRef, () => ({
1203
- refresh: () => {
1204
- projector.updateData(model?.graph);
1205
- },
1206
- repaint: () => {
1207
- renderer.render(projector.layout);
1208
- },
1209
- findNode: (id) => {
1210
- return graphRef.current?.querySelector(`g[data-id="${id}"]`);
1211
- }
1212
- }), [
1213
- model,
1214
- projector,
1215
- renderer
1216
- ]);
1217
- (0, import_react.useEffect)(() => {
1218
- return (0, import_async.combine)((0, import_signals_core.effect)(() => {
1219
- projector.updateData(model?.graph);
1220
- }), projector.updated.on(({ layout }) => {
1221
- try {
1222
- renderer.render(layout);
1223
- } catch (error) {
1224
- void projector.stop();
1225
- import_log.log.catch(error, void 0, {
1226
- F: __dxlog_file8,
1227
- L: 108,
1228
- S: void 0,
1229
- C: (f, a) => f(...a)
1230
- });
1231
- }
1232
- }));
1233
- }, [
1234
- model,
1235
- projector,
1236
- renderer
1237
- ]);
1238
- (0, import_react.useEffect)(() => {
1239
- void projector.start();
1240
- return () => {
1241
- void projector.stop();
1242
- };
1243
- }, [
1244
- projector
1245
- ]);
1246
- return /* @__PURE__ */ import_react.default.createElement("g", {
1247
- ref: graphRef,
1248
- className: (0, import_react_ui_theme.mx)("dx-graph", classNames)
1249
- });
1250
- } finally {
1251
- _effect.f();
1252
- }
1253
- };
1254
- var Graph = /* @__PURE__ */ (0, import_react.forwardRef)(GraphInner);
1255
- var Mesh = ({ radius = 16, value = 0.5 }) => {
1256
- const { svg, size } = (0, import_chunk_WFHWEMPB.useSvgContext)();
1257
- (0, import_react2.useEffect)(() => {
1258
- if (size) {
1259
- const topology = hexTopology(size, radius, value);
1260
- const projection = hexProjection(radius);
1261
- const path = (0, import_d39.geoPath)().projection(projection);
1262
- (0, import_d39.select)(svg).append("g").attr("class", "hexagon").selectAll("path").data(topology.objects.hexagons.geometries).enter().append("path").attr("d", (d) => path((0, import_topojson_client.feature)(topology, d))).attr("class", (d) => d.properties?.fill ? "fill" : null);
1263
- (0, import_d39.select)(svg).append("path").datum((0, import_topojson_client.mesh)(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
1264
- const redraw = (border) => {
1265
- border.attr("d", path((0, import_topojson_client.mesh)(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
1266
- };
1267
- (0, import_d39.select)(svg).append("path").attr("class", "border").call(redraw);
1268
- }
1269
- }, [
1270
- svg,
1271
- size,
1272
- value
1273
- ]);
1274
- return null;
1275
- };
1276
- var hexTopology = ({ width, height }, radius, value = 1) => {
1277
- const dx = radius * 2 * Math.sin(Math.PI / 3);
1278
- const dy = radius * 1.5;
1279
- const m = Math.ceil((height + radius) / dy) + 1;
1280
- const n = Math.ceil(width / dx) + 1;
1281
- const geometries = [];
1282
- const arcs = [];
1283
- for (let j = -1; j <= m; ++j) {
1284
- for (let i = -1; i <= n; ++i) {
1285
- const y = j * 2;
1286
- const x = (i + (j & 1) / 2) * 2;
1287
- arcs.push([
1288
- [
1289
- x,
1290
- y - 1
1291
- ],
1292
- [
1293
- 1,
1294
- 1
1295
- ]
1296
- ], [
1297
- [
1298
- x + 1,
1299
- y
1300
- ],
1301
- [
1302
- 0,
1303
- 1
1304
- ]
1305
- ], [
1306
- [
1307
- x + 1,
1308
- y + 1
1309
- ],
1310
- [
1311
- -1,
1312
- 1
1313
- ]
1314
- ]);
1315
- }
1316
- }
1317
- for (let j = 0, q = 3; j < m; ++j, q += 6) {
1318
- for (let i = 0; i < n; ++i, q += 3) {
1319
- geometries.push({
1320
- type: "Polygon",
1321
- arcs: [
1322
- [
1323
- q,
1324
- q + 1,
1325
- q + 2,
1326
- ~(q + (n + 2 - (j & 1)) * 3),
1327
- ~(q - 2),
1328
- ~(q - (n + 2 + (j & 1)) * 3 + 2)
1329
- ]
1330
- ],
1331
- properties: {
1332
- fill: Math.random() > i / n * (1 / value)
1333
- }
1334
- });
1335
- }
1336
- }
1337
- const hexagons = {
1338
- type: "GeometryCollection",
1339
- geometries
1340
- };
1341
- return {
1342
- type: "Topology",
1343
- transform: {
1344
- translate: [
1345
- 0,
1346
- 0
1347
- ],
1348
- scale: [
1349
- 1,
1350
- 1
1351
- ]
1352
- },
1353
- objects: {
1354
- hexagons
1355
- },
1356
- arcs
1357
- };
1358
- };
1359
- var hexProjection = (radius) => {
1360
- const dx = radius * 2 * Math.sin(Math.PI / 3);
1361
- const dy = radius * 1.5;
1362
- return {
1363
- stream: (stream) => ({
1364
- point: (x, y) => {
1365
- stream.point(x * dx / 2, (y - (2 - (y & 1)) / 3) * dy / 2);
1366
- },
1367
- lineStart: () => {
1368
- stream.lineStart();
1369
- },
1370
- lineEnd: () => {
1371
- stream.lineEnd();
1372
- },
1373
- polygonStart: () => {
1374
- stream.polygonStart();
1375
- },
1376
- polygonEnd: () => {
1377
- stream.polygonEnd();
1378
- }
1379
- })
1380
- };
1381
- };
1382
- var Grid = ({ classNames, ...props }) => {
1383
- var _effect = (0, import_tracking2.useSignals)();
1384
- try {
1385
- const { ref } = (0, import_chunk_WFHWEMPB.useGrid)(props);
1386
- return /* @__PURE__ */ import_react3.default.createElement("g", {
1387
- ref,
1388
- className: (0, import_react_ui_theme2.mx)("dx-grid", classNames)
1389
- });
1390
- } finally {
1391
- _effect.f();
1392
- }
1393
- };
1394
- var Markers = ({ arrowSize, className }) => {
1395
- var _effect = (0, import_tracking3.useSignals)();
1396
- try {
1397
- const ref = (0, import_react4.useRef)();
1398
- (0, import_react4.useEffect)(() => {
1399
- (0, import_d310.select)(ref.current).call(createMarkers({
1400
- arrowSize
1401
- }));
1402
- }, [
1403
- ref
1404
- ]);
1405
- return /* @__PURE__ */ import_react4.default.createElement("defs", {
1406
- ref,
1407
- className
1408
- });
1409
- } finally {
1410
- _effect.f();
1411
- }
1412
- };
1413
- var Root = /* @__PURE__ */ (0, import_react5.forwardRef)(({ classNames, children, ...props }, ref) => {
1414
- var _effect = (0, import_tracking4.useSignals)();
1415
- try {
1416
- const { ref: containerRef, width = 0, height = 0 } = (0, import_react_resize_detector.useResizeDetector)({
1417
- refreshRate: 200
1418
- });
1419
- const context = (0, import_react5.useMemo)(() => {
1420
- return new import_chunk_WFHWEMPB.SVGContext(props);
1421
- }, [
1422
- props.scale,
1423
- props.centered
1424
- ]);
1425
- (0, import_react5.useImperativeHandle)(ref, () => context, [
1426
- context
1427
- ]);
1428
- (0, import_react5.useEffect)(() => {
1429
- if (width && height) {
1430
- context.setSize({
1431
- width,
1432
- height
1433
- });
1434
- (0, import_d311.select)(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
1435
- }
1436
- }, [
1437
- context,
1438
- width,
1439
- height
1440
- ]);
1441
- const ready = width !== 0 && height !== 0;
1442
- return /* @__PURE__ */ import_react5.default.createElement(import_chunk_WFHWEMPB.SVGContextProvider, {
1443
- value: context
1444
- }, /* @__PURE__ */ import_react5.default.createElement("div", {
1445
- ref: containerRef,
1446
- className: (0, import_react_ui_theme3.mx)("grid grow overflow-hidden", classNames)
1447
- }, /* @__PURE__ */ import_react5.default.createElement("svg", {
1448
- xmlns: "http://www.w3.org/2000/svg",
1449
- ref: context.ref,
1450
- className: (0, import_react_ui_theme3.mx)("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
1451
- }, ready && children)));
1452
- } finally {
1453
- _effect.f();
1454
- }
1455
- });
1456
- var Zoom = /* @__PURE__ */ (0, import_react6.memo)(({ extent, className, children }) => {
1457
- var _effect = (0, import_tracking5.useSignals)();
1458
- try {
1459
- const options = (0, import_react6.useMemo)(() => ({
1460
- extent
1461
- }), [
1462
- JSON.stringify(extent)
1463
- ]);
1464
- const zoom = (0, import_chunk_WFHWEMPB.useZoom)(options);
1465
- return /* @__PURE__ */ import_react6.default.createElement("g", {
1466
- ref: zoom.ref,
1467
- className
1468
- }, children);
1469
- } finally {
1470
- _effect.f();
1471
- }
1472
- });
1473
- var SVG = {
1474
- Root,
1475
- Grid,
1476
- Markers,
1477
- Mesh,
1478
- Zoom,
1479
- Graph
1480
- };
1481
- var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
1482
- (function(Pulsar2) {
1483
- Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
1484
- Pulsar2.create = (group, r, options = {}) => {
1485
- const pulsar = group.append("circle").classed("dx-pulsar", true).classed("stroke-2 stroke-red-500 fill-none", true).property(PROP_PULSAR_ACTIVE, true);
1486
- startAnimation(pulsar, r, options);
1487
- };
1488
- Pulsar2.remove = (group) => {
1489
- group.select("circle.dx-pulsar").property(PROP_PULSAR_ACTIVE, false);
1490
- };
1491
- })(Pulsar || (Pulsar = {}));
1492
- var startAnimation = (pulsar, r, options = {}) => {
1493
- const { period = 1e3, duration = 800, ratio = 3 } = options;
1494
- return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(import_d312.easeCubicOut).attr("r", r * ratio).attr("opacity", -0.1).on("end", function() {
1495
- if ((0, import_d312.select)(this).property(PROP_PULSAR_ACTIVE)) {
1496
- startAnimation((0, import_d312.select)(this), r, options);
1497
- } else {
1498
- (0, import_d312.select)(this).remove();
1499
- }
1500
- });
1501
- };
1502
- var Pulsar;
1503
- // Annotate the CommonJS export names for ESM import in node:
1504
- 0 && (module.exports = {
1505
- EventEmitter,
1506
- FractionUtil,
1507
- Graph,
1508
- GraphForceProjector,
1509
- GraphHierarchicalProjector,
1510
- GraphInner,
1511
- GraphProjector,
1512
- GraphRadialProjector,
1513
- GraphRelationalProjector,
1514
- GraphRenderer,
1515
- GridController,
1516
- Mesh,
1517
- Projector,
1518
- Pulsar,
1519
- Renderer,
1520
- SVG,
1521
- SVGContext,
1522
- SVGContextProvider,
1523
- Scale,
1524
- Screen,
1525
- Vector,
1526
- ZoomHandler,
1527
- createGraphDrag,
1528
- createMarkers,
1529
- defaultForceOptions,
1530
- defaultIdAccessor,
1531
- emptyGraph,
1532
- getCircumferencePoints,
1533
- layoutHorizontal,
1534
- layoutRadial,
1535
- layoutVertical,
1536
- linkerRenderer,
1537
- normal,
1538
- offsetPoints,
1539
- updateNode,
1540
- useDynamicRef,
1541
- useGrid,
1542
- useStateRef,
1543
- useSvgContext,
1544
- useTimestamp,
1545
- useZoom
1546
- });
1547
- //# sourceMappingURL=index.cjs.map