@dxos/react-ui-graph 0.8.4-main.ead640a → 0.8.4-main.effb148878
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/LICENSE +102 -5
- 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 +2032 -699
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +16 -16
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs +54 -0
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2032 -699
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +16 -16
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/components/Graph/Graph.d.ts +9 -6
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +6 -6
- 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.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 +8 -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 +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +3 -3
- 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-bundle-projector.d.ts +47 -0
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +60 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts +23 -0
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts +2 -2
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +7 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/index.d.ts +3 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts +10 -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 +21 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/renderer.d.ts +12 -1
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +15 -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 +4 -3
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +5 -5
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts +2 -16
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/testing/model.d.ts +4 -8
- package/dist/types/src/testing/model.d.ts.map +1 -1
- package/dist/types/src/util/events.d.ts.map +1 -1
- package/dist/types/src/util/fraction.d.ts +1 -1
- package/dist/types/src/util/fraction.d.ts.map +1 -1
- package/dist/types/src/util/points.d.ts.map +1 -1
- package/dist/types/src/util/scale.d.ts.map +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -35
- package/src/components/Graph/Graph.stories.tsx +53 -47
- package/src/components/Graph/Graph.tsx +58 -23
- package/src/components/Mesh/Mesh.stories.tsx +8 -7
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Root.tsx +42 -9
- package/src/components/SVG/SVG.tsx +10 -2
- package/src/components/SVG/Svg.stories.tsx +4 -5
- package/src/fx/fx.stories.tsx +7 -8
- package/src/graph/projector/graph-bundle-projector.ts +210 -0
- package/src/graph/projector/graph-cluster-projector.ts +325 -0
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +6 -3
- package/src/graph/projector/graph-hierarchical-projector.ts +4 -4
- package/src/graph/projector/graph-lattice-projector.ts +86 -0
- package/src/graph/projector/graph-projector.ts +9 -3
- package/src/graph/projector/graph-radial-projector.ts +31 -4
- package/src/graph/projector/graph-relational-projector.ts +4 -4
- package/src/graph/projector/index.ts +3 -0
- package/src/graph/projector/projector.ts +12 -3
- package/src/graph/renderer/graph-renderer.ts +175 -30
- package/src/graph/renderer/renderer.ts +15 -4
- package/src/graph/types.ts +15 -1
- package/src/stories/hooks.stories.tsx +21 -10
- package/src/testing/data.ts +14 -14
- package/src/testing/hooks.ts +3 -4
- package/src/testing/model.ts +6 -6
- package/src/util/fraction.ts +1 -1
- package/styles/graph.css +341 -43
- package/dist/lib/browser/chunk-EX2Q43O6.mjs +0 -966
- package/dist/lib/browser/chunk-EX2Q43O6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SWA6OT3W.mjs +0 -968
- package/dist/lib/node-esm/chunk-SWA6OT3W.mjs.map +0 -7
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
EventEmitter,
|
|
3
|
-
FractionUtil,
|
|
4
|
-
GridController,
|
|
5
|
-
SVGContext,
|
|
6
|
-
SVGContextProvider,
|
|
7
|
-
Scale,
|
|
8
|
-
Screen,
|
|
9
|
-
Vector,
|
|
10
|
-
ZoomHandler,
|
|
11
|
-
getCircumferencePoints,
|
|
12
|
-
normal,
|
|
13
|
-
offsetPoints,
|
|
14
2
|
useDynamicRef,
|
|
15
|
-
useGrid,
|
|
16
3
|
useStateRef,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
useZoom
|
|
20
|
-
} from "./chunk-EX2Q43O6.mjs";
|
|
4
|
+
useTimestamp
|
|
5
|
+
} from "./chunk-EASNZZ7B.mjs";
|
|
21
6
|
|
|
22
7
|
// src/components/Graph/Graph.tsx
|
|
23
|
-
import {
|
|
24
|
-
import { effect } from "@preact/signals-core";
|
|
25
|
-
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from "react";
|
|
8
|
+
import React, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo3, useRef as useRef3 } from "react";
|
|
26
9
|
import { combine } from "@dxos/async";
|
|
27
|
-
import { log as
|
|
28
|
-
import { mx } from "@dxos/
|
|
10
|
+
import { log as log9 } from "@dxos/log";
|
|
11
|
+
import { mx } from "@dxos/ui-theme";
|
|
29
12
|
|
|
30
13
|
// src/graph/markers.ts
|
|
31
14
|
import { line, select } from "d3";
|
|
@@ -78,99 +61,19 @@ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
|
|
|
78
61
|
});
|
|
79
62
|
};
|
|
80
63
|
|
|
81
|
-
// src/graph/projector/graph-
|
|
82
|
-
import {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
let mode;
|
|
89
|
-
let source;
|
|
90
|
-
let target;
|
|
91
|
-
let offset;
|
|
92
|
-
let moved = false;
|
|
93
|
-
const keyMod = (event, key) => {
|
|
94
|
-
const modKey = options?.[key] ?? defaultDragOptions[key];
|
|
95
|
-
return modKey === void 0 || event[modKey];
|
|
96
|
-
};
|
|
97
|
-
return drag().filter((event) => !event.ctrlKey).on("start", function(event, d) {
|
|
98
|
-
source = d;
|
|
99
|
-
offset = pointer(event, this.parentElement);
|
|
100
|
-
if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) {
|
|
101
|
-
mode = 1;
|
|
102
|
-
} else if (keyMod(event.sourceEvent, "dragMod")) {
|
|
103
|
-
mode = 0;
|
|
104
|
-
}
|
|
105
|
-
}).on("drag", function(event, d) {
|
|
106
|
-
const parent = this.closest("g.node");
|
|
107
|
-
select2(parent).classed("dragging", true).raise();
|
|
108
|
-
const [dx, dy] = pointer(event, this.parentElement);
|
|
109
|
-
const x = d.x + dx - offset[0];
|
|
110
|
-
const y = d.y + dy - offset[1];
|
|
111
|
-
const point = [
|
|
112
|
-
x,
|
|
113
|
-
y
|
|
114
|
-
];
|
|
115
|
-
switch (mode) {
|
|
116
|
-
case 0: {
|
|
117
|
-
select2(context.svg).attr("cursor", "grabbing");
|
|
118
|
-
event.subject.x = event.subject.fx = point[0];
|
|
119
|
-
event.subject.y = event.subject.fy = point[1];
|
|
120
|
-
projector.refresh(true);
|
|
121
|
-
moved = true;
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
case 1: {
|
|
125
|
-
if (options?.onDrag) {
|
|
126
|
-
target = projector.findNode(event.x, event.y, 16);
|
|
127
|
-
if (source === target) {
|
|
128
|
-
select2(context.svg).attr("cursor", void 0);
|
|
129
|
-
options?.onDrag?.();
|
|
130
|
-
} else {
|
|
131
|
-
select2(context.svg).attr("cursor", target ? "alias" : "cell");
|
|
132
|
-
options?.onDrag?.(source, target, point);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}).on("end", function(event) {
|
|
138
|
-
select2(context.svg).attr("cursor", void 0);
|
|
139
|
-
select2(this.parentElement).classed("dragging", false);
|
|
140
|
-
switch (mode) {
|
|
141
|
-
case 1: {
|
|
142
|
-
options?.onDrop?.(source, target);
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (!keyMod(event.sourceEvent, "freezeMod")) {
|
|
147
|
-
event.subject.fx = null;
|
|
148
|
-
event.subject.fy = null;
|
|
149
|
-
}
|
|
150
|
-
mode = void 0;
|
|
151
|
-
source = void 0;
|
|
152
|
-
target = void 0;
|
|
153
|
-
offset = void 0;
|
|
154
|
-
if (moved) {
|
|
155
|
-
projector.refresh(false);
|
|
156
|
-
moved = false;
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
};
|
|
64
|
+
// src/graph/projector/graph-bundle-projector.ts
|
|
65
|
+
import { cluster as d3Cluster, curveBundle, hierarchy, lineRadial } from "d3";
|
|
66
|
+
import { log as log2 } from "@dxos/log";
|
|
67
|
+
|
|
68
|
+
// src/graph/projector/graph-radial-projector.ts
|
|
69
|
+
import { easeCubic, timer } from "d3";
|
|
70
|
+
import { log } from "@dxos/log";
|
|
160
71
|
|
|
161
72
|
// src/graph/types.ts
|
|
162
73
|
import { invariant } from "@dxos/invariant";
|
|
163
74
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
|
|
164
75
|
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
|
-
});
|
|
76
|
+
invariant(node.id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 10, S: void 0, A: ["node.id", ""] });
|
|
174
77
|
return node.id;
|
|
175
78
|
};
|
|
176
79
|
var emptyGraph = {
|
|
@@ -178,149 +81,1288 @@ var emptyGraph = {
|
|
|
178
81
|
edges: []
|
|
179
82
|
};
|
|
180
83
|
|
|
181
|
-
// src/
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
enumerable: true,
|
|
187
|
-
configurable: true,
|
|
188
|
-
writable: true
|
|
189
|
-
});
|
|
190
|
-
} else {
|
|
191
|
-
obj[key] = value;
|
|
192
|
-
}
|
|
193
|
-
return obj;
|
|
194
|
-
}
|
|
195
|
-
var Projector = class {
|
|
196
|
-
get context() {
|
|
197
|
-
return this._context;
|
|
198
|
-
}
|
|
199
|
-
get options() {
|
|
200
|
-
return this._options;
|
|
201
|
-
}
|
|
202
|
-
refresh(dragging = false) {
|
|
203
|
-
this.onRefresh(dragging);
|
|
204
|
-
}
|
|
205
|
-
updateData(data) {
|
|
206
|
-
this.onUpdate(data);
|
|
207
|
-
}
|
|
208
|
-
emitUpdate() {
|
|
209
|
-
this.updated.emit({
|
|
210
|
-
layout: this.layout
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
async clear() {
|
|
214
|
-
await this.onClear();
|
|
215
|
-
}
|
|
216
|
-
async start() {
|
|
217
|
-
await this.onStart();
|
|
218
|
-
}
|
|
219
|
-
async stop() {
|
|
220
|
-
await this.onStop();
|
|
221
|
-
}
|
|
222
|
-
onRefresh(dragging = false) {
|
|
223
|
-
}
|
|
224
|
-
onUpdate(data) {
|
|
225
|
-
}
|
|
226
|
-
async onClear() {
|
|
84
|
+
// src/util/events.ts
|
|
85
|
+
var EventEmitter = class {
|
|
86
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
87
|
+
clear() {
|
|
88
|
+
this._listeners.clear();
|
|
227
89
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
90
|
+
on(onEvent) {
|
|
91
|
+
this._listeners.add(onEvent);
|
|
92
|
+
return () => this._listeners.delete(onEvent);
|
|
231
93
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
_define_property(this, "updated", void 0);
|
|
235
|
-
_define_property(this, "_options", void 0);
|
|
236
|
-
this._context = _context;
|
|
237
|
-
this.updated = new EventEmitter();
|
|
238
|
-
this._options = Object.assign({
|
|
239
|
-
idAccessor: defaultIdAccessor
|
|
240
|
-
}, options);
|
|
94
|
+
emit(value) {
|
|
95
|
+
this._listeners.forEach((listener) => listener(value));
|
|
241
96
|
}
|
|
242
97
|
};
|
|
243
98
|
|
|
244
|
-
// src/
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
99
|
+
// src/util/fraction.ts
|
|
100
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
101
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/util/fraction.ts";
|
|
102
|
+
var FractionUtil = class _FractionUtil {
|
|
103
|
+
/**
|
|
104
|
+
* Convert number to fraction.
|
|
105
|
+
* @param n
|
|
106
|
+
*/
|
|
107
|
+
static toFraction = (n) => {
|
|
108
|
+
return typeof n === "number" ? [
|
|
109
|
+
n,
|
|
110
|
+
1
|
|
111
|
+
] : n;
|
|
112
|
+
};
|
|
113
|
+
static validate = (...fraction) => {
|
|
114
|
+
fraction.forEach(([n, d]) => {
|
|
115
|
+
if (!Number.isFinite(n) || !Number.isFinite(d) || d === 0) {
|
|
116
|
+
throw new Error(`Invalid fraction: ${n}/${d}`);
|
|
117
|
+
}
|
|
252
118
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
119
|
+
return fraction;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* @param {Fraction}
|
|
123
|
+
* Convert to rounded-sm number.
|
|
124
|
+
*/
|
|
125
|
+
static toNumber = ([n, d]) => {
|
|
126
|
+
_FractionUtil.validate([
|
|
127
|
+
n,
|
|
128
|
+
d
|
|
129
|
+
]);
|
|
130
|
+
return n / d;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Round the number to the nearest fraction.
|
|
134
|
+
* Example: 3/5 => 1/1; 3/5 (precision 2) => 1/2.
|
|
135
|
+
* @param {Fraction}
|
|
136
|
+
* @param p Precision (e.g., 1/2, 1/4, etc.)
|
|
137
|
+
*/
|
|
138
|
+
static round = ([n, d], p = 1) => {
|
|
139
|
+
_FractionUtil.validate([
|
|
140
|
+
n,
|
|
141
|
+
d
|
|
142
|
+
]);
|
|
143
|
+
const v = Math.round(_FractionUtil.toNumber(_FractionUtil.divide([
|
|
144
|
+
n,
|
|
145
|
+
d
|
|
146
|
+
], [
|
|
147
|
+
1,
|
|
148
|
+
p
|
|
149
|
+
])));
|
|
150
|
+
return _FractionUtil.simplify([
|
|
151
|
+
v,
|
|
152
|
+
p
|
|
153
|
+
]);
|
|
154
|
+
};
|
|
155
|
+
//
|
|
156
|
+
// Boolean.
|
|
157
|
+
//
|
|
158
|
+
/**
|
|
159
|
+
* Tests if equals.
|
|
160
|
+
* @param n1
|
|
161
|
+
* @param n2
|
|
162
|
+
*/
|
|
163
|
+
static equals = (n1, n2) => {
|
|
164
|
+
return n1[0] * n2[1] === n1[1] * n2[0];
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* @param {Fraction}
|
|
168
|
+
* True if zero.
|
|
169
|
+
*/
|
|
170
|
+
static isZero = ([n]) => {
|
|
171
|
+
return n === 0;
|
|
172
|
+
};
|
|
173
|
+
//
|
|
174
|
+
// Normalization.
|
|
175
|
+
//
|
|
176
|
+
/**
|
|
177
|
+
* Simplify fraction finding LCDs.
|
|
178
|
+
* @param n
|
|
179
|
+
* @param d
|
|
180
|
+
*/
|
|
181
|
+
static simplify = ([n, d]) => {
|
|
182
|
+
_FractionUtil.validate([
|
|
183
|
+
n,
|
|
184
|
+
d
|
|
185
|
+
]);
|
|
186
|
+
if (d < 1) {
|
|
187
|
+
const t = n / d;
|
|
188
|
+
if (Math.floor(t) === t) {
|
|
189
|
+
n = t;
|
|
190
|
+
d = 1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const fn = _FractionUtil.factors(n).reverse();
|
|
194
|
+
const fd = _FractionUtil.factors(d).reverse();
|
|
195
|
+
let c;
|
|
196
|
+
for (let i = 0; i < fn.length; i++) {
|
|
197
|
+
c = fd.find((n2) => n2 === fn[i]);
|
|
198
|
+
if (c) {
|
|
199
|
+
return [
|
|
200
|
+
n / c,
|
|
201
|
+
d / c
|
|
202
|
+
];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return [
|
|
206
|
+
n,
|
|
207
|
+
d
|
|
208
|
+
];
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Return common factors.
|
|
212
|
+
* @param n
|
|
213
|
+
*/
|
|
214
|
+
static factors = (n) => {
|
|
215
|
+
invariant2(Number.isFinite(n), `Invalid number: ${n}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 113, S: this, A: ["Number.isFinite(n)", "`Invalid number: ${n}`"] });
|
|
216
|
+
const factors = [
|
|
217
|
+
1
|
|
218
|
+
];
|
|
219
|
+
if (Number.isSafeInteger(n)) {
|
|
220
|
+
let f = 1;
|
|
221
|
+
do {
|
|
222
|
+
if (n % ++f === 0) {
|
|
223
|
+
factors.push(f);
|
|
224
|
+
}
|
|
225
|
+
} while (n / f > 1 && f < 100);
|
|
226
|
+
}
|
|
227
|
+
return factors;
|
|
228
|
+
};
|
|
229
|
+
//
|
|
230
|
+
// Basic arithmetic.
|
|
231
|
+
//
|
|
232
|
+
/**
|
|
233
|
+
* @param n1
|
|
234
|
+
* @param n2
|
|
235
|
+
*/
|
|
236
|
+
static add = (n1, n2) => {
|
|
237
|
+
_FractionUtil.validate(n1, n2);
|
|
238
|
+
const d = n1[1] * n2[1];
|
|
239
|
+
const n = n1[0] * n2[1] + n2[0] * n1[1];
|
|
240
|
+
return _FractionUtil.simplify([
|
|
241
|
+
n,
|
|
242
|
+
d
|
|
243
|
+
]);
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* @param n1
|
|
247
|
+
* @param n2
|
|
248
|
+
*/
|
|
249
|
+
static subtract = (n1, n2) => {
|
|
250
|
+
_FractionUtil.validate(n1, n2);
|
|
251
|
+
const d = n1[1] * n2[1];
|
|
252
|
+
const n = n1[0] * n2[1] - n2[0] * n1[1];
|
|
253
|
+
return _FractionUtil.simplify([
|
|
254
|
+
n,
|
|
255
|
+
d
|
|
256
|
+
]);
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* @param n1
|
|
260
|
+
* @param n2
|
|
261
|
+
*/
|
|
262
|
+
static multiply = (n1, n2) => {
|
|
263
|
+
_FractionUtil.validate(n1, n2);
|
|
264
|
+
const n = n1[0] * n2[0];
|
|
265
|
+
const d = n1[1] * n2[1];
|
|
266
|
+
return _FractionUtil.simplify([
|
|
267
|
+
n,
|
|
268
|
+
d
|
|
269
|
+
]);
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* @param n1
|
|
273
|
+
* @param n2
|
|
274
|
+
*/
|
|
275
|
+
static divide = (n1, n2) => {
|
|
276
|
+
_FractionUtil.validate(n1, n2);
|
|
277
|
+
const n = n1[0] * n2[1];
|
|
278
|
+
const d = n1[1] * n2[0];
|
|
279
|
+
return _FractionUtil.simplify([
|
|
280
|
+
n,
|
|
281
|
+
d
|
|
282
|
+
]);
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/util/points.ts
|
|
287
|
+
var getCircumferencePoints = (p1, p2, r1 = 0, r2 = 0) => {
|
|
288
|
+
const [x1, y1] = p1;
|
|
289
|
+
const [x2, y2] = p2;
|
|
290
|
+
const theta = Math.atan2(x2 - x1, y2 - y1);
|
|
291
|
+
return [
|
|
292
|
+
[
|
|
293
|
+
// p1
|
|
294
|
+
x1 + (r1 === 0 ? 0 : r1 * Math.sin(theta)),
|
|
295
|
+
y1 + (r1 === 0 ? 0 : r1 * Math.cos(theta))
|
|
296
|
+
],
|
|
297
|
+
[
|
|
298
|
+
// p2
|
|
299
|
+
x2 - (r2 === 0 ? 0 : r2 * Math.cos(Math.PI / 2 - theta)),
|
|
300
|
+
y2 - (r2 === 0 ? 0 : r2 * Math.sin(Math.PI / 2 - theta))
|
|
301
|
+
]
|
|
302
|
+
];
|
|
303
|
+
};
|
|
304
|
+
var normal = (p1, p2) => {
|
|
305
|
+
const dx = p2[0] - p1[0];
|
|
306
|
+
const dy = p2[1] - p1[1];
|
|
307
|
+
const len = Math.hypot(dx, dy);
|
|
308
|
+
return [
|
|
309
|
+
dy / len,
|
|
310
|
+
-dx / len
|
|
311
|
+
];
|
|
312
|
+
};
|
|
313
|
+
var offsetPoints = (points, distance, closed) => {
|
|
314
|
+
const len = points.length;
|
|
315
|
+
const out = [];
|
|
316
|
+
for (let i = 0; i < len; i++) {
|
|
317
|
+
const p0 = points[(i - 1 + len) % len];
|
|
318
|
+
const p1 = points[i];
|
|
319
|
+
const p2 = points[(i + 1) % len];
|
|
320
|
+
const n1 = normal(p0, p1);
|
|
321
|
+
const n2 = normal(p1, p2);
|
|
322
|
+
const nx = (n1[0] + n2[0]) / 2;
|
|
323
|
+
const ny = (n1[1] + n2[1]) / 2;
|
|
324
|
+
const norm = Math.hypot(nx, ny) || 1;
|
|
325
|
+
out.push([
|
|
326
|
+
p1[0] + distance * nx / norm,
|
|
327
|
+
p1[1] + distance * ny / norm
|
|
328
|
+
]);
|
|
329
|
+
if (!closed && (i === 0 || i === len - 1)) {
|
|
330
|
+
out[i] = [
|
|
331
|
+
p1[0] + distance * normal(p0, p1)[0],
|
|
332
|
+
p1[1] + distance * normal(p0, p1)[1]
|
|
333
|
+
];
|
|
334
|
+
}
|
|
264
335
|
}
|
|
265
|
-
|
|
266
|
-
|
|
336
|
+
return out;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// src/util/scale.ts
|
|
340
|
+
import { zoomIdentity } from "d3";
|
|
341
|
+
var Scale = class {
|
|
342
|
+
_gridSize;
|
|
343
|
+
_transform;
|
|
344
|
+
constructor(_gridSize = 32) {
|
|
345
|
+
this._gridSize = _gridSize;
|
|
346
|
+
}
|
|
347
|
+
get gridSize() {
|
|
348
|
+
return this._gridSize;
|
|
349
|
+
}
|
|
350
|
+
get transform() {
|
|
351
|
+
return this._transform || zoomIdentity;
|
|
352
|
+
}
|
|
353
|
+
setTransform(transform) {
|
|
354
|
+
if (this._transform?.x === transform.x && this._transform?.y === transform.y && this._transform?.k === transform.k) {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
this._transform = transform;
|
|
358
|
+
return true;
|
|
267
359
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
360
|
+
/**
|
|
361
|
+
* Translate a screen point to a logical point.
|
|
362
|
+
* @param point
|
|
363
|
+
*/
|
|
364
|
+
translate(point) {
|
|
365
|
+
const { x, y, k } = this._transform ?? {
|
|
366
|
+
x: 0,
|
|
367
|
+
y: 0,
|
|
368
|
+
k: 1
|
|
369
|
+
};
|
|
370
|
+
return [
|
|
371
|
+
(point[0] - x) / k,
|
|
372
|
+
(point[1] - y) / k
|
|
373
|
+
];
|
|
272
374
|
}
|
|
273
375
|
/**
|
|
274
|
-
*
|
|
275
|
-
*
|
|
376
|
+
* Map model to screen.
|
|
377
|
+
* Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
|
|
276
378
|
*/
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
379
|
+
model = {
|
|
380
|
+
// TODO(burdon): Precision depends on scale.
|
|
381
|
+
snapValues: (array) => array.map((n) => FractionUtil.round(n)),
|
|
382
|
+
snapVertex: ({ x, y }) => {
|
|
383
|
+
const [sx, sy] = this.model.snapValues([
|
|
384
|
+
x,
|
|
385
|
+
y
|
|
386
|
+
]);
|
|
387
|
+
return {
|
|
388
|
+
x: sx,
|
|
389
|
+
y: sy
|
|
390
|
+
};
|
|
391
|
+
},
|
|
392
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
393
|
+
[x, y, width, height] = this.model.snapValues([
|
|
394
|
+
x,
|
|
395
|
+
y,
|
|
396
|
+
width,
|
|
397
|
+
height
|
|
398
|
+
]);
|
|
399
|
+
return {
|
|
400
|
+
x,
|
|
401
|
+
y,
|
|
402
|
+
width,
|
|
403
|
+
height
|
|
404
|
+
};
|
|
405
|
+
},
|
|
406
|
+
toValue: (value) => {
|
|
407
|
+
return Math.round(FractionUtil.toNumber(value) * this._gridSize);
|
|
408
|
+
},
|
|
409
|
+
toValues: (values) => {
|
|
410
|
+
return values.map((value) => Math.round(FractionUtil.toNumber(value) * this._gridSize));
|
|
411
|
+
},
|
|
412
|
+
toPoint: (point) => {
|
|
413
|
+
const [x, y] = this.model.toValues([
|
|
414
|
+
point.x,
|
|
415
|
+
point.y
|
|
416
|
+
]);
|
|
417
|
+
return [
|
|
418
|
+
x,
|
|
419
|
+
y === 0 ? 0 : -y
|
|
420
|
+
];
|
|
421
|
+
},
|
|
422
|
+
toBounds: ({ x, y, width, height }) => {
|
|
423
|
+
const point = this.model.toPoint({
|
|
424
|
+
x,
|
|
425
|
+
y
|
|
426
|
+
});
|
|
427
|
+
const [width2, height2] = this.model.toValues([
|
|
428
|
+
width,
|
|
429
|
+
height
|
|
430
|
+
]);
|
|
431
|
+
return {
|
|
432
|
+
x: point[0],
|
|
433
|
+
y: point[1] - height2,
|
|
434
|
+
width: width2,
|
|
435
|
+
height: height2
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* Map screen to model.
|
|
441
|
+
* Screen points are represented by floating numbers and use translated SVG coordinates (with the y-axis inverted).
|
|
442
|
+
*/
|
|
443
|
+
screen = {
|
|
444
|
+
snapValues: (array) => array.map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
445
|
+
snapPoint: ([x, y]) => [
|
|
446
|
+
x,
|
|
447
|
+
y
|
|
448
|
+
].map((n) => Math.round(n / this._gridSize) * this._gridSize),
|
|
449
|
+
snapBounds: ({ x, y, width, height }) => {
|
|
450
|
+
[x, y, width, height] = this.screen.snapValues([
|
|
451
|
+
x,
|
|
452
|
+
y,
|
|
453
|
+
width,
|
|
454
|
+
height
|
|
455
|
+
]);
|
|
456
|
+
return {
|
|
457
|
+
x,
|
|
458
|
+
y,
|
|
459
|
+
width,
|
|
460
|
+
height
|
|
461
|
+
};
|
|
462
|
+
},
|
|
463
|
+
toValue: (value) => {
|
|
464
|
+
return FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
465
|
+
this._gridSize,
|
|
466
|
+
1
|
|
467
|
+
]);
|
|
468
|
+
},
|
|
469
|
+
toValues: (values) => {
|
|
470
|
+
return values.map((value) => FractionUtil.divide(FractionUtil.toFraction(value), [
|
|
471
|
+
this._gridSize,
|
|
472
|
+
1
|
|
473
|
+
]));
|
|
474
|
+
},
|
|
475
|
+
toVertex: (point) => {
|
|
476
|
+
const [x, y] = point;
|
|
477
|
+
return {
|
|
478
|
+
x: FractionUtil.toFraction(x / this._gridSize),
|
|
479
|
+
y: FractionUtil.toFraction(-y / this._gridSize)
|
|
480
|
+
};
|
|
481
|
+
},
|
|
482
|
+
toBounds: (bounds) => {
|
|
483
|
+
const { x, y } = this.screen.toVertex([
|
|
484
|
+
bounds.x,
|
|
485
|
+
bounds.y
|
|
486
|
+
]);
|
|
487
|
+
const [width, height] = this.screen.toValues([
|
|
488
|
+
bounds.width,
|
|
489
|
+
bounds.height
|
|
490
|
+
]);
|
|
491
|
+
return {
|
|
492
|
+
x,
|
|
493
|
+
y: FractionUtil.subtract(y, height),
|
|
494
|
+
width,
|
|
495
|
+
height
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/util/screen.ts
|
|
502
|
+
var Screen = class {
|
|
503
|
+
static createBounds = ([x1, y1], [x2, y2], mod = {}) => {
|
|
504
|
+
const { constrain, center } = mod;
|
|
505
|
+
const x = Math.min(x1, x2);
|
|
506
|
+
const y = Math.min(y1, y2);
|
|
507
|
+
let width = Math.abs(x2 - x1);
|
|
508
|
+
let height = Math.abs(y2 - y1);
|
|
509
|
+
if (constrain) {
|
|
510
|
+
width = height = Math.max(width, height);
|
|
511
|
+
}
|
|
512
|
+
if (center) {
|
|
513
|
+
return {
|
|
514
|
+
x: x - width,
|
|
515
|
+
y: y - height,
|
|
516
|
+
width: width * 2,
|
|
517
|
+
height: height * 2
|
|
518
|
+
};
|
|
519
|
+
} else {
|
|
520
|
+
return {
|
|
521
|
+
x,
|
|
522
|
+
y,
|
|
523
|
+
width,
|
|
524
|
+
height
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
static center = ({ x, y, width, height }) => {
|
|
529
|
+
return [
|
|
530
|
+
x + width / 2,
|
|
531
|
+
y + height / 2
|
|
532
|
+
];
|
|
533
|
+
};
|
|
534
|
+
static contains = (bounds, point) => {
|
|
535
|
+
const [x, y] = point;
|
|
536
|
+
if (x < bounds.x || y < bounds.y) {
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
if (x > bounds.x + bounds.width || y > bounds.y + bounds.height) {
|
|
540
|
+
return false;
|
|
541
|
+
}
|
|
542
|
+
return true;
|
|
543
|
+
};
|
|
544
|
+
/**
|
|
545
|
+
* Distance between two points.
|
|
546
|
+
* @param p1
|
|
547
|
+
* @param p2
|
|
548
|
+
*/
|
|
549
|
+
static len = (p1, p2) => {
|
|
550
|
+
return Math.sqrt(Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2));
|
|
551
|
+
};
|
|
552
|
+
/**
|
|
553
|
+
* Distance to line segment.
|
|
554
|
+
* https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment#1501725
|
|
555
|
+
* @param v1
|
|
556
|
+
* @param v2
|
|
557
|
+
* @param p
|
|
558
|
+
*/
|
|
559
|
+
static normal = (v1, v2, p) => {
|
|
560
|
+
const d2 = (p1, p2) => Math.pow(Math.abs(p1[0] - p2[0]), 2) + Math.pow(Math.abs(p1[1] - p2[1]), 2);
|
|
561
|
+
let d;
|
|
562
|
+
const len2 = d2(v1, v2);
|
|
563
|
+
if (len2 === 0) {
|
|
564
|
+
d = d2(p, v1);
|
|
565
|
+
} else {
|
|
566
|
+
let t = ((p[0] - v1[0]) * (v2[0] - v1[0]) + (p[1] - v1[1]) * (v2[1] - v1[1])) / len2;
|
|
567
|
+
t = Math.max(0, Math.min(1, t));
|
|
568
|
+
d = d2(p, [
|
|
569
|
+
v1[0] + t * (v2[0] - v1[0]),
|
|
570
|
+
v1[1] + t * (v2[1] - v1[1])
|
|
571
|
+
]);
|
|
572
|
+
}
|
|
573
|
+
return Math.sqrt(d);
|
|
574
|
+
};
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
// src/util/vector.ts
|
|
578
|
+
var Vector = class {
|
|
579
|
+
/**
|
|
580
|
+
* Convert to Vertex.
|
|
581
|
+
* @param x
|
|
582
|
+
* @param y
|
|
583
|
+
*/
|
|
584
|
+
static toVertex = ({ x, y }) => ({
|
|
585
|
+
x: FractionUtil.toFraction(x),
|
|
586
|
+
y: FractionUtil.toFraction(y)
|
|
587
|
+
});
|
|
588
|
+
/**
|
|
589
|
+
* Convert to Bounds.
|
|
590
|
+
* @param bounds
|
|
591
|
+
*/
|
|
592
|
+
static toBounds = ({ x, y, width, height }) => ({
|
|
593
|
+
x: FractionUtil.toFraction(x),
|
|
594
|
+
y: FractionUtil.toFraction(y),
|
|
595
|
+
width: FractionUtil.toFraction(width),
|
|
596
|
+
height: FractionUtil.toFraction(height)
|
|
597
|
+
});
|
|
598
|
+
/**
|
|
599
|
+
* Calculate center point.
|
|
600
|
+
* @param bounds
|
|
601
|
+
*/
|
|
602
|
+
static center = ({ x, y, width, height }) => {
|
|
603
|
+
const cx = FractionUtil.add(x, FractionUtil.multiply(width, [
|
|
604
|
+
1,
|
|
605
|
+
2
|
|
606
|
+
]));
|
|
607
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
608
|
+
1,
|
|
609
|
+
2
|
|
610
|
+
]));
|
|
611
|
+
return {
|
|
612
|
+
x: cx,
|
|
613
|
+
y: cy
|
|
614
|
+
};
|
|
615
|
+
};
|
|
616
|
+
/**
|
|
617
|
+
* Calculate centered left edge.
|
|
618
|
+
* @param bounds
|
|
619
|
+
*/
|
|
620
|
+
static left = ({ x, y, height }) => {
|
|
621
|
+
const cx = x;
|
|
622
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
623
|
+
1,
|
|
624
|
+
2
|
|
625
|
+
]));
|
|
626
|
+
return {
|
|
627
|
+
x: cx,
|
|
628
|
+
y: cy
|
|
629
|
+
};
|
|
630
|
+
};
|
|
631
|
+
/**
|
|
632
|
+
* Calculate centered right edge.
|
|
633
|
+
* @param bounds
|
|
634
|
+
*/
|
|
635
|
+
static right = ({ x, y, width, height }) => {
|
|
636
|
+
const cx = FractionUtil.add(x, width);
|
|
637
|
+
const cy = FractionUtil.add(y, FractionUtil.multiply(height, [
|
|
638
|
+
1,
|
|
639
|
+
2
|
|
640
|
+
]));
|
|
641
|
+
return {
|
|
642
|
+
x: cx,
|
|
643
|
+
y: cy
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
// src/graph/projector/projector.ts
|
|
649
|
+
var Projector = class {
|
|
650
|
+
_context;
|
|
651
|
+
updated = new EventEmitter();
|
|
652
|
+
_options;
|
|
653
|
+
constructor(_context, options) {
|
|
654
|
+
this._context = _context;
|
|
655
|
+
this._options = Object.assign({
|
|
656
|
+
idAccessor: defaultIdAccessor
|
|
657
|
+
}, options);
|
|
658
|
+
}
|
|
659
|
+
get context() {
|
|
660
|
+
return this._context;
|
|
661
|
+
}
|
|
662
|
+
get options() {
|
|
663
|
+
return this._options;
|
|
664
|
+
}
|
|
665
|
+
refresh(dragging = false) {
|
|
666
|
+
this.onRefresh(dragging);
|
|
667
|
+
}
|
|
668
|
+
updateData(data) {
|
|
669
|
+
this.onUpdate(data);
|
|
670
|
+
}
|
|
671
|
+
emitUpdate(kind = "topology") {
|
|
672
|
+
this.updated.emit({
|
|
673
|
+
layout: this.layout,
|
|
674
|
+
kind
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
async clear() {
|
|
678
|
+
await this.onClear();
|
|
679
|
+
}
|
|
680
|
+
async start() {
|
|
681
|
+
await this.onStart();
|
|
682
|
+
}
|
|
683
|
+
async stop() {
|
|
684
|
+
await this.onStop();
|
|
685
|
+
}
|
|
686
|
+
onRefresh(dragging = false) {
|
|
687
|
+
}
|
|
688
|
+
onUpdate(data) {
|
|
689
|
+
}
|
|
690
|
+
async onClear() {
|
|
691
|
+
}
|
|
692
|
+
async onStart() {
|
|
693
|
+
}
|
|
694
|
+
async onStop() {
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
// src/graph/projector/graph-projector.ts
|
|
699
|
+
var GraphProjector = class extends Projector {
|
|
700
|
+
_selection;
|
|
701
|
+
_layout;
|
|
702
|
+
// TODO(burdon): Change to object props.
|
|
703
|
+
constructor(context, options, _selection, layout) {
|
|
704
|
+
super(context, options), this._selection = _selection;
|
|
705
|
+
this._layout = {
|
|
706
|
+
id: (Math.random() * 10).toString().slice(8),
|
|
707
|
+
graph: {
|
|
708
|
+
nodes: [
|
|
709
|
+
...layout?.graph.nodes ?? []
|
|
710
|
+
],
|
|
711
|
+
edges: [
|
|
712
|
+
...layout?.graph.edges ?? []
|
|
713
|
+
]
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
get layout() {
|
|
718
|
+
return this._layout;
|
|
719
|
+
}
|
|
720
|
+
get selection() {
|
|
721
|
+
return this._selection;
|
|
722
|
+
}
|
|
723
|
+
numChildren(node) {
|
|
724
|
+
return this._layout.graph.edges.filter((edge) => edge.source.id === this.options.idAccessor(node)).length;
|
|
725
|
+
}
|
|
726
|
+
reset() {
|
|
727
|
+
this._layout.graph.nodes = [];
|
|
728
|
+
this._layout.graph.edges = [];
|
|
729
|
+
this.emitUpdate();
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Merge external data with internal representation (e.g., so force properties like position are preserved).
|
|
733
|
+
* @param data
|
|
734
|
+
*/
|
|
735
|
+
mergeData(data = emptyGraph) {
|
|
736
|
+
const nodes = data.nodes.map((node) => {
|
|
737
|
+
let current = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
|
|
738
|
+
if (!current) {
|
|
739
|
+
current = {
|
|
740
|
+
id: this.options.idAccessor(node)
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
current.data = node;
|
|
744
|
+
current.hidden = false;
|
|
745
|
+
return current;
|
|
746
|
+
});
|
|
747
|
+
const edges = data.edges.map((edge) => ({
|
|
748
|
+
id: edge.id,
|
|
749
|
+
source: nodes.find((n) => n.id === edge.source),
|
|
750
|
+
target: nodes.find((n) => n.id === edge.target),
|
|
751
|
+
data: edge.data
|
|
752
|
+
})).filter((edge) => edge.source && edge.target);
|
|
753
|
+
Object.assign(this._layout, {
|
|
754
|
+
graph: {
|
|
755
|
+
nodes,
|
|
756
|
+
edges
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
async onClear() {
|
|
761
|
+
this.reset();
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
// src/graph/projector/graph-radial-projector.ts
|
|
766
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
767
|
+
var GraphRadialProjector = class extends GraphProjector {
|
|
768
|
+
_timer;
|
|
769
|
+
findNode(x, y, radius) {
|
|
770
|
+
return void 0;
|
|
771
|
+
}
|
|
772
|
+
onUpdate(graph) {
|
|
773
|
+
log("onUpdate", {
|
|
774
|
+
graph: {
|
|
775
|
+
nodes: graph?.nodes.length,
|
|
776
|
+
edges: graph?.edges.length
|
|
777
|
+
}
|
|
778
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 13, S: this });
|
|
779
|
+
this.mergeData(graph);
|
|
780
|
+
this.emitUpdate("topology");
|
|
781
|
+
this.doRadialLayout();
|
|
782
|
+
}
|
|
783
|
+
animate() {
|
|
784
|
+
this._timer?.stop();
|
|
785
|
+
this._timer = void 0;
|
|
786
|
+
const start = Date.now();
|
|
787
|
+
if (this.options.duration) {
|
|
788
|
+
this._timer = timer(() => {
|
|
789
|
+
const t = Math.min(1, (Date.now() - start) / this.options.duration);
|
|
790
|
+
const d = easeCubic(t);
|
|
791
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
792
|
+
node.x = node.sx + (node.tx - node.sx) * d;
|
|
793
|
+
node.y = node.sy + (node.ty - node.sy) * d;
|
|
794
|
+
node.r = node.sr + (node.tr - node.sr) * d;
|
|
795
|
+
});
|
|
796
|
+
this.onTickFrame(d);
|
|
797
|
+
this.emitUpdate("positions");
|
|
798
|
+
if (t >= 1) {
|
|
799
|
+
this._timer.stop();
|
|
800
|
+
this._timer = void 0;
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
} else {
|
|
804
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
805
|
+
node.x = node.tx;
|
|
806
|
+
node.y = node.ty;
|
|
807
|
+
node.r = node.tr;
|
|
808
|
+
});
|
|
809
|
+
this.onTickFrame(1);
|
|
810
|
+
this.emitUpdate("positions");
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Per-frame hook called after node x/y/r are interpolated and before the
|
|
815
|
+
* 'positions' emit. Subclasses override to update edge geometry (`edge.path`)
|
|
816
|
+
* so curves stay glued to moving endpoints. `t` is the eased progress in [0, 1].
|
|
817
|
+
*/
|
|
818
|
+
onTickFrame(t) {
|
|
819
|
+
}
|
|
820
|
+
async onStop() {
|
|
821
|
+
this._timer?.stop();
|
|
822
|
+
this._timer = void 0;
|
|
823
|
+
}
|
|
824
|
+
doRadialLayout() {
|
|
825
|
+
if (!this.context.size) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
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);
|
|
829
|
+
this.layout.graph.nodes.forEach((node, i) => {
|
|
830
|
+
const [tx, ty] = radial(i);
|
|
831
|
+
updateNode(node, [
|
|
832
|
+
tx,
|
|
833
|
+
ty
|
|
834
|
+
]);
|
|
835
|
+
});
|
|
836
|
+
this.animate();
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
840
|
+
const sx = node.x ?? tx;
|
|
841
|
+
const sy = node.y ?? ty;
|
|
842
|
+
const sr = node.r ?? tr;
|
|
843
|
+
Object.assign(node, {
|
|
844
|
+
initialized: true,
|
|
845
|
+
// Start.
|
|
846
|
+
sx,
|
|
847
|
+
sy,
|
|
848
|
+
sr,
|
|
849
|
+
// Target.
|
|
850
|
+
tx,
|
|
851
|
+
ty,
|
|
852
|
+
tr,
|
|
853
|
+
// Current.
|
|
854
|
+
x: sx,
|
|
855
|
+
y: sy,
|
|
856
|
+
r: sr
|
|
857
|
+
});
|
|
858
|
+
};
|
|
859
|
+
var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
|
|
860
|
+
const da = 2 * Math.PI / n;
|
|
861
|
+
return (i) => {
|
|
862
|
+
const a = start + i * da;
|
|
863
|
+
return [
|
|
864
|
+
x + Math.cos(a) * r,
|
|
865
|
+
y + Math.sin(a) * r
|
|
866
|
+
];
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
var layoutHorizontal = (x, y, w, n) => {
|
|
870
|
+
const dx = n > 1 ? w / (n - 1) : 0;
|
|
871
|
+
const sx = x - (n - 1) * dx / 2;
|
|
872
|
+
return (i) => {
|
|
873
|
+
return [
|
|
874
|
+
sx + i * dx,
|
|
875
|
+
y
|
|
876
|
+
];
|
|
877
|
+
};
|
|
878
|
+
};
|
|
879
|
+
var layoutVertical = (x, y, h, n) => {
|
|
880
|
+
const dy = n > 1 ? h / (n - 1) : 0;
|
|
881
|
+
const sy = y - (n - 1) * dy / 2;
|
|
882
|
+
return (i) => {
|
|
883
|
+
return [
|
|
884
|
+
x,
|
|
885
|
+
sy + i * dy
|
|
886
|
+
];
|
|
887
|
+
};
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
// src/graph/projector/graph-bundle-projector.ts
|
|
891
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-bundle-projector.ts";
|
|
892
|
+
var ROOT_ID = "__bundle_root__";
|
|
893
|
+
var GROUP_PREFIX = "__bundle_group__:";
|
|
894
|
+
var cartesianToPolar = (x, y) => ({
|
|
895
|
+
angle: Math.atan2(x, -y),
|
|
896
|
+
radius: Math.hypot(x, y)
|
|
897
|
+
});
|
|
898
|
+
var GraphBundleProjector = class extends GraphRadialProjector {
|
|
899
|
+
// Per-edge polar point arrays. Points 0 and N-1 are the source / target leaves and are
|
|
900
|
+
// overwritten from current cartesian on every tick; intermediate points stay fixed at
|
|
901
|
+
// their cluster-layout polar coordinates.
|
|
902
|
+
#edgePoints = /* @__PURE__ */ new Map();
|
|
903
|
+
#lineGen = lineRadial().radius((d) => d.radius).angle((d) => d.angle);
|
|
904
|
+
onUpdate(graph) {
|
|
905
|
+
log2("onUpdate", {
|
|
906
|
+
graph: {
|
|
907
|
+
nodes: graph?.nodes.length,
|
|
908
|
+
edges: graph?.edges.length
|
|
909
|
+
}
|
|
910
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 40, S: this });
|
|
911
|
+
this.mergeData(graph);
|
|
912
|
+
this.doBundleLayout();
|
|
913
|
+
this.emitUpdate("topology");
|
|
914
|
+
this.animate();
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Refresh leaf endpoint polar values from current cartesian so the curve tracks
|
|
918
|
+
* its endpoints during the tween. Internal hierarchy positions stay constant.
|
|
919
|
+
*/
|
|
920
|
+
onTickFrame(_t) {
|
|
921
|
+
for (const edge of this.layout.graph.edges) {
|
|
922
|
+
if (edge.type !== "bundle") {
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
const points = this.#edgePoints.get(edge.id);
|
|
926
|
+
if (!points || points.length < 2) {
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
const s = cartesianToPolar(edge.source.x ?? 0, edge.source.y ?? 0);
|
|
930
|
+
const t = cartesianToPolar(edge.target.x ?? 0, edge.target.y ?? 0);
|
|
931
|
+
points[0] = {
|
|
932
|
+
angle: s.angle,
|
|
933
|
+
radius: s.radius
|
|
934
|
+
};
|
|
935
|
+
points[points.length - 1] = {
|
|
936
|
+
angle: t.angle,
|
|
937
|
+
radius: t.radius
|
|
938
|
+
};
|
|
939
|
+
edge.path = this.#lineGen(points) ?? void 0;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
doBundleLayout() {
|
|
943
|
+
if (!this.context.size) {
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
const dataNodes = [
|
|
947
|
+
...this.layout.graph.nodes
|
|
948
|
+
];
|
|
949
|
+
if (!dataNodes.length) {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
const groupOf = this.options.groupOf;
|
|
953
|
+
const items = [
|
|
954
|
+
{
|
|
955
|
+
id: ROOT_ID
|
|
956
|
+
}
|
|
957
|
+
];
|
|
958
|
+
const groupIds = /* @__PURE__ */ new Map();
|
|
959
|
+
for (const node of dataNodes) {
|
|
960
|
+
const key = groupOf?.(node);
|
|
961
|
+
let parent = ROOT_ID;
|
|
962
|
+
if (key !== void 0) {
|
|
963
|
+
let groupId = groupIds.get(key);
|
|
964
|
+
if (!groupId) {
|
|
965
|
+
groupId = `${GROUP_PREFIX}${key}`;
|
|
966
|
+
groupIds.set(key, groupId);
|
|
967
|
+
items.push({
|
|
968
|
+
id: groupId,
|
|
969
|
+
parent: ROOT_ID
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
parent = groupId;
|
|
973
|
+
}
|
|
974
|
+
items.push({
|
|
975
|
+
id: node.id,
|
|
976
|
+
parent,
|
|
977
|
+
node
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
981
|
+
for (const item of items) {
|
|
982
|
+
if (item.parent) {
|
|
983
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
984
|
+
list.push(item);
|
|
985
|
+
childrenByParent.set(item.parent, list);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const root = hierarchy({
|
|
989
|
+
id: ROOT_ID
|
|
990
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
991
|
+
const { width, height } = this.context.size;
|
|
992
|
+
const margin = this.options.margin ?? 120;
|
|
993
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
994
|
+
d3Cluster().size([
|
|
995
|
+
2 * Math.PI,
|
|
996
|
+
ringRadius
|
|
997
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
998
|
+
const leafR = this.options.leafRadius ?? 4;
|
|
999
|
+
const tension = this.options.tension ?? 0.85;
|
|
1000
|
+
this.#lineGen = lineRadial().curve(curveBundle.beta(tension)).radius((d) => d.radius).angle((d) => d.angle);
|
|
1001
|
+
const hierById = /* @__PURE__ */ new Map();
|
|
1002
|
+
root.each((d) => {
|
|
1003
|
+
hierById.set(d.data.id, d);
|
|
1004
|
+
});
|
|
1005
|
+
root.leaves().forEach((d) => {
|
|
1006
|
+
const angle = d.x;
|
|
1007
|
+
const radius = d.y;
|
|
1008
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1009
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1010
|
+
if (d.data.node) {
|
|
1011
|
+
updateNode(d.data.node, [
|
|
1012
|
+
x,
|
|
1013
|
+
y
|
|
1014
|
+
], leafR);
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
this.layout.graph.nodes = dataNodes;
|
|
1018
|
+
this.#edgePoints.clear();
|
|
1019
|
+
const incomingEdges = [
|
|
1020
|
+
...this.layout.graph.edges
|
|
1021
|
+
];
|
|
1022
|
+
const bundleEdges = [];
|
|
1023
|
+
for (const edge of incomingEdges) {
|
|
1024
|
+
const sourceHier = hierById.get(edge.source.id);
|
|
1025
|
+
const targetHier = hierById.get(edge.target.id);
|
|
1026
|
+
if (!sourceHier || !targetHier || sourceHier === targetHier) {
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
1029
|
+
const pathNodes = sourceHier.path(targetHier);
|
|
1030
|
+
const points = pathNodes.map((n) => ({
|
|
1031
|
+
angle: n.x,
|
|
1032
|
+
radius: n.y
|
|
1033
|
+
}));
|
|
1034
|
+
this.#edgePoints.set(edge.id, points);
|
|
1035
|
+
bundleEdges.push({
|
|
1036
|
+
id: edge.id,
|
|
1037
|
+
type: "bundle",
|
|
1038
|
+
source: edge.source,
|
|
1039
|
+
target: edge.target,
|
|
1040
|
+
data: edge.data
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
this.layout.graph.edges = bundleEdges;
|
|
1044
|
+
this.onTickFrame(0);
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
// src/graph/projector/graph-cluster-projector.ts
|
|
1049
|
+
import { cluster as d3Cluster2, hierarchy as hierarchy2, linkRadial } from "d3";
|
|
1050
|
+
import { log as log3 } from "@dxos/log";
|
|
1051
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-cluster-projector.ts";
|
|
1052
|
+
var ROOT_ID2 = "__cluster_root__";
|
|
1053
|
+
var GROUP_PREFIX2 = "__group__:";
|
|
1054
|
+
var HIER_EDGE_PREFIX = "__hier__:";
|
|
1055
|
+
var CLUSTER_NODE_TYPE_LEAF = "leaf";
|
|
1056
|
+
var CLUSTER_NODE_TYPE_GROUP = "group";
|
|
1057
|
+
var CLUSTER_NODE_TYPE_ROOT = "root";
|
|
1058
|
+
var linkPath = linkRadial().angle((d) => d.x).radius((d) => d.y);
|
|
1059
|
+
var cartesianToPolar2 = (x, y) => ({
|
|
1060
|
+
angle: Math.atan2(x, -y),
|
|
1061
|
+
radius: Math.hypot(x, y)
|
|
1062
|
+
});
|
|
1063
|
+
var GraphClusterProjector = class extends GraphRadialProjector {
|
|
1064
|
+
// Synthetic-node ids (root id, or `${GROUP_PREFIX}${key}`) whose subtree is currently
|
|
1065
|
+
// hidden. Clicking the corresponding rendered circle calls toggleCollapsed to flip
|
|
1066
|
+
// membership, then re-runs the layout so the renderer's exit transition fades the
|
|
1067
|
+
// hidden leaves + hierarchy edges out (and back in on expand).
|
|
1068
|
+
#collapsed = /* @__PURE__ */ new Set();
|
|
1069
|
+
// Snapshot of the full data-node set as of the last mergeData. doClusterLayout always
|
|
1070
|
+
// reads from this rather than `layout.graph.nodes` — the layout view is filtered (it
|
|
1071
|
+
// drops hidden leaves so the renderer doesn't see them), so re-reading from there
|
|
1072
|
+
// would permanently lose the hidden leaves and they couldn't reappear on expand.
|
|
1073
|
+
#dataNodes = [];
|
|
1074
|
+
/** Toggle collapse state for a synthetic node id. Triggers a topology re-emit. */
|
|
1075
|
+
toggleCollapsed(id) {
|
|
1076
|
+
if (this.#collapsed.has(id)) {
|
|
1077
|
+
this.#collapsed.delete(id);
|
|
1078
|
+
} else {
|
|
1079
|
+
this.#collapsed.add(id);
|
|
1080
|
+
}
|
|
1081
|
+
this.doClusterLayout();
|
|
1082
|
+
this.emitUpdate("topology");
|
|
1083
|
+
this.animate();
|
|
1084
|
+
}
|
|
1085
|
+
/** Whether a synthetic-node id is currently collapsed. */
|
|
1086
|
+
isCollapsed(id) {
|
|
1087
|
+
return this.#collapsed.has(id);
|
|
1088
|
+
}
|
|
1089
|
+
onUpdate(graph) {
|
|
1090
|
+
log3("onUpdate", {
|
|
1091
|
+
graph: {
|
|
1092
|
+
nodes: graph?.nodes.length,
|
|
1093
|
+
edges: graph?.edges.length
|
|
1094
|
+
}
|
|
1095
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 69, S: this });
|
|
1096
|
+
this.mergeData(graph);
|
|
1097
|
+
this.#dataNodes = [
|
|
1098
|
+
...this.layout.graph.nodes
|
|
1099
|
+
];
|
|
1100
|
+
this.doClusterLayout();
|
|
1101
|
+
this.emitUpdate("topology");
|
|
1102
|
+
this.animate();
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Recompute each hierarchy edge's `path` from current cartesian source/target positions,
|
|
1106
|
+
* so the curves track moving endpoints during a cross-variant tween (e.g. force → cluster)
|
|
1107
|
+
* instead of being pinned to the final polar layout.
|
|
1108
|
+
*/
|
|
1109
|
+
onTickFrame(_t) {
|
|
1110
|
+
for (const edge of this.layout.graph.edges) {
|
|
1111
|
+
if (edge.type !== "hierarchy") {
|
|
1112
|
+
continue;
|
|
1113
|
+
}
|
|
1114
|
+
const { source, target } = edge;
|
|
1115
|
+
const s = cartesianToPolar2(source.x ?? 0, source.y ?? 0);
|
|
1116
|
+
const t = cartesianToPolar2(target.x ?? 0, target.y ?? 0);
|
|
1117
|
+
edge.path = linkPath({
|
|
1118
|
+
source: {
|
|
1119
|
+
x: s.angle,
|
|
1120
|
+
y: s.radius
|
|
1121
|
+
},
|
|
1122
|
+
target: {
|
|
1123
|
+
x: t.angle,
|
|
1124
|
+
y: t.radius
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
doClusterLayout() {
|
|
1130
|
+
if (!this.context.size) {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
const dataNodes = this.#dataNodes;
|
|
1134
|
+
if (!dataNodes.length) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
const groupOf = this.options.groupOf;
|
|
1138
|
+
const rootId = this.options.rootId ?? ROOT_ID2;
|
|
1139
|
+
const items = [
|
|
1140
|
+
{
|
|
1141
|
+
id: rootId
|
|
1142
|
+
}
|
|
1143
|
+
];
|
|
1144
|
+
const groupIds = /* @__PURE__ */ new Map();
|
|
1145
|
+
const rootCollapsed = this.#collapsed.has(rootId);
|
|
1146
|
+
if (!rootCollapsed) {
|
|
1147
|
+
for (const node of dataNodes) {
|
|
1148
|
+
const key = groupOf?.(node);
|
|
1149
|
+
let parent = rootId;
|
|
1150
|
+
if (key !== void 0) {
|
|
1151
|
+
let groupId = groupIds.get(key);
|
|
1152
|
+
if (!groupId) {
|
|
1153
|
+
groupId = `${GROUP_PREFIX2}${key}`;
|
|
1154
|
+
groupIds.set(key, groupId);
|
|
1155
|
+
items.push({
|
|
1156
|
+
id: groupId,
|
|
1157
|
+
parent: rootId,
|
|
1158
|
+
groupKey: key
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
parent = groupId;
|
|
1162
|
+
}
|
|
1163
|
+
if (this.#collapsed.has(parent)) {
|
|
1164
|
+
continue;
|
|
1165
|
+
}
|
|
1166
|
+
items.push({
|
|
1167
|
+
id: node.id,
|
|
1168
|
+
parent,
|
|
1169
|
+
node
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
1174
|
+
for (const item of items) {
|
|
1175
|
+
if (item.parent) {
|
|
1176
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
1177
|
+
list.push(item);
|
|
1178
|
+
childrenByParent.set(item.parent, list);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
const root = hierarchy2({
|
|
1182
|
+
id: rootId
|
|
1183
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1184
|
+
const { width, height } = this.context.size;
|
|
1185
|
+
const margin = this.options.margin ?? 80;
|
|
1186
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1187
|
+
d3Cluster2().size([
|
|
1188
|
+
2 * Math.PI,
|
|
1189
|
+
ringRadius
|
|
1190
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1191
|
+
const leafR = this.options.leafRadius ?? 4;
|
|
1192
|
+
const groupR = this.options.groupRadius ?? 3;
|
|
1193
|
+
const rootR = this.options.rootRadius ?? 5;
|
|
1194
|
+
const prevStubsById = /* @__PURE__ */ new Map();
|
|
1195
|
+
for (const node of this.layout.graph.nodes) {
|
|
1196
|
+
if (node.type === CLUSTER_NODE_TYPE_ROOT || node.type === CLUSTER_NODE_TYPE_GROUP) {
|
|
1197
|
+
prevStubsById.set(node.id, node);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
const syntheticNodes = /* @__PURE__ */ new Map();
|
|
1201
|
+
root.each((d) => {
|
|
1202
|
+
const id = d.data.id;
|
|
1203
|
+
const angle = d.x;
|
|
1204
|
+
const radius = d.y;
|
|
1205
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1206
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1207
|
+
if (d.data.node) {
|
|
1208
|
+
updateNode(d.data.node, [
|
|
1209
|
+
x,
|
|
1210
|
+
y
|
|
1211
|
+
], leafR);
|
|
1212
|
+
d.data.node.type = CLUSTER_NODE_TYPE_LEAF;
|
|
1213
|
+
d.data.node.hidden = false;
|
|
1214
|
+
} else {
|
|
1215
|
+
const isRoot = id === rootId;
|
|
1216
|
+
const stub = prevStubsById.get(id) ?? {
|
|
1217
|
+
id,
|
|
1218
|
+
x: 0,
|
|
1219
|
+
y: 0
|
|
283
1220
|
};
|
|
1221
|
+
updateNode(stub, [
|
|
1222
|
+
x,
|
|
1223
|
+
y
|
|
1224
|
+
], isRoot ? rootR : groupR);
|
|
1225
|
+
stub.type = isRoot ? CLUSTER_NODE_TYPE_ROOT : CLUSTER_NODE_TYPE_GROUP;
|
|
1226
|
+
if (isRoot) {
|
|
1227
|
+
stub.label = this.options.rootLabel;
|
|
1228
|
+
} else if (d.data.groupKey !== void 0) {
|
|
1229
|
+
stub.label = this.options.groupLabel ? this.options.groupLabel(d.data.groupKey) : d.data.groupKey;
|
|
1230
|
+
}
|
|
1231
|
+
syntheticNodes.set(id, stub);
|
|
284
1232
|
}
|
|
285
|
-
current.data = node;
|
|
286
|
-
return current;
|
|
287
1233
|
});
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
edges
|
|
1234
|
+
const visibleLeafIds = /* @__PURE__ */ new Set();
|
|
1235
|
+
for (const item of items) {
|
|
1236
|
+
if (item.node) {
|
|
1237
|
+
visibleLeafIds.add(item.id);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
for (const node of dataNodes) {
|
|
1241
|
+
if (visibleLeafIds.has(node.id)) {
|
|
1242
|
+
continue;
|
|
298
1243
|
}
|
|
1244
|
+
const key = groupOf?.(node);
|
|
1245
|
+
const parentId = key !== void 0 && groupIds.has(key) ? groupIds.get(key) : rootId;
|
|
1246
|
+
const parentStub = syntheticNodes.get(parentId);
|
|
1247
|
+
const targetX = parentStub?.tx ?? 0;
|
|
1248
|
+
const targetY = parentStub?.ty ?? 0;
|
|
1249
|
+
updateNode(node, [
|
|
1250
|
+
targetX,
|
|
1251
|
+
targetY
|
|
1252
|
+
], leafR);
|
|
1253
|
+
node.type = CLUSTER_NODE_TYPE_LEAF;
|
|
1254
|
+
node.hidden = true;
|
|
1255
|
+
}
|
|
1256
|
+
const nextNodes = [];
|
|
1257
|
+
for (const stub of syntheticNodes.values()) {
|
|
1258
|
+
nextNodes.push(stub);
|
|
1259
|
+
}
|
|
1260
|
+
for (const node of dataNodes) {
|
|
1261
|
+
nextNodes.push(node);
|
|
1262
|
+
}
|
|
1263
|
+
this.layout.graph.nodes = nextNodes;
|
|
1264
|
+
const hierarchyEdges = [];
|
|
1265
|
+
root.links().forEach((link) => {
|
|
1266
|
+
const sid = link.source.data.id;
|
|
1267
|
+
const tid = link.target.data.id;
|
|
1268
|
+
const sourceNode = link.source.data.node ?? syntheticNodes.get(sid);
|
|
1269
|
+
const targetNode = link.target.data.node ?? syntheticNodes.get(tid);
|
|
1270
|
+
hierarchyEdges.push({
|
|
1271
|
+
id: `${HIER_EDGE_PREFIX}${sid}->${tid}`,
|
|
1272
|
+
type: "hierarchy",
|
|
1273
|
+
source: sourceNode,
|
|
1274
|
+
target: targetNode,
|
|
1275
|
+
data: void 0
|
|
1276
|
+
});
|
|
299
1277
|
});
|
|
1278
|
+
this.layout.graph.edges = hierarchyEdges;
|
|
1279
|
+
this.onTickFrame(0);
|
|
300
1280
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
// src/graph/projector/graph-drag.ts
|
|
1284
|
+
import { drag, pointer, select as select2 } from "d3";
|
|
1285
|
+
var defaultDragOptions = {
|
|
1286
|
+
linkMod: "metaKey",
|
|
1287
|
+
freezeMod: "shiftKey"
|
|
1288
|
+
};
|
|
1289
|
+
var createGraphDrag = (context, projector, options = defaultDragOptions) => {
|
|
1290
|
+
let mode;
|
|
1291
|
+
let source;
|
|
1292
|
+
let target;
|
|
1293
|
+
let offset;
|
|
1294
|
+
let moved = false;
|
|
1295
|
+
const keyMod = (event, key) => {
|
|
1296
|
+
const modKey = options?.[key] ?? defaultDragOptions[key];
|
|
1297
|
+
return modKey === void 0 || event[modKey];
|
|
1298
|
+
};
|
|
1299
|
+
return drag().filter((event) => !event.ctrlKey).on("start", function(event, d) {
|
|
1300
|
+
source = d;
|
|
1301
|
+
offset = pointer(event, this.parentElement);
|
|
1302
|
+
if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) {
|
|
1303
|
+
mode = 1;
|
|
1304
|
+
} else if (keyMod(event.sourceEvent, "dragMod")) {
|
|
1305
|
+
mode = 0;
|
|
1306
|
+
}
|
|
1307
|
+
}).on("drag", function(event, d) {
|
|
1308
|
+
const parent = this.closest("g.node");
|
|
1309
|
+
select2(parent).classed("dragging", true).raise();
|
|
1310
|
+
const [dx, dy] = pointer(event, this.parentElement);
|
|
1311
|
+
const x = d.x + dx - offset[0];
|
|
1312
|
+
const y = d.y + dy - offset[1];
|
|
1313
|
+
const point = [
|
|
1314
|
+
x,
|
|
1315
|
+
y
|
|
1316
|
+
];
|
|
1317
|
+
switch (mode) {
|
|
1318
|
+
case 0: {
|
|
1319
|
+
select2(context.svg).attr("cursor", "grabbing");
|
|
1320
|
+
event.subject.x = event.subject.fx = point[0];
|
|
1321
|
+
event.subject.y = event.subject.fy = point[1];
|
|
1322
|
+
projector.refresh(true);
|
|
1323
|
+
moved = true;
|
|
1324
|
+
break;
|
|
316
1325
|
}
|
|
317
|
-
|
|
318
|
-
|
|
1326
|
+
case 1: {
|
|
1327
|
+
if (options?.onDrag) {
|
|
1328
|
+
target = projector.findNode(event.x, event.y, 16);
|
|
1329
|
+
if (source === target) {
|
|
1330
|
+
select2(context.svg).attr("cursor", void 0);
|
|
1331
|
+
options?.onDrag?.();
|
|
1332
|
+
} else {
|
|
1333
|
+
select2(context.svg).attr("cursor", target ? "alias" : "cell");
|
|
1334
|
+
options?.onDrag?.(source, target, point);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
}).on("end", function(event) {
|
|
1340
|
+
select2(context.svg).attr("cursor", void 0);
|
|
1341
|
+
select2(this.parentElement).classed("dragging", false);
|
|
1342
|
+
switch (mode) {
|
|
1343
|
+
case 1: {
|
|
1344
|
+
options?.onDrop?.(source, target);
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
if (!keyMod(event.sourceEvent, "freezeMod")) {
|
|
1349
|
+
event.subject.fx = null;
|
|
1350
|
+
event.subject.fy = null;
|
|
1351
|
+
}
|
|
1352
|
+
mode = void 0;
|
|
1353
|
+
source = void 0;
|
|
1354
|
+
target = void 0;
|
|
1355
|
+
offset = void 0;
|
|
1356
|
+
if (moved) {
|
|
1357
|
+
projector.refresh(false);
|
|
1358
|
+
moved = false;
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
319
1361
|
};
|
|
320
1362
|
|
|
321
1363
|
// src/graph/projector/graph-force-projector.ts
|
|
322
1364
|
import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
|
|
323
|
-
import { log } from "@dxos/log";
|
|
1365
|
+
import { log as log4 } from "@dxos/log";
|
|
324
1366
|
|
|
325
1367
|
// src/graph/projector/graph-forces.ts
|
|
326
1368
|
import { forceX, forceY } from "d3";
|
|
@@ -339,20 +1381,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
339
1381
|
};
|
|
340
1382
|
|
|
341
1383
|
// src/graph/projector/graph-force-projector.ts
|
|
342
|
-
|
|
343
|
-
if (key in obj) {
|
|
344
|
-
Object.defineProperty(obj, key, {
|
|
345
|
-
value,
|
|
346
|
-
enumerable: true,
|
|
347
|
-
configurable: true,
|
|
348
|
-
writable: true
|
|
349
|
-
});
|
|
350
|
-
} else {
|
|
351
|
-
obj[key] = value;
|
|
352
|
-
}
|
|
353
|
-
return obj;
|
|
354
|
-
}
|
|
355
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
1384
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
356
1385
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
357
1386
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
358
1387
|
};
|
|
@@ -369,6 +1398,9 @@ var defaultForceOptions = {
|
|
|
369
1398
|
point: true
|
|
370
1399
|
};
|
|
371
1400
|
var GraphForceProjector = class extends GraphProjector {
|
|
1401
|
+
// https://github.com/d3/d3-force
|
|
1402
|
+
_simulation = forceSimulation();
|
|
1403
|
+
_timeout;
|
|
372
1404
|
get forces() {
|
|
373
1405
|
return this.options.forces ?? defaultForceOptions;
|
|
374
1406
|
}
|
|
@@ -399,7 +1431,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
399
1431
|
} else {
|
|
400
1432
|
this.updateForces(this.forces);
|
|
401
1433
|
}
|
|
402
|
-
this._simulation.on("tick", () => propagating && this.emitUpdate()).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
|
|
1434
|
+
this._simulation.on("tick", () => propagating && this.emitUpdate("positions")).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
|
|
403
1435
|
}
|
|
404
1436
|
async onStop() {
|
|
405
1437
|
clearTimeout(this._timeout);
|
|
@@ -416,21 +1448,17 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
416
1448
|
this.restart();
|
|
417
1449
|
}
|
|
418
1450
|
onUpdate(graph) {
|
|
419
|
-
|
|
1451
|
+
log4("onUpdate", {
|
|
420
1452
|
graph: {
|
|
421
1453
|
nodes: graph?.nodes.length,
|
|
422
1454
|
edges: graph?.edges.length
|
|
423
1455
|
}
|
|
424
|
-
}, {
|
|
425
|
-
F: __dxlog_file2,
|
|
426
|
-
L: 227,
|
|
427
|
-
S: this,
|
|
428
|
-
C: (f, a) => f(...a)
|
|
429
|
-
});
|
|
1456
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 90, S: this });
|
|
430
1457
|
this._simulation.stop();
|
|
431
1458
|
this.mergeData(graph);
|
|
432
1459
|
this.updateLayout();
|
|
433
1460
|
this.updateForces(this.forces);
|
|
1461
|
+
this.emitUpdate("topology");
|
|
434
1462
|
this.restart();
|
|
435
1463
|
}
|
|
436
1464
|
updateLayout() {
|
|
@@ -474,14 +1502,9 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
474
1502
|
* Update all forces.
|
|
475
1503
|
*/
|
|
476
1504
|
updateForces(forces) {
|
|
477
|
-
|
|
1505
|
+
log4("updateForces", {
|
|
478
1506
|
forces
|
|
479
|
-
}, {
|
|
480
|
-
F: __dxlog_file2,
|
|
481
|
-
L: 288,
|
|
482
|
-
S: this,
|
|
483
|
-
C: (f, a) => f(...a)
|
|
484
|
-
});
|
|
1507
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 152, S: this });
|
|
485
1508
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
486
1509
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
487
1510
|
if (config.distance != null) {
|
|
@@ -529,176 +1552,36 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
529
1552
|
strength
|
|
530
1553
|
});
|
|
531
1554
|
})).force("x", maybeForce(forces?.x, (config) => {
|
|
532
|
-
const force = forceX2(config.x ?? 0);
|
|
533
|
-
if (config.strength != null) {
|
|
534
|
-
force.strength(config.strength);
|
|
535
|
-
}
|
|
536
|
-
return force;
|
|
537
|
-
})).force("y", maybeForce(forces?.y, (config) => {
|
|
538
|
-
const force = forceY2(config.y ?? 0);
|
|
539
|
-
if (config.strength != null) {
|
|
540
|
-
force.strength(config.strength);
|
|
541
|
-
}
|
|
542
|
-
return force;
|
|
543
|
-
}));
|
|
544
|
-
}
|
|
545
|
-
constructor(...args) {
|
|
546
|
-
super(...args), // https://github.com/d3/d3-force
|
|
547
|
-
_define_property3(this, "_simulation", forceSimulation()), _define_property3(this, "_timeout", void 0);
|
|
548
|
-
}
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
// src/graph/projector/graph-hierarchical-projector.ts
|
|
552
|
-
import { log as log3 } from "@dxos/log";
|
|
553
|
-
|
|
554
|
-
// src/graph/projector/graph-radial-projector.ts
|
|
555
|
-
import { easeCubic, timer } from "d3";
|
|
556
|
-
import { log as log2 } from "@dxos/log";
|
|
557
|
-
function _define_property4(obj, key, value) {
|
|
558
|
-
if (key in obj) {
|
|
559
|
-
Object.defineProperty(obj, key, {
|
|
560
|
-
value,
|
|
561
|
-
enumerable: true,
|
|
562
|
-
configurable: true,
|
|
563
|
-
writable: true
|
|
564
|
-
});
|
|
565
|
-
} else {
|
|
566
|
-
obj[key] = value;
|
|
567
|
-
}
|
|
568
|
-
return obj;
|
|
569
|
-
}
|
|
570
|
-
var __dxlog_file3 = "/__w/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
|
-
log2("onUpdate", {
|
|
577
|
-
graph: {
|
|
578
|
-
nodes: graph?.nodes.length,
|
|
579
|
-
edges: graph?.edges.length
|
|
580
|
-
}
|
|
581
|
-
}, {
|
|
582
|
-
F: __dxlog_file3,
|
|
583
|
-
L: 32,
|
|
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 = timer(() => {
|
|
594
|
-
const t = Math.min(1, (Date.now() - start) / this.options.duration);
|
|
595
|
-
const d = 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
|
-
constructor(...args) {
|
|
630
|
-
super(...args), _define_property4(this, "_timer", void 0);
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
634
|
-
const sx = node.x ?? tx;
|
|
635
|
-
const sy = node.y ?? ty;
|
|
636
|
-
const sr = node.r ?? tr;
|
|
637
|
-
Object.assign(node, {
|
|
638
|
-
initialized: true,
|
|
639
|
-
// Start.
|
|
640
|
-
sx,
|
|
641
|
-
sy,
|
|
642
|
-
sr,
|
|
643
|
-
// Target.
|
|
644
|
-
tx,
|
|
645
|
-
ty,
|
|
646
|
-
tr,
|
|
647
|
-
// Current.
|
|
648
|
-
x: sx,
|
|
649
|
-
y: sy,
|
|
650
|
-
r: sr
|
|
651
|
-
});
|
|
652
|
-
};
|
|
653
|
-
var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
|
|
654
|
-
const da = 2 * Math.PI / n;
|
|
655
|
-
return (i) => {
|
|
656
|
-
const a = start + i * da;
|
|
657
|
-
return [
|
|
658
|
-
x + Math.cos(a) * r,
|
|
659
|
-
y + Math.sin(a) * r
|
|
660
|
-
];
|
|
661
|
-
};
|
|
662
|
-
};
|
|
663
|
-
var layoutHorizontal = (x, y, w, n) => {
|
|
664
|
-
const dx = n > 1 ? w / (n - 1) : 0;
|
|
665
|
-
const sx = x - (n - 1) * dx / 2;
|
|
666
|
-
return (i) => {
|
|
667
|
-
return [
|
|
668
|
-
sx + i * dx,
|
|
669
|
-
y
|
|
670
|
-
];
|
|
671
|
-
};
|
|
672
|
-
};
|
|
673
|
-
var layoutVertical = (x, y, h, n) => {
|
|
674
|
-
const dy = n > 1 ? h / (n - 1) : 0;
|
|
675
|
-
const sy = y - (n - 1) * dy / 2;
|
|
676
|
-
return (i) => {
|
|
677
|
-
return [
|
|
678
|
-
x,
|
|
679
|
-
sy + i * dy
|
|
680
|
-
];
|
|
681
|
-
};
|
|
1555
|
+
const force = forceX2(config.x ?? 0);
|
|
1556
|
+
if (config.strength != null) {
|
|
1557
|
+
force.strength(config.strength);
|
|
1558
|
+
}
|
|
1559
|
+
return force;
|
|
1560
|
+
})).force("y", maybeForce(forces?.y, (config) => {
|
|
1561
|
+
const force = forceY2(config.y ?? 0);
|
|
1562
|
+
if (config.strength != null) {
|
|
1563
|
+
force.strength(config.strength);
|
|
1564
|
+
}
|
|
1565
|
+
return force;
|
|
1566
|
+
}));
|
|
1567
|
+
}
|
|
682
1568
|
};
|
|
683
1569
|
|
|
684
1570
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
685
|
-
|
|
1571
|
+
import { log as log5 } from "@dxos/log";
|
|
1572
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
686
1573
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
687
1574
|
onUpdate(graph) {
|
|
688
|
-
|
|
1575
|
+
log5("onUpdate", {
|
|
689
1576
|
graph: {
|
|
690
1577
|
nodes: graph?.nodes.length,
|
|
691
1578
|
edges: graph?.edges.length
|
|
692
1579
|
},
|
|
693
|
-
selection: this.selection?.
|
|
694
|
-
}, {
|
|
695
|
-
F: __dxlog_file4,
|
|
696
|
-
L: 24,
|
|
697
|
-
S: this,
|
|
698
|
-
C: (f, a) => f(...a)
|
|
699
|
-
});
|
|
1580
|
+
selection: this.selection?.getSelectedIds()
|
|
1581
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 8, S: this });
|
|
700
1582
|
this.mergeData(graph);
|
|
701
|
-
|
|
1583
|
+
this.emitUpdate("topology");
|
|
1584
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
702
1585
|
if (selected) {
|
|
703
1586
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
704
1587
|
if (node) {
|
|
@@ -743,25 +1626,72 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
743
1626
|
}
|
|
744
1627
|
};
|
|
745
1628
|
|
|
1629
|
+
// src/graph/projector/graph-lattice-projector.ts
|
|
1630
|
+
import { log as log6 } from "@dxos/log";
|
|
1631
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-lattice-projector.ts";
|
|
1632
|
+
var GraphLatticeProjector = class extends GraphRadialProjector {
|
|
1633
|
+
onUpdate(graph) {
|
|
1634
|
+
log6("onUpdate", {
|
|
1635
|
+
graph: {
|
|
1636
|
+
nodes: graph?.nodes.length,
|
|
1637
|
+
edges: graph?.edges.length
|
|
1638
|
+
}
|
|
1639
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 14, S: this });
|
|
1640
|
+
this.mergeData(graph);
|
|
1641
|
+
this.doLatticeLayout();
|
|
1642
|
+
this.emitUpdate("topology");
|
|
1643
|
+
this.animate();
|
|
1644
|
+
}
|
|
1645
|
+
doLatticeLayout() {
|
|
1646
|
+
if (!this.context.size) {
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1649
|
+
const nodes = this.layout.graph.nodes;
|
|
1650
|
+
const count = nodes.length;
|
|
1651
|
+
if (!count) {
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
const sortBy = this.options.sortBy ?? ((n) => n.data?.label ?? n.id);
|
|
1655
|
+
nodes.sort((a, b) => sortBy(a).localeCompare(sortBy(b)));
|
|
1656
|
+
const columns = Math.max(1, Math.ceil(Math.sqrt(count)));
|
|
1657
|
+
const rows = Math.ceil(count / columns);
|
|
1658
|
+
const margin = this.options.margin ?? 16;
|
|
1659
|
+
const { width, height } = this.context.size;
|
|
1660
|
+
const innerW = Math.max(0, width - 2 * margin);
|
|
1661
|
+
const innerH = Math.max(0, height - 2 * margin);
|
|
1662
|
+
const r = this.options.radius ?? 6;
|
|
1663
|
+
const fit = Math.min(innerW / columns, innerH / rows);
|
|
1664
|
+
const cellSize = Math.max(0, Math.min(fit, r * 6));
|
|
1665
|
+
const gridW = cellSize * columns;
|
|
1666
|
+
const gridH = cellSize * rows;
|
|
1667
|
+
const offsetX = -gridW / 2 + cellSize / 2;
|
|
1668
|
+
const offsetY = -gridH / 2 + cellSize / 2;
|
|
1669
|
+
nodes.forEach((node, i) => {
|
|
1670
|
+
const tx = offsetX + i % columns * cellSize;
|
|
1671
|
+
const ty = offsetY + Math.floor(i / columns) * cellSize;
|
|
1672
|
+
updateNode(node, [
|
|
1673
|
+
tx,
|
|
1674
|
+
ty
|
|
1675
|
+
], r);
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
|
|
746
1680
|
// src/graph/projector/graph-relational-projector.ts
|
|
747
|
-
import { log as
|
|
748
|
-
var
|
|
1681
|
+
import { log as log7 } from "@dxos/log";
|
|
1682
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
749
1683
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
750
1684
|
onUpdate(graph) {
|
|
751
|
-
|
|
1685
|
+
log7("onUpdate", {
|
|
752
1686
|
graph: {
|
|
753
1687
|
nodes: graph?.nodes.length,
|
|
754
1688
|
edges: graph?.edges.length
|
|
755
1689
|
},
|
|
756
|
-
selection: this.selection?.
|
|
757
|
-
}, {
|
|
758
|
-
F: __dxlog_file5,
|
|
759
|
-
L: 24,
|
|
760
|
-
S: this,
|
|
761
|
-
C: (f, a) => f(...a)
|
|
762
|
-
});
|
|
1690
|
+
selection: this.selection?.getSelectedIds()
|
|
1691
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 8, S: this });
|
|
763
1692
|
this.mergeData(graph);
|
|
764
|
-
|
|
1693
|
+
this.emitUpdate("topology");
|
|
1694
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
765
1695
|
if (selected) {
|
|
766
1696
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
767
1697
|
if (node) {
|
|
@@ -835,7 +1765,7 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
835
1765
|
// src/graph/renderer/graph-renderer.ts
|
|
836
1766
|
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
837
1767
|
import * as Clipper from "js-clipper";
|
|
838
|
-
import { log as
|
|
1768
|
+
import { log as log8 } from "@dxos/log";
|
|
839
1769
|
|
|
840
1770
|
// src/graph/renderer/bullets.ts
|
|
841
1771
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
@@ -868,63 +1798,62 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
868
1798
|
};
|
|
869
1799
|
|
|
870
1800
|
// src/graph/renderer/renderer.ts
|
|
871
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
872
|
-
function _define_property5(obj, key, value) {
|
|
873
|
-
if (key in obj) {
|
|
874
|
-
Object.defineProperty(obj, key, {
|
|
875
|
-
value,
|
|
876
|
-
enumerable: true,
|
|
877
|
-
configurable: true,
|
|
878
|
-
writable: true
|
|
879
|
-
});
|
|
880
|
-
} else {
|
|
881
|
-
obj[key] = value;
|
|
882
|
-
}
|
|
883
|
-
return obj;
|
|
884
|
-
}
|
|
885
|
-
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
886
1801
|
var Renderer = class {
|
|
1802
|
+
_context;
|
|
1803
|
+
_root;
|
|
1804
|
+
_options;
|
|
1805
|
+
constructor(_context, _root, options) {
|
|
1806
|
+
this._context = _context;
|
|
1807
|
+
this._root = _root;
|
|
1808
|
+
this._options = Object.assign({
|
|
1809
|
+
idAccessor: defaultIdAccessor
|
|
1810
|
+
}, options);
|
|
1811
|
+
}
|
|
887
1812
|
get context() {
|
|
888
1813
|
return this._context;
|
|
889
1814
|
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Returns the SVG group root if mounted.
|
|
1817
|
+
* The ref may be null between mount/unmount cycles or before the SVG container has sized.
|
|
1818
|
+
* Callers should treat null as "skip this render" rather than as an error.
|
|
1819
|
+
*/
|
|
890
1820
|
get root() {
|
|
891
|
-
invariant2(this._root.current, "SVG root is not initialized", {
|
|
892
|
-
F: __dxlog_file6,
|
|
893
|
-
L: 40,
|
|
894
|
-
S: this,
|
|
895
|
-
A: [
|
|
896
|
-
"this._root.current",
|
|
897
|
-
"'SVG root is not initialized'"
|
|
898
|
-
]
|
|
899
|
-
});
|
|
900
1821
|
return this._root.current;
|
|
901
1822
|
}
|
|
902
1823
|
get options() {
|
|
903
1824
|
return this._options;
|
|
904
1825
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
this.
|
|
912
|
-
idAccessor: defaultIdAccessor
|
|
913
|
-
}, options);
|
|
1826
|
+
/**
|
|
1827
|
+
* Fast path invoked when only positions changed.
|
|
1828
|
+
* Default falls back to a full `render`; subclasses can override to skip
|
|
1829
|
+
* enter/exit joins and attribute callbacks for per-tick updates.
|
|
1830
|
+
*/
|
|
1831
|
+
applyPositions(layout) {
|
|
1832
|
+
this.render(layout);
|
|
914
1833
|
}
|
|
915
1834
|
};
|
|
916
1835
|
|
|
917
1836
|
// src/graph/renderer/graph-renderer.ts
|
|
918
|
-
var
|
|
1837
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
919
1838
|
var createLine2 = line2();
|
|
1839
|
+
var EDGE_FADE_MS = 300;
|
|
1840
|
+
var NODE_HIDE_MS = 500;
|
|
920
1841
|
var GraphRenderer = class extends Renderer {
|
|
1842
|
+
// First render of this instance — used to clear DOM left behind by a previous
|
|
1843
|
+
// renderer pointing at the same `<g>` (e.g. when the consumer swaps projectors
|
|
1844
|
+
// and a new renderer is constructed for the same SVG root). Without this, the
|
|
1845
|
+
// previous variant's node shapes (e.g. circles) would persist as d3.join sees
|
|
1846
|
+
// them in the `update` set instead of `enter`.
|
|
1847
|
+
#firstRender = true;
|
|
921
1848
|
render(layout) {
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1849
|
+
if (!this.root) {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
if (this.#firstRender) {
|
|
1853
|
+
this.#firstRender = false;
|
|
1854
|
+
this.root.replaceChildren();
|
|
1855
|
+
}
|
|
1856
|
+
log8("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 35, S: this });
|
|
928
1857
|
const root = select4(this.root);
|
|
929
1858
|
if (layout.guides) {
|
|
930
1859
|
root.selectAll("g.dx-guides").data([
|
|
@@ -988,31 +1917,82 @@ var GraphRenderer = class extends Renderer {
|
|
|
988
1917
|
id: "nodes"
|
|
989
1918
|
}
|
|
990
1919
|
], (d) => d.id).join("g").classed("dx-nodes", true);
|
|
991
|
-
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
|
|
1920
|
+
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", (d) => d.hidden ? 0 : 1).classed("dx-node", true).call(createNode, this.options), (update) => update, (exit) => {
|
|
992
1921
|
return exit.transition().ease(easeCubicOut).duration(300).attr("opacity", 0).on("end", function(d) {
|
|
993
1922
|
select4(this).remove();
|
|
994
1923
|
});
|
|
995
|
-
}).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
996
|
-
edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
|
|
997
|
-
|
|
1924
|
+
}).call(updateNode2, this.options).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
1925
|
+
edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
|
|
1926
|
+
(enter) => enter.append("g").attr("data-id", (d) => d.id).classed("dx-edge", true).call(createEdge, this.options),
|
|
1927
|
+
(update) => update,
|
|
1928
|
+
// Exit fade: edges removed by a topology change (e.g. variant switch from cluster
|
|
1929
|
+
// back to force replaces hierarchy edges with data edges) ease out rather than pop.
|
|
1930
|
+
(exit) => exit.transition().ease(easeCubicOut).duration(EDGE_FADE_MS).attr("opacity", 0).on("end", function() {
|
|
1931
|
+
select4(this).remove();
|
|
1932
|
+
})
|
|
1933
|
+
).call(updateEdge, this.options, nodeGroup).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
1934
|
+
}
|
|
1935
|
+
/**
|
|
1936
|
+
* Fast positions-only update. Skips enter/exit, attribute callbacks, label sizing,
|
|
1937
|
+
* and the subgraph hull pass; just writes `transform` per node and `d` per edge.
|
|
1938
|
+
* Called per simulation tick / animation frame.
|
|
1939
|
+
*/
|
|
1940
|
+
applyPositions(layout) {
|
|
1941
|
+
if (!this.root) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
const root = select4(this.root);
|
|
1945
|
+
root.select("g.dx-nodes").selectAll("g.dx-node").attr("transform", (d) => d.x != null && d.y != null ? `translate(${d.x},${d.y})` : null);
|
|
1946
|
+
root.select("g.dx-edges").selectAll("g.dx-edge").selectAll("path").attr("d", function() {
|
|
1947
|
+
const edge = select4(this.parentElement).datum();
|
|
1948
|
+
if (edge.path) {
|
|
1949
|
+
return edge.path;
|
|
1950
|
+
}
|
|
1951
|
+
const { source, target } = edge;
|
|
1952
|
+
if (!source.initialized || !target.initialized) {
|
|
1953
|
+
return null;
|
|
1954
|
+
}
|
|
1955
|
+
return createLine2(getCircumferencePoints([
|
|
1956
|
+
source.x,
|
|
1957
|
+
source.y
|
|
1958
|
+
], [
|
|
1959
|
+
target.x,
|
|
1960
|
+
target.y
|
|
1961
|
+
], source.r, target.r));
|
|
1962
|
+
});
|
|
998
1963
|
}
|
|
999
1964
|
/**
|
|
1000
1965
|
* Trigger path bullets.
|
|
1001
1966
|
* @param node
|
|
1002
1967
|
*/
|
|
1003
1968
|
fireBullet(node) {
|
|
1969
|
+
if (!this.root) {
|
|
1970
|
+
return;
|
|
1971
|
+
}
|
|
1004
1972
|
select4(this.root).selectAll("g.dx-edges").selectAll("path").call(createBullets(this.root, node.id));
|
|
1005
1973
|
}
|
|
1006
1974
|
};
|
|
1975
|
+
var SHAPE_CLASS = "dx-shape";
|
|
1976
|
+
var renderCustomShape = (group, options) => {
|
|
1977
|
+
group.each(function(d) {
|
|
1978
|
+
const g = select4(this);
|
|
1979
|
+
g.selectAll(`.${SHAPE_CLASS}`).remove();
|
|
1980
|
+
const shapeGroup = g.append("g").classed(SHAPE_CLASS, true);
|
|
1981
|
+
options.renderNode(shapeGroup, d);
|
|
1982
|
+
});
|
|
1983
|
+
};
|
|
1007
1984
|
var createNode = (group, options) => {
|
|
1008
|
-
const
|
|
1985
|
+
const useCustom = !!options.renderNode;
|
|
1986
|
+
if (useCustom) {
|
|
1987
|
+
renderCustomShape(group, options);
|
|
1988
|
+
}
|
|
1989
|
+
const hitTarget = useCustom ? group : group.append("circle");
|
|
1009
1990
|
if (options.drag) {
|
|
1010
|
-
|
|
1991
|
+
hitTarget.call(options.drag);
|
|
1011
1992
|
}
|
|
1012
1993
|
if (options.onNodeClick) {
|
|
1013
|
-
group.on("click", (event) => {
|
|
1014
|
-
|
|
1015
|
-
options.onNodeClick(node, event);
|
|
1994
|
+
group.on("click", (event, d) => {
|
|
1995
|
+
options.onNodeClick(d, event);
|
|
1016
1996
|
});
|
|
1017
1997
|
}
|
|
1018
1998
|
if (options.labels && !options.onNodePointerEnter) {
|
|
@@ -1021,24 +2001,28 @@ var createNode = (group, options) => {
|
|
|
1021
2001
|
g.append("rect");
|
|
1022
2002
|
g.append("text").style("dominant-baseline", "middle");
|
|
1023
2003
|
}
|
|
1024
|
-
if (options.onNodePointerEnter) {
|
|
1025
|
-
|
|
1026
|
-
const node = select4(this.parentElement).datum();
|
|
1027
|
-
options.onNodePointerEnter(node, event);
|
|
2004
|
+
if (options.onNodePointerEnter || options.onNodePointerLeave) {
|
|
2005
|
+
hitTarget.on("pointerenter", function(event) {
|
|
2006
|
+
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2007
|
+
options.onNodePointerEnter?.(node, event);
|
|
2008
|
+
});
|
|
2009
|
+
hitTarget.on("pointerleave", function(event) {
|
|
2010
|
+
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2011
|
+
options.onNodePointerLeave?.(node, event);
|
|
1028
2012
|
});
|
|
1029
2013
|
group.attr("data-hover", "handled");
|
|
1030
|
-
} else if (options.highlight !== false) {
|
|
1031
|
-
|
|
2014
|
+
} else if (options.highlight !== false && !useCustom) {
|
|
2015
|
+
hitTarget.on("pointerenter", function() {
|
|
1032
2016
|
select4(this.closest("g.dx-node")).raise();
|
|
1033
2017
|
if (options.labels) {
|
|
1034
|
-
select4(this.parentElement).classed("dx-active", true).classed("dx-highlight", true);
|
|
2018
|
+
select4(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
|
|
1035
2019
|
}
|
|
1036
2020
|
});
|
|
1037
2021
|
group.on("pointerleave", function() {
|
|
1038
2022
|
if (options.labels) {
|
|
1039
|
-
select4(this).classed("dx-active", false);
|
|
2023
|
+
select4(this).classed("dx-node-active", false);
|
|
1040
2024
|
setTimeout(() => {
|
|
1041
|
-
if (!select4(this).classed("dx-active")) {
|
|
2025
|
+
if (!select4(this).classed("dx-node-active")) {
|
|
1042
2026
|
select4(this).classed("dx-highlight", false);
|
|
1043
2027
|
}
|
|
1044
2028
|
}, 300);
|
|
@@ -1050,6 +2034,11 @@ var updateNode2 = (group, options) => {
|
|
|
1050
2034
|
group.attr("transform", (d) => {
|
|
1051
2035
|
return d.x != null && d.y != null ? `translate(${d.x},${d.y})` : void 0;
|
|
1052
2036
|
});
|
|
2037
|
+
group.classed("dx-hidden", (d) => d.hidden ?? false);
|
|
2038
|
+
group.transition("hide").ease(easeCubicOut).duration(NODE_HIDE_MS).attr("opacity", (d) => d.hidden ? 0 : 1);
|
|
2039
|
+
if (options.renderNode) {
|
|
2040
|
+
renderCustomShape(group, options);
|
|
2041
|
+
}
|
|
1053
2042
|
if (options.attributes?.node) {
|
|
1054
2043
|
try {
|
|
1055
2044
|
group.each((d, i, nodes) => {
|
|
@@ -1065,18 +2054,15 @@ var updateNode2 = (group, options) => {
|
|
|
1065
2054
|
}
|
|
1066
2055
|
});
|
|
1067
2056
|
} catch (error) {
|
|
1068
|
-
|
|
2057
|
+
log8.error("updateNode", {
|
|
1069
2058
|
error: error?.message
|
|
1070
|
-
}, {
|
|
1071
|
-
F: __dxlog_file7,
|
|
1072
|
-
L: 305,
|
|
1073
|
-
S: void 0,
|
|
1074
|
-
C: (f, a) => f(...a)
|
|
1075
|
-
});
|
|
2059
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 292, S: void 0 });
|
|
1076
2060
|
}
|
|
1077
2061
|
}
|
|
1078
2062
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1079
|
-
|
|
2063
|
+
if (!options.renderNode) {
|
|
2064
|
+
groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
|
|
2065
|
+
}
|
|
1080
2066
|
if (options.labels) {
|
|
1081
2067
|
const bx = 1;
|
|
1082
2068
|
const px = 4;
|
|
@@ -1121,18 +2107,17 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1121
2107
|
}
|
|
1122
2108
|
});
|
|
1123
2109
|
} catch (error) {
|
|
1124
|
-
|
|
2110
|
+
log8.error("updateEdge", {
|
|
1125
2111
|
error: error?.message
|
|
1126
|
-
}, {
|
|
1127
|
-
F: __dxlog_file7,
|
|
1128
|
-
L: 417,
|
|
1129
|
-
S: void 0,
|
|
1130
|
-
C: (f, a) => f(...a)
|
|
1131
|
-
});
|
|
2112
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 360, S: void 0 });
|
|
1132
2113
|
}
|
|
1133
2114
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1134
2115
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
1135
|
-
const
|
|
2116
|
+
const edge = select4(this.parentElement).datum();
|
|
2117
|
+
if (edge.path) {
|
|
2118
|
+
return edge.path;
|
|
2119
|
+
}
|
|
2120
|
+
const { source, target } = edge;
|
|
1136
2121
|
if (!source.initialized || !target.initialized) {
|
|
1137
2122
|
return;
|
|
1138
2123
|
}
|
|
@@ -1206,117 +2191,451 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1206
2191
|
});
|
|
1207
2192
|
};
|
|
1208
2193
|
|
|
2194
|
+
// src/hooks/useGrid.ts
|
|
2195
|
+
import { line as line4, range, select as select5 } from "d3";
|
|
2196
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2197
|
+
|
|
2198
|
+
// src/hooks/useSvgContext.ts
|
|
2199
|
+
import { createContext, useContext } from "react";
|
|
2200
|
+
import { createRef } from "react";
|
|
2201
|
+
import { raise } from "@dxos/debug";
|
|
2202
|
+
var SVGContext = class {
|
|
2203
|
+
_ref = createRef();
|
|
2204
|
+
_scale;
|
|
2205
|
+
_centered;
|
|
2206
|
+
_size;
|
|
2207
|
+
_center;
|
|
2208
|
+
resized = new EventEmitter();
|
|
2209
|
+
constructor({ scale = new Scale(), centered = true }) {
|
|
2210
|
+
this._scale = scale;
|
|
2211
|
+
this._centered = centered;
|
|
2212
|
+
}
|
|
2213
|
+
get ref() {
|
|
2214
|
+
return this._ref;
|
|
2215
|
+
}
|
|
2216
|
+
get svg() {
|
|
2217
|
+
return this._ref.current;
|
|
2218
|
+
}
|
|
2219
|
+
get scale() {
|
|
2220
|
+
return this._scale;
|
|
2221
|
+
}
|
|
2222
|
+
get center() {
|
|
2223
|
+
return this._center;
|
|
2224
|
+
}
|
|
2225
|
+
get size() {
|
|
2226
|
+
return this._size;
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
|
|
2230
|
+
*/
|
|
2231
|
+
get viewBox() {
|
|
2232
|
+
const [x, y] = this.center;
|
|
2233
|
+
return `${x},${y},${this._size.width},${this._size.height}`;
|
|
2234
|
+
}
|
|
2235
|
+
setSize(size) {
|
|
2236
|
+
this._size = {
|
|
2237
|
+
...size
|
|
2238
|
+
};
|
|
2239
|
+
this._center = this._centered ? [
|
|
2240
|
+
-Math.floor(size.width / 2),
|
|
2241
|
+
-Math.floor(size.height / 2)
|
|
2242
|
+
] : [
|
|
2243
|
+
0,
|
|
2244
|
+
0
|
|
2245
|
+
];
|
|
2246
|
+
this.resized.emit(this);
|
|
2247
|
+
}
|
|
2248
|
+
setTransform(transform) {
|
|
2249
|
+
if (this._scale.setTransform(transform)) {
|
|
2250
|
+
this.resized.emit(this);
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
/**
|
|
2254
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
|
|
2255
|
+
* @param point
|
|
2256
|
+
*/
|
|
2257
|
+
elementFromPoint(point) {
|
|
2258
|
+
const [x, y] = point;
|
|
2259
|
+
const [cx, cy] = this._center;
|
|
2260
|
+
return document.elementFromPoint(cx + x, cy + y);
|
|
2261
|
+
}
|
|
2262
|
+
};
|
|
2263
|
+
var SVGContextType = createContext(void 0);
|
|
2264
|
+
var SVGContextProvider = SVGContextType.Provider;
|
|
2265
|
+
var useSvgContext = () => {
|
|
2266
|
+
return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
|
|
2267
|
+
};
|
|
2268
|
+
|
|
2269
|
+
// src/hooks/useGrid.ts
|
|
2270
|
+
var createLine4 = line4();
|
|
2271
|
+
var createGrid = (context, options) => {
|
|
2272
|
+
if (!context.size) {
|
|
2273
|
+
return [];
|
|
2274
|
+
}
|
|
2275
|
+
const paths = [];
|
|
2276
|
+
const { width, height } = context.size;
|
|
2277
|
+
const { x, y, k } = context.scale.transform;
|
|
2278
|
+
const s = 1 / k;
|
|
2279
|
+
const w = width * s;
|
|
2280
|
+
const h = height * s;
|
|
2281
|
+
const dx = -(x + width / 2) * s;
|
|
2282
|
+
const dy = -(y + height / 2) * s;
|
|
2283
|
+
if (options.axis) {
|
|
2284
|
+
const axis = [
|
|
2285
|
+
[
|
|
2286
|
+
[
|
|
2287
|
+
0,
|
|
2288
|
+
dy
|
|
2289
|
+
],
|
|
2290
|
+
[
|
|
2291
|
+
0,
|
|
2292
|
+
dy + h
|
|
2293
|
+
]
|
|
2294
|
+
],
|
|
2295
|
+
[
|
|
2296
|
+
[
|
|
2297
|
+
dx,
|
|
2298
|
+
0
|
|
2299
|
+
],
|
|
2300
|
+
[
|
|
2301
|
+
dx + w,
|
|
2302
|
+
0
|
|
2303
|
+
]
|
|
2304
|
+
]
|
|
2305
|
+
];
|
|
2306
|
+
paths.push({
|
|
2307
|
+
id: "axis",
|
|
2308
|
+
class: "dx-axis",
|
|
2309
|
+
path: axis.map((line5) => createLine4(line5)).join()
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
if (options.grid) {
|
|
2313
|
+
const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
|
|
2314
|
+
const majorSize = context.scale.gridSize;
|
|
2315
|
+
const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
|
|
2316
|
+
const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
|
|
2317
|
+
const major = [
|
|
2318
|
+
...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
|
|
2319
|
+
[
|
|
2320
|
+
x2,
|
|
2321
|
+
dy
|
|
2322
|
+
],
|
|
2323
|
+
[
|
|
2324
|
+
x2,
|
|
2325
|
+
dy + h
|
|
2326
|
+
]
|
|
2327
|
+
]),
|
|
2328
|
+
...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
|
|
2329
|
+
[
|
|
2330
|
+
dx,
|
|
2331
|
+
y2
|
|
2332
|
+
],
|
|
2333
|
+
[
|
|
2334
|
+
dx + w,
|
|
2335
|
+
y2
|
|
2336
|
+
]
|
|
2337
|
+
])
|
|
2338
|
+
];
|
|
2339
|
+
paths.push({
|
|
2340
|
+
id: "major",
|
|
2341
|
+
class: "dx-major",
|
|
2342
|
+
path: major.map((line5) => createLine4(line5)).join()
|
|
2343
|
+
});
|
|
2344
|
+
const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
|
|
2345
|
+
if (majorSize > minorSize) {
|
|
2346
|
+
const xMinor = range(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
|
|
2347
|
+
const yMinor = range(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
|
|
2348
|
+
const minor = [
|
|
2349
|
+
...xMinor.filter((x2) => xMajor.indexOf(x2) === -1).map((x2) => [
|
|
2350
|
+
[
|
|
2351
|
+
x2,
|
|
2352
|
+
dy
|
|
2353
|
+
],
|
|
2354
|
+
[
|
|
2355
|
+
x2,
|
|
2356
|
+
dy + h
|
|
2357
|
+
]
|
|
2358
|
+
]),
|
|
2359
|
+
...yMinor.filter((y2) => yMajor.indexOf(y2) === -1).map((y2) => [
|
|
2360
|
+
[
|
|
2361
|
+
dx,
|
|
2362
|
+
y2
|
|
2363
|
+
],
|
|
2364
|
+
[
|
|
2365
|
+
dx + w,
|
|
2366
|
+
y2
|
|
2367
|
+
]
|
|
2368
|
+
])
|
|
2369
|
+
];
|
|
2370
|
+
paths.push({
|
|
2371
|
+
id: "minor",
|
|
2372
|
+
class: "dx-minor",
|
|
2373
|
+
path: minor.map((line5) => createLine4(line5)).join()
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
return paths;
|
|
2378
|
+
};
|
|
2379
|
+
var defaultGridOptions = {
|
|
2380
|
+
visible: true,
|
|
2381
|
+
axis: true,
|
|
2382
|
+
grid: true
|
|
2383
|
+
};
|
|
2384
|
+
var GridController = class {
|
|
2385
|
+
_ref;
|
|
2386
|
+
_context;
|
|
2387
|
+
_options;
|
|
2388
|
+
_visible = false;
|
|
2389
|
+
constructor(_ref, _context, _options) {
|
|
2390
|
+
this._ref = _ref;
|
|
2391
|
+
this._context = _context;
|
|
2392
|
+
this._options = _options;
|
|
2393
|
+
this._visible = this._options.visible ?? true;
|
|
2394
|
+
}
|
|
2395
|
+
get ref() {
|
|
2396
|
+
return this._ref;
|
|
2397
|
+
}
|
|
2398
|
+
get visible() {
|
|
2399
|
+
return this._visible;
|
|
2400
|
+
}
|
|
2401
|
+
draw() {
|
|
2402
|
+
if (!this._context.size) {
|
|
2403
|
+
return;
|
|
2404
|
+
}
|
|
2405
|
+
const paths = this._visible ? createGrid(this._context, this._options) : [];
|
|
2406
|
+
const root = select5(this._ref.current);
|
|
2407
|
+
root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
|
|
2408
|
+
const transform = this._context.scale.transform;
|
|
2409
|
+
if (transform) {
|
|
2410
|
+
root.attr("transform", transform);
|
|
2411
|
+
root.attr("stroke-width", 1 / transform.k);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
setVisible(visible) {
|
|
2415
|
+
this._visible = visible;
|
|
2416
|
+
this.draw();
|
|
2417
|
+
return this;
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2420
|
+
var useGrid = (options = defaultGridOptions) => {
|
|
2421
|
+
const ref = useRef(null);
|
|
2422
|
+
const context = useSvgContext();
|
|
2423
|
+
const controller = useMemo(() => new GridController(ref, context, options), []);
|
|
2424
|
+
useEffect(() => context.resized.on(() => controller.draw()), [
|
|
2425
|
+
context,
|
|
2426
|
+
controller
|
|
2427
|
+
]);
|
|
2428
|
+
return controller;
|
|
2429
|
+
};
|
|
2430
|
+
|
|
2431
|
+
// src/hooks/useZoom.ts
|
|
2432
|
+
import { select as select6, zoom, zoomIdentity as zoomIdentity2 } from "d3";
|
|
2433
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
2434
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
2435
|
+
var defaultZoomOptions = {
|
|
2436
|
+
enabled: true,
|
|
2437
|
+
extent: [
|
|
2438
|
+
1 / 4,
|
|
2439
|
+
4
|
|
2440
|
+
],
|
|
2441
|
+
onDblClick: (zoom2) => zoom2.reset()
|
|
2442
|
+
};
|
|
2443
|
+
var ZoomHandler = class {
|
|
2444
|
+
_ref;
|
|
2445
|
+
_context;
|
|
2446
|
+
_zoom;
|
|
2447
|
+
_options;
|
|
2448
|
+
_enabled;
|
|
2449
|
+
constructor(_ref, _context, options) {
|
|
2450
|
+
this._ref = _ref;
|
|
2451
|
+
this._context = _context;
|
|
2452
|
+
this._options = defaultsDeep({}, options, defaultZoomOptions);
|
|
2453
|
+
this._enabled = this._options.enabled ?? true;
|
|
2454
|
+
this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Gets the reference which the transform is applied to.
|
|
2458
|
+
*/
|
|
2459
|
+
get ref() {
|
|
2460
|
+
return this._ref;
|
|
2461
|
+
}
|
|
2462
|
+
get zoom() {
|
|
2463
|
+
return this._zoom;
|
|
2464
|
+
}
|
|
2465
|
+
init() {
|
|
2466
|
+
this.setEnabled(this._enabled);
|
|
2467
|
+
this.reset(0);
|
|
2468
|
+
return this;
|
|
2469
|
+
}
|
|
2470
|
+
setEnabled(enable) {
|
|
2471
|
+
if (enable) {
|
|
2472
|
+
select6(this._context.svg).call(this._zoom).on(
|
|
2473
|
+
"dblclick.zoom",
|
|
2474
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2475
|
+
// @ts-ignore
|
|
2476
|
+
this._options?.onDblClick ? () => {
|
|
2477
|
+
this._options?.onDblClick(this);
|
|
2478
|
+
} : null
|
|
2479
|
+
);
|
|
2480
|
+
} else {
|
|
2481
|
+
select6(this._context.svg).on(".zoom", null);
|
|
2482
|
+
}
|
|
2483
|
+
this._enabled = enable;
|
|
2484
|
+
return this;
|
|
2485
|
+
}
|
|
2486
|
+
reset(duration = 500) {
|
|
2487
|
+
const scale = 1;
|
|
2488
|
+
const transform = zoomIdentity2.scale(scale);
|
|
2489
|
+
select6(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
|
|
2490
|
+
return this;
|
|
2491
|
+
}
|
|
2492
|
+
};
|
|
2493
|
+
var useZoom = (options = defaultZoomOptions) => {
|
|
2494
|
+
const context = useSvgContext();
|
|
2495
|
+
const ref = useRef2(null);
|
|
2496
|
+
const handler = useMemo2(() => new ZoomHandler(ref, context, options), [
|
|
2497
|
+
context,
|
|
2498
|
+
options
|
|
2499
|
+
]);
|
|
2500
|
+
useEffect2(() => {
|
|
2501
|
+
handler.zoom.on("zoom", ({ transform }) => {
|
|
2502
|
+
context.setTransform(transform);
|
|
2503
|
+
select6(ref.current).attr("transform", transform);
|
|
2504
|
+
});
|
|
2505
|
+
handler.init();
|
|
2506
|
+
}, [
|
|
2507
|
+
handler
|
|
2508
|
+
]);
|
|
2509
|
+
return handler;
|
|
2510
|
+
};
|
|
2511
|
+
|
|
1209
2512
|
// src/components/Graph/Graph.tsx
|
|
1210
|
-
var
|
|
1211
|
-
var GraphInner = ({ classNames, model, projector:
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
renderer
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
return
|
|
2513
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
2514
|
+
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
2515
|
+
const context = useSvgContext();
|
|
2516
|
+
const graphRef = useRef3(null);
|
|
2517
|
+
const { projector, renderer } = useMemo3(() => {
|
|
2518
|
+
let projector2 = projectorProp;
|
|
2519
|
+
if (!projector2) {
|
|
2520
|
+
projector2 = new GraphForceProjector(context);
|
|
2521
|
+
}
|
|
2522
|
+
let renderer2 = rendererProp;
|
|
2523
|
+
if (!renderer2) {
|
|
2524
|
+
renderer2 = new GraphRenderer(context, graphRef, {
|
|
2525
|
+
...props,
|
|
2526
|
+
// TODO(burdon): Replace drag when projector is updated.
|
|
2527
|
+
drag: drag2 ? createGraphDrag(context, projector2) : void 0,
|
|
2528
|
+
arrows: {
|
|
2529
|
+
end: arrows
|
|
2530
|
+
},
|
|
2531
|
+
onNodeClick: onSelect,
|
|
2532
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0,
|
|
2533
|
+
// Pair pointerenter with leave so consumers can clear hover-driven previews.
|
|
2534
|
+
// The callback receives `null` on leave (event still carries the source).
|
|
2535
|
+
onNodePointerLeave: onInspect ? (_node, event) => onInspect(null, event) : void 0
|
|
2536
|
+
});
|
|
2537
|
+
}
|
|
2538
|
+
return {
|
|
2539
|
+
projector: projector2,
|
|
2540
|
+
renderer: renderer2
|
|
2541
|
+
};
|
|
2542
|
+
}, [
|
|
2543
|
+
context,
|
|
2544
|
+
projectorProp,
|
|
2545
|
+
rendererProp,
|
|
2546
|
+
drag2,
|
|
2547
|
+
arrows,
|
|
2548
|
+
onSelect,
|
|
2549
|
+
onInspect,
|
|
2550
|
+
props.labels,
|
|
2551
|
+
props.subgraphs,
|
|
2552
|
+
props.attributes,
|
|
2553
|
+
props.renderNode
|
|
2554
|
+
]);
|
|
2555
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
2556
|
+
refresh: () => {
|
|
2557
|
+
projector.updateData(model?.graph);
|
|
2558
|
+
},
|
|
2559
|
+
repaint: () => {
|
|
2560
|
+
renderer.render(projector.layout);
|
|
2561
|
+
},
|
|
2562
|
+
findNode: (id) => {
|
|
2563
|
+
return graphRef.current?.querySelector(`g[data-id="${id}"]`);
|
|
2564
|
+
}
|
|
2565
|
+
}), [
|
|
2566
|
+
model,
|
|
2567
|
+
projector,
|
|
2568
|
+
renderer
|
|
2569
|
+
]);
|
|
2570
|
+
useEffect3(() => {
|
|
2571
|
+
const cleanup = combine(
|
|
2572
|
+
// Subscribe to model changes if reactive model.
|
|
2573
|
+
model ? model.subscribe(() => {
|
|
1261
2574
|
projector.updateData(model?.graph);
|
|
1262
|
-
})
|
|
2575
|
+
}) : void 0,
|
|
2576
|
+
projector.updated.on(({ layout, kind }) => {
|
|
1263
2577
|
try {
|
|
1264
|
-
|
|
2578
|
+
if (kind === "positions") {
|
|
2579
|
+
renderer.applyPositions(layout);
|
|
2580
|
+
} else {
|
|
2581
|
+
renderer.render(layout);
|
|
2582
|
+
}
|
|
1265
2583
|
} catch (error) {
|
|
2584
|
+
log9.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 85, S: void 0 });
|
|
1266
2585
|
void projector.stop();
|
|
1267
|
-
log6.catch(error, void 0, {
|
|
1268
|
-
F: __dxlog_file8,
|
|
1269
|
-
L: 108,
|
|
1270
|
-
S: void 0,
|
|
1271
|
-
C: (f, a) => f(...a)
|
|
1272
|
-
});
|
|
1273
2586
|
}
|
|
1274
|
-
})
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
projector
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
}
|
|
2587
|
+
})
|
|
2588
|
+
);
|
|
2589
|
+
projector.updateData(model?.graph);
|
|
2590
|
+
return cleanup;
|
|
2591
|
+
}, [
|
|
2592
|
+
model,
|
|
2593
|
+
projector,
|
|
2594
|
+
renderer
|
|
2595
|
+
]);
|
|
2596
|
+
useEffect3(() => {
|
|
2597
|
+
void projector.start();
|
|
2598
|
+
return () => {
|
|
2599
|
+
void projector.stop();
|
|
2600
|
+
};
|
|
2601
|
+
}, [
|
|
2602
|
+
projector
|
|
2603
|
+
]);
|
|
2604
|
+
return /* @__PURE__ */ React.createElement("g", {
|
|
2605
|
+
ref: graphRef,
|
|
2606
|
+
className: mx("dx-graph", classNames)
|
|
2607
|
+
});
|
|
1295
2608
|
};
|
|
1296
2609
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1297
2610
|
|
|
1298
2611
|
// src/components/Mesh/Mesh.tsx
|
|
1299
|
-
import { geoPath, select as
|
|
1300
|
-
import { useEffect as
|
|
2612
|
+
import { geoPath, select as select7 } from "d3";
|
|
2613
|
+
import { useEffect as useEffect4 } from "react";
|
|
1301
2614
|
import { feature, mesh } from "topojson-client";
|
|
1302
2615
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1303
2616
|
const { svg, size } = useSvgContext();
|
|
1304
|
-
|
|
1305
|
-
if (size) {
|
|
1306
|
-
|
|
1307
|
-
const projection = hexProjection(radius);
|
|
1308
|
-
const path = geoPath().projection(projection);
|
|
1309
|
-
select5(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);
|
|
1310
|
-
select5(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
1311
|
-
const redraw = (border) => {
|
|
1312
|
-
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1313
|
-
};
|
|
1314
|
-
select5(svg).append("path").attr("class", "border").call(redraw);
|
|
2617
|
+
useEffect4(() => {
|
|
2618
|
+
if (!size) {
|
|
2619
|
+
return;
|
|
1315
2620
|
}
|
|
2621
|
+
const topology = hexTopology(size, radius, value);
|
|
2622
|
+
const projection = hexProjection(radius);
|
|
2623
|
+
const path = geoPath().projection(projection);
|
|
2624
|
+
const root = select7(svg).selectAll("g.dx-mesh-root").data([
|
|
2625
|
+
null
|
|
2626
|
+
]).join("g").classed("dx-mesh-root", true);
|
|
2627
|
+
root.selectAll("*").remove();
|
|
2628
|
+
root.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);
|
|
2629
|
+
root.append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
2630
|
+
const redraw = (border) => {
|
|
2631
|
+
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
2632
|
+
};
|
|
2633
|
+
root.append("path").attr("class", "border").call(redraw);
|
|
1316
2634
|
}, [
|
|
1317
2635
|
svg,
|
|
1318
2636
|
size,
|
|
1319
|
-
value
|
|
2637
|
+
value,
|
|
2638
|
+
radius
|
|
1320
2639
|
]);
|
|
1321
2640
|
return null;
|
|
1322
2641
|
};
|
|
@@ -1428,115 +2747,124 @@ var hexProjection = (radius) => {
|
|
|
1428
2747
|
};
|
|
1429
2748
|
|
|
1430
2749
|
// src/components/SVG/Grid.tsx
|
|
1431
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
1432
2750
|
import React2 from "react";
|
|
1433
|
-
import { mx as mx2 } from "@dxos/
|
|
2751
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
1434
2752
|
var Grid = ({ classNames, ...props }) => {
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
className: mx2("dx-grid", classNames)
|
|
1441
|
-
});
|
|
1442
|
-
} finally {
|
|
1443
|
-
_effect.f();
|
|
1444
|
-
}
|
|
2753
|
+
const { ref } = useGrid(props);
|
|
2754
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
2755
|
+
ref,
|
|
2756
|
+
className: mx2("dx-grid", classNames)
|
|
2757
|
+
});
|
|
1445
2758
|
};
|
|
1446
2759
|
|
|
1447
2760
|
// src/components/SVG/Markers.tsx
|
|
1448
|
-
import {
|
|
1449
|
-
import {
|
|
1450
|
-
import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
2761
|
+
import { select as select8 } from "d3";
|
|
2762
|
+
import React3, { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
1451
2763
|
var Markers = ({ arrowSize, className }) => {
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
className
|
|
1465
|
-
});
|
|
1466
|
-
} finally {
|
|
1467
|
-
_effect.f();
|
|
1468
|
-
}
|
|
2764
|
+
const ref = useRef4(null);
|
|
2765
|
+
useEffect5(() => {
|
|
2766
|
+
select8(ref.current).call(createMarkers({
|
|
2767
|
+
arrowSize
|
|
2768
|
+
}));
|
|
2769
|
+
}, [
|
|
2770
|
+
ref
|
|
2771
|
+
]);
|
|
2772
|
+
return /* @__PURE__ */ React3.createElement("defs", {
|
|
2773
|
+
ref,
|
|
2774
|
+
className
|
|
2775
|
+
});
|
|
1469
2776
|
};
|
|
1470
2777
|
|
|
1471
2778
|
// src/components/SVG/Root.tsx
|
|
1472
|
-
import {
|
|
1473
|
-
import {
|
|
1474
|
-
import
|
|
1475
|
-
import {
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
2779
|
+
import { select as select9 } from "d3";
|
|
2780
|
+
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4, useState } from "react";
|
|
2781
|
+
import { composableProps } from "@dxos/react-ui";
|
|
2782
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
2783
|
+
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
2784
|
+
const [container, setContainer] = useState(null);
|
|
2785
|
+
const [size, setSize] = useState({
|
|
2786
|
+
width: 0,
|
|
2787
|
+
height: 0
|
|
2788
|
+
});
|
|
2789
|
+
useEffect6(() => {
|
|
2790
|
+
if (!container) {
|
|
2791
|
+
return;
|
|
2792
|
+
}
|
|
2793
|
+
const rect = container.getBoundingClientRect();
|
|
2794
|
+
setSize({
|
|
2795
|
+
width: rect.width,
|
|
2796
|
+
height: rect.height
|
|
1482
2797
|
});
|
|
1483
|
-
const
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
props.centered
|
|
1488
|
-
]);
|
|
1489
|
-
useImperativeHandle2(ref, () => context, [
|
|
1490
|
-
context
|
|
1491
|
-
]);
|
|
1492
|
-
useEffect4(() => {
|
|
1493
|
-
if (width && height) {
|
|
1494
|
-
context.setSize({
|
|
1495
|
-
width,
|
|
1496
|
-
height
|
|
1497
|
-
});
|
|
1498
|
-
select7(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
2798
|
+
const observer = new ResizeObserver((entries) => {
|
|
2799
|
+
const entry = entries[0];
|
|
2800
|
+
if (!entry) {
|
|
2801
|
+
return;
|
|
1499
2802
|
}
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
2803
|
+
const { width: width2, height: height2 } = entry.contentRect;
|
|
2804
|
+
setSize((prev) => prev.width === width2 && prev.height === height2 ? prev : {
|
|
2805
|
+
width: width2,
|
|
2806
|
+
height: height2
|
|
2807
|
+
});
|
|
2808
|
+
});
|
|
2809
|
+
observer.observe(container);
|
|
2810
|
+
return () => observer.disconnect();
|
|
2811
|
+
}, [
|
|
2812
|
+
container
|
|
2813
|
+
]);
|
|
2814
|
+
const { width, height } = size;
|
|
2815
|
+
const context = useMemo4(() => {
|
|
2816
|
+
return new SVGContext({
|
|
2817
|
+
scale,
|
|
2818
|
+
centered
|
|
2819
|
+
});
|
|
2820
|
+
}, [
|
|
2821
|
+
scale,
|
|
2822
|
+
centered
|
|
2823
|
+
]);
|
|
2824
|
+
useImperativeHandle2(ref, () => context, [
|
|
2825
|
+
context
|
|
2826
|
+
]);
|
|
2827
|
+
useEffect6(() => {
|
|
2828
|
+
if (width && height) {
|
|
2829
|
+
context.setSize({
|
|
2830
|
+
width,
|
|
2831
|
+
height
|
|
2832
|
+
});
|
|
2833
|
+
select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
2834
|
+
}
|
|
2835
|
+
}, [
|
|
2836
|
+
context,
|
|
2837
|
+
width,
|
|
2838
|
+
height
|
|
2839
|
+
]);
|
|
2840
|
+
const ready = width !== 0 && height !== 0;
|
|
2841
|
+
return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
|
|
2842
|
+
value: context
|
|
2843
|
+
}, /* @__PURE__ */ React4.createElement("div", {
|
|
2844
|
+
...composableProps(props, {
|
|
2845
|
+
classNames: "dx-expander"
|
|
2846
|
+
}),
|
|
2847
|
+
ref: setContainer
|
|
2848
|
+
}, /* @__PURE__ */ React4.createElement("svg", {
|
|
2849
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2850
|
+
ref: context.ref,
|
|
2851
|
+
className: mx3("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
2852
|
+
}, ready && children)));
|
|
1519
2853
|
});
|
|
1520
2854
|
|
|
1521
2855
|
// src/components/SVG/Zoom.tsx
|
|
1522
|
-
import {
|
|
1523
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
2856
|
+
import React5, { memo, useMemo as useMemo5 } from "react";
|
|
1524
2857
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
className
|
|
1536
|
-
}, children);
|
|
1537
|
-
} finally {
|
|
1538
|
-
_effect.f();
|
|
1539
|
-
}
|
|
2858
|
+
const options = useMemo5(() => ({
|
|
2859
|
+
extent
|
|
2860
|
+
}), [
|
|
2861
|
+
JSON.stringify(extent)
|
|
2862
|
+
]);
|
|
2863
|
+
const zoom2 = useZoom(options);
|
|
2864
|
+
return /* @__PURE__ */ React5.createElement("g", {
|
|
2865
|
+
ref: zoom2.ref,
|
|
2866
|
+
className
|
|
2867
|
+
}, children);
|
|
1540
2868
|
});
|
|
1541
2869
|
|
|
1542
2870
|
// src/components/SVG/SVG.tsx
|
|
@@ -1550,7 +2878,7 @@ var SVG = {
|
|
|
1550
2878
|
};
|
|
1551
2879
|
|
|
1552
2880
|
// src/fx/pulsar.ts
|
|
1553
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
2881
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1554
2882
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1555
2883
|
(function(Pulsar2) {
|
|
1556
2884
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1565,21 +2893,26 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1565
2893
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1566
2894
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1567
2895
|
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() {
|
|
1568
|
-
if (
|
|
1569
|
-
startAnimation(
|
|
2896
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
2897
|
+
startAnimation(select10(this), r, options);
|
|
1570
2898
|
} else {
|
|
1571
|
-
|
|
2899
|
+
select10(this).remove();
|
|
1572
2900
|
}
|
|
1573
2901
|
});
|
|
1574
2902
|
};
|
|
1575
2903
|
var Pulsar;
|
|
1576
2904
|
export {
|
|
2905
|
+
CLUSTER_NODE_TYPE_GROUP,
|
|
2906
|
+
CLUSTER_NODE_TYPE_LEAF,
|
|
2907
|
+
CLUSTER_NODE_TYPE_ROOT,
|
|
1577
2908
|
EventEmitter,
|
|
1578
2909
|
FractionUtil,
|
|
1579
2910
|
Graph,
|
|
2911
|
+
GraphBundleProjector,
|
|
2912
|
+
GraphClusterProjector,
|
|
1580
2913
|
GraphForceProjector,
|
|
1581
2914
|
GraphHierarchicalProjector,
|
|
1582
|
-
|
|
2915
|
+
GraphLatticeProjector,
|
|
1583
2916
|
GraphProjector,
|
|
1584
2917
|
GraphRadialProjector,
|
|
1585
2918
|
GraphRelationalProjector,
|