@dxos/react-ui-graph 0.8.4-main.fffef41 → 0.9.0
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 +2729 -592
- 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 +2729 -592
- 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 +23 -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/FPS.d.ts +20 -0
- package/dist/types/src/components/SVG/FPS.d.ts.map +1 -0
- 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 +17 -18
- 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 +65 -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-plexus-projector.d.ts +67 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts +2 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts +10 -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/graph-swarm-projector.d.ts +72 -0
- package/dist/types/src/graph/projector/graph-swarm-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/index.d.ts +5 -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 +41 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/index.d.ts +1 -0
- package/dist/types/src/graph/renderer/index.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/labels.d.ts +33 -0
- package/dist/types/src/graph/renderer/labels.d.ts.map +1 -0
- 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/experimental.stories.d.ts +7 -0
- package/dist/types/src/stories/experimental.stories.d.ts.map +1 -0
- 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 +45 -39
- package/src/components/Graph/Graph.tsx +126 -23
- package/src/components/Mesh/Mesh.stories.tsx +8 -7
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/FPS.tsx +91 -0
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Root.tsx +42 -9
- package/src/components/SVG/SVG.tsx +14 -3
- 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 +337 -0
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +7 -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-plexus-projector.test.ts +102 -0
- package/src/graph/projector/graph-plexus-projector.ts +309 -0
- package/src/graph/projector/graph-projector.ts +24 -4
- package/src/graph/projector/graph-radial-projector.ts +31 -4
- package/src/graph/projector/graph-relational-projector.ts +4 -4
- package/src/graph/projector/graph-swarm-projector.ts +373 -0
- package/src/graph/projector/index.ts +5 -0
- package/src/graph/projector/projector.ts +12 -3
- package/src/graph/renderer/graph-renderer.ts +289 -31
- package/src/graph/renderer/index.ts +1 -0
- package/src/graph/renderer/labels.ts +138 -0
- package/src/graph/renderer/renderer.ts +15 -4
- package/src/graph/types.ts +15 -1
- package/src/stories/experimental.stories.tsx +446 -0
- 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-XWA2XJDX.mjs +0 -955
- package/dist/lib/browser/chunk-XWA2XJDX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3RLSFEEV.mjs +0 -957
- package/dist/lib/node-esm/chunk-3RLSFEEV.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-XWA2XJDX.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 log11 } 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";
|
|
@@ -73,9 +56,1250 @@ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
|
|
|
73
56
|
generator: createDot(6),
|
|
74
57
|
className: "dx-dot"
|
|
75
58
|
}
|
|
76
|
-
]).join("marker").attr("id", (d) => d.id).attr("markerUnits", "strokeWidth").attr("class", (d) => d.className).each((d, i, nodes) => {
|
|
77
|
-
select(nodes[i]).call(d.generator);
|
|
78
|
-
});
|
|
59
|
+
]).join("marker").attr("id", (d) => d.id).attr("markerUnits", "strokeWidth").attr("class", (d) => d.className).each((d, i, nodes) => {
|
|
60
|
+
select(nodes[i]).call(d.generator);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
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";
|
|
71
|
+
|
|
72
|
+
// src/graph/types.ts
|
|
73
|
+
import { invariant } from "@dxos/invariant";
|
|
74
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
|
|
75
|
+
var defaultIdAccessor = (node) => {
|
|
76
|
+
invariant(node.id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 10, S: void 0, A: ["node.id", ""] });
|
|
77
|
+
return node.id;
|
|
78
|
+
};
|
|
79
|
+
var emptyGraph = {
|
|
80
|
+
nodes: [],
|
|
81
|
+
edges: []
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/util/events.ts
|
|
85
|
+
var EventEmitter = class {
|
|
86
|
+
_listeners = /* @__PURE__ */ new Set();
|
|
87
|
+
clear() {
|
|
88
|
+
this._listeners.clear();
|
|
89
|
+
}
|
|
90
|
+
on(onEvent) {
|
|
91
|
+
this._listeners.add(onEvent);
|
|
92
|
+
return () => this._listeners.delete(onEvent);
|
|
93
|
+
}
|
|
94
|
+
emit(value) {
|
|
95
|
+
this._listeners.forEach((listener) => listener(value));
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
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
|
+
}
|
|
118
|
+
});
|
|
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
|
+
}
|
|
335
|
+
}
|
|
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;
|
|
359
|
+
}
|
|
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
|
+
];
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Map model to screen.
|
|
377
|
+
* Model points are represented by fractions (to preserve precision) and use normal cartesian coordinates.
|
|
378
|
+
*/
|
|
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
|
+
type: edge.type,
|
|
750
|
+
source: nodes.find((n) => n.id === edge.source),
|
|
751
|
+
target: nodes.find((n) => n.id === edge.target),
|
|
752
|
+
data: edge.data
|
|
753
|
+
})).filter((edge) => edge.source && edge.target);
|
|
754
|
+
Object.assign(this._layout, {
|
|
755
|
+
graph: {
|
|
756
|
+
nodes,
|
|
757
|
+
edges
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
async onClear() {
|
|
762
|
+
this.reset();
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Optional projector-owned click intercept. The Graph component invokes this BEFORE
|
|
766
|
+
* forwarding to the consumer's `onSelect`, so projectors can implement built-in
|
|
767
|
+
* interactions (e.g. cluster collapse) without each consumer wiring them. Returning
|
|
768
|
+
* `true` indicates the click was handled — consumer's `onSelect` is suppressed.
|
|
769
|
+
* Default no-op returns `false` so consumer handlers still run.
|
|
770
|
+
*/
|
|
771
|
+
handleNodeClick(_node, _event) {
|
|
772
|
+
return false;
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
|
|
776
|
+
// src/graph/projector/graph-radial-projector.ts
|
|
777
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
778
|
+
var GraphRadialProjector = class extends GraphProjector {
|
|
779
|
+
_timer;
|
|
780
|
+
findNode(x, y, radius) {
|
|
781
|
+
return void 0;
|
|
782
|
+
}
|
|
783
|
+
onUpdate(graph) {
|
|
784
|
+
log("onUpdate", {
|
|
785
|
+
graph: {
|
|
786
|
+
nodes: graph?.nodes.length,
|
|
787
|
+
edges: graph?.edges.length
|
|
788
|
+
}
|
|
789
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 13, S: this });
|
|
790
|
+
this.mergeData(graph);
|
|
791
|
+
this.emitUpdate("topology");
|
|
792
|
+
this.doRadialLayout();
|
|
793
|
+
}
|
|
794
|
+
animate() {
|
|
795
|
+
this._timer?.stop();
|
|
796
|
+
this._timer = void 0;
|
|
797
|
+
const start = Date.now();
|
|
798
|
+
if (this.options.duration) {
|
|
799
|
+
this._timer = timer(() => {
|
|
800
|
+
const t = Math.min(1, (Date.now() - start) / this.options.duration);
|
|
801
|
+
const d = easeCubic(t);
|
|
802
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
803
|
+
node.x = node.sx + (node.tx - node.sx) * d;
|
|
804
|
+
node.y = node.sy + (node.ty - node.sy) * d;
|
|
805
|
+
node.r = node.sr + (node.tr - node.sr) * d;
|
|
806
|
+
});
|
|
807
|
+
this.onTickFrame(d);
|
|
808
|
+
this.emitUpdate("positions");
|
|
809
|
+
if (t >= 1) {
|
|
810
|
+
this._timer.stop();
|
|
811
|
+
this._timer = void 0;
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
} else {
|
|
815
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
816
|
+
node.x = node.tx;
|
|
817
|
+
node.y = node.ty;
|
|
818
|
+
node.r = node.tr;
|
|
819
|
+
});
|
|
820
|
+
this.onTickFrame(1);
|
|
821
|
+
this.emitUpdate("positions");
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Per-frame hook called after node x/y/r are interpolated and before the
|
|
826
|
+
* 'positions' emit. Subclasses override to update edge geometry (`edge.path`)
|
|
827
|
+
* so curves stay glued to moving endpoints. `t` is the eased progress in [0, 1].
|
|
828
|
+
*/
|
|
829
|
+
onTickFrame(t) {
|
|
830
|
+
}
|
|
831
|
+
async onStop() {
|
|
832
|
+
this._timer?.stop();
|
|
833
|
+
this._timer = void 0;
|
|
834
|
+
}
|
|
835
|
+
doRadialLayout() {
|
|
836
|
+
if (!this.context.size) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
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);
|
|
840
|
+
this.layout.graph.nodes.forEach((node, i) => {
|
|
841
|
+
const [tx, ty] = radial(i);
|
|
842
|
+
updateNode(node, [
|
|
843
|
+
tx,
|
|
844
|
+
ty
|
|
845
|
+
]);
|
|
846
|
+
});
|
|
847
|
+
this.animate();
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
851
|
+
const sx = node.x ?? tx;
|
|
852
|
+
const sy = node.y ?? ty;
|
|
853
|
+
const sr = node.r ?? tr;
|
|
854
|
+
Object.assign(node, {
|
|
855
|
+
initialized: true,
|
|
856
|
+
// Start.
|
|
857
|
+
sx,
|
|
858
|
+
sy,
|
|
859
|
+
sr,
|
|
860
|
+
// Target.
|
|
861
|
+
tx,
|
|
862
|
+
ty,
|
|
863
|
+
tr,
|
|
864
|
+
// Current.
|
|
865
|
+
x: sx,
|
|
866
|
+
y: sy,
|
|
867
|
+
r: sr
|
|
868
|
+
});
|
|
869
|
+
};
|
|
870
|
+
var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
|
|
871
|
+
const da = 2 * Math.PI / n;
|
|
872
|
+
return (i) => {
|
|
873
|
+
const a = start + i * da;
|
|
874
|
+
return [
|
|
875
|
+
x + Math.cos(a) * r,
|
|
876
|
+
y + Math.sin(a) * r
|
|
877
|
+
];
|
|
878
|
+
};
|
|
879
|
+
};
|
|
880
|
+
var layoutHorizontal = (x, y, w, n) => {
|
|
881
|
+
const dx = n > 1 ? w / (n - 1) : 0;
|
|
882
|
+
const sx = x - (n - 1) * dx / 2;
|
|
883
|
+
return (i) => {
|
|
884
|
+
return [
|
|
885
|
+
sx + i * dx,
|
|
886
|
+
y
|
|
887
|
+
];
|
|
888
|
+
};
|
|
889
|
+
};
|
|
890
|
+
var layoutVertical = (x, y, h, n) => {
|
|
891
|
+
const dy = n > 1 ? h / (n - 1) : 0;
|
|
892
|
+
const sy = y - (n - 1) * dy / 2;
|
|
893
|
+
return (i) => {
|
|
894
|
+
return [
|
|
895
|
+
x,
|
|
896
|
+
sy + i * dy
|
|
897
|
+
];
|
|
898
|
+
};
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
// src/graph/projector/graph-bundle-projector.ts
|
|
902
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-bundle-projector.ts";
|
|
903
|
+
var ROOT_ID = "__bundle_root__";
|
|
904
|
+
var GROUP_PREFIX = "__bundle_group__:";
|
|
905
|
+
var cartesianToPolar = (x, y) => ({
|
|
906
|
+
angle: Math.atan2(x, -y),
|
|
907
|
+
radius: Math.hypot(x, y)
|
|
908
|
+
});
|
|
909
|
+
var GraphBundleProjector = class extends GraphRadialProjector {
|
|
910
|
+
// Per-edge polar point arrays. Points 0 and N-1 are the source / target leaves and are
|
|
911
|
+
// overwritten from current cartesian on every tick; intermediate points stay fixed at
|
|
912
|
+
// their cluster-layout polar coordinates.
|
|
913
|
+
#edgePoints = /* @__PURE__ */ new Map();
|
|
914
|
+
#lineGen = lineRadial().radius((d) => d.radius).angle((d) => d.angle);
|
|
915
|
+
onUpdate(graph) {
|
|
916
|
+
log2("onUpdate", {
|
|
917
|
+
graph: {
|
|
918
|
+
nodes: graph?.nodes.length,
|
|
919
|
+
edges: graph?.edges.length
|
|
920
|
+
}
|
|
921
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 40, S: this });
|
|
922
|
+
this.mergeData(graph);
|
|
923
|
+
this.doBundleLayout();
|
|
924
|
+
this.emitUpdate("topology");
|
|
925
|
+
this.animate();
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Refresh leaf endpoint polar values from current cartesian so the curve tracks
|
|
929
|
+
* its endpoints during the tween. Internal hierarchy positions stay constant.
|
|
930
|
+
*/
|
|
931
|
+
onTickFrame(_t) {
|
|
932
|
+
for (const edge of this.layout.graph.edges) {
|
|
933
|
+
if (edge.type !== "bundle") {
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
const points = this.#edgePoints.get(edge.id);
|
|
937
|
+
if (!points || points.length < 2) {
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
const s = cartesianToPolar(edge.source.x ?? 0, edge.source.y ?? 0);
|
|
941
|
+
const t = cartesianToPolar(edge.target.x ?? 0, edge.target.y ?? 0);
|
|
942
|
+
points[0] = {
|
|
943
|
+
angle: s.angle,
|
|
944
|
+
radius: s.radius
|
|
945
|
+
};
|
|
946
|
+
points[points.length - 1] = {
|
|
947
|
+
angle: t.angle,
|
|
948
|
+
radius: t.radius
|
|
949
|
+
};
|
|
950
|
+
edge.path = this.#lineGen(points) ?? void 0;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
doBundleLayout() {
|
|
954
|
+
if (!this.context.size) {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const dataNodes = [
|
|
958
|
+
...this.layout.graph.nodes
|
|
959
|
+
];
|
|
960
|
+
if (!dataNodes.length) {
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const groupOf = this.options.groupOf;
|
|
964
|
+
const items = [
|
|
965
|
+
{
|
|
966
|
+
id: ROOT_ID
|
|
967
|
+
}
|
|
968
|
+
];
|
|
969
|
+
const groupIds = /* @__PURE__ */ new Map();
|
|
970
|
+
for (const node of dataNodes) {
|
|
971
|
+
const key = groupOf?.(node);
|
|
972
|
+
let parent = ROOT_ID;
|
|
973
|
+
if (key !== void 0) {
|
|
974
|
+
let groupId = groupIds.get(key);
|
|
975
|
+
if (!groupId) {
|
|
976
|
+
groupId = `${GROUP_PREFIX}${key}`;
|
|
977
|
+
groupIds.set(key, groupId);
|
|
978
|
+
items.push({
|
|
979
|
+
id: groupId,
|
|
980
|
+
parent: ROOT_ID
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
parent = groupId;
|
|
984
|
+
}
|
|
985
|
+
items.push({
|
|
986
|
+
id: node.id,
|
|
987
|
+
parent,
|
|
988
|
+
node
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
992
|
+
for (const item of items) {
|
|
993
|
+
if (item.parent) {
|
|
994
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
995
|
+
list.push(item);
|
|
996
|
+
childrenByParent.set(item.parent, list);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
const root = hierarchy({
|
|
1000
|
+
id: ROOT_ID
|
|
1001
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1002
|
+
const { width, height } = this.context.size;
|
|
1003
|
+
const margin = this.options.margin ?? 120;
|
|
1004
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1005
|
+
d3Cluster().size([
|
|
1006
|
+
2 * Math.PI,
|
|
1007
|
+
ringRadius
|
|
1008
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1009
|
+
const leafR = this.options.leafRadius ?? 4;
|
|
1010
|
+
const tension = this.options.tension ?? 0.85;
|
|
1011
|
+
this.#lineGen = lineRadial().curve(curveBundle.beta(tension)).radius((d) => d.radius).angle((d) => d.angle);
|
|
1012
|
+
const hierById = /* @__PURE__ */ new Map();
|
|
1013
|
+
root.each((d) => {
|
|
1014
|
+
hierById.set(d.data.id, d);
|
|
1015
|
+
});
|
|
1016
|
+
root.leaves().forEach((d) => {
|
|
1017
|
+
const angle = d.x;
|
|
1018
|
+
const radius = d.y;
|
|
1019
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1020
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1021
|
+
if (d.data.node) {
|
|
1022
|
+
updateNode(d.data.node, [
|
|
1023
|
+
x,
|
|
1024
|
+
y
|
|
1025
|
+
], leafR);
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
this.layout.graph.nodes = dataNodes;
|
|
1029
|
+
this.#edgePoints.clear();
|
|
1030
|
+
const incomingEdges = [
|
|
1031
|
+
...this.layout.graph.edges
|
|
1032
|
+
];
|
|
1033
|
+
const bundleEdges = [];
|
|
1034
|
+
for (const edge of incomingEdges) {
|
|
1035
|
+
const sourceHier = hierById.get(edge.source.id);
|
|
1036
|
+
const targetHier = hierById.get(edge.target.id);
|
|
1037
|
+
if (!sourceHier || !targetHier || sourceHier === targetHier) {
|
|
1038
|
+
continue;
|
|
1039
|
+
}
|
|
1040
|
+
const pathNodes = sourceHier.path(targetHier);
|
|
1041
|
+
const points = pathNodes.map((n) => ({
|
|
1042
|
+
angle: n.x,
|
|
1043
|
+
radius: n.y
|
|
1044
|
+
}));
|
|
1045
|
+
this.#edgePoints.set(edge.id, points);
|
|
1046
|
+
bundleEdges.push({
|
|
1047
|
+
id: edge.id,
|
|
1048
|
+
type: "bundle",
|
|
1049
|
+
source: edge.source,
|
|
1050
|
+
target: edge.target,
|
|
1051
|
+
data: edge.data
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
this.layout.graph.edges = bundleEdges;
|
|
1055
|
+
this.onTickFrame(0);
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
// src/graph/projector/graph-cluster-projector.ts
|
|
1060
|
+
import { cluster as d3Cluster2, hierarchy as hierarchy2, linkRadial } from "d3";
|
|
1061
|
+
import { log as log3 } from "@dxos/log";
|
|
1062
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-cluster-projector.ts";
|
|
1063
|
+
var ROOT_ID2 = "__cluster_root__";
|
|
1064
|
+
var GROUP_PREFIX2 = "__group__:";
|
|
1065
|
+
var HIER_EDGE_PREFIX = "__hier__:";
|
|
1066
|
+
var CLUSTER_NODE_TYPE_LEAF = "leaf";
|
|
1067
|
+
var CLUSTER_NODE_TYPE_GROUP = "group";
|
|
1068
|
+
var CLUSTER_NODE_TYPE_ROOT = "root";
|
|
1069
|
+
var linkPath = linkRadial().angle((d) => d.x).radius((d) => d.y);
|
|
1070
|
+
var cartesianToPolar2 = (x, y) => ({
|
|
1071
|
+
angle: Math.atan2(x, -y),
|
|
1072
|
+
radius: Math.hypot(x, y)
|
|
1073
|
+
});
|
|
1074
|
+
var GraphClusterProjector = class extends GraphRadialProjector {
|
|
1075
|
+
// Synthetic-node ids (root id, or `${GROUP_PREFIX}${key}`) whose subtree is currently
|
|
1076
|
+
// hidden. Clicking the corresponding rendered circle calls toggleCollapsed to flip
|
|
1077
|
+
// membership, then re-runs the layout so the renderer's exit transition fades the
|
|
1078
|
+
// hidden leaves + hierarchy edges out (and back in on expand).
|
|
1079
|
+
#collapsed = /* @__PURE__ */ new Set();
|
|
1080
|
+
// Snapshot of the full data-node set as of the last mergeData. doClusterLayout always
|
|
1081
|
+
// reads from this rather than `layout.graph.nodes` — the layout view is filtered (it
|
|
1082
|
+
// drops hidden leaves so the renderer doesn't see them), so re-reading from there
|
|
1083
|
+
// would permanently lose the hidden leaves and they couldn't reappear on expand.
|
|
1084
|
+
#dataNodes = [];
|
|
1085
|
+
/**
|
|
1086
|
+
* Built-in click semantics: clicking a synthetic root / group node toggles its subtree.
|
|
1087
|
+
* Leaf clicks fall through to the consumer's `onSelect` (returns `false`).
|
|
1088
|
+
*/
|
|
1089
|
+
handleNodeClick(node, _event) {
|
|
1090
|
+
if (node.type !== CLUSTER_NODE_TYPE_ROOT && node.type !== CLUSTER_NODE_TYPE_GROUP) {
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
this.toggleCollapsed(node.id);
|
|
1094
|
+
return true;
|
|
1095
|
+
}
|
|
1096
|
+
/** Toggle collapse state for a synthetic node id. Triggers a topology re-emit. */
|
|
1097
|
+
toggleCollapsed(id) {
|
|
1098
|
+
if (this.#collapsed.has(id)) {
|
|
1099
|
+
this.#collapsed.delete(id);
|
|
1100
|
+
} else {
|
|
1101
|
+
this.#collapsed.add(id);
|
|
1102
|
+
}
|
|
1103
|
+
this.doClusterLayout();
|
|
1104
|
+
this.emitUpdate("topology");
|
|
1105
|
+
this.animate();
|
|
1106
|
+
}
|
|
1107
|
+
/** Whether a synthetic-node id is currently collapsed. */
|
|
1108
|
+
isCollapsed(id) {
|
|
1109
|
+
return this.#collapsed.has(id);
|
|
1110
|
+
}
|
|
1111
|
+
onUpdate(graph) {
|
|
1112
|
+
log3("onUpdate", {
|
|
1113
|
+
graph: {
|
|
1114
|
+
nodes: graph?.nodes.length,
|
|
1115
|
+
edges: graph?.edges.length
|
|
1116
|
+
}
|
|
1117
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 79, S: this });
|
|
1118
|
+
this.mergeData(graph);
|
|
1119
|
+
this.#dataNodes = [
|
|
1120
|
+
...this.layout.graph.nodes
|
|
1121
|
+
];
|
|
1122
|
+
this.doClusterLayout();
|
|
1123
|
+
this.emitUpdate("topology");
|
|
1124
|
+
this.animate();
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Recompute each hierarchy edge's `path` from current cartesian source/target positions,
|
|
1128
|
+
* so the curves track moving endpoints during a cross-variant tween (e.g. force → cluster)
|
|
1129
|
+
* instead of being pinned to the final polar layout.
|
|
1130
|
+
*/
|
|
1131
|
+
onTickFrame(_t) {
|
|
1132
|
+
for (const edge of this.layout.graph.edges) {
|
|
1133
|
+
if (edge.type !== "hierarchy") {
|
|
1134
|
+
continue;
|
|
1135
|
+
}
|
|
1136
|
+
const { source, target } = edge;
|
|
1137
|
+
const s = cartesianToPolar2(source.x ?? 0, source.y ?? 0);
|
|
1138
|
+
const t = cartesianToPolar2(target.x ?? 0, target.y ?? 0);
|
|
1139
|
+
edge.path = linkPath({
|
|
1140
|
+
source: {
|
|
1141
|
+
x: s.angle,
|
|
1142
|
+
y: s.radius
|
|
1143
|
+
},
|
|
1144
|
+
target: {
|
|
1145
|
+
x: t.angle,
|
|
1146
|
+
y: t.radius
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
doClusterLayout() {
|
|
1152
|
+
if (!this.context.size) {
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
const dataNodes = this.#dataNodes;
|
|
1156
|
+
if (!dataNodes.length) {
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
const groupOf = this.options.groupOf;
|
|
1160
|
+
const rootId = this.options.rootId ?? ROOT_ID2;
|
|
1161
|
+
const items = [
|
|
1162
|
+
{
|
|
1163
|
+
id: rootId
|
|
1164
|
+
}
|
|
1165
|
+
];
|
|
1166
|
+
const groupIds = /* @__PURE__ */ new Map();
|
|
1167
|
+
const rootCollapsed = this.#collapsed.has(rootId);
|
|
1168
|
+
if (!rootCollapsed) {
|
|
1169
|
+
for (const node of dataNodes) {
|
|
1170
|
+
const key = groupOf?.(node);
|
|
1171
|
+
let parent = rootId;
|
|
1172
|
+
if (key !== void 0) {
|
|
1173
|
+
let groupId = groupIds.get(key);
|
|
1174
|
+
if (!groupId) {
|
|
1175
|
+
groupId = `${GROUP_PREFIX2}${key}`;
|
|
1176
|
+
groupIds.set(key, groupId);
|
|
1177
|
+
items.push({
|
|
1178
|
+
id: groupId,
|
|
1179
|
+
parent: rootId,
|
|
1180
|
+
groupKey: key
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
parent = groupId;
|
|
1184
|
+
}
|
|
1185
|
+
if (this.#collapsed.has(parent)) {
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
items.push({
|
|
1189
|
+
id: node.id,
|
|
1190
|
+
parent,
|
|
1191
|
+
node
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
1196
|
+
for (const item of items) {
|
|
1197
|
+
if (item.parent) {
|
|
1198
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
1199
|
+
list.push(item);
|
|
1200
|
+
childrenByParent.set(item.parent, list);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
const root = hierarchy2({
|
|
1204
|
+
id: rootId
|
|
1205
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1206
|
+
const { width, height } = this.context.size;
|
|
1207
|
+
const margin = this.options.margin ?? 80;
|
|
1208
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1209
|
+
d3Cluster2().size([
|
|
1210
|
+
2 * Math.PI,
|
|
1211
|
+
ringRadius
|
|
1212
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1213
|
+
const leafR = this.options.leafRadius ?? 4;
|
|
1214
|
+
const groupR = this.options.groupRadius ?? 3;
|
|
1215
|
+
const rootR = this.options.rootRadius ?? 5;
|
|
1216
|
+
const prevStubsById = /* @__PURE__ */ new Map();
|
|
1217
|
+
for (const node of this.layout.graph.nodes) {
|
|
1218
|
+
if (node.type === CLUSTER_NODE_TYPE_ROOT || node.type === CLUSTER_NODE_TYPE_GROUP) {
|
|
1219
|
+
prevStubsById.set(node.id, node);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
const syntheticNodes = /* @__PURE__ */ new Map();
|
|
1223
|
+
root.each((d) => {
|
|
1224
|
+
const id = d.data.id;
|
|
1225
|
+
const angle = d.x;
|
|
1226
|
+
const radius = d.y;
|
|
1227
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1228
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1229
|
+
if (d.data.node) {
|
|
1230
|
+
updateNode(d.data.node, [
|
|
1231
|
+
x,
|
|
1232
|
+
y
|
|
1233
|
+
], leafR);
|
|
1234
|
+
d.data.node.type = CLUSTER_NODE_TYPE_LEAF;
|
|
1235
|
+
d.data.node.hidden = false;
|
|
1236
|
+
} else {
|
|
1237
|
+
const isRoot = id === rootId;
|
|
1238
|
+
const stub = prevStubsById.get(id) ?? {
|
|
1239
|
+
id,
|
|
1240
|
+
x: 0,
|
|
1241
|
+
y: 0
|
|
1242
|
+
};
|
|
1243
|
+
updateNode(stub, [
|
|
1244
|
+
x,
|
|
1245
|
+
y
|
|
1246
|
+
], isRoot ? rootR : groupR);
|
|
1247
|
+
stub.type = isRoot ? CLUSTER_NODE_TYPE_ROOT : CLUSTER_NODE_TYPE_GROUP;
|
|
1248
|
+
if (isRoot) {
|
|
1249
|
+
stub.label = this.options.rootLabel;
|
|
1250
|
+
} else if (d.data.groupKey !== void 0) {
|
|
1251
|
+
stub.label = this.options.groupLabel ? this.options.groupLabel(d.data.groupKey) : d.data.groupKey;
|
|
1252
|
+
}
|
|
1253
|
+
syntheticNodes.set(id, stub);
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
const visibleLeafIds = /* @__PURE__ */ new Set();
|
|
1257
|
+
for (const item of items) {
|
|
1258
|
+
if (item.node) {
|
|
1259
|
+
visibleLeafIds.add(item.id);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
for (const node of dataNodes) {
|
|
1263
|
+
if (visibleLeafIds.has(node.id)) {
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
const key = groupOf?.(node);
|
|
1267
|
+
const parentId = key !== void 0 && groupIds.has(key) ? groupIds.get(key) : rootId;
|
|
1268
|
+
const parentStub = syntheticNodes.get(parentId);
|
|
1269
|
+
const targetX = parentStub?.tx ?? 0;
|
|
1270
|
+
const targetY = parentStub?.ty ?? 0;
|
|
1271
|
+
updateNode(node, [
|
|
1272
|
+
targetX,
|
|
1273
|
+
targetY
|
|
1274
|
+
], leafR);
|
|
1275
|
+
node.type = CLUSTER_NODE_TYPE_LEAF;
|
|
1276
|
+
node.hidden = true;
|
|
1277
|
+
}
|
|
1278
|
+
const nextNodes = [];
|
|
1279
|
+
for (const stub of syntheticNodes.values()) {
|
|
1280
|
+
nextNodes.push(stub);
|
|
1281
|
+
}
|
|
1282
|
+
for (const node of dataNodes) {
|
|
1283
|
+
nextNodes.push(node);
|
|
1284
|
+
}
|
|
1285
|
+
this.layout.graph.nodes = nextNodes;
|
|
1286
|
+
const hierarchyEdges = [];
|
|
1287
|
+
root.links().forEach((link) => {
|
|
1288
|
+
const sid = link.source.data.id;
|
|
1289
|
+
const tid = link.target.data.id;
|
|
1290
|
+
const sourceNode = link.source.data.node ?? syntheticNodes.get(sid);
|
|
1291
|
+
const targetNode = link.target.data.node ?? syntheticNodes.get(tid);
|
|
1292
|
+
hierarchyEdges.push({
|
|
1293
|
+
id: `${HIER_EDGE_PREFIX}${sid}->${tid}`,
|
|
1294
|
+
type: "hierarchy",
|
|
1295
|
+
source: sourceNode,
|
|
1296
|
+
target: targetNode,
|
|
1297
|
+
data: void 0
|
|
1298
|
+
});
|
|
1299
|
+
});
|
|
1300
|
+
this.layout.graph.edges = hierarchyEdges;
|
|
1301
|
+
this.onTickFrame(0);
|
|
1302
|
+
}
|
|
79
1303
|
};
|
|
80
1304
|
|
|
81
1305
|
// src/graph/projector/graph-drag.ts
|
|
@@ -158,144 +1382,9 @@ var createGraphDrag = (context, projector, options = defaultDragOptions) => {
|
|
|
158
1382
|
});
|
|
159
1383
|
};
|
|
160
1384
|
|
|
161
|
-
// src/graph/types.ts
|
|
162
|
-
import { invariant } from "@dxos/invariant";
|
|
163
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
|
|
164
|
-
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
|
-
});
|
|
174
|
-
return node.id;
|
|
175
|
-
};
|
|
176
|
-
var emptyGraph = {
|
|
177
|
-
nodes: [],
|
|
178
|
-
edges: []
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// src/graph/projector/projector.ts
|
|
182
|
-
var Projector = class {
|
|
183
|
-
_context;
|
|
184
|
-
updated = new EventEmitter();
|
|
185
|
-
_options;
|
|
186
|
-
constructor(_context, options) {
|
|
187
|
-
this._context = _context;
|
|
188
|
-
this._options = Object.assign({
|
|
189
|
-
idAccessor: defaultIdAccessor
|
|
190
|
-
}, options);
|
|
191
|
-
}
|
|
192
|
-
get context() {
|
|
193
|
-
return this._context;
|
|
194
|
-
}
|
|
195
|
-
get options() {
|
|
196
|
-
return this._options;
|
|
197
|
-
}
|
|
198
|
-
refresh(dragging = false) {
|
|
199
|
-
this.onRefresh(dragging);
|
|
200
|
-
}
|
|
201
|
-
updateData(data) {
|
|
202
|
-
this.onUpdate(data);
|
|
203
|
-
}
|
|
204
|
-
emitUpdate() {
|
|
205
|
-
this.updated.emit({
|
|
206
|
-
layout: this.layout
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
async clear() {
|
|
210
|
-
await this.onClear();
|
|
211
|
-
}
|
|
212
|
-
async start() {
|
|
213
|
-
await this.onStart();
|
|
214
|
-
}
|
|
215
|
-
async stop() {
|
|
216
|
-
await this.onStop();
|
|
217
|
-
}
|
|
218
|
-
onRefresh(dragging = false) {
|
|
219
|
-
}
|
|
220
|
-
onUpdate(data) {
|
|
221
|
-
}
|
|
222
|
-
async onClear() {
|
|
223
|
-
}
|
|
224
|
-
async onStart() {
|
|
225
|
-
}
|
|
226
|
-
async onStop() {
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
// src/graph/projector/graph-projector.ts
|
|
231
|
-
var GraphProjector = class extends Projector {
|
|
232
|
-
_selection;
|
|
233
|
-
_layout;
|
|
234
|
-
// TODO(burdon): Change to object props.
|
|
235
|
-
constructor(context, options, _selection, layout) {
|
|
236
|
-
super(context, options), this._selection = _selection;
|
|
237
|
-
this._layout = {
|
|
238
|
-
id: (Math.random() * 10).toString().slice(8),
|
|
239
|
-
graph: {
|
|
240
|
-
nodes: [
|
|
241
|
-
...layout?.graph.nodes ?? []
|
|
242
|
-
],
|
|
243
|
-
edges: [
|
|
244
|
-
...layout?.graph.edges ?? []
|
|
245
|
-
]
|
|
246
|
-
}
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
get layout() {
|
|
250
|
-
return this._layout;
|
|
251
|
-
}
|
|
252
|
-
get selection() {
|
|
253
|
-
return this._selection;
|
|
254
|
-
}
|
|
255
|
-
numChildren(node) {
|
|
256
|
-
return this._layout.graph.edges.filter((edge) => edge.source.id === this.options.idAccessor(node)).length;
|
|
257
|
-
}
|
|
258
|
-
reset() {
|
|
259
|
-
this._layout.graph.nodes = [];
|
|
260
|
-
this._layout.graph.edges = [];
|
|
261
|
-
this.emitUpdate();
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Merge external data with internal representation (e.g., so force properties like position are preserved).
|
|
265
|
-
* @param data
|
|
266
|
-
*/
|
|
267
|
-
mergeData(data = emptyGraph) {
|
|
268
|
-
const nodes = data.nodes.map((node) => {
|
|
269
|
-
let current = this._layout.graph.nodes.find((n) => n.id === this.options.idAccessor(node));
|
|
270
|
-
if (!current) {
|
|
271
|
-
current = {
|
|
272
|
-
id: this.options.idAccessor(node)
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
current.data = node;
|
|
276
|
-
return current;
|
|
277
|
-
});
|
|
278
|
-
const edges = data.edges.map((edge) => ({
|
|
279
|
-
id: edge.id,
|
|
280
|
-
source: nodes.find((n) => n.id === edge.source),
|
|
281
|
-
target: nodes.find((n) => n.id === edge.target),
|
|
282
|
-
data: edge.data
|
|
283
|
-
})).filter((edge) => edge.source && edge.target);
|
|
284
|
-
Object.assign(this._layout, {
|
|
285
|
-
graph: {
|
|
286
|
-
nodes,
|
|
287
|
-
edges
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
async onClear() {
|
|
292
|
-
this.reset();
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
|
|
296
1385
|
// src/graph/projector/graph-force-projector.ts
|
|
297
1386
|
import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
|
|
298
|
-
import { log } from "@dxos/log";
|
|
1387
|
+
import { log as log4 } from "@dxos/log";
|
|
299
1388
|
|
|
300
1389
|
// src/graph/projector/graph-forces.ts
|
|
301
1390
|
import { forceX, forceY } from "d3";
|
|
@@ -314,7 +1403,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
314
1403
|
};
|
|
315
1404
|
|
|
316
1405
|
// src/graph/projector/graph-force-projector.ts
|
|
317
|
-
var
|
|
1406
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
318
1407
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
319
1408
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
320
1409
|
};
|
|
@@ -364,7 +1453,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
364
1453
|
} else {
|
|
365
1454
|
this.updateForces(this.forces);
|
|
366
1455
|
}
|
|
367
|
-
this._simulation.on("tick", () => propagating && this.emitUpdate()).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
|
|
1456
|
+
this._simulation.on("tick", () => propagating && this.emitUpdate("positions")).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
|
|
368
1457
|
}
|
|
369
1458
|
async onStop() {
|
|
370
1459
|
clearTimeout(this._timeout);
|
|
@@ -381,21 +1470,17 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
381
1470
|
this.restart();
|
|
382
1471
|
}
|
|
383
1472
|
onUpdate(graph) {
|
|
384
|
-
|
|
1473
|
+
log4("onUpdate", {
|
|
385
1474
|
graph: {
|
|
386
1475
|
nodes: graph?.nodes.length,
|
|
387
1476
|
edges: graph?.edges.length
|
|
388
1477
|
}
|
|
389
|
-
}, {
|
|
390
|
-
F: __dxlog_file2,
|
|
391
|
-
L: 227,
|
|
392
|
-
S: this,
|
|
393
|
-
C: (f, a) => f(...a)
|
|
394
|
-
});
|
|
1478
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 91, S: this });
|
|
395
1479
|
this._simulation.stop();
|
|
396
1480
|
this.mergeData(graph);
|
|
397
1481
|
this.updateLayout();
|
|
398
1482
|
this.updateForces(this.forces);
|
|
1483
|
+
this.emitUpdate("topology");
|
|
399
1484
|
this.restart();
|
|
400
1485
|
}
|
|
401
1486
|
updateLayout() {
|
|
@@ -439,14 +1524,9 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
439
1524
|
* Update all forces.
|
|
440
1525
|
*/
|
|
441
1526
|
updateForces(forces) {
|
|
442
|
-
|
|
1527
|
+
log4("updateForces", {
|
|
443
1528
|
forces
|
|
444
|
-
}, {
|
|
445
|
-
F: __dxlog_file2,
|
|
446
|
-
L: 288,
|
|
447
|
-
S: this,
|
|
448
|
-
C: (f, a) => f(...a)
|
|
449
|
-
});
|
|
1529
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 153, S: this });
|
|
450
1530
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
451
1531
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
452
1532
|
if (config.distance != null) {
|
|
@@ -479,172 +1559,51 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
479
1559
|
const force = forceRadial(config.radius ?? 100, config.x ?? 0, config.y ?? 0);
|
|
480
1560
|
if (config.strength != null) {
|
|
481
1561
|
force.strength(config.strength);
|
|
482
|
-
}
|
|
483
|
-
return force;
|
|
484
|
-
})).force("center", maybeForce(forces?.center, (config) => {
|
|
485
|
-
const force = forceCenter().x(config.x ?? 0).y(config.y ?? 0);
|
|
486
|
-
if (config.strength != null) {
|
|
487
|
-
force.strength(config.strength);
|
|
488
|
-
}
|
|
489
|
-
return force;
|
|
490
|
-
})).force("point", maybeForce(forces?.point, ({ x = 0, y = 0, strength }) => {
|
|
491
|
-
return forcePoint({
|
|
492
|
-
x,
|
|
493
|
-
y,
|
|
494
|
-
strength
|
|
495
|
-
});
|
|
496
|
-
})).force("x", maybeForce(forces?.x, (config) => {
|
|
497
|
-
const force = forceX2(config.x ?? 0);
|
|
498
|
-
if (config.strength != null) {
|
|
499
|
-
force.strength(config.strength);
|
|
500
|
-
}
|
|
501
|
-
return force;
|
|
502
|
-
})).force("y", maybeForce(forces?.y, (config) => {
|
|
503
|
-
const force = forceY2(config.y ?? 0);
|
|
504
|
-
if (config.strength != null) {
|
|
505
|
-
force.strength(config.strength);
|
|
506
|
-
}
|
|
507
|
-
return force;
|
|
508
|
-
}));
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
// src/graph/projector/graph-hierarchical-projector.ts
|
|
513
|
-
import { log as log3 } from "@dxos/log";
|
|
514
|
-
|
|
515
|
-
// src/graph/projector/graph-radial-projector.ts
|
|
516
|
-
import { easeCubic, timer } from "d3";
|
|
517
|
-
import { log as log2 } from "@dxos/log";
|
|
518
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
519
|
-
var GraphRadialProjector = class extends GraphProjector {
|
|
520
|
-
_timer;
|
|
521
|
-
findNode(x, y, radius) {
|
|
522
|
-
return void 0;
|
|
523
|
-
}
|
|
524
|
-
onUpdate(graph) {
|
|
525
|
-
log2("onUpdate", {
|
|
526
|
-
graph: {
|
|
527
|
-
nodes: graph?.nodes.length,
|
|
528
|
-
edges: graph?.edges.length
|
|
529
|
-
}
|
|
530
|
-
}, {
|
|
531
|
-
F: __dxlog_file3,
|
|
532
|
-
L: 32,
|
|
533
|
-
S: this,
|
|
534
|
-
C: (f, a) => f(...a)
|
|
535
|
-
});
|
|
536
|
-
this.mergeData(graph);
|
|
537
|
-
this.doRadialLayout();
|
|
538
|
-
}
|
|
539
|
-
animate() {
|
|
540
|
-
const start = Date.now();
|
|
541
|
-
if (this.options.duration) {
|
|
542
|
-
this._timer = timer(() => {
|
|
543
|
-
const t = Math.min(1, (Date.now() - start) / this.options.duration);
|
|
544
|
-
const d = easeCubic(t);
|
|
545
|
-
this.layout.graph.nodes.forEach((node) => {
|
|
546
|
-
node.x = node.sx + (node.tx - node.sx) * d;
|
|
547
|
-
node.y = node.sy + (node.ty - node.sy) * d;
|
|
548
|
-
node.r = node.sr + (node.tr - node.sr) * d;
|
|
549
|
-
});
|
|
550
|
-
this.emitUpdate();
|
|
551
|
-
if (t >= 1) {
|
|
552
|
-
this._timer.stop();
|
|
553
|
-
this._timer = void 0;
|
|
554
|
-
}
|
|
1562
|
+
}
|
|
1563
|
+
return force;
|
|
1564
|
+
})).force("center", maybeForce(forces?.center, (config) => {
|
|
1565
|
+
const force = forceCenter().x(config.x ?? 0).y(config.y ?? 0);
|
|
1566
|
+
if (config.strength != null) {
|
|
1567
|
+
force.strength(config.strength);
|
|
1568
|
+
}
|
|
1569
|
+
return force;
|
|
1570
|
+
})).force("point", maybeForce(forces?.point, ({ x = 0, y = 0, strength }) => {
|
|
1571
|
+
return forcePoint({
|
|
1572
|
+
x,
|
|
1573
|
+
y,
|
|
1574
|
+
strength
|
|
555
1575
|
});
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
this.layout.graph.nodes.forEach((node, i) => {
|
|
570
|
-
const [tx, ty] = radial(i);
|
|
571
|
-
updateNode(node, [
|
|
572
|
-
tx,
|
|
573
|
-
ty
|
|
574
|
-
]);
|
|
575
|
-
});
|
|
576
|
-
this.animate();
|
|
1576
|
+
})).force("x", maybeForce(forces?.x, (config) => {
|
|
1577
|
+
const force = forceX2(config.x ?? 0);
|
|
1578
|
+
if (config.strength != null) {
|
|
1579
|
+
force.strength(config.strength);
|
|
1580
|
+
}
|
|
1581
|
+
return force;
|
|
1582
|
+
})).force("y", maybeForce(forces?.y, (config) => {
|
|
1583
|
+
const force = forceY2(config.y ?? 0);
|
|
1584
|
+
if (config.strength != null) {
|
|
1585
|
+
force.strength(config.strength);
|
|
1586
|
+
}
|
|
1587
|
+
return force;
|
|
1588
|
+
}));
|
|
577
1589
|
}
|
|
578
1590
|
};
|
|
579
|
-
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
580
|
-
const sx = node.x ?? tx;
|
|
581
|
-
const sy = node.y ?? ty;
|
|
582
|
-
const sr = node.r ?? tr;
|
|
583
|
-
Object.assign(node, {
|
|
584
|
-
initialized: true,
|
|
585
|
-
// Start.
|
|
586
|
-
sx,
|
|
587
|
-
sy,
|
|
588
|
-
sr,
|
|
589
|
-
// Target.
|
|
590
|
-
tx,
|
|
591
|
-
ty,
|
|
592
|
-
tr,
|
|
593
|
-
// Current.
|
|
594
|
-
x: sx,
|
|
595
|
-
y: sy,
|
|
596
|
-
r: sr
|
|
597
|
-
});
|
|
598
|
-
};
|
|
599
|
-
var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
|
|
600
|
-
const da = 2 * Math.PI / n;
|
|
601
|
-
return (i) => {
|
|
602
|
-
const a = start + i * da;
|
|
603
|
-
return [
|
|
604
|
-
x + Math.cos(a) * r,
|
|
605
|
-
y + Math.sin(a) * r
|
|
606
|
-
];
|
|
607
|
-
};
|
|
608
|
-
};
|
|
609
|
-
var layoutHorizontal = (x, y, w, n) => {
|
|
610
|
-
const dx = n > 1 ? w / (n - 1) : 0;
|
|
611
|
-
const sx = x - (n - 1) * dx / 2;
|
|
612
|
-
return (i) => {
|
|
613
|
-
return [
|
|
614
|
-
sx + i * dx,
|
|
615
|
-
y
|
|
616
|
-
];
|
|
617
|
-
};
|
|
618
|
-
};
|
|
619
|
-
var layoutVertical = (x, y, h, n) => {
|
|
620
|
-
const dy = n > 1 ? h / (n - 1) : 0;
|
|
621
|
-
const sy = y - (n - 1) * dy / 2;
|
|
622
|
-
return (i) => {
|
|
623
|
-
return [
|
|
624
|
-
x,
|
|
625
|
-
sy + i * dy
|
|
626
|
-
];
|
|
627
|
-
};
|
|
628
|
-
};
|
|
629
1591
|
|
|
630
1592
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
631
|
-
|
|
1593
|
+
import { log as log5 } from "@dxos/log";
|
|
1594
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
632
1595
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
633
1596
|
onUpdate(graph) {
|
|
634
|
-
|
|
1597
|
+
log5("onUpdate", {
|
|
635
1598
|
graph: {
|
|
636
1599
|
nodes: graph?.nodes.length,
|
|
637
1600
|
edges: graph?.edges.length
|
|
638
1601
|
},
|
|
639
|
-
selection: this.selection?.
|
|
640
|
-
}, {
|
|
641
|
-
F: __dxlog_file4,
|
|
642
|
-
L: 24,
|
|
643
|
-
S: this,
|
|
644
|
-
C: (f, a) => f(...a)
|
|
645
|
-
});
|
|
1602
|
+
selection: this.selection?.getSelectedIds()
|
|
1603
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 8, S: this });
|
|
646
1604
|
this.mergeData(graph);
|
|
647
|
-
|
|
1605
|
+
this.emitUpdate("topology");
|
|
1606
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
648
1607
|
if (selected) {
|
|
649
1608
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
650
1609
|
if (node) {
|
|
@@ -689,25 +1648,307 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
689
1648
|
}
|
|
690
1649
|
};
|
|
691
1650
|
|
|
1651
|
+
// src/graph/projector/graph-lattice-projector.ts
|
|
1652
|
+
import { log as log6 } from "@dxos/log";
|
|
1653
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-lattice-projector.ts";
|
|
1654
|
+
var GraphLatticeProjector = class extends GraphRadialProjector {
|
|
1655
|
+
onUpdate(graph) {
|
|
1656
|
+
log6("onUpdate", {
|
|
1657
|
+
graph: {
|
|
1658
|
+
nodes: graph?.nodes.length,
|
|
1659
|
+
edges: graph?.edges.length
|
|
1660
|
+
}
|
|
1661
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 14, S: this });
|
|
1662
|
+
this.mergeData(graph);
|
|
1663
|
+
this.doLatticeLayout();
|
|
1664
|
+
this.emitUpdate("topology");
|
|
1665
|
+
this.animate();
|
|
1666
|
+
}
|
|
1667
|
+
doLatticeLayout() {
|
|
1668
|
+
if (!this.context.size) {
|
|
1669
|
+
return;
|
|
1670
|
+
}
|
|
1671
|
+
const nodes = this.layout.graph.nodes;
|
|
1672
|
+
const count = nodes.length;
|
|
1673
|
+
if (!count) {
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
const sortBy = this.options.sortBy ?? ((n) => n.data?.label ?? n.id);
|
|
1677
|
+
nodes.sort((a, b) => sortBy(a).localeCompare(sortBy(b)));
|
|
1678
|
+
const columns = Math.max(1, Math.ceil(Math.sqrt(count)));
|
|
1679
|
+
const rows = Math.ceil(count / columns);
|
|
1680
|
+
const margin = this.options.margin ?? 16;
|
|
1681
|
+
const { width, height } = this.context.size;
|
|
1682
|
+
const innerW = Math.max(0, width - 2 * margin);
|
|
1683
|
+
const innerH = Math.max(0, height - 2 * margin);
|
|
1684
|
+
const r = this.options.radius ?? 6;
|
|
1685
|
+
const fit = Math.min(innerW / columns, innerH / rows);
|
|
1686
|
+
const cellSize = Math.max(0, Math.min(fit, r * 6));
|
|
1687
|
+
const gridW = cellSize * columns;
|
|
1688
|
+
const gridH = cellSize * rows;
|
|
1689
|
+
const offsetX = -gridW / 2 + cellSize / 2;
|
|
1690
|
+
const offsetY = -gridH / 2 + cellSize / 2;
|
|
1691
|
+
nodes.forEach((node, i) => {
|
|
1692
|
+
const tx = offsetX + i % columns * cellSize;
|
|
1693
|
+
const ty = offsetY + Math.floor(i / columns) * cellSize;
|
|
1694
|
+
updateNode(node, [
|
|
1695
|
+
tx,
|
|
1696
|
+
ty
|
|
1697
|
+
], r);
|
|
1698
|
+
});
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
|
|
1702
|
+
// src/graph/projector/graph-plexus-projector.ts
|
|
1703
|
+
import { cluster as d3Cluster3, hierarchy as hierarchy3, linkRadial as linkRadial2 } from "d3";
|
|
1704
|
+
import { log as log7 } from "@dxos/log";
|
|
1705
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-plexus-projector.ts";
|
|
1706
|
+
var RELATION_PREFIX = "__plexus_relation__:";
|
|
1707
|
+
var HIER_EDGE_PREFIX2 = "__plexus_hier__:";
|
|
1708
|
+
var PLEXUS_NODE_TYPE_FOCUS = "plexus-focus";
|
|
1709
|
+
var PLEXUS_NODE_TYPE_RELATION = "plexus-relation";
|
|
1710
|
+
var PLEXUS_NODE_TYPE_OBJECT = "plexus-object";
|
|
1711
|
+
var linkPath2 = linkRadial2().angle((d) => d.x).radius((d) => d.y);
|
|
1712
|
+
var cartesianToPolar3 = (x, y) => ({
|
|
1713
|
+
angle: Math.atan2(x, -y),
|
|
1714
|
+
radius: Math.hypot(x, y)
|
|
1715
|
+
});
|
|
1716
|
+
var GraphPlexusProjector = class extends GraphRadialProjector {
|
|
1717
|
+
// Full node / edge snapshots taken right after mergeData — doPlexusLayout reads from
|
|
1718
|
+
// these because it overwrites layout.graph with the filtered focus-centric view.
|
|
1719
|
+
#dataNodes = [];
|
|
1720
|
+
#dataEdges = [];
|
|
1721
|
+
onUpdate(graph) {
|
|
1722
|
+
log7("onUpdate", {
|
|
1723
|
+
graph: {
|
|
1724
|
+
nodes: graph?.nodes.length,
|
|
1725
|
+
edges: graph?.edges.length
|
|
1726
|
+
}
|
|
1727
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 48, S: this });
|
|
1728
|
+
this.mergeData(graph);
|
|
1729
|
+
this.#dataNodes = [
|
|
1730
|
+
...this.layout.graph.nodes
|
|
1731
|
+
];
|
|
1732
|
+
this.#dataEdges = [
|
|
1733
|
+
...this.layout.graph.edges
|
|
1734
|
+
];
|
|
1735
|
+
this.doPlexusLayout();
|
|
1736
|
+
this.emitUpdate("topology");
|
|
1737
|
+
this.animate();
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Recompute each hierarchy edge's `path` from current cartesian endpoints so curves track
|
|
1741
|
+
* moving nodes during the tween (identical strategy to the cluster projector).
|
|
1742
|
+
*/
|
|
1743
|
+
onTickFrame(_t) {
|
|
1744
|
+
for (const edge of this.layout.graph.edges) {
|
|
1745
|
+
if (edge.type !== "hierarchy") {
|
|
1746
|
+
continue;
|
|
1747
|
+
}
|
|
1748
|
+
const { source, target } = edge;
|
|
1749
|
+
const s = cartesianToPolar3(source.x ?? 0, source.y ?? 0);
|
|
1750
|
+
const t = cartesianToPolar3(target.x ?? 0, target.y ?? 0);
|
|
1751
|
+
edge.path = linkPath2({
|
|
1752
|
+
source: {
|
|
1753
|
+
x: s.angle,
|
|
1754
|
+
y: s.radius
|
|
1755
|
+
},
|
|
1756
|
+
target: {
|
|
1757
|
+
x: t.angle,
|
|
1758
|
+
y: t.radius
|
|
1759
|
+
}
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
doPlexusLayout() {
|
|
1764
|
+
if (!this.context.size) {
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
const dataNodes = this.#dataNodes;
|
|
1768
|
+
if (!dataNodes.length) {
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
const focusId = this.options.focus;
|
|
1772
|
+
const focusNode = focusId ? dataNodes.find((node) => node.id === focusId) : void 0;
|
|
1773
|
+
if (!focusNode) {
|
|
1774
|
+
const radial = layoutRadial(0, 0, Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 100), dataNodes.length);
|
|
1775
|
+
dataNodes.forEach((node, index) => updateNode(node, radial(index), this.options.leafRadius ?? 5));
|
|
1776
|
+
this.layout.graph.nodes = dataNodes;
|
|
1777
|
+
this.layout.graph.edges = [];
|
|
1778
|
+
this.animate();
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
const relationOf = this.options.relationOf ?? defaultRelationOf;
|
|
1782
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1783
|
+
const placed = /* @__PURE__ */ new Set([
|
|
1784
|
+
focusId
|
|
1785
|
+
]);
|
|
1786
|
+
for (const edge of this.#dataEdges) {
|
|
1787
|
+
const relation = relationOf(edge, focusId);
|
|
1788
|
+
if (!relation) {
|
|
1789
|
+
continue;
|
|
1790
|
+
}
|
|
1791
|
+
const neighbour = edge.source.id === focusId ? edge.target : edge.source;
|
|
1792
|
+
if (placed.has(neighbour.id)) {
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1795
|
+
placed.add(neighbour.id);
|
|
1796
|
+
let group = groups.get(relation.key);
|
|
1797
|
+
if (!group) {
|
|
1798
|
+
group = {
|
|
1799
|
+
id: `${RELATION_PREFIX}${relation.key}`,
|
|
1800
|
+
label: relation.label,
|
|
1801
|
+
leaves: []
|
|
1802
|
+
};
|
|
1803
|
+
groups.set(relation.key, group);
|
|
1804
|
+
}
|
|
1805
|
+
group.leaves.push(neighbour);
|
|
1806
|
+
}
|
|
1807
|
+
const items = [
|
|
1808
|
+
{
|
|
1809
|
+
id: focusId,
|
|
1810
|
+
node: focusNode
|
|
1811
|
+
}
|
|
1812
|
+
];
|
|
1813
|
+
for (const group of groups.values()) {
|
|
1814
|
+
items.push({
|
|
1815
|
+
id: group.id,
|
|
1816
|
+
parent: focusId,
|
|
1817
|
+
relationLabel: group.label
|
|
1818
|
+
});
|
|
1819
|
+
for (const leaf of group.leaves) {
|
|
1820
|
+
items.push({
|
|
1821
|
+
id: leaf.id,
|
|
1822
|
+
parent: group.id,
|
|
1823
|
+
node: leaf
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
1828
|
+
for (const item of items) {
|
|
1829
|
+
if (item.parent) {
|
|
1830
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
1831
|
+
list.push(item);
|
|
1832
|
+
childrenByParent.set(item.parent, list);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
const root = hierarchy3({
|
|
1836
|
+
id: focusId,
|
|
1837
|
+
node: focusNode
|
|
1838
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1839
|
+
const { width, height } = this.context.size;
|
|
1840
|
+
const margin = this.options.margin ?? 100;
|
|
1841
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1842
|
+
d3Cluster3().size([
|
|
1843
|
+
2 * Math.PI,
|
|
1844
|
+
ringRadius
|
|
1845
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1846
|
+
const leafR = this.options.leafRadius ?? 5;
|
|
1847
|
+
const relationR = this.options.relationRadius ?? leafR;
|
|
1848
|
+
const focusR = this.options.focusRadius ?? leafR * 2;
|
|
1849
|
+
const prevStubsById = /* @__PURE__ */ new Map();
|
|
1850
|
+
for (const node of this.layout.graph.nodes) {
|
|
1851
|
+
if (node.type === PLEXUS_NODE_TYPE_RELATION) {
|
|
1852
|
+
prevStubsById.set(node.id, node);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
const relationStubs = /* @__PURE__ */ new Map();
|
|
1856
|
+
root.each((d) => {
|
|
1857
|
+
const angle = d.x;
|
|
1858
|
+
const radius = d.y;
|
|
1859
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1860
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1861
|
+
const id = d.data.id;
|
|
1862
|
+
if (id === focusId) {
|
|
1863
|
+
updateNode(focusNode, [
|
|
1864
|
+
x,
|
|
1865
|
+
y
|
|
1866
|
+
], focusR);
|
|
1867
|
+
focusNode.type = PLEXUS_NODE_TYPE_FOCUS;
|
|
1868
|
+
focusNode.hidden = false;
|
|
1869
|
+
} else if (d.data.node) {
|
|
1870
|
+
updateNode(d.data.node, [
|
|
1871
|
+
x,
|
|
1872
|
+
y
|
|
1873
|
+
], leafR);
|
|
1874
|
+
d.data.node.type = PLEXUS_NODE_TYPE_OBJECT;
|
|
1875
|
+
d.data.node.hidden = false;
|
|
1876
|
+
} else {
|
|
1877
|
+
const stub = prevStubsById.get(id) ?? {
|
|
1878
|
+
id,
|
|
1879
|
+
x: 0,
|
|
1880
|
+
y: 0
|
|
1881
|
+
};
|
|
1882
|
+
updateNode(stub, [
|
|
1883
|
+
x,
|
|
1884
|
+
y
|
|
1885
|
+
], relationR);
|
|
1886
|
+
stub.type = PLEXUS_NODE_TYPE_RELATION;
|
|
1887
|
+
stub.label = d.data.relationLabel;
|
|
1888
|
+
relationStubs.set(id, stub);
|
|
1889
|
+
}
|
|
1890
|
+
});
|
|
1891
|
+
const nextNodes = [];
|
|
1892
|
+
for (const stub of relationStubs.values()) {
|
|
1893
|
+
nextNodes.push(stub);
|
|
1894
|
+
}
|
|
1895
|
+
for (const group of groups.values()) {
|
|
1896
|
+
for (const leaf of group.leaves) {
|
|
1897
|
+
nextNodes.push(leaf);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
nextNodes.push(focusNode);
|
|
1901
|
+
this.layout.graph.nodes = nextNodes;
|
|
1902
|
+
const edges = [];
|
|
1903
|
+
root.links().forEach((link) => {
|
|
1904
|
+
const sid = link.source.data.id;
|
|
1905
|
+
const tid = link.target.data.id;
|
|
1906
|
+
const sourceNode = sid === focusId ? focusNode : link.source.data.node ?? relationStubs.get(sid);
|
|
1907
|
+
const targetNode = link.target.data.node ?? relationStubs.get(tid);
|
|
1908
|
+
if (!sourceNode || !targetNode) {
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
edges.push({
|
|
1912
|
+
id: `${HIER_EDGE_PREFIX2}${sid}->${tid}`,
|
|
1913
|
+
type: "hierarchy",
|
|
1914
|
+
source: sourceNode,
|
|
1915
|
+
target: targetNode,
|
|
1916
|
+
data: void 0
|
|
1917
|
+
});
|
|
1918
|
+
});
|
|
1919
|
+
this.layout.graph.edges = edges;
|
|
1920
|
+
this.onTickFrame(0);
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
var defaultRelationOf = (edge, focusId) => {
|
|
1924
|
+
const outgoing = edge.source.id === focusId;
|
|
1925
|
+
const incoming = edge.target.id === focusId;
|
|
1926
|
+
if (!outgoing && !incoming) {
|
|
1927
|
+
return void 0;
|
|
1928
|
+
}
|
|
1929
|
+
const type = edge.type ?? "edge";
|
|
1930
|
+
const arrow = outgoing ? "\u2192" : "\u2190";
|
|
1931
|
+
return {
|
|
1932
|
+
key: `${type}:${outgoing ? "out" : "in"}`,
|
|
1933
|
+
label: `${type} ${arrow}`
|
|
1934
|
+
};
|
|
1935
|
+
};
|
|
1936
|
+
|
|
692
1937
|
// src/graph/projector/graph-relational-projector.ts
|
|
693
|
-
import { log as
|
|
694
|
-
var
|
|
1938
|
+
import { log as log8 } from "@dxos/log";
|
|
1939
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
695
1940
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
696
1941
|
onUpdate(graph) {
|
|
697
|
-
|
|
1942
|
+
log8("onUpdate", {
|
|
698
1943
|
graph: {
|
|
699
1944
|
nodes: graph?.nodes.length,
|
|
700
1945
|
edges: graph?.edges.length
|
|
701
1946
|
},
|
|
702
|
-
selection: this.selection?.
|
|
703
|
-
}, {
|
|
704
|
-
F: __dxlog_file5,
|
|
705
|
-
L: 24,
|
|
706
|
-
S: this,
|
|
707
|
-
C: (f, a) => f(...a)
|
|
708
|
-
});
|
|
1947
|
+
selection: this.selection?.getSelectedIds()
|
|
1948
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 8, S: this });
|
|
709
1949
|
this.mergeData(graph);
|
|
710
|
-
|
|
1950
|
+
this.emitUpdate("topology");
|
|
1951
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
711
1952
|
if (selected) {
|
|
712
1953
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
713
1954
|
if (node) {
|
|
@@ -774,14 +2015,271 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
774
2015
|
]);
|
|
775
2016
|
});
|
|
776
2017
|
}
|
|
777
|
-
this.animate();
|
|
2018
|
+
this.animate();
|
|
2019
|
+
}
|
|
2020
|
+
};
|
|
2021
|
+
|
|
2022
|
+
// src/graph/projector/graph-swarm-projector.ts
|
|
2023
|
+
import { timer as timer2 } from "d3";
|
|
2024
|
+
import { log as log9 } from "@dxos/log";
|
|
2025
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-swarm-projector.ts";
|
|
2026
|
+
var SWARMMATE_RADIUS = 60;
|
|
2027
|
+
var SEPARATION_DISTANCE = 30;
|
|
2028
|
+
var DEFAULTS = {
|
|
2029
|
+
spawnRadius: 200,
|
|
2030
|
+
maxVelocity: 1.2,
|
|
2031
|
+
alignment: 3,
|
|
2032
|
+
cohesion: 3,
|
|
2033
|
+
separation: 3,
|
|
2034
|
+
cursorRepel: 120,
|
|
2035
|
+
avoidance: 3,
|
|
2036
|
+
trailLength: 30
|
|
2037
|
+
};
|
|
2038
|
+
var GraphSwarmProjector = class extends GraphProjector {
|
|
2039
|
+
#timer;
|
|
2040
|
+
/** Cursor in SVG model coordinates, or null when the pointer is outside the surface. */
|
|
2041
|
+
#cursor = null;
|
|
2042
|
+
findNode() {
|
|
2043
|
+
return void 0;
|
|
2044
|
+
}
|
|
2045
|
+
/**
|
|
2046
|
+
* Tell the projector where the pointer is, in SVG model coordinates (the same space
|
|
2047
|
+
* `node.x/y` live in — center origin, post-zoom). Pass `null` (or omit args) on
|
|
2048
|
+
* pointer-leave to disable cursor avoidance.
|
|
2049
|
+
*/
|
|
2050
|
+
setCursor(x, y) {
|
|
2051
|
+
if (x == null || y == null) {
|
|
2052
|
+
this.#cursor = null;
|
|
2053
|
+
} else {
|
|
2054
|
+
this.#cursor = {
|
|
2055
|
+
x,
|
|
2056
|
+
y
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
onUpdate(graph) {
|
|
2061
|
+
log9("onUpdate", {
|
|
2062
|
+
graph: {
|
|
2063
|
+
nodes: graph?.nodes.length,
|
|
2064
|
+
edges: graph?.edges.length
|
|
2065
|
+
}
|
|
2066
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 54, S: this });
|
|
2067
|
+
this.mergeData(graph);
|
|
2068
|
+
this.initializeNodes();
|
|
2069
|
+
this.emitUpdate("topology");
|
|
2070
|
+
}
|
|
2071
|
+
async onStart() {
|
|
2072
|
+
this.startTimer();
|
|
2073
|
+
}
|
|
2074
|
+
async onStop() {
|
|
2075
|
+
this.stopTimer();
|
|
2076
|
+
}
|
|
2077
|
+
onRefresh() {
|
|
2078
|
+
if (!this.#timer) {
|
|
2079
|
+
this.startTimer();
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
#opt(key) {
|
|
2083
|
+
return this.options[key] ?? DEFAULTS[key];
|
|
2084
|
+
}
|
|
2085
|
+
initializeNodes() {
|
|
2086
|
+
const spawnRadius = this.#opt("spawnRadius");
|
|
2087
|
+
const maxVelocity = this.#opt("maxVelocity");
|
|
2088
|
+
for (const node of this.layout.graph.nodes) {
|
|
2089
|
+
if (!node.initialized) {
|
|
2090
|
+
const theta = Math.random() * 2 * Math.PI;
|
|
2091
|
+
const r = Math.random() * spawnRadius;
|
|
2092
|
+
node.x = Math.cos(theta) * r;
|
|
2093
|
+
node.y = Math.sin(theta) * r;
|
|
2094
|
+
const phi = Math.random() * 2 * Math.PI;
|
|
2095
|
+
const speed = (0.3 + Math.random() * 0.7) * maxVelocity;
|
|
2096
|
+
node.vx = Math.cos(phi) * speed;
|
|
2097
|
+
node.vy = Math.sin(phi) * speed;
|
|
2098
|
+
node.ax = 0;
|
|
2099
|
+
node.ay = 0;
|
|
2100
|
+
node.initialized = true;
|
|
2101
|
+
} else {
|
|
2102
|
+
node.vx ??= 0;
|
|
2103
|
+
node.vy ??= 0;
|
|
2104
|
+
node.ax ??= 0;
|
|
2105
|
+
node.ay ??= 0;
|
|
2106
|
+
}
|
|
2107
|
+
node.r ??= 6;
|
|
2108
|
+
node.history = [
|
|
2109
|
+
{
|
|
2110
|
+
x: node.x ?? 0,
|
|
2111
|
+
y: node.y ?? 0
|
|
2112
|
+
}
|
|
2113
|
+
];
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
startTimer() {
|
|
2117
|
+
this.stopTimer();
|
|
2118
|
+
this.#timer = timer2(() => this.tick());
|
|
2119
|
+
}
|
|
2120
|
+
stopTimer() {
|
|
2121
|
+
this.#timer?.stop();
|
|
2122
|
+
this.#timer = void 0;
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* One simulation step. Modeled on `tick` in Swarm.tsx, but operating in the
|
|
2126
|
+
* SVG centered-origin coordinate space and writing to `node.x/y` directly so
|
|
2127
|
+
* the existing `GraphRenderer.applyPositions` reads them unchanged.
|
|
2128
|
+
*/
|
|
2129
|
+
tick() {
|
|
2130
|
+
const size = this.context.size;
|
|
2131
|
+
if (!size) {
|
|
2132
|
+
return;
|
|
2133
|
+
}
|
|
2134
|
+
const { width, height } = size;
|
|
2135
|
+
const halfW = width / 2;
|
|
2136
|
+
const halfH = height / 2;
|
|
2137
|
+
const nodes = this.layout.graph.nodes;
|
|
2138
|
+
const maxVelocity = this.#opt("maxVelocity");
|
|
2139
|
+
const alignmentW = this.#opt("alignment") / 100;
|
|
2140
|
+
const cohesionW = this.#opt("cohesion") / 100;
|
|
2141
|
+
const separationW = this.#opt("separation") / 100;
|
|
2142
|
+
const avoidanceW = this.#opt("avoidance") / 10;
|
|
2143
|
+
const cursorRepel = this.#opt("cursorRepel");
|
|
2144
|
+
const cursor = cursorRepel > 0 ? this.#cursor : null;
|
|
2145
|
+
for (const b1 of nodes) {
|
|
2146
|
+
let ax = 0;
|
|
2147
|
+
let ay = 0;
|
|
2148
|
+
let alignX = 0;
|
|
2149
|
+
let alignY = 0;
|
|
2150
|
+
let alignActive = false;
|
|
2151
|
+
let cohX = 0;
|
|
2152
|
+
let cohY = 0;
|
|
2153
|
+
let cohActive = false;
|
|
2154
|
+
let sepX = 0;
|
|
2155
|
+
let sepY = 0;
|
|
2156
|
+
let sepActive = false;
|
|
2157
|
+
let avoidX = 0;
|
|
2158
|
+
let avoidY = 0;
|
|
2159
|
+
let avoidActive = false;
|
|
2160
|
+
if (cursor) {
|
|
2161
|
+
const dx = cursor.x - (b1.x ?? 0);
|
|
2162
|
+
const dy = cursor.y - (b1.y ?? 0);
|
|
2163
|
+
const distSq = dx * dx + dy * dy;
|
|
2164
|
+
if (distSq > 0 && distSq < cursorRepel * cursorRepel) {
|
|
2165
|
+
const dist = Math.sqrt(distSq);
|
|
2166
|
+
avoidX = -dx / dist * (1 / dist);
|
|
2167
|
+
avoidY = -dy / dist * (1 / dist);
|
|
2168
|
+
avoidActive = true;
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
if (!avoidActive) {
|
|
2172
|
+
for (const b2 of nodes) {
|
|
2173
|
+
if (b1 === b2) {
|
|
2174
|
+
continue;
|
|
2175
|
+
}
|
|
2176
|
+
const dx = (b2.x ?? 0) - (b1.x ?? 0);
|
|
2177
|
+
const dy = (b2.y ?? 0) - (b1.y ?? 0);
|
|
2178
|
+
const distSq = dx * dx + dy * dy;
|
|
2179
|
+
if (distSq === 0) {
|
|
2180
|
+
continue;
|
|
2181
|
+
}
|
|
2182
|
+
const dist = Math.sqrt(distSq);
|
|
2183
|
+
if (dist < SEPARATION_DISTANCE) {
|
|
2184
|
+
sepX += -dx / dist * (1 / dist);
|
|
2185
|
+
sepY += -dy / dist * (1 / dist);
|
|
2186
|
+
sepActive = true;
|
|
2187
|
+
}
|
|
2188
|
+
if (dist < SWARMMATE_RADIUS) {
|
|
2189
|
+
cohX += dx;
|
|
2190
|
+
cohY += dy;
|
|
2191
|
+
cohActive = true;
|
|
2192
|
+
alignX += b2.vx ?? 0;
|
|
2193
|
+
alignY += b2.vy ?? 0;
|
|
2194
|
+
alignActive = true;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
const applyForce = (fx, fy, weight, active) => {
|
|
2199
|
+
if (!active || weight === 0) {
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
const len = Math.sqrt(fx * fx + fy * fy);
|
|
2203
|
+
if (len === 0) {
|
|
2204
|
+
return;
|
|
2205
|
+
}
|
|
2206
|
+
const sx = fx * maxVelocity / len - (b1.vx ?? 0);
|
|
2207
|
+
const sy = fy * maxVelocity / len - (b1.vy ?? 0);
|
|
2208
|
+
const slen = Math.sqrt(sx * sx + sy * sy);
|
|
2209
|
+
if (slen > weight) {
|
|
2210
|
+
ax += sx * weight / slen;
|
|
2211
|
+
ay += sy * weight / slen;
|
|
2212
|
+
} else {
|
|
2213
|
+
ax += sx;
|
|
2214
|
+
ay += sy;
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2217
|
+
applyForce(alignX, alignY, alignmentW, alignActive);
|
|
2218
|
+
applyForce(cohX, cohY, cohesionW, cohActive);
|
|
2219
|
+
applyForce(sepX, sepY, separationW, sepActive);
|
|
2220
|
+
applyForce(avoidX, avoidY, avoidanceW, avoidActive);
|
|
2221
|
+
b1.ax = ax;
|
|
2222
|
+
b1.ay = ay;
|
|
2223
|
+
}
|
|
2224
|
+
const trailLength = Math.max(0, Math.round(this.#opt("trailLength")));
|
|
2225
|
+
for (const b of nodes) {
|
|
2226
|
+
let vx = (b.vx ?? 0) + (b.ax ?? 0);
|
|
2227
|
+
let vy = (b.vy ?? 0) + (b.ay ?? 0);
|
|
2228
|
+
const vlen = Math.sqrt(vx * vx + vy * vy);
|
|
2229
|
+
if (vlen > maxVelocity) {
|
|
2230
|
+
vx = vx * maxVelocity / vlen;
|
|
2231
|
+
vy = vy * maxVelocity / vlen;
|
|
2232
|
+
}
|
|
2233
|
+
b.vx = vx;
|
|
2234
|
+
b.vy = vy;
|
|
2235
|
+
if (trailLength > 0) {
|
|
2236
|
+
const history = b.history ?? (b.history = []);
|
|
2237
|
+
history.push({
|
|
2238
|
+
x: b.x ?? 0,
|
|
2239
|
+
y: b.y ?? 0
|
|
2240
|
+
});
|
|
2241
|
+
if (history.length > trailLength) {
|
|
2242
|
+
history.splice(0, history.length - trailLength);
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
let x = (b.x ?? 0) + vx;
|
|
2246
|
+
let y = (b.y ?? 0) + vy;
|
|
2247
|
+
let wrapped = false;
|
|
2248
|
+
if (x > halfW) {
|
|
2249
|
+
x -= width;
|
|
2250
|
+
wrapped = true;
|
|
2251
|
+
} else if (x < -halfW) {
|
|
2252
|
+
x += width;
|
|
2253
|
+
wrapped = true;
|
|
2254
|
+
}
|
|
2255
|
+
if (y > halfH) {
|
|
2256
|
+
y -= height;
|
|
2257
|
+
wrapped = true;
|
|
2258
|
+
} else if (y < -halfH) {
|
|
2259
|
+
y += height;
|
|
2260
|
+
wrapped = true;
|
|
2261
|
+
}
|
|
2262
|
+
if (wrapped && b.history) {
|
|
2263
|
+
b.history.length = 0;
|
|
2264
|
+
}
|
|
2265
|
+
b.x = x;
|
|
2266
|
+
b.y = y;
|
|
2267
|
+
}
|
|
2268
|
+
for (const edge of this.layout.graph.edges) {
|
|
2269
|
+
const sx = edge.source.x ?? 0;
|
|
2270
|
+
const sy = edge.source.y ?? 0;
|
|
2271
|
+
const tx = edge.target.x ?? 0;
|
|
2272
|
+
const ty = edge.target.y ?? 0;
|
|
2273
|
+
edge.path = `M ${sx} ${sy} Q 0 0 ${tx} ${ty}`;
|
|
2274
|
+
}
|
|
2275
|
+
this.emitUpdate("positions");
|
|
778
2276
|
}
|
|
779
2277
|
};
|
|
780
2278
|
|
|
781
2279
|
// src/graph/renderer/graph-renderer.ts
|
|
782
2280
|
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
783
2281
|
import * as Clipper from "js-clipper";
|
|
784
|
-
import { log as
|
|
2282
|
+
import { log as log10 } from "@dxos/log";
|
|
785
2283
|
|
|
786
2284
|
// src/graph/renderer/bullets.ts
|
|
787
2285
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
@@ -814,8 +2312,6 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
814
2312
|
};
|
|
815
2313
|
|
|
816
2314
|
// src/graph/renderer/renderer.ts
|
|
817
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
818
|
-
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
819
2315
|
var Renderer = class {
|
|
820
2316
|
_context;
|
|
821
2317
|
_root;
|
|
@@ -830,34 +2326,48 @@ var Renderer = class {
|
|
|
830
2326
|
get context() {
|
|
831
2327
|
return this._context;
|
|
832
2328
|
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Returns the SVG group root if mounted.
|
|
2331
|
+
* The ref may be null between mount/unmount cycles or before the SVG container has sized.
|
|
2332
|
+
* Callers should treat null as "skip this render" rather than as an error.
|
|
2333
|
+
*/
|
|
833
2334
|
get root() {
|
|
834
|
-
invariant2(this._root.current, "SVG root is not initialized", {
|
|
835
|
-
F: __dxlog_file6,
|
|
836
|
-
L: 40,
|
|
837
|
-
S: this,
|
|
838
|
-
A: [
|
|
839
|
-
"this._root.current",
|
|
840
|
-
"'SVG root is not initialized'"
|
|
841
|
-
]
|
|
842
|
-
});
|
|
843
2335
|
return this._root.current;
|
|
844
2336
|
}
|
|
845
2337
|
get options() {
|
|
846
2338
|
return this._options;
|
|
847
2339
|
}
|
|
2340
|
+
/**
|
|
2341
|
+
* Fast path invoked when only positions changed.
|
|
2342
|
+
* Default falls back to a full `render`; subclasses can override to skip
|
|
2343
|
+
* enter/exit joins and attribute callbacks for per-tick updates.
|
|
2344
|
+
*/
|
|
2345
|
+
applyPositions(layout) {
|
|
2346
|
+
this.render(layout);
|
|
2347
|
+
}
|
|
848
2348
|
};
|
|
849
2349
|
|
|
850
2350
|
// src/graph/renderer/graph-renderer.ts
|
|
851
|
-
var
|
|
2351
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
852
2352
|
var createLine2 = line2();
|
|
2353
|
+
var EDGE_FADE_MS = 300;
|
|
2354
|
+
var NODE_HIDE_MS = 500;
|
|
853
2355
|
var GraphRenderer = class extends Renderer {
|
|
2356
|
+
// First render of this instance — used to clear DOM left behind by a previous
|
|
2357
|
+
// renderer pointing at the same `<g>` (e.g. when the consumer swaps projectors
|
|
2358
|
+
// and a new renderer is constructed for the same SVG root). Without this, the
|
|
2359
|
+
// previous variant's node shapes (e.g. circles) would persist as d3.join sees
|
|
2360
|
+
// them in the `update` set instead of `enter`.
|
|
2361
|
+
#firstRender = true;
|
|
854
2362
|
render(layout) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
2363
|
+
if (!this.root) {
|
|
2364
|
+
return;
|
|
2365
|
+
}
|
|
2366
|
+
if (this.#firstRender) {
|
|
2367
|
+
this.#firstRender = false;
|
|
2368
|
+
this.root.replaceChildren();
|
|
2369
|
+
}
|
|
2370
|
+
log10("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 35, S: this });
|
|
861
2371
|
const root = select4(this.root);
|
|
862
2372
|
if (layout.guides) {
|
|
863
2373
|
root.selectAll("g.dx-guides").data([
|
|
@@ -915,37 +2425,92 @@ var GraphRenderer = class extends Renderer {
|
|
|
915
2425
|
{
|
|
916
2426
|
id: "edges"
|
|
917
2427
|
}
|
|
918
|
-
], (d) => d.id).join("g").classed("dx-edges", true);
|
|
2428
|
+
], (d) => d.id).join("g").classed("dx-edges", true).style("opacity", this.options.edgeOpacity != null ? String(this.options.edgeOpacity) : null);
|
|
919
2429
|
const nodeGroup = root.selectAll("g.dx-nodes").data([
|
|
920
2430
|
{
|
|
921
2431
|
id: "nodes"
|
|
922
2432
|
}
|
|
923
2433
|
], (d) => d.id).join("g").classed("dx-nodes", true);
|
|
924
|
-
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
|
|
2434
|
+
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) => {
|
|
925
2435
|
return exit.transition().ease(easeCubicOut).duration(300).attr("opacity", 0).on("end", function(d) {
|
|
926
2436
|
select4(this).remove();
|
|
927
2437
|
});
|
|
928
|
-
}).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
929
|
-
edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
|
|
930
|
-
|
|
2438
|
+
}).call(updateNode2, this.options).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
2439
|
+
edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
|
|
2440
|
+
(enter) => enter.append("g").attr("data-id", (d) => d.id).classed("dx-edge", true).call(createEdge, this.options),
|
|
2441
|
+
(update) => update,
|
|
2442
|
+
// Exit fade: edges removed by a topology change (e.g. variant switch from cluster
|
|
2443
|
+
// back to force replaces hierarchy edges with data edges) ease out rather than pop.
|
|
2444
|
+
(exit) => exit.transition().ease(easeCubicOut).duration(EDGE_FADE_MS).attr("opacity", 0).on("end", function() {
|
|
2445
|
+
select4(this).remove();
|
|
2446
|
+
})
|
|
2447
|
+
).call(updateEdge, this.options, nodeGroup).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* Fast positions-only update. Skips enter/exit, attribute callbacks, label sizing,
|
|
2451
|
+
* and the subgraph hull pass; just writes `transform` per node and `d` per edge.
|
|
2452
|
+
* Called per simulation tick / animation frame.
|
|
2453
|
+
*/
|
|
2454
|
+
applyPositions(layout) {
|
|
2455
|
+
if (!this.root) {
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2458
|
+
const root = select4(this.root);
|
|
2459
|
+
const applyNode = this.options.applyNode;
|
|
2460
|
+
root.select("g.dx-nodes").selectAll("g.dx-node").attr("transform", (d) => d.x != null && d.y != null ? `translate(${d.x},${d.y})` : null).each(applyNode ? function(d) {
|
|
2461
|
+
applyNode(this, d);
|
|
2462
|
+
} : () => {
|
|
2463
|
+
});
|
|
2464
|
+
root.select("g.dx-edges").selectAll("g.dx-edge").selectAll("path").attr("d", function() {
|
|
2465
|
+
const edge = select4(this.parentElement).datum();
|
|
2466
|
+
if (edge.path) {
|
|
2467
|
+
return edge.path;
|
|
2468
|
+
}
|
|
2469
|
+
const { source, target } = edge;
|
|
2470
|
+
if (!source.initialized || !target.initialized) {
|
|
2471
|
+
return null;
|
|
2472
|
+
}
|
|
2473
|
+
return createLine2(getCircumferencePoints([
|
|
2474
|
+
source.x,
|
|
2475
|
+
source.y
|
|
2476
|
+
], [
|
|
2477
|
+
target.x,
|
|
2478
|
+
target.y
|
|
2479
|
+
], source.r, target.r));
|
|
2480
|
+
});
|
|
931
2481
|
}
|
|
932
2482
|
/**
|
|
933
2483
|
* Trigger path bullets.
|
|
934
2484
|
* @param node
|
|
935
2485
|
*/
|
|
936
2486
|
fireBullet(node) {
|
|
2487
|
+
if (!this.root) {
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
937
2490
|
select4(this.root).selectAll("g.dx-edges").selectAll("path").call(createBullets(this.root, node.id));
|
|
938
2491
|
}
|
|
939
2492
|
};
|
|
2493
|
+
var SHAPE_CLASS = "dx-shape";
|
|
2494
|
+
var renderCustomShape = (group, options) => {
|
|
2495
|
+
group.each(function(d) {
|
|
2496
|
+
const g = select4(this);
|
|
2497
|
+
g.selectAll(`.${SHAPE_CLASS}`).remove();
|
|
2498
|
+
const shapeGroup = g.append("g").classed(SHAPE_CLASS, true);
|
|
2499
|
+
options.renderNode(shapeGroup, d);
|
|
2500
|
+
});
|
|
2501
|
+
};
|
|
940
2502
|
var createNode = (group, options) => {
|
|
941
|
-
const
|
|
2503
|
+
const useCustom = !!options.renderNode;
|
|
2504
|
+
if (useCustom) {
|
|
2505
|
+
renderCustomShape(group, options);
|
|
2506
|
+
}
|
|
2507
|
+
const hitTarget = useCustom ? group : group.append("circle");
|
|
942
2508
|
if (options.drag) {
|
|
943
|
-
|
|
2509
|
+
hitTarget.call(options.drag);
|
|
944
2510
|
}
|
|
945
2511
|
if (options.onNodeClick) {
|
|
946
|
-
group.on("click", (event) => {
|
|
947
|
-
|
|
948
|
-
options.onNodeClick(node, event);
|
|
2512
|
+
group.on("click", (event, d) => {
|
|
2513
|
+
options.onNodeClick(d, event);
|
|
949
2514
|
});
|
|
950
2515
|
}
|
|
951
2516
|
if (options.labels && !options.onNodePointerEnter) {
|
|
@@ -954,24 +2519,34 @@ var createNode = (group, options) => {
|
|
|
954
2519
|
g.append("rect");
|
|
955
2520
|
g.append("text").style("dominant-baseline", "middle");
|
|
956
2521
|
}
|
|
957
|
-
if (options.onNodePointerEnter) {
|
|
958
|
-
|
|
959
|
-
const node = select4(this.parentElement).datum();
|
|
960
|
-
options.onNodePointerEnter(node, event);
|
|
2522
|
+
if (options.onNodePointerEnter || options.onNodePointerLeave || options.highlightOnHover) {
|
|
2523
|
+
hitTarget.on("pointerenter", function(event) {
|
|
2524
|
+
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2525
|
+
options.onNodePointerEnter?.(node, event);
|
|
2526
|
+
if (options.highlightOnHover) {
|
|
2527
|
+
applyHoverHighlight(this.closest("g.dx-graph"), node.id);
|
|
2528
|
+
}
|
|
2529
|
+
});
|
|
2530
|
+
hitTarget.on("pointerleave", function(event) {
|
|
2531
|
+
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2532
|
+
options.onNodePointerLeave?.(node, event);
|
|
2533
|
+
if (options.highlightOnHover) {
|
|
2534
|
+
applyHoverHighlight(this.closest("g.dx-graph"), null);
|
|
2535
|
+
}
|
|
961
2536
|
});
|
|
962
2537
|
group.attr("data-hover", "handled");
|
|
963
|
-
} else if (options.highlight !== false) {
|
|
964
|
-
|
|
2538
|
+
} else if (options.highlight !== false && !useCustom) {
|
|
2539
|
+
hitTarget.on("pointerenter", function() {
|
|
965
2540
|
select4(this.closest("g.dx-node")).raise();
|
|
966
2541
|
if (options.labels) {
|
|
967
|
-
select4(this.parentElement).classed("dx-active", true).classed("dx-highlight", true);
|
|
2542
|
+
select4(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
|
|
968
2543
|
}
|
|
969
2544
|
});
|
|
970
2545
|
group.on("pointerleave", function() {
|
|
971
2546
|
if (options.labels) {
|
|
972
|
-
select4(this).classed("dx-active", false);
|
|
2547
|
+
select4(this).classed("dx-node-active", false);
|
|
973
2548
|
setTimeout(() => {
|
|
974
|
-
if (!select4(this).classed("dx-active")) {
|
|
2549
|
+
if (!select4(this).classed("dx-node-active")) {
|
|
975
2550
|
select4(this).classed("dx-highlight", false);
|
|
976
2551
|
}
|
|
977
2552
|
}, 300);
|
|
@@ -983,6 +2558,11 @@ var updateNode2 = (group, options) => {
|
|
|
983
2558
|
group.attr("transform", (d) => {
|
|
984
2559
|
return d.x != null && d.y != null ? `translate(${d.x},${d.y})` : void 0;
|
|
985
2560
|
});
|
|
2561
|
+
group.classed("dx-hidden", (d) => d.hidden ?? false);
|
|
2562
|
+
group.transition("hide").ease(easeCubicOut).duration(NODE_HIDE_MS).attr("opacity", (d) => d.hidden ? 0 : 1);
|
|
2563
|
+
if (options.renderNode) {
|
|
2564
|
+
renderCustomShape(group, options);
|
|
2565
|
+
}
|
|
986
2566
|
if (options.attributes?.node) {
|
|
987
2567
|
try {
|
|
988
2568
|
group.each((d, i, nodes) => {
|
|
@@ -998,18 +2578,15 @@ var updateNode2 = (group, options) => {
|
|
|
998
2578
|
}
|
|
999
2579
|
});
|
|
1000
2580
|
} catch (error) {
|
|
1001
|
-
|
|
2581
|
+
log10.error("updateNode", {
|
|
1002
2582
|
error: error?.message
|
|
1003
|
-
}, {
|
|
1004
|
-
F: __dxlog_file7,
|
|
1005
|
-
L: 305,
|
|
1006
|
-
S: void 0,
|
|
1007
|
-
C: (f, a) => f(...a)
|
|
1008
|
-
});
|
|
2583
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 303, S: void 0 });
|
|
1009
2584
|
}
|
|
1010
2585
|
}
|
|
1011
2586
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1012
|
-
|
|
2587
|
+
if (!options.renderNode) {
|
|
2588
|
+
groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
|
|
2589
|
+
}
|
|
1013
2590
|
if (options.labels) {
|
|
1014
2591
|
const bx = 1;
|
|
1015
2592
|
const px = 4;
|
|
@@ -1054,18 +2631,17 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1054
2631
|
}
|
|
1055
2632
|
});
|
|
1056
2633
|
} catch (error) {
|
|
1057
|
-
|
|
2634
|
+
log10.error("updateEdge", {
|
|
1058
2635
|
error: error?.message
|
|
1059
|
-
}, {
|
|
1060
|
-
F: __dxlog_file7,
|
|
1061
|
-
L: 417,
|
|
1062
|
-
S: void 0,
|
|
1063
|
-
C: (f, a) => f(...a)
|
|
1064
|
-
});
|
|
2636
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 371, S: void 0 });
|
|
1065
2637
|
}
|
|
1066
2638
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1067
2639
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
1068
|
-
const
|
|
2640
|
+
const edge = select4(this.parentElement).datum();
|
|
2641
|
+
if (edge.path) {
|
|
2642
|
+
return edge.path;
|
|
2643
|
+
}
|
|
2644
|
+
const { source, target } = edge;
|
|
1069
2645
|
if (!source.initialized || !target.initialized) {
|
|
1070
2646
|
return;
|
|
1071
2647
|
}
|
|
@@ -1078,6 +2654,62 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1078
2654
|
], source.r, target.r));
|
|
1079
2655
|
});
|
|
1080
2656
|
};
|
|
2657
|
+
var applyHoverHighlight = (root, focusedId) => {
|
|
2658
|
+
if (!root) {
|
|
2659
|
+
return;
|
|
2660
|
+
}
|
|
2661
|
+
const r = select4(root);
|
|
2662
|
+
const on = focusedId != null;
|
|
2663
|
+
const outgoing = /* @__PURE__ */ new Set();
|
|
2664
|
+
const incoming = /* @__PURE__ */ new Set();
|
|
2665
|
+
if (on) {
|
|
2666
|
+
r.select("g.dx-edges").selectAll("g.dx-edge").each((edge) => {
|
|
2667
|
+
if (edge.source.id === focusedId) {
|
|
2668
|
+
outgoing.add(edge.target.id);
|
|
2669
|
+
}
|
|
2670
|
+
if (edge.target.id === focusedId) {
|
|
2671
|
+
incoming.add(edge.source.id);
|
|
2672
|
+
}
|
|
2673
|
+
});
|
|
2674
|
+
}
|
|
2675
|
+
r.select("g.dx-edges").selectAll("g.dx-edge").each(function(edge) {
|
|
2676
|
+
const path = select4(this).select("path:not(.dx-click)");
|
|
2677
|
+
if (!on) {
|
|
2678
|
+
path.style("stroke", null).style("stroke-width", null).style("opacity", null);
|
|
2679
|
+
return;
|
|
2680
|
+
}
|
|
2681
|
+
if (edge.source.id === focusedId) {
|
|
2682
|
+
path.style("stroke", "var(--color-orange-500)").style("stroke-width", "1.5px").style("opacity", null);
|
|
2683
|
+
} else if (edge.target.id === focusedId) {
|
|
2684
|
+
path.style("stroke", "var(--color-sky-500)").style("stroke-width", "1.5px").style("opacity", null);
|
|
2685
|
+
} else {
|
|
2686
|
+
path.style("stroke", null).style("stroke-width", null).style("opacity", "0.8");
|
|
2687
|
+
}
|
|
2688
|
+
});
|
|
2689
|
+
r.select("g.dx-nodes").selectAll("g.dx-node").each(function(node) {
|
|
2690
|
+
const groupSel = select4(this);
|
|
2691
|
+
const shape = groupSel.select("circle, rect");
|
|
2692
|
+
if (node.hidden) {
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
if (!on) {
|
|
2696
|
+
groupSel.style("opacity", null);
|
|
2697
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
const connected = outgoing.has(node.id) || incoming.has(node.id);
|
|
2701
|
+
if (node.id === focusedId) {
|
|
2702
|
+
groupSel.style("opacity", null);
|
|
2703
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2704
|
+
} else if (connected) {
|
|
2705
|
+
groupSel.style("opacity", null);
|
|
2706
|
+
shape.style("stroke", "var(--color-orange-400)").style("stroke-width", "2.5px");
|
|
2707
|
+
} else {
|
|
2708
|
+
groupSel.style("opacity", "0.4");
|
|
2709
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2710
|
+
}
|
|
2711
|
+
});
|
|
2712
|
+
};
|
|
1081
2713
|
var applyClasses = (el, classes) => {
|
|
1082
2714
|
for (const [className, value] of Object.entries(classes)) {
|
|
1083
2715
|
el.classed(className, value);
|
|
@@ -1116,6 +2748,45 @@ var findConnectedComponents = (graph) => {
|
|
|
1116
2748
|
return components;
|
|
1117
2749
|
};
|
|
1118
2750
|
|
|
2751
|
+
// src/graph/renderer/labels.ts
|
|
2752
|
+
var DEFAULT_DURATION = 200;
|
|
2753
|
+
var DEFAULT_OFFSET = 4;
|
|
2754
|
+
var getTarget = (node) => {
|
|
2755
|
+
const tx = node.tx;
|
|
2756
|
+
const ty = node.ty;
|
|
2757
|
+
return {
|
|
2758
|
+
x: tx ?? node.x ?? 0,
|
|
2759
|
+
y: ty ?? node.y ?? 0
|
|
2760
|
+
};
|
|
2761
|
+
};
|
|
2762
|
+
var appendRadialLeafLabel = (group, node, label, r, options = {}) => {
|
|
2763
|
+
if (!label) {
|
|
2764
|
+
return;
|
|
2765
|
+
}
|
|
2766
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label" } = options;
|
|
2767
|
+
const { x: targetX, y: targetY } = getTarget(node);
|
|
2768
|
+
const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
|
|
2769
|
+
const flipped = angleDeg > 90 || angleDeg < -90;
|
|
2770
|
+
group.append("text").attr("class", className).attr("dy", "0.32em").attr("transform", `rotate(${flipped ? angleDeg + 180 : angleDeg})`).attr("x", flipped ? -(r + offset) : r + offset).attr("text-anchor", flipped ? "end" : "start").attr("opacity", 0).style("cursor", "pointer").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2771
|
+
};
|
|
2772
|
+
var appendRadialGroupLabel = (group, node, label, r, options = {}) => {
|
|
2773
|
+
if (!label) {
|
|
2774
|
+
return;
|
|
2775
|
+
}
|
|
2776
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label dx-cluster-label-group" } = options;
|
|
2777
|
+
const { x: targetX, y: targetY } = getTarget(node);
|
|
2778
|
+
const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
|
|
2779
|
+
const flipped = angleDeg > 90 || angleDeg < -90;
|
|
2780
|
+
group.append("text").attr("class", className).attr("dy", "0.32em").attr("transform", `rotate(${flipped ? angleDeg + 180 : angleDeg})`).attr("x", flipped ? r + offset : -(r + offset)).attr("text-anchor", flipped ? "start" : "end").attr("opacity", 0).style("pointer-events", "none").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2781
|
+
};
|
|
2782
|
+
var appendRootLabel = (group, label, r, options = {}) => {
|
|
2783
|
+
if (!label) {
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = 6, className = "dx-cluster-label dx-cluster-label-root" } = options;
|
|
2787
|
+
group.append("text").attr("class", className).attr("text-anchor", "middle").attr("y", -(r + offset)).attr("opacity", 0).style("pointer-events", "none").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2788
|
+
};
|
|
2789
|
+
|
|
1119
2790
|
// src/graph/renderer/linker.ts
|
|
1120
2791
|
import { line as line3 } from "d3";
|
|
1121
2792
|
var createLine3 = line3();
|
|
@@ -1139,117 +2810,504 @@ var linkerRenderer = (root, { source, target, point } = {}) => {
|
|
|
1139
2810
|
});
|
|
1140
2811
|
};
|
|
1141
2812
|
|
|
2813
|
+
// src/hooks/useGrid.ts
|
|
2814
|
+
import { line as line4, range, select as select5 } from "d3";
|
|
2815
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
2816
|
+
|
|
2817
|
+
// src/hooks/useSvgContext.ts
|
|
2818
|
+
import { createContext, useContext } from "react";
|
|
2819
|
+
import { createRef } from "react";
|
|
2820
|
+
import { raise } from "@dxos/debug";
|
|
2821
|
+
var SVGContext = class {
|
|
2822
|
+
_ref = createRef();
|
|
2823
|
+
_scale;
|
|
2824
|
+
_centered;
|
|
2825
|
+
_size;
|
|
2826
|
+
_center;
|
|
2827
|
+
resized = new EventEmitter();
|
|
2828
|
+
constructor({ scale = new Scale(), centered = true }) {
|
|
2829
|
+
this._scale = scale;
|
|
2830
|
+
this._centered = centered;
|
|
2831
|
+
}
|
|
2832
|
+
get ref() {
|
|
2833
|
+
return this._ref;
|
|
2834
|
+
}
|
|
2835
|
+
get svg() {
|
|
2836
|
+
return this._ref.current;
|
|
2837
|
+
}
|
|
2838
|
+
get scale() {
|
|
2839
|
+
return this._scale;
|
|
2840
|
+
}
|
|
2841
|
+
get center() {
|
|
2842
|
+
return this._center;
|
|
2843
|
+
}
|
|
2844
|
+
get size() {
|
|
2845
|
+
return this._size;
|
|
2846
|
+
}
|
|
2847
|
+
/**
|
|
2848
|
+
* https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox
|
|
2849
|
+
*/
|
|
2850
|
+
get viewBox() {
|
|
2851
|
+
const [x, y] = this.center;
|
|
2852
|
+
return `${x},${y},${this._size.width},${this._size.height}`;
|
|
2853
|
+
}
|
|
2854
|
+
setSize(size) {
|
|
2855
|
+
this._size = {
|
|
2856
|
+
...size
|
|
2857
|
+
};
|
|
2858
|
+
this._center = this._centered ? [
|
|
2859
|
+
-Math.floor(size.width / 2),
|
|
2860
|
+
-Math.floor(size.height / 2)
|
|
2861
|
+
] : [
|
|
2862
|
+
0,
|
|
2863
|
+
0
|
|
2864
|
+
];
|
|
2865
|
+
this.resized.emit(this);
|
|
2866
|
+
}
|
|
2867
|
+
setTransform(transform) {
|
|
2868
|
+
if (this._scale.setTransform(transform)) {
|
|
2869
|
+
this.resized.emit(this);
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
/**
|
|
2873
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
|
|
2874
|
+
* @param point
|
|
2875
|
+
*/
|
|
2876
|
+
elementFromPoint(point) {
|
|
2877
|
+
const [x, y] = point;
|
|
2878
|
+
const [cx, cy] = this._center;
|
|
2879
|
+
return document.elementFromPoint(cx + x, cy + y);
|
|
2880
|
+
}
|
|
2881
|
+
};
|
|
2882
|
+
var SVGContextType = createContext(void 0);
|
|
2883
|
+
var SVGContextProvider = SVGContextType.Provider;
|
|
2884
|
+
var useSvgContext = () => {
|
|
2885
|
+
return useContext(SVGContextType) ?? raise(new Error("Missing SVGRoot"));
|
|
2886
|
+
};
|
|
2887
|
+
|
|
2888
|
+
// src/hooks/useGrid.ts
|
|
2889
|
+
var createLine4 = line4();
|
|
2890
|
+
var createGrid = (context, options) => {
|
|
2891
|
+
if (!context.size) {
|
|
2892
|
+
return [];
|
|
2893
|
+
}
|
|
2894
|
+
const paths = [];
|
|
2895
|
+
const { width, height } = context.size;
|
|
2896
|
+
const { x, y, k } = context.scale.transform;
|
|
2897
|
+
const s = 1 / k;
|
|
2898
|
+
const w = width * s;
|
|
2899
|
+
const h = height * s;
|
|
2900
|
+
const dx = -(x + width / 2) * s;
|
|
2901
|
+
const dy = -(y + height / 2) * s;
|
|
2902
|
+
if (options.axis) {
|
|
2903
|
+
const axis = [
|
|
2904
|
+
[
|
|
2905
|
+
[
|
|
2906
|
+
0,
|
|
2907
|
+
dy
|
|
2908
|
+
],
|
|
2909
|
+
[
|
|
2910
|
+
0,
|
|
2911
|
+
dy + h
|
|
2912
|
+
]
|
|
2913
|
+
],
|
|
2914
|
+
[
|
|
2915
|
+
[
|
|
2916
|
+
dx,
|
|
2917
|
+
0
|
|
2918
|
+
],
|
|
2919
|
+
[
|
|
2920
|
+
dx + w,
|
|
2921
|
+
0
|
|
2922
|
+
]
|
|
2923
|
+
]
|
|
2924
|
+
];
|
|
2925
|
+
paths.push({
|
|
2926
|
+
id: "axis",
|
|
2927
|
+
class: "dx-axis",
|
|
2928
|
+
path: axis.map((line5) => createLine4(line5)).join()
|
|
2929
|
+
});
|
|
2930
|
+
}
|
|
2931
|
+
if (options.grid) {
|
|
2932
|
+
const mod = (n, size, delta = 0) => Math.floor(n / size + delta) * size;
|
|
2933
|
+
const majorSize = context.scale.gridSize;
|
|
2934
|
+
const xMajor = range(-mod((x + width / 2) * s, majorSize), mod((-x + width / 2) * s, majorSize, 1), majorSize);
|
|
2935
|
+
const yMajor = range(-mod((y + height / 2) * s, majorSize), mod((-y + height / 2) * s, majorSize, 1), majorSize);
|
|
2936
|
+
const major = [
|
|
2937
|
+
...xMajor.filter((x2) => !options.axis || x2).map((x2) => [
|
|
2938
|
+
[
|
|
2939
|
+
x2,
|
|
2940
|
+
dy
|
|
2941
|
+
],
|
|
2942
|
+
[
|
|
2943
|
+
x2,
|
|
2944
|
+
dy + h
|
|
2945
|
+
]
|
|
2946
|
+
]),
|
|
2947
|
+
...yMajor.filter((y2) => !options.axis || y2).map((y2) => [
|
|
2948
|
+
[
|
|
2949
|
+
dx,
|
|
2950
|
+
y2
|
|
2951
|
+
],
|
|
2952
|
+
[
|
|
2953
|
+
dx + w,
|
|
2954
|
+
y2
|
|
2955
|
+
]
|
|
2956
|
+
])
|
|
2957
|
+
];
|
|
2958
|
+
paths.push({
|
|
2959
|
+
id: "major",
|
|
2960
|
+
class: "dx-major",
|
|
2961
|
+
path: major.map((line5) => createLine4(line5)).join()
|
|
2962
|
+
});
|
|
2963
|
+
const minorSize = Math.pow(2, Math.round(Math.log2(s * context.scale.gridSize)));
|
|
2964
|
+
if (majorSize > minorSize) {
|
|
2965
|
+
const xMinor = range(-mod((x + width / 2) * s, minorSize), mod((-x + width / 2) * s, minorSize, 1), minorSize);
|
|
2966
|
+
const yMinor = range(-mod((y + height / 2) * s, minorSize), mod((-y + height / 2) * s, minorSize, 1), minorSize);
|
|
2967
|
+
const minor = [
|
|
2968
|
+
...xMinor.filter((x2) => xMajor.indexOf(x2) === -1).map((x2) => [
|
|
2969
|
+
[
|
|
2970
|
+
x2,
|
|
2971
|
+
dy
|
|
2972
|
+
],
|
|
2973
|
+
[
|
|
2974
|
+
x2,
|
|
2975
|
+
dy + h
|
|
2976
|
+
]
|
|
2977
|
+
]),
|
|
2978
|
+
...yMinor.filter((y2) => yMajor.indexOf(y2) === -1).map((y2) => [
|
|
2979
|
+
[
|
|
2980
|
+
dx,
|
|
2981
|
+
y2
|
|
2982
|
+
],
|
|
2983
|
+
[
|
|
2984
|
+
dx + w,
|
|
2985
|
+
y2
|
|
2986
|
+
]
|
|
2987
|
+
])
|
|
2988
|
+
];
|
|
2989
|
+
paths.push({
|
|
2990
|
+
id: "minor",
|
|
2991
|
+
class: "dx-minor",
|
|
2992
|
+
path: minor.map((line5) => createLine4(line5)).join()
|
|
2993
|
+
});
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
return paths;
|
|
2997
|
+
};
|
|
2998
|
+
var defaultGridOptions = {
|
|
2999
|
+
visible: true,
|
|
3000
|
+
axis: true,
|
|
3001
|
+
grid: true
|
|
3002
|
+
};
|
|
3003
|
+
var GridController = class {
|
|
3004
|
+
_ref;
|
|
3005
|
+
_context;
|
|
3006
|
+
_options;
|
|
3007
|
+
_visible = false;
|
|
3008
|
+
constructor(_ref, _context, _options) {
|
|
3009
|
+
this._ref = _ref;
|
|
3010
|
+
this._context = _context;
|
|
3011
|
+
this._options = _options;
|
|
3012
|
+
this._visible = this._options.visible ?? true;
|
|
3013
|
+
}
|
|
3014
|
+
get ref() {
|
|
3015
|
+
return this._ref;
|
|
3016
|
+
}
|
|
3017
|
+
get visible() {
|
|
3018
|
+
return this._visible;
|
|
3019
|
+
}
|
|
3020
|
+
draw() {
|
|
3021
|
+
if (!this._context.size) {
|
|
3022
|
+
return;
|
|
3023
|
+
}
|
|
3024
|
+
const paths = this._visible ? createGrid(this._context, this._options) : [];
|
|
3025
|
+
const root = select5(this._ref.current);
|
|
3026
|
+
root.selectAll("path").data(paths, (path) => path.id).join("path").style("pointer-events", "none").attr("d", (d) => d.path).attr("class", (d) => d.class);
|
|
3027
|
+
const transform = this._context.scale.transform;
|
|
3028
|
+
if (transform) {
|
|
3029
|
+
root.attr("transform", transform);
|
|
3030
|
+
root.attr("stroke-width", 1 / transform.k);
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
setVisible(visible) {
|
|
3034
|
+
this._visible = visible;
|
|
3035
|
+
this.draw();
|
|
3036
|
+
return this;
|
|
3037
|
+
}
|
|
3038
|
+
};
|
|
3039
|
+
var useGrid = (options = defaultGridOptions) => {
|
|
3040
|
+
const ref = useRef(null);
|
|
3041
|
+
const context = useSvgContext();
|
|
3042
|
+
const controller = useMemo(() => new GridController(ref, context, options), []);
|
|
3043
|
+
useEffect(() => context.resized.on(() => controller.draw()), [
|
|
3044
|
+
context,
|
|
3045
|
+
controller
|
|
3046
|
+
]);
|
|
3047
|
+
return controller;
|
|
3048
|
+
};
|
|
3049
|
+
|
|
3050
|
+
// src/hooks/useZoom.ts
|
|
3051
|
+
import { select as select6, zoom, zoomIdentity as zoomIdentity2 } from "d3";
|
|
3052
|
+
import defaultsDeep from "lodash.defaultsdeep";
|
|
3053
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
3054
|
+
var defaultZoomOptions = {
|
|
3055
|
+
enabled: true,
|
|
3056
|
+
extent: [
|
|
3057
|
+
1 / 4,
|
|
3058
|
+
4
|
|
3059
|
+
],
|
|
3060
|
+
onDblClick: (zoom2) => zoom2.reset()
|
|
3061
|
+
};
|
|
3062
|
+
var ZoomHandler = class {
|
|
3063
|
+
_ref;
|
|
3064
|
+
_context;
|
|
3065
|
+
_zoom;
|
|
3066
|
+
_options;
|
|
3067
|
+
_enabled;
|
|
3068
|
+
constructor(_ref, _context, options) {
|
|
3069
|
+
this._ref = _ref;
|
|
3070
|
+
this._context = _context;
|
|
3071
|
+
this._options = defaultsDeep({}, options, defaultZoomOptions);
|
|
3072
|
+
this._enabled = this._options.enabled ?? true;
|
|
3073
|
+
this._zoom = zoom().scaleExtent(this._options.extent ?? defaultZoomOptions.extent);
|
|
3074
|
+
}
|
|
3075
|
+
/**
|
|
3076
|
+
* Gets the reference which the transform is applied to.
|
|
3077
|
+
*/
|
|
3078
|
+
get ref() {
|
|
3079
|
+
return this._ref;
|
|
3080
|
+
}
|
|
3081
|
+
get zoom() {
|
|
3082
|
+
return this._zoom;
|
|
3083
|
+
}
|
|
3084
|
+
init() {
|
|
3085
|
+
this.setEnabled(this._enabled);
|
|
3086
|
+
this.reset(0);
|
|
3087
|
+
return this;
|
|
3088
|
+
}
|
|
3089
|
+
setEnabled(enable) {
|
|
3090
|
+
if (enable) {
|
|
3091
|
+
select6(this._context.svg).call(this._zoom).on(
|
|
3092
|
+
"dblclick.zoom",
|
|
3093
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3094
|
+
// @ts-ignore
|
|
3095
|
+
this._options?.onDblClick ? () => {
|
|
3096
|
+
this._options?.onDblClick(this);
|
|
3097
|
+
} : null
|
|
3098
|
+
);
|
|
3099
|
+
} else {
|
|
3100
|
+
select6(this._context.svg).on(".zoom", null);
|
|
3101
|
+
}
|
|
3102
|
+
this._enabled = enable;
|
|
3103
|
+
return this;
|
|
3104
|
+
}
|
|
3105
|
+
reset(duration = 500) {
|
|
3106
|
+
const scale = 1;
|
|
3107
|
+
const transform = zoomIdentity2.scale(scale);
|
|
3108
|
+
select6(this._context.svg).transition().duration(duration).call(this._zoom.transform, transform);
|
|
3109
|
+
return this;
|
|
3110
|
+
}
|
|
3111
|
+
};
|
|
3112
|
+
var useZoom = (options = defaultZoomOptions) => {
|
|
3113
|
+
const context = useSvgContext();
|
|
3114
|
+
const ref = useRef2(null);
|
|
3115
|
+
const handler = useMemo2(() => new ZoomHandler(ref, context, options), [
|
|
3116
|
+
context,
|
|
3117
|
+
options
|
|
3118
|
+
]);
|
|
3119
|
+
useEffect2(() => {
|
|
3120
|
+
handler.zoom.on("zoom", ({ transform }) => {
|
|
3121
|
+
context.setTransform(transform);
|
|
3122
|
+
select6(ref.current).attr("transform", transform);
|
|
3123
|
+
});
|
|
3124
|
+
handler.init();
|
|
3125
|
+
}, [
|
|
3126
|
+
handler
|
|
3127
|
+
]);
|
|
3128
|
+
return handler;
|
|
3129
|
+
};
|
|
3130
|
+
|
|
1142
3131
|
// src/components/Graph/Graph.tsx
|
|
1143
|
-
var
|
|
1144
|
-
var GraphInner = ({ classNames, model, projector:
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
3132
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
3133
|
+
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, onPointerMove, onPointerLeave, ...props }, forwardedRef) => {
|
|
3134
|
+
const context = useSvgContext();
|
|
3135
|
+
const graphRef = useRef3(null);
|
|
3136
|
+
const { projector, renderer } = useMemo3(() => {
|
|
3137
|
+
let projector2 = projectorProp;
|
|
3138
|
+
if (!projector2) {
|
|
3139
|
+
projector2 = new GraphForceProjector(context);
|
|
3140
|
+
}
|
|
3141
|
+
let renderer2 = rendererProp;
|
|
3142
|
+
if (!renderer2) {
|
|
3143
|
+
renderer2 = new GraphRenderer(context, graphRef, {
|
|
3144
|
+
...props,
|
|
3145
|
+
// TODO(burdon): Replace drag when projector is updated.
|
|
3146
|
+
drag: drag2 ? createGraphDrag(context, projector2) : void 0,
|
|
3147
|
+
arrows: {
|
|
3148
|
+
end: arrows
|
|
3149
|
+
},
|
|
3150
|
+
// Projector intercept first so built-in interactions (e.g. cluster collapse) can
|
|
3151
|
+
// run without consumers wiring them. Returning true suppresses the user handler.
|
|
3152
|
+
onNodeClick: (node, event) => {
|
|
3153
|
+
if (projector2.handleNodeClick(node, event)) {
|
|
3154
|
+
return;
|
|
3155
|
+
}
|
|
3156
|
+
onSelect?.(node, event);
|
|
3157
|
+
},
|
|
3158
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0,
|
|
3159
|
+
// Pair pointerenter with leave so consumers can clear hover-driven previews.
|
|
3160
|
+
// The callback receives `null` on leave (event still carries the source).
|
|
3161
|
+
onNodePointerLeave: onInspect ? (_node, event) => onInspect(null, event) : void 0
|
|
3162
|
+
});
|
|
3163
|
+
}
|
|
3164
|
+
return {
|
|
3165
|
+
projector: projector2,
|
|
3166
|
+
renderer: renderer2
|
|
3167
|
+
};
|
|
3168
|
+
}, [
|
|
3169
|
+
context,
|
|
3170
|
+
projectorProp,
|
|
3171
|
+
rendererProp,
|
|
3172
|
+
drag2,
|
|
3173
|
+
arrows,
|
|
3174
|
+
onSelect,
|
|
3175
|
+
onInspect,
|
|
3176
|
+
props.labels,
|
|
3177
|
+
props.subgraphs,
|
|
3178
|
+
props.attributes,
|
|
3179
|
+
props.renderNode,
|
|
3180
|
+
props.highlightOnHover,
|
|
3181
|
+
props.applyNode,
|
|
3182
|
+
props.edgeOpacity
|
|
3183
|
+
]);
|
|
3184
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
3185
|
+
refresh: () => {
|
|
3186
|
+
projector.updateData(model?.graph);
|
|
3187
|
+
},
|
|
3188
|
+
repaint: () => {
|
|
3189
|
+
renderer.render(projector.layout);
|
|
3190
|
+
},
|
|
3191
|
+
findNode: (id) => {
|
|
3192
|
+
return graphRef.current?.querySelector(`g[data-id="${id}"]`);
|
|
3193
|
+
}
|
|
3194
|
+
}), [
|
|
3195
|
+
model,
|
|
3196
|
+
projector,
|
|
3197
|
+
renderer
|
|
3198
|
+
]);
|
|
3199
|
+
useEffect3(() => {
|
|
3200
|
+
const cleanup = combine(
|
|
3201
|
+
// Subscribe to model changes if reactive model.
|
|
3202
|
+
model ? model.subscribe(() => {
|
|
1194
3203
|
projector.updateData(model?.graph);
|
|
1195
|
-
})
|
|
3204
|
+
}) : void 0,
|
|
3205
|
+
projector.updated.on(({ layout, kind }) => {
|
|
1196
3206
|
try {
|
|
1197
|
-
|
|
3207
|
+
if (kind === "positions") {
|
|
3208
|
+
renderer.applyPositions(layout);
|
|
3209
|
+
} else {
|
|
3210
|
+
renderer.render(layout);
|
|
3211
|
+
}
|
|
1198
3212
|
} catch (error) {
|
|
3213
|
+
log11.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 95, S: void 0 });
|
|
1199
3214
|
void projector.stop();
|
|
1200
|
-
log6.catch(error, void 0, {
|
|
1201
|
-
F: __dxlog_file8,
|
|
1202
|
-
L: 108,
|
|
1203
|
-
S: void 0,
|
|
1204
|
-
C: (f, a) => f(...a)
|
|
1205
|
-
});
|
|
1206
3215
|
}
|
|
1207
|
-
})
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
projector
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
3216
|
+
})
|
|
3217
|
+
);
|
|
3218
|
+
projector.updateData(model?.graph);
|
|
3219
|
+
return cleanup;
|
|
3220
|
+
}, [
|
|
3221
|
+
model,
|
|
3222
|
+
projector,
|
|
3223
|
+
renderer
|
|
3224
|
+
]);
|
|
3225
|
+
useEffect3(() => {
|
|
3226
|
+
void projector.start();
|
|
3227
|
+
return () => {
|
|
3228
|
+
void projector.stop();
|
|
3229
|
+
};
|
|
3230
|
+
}, [
|
|
3231
|
+
projector
|
|
3232
|
+
]);
|
|
3233
|
+
useEffect3(() => {
|
|
3234
|
+
if (!onPointerMove && !onPointerLeave) {
|
|
3235
|
+
return;
|
|
3236
|
+
}
|
|
3237
|
+
const svg = context.svg;
|
|
3238
|
+
if (!svg) {
|
|
3239
|
+
return;
|
|
3240
|
+
}
|
|
3241
|
+
const previousPointerEvents = svg.style.pointerEvents;
|
|
3242
|
+
svg.style.pointerEvents = "all";
|
|
3243
|
+
const handleMove = (event) => {
|
|
3244
|
+
if (!onPointerMove) {
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
const target = graphRef.current;
|
|
3248
|
+
const ctm = target?.getScreenCTM();
|
|
3249
|
+
if (!target || !ctm) {
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
const point = svg.createSVGPoint();
|
|
3253
|
+
point.x = event.clientX;
|
|
3254
|
+
point.y = event.clientY;
|
|
3255
|
+
const modelPoint = point.matrixTransform(ctm.inverse());
|
|
3256
|
+
onPointerMove({
|
|
3257
|
+
x: modelPoint.x,
|
|
3258
|
+
y: modelPoint.y
|
|
3259
|
+
}, event);
|
|
3260
|
+
};
|
|
3261
|
+
const handleLeave = (event) => {
|
|
3262
|
+
onPointerLeave?.(event);
|
|
3263
|
+
};
|
|
3264
|
+
svg.addEventListener("pointermove", handleMove);
|
|
3265
|
+
svg.addEventListener("pointerleave", handleLeave);
|
|
3266
|
+
return () => {
|
|
3267
|
+
svg.removeEventListener("pointermove", handleMove);
|
|
3268
|
+
svg.removeEventListener("pointerleave", handleLeave);
|
|
3269
|
+
svg.style.pointerEvents = previousPointerEvents;
|
|
3270
|
+
};
|
|
3271
|
+
}, [
|
|
3272
|
+
context,
|
|
3273
|
+
onPointerMove,
|
|
3274
|
+
onPointerLeave
|
|
3275
|
+
]);
|
|
3276
|
+
return /* @__PURE__ */ React.createElement("g", {
|
|
3277
|
+
ref: graphRef,
|
|
3278
|
+
className: mx("dx-graph", classNames)
|
|
3279
|
+
});
|
|
1228
3280
|
};
|
|
1229
3281
|
var Graph = /* @__PURE__ */ forwardRef(GraphInner);
|
|
1230
3282
|
|
|
1231
3283
|
// src/components/Mesh/Mesh.tsx
|
|
1232
|
-
import { geoPath, select as
|
|
1233
|
-
import { useEffect as
|
|
3284
|
+
import { geoPath, select as select7 } from "d3";
|
|
3285
|
+
import { useEffect as useEffect4 } from "react";
|
|
1234
3286
|
import { feature, mesh } from "topojson-client";
|
|
1235
3287
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
1236
3288
|
const { svg, size } = useSvgContext();
|
|
1237
|
-
|
|
1238
|
-
if (size) {
|
|
1239
|
-
|
|
1240
|
-
const projection = hexProjection(radius);
|
|
1241
|
-
const path = geoPath().projection(projection);
|
|
1242
|
-
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);
|
|
1243
|
-
select5(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
1244
|
-
const redraw = (border) => {
|
|
1245
|
-
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
1246
|
-
};
|
|
1247
|
-
select5(svg).append("path").attr("class", "border").call(redraw);
|
|
3289
|
+
useEffect4(() => {
|
|
3290
|
+
if (!size) {
|
|
3291
|
+
return;
|
|
1248
3292
|
}
|
|
3293
|
+
const topology = hexTopology(size, radius, value);
|
|
3294
|
+
const projection = hexProjection(radius);
|
|
3295
|
+
const path = geoPath().projection(projection);
|
|
3296
|
+
const root = select7(svg).selectAll("g.dx-mesh-root").data([
|
|
3297
|
+
null
|
|
3298
|
+
]).join("g").classed("dx-mesh-root", true);
|
|
3299
|
+
root.selectAll("*").remove();
|
|
3300
|
+
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);
|
|
3301
|
+
root.append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
3302
|
+
const redraw = (border) => {
|
|
3303
|
+
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
3304
|
+
};
|
|
3305
|
+
root.append("path").attr("class", "border").call(redraw);
|
|
1249
3306
|
}, [
|
|
1250
3307
|
svg,
|
|
1251
3308
|
size,
|
|
1252
|
-
value
|
|
3309
|
+
value,
|
|
3310
|
+
radius
|
|
1253
3311
|
]);
|
|
1254
3312
|
return null;
|
|
1255
3313
|
};
|
|
@@ -1360,116 +3418,181 @@ var hexProjection = (radius) => {
|
|
|
1360
3418
|
};
|
|
1361
3419
|
};
|
|
1362
3420
|
|
|
3421
|
+
// src/components/SVG/FPS.tsx
|
|
3422
|
+
import React2, { useEffect as useEffect5, useState } from "react";
|
|
3423
|
+
import { mx as mx2 } from "@dxos/ui-theme";
|
|
3424
|
+
var PADDING = 8;
|
|
3425
|
+
var FPS = ({ classNames, corner = "top-right", margin = PADDING }) => {
|
|
3426
|
+
const context = useSvgContext();
|
|
3427
|
+
const [size, setSize] = useState(context.size);
|
|
3428
|
+
const [fps, setFps] = useState(null);
|
|
3429
|
+
useEffect5(() => {
|
|
3430
|
+
setSize(context.size);
|
|
3431
|
+
return context.resized.on((ctx) => setSize(ctx.size));
|
|
3432
|
+
}, [
|
|
3433
|
+
context
|
|
3434
|
+
]);
|
|
3435
|
+
useEffect5(() => {
|
|
3436
|
+
let frames = 0;
|
|
3437
|
+
let windowStart = performance.now();
|
|
3438
|
+
let rafId = 0;
|
|
3439
|
+
const loop = (now) => {
|
|
3440
|
+
frames++;
|
|
3441
|
+
const elapsed = now - windowStart;
|
|
3442
|
+
if (elapsed >= 1e3) {
|
|
3443
|
+
setFps(frames * 1e3 / elapsed);
|
|
3444
|
+
frames = 0;
|
|
3445
|
+
windowStart = now;
|
|
3446
|
+
}
|
|
3447
|
+
rafId = requestAnimationFrame(loop);
|
|
3448
|
+
};
|
|
3449
|
+
rafId = requestAnimationFrame(loop);
|
|
3450
|
+
return () => cancelAnimationFrame(rafId);
|
|
3451
|
+
}, []);
|
|
3452
|
+
if (!size) {
|
|
3453
|
+
return null;
|
|
3454
|
+
}
|
|
3455
|
+
const halfW = size.width / 2;
|
|
3456
|
+
const halfH = size.height / 2;
|
|
3457
|
+
const left = corner === "top-left" || corner === "bottom-left";
|
|
3458
|
+
const top = corner === "top-left" || corner === "top-right";
|
|
3459
|
+
const x = left ? -halfW + margin : halfW - margin;
|
|
3460
|
+
const y = top ? -halfH + margin : halfH - margin;
|
|
3461
|
+
const textAnchor = left ? "start" : "end";
|
|
3462
|
+
const dominantBaseline = top ? "hanging" : "alphabetic";
|
|
3463
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
3464
|
+
className: "dx-fps",
|
|
3465
|
+
style: {
|
|
3466
|
+
pointerEvents: "none"
|
|
3467
|
+
}
|
|
3468
|
+
}, /* @__PURE__ */ React2.createElement("text", {
|
|
3469
|
+
x,
|
|
3470
|
+
y,
|
|
3471
|
+
textAnchor,
|
|
3472
|
+
dominantBaseline,
|
|
3473
|
+
className: mx2("font-mono text-xs fill-neutral-500 tabular-nums", classNames)
|
|
3474
|
+
}, fps == null ? "\u2014 fps" : `${fps.toFixed(0)} fps`));
|
|
3475
|
+
};
|
|
3476
|
+
|
|
1363
3477
|
// src/components/SVG/Grid.tsx
|
|
1364
|
-
import
|
|
1365
|
-
import
|
|
1366
|
-
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
3478
|
+
import React3 from "react";
|
|
3479
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
1367
3480
|
var Grid = ({ classNames, ...props }) => {
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
className: mx2("dx-grid", classNames)
|
|
1374
|
-
});
|
|
1375
|
-
} finally {
|
|
1376
|
-
_effect.f();
|
|
1377
|
-
}
|
|
3481
|
+
const { ref } = useGrid(props);
|
|
3482
|
+
return /* @__PURE__ */ React3.createElement("g", {
|
|
3483
|
+
ref,
|
|
3484
|
+
className: mx3("dx-grid", classNames)
|
|
3485
|
+
});
|
|
1378
3486
|
};
|
|
1379
3487
|
|
|
1380
3488
|
// src/components/SVG/Markers.tsx
|
|
1381
|
-
import {
|
|
1382
|
-
import {
|
|
1383
|
-
import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
3489
|
+
import { select as select8 } from "d3";
|
|
3490
|
+
import React4, { useEffect as useEffect6, useRef as useRef4 } from "react";
|
|
1384
3491
|
var Markers = ({ arrowSize, className }) => {
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
className
|
|
1398
|
-
});
|
|
1399
|
-
} finally {
|
|
1400
|
-
_effect.f();
|
|
1401
|
-
}
|
|
3492
|
+
const ref = useRef4(null);
|
|
3493
|
+
useEffect6(() => {
|
|
3494
|
+
select8(ref.current).call(createMarkers({
|
|
3495
|
+
arrowSize
|
|
3496
|
+
}));
|
|
3497
|
+
}, [
|
|
3498
|
+
ref
|
|
3499
|
+
]);
|
|
3500
|
+
return /* @__PURE__ */ React4.createElement("defs", {
|
|
3501
|
+
ref,
|
|
3502
|
+
className
|
|
3503
|
+
});
|
|
1402
3504
|
};
|
|
1403
3505
|
|
|
1404
3506
|
// src/components/SVG/Root.tsx
|
|
1405
|
-
import {
|
|
1406
|
-
import {
|
|
1407
|
-
import
|
|
1408
|
-
import {
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
3507
|
+
import { select as select9 } from "d3";
|
|
3508
|
+
import React5, { forwardRef as forwardRef2, useEffect as useEffect7, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4, useState as useState2 } from "react";
|
|
3509
|
+
import { composableProps } from "@dxos/react-ui";
|
|
3510
|
+
import { mx as mx4 } from "@dxos/ui-theme";
|
|
3511
|
+
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
3512
|
+
const [container, setContainer] = useState2(null);
|
|
3513
|
+
const [size, setSize] = useState2({
|
|
3514
|
+
width: 0,
|
|
3515
|
+
height: 0
|
|
3516
|
+
});
|
|
3517
|
+
useEffect7(() => {
|
|
3518
|
+
if (!container) {
|
|
3519
|
+
return;
|
|
3520
|
+
}
|
|
3521
|
+
const rect = container.getBoundingClientRect();
|
|
3522
|
+
setSize({
|
|
3523
|
+
width: rect.width,
|
|
3524
|
+
height: rect.height
|
|
1415
3525
|
});
|
|
1416
|
-
const
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
props.centered
|
|
1421
|
-
]);
|
|
1422
|
-
useImperativeHandle2(ref, () => context, [
|
|
1423
|
-
context
|
|
1424
|
-
]);
|
|
1425
|
-
useEffect4(() => {
|
|
1426
|
-
if (width && height) {
|
|
1427
|
-
context.setSize({
|
|
1428
|
-
width,
|
|
1429
|
-
height
|
|
1430
|
-
});
|
|
1431
|
-
select7(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
3526
|
+
const observer = new ResizeObserver((entries) => {
|
|
3527
|
+
const entry = entries[0];
|
|
3528
|
+
if (!entry) {
|
|
3529
|
+
return;
|
|
1432
3530
|
}
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
3531
|
+
const { width: width2, height: height2 } = entry.contentRect;
|
|
3532
|
+
setSize((prev) => prev.width === width2 && prev.height === height2 ? prev : {
|
|
3533
|
+
width: width2,
|
|
3534
|
+
height: height2
|
|
3535
|
+
});
|
|
3536
|
+
});
|
|
3537
|
+
observer.observe(container);
|
|
3538
|
+
return () => observer.disconnect();
|
|
3539
|
+
}, [
|
|
3540
|
+
container
|
|
3541
|
+
]);
|
|
3542
|
+
const { width, height } = size;
|
|
3543
|
+
const context = useMemo4(() => {
|
|
3544
|
+
return new SVGContext({
|
|
3545
|
+
scale,
|
|
3546
|
+
centered
|
|
3547
|
+
});
|
|
3548
|
+
}, [
|
|
3549
|
+
scale,
|
|
3550
|
+
centered
|
|
3551
|
+
]);
|
|
3552
|
+
useImperativeHandle2(ref, () => context, [
|
|
3553
|
+
context
|
|
3554
|
+
]);
|
|
3555
|
+
useEffect7(() => {
|
|
3556
|
+
if (width && height) {
|
|
3557
|
+
context.setSize({
|
|
3558
|
+
width,
|
|
3559
|
+
height
|
|
3560
|
+
});
|
|
3561
|
+
select9(context.svg).attr("display", "block").attr("viewBox", context.viewBox).attr("width", width).attr("height", height);
|
|
3562
|
+
}
|
|
3563
|
+
}, [
|
|
3564
|
+
context,
|
|
3565
|
+
width,
|
|
3566
|
+
height
|
|
3567
|
+
]);
|
|
3568
|
+
const ready = width !== 0 && height !== 0;
|
|
3569
|
+
return /* @__PURE__ */ React5.createElement(SVGContextProvider, {
|
|
3570
|
+
value: context
|
|
3571
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
3572
|
+
...composableProps(props, {
|
|
3573
|
+
classNames: "dx-expander"
|
|
3574
|
+
}),
|
|
3575
|
+
ref: setContainer
|
|
3576
|
+
}, /* @__PURE__ */ React5.createElement("svg", {
|
|
3577
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3578
|
+
ref: context.ref,
|
|
3579
|
+
className: mx4("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
3580
|
+
}, ready && children)));
|
|
1452
3581
|
});
|
|
1453
3582
|
|
|
1454
3583
|
// src/components/SVG/Zoom.tsx
|
|
1455
|
-
import {
|
|
1456
|
-
import React5, { memo, useMemo as useMemo3 } from "react";
|
|
3584
|
+
import React6, { memo, useMemo as useMemo5 } from "react";
|
|
1457
3585
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
className
|
|
1469
|
-
}, children);
|
|
1470
|
-
} finally {
|
|
1471
|
-
_effect.f();
|
|
1472
|
-
}
|
|
3586
|
+
const options = useMemo5(() => ({
|
|
3587
|
+
extent
|
|
3588
|
+
}), [
|
|
3589
|
+
JSON.stringify(extent)
|
|
3590
|
+
]);
|
|
3591
|
+
const zoom2 = useZoom(options);
|
|
3592
|
+
return /* @__PURE__ */ React6.createElement("g", {
|
|
3593
|
+
ref: zoom2.ref,
|
|
3594
|
+
className
|
|
3595
|
+
}, children);
|
|
1473
3596
|
});
|
|
1474
3597
|
|
|
1475
3598
|
// src/components/SVG/SVG.tsx
|
|
@@ -1479,11 +3602,12 @@ var SVG = {
|
|
|
1479
3602
|
Markers,
|
|
1480
3603
|
Mesh,
|
|
1481
3604
|
Zoom,
|
|
1482
|
-
Graph
|
|
3605
|
+
Graph,
|
|
3606
|
+
FPS
|
|
1483
3607
|
};
|
|
1484
3608
|
|
|
1485
3609
|
// src/fx/pulsar.ts
|
|
1486
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
3610
|
+
import { easeCubicOut as easeCubicOut2, select as select10 } from "d3";
|
|
1487
3611
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
1488
3612
|
(function(Pulsar2) {
|
|
1489
3613
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -1498,27 +3622,37 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
1498
3622
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
1499
3623
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
1500
3624
|
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() {
|
|
1501
|
-
if (
|
|
1502
|
-
startAnimation(
|
|
3625
|
+
if (select10(this).property(PROP_PULSAR_ACTIVE)) {
|
|
3626
|
+
startAnimation(select10(this), r, options);
|
|
1503
3627
|
} else {
|
|
1504
|
-
|
|
3628
|
+
select10(this).remove();
|
|
1505
3629
|
}
|
|
1506
3630
|
});
|
|
1507
3631
|
};
|
|
1508
3632
|
var Pulsar;
|
|
1509
3633
|
export {
|
|
3634
|
+
CLUSTER_NODE_TYPE_GROUP,
|
|
3635
|
+
CLUSTER_NODE_TYPE_LEAF,
|
|
3636
|
+
CLUSTER_NODE_TYPE_ROOT,
|
|
1510
3637
|
EventEmitter,
|
|
1511
3638
|
FractionUtil,
|
|
1512
3639
|
Graph,
|
|
3640
|
+
GraphBundleProjector,
|
|
3641
|
+
GraphClusterProjector,
|
|
1513
3642
|
GraphForceProjector,
|
|
1514
3643
|
GraphHierarchicalProjector,
|
|
1515
|
-
|
|
3644
|
+
GraphLatticeProjector,
|
|
3645
|
+
GraphPlexusProjector,
|
|
1516
3646
|
GraphProjector,
|
|
1517
3647
|
GraphRadialProjector,
|
|
1518
3648
|
GraphRelationalProjector,
|
|
1519
3649
|
GraphRenderer,
|
|
3650
|
+
GraphSwarmProjector,
|
|
1520
3651
|
GridController,
|
|
1521
3652
|
Mesh,
|
|
3653
|
+
PLEXUS_NODE_TYPE_FOCUS,
|
|
3654
|
+
PLEXUS_NODE_TYPE_OBJECT,
|
|
3655
|
+
PLEXUS_NODE_TYPE_RELATION,
|
|
1522
3656
|
Projector,
|
|
1523
3657
|
Pulsar,
|
|
1524
3658
|
Renderer,
|
|
@@ -1529,6 +3663,9 @@ export {
|
|
|
1529
3663
|
Screen,
|
|
1530
3664
|
Vector,
|
|
1531
3665
|
ZoomHandler,
|
|
3666
|
+
appendRadialGroupLabel,
|
|
3667
|
+
appendRadialLeafLabel,
|
|
3668
|
+
appendRootLabel,
|
|
1532
3669
|
createGraphDrag,
|
|
1533
3670
|
createMarkers,
|
|
1534
3671
|
defaultForceOptions,
|