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