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