@dxos/react-ui-graph 0.8.4-main.422d1c7879 → 0.8.4-main.43cb759274
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/dist/lib/browser/{chunk-LKC455GK.mjs → chunk-EASNZZ7B.mjs} +1 -1
- package/dist/lib/browser/{chunk-LKC455GK.mjs.map → chunk-EASNZZ7B.mjs.map} +2 -2
- package/dist/lib/browser/index.mjs +1783 -496
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/{chunk-JE4KZCUF.mjs → chunk-JSE2X4ML.mjs} +1 -1
- package/dist/lib/node-esm/{chunk-JE4KZCUF.mjs.map → chunk-JSE2X4ML.mjs.map} +2 -2
- package/dist/lib/node-esm/index.mjs +1783 -496
- 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 +1 -1
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/src/components/Graph/Graph.d.ts +20 -2
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +3 -3
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/FPS.d.ts +20 -0
- package/dist/types/src/components/SVG/FPS.d.ts.map +1 -0
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Markers.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +5 -1
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +3 -1
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/fx/pulsar.d.ts.map +1 -1
- package/dist/types/src/graph/markers.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts +47 -0
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +65 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.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.map +1 -1
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts +23 -0
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts +67 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts +2 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts +8 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +6 -0
- 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.map +1 -1
- package/dist/types/src/graph/projector/graph-swarm-projector.d.ts +72 -0
- package/dist/types/src/graph/projector/graph-swarm-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/index.d.ts +5 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts +10 -1
- package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +41 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/index.d.ts +1 -0
- package/dist/types/src/graph/renderer/index.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/labels.d.ts +33 -0
- package/dist/types/src/graph/renderer/labels.d.ts.map +1 -0
- package/dist/types/src/graph/renderer/renderer.d.ts +12 -1
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +14 -0
- package/dist/types/src/graph/types.d.ts.map +1 -1
- package/dist/types/src/hooks/useGrid.d.ts.map +1 -1
- package/dist/types/src/hooks/useStateRef.d.ts.map +1 -1
- package/dist/types/src/hooks/useSvgContext.d.ts.map +1 -1
- package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
- package/dist/types/src/stories/experimental.stories.d.ts +7 -0
- package/dist/types/src/stories/experimental.stories.d.ts.map +1 -0
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +1 -1
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/types/src/util/points.d.ts.map +1 -1
- package/dist/types/src/util/scale.d.ts.map +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -19
- package/src/components/Graph/Graph.stories.tsx +5 -5
- package/src/components/Graph/Graph.tsx +116 -21
- package/src/components/Mesh/Mesh.stories.tsx +6 -4
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/FPS.tsx +91 -0
- package/src/components/SVG/Root.tsx +30 -4
- package/src/components/SVG/SVG.tsx +4 -1
- package/src/graph/projector/graph-bundle-projector.ts +210 -0
- package/src/graph/projector/graph-cluster-projector.ts +337 -0
- package/src/graph/projector/graph-force-projector.ts +6 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +1 -0
- package/src/graph/projector/graph-lattice-projector.ts +86 -0
- package/src/graph/projector/graph-plexus-projector.test.ts +102 -0
- package/src/graph/projector/graph-plexus-projector.ts +309 -0
- package/src/graph/projector/graph-projector.ts +22 -1
- package/src/graph/projector/graph-radial-projector.ts +30 -2
- package/src/graph/projector/graph-relational-projector.ts +1 -0
- package/src/graph/projector/graph-swarm-projector.ts +373 -0
- package/src/graph/projector/index.ts +5 -0
- package/src/graph/projector/projector.ts +12 -3
- package/src/graph/renderer/graph-renderer.ts +289 -30
- package/src/graph/renderer/index.ts +1 -0
- package/src/graph/renderer/labels.ts +138 -0
- package/src/graph/renderer/renderer.ts +15 -4
- package/src/graph/types.ts +14 -0
- package/src/stories/experimental.stories.tsx +446 -0
- package/src/stories/hooks.stories.tsx +6 -1
- package/styles/graph.css +51 -2
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
useDynamicRef,
|
|
3
3
|
useStateRef,
|
|
4
4
|
useTimestamp
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-EASNZZ7B.mjs";
|
|
6
6
|
|
|
7
7
|
// src/components/Graph/Graph.tsx
|
|
8
8
|
import React, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo3, useRef as useRef3 } from "react";
|
|
9
9
|
import { combine } from "@dxos/async";
|
|
10
|
-
import { log as
|
|
10
|
+
import { log as log11 } from "@dxos/log";
|
|
11
11
|
import { mx } from "@dxos/ui-theme";
|
|
12
12
|
|
|
13
13
|
// src/graph/markers.ts
|
|
@@ -61,99 +61,19 @@ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
|
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
// src/graph/projector/graph-
|
|
65
|
-
import {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
let mode;
|
|
72
|
-
let source;
|
|
73
|
-
let target;
|
|
74
|
-
let offset;
|
|
75
|
-
let moved = false;
|
|
76
|
-
const keyMod = (event, key) => {
|
|
77
|
-
const modKey = options?.[key] ?? defaultDragOptions[key];
|
|
78
|
-
return modKey === void 0 || event[modKey];
|
|
79
|
-
};
|
|
80
|
-
return drag().filter((event) => !event.ctrlKey).on("start", function(event, d) {
|
|
81
|
-
source = d;
|
|
82
|
-
offset = pointer(event, this.parentElement);
|
|
83
|
-
if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) {
|
|
84
|
-
mode = 1;
|
|
85
|
-
} else if (keyMod(event.sourceEvent, "dragMod")) {
|
|
86
|
-
mode = 0;
|
|
87
|
-
}
|
|
88
|
-
}).on("drag", function(event, d) {
|
|
89
|
-
const parent = this.closest("g.node");
|
|
90
|
-
select2(parent).classed("dragging", true).raise();
|
|
91
|
-
const [dx, dy] = pointer(event, this.parentElement);
|
|
92
|
-
const x = d.x + dx - offset[0];
|
|
93
|
-
const y = d.y + dy - offset[1];
|
|
94
|
-
const point = [
|
|
95
|
-
x,
|
|
96
|
-
y
|
|
97
|
-
];
|
|
98
|
-
switch (mode) {
|
|
99
|
-
case 0: {
|
|
100
|
-
select2(context.svg).attr("cursor", "grabbing");
|
|
101
|
-
event.subject.x = event.subject.fx = point[0];
|
|
102
|
-
event.subject.y = event.subject.fy = point[1];
|
|
103
|
-
projector.refresh(true);
|
|
104
|
-
moved = true;
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
case 1: {
|
|
108
|
-
if (options?.onDrag) {
|
|
109
|
-
target = projector.findNode(event.x, event.y, 16);
|
|
110
|
-
if (source === target) {
|
|
111
|
-
select2(context.svg).attr("cursor", void 0);
|
|
112
|
-
options?.onDrag?.();
|
|
113
|
-
} else {
|
|
114
|
-
select2(context.svg).attr("cursor", target ? "alias" : "cell");
|
|
115
|
-
options?.onDrag?.(source, target, point);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}).on("end", function(event) {
|
|
121
|
-
select2(context.svg).attr("cursor", void 0);
|
|
122
|
-
select2(this.parentElement).classed("dragging", false);
|
|
123
|
-
switch (mode) {
|
|
124
|
-
case 1: {
|
|
125
|
-
options?.onDrop?.(source, target);
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (!keyMod(event.sourceEvent, "freezeMod")) {
|
|
130
|
-
event.subject.fx = null;
|
|
131
|
-
event.subject.fy = null;
|
|
132
|
-
}
|
|
133
|
-
mode = void 0;
|
|
134
|
-
source = void 0;
|
|
135
|
-
target = void 0;
|
|
136
|
-
offset = void 0;
|
|
137
|
-
if (moved) {
|
|
138
|
-
projector.refresh(false);
|
|
139
|
-
moved = false;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
};
|
|
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";
|
|
143
71
|
|
|
144
72
|
// src/graph/types.ts
|
|
145
73
|
import { invariant } from "@dxos/invariant";
|
|
146
74
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/types.ts";
|
|
147
75
|
var defaultIdAccessor = (node) => {
|
|
148
|
-
invariant(node.id, void 0, {
|
|
149
|
-
F: __dxlog_file,
|
|
150
|
-
L: 18,
|
|
151
|
-
S: void 0,
|
|
152
|
-
A: [
|
|
153
|
-
"node.id",
|
|
154
|
-
""
|
|
155
|
-
]
|
|
156
|
-
});
|
|
76
|
+
invariant(node.id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 10, S: void 0, A: ["node.id", ""] });
|
|
157
77
|
return node.id;
|
|
158
78
|
};
|
|
159
79
|
var emptyGraph = {
|
|
@@ -292,15 +212,7 @@ var FractionUtil = class _FractionUtil {
|
|
|
292
212
|
* @param n
|
|
293
213
|
*/
|
|
294
214
|
static factors = (n) => {
|
|
295
|
-
invariant2(Number.isFinite(n), `Invalid number: ${n}`, {
|
|
296
|
-
F: __dxlog_file2,
|
|
297
|
-
L: 113,
|
|
298
|
-
S: this,
|
|
299
|
-
A: [
|
|
300
|
-
"Number.isFinite(n)",
|
|
301
|
-
"`Invalid number: ${n}`"
|
|
302
|
-
]
|
|
303
|
-
});
|
|
215
|
+
invariant2(Number.isFinite(n), `Invalid number: ${n}`, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 113, S: this, A: ["Number.isFinite(n)", "`Invalid number: ${n}`"] });
|
|
304
216
|
const factors = [
|
|
305
217
|
1
|
|
306
218
|
];
|
|
@@ -756,9 +668,10 @@ var Projector = class {
|
|
|
756
668
|
updateData(data) {
|
|
757
669
|
this.onUpdate(data);
|
|
758
670
|
}
|
|
759
|
-
emitUpdate() {
|
|
671
|
+
emitUpdate(kind = "topology") {
|
|
760
672
|
this.updated.emit({
|
|
761
|
-
layout: this.layout
|
|
673
|
+
layout: this.layout,
|
|
674
|
+
kind
|
|
762
675
|
});
|
|
763
676
|
}
|
|
764
677
|
async clear() {
|
|
@@ -828,10 +741,12 @@ var GraphProjector = class extends Projector {
|
|
|
828
741
|
};
|
|
829
742
|
}
|
|
830
743
|
current.data = node;
|
|
744
|
+
current.hidden = false;
|
|
831
745
|
return current;
|
|
832
746
|
});
|
|
833
747
|
const edges = data.edges.map((edge) => ({
|
|
834
748
|
id: edge.id,
|
|
749
|
+
type: edge.type,
|
|
835
750
|
source: nodes.find((n) => n.id === edge.source),
|
|
836
751
|
target: nodes.find((n) => n.id === edge.target),
|
|
837
752
|
data: edge.data
|
|
@@ -846,94 +761,24 @@ var GraphProjector = class extends Projector {
|
|
|
846
761
|
async onClear() {
|
|
847
762
|
this.reset();
|
|
848
763
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
const fx = x != null ? forceX(x).strength(strength) : void 0;
|
|
859
|
-
const fy = y != null ? forceY(y).strength(strength) : void 0;
|
|
860
|
-
const force = (alpha) => {
|
|
861
|
-
fx?.(alpha);
|
|
862
|
-
fy?.(alpha);
|
|
863
|
-
};
|
|
864
|
-
force.initialize = (nodes, random) => {
|
|
865
|
-
fx?.initialize(nodes, random);
|
|
866
|
-
fy?.initialize(nodes, random);
|
|
867
|
-
};
|
|
868
|
-
return force;
|
|
869
|
-
};
|
|
870
|
-
|
|
871
|
-
// src/graph/projector/graph-force-projector.ts
|
|
872
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
873
|
-
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
874
|
-
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
875
|
-
};
|
|
876
|
-
var maybeForce = (options, cb, defaultValue = void 0) => {
|
|
877
|
-
const value = typeof options === "boolean" ? options ? {} : void 0 : options ?? defaultValue;
|
|
878
|
-
if (value) {
|
|
879
|
-
return cb(value);
|
|
764
|
+
/**
|
|
765
|
+
* Optional projector-owned click intercept. The Graph component invokes this BEFORE
|
|
766
|
+
* forwarding to the consumer's `onSelect`, so projectors can implement built-in
|
|
767
|
+
* interactions (e.g. cluster collapse) without each consumer wiring them. Returning
|
|
768
|
+
* `true` indicates the click was handled — consumer's `onSelect` is suppressed.
|
|
769
|
+
* Default no-op returns `false` so consumer handlers still run.
|
|
770
|
+
*/
|
|
771
|
+
handleNodeClick(_node, _event) {
|
|
772
|
+
return false;
|
|
880
773
|
}
|
|
881
774
|
};
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
};
|
|
888
|
-
var GraphForceProjector = class extends GraphProjector {
|
|
889
|
-
// https://github.com/d3/d3-force
|
|
890
|
-
_simulation = forceSimulation();
|
|
891
|
-
_timeout;
|
|
892
|
-
get forces() {
|
|
893
|
-
return this.options.forces ?? defaultForceOptions;
|
|
894
|
-
}
|
|
895
|
-
get simulation() {
|
|
896
|
-
return this._simulation;
|
|
897
|
-
}
|
|
898
|
-
restart() {
|
|
899
|
-
this._simulation.alpha(1).restart();
|
|
900
|
-
}
|
|
775
|
+
|
|
776
|
+
// src/graph/projector/graph-radial-projector.ts
|
|
777
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
778
|
+
var GraphRadialProjector = class extends GraphProjector {
|
|
779
|
+
_timer;
|
|
901
780
|
findNode(x, y, radius) {
|
|
902
|
-
return
|
|
903
|
-
}
|
|
904
|
-
async onStart() {
|
|
905
|
-
clearTimeout(this._timeout);
|
|
906
|
-
let propagating = true;
|
|
907
|
-
const { radial, ...forces } = this.forces;
|
|
908
|
-
const delay = typeof radial === "object" ? radial.delay : void 0;
|
|
909
|
-
if (delay) {
|
|
910
|
-
propagating = false;
|
|
911
|
-
this.updateForces(forces);
|
|
912
|
-
this._timeout = setTimeout(() => {
|
|
913
|
-
this.updateForces(this.forces);
|
|
914
|
-
this.restart();
|
|
915
|
-
this._timeout = setTimeout(() => {
|
|
916
|
-
propagating = true;
|
|
917
|
-
}, delay);
|
|
918
|
-
}, delay);
|
|
919
|
-
} else {
|
|
920
|
-
this.updateForces(this.forces);
|
|
921
|
-
}
|
|
922
|
-
this._simulation.on("tick", () => propagating && this.emitUpdate()).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
|
|
923
|
-
}
|
|
924
|
-
async onStop() {
|
|
925
|
-
clearTimeout(this._timeout);
|
|
926
|
-
this._simulation.stop();
|
|
927
|
-
}
|
|
928
|
-
onRefresh(dragging = false) {
|
|
929
|
-
if (this.forces.center) {
|
|
930
|
-
if (dragging) {
|
|
931
|
-
this._simulation.force("center", null);
|
|
932
|
-
} else {
|
|
933
|
-
this.updateForces(this.forces);
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
this.restart();
|
|
781
|
+
return void 0;
|
|
937
782
|
}
|
|
938
783
|
onUpdate(graph) {
|
|
939
784
|
log("onUpdate", {
|
|
@@ -941,68 +786,748 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
941
786
|
nodes: graph?.nodes.length,
|
|
942
787
|
edges: graph?.edges.length
|
|
943
788
|
}
|
|
944
|
-
}, {
|
|
945
|
-
F: __dxlog_file3,
|
|
946
|
-
L: 226,
|
|
947
|
-
S: this,
|
|
948
|
-
C: (f, a) => f(...a)
|
|
949
|
-
});
|
|
950
|
-
this._simulation.stop();
|
|
789
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 13, S: this });
|
|
951
790
|
this.mergeData(graph);
|
|
952
|
-
this.
|
|
953
|
-
this.
|
|
954
|
-
this.restart();
|
|
791
|
+
this.emitUpdate("topology");
|
|
792
|
+
this.doRadialLayout();
|
|
955
793
|
}
|
|
956
|
-
|
|
957
|
-
this.
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
] : void 0;
|
|
969
|
-
this.layout.graph.nodes.forEach((node) => {
|
|
970
|
-
if (!node.initialized) {
|
|
971
|
-
const a = 2 * Math.PI * Math.random();
|
|
972
|
-
const r = this.options.radius ?? 200;
|
|
973
|
-
Object.assign(node, {
|
|
974
|
-
initialized: true,
|
|
975
|
-
// TODO(burdon): Only when new nodes added to initial layout.
|
|
976
|
-
// Position around center or parent; must have delta to avoid spike.
|
|
977
|
-
// x: edge?.source?.x ?? Math.cos(a) * r,
|
|
978
|
-
// y: edge?.source?.y ?? Math.sin(a) * r,
|
|
979
|
-
x: Math.cos(a) * r,
|
|
980
|
-
y: Math.sin(a) * r
|
|
794
|
+
animate() {
|
|
795
|
+
this._timer?.stop();
|
|
796
|
+
this._timer = void 0;
|
|
797
|
+
const start = Date.now();
|
|
798
|
+
if (this.options.duration) {
|
|
799
|
+
this._timer = timer(() => {
|
|
800
|
+
const t = Math.min(1, (Date.now() - start) / this.options.duration);
|
|
801
|
+
const d = easeCubic(t);
|
|
802
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
803
|
+
node.x = node.sx + (node.tx - node.sx) * d;
|
|
804
|
+
node.y = node.sy + (node.ty - node.sy) * d;
|
|
805
|
+
node.r = node.sr + (node.tr - node.sr) * d;
|
|
981
806
|
});
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
807
|
+
this.onTickFrame(d);
|
|
808
|
+
this.emitUpdate("positions");
|
|
809
|
+
if (t >= 1) {
|
|
810
|
+
this._timer.stop();
|
|
811
|
+
this._timer = void 0;
|
|
812
|
+
}
|
|
985
813
|
});
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
814
|
+
} else {
|
|
815
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
816
|
+
node.x = node.tx;
|
|
817
|
+
node.y = node.ty;
|
|
818
|
+
node.r = node.tr;
|
|
990
819
|
});
|
|
991
|
-
|
|
820
|
+
this.onTickFrame(1);
|
|
821
|
+
this.emitUpdate("positions");
|
|
822
|
+
}
|
|
992
823
|
}
|
|
993
824
|
/**
|
|
994
|
-
*
|
|
825
|
+
* Per-frame hook called after node x/y/r are interpolated and before the
|
|
826
|
+
* 'positions' emit. Subclasses override to update edge geometry (`edge.path`)
|
|
827
|
+
* so curves stay glued to moving endpoints. `t` is the eased progress in [0, 1].
|
|
995
828
|
*/
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
829
|
+
onTickFrame(t) {
|
|
830
|
+
}
|
|
831
|
+
async onStop() {
|
|
832
|
+
this._timer?.stop();
|
|
833
|
+
this._timer = void 0;
|
|
834
|
+
}
|
|
835
|
+
doRadialLayout() {
|
|
836
|
+
if (!this.context.size) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const radial = layoutRadial(0, 0, this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80), this.layout.graph.nodes.length);
|
|
840
|
+
this.layout.graph.nodes.forEach((node, i) => {
|
|
841
|
+
const [tx, ty] = radial(i);
|
|
842
|
+
updateNode(node, [
|
|
843
|
+
tx,
|
|
844
|
+
ty
|
|
845
|
+
]);
|
|
1004
846
|
});
|
|
1005
|
-
this.
|
|
847
|
+
this.animate();
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
851
|
+
const sx = node.x ?? tx;
|
|
852
|
+
const sy = node.y ?? ty;
|
|
853
|
+
const sr = node.r ?? tr;
|
|
854
|
+
Object.assign(node, {
|
|
855
|
+
initialized: true,
|
|
856
|
+
// Start.
|
|
857
|
+
sx,
|
|
858
|
+
sy,
|
|
859
|
+
sr,
|
|
860
|
+
// Target.
|
|
861
|
+
tx,
|
|
862
|
+
ty,
|
|
863
|
+
tr,
|
|
864
|
+
// Current.
|
|
865
|
+
x: sx,
|
|
866
|
+
y: sy,
|
|
867
|
+
r: sr
|
|
868
|
+
});
|
|
869
|
+
};
|
|
870
|
+
var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
|
|
871
|
+
const da = 2 * Math.PI / n;
|
|
872
|
+
return (i) => {
|
|
873
|
+
const a = start + i * da;
|
|
874
|
+
return [
|
|
875
|
+
x + Math.cos(a) * r,
|
|
876
|
+
y + Math.sin(a) * r
|
|
877
|
+
];
|
|
878
|
+
};
|
|
879
|
+
};
|
|
880
|
+
var layoutHorizontal = (x, y, w, n) => {
|
|
881
|
+
const dx = n > 1 ? w / (n - 1) : 0;
|
|
882
|
+
const sx = x - (n - 1) * dx / 2;
|
|
883
|
+
return (i) => {
|
|
884
|
+
return [
|
|
885
|
+
sx + i * dx,
|
|
886
|
+
y
|
|
887
|
+
];
|
|
888
|
+
};
|
|
889
|
+
};
|
|
890
|
+
var layoutVertical = (x, y, h, n) => {
|
|
891
|
+
const dy = n > 1 ? h / (n - 1) : 0;
|
|
892
|
+
const sy = y - (n - 1) * dy / 2;
|
|
893
|
+
return (i) => {
|
|
894
|
+
return [
|
|
895
|
+
x,
|
|
896
|
+
sy + i * dy
|
|
897
|
+
];
|
|
898
|
+
};
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
// src/graph/projector/graph-bundle-projector.ts
|
|
902
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-bundle-projector.ts";
|
|
903
|
+
var ROOT_ID = "__bundle_root__";
|
|
904
|
+
var GROUP_PREFIX = "__bundle_group__:";
|
|
905
|
+
var cartesianToPolar = (x, y) => ({
|
|
906
|
+
angle: Math.atan2(x, -y),
|
|
907
|
+
radius: Math.hypot(x, y)
|
|
908
|
+
});
|
|
909
|
+
var GraphBundleProjector = class extends GraphRadialProjector {
|
|
910
|
+
// Per-edge polar point arrays. Points 0 and N-1 are the source / target leaves and are
|
|
911
|
+
// overwritten from current cartesian on every tick; intermediate points stay fixed at
|
|
912
|
+
// their cluster-layout polar coordinates.
|
|
913
|
+
#edgePoints = /* @__PURE__ */ new Map();
|
|
914
|
+
#lineGen = lineRadial().radius((d) => d.radius).angle((d) => d.angle);
|
|
915
|
+
onUpdate(graph) {
|
|
916
|
+
log2("onUpdate", {
|
|
917
|
+
graph: {
|
|
918
|
+
nodes: graph?.nodes.length,
|
|
919
|
+
edges: graph?.edges.length
|
|
920
|
+
}
|
|
921
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 40, S: this });
|
|
922
|
+
this.mergeData(graph);
|
|
923
|
+
this.doBundleLayout();
|
|
924
|
+
this.emitUpdate("topology");
|
|
925
|
+
this.animate();
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Refresh leaf endpoint polar values from current cartesian so the curve tracks
|
|
929
|
+
* its endpoints during the tween. Internal hierarchy positions stay constant.
|
|
930
|
+
*/
|
|
931
|
+
onTickFrame(_t) {
|
|
932
|
+
for (const edge of this.layout.graph.edges) {
|
|
933
|
+
if (edge.type !== "bundle") {
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
const points = this.#edgePoints.get(edge.id);
|
|
937
|
+
if (!points || points.length < 2) {
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
const s = cartesianToPolar(edge.source.x ?? 0, edge.source.y ?? 0);
|
|
941
|
+
const t = cartesianToPolar(edge.target.x ?? 0, edge.target.y ?? 0);
|
|
942
|
+
points[0] = {
|
|
943
|
+
angle: s.angle,
|
|
944
|
+
radius: s.radius
|
|
945
|
+
};
|
|
946
|
+
points[points.length - 1] = {
|
|
947
|
+
angle: t.angle,
|
|
948
|
+
radius: t.radius
|
|
949
|
+
};
|
|
950
|
+
edge.path = this.#lineGen(points) ?? void 0;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
doBundleLayout() {
|
|
954
|
+
if (!this.context.size) {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const dataNodes = [
|
|
958
|
+
...this.layout.graph.nodes
|
|
959
|
+
];
|
|
960
|
+
if (!dataNodes.length) {
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const groupOf = this.options.groupOf;
|
|
964
|
+
const items = [
|
|
965
|
+
{
|
|
966
|
+
id: ROOT_ID
|
|
967
|
+
}
|
|
968
|
+
];
|
|
969
|
+
const groupIds = /* @__PURE__ */ new Map();
|
|
970
|
+
for (const node of dataNodes) {
|
|
971
|
+
const key = groupOf?.(node);
|
|
972
|
+
let parent = ROOT_ID;
|
|
973
|
+
if (key !== void 0) {
|
|
974
|
+
let groupId = groupIds.get(key);
|
|
975
|
+
if (!groupId) {
|
|
976
|
+
groupId = `${GROUP_PREFIX}${key}`;
|
|
977
|
+
groupIds.set(key, groupId);
|
|
978
|
+
items.push({
|
|
979
|
+
id: groupId,
|
|
980
|
+
parent: ROOT_ID
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
parent = groupId;
|
|
984
|
+
}
|
|
985
|
+
items.push({
|
|
986
|
+
id: node.id,
|
|
987
|
+
parent,
|
|
988
|
+
node
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
992
|
+
for (const item of items) {
|
|
993
|
+
if (item.parent) {
|
|
994
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
995
|
+
list.push(item);
|
|
996
|
+
childrenByParent.set(item.parent, list);
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
const root = hierarchy({
|
|
1000
|
+
id: ROOT_ID
|
|
1001
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1002
|
+
const { width, height } = this.context.size;
|
|
1003
|
+
const margin = this.options.margin ?? 120;
|
|
1004
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1005
|
+
d3Cluster().size([
|
|
1006
|
+
2 * Math.PI,
|
|
1007
|
+
ringRadius
|
|
1008
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1009
|
+
const leafR = this.options.leafRadius ?? 4;
|
|
1010
|
+
const tension = this.options.tension ?? 0.85;
|
|
1011
|
+
this.#lineGen = lineRadial().curve(curveBundle.beta(tension)).radius((d) => d.radius).angle((d) => d.angle);
|
|
1012
|
+
const hierById = /* @__PURE__ */ new Map();
|
|
1013
|
+
root.each((d) => {
|
|
1014
|
+
hierById.set(d.data.id, d);
|
|
1015
|
+
});
|
|
1016
|
+
root.leaves().forEach((d) => {
|
|
1017
|
+
const angle = d.x;
|
|
1018
|
+
const radius = d.y;
|
|
1019
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1020
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1021
|
+
if (d.data.node) {
|
|
1022
|
+
updateNode(d.data.node, [
|
|
1023
|
+
x,
|
|
1024
|
+
y
|
|
1025
|
+
], leafR);
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
this.layout.graph.nodes = dataNodes;
|
|
1029
|
+
this.#edgePoints.clear();
|
|
1030
|
+
const incomingEdges = [
|
|
1031
|
+
...this.layout.graph.edges
|
|
1032
|
+
];
|
|
1033
|
+
const bundleEdges = [];
|
|
1034
|
+
for (const edge of incomingEdges) {
|
|
1035
|
+
const sourceHier = hierById.get(edge.source.id);
|
|
1036
|
+
const targetHier = hierById.get(edge.target.id);
|
|
1037
|
+
if (!sourceHier || !targetHier || sourceHier === targetHier) {
|
|
1038
|
+
continue;
|
|
1039
|
+
}
|
|
1040
|
+
const pathNodes = sourceHier.path(targetHier);
|
|
1041
|
+
const points = pathNodes.map((n) => ({
|
|
1042
|
+
angle: n.x,
|
|
1043
|
+
radius: n.y
|
|
1044
|
+
}));
|
|
1045
|
+
this.#edgePoints.set(edge.id, points);
|
|
1046
|
+
bundleEdges.push({
|
|
1047
|
+
id: edge.id,
|
|
1048
|
+
type: "bundle",
|
|
1049
|
+
source: edge.source,
|
|
1050
|
+
target: edge.target,
|
|
1051
|
+
data: edge.data
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
this.layout.graph.edges = bundleEdges;
|
|
1055
|
+
this.onTickFrame(0);
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
// src/graph/projector/graph-cluster-projector.ts
|
|
1060
|
+
import { cluster as d3Cluster2, hierarchy as hierarchy2, linkRadial } from "d3";
|
|
1061
|
+
import { log as log3 } from "@dxos/log";
|
|
1062
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-cluster-projector.ts";
|
|
1063
|
+
var ROOT_ID2 = "__cluster_root__";
|
|
1064
|
+
var GROUP_PREFIX2 = "__group__:";
|
|
1065
|
+
var HIER_EDGE_PREFIX = "__hier__:";
|
|
1066
|
+
var CLUSTER_NODE_TYPE_LEAF = "leaf";
|
|
1067
|
+
var CLUSTER_NODE_TYPE_GROUP = "group";
|
|
1068
|
+
var CLUSTER_NODE_TYPE_ROOT = "root";
|
|
1069
|
+
var linkPath = linkRadial().angle((d) => d.x).radius((d) => d.y);
|
|
1070
|
+
var cartesianToPolar2 = (x, y) => ({
|
|
1071
|
+
angle: Math.atan2(x, -y),
|
|
1072
|
+
radius: Math.hypot(x, y)
|
|
1073
|
+
});
|
|
1074
|
+
var GraphClusterProjector = class extends GraphRadialProjector {
|
|
1075
|
+
// Synthetic-node ids (root id, or `${GROUP_PREFIX}${key}`) whose subtree is currently
|
|
1076
|
+
// hidden. Clicking the corresponding rendered circle calls toggleCollapsed to flip
|
|
1077
|
+
// membership, then re-runs the layout so the renderer's exit transition fades the
|
|
1078
|
+
// hidden leaves + hierarchy edges out (and back in on expand).
|
|
1079
|
+
#collapsed = /* @__PURE__ */ new Set();
|
|
1080
|
+
// Snapshot of the full data-node set as of the last mergeData. doClusterLayout always
|
|
1081
|
+
// reads from this rather than `layout.graph.nodes` — the layout view is filtered (it
|
|
1082
|
+
// drops hidden leaves so the renderer doesn't see them), so re-reading from there
|
|
1083
|
+
// would permanently lose the hidden leaves and they couldn't reappear on expand.
|
|
1084
|
+
#dataNodes = [];
|
|
1085
|
+
/**
|
|
1086
|
+
* Built-in click semantics: clicking a synthetic root / group node toggles its subtree.
|
|
1087
|
+
* Leaf clicks fall through to the consumer's `onSelect` (returns `false`).
|
|
1088
|
+
*/
|
|
1089
|
+
handleNodeClick(node, _event) {
|
|
1090
|
+
if (node.type !== CLUSTER_NODE_TYPE_ROOT && node.type !== CLUSTER_NODE_TYPE_GROUP) {
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
this.toggleCollapsed(node.id);
|
|
1094
|
+
return true;
|
|
1095
|
+
}
|
|
1096
|
+
/** Toggle collapse state for a synthetic node id. Triggers a topology re-emit. */
|
|
1097
|
+
toggleCollapsed(id) {
|
|
1098
|
+
if (this.#collapsed.has(id)) {
|
|
1099
|
+
this.#collapsed.delete(id);
|
|
1100
|
+
} else {
|
|
1101
|
+
this.#collapsed.add(id);
|
|
1102
|
+
}
|
|
1103
|
+
this.doClusterLayout();
|
|
1104
|
+
this.emitUpdate("topology");
|
|
1105
|
+
this.animate();
|
|
1106
|
+
}
|
|
1107
|
+
/** Whether a synthetic-node id is currently collapsed. */
|
|
1108
|
+
isCollapsed(id) {
|
|
1109
|
+
return this.#collapsed.has(id);
|
|
1110
|
+
}
|
|
1111
|
+
onUpdate(graph) {
|
|
1112
|
+
log3("onUpdate", {
|
|
1113
|
+
graph: {
|
|
1114
|
+
nodes: graph?.nodes.length,
|
|
1115
|
+
edges: graph?.edges.length
|
|
1116
|
+
}
|
|
1117
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 79, S: this });
|
|
1118
|
+
this.mergeData(graph);
|
|
1119
|
+
this.#dataNodes = [
|
|
1120
|
+
...this.layout.graph.nodes
|
|
1121
|
+
];
|
|
1122
|
+
this.doClusterLayout();
|
|
1123
|
+
this.emitUpdate("topology");
|
|
1124
|
+
this.animate();
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Recompute each hierarchy edge's `path` from current cartesian source/target positions,
|
|
1128
|
+
* so the curves track moving endpoints during a cross-variant tween (e.g. force → cluster)
|
|
1129
|
+
* instead of being pinned to the final polar layout.
|
|
1130
|
+
*/
|
|
1131
|
+
onTickFrame(_t) {
|
|
1132
|
+
for (const edge of this.layout.graph.edges) {
|
|
1133
|
+
if (edge.type !== "hierarchy") {
|
|
1134
|
+
continue;
|
|
1135
|
+
}
|
|
1136
|
+
const { source, target } = edge;
|
|
1137
|
+
const s = cartesianToPolar2(source.x ?? 0, source.y ?? 0);
|
|
1138
|
+
const t = cartesianToPolar2(target.x ?? 0, target.y ?? 0);
|
|
1139
|
+
edge.path = linkPath({
|
|
1140
|
+
source: {
|
|
1141
|
+
x: s.angle,
|
|
1142
|
+
y: s.radius
|
|
1143
|
+
},
|
|
1144
|
+
target: {
|
|
1145
|
+
x: t.angle,
|
|
1146
|
+
y: t.radius
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
doClusterLayout() {
|
|
1152
|
+
if (!this.context.size) {
|
|
1153
|
+
return;
|
|
1154
|
+
}
|
|
1155
|
+
const dataNodes = this.#dataNodes;
|
|
1156
|
+
if (!dataNodes.length) {
|
|
1157
|
+
return;
|
|
1158
|
+
}
|
|
1159
|
+
const groupOf = this.options.groupOf;
|
|
1160
|
+
const rootId = this.options.rootId ?? ROOT_ID2;
|
|
1161
|
+
const items = [
|
|
1162
|
+
{
|
|
1163
|
+
id: rootId
|
|
1164
|
+
}
|
|
1165
|
+
];
|
|
1166
|
+
const groupIds = /* @__PURE__ */ new Map();
|
|
1167
|
+
const rootCollapsed = this.#collapsed.has(rootId);
|
|
1168
|
+
if (!rootCollapsed) {
|
|
1169
|
+
for (const node of dataNodes) {
|
|
1170
|
+
const key = groupOf?.(node);
|
|
1171
|
+
let parent = rootId;
|
|
1172
|
+
if (key !== void 0) {
|
|
1173
|
+
let groupId = groupIds.get(key);
|
|
1174
|
+
if (!groupId) {
|
|
1175
|
+
groupId = `${GROUP_PREFIX2}${key}`;
|
|
1176
|
+
groupIds.set(key, groupId);
|
|
1177
|
+
items.push({
|
|
1178
|
+
id: groupId,
|
|
1179
|
+
parent: rootId,
|
|
1180
|
+
groupKey: key
|
|
1181
|
+
});
|
|
1182
|
+
}
|
|
1183
|
+
parent = groupId;
|
|
1184
|
+
}
|
|
1185
|
+
if (this.#collapsed.has(parent)) {
|
|
1186
|
+
continue;
|
|
1187
|
+
}
|
|
1188
|
+
items.push({
|
|
1189
|
+
id: node.id,
|
|
1190
|
+
parent,
|
|
1191
|
+
node
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
1196
|
+
for (const item of items) {
|
|
1197
|
+
if (item.parent) {
|
|
1198
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
1199
|
+
list.push(item);
|
|
1200
|
+
childrenByParent.set(item.parent, list);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
const root = hierarchy2({
|
|
1204
|
+
id: rootId
|
|
1205
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1206
|
+
const { width, height } = this.context.size;
|
|
1207
|
+
const margin = this.options.margin ?? 80;
|
|
1208
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1209
|
+
d3Cluster2().size([
|
|
1210
|
+
2 * Math.PI,
|
|
1211
|
+
ringRadius
|
|
1212
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1213
|
+
const leafR = this.options.leafRadius ?? 4;
|
|
1214
|
+
const groupR = this.options.groupRadius ?? 3;
|
|
1215
|
+
const rootR = this.options.rootRadius ?? 5;
|
|
1216
|
+
const prevStubsById = /* @__PURE__ */ new Map();
|
|
1217
|
+
for (const node of this.layout.graph.nodes) {
|
|
1218
|
+
if (node.type === CLUSTER_NODE_TYPE_ROOT || node.type === CLUSTER_NODE_TYPE_GROUP) {
|
|
1219
|
+
prevStubsById.set(node.id, node);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
const syntheticNodes = /* @__PURE__ */ new Map();
|
|
1223
|
+
root.each((d) => {
|
|
1224
|
+
const id = d.data.id;
|
|
1225
|
+
const angle = d.x;
|
|
1226
|
+
const radius = d.y;
|
|
1227
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1228
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1229
|
+
if (d.data.node) {
|
|
1230
|
+
updateNode(d.data.node, [
|
|
1231
|
+
x,
|
|
1232
|
+
y
|
|
1233
|
+
], leafR);
|
|
1234
|
+
d.data.node.type = CLUSTER_NODE_TYPE_LEAF;
|
|
1235
|
+
d.data.node.hidden = false;
|
|
1236
|
+
} else {
|
|
1237
|
+
const isRoot = id === rootId;
|
|
1238
|
+
const stub = prevStubsById.get(id) ?? {
|
|
1239
|
+
id,
|
|
1240
|
+
x: 0,
|
|
1241
|
+
y: 0
|
|
1242
|
+
};
|
|
1243
|
+
updateNode(stub, [
|
|
1244
|
+
x,
|
|
1245
|
+
y
|
|
1246
|
+
], isRoot ? rootR : groupR);
|
|
1247
|
+
stub.type = isRoot ? CLUSTER_NODE_TYPE_ROOT : CLUSTER_NODE_TYPE_GROUP;
|
|
1248
|
+
if (isRoot) {
|
|
1249
|
+
stub.label = this.options.rootLabel;
|
|
1250
|
+
} else if (d.data.groupKey !== void 0) {
|
|
1251
|
+
stub.label = this.options.groupLabel ? this.options.groupLabel(d.data.groupKey) : d.data.groupKey;
|
|
1252
|
+
}
|
|
1253
|
+
syntheticNodes.set(id, stub);
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
const visibleLeafIds = /* @__PURE__ */ new Set();
|
|
1257
|
+
for (const item of items) {
|
|
1258
|
+
if (item.node) {
|
|
1259
|
+
visibleLeafIds.add(item.id);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
for (const node of dataNodes) {
|
|
1263
|
+
if (visibleLeafIds.has(node.id)) {
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
const key = groupOf?.(node);
|
|
1267
|
+
const parentId = key !== void 0 && groupIds.has(key) ? groupIds.get(key) : rootId;
|
|
1268
|
+
const parentStub = syntheticNodes.get(parentId);
|
|
1269
|
+
const targetX = parentStub?.tx ?? 0;
|
|
1270
|
+
const targetY = parentStub?.ty ?? 0;
|
|
1271
|
+
updateNode(node, [
|
|
1272
|
+
targetX,
|
|
1273
|
+
targetY
|
|
1274
|
+
], leafR);
|
|
1275
|
+
node.type = CLUSTER_NODE_TYPE_LEAF;
|
|
1276
|
+
node.hidden = true;
|
|
1277
|
+
}
|
|
1278
|
+
const nextNodes = [];
|
|
1279
|
+
for (const stub of syntheticNodes.values()) {
|
|
1280
|
+
nextNodes.push(stub);
|
|
1281
|
+
}
|
|
1282
|
+
for (const node of dataNodes) {
|
|
1283
|
+
nextNodes.push(node);
|
|
1284
|
+
}
|
|
1285
|
+
this.layout.graph.nodes = nextNodes;
|
|
1286
|
+
const hierarchyEdges = [];
|
|
1287
|
+
root.links().forEach((link) => {
|
|
1288
|
+
const sid = link.source.data.id;
|
|
1289
|
+
const tid = link.target.data.id;
|
|
1290
|
+
const sourceNode = link.source.data.node ?? syntheticNodes.get(sid);
|
|
1291
|
+
const targetNode = link.target.data.node ?? syntheticNodes.get(tid);
|
|
1292
|
+
hierarchyEdges.push({
|
|
1293
|
+
id: `${HIER_EDGE_PREFIX}${sid}->${tid}`,
|
|
1294
|
+
type: "hierarchy",
|
|
1295
|
+
source: sourceNode,
|
|
1296
|
+
target: targetNode,
|
|
1297
|
+
data: void 0
|
|
1298
|
+
});
|
|
1299
|
+
});
|
|
1300
|
+
this.layout.graph.edges = hierarchyEdges;
|
|
1301
|
+
this.onTickFrame(0);
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
// src/graph/projector/graph-drag.ts
|
|
1306
|
+
import { drag, pointer, select as select2 } from "d3";
|
|
1307
|
+
var defaultDragOptions = {
|
|
1308
|
+
linkMod: "metaKey",
|
|
1309
|
+
freezeMod: "shiftKey"
|
|
1310
|
+
};
|
|
1311
|
+
var createGraphDrag = (context, projector, options = defaultDragOptions) => {
|
|
1312
|
+
let mode;
|
|
1313
|
+
let source;
|
|
1314
|
+
let target;
|
|
1315
|
+
let offset;
|
|
1316
|
+
let moved = false;
|
|
1317
|
+
const keyMod = (event, key) => {
|
|
1318
|
+
const modKey = options?.[key] ?? defaultDragOptions[key];
|
|
1319
|
+
return modKey === void 0 || event[modKey];
|
|
1320
|
+
};
|
|
1321
|
+
return drag().filter((event) => !event.ctrlKey).on("start", function(event, d) {
|
|
1322
|
+
source = d;
|
|
1323
|
+
offset = pointer(event, this.parentElement);
|
|
1324
|
+
if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) {
|
|
1325
|
+
mode = 1;
|
|
1326
|
+
} else if (keyMod(event.sourceEvent, "dragMod")) {
|
|
1327
|
+
mode = 0;
|
|
1328
|
+
}
|
|
1329
|
+
}).on("drag", function(event, d) {
|
|
1330
|
+
const parent = this.closest("g.node");
|
|
1331
|
+
select2(parent).classed("dragging", true).raise();
|
|
1332
|
+
const [dx, dy] = pointer(event, this.parentElement);
|
|
1333
|
+
const x = d.x + dx - offset[0];
|
|
1334
|
+
const y = d.y + dy - offset[1];
|
|
1335
|
+
const point = [
|
|
1336
|
+
x,
|
|
1337
|
+
y
|
|
1338
|
+
];
|
|
1339
|
+
switch (mode) {
|
|
1340
|
+
case 0: {
|
|
1341
|
+
select2(context.svg).attr("cursor", "grabbing");
|
|
1342
|
+
event.subject.x = event.subject.fx = point[0];
|
|
1343
|
+
event.subject.y = event.subject.fy = point[1];
|
|
1344
|
+
projector.refresh(true);
|
|
1345
|
+
moved = true;
|
|
1346
|
+
break;
|
|
1347
|
+
}
|
|
1348
|
+
case 1: {
|
|
1349
|
+
if (options?.onDrag) {
|
|
1350
|
+
target = projector.findNode(event.x, event.y, 16);
|
|
1351
|
+
if (source === target) {
|
|
1352
|
+
select2(context.svg).attr("cursor", void 0);
|
|
1353
|
+
options?.onDrag?.();
|
|
1354
|
+
} else {
|
|
1355
|
+
select2(context.svg).attr("cursor", target ? "alias" : "cell");
|
|
1356
|
+
options?.onDrag?.(source, target, point);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
}).on("end", function(event) {
|
|
1362
|
+
select2(context.svg).attr("cursor", void 0);
|
|
1363
|
+
select2(this.parentElement).classed("dragging", false);
|
|
1364
|
+
switch (mode) {
|
|
1365
|
+
case 1: {
|
|
1366
|
+
options?.onDrop?.(source, target);
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
if (!keyMod(event.sourceEvent, "freezeMod")) {
|
|
1371
|
+
event.subject.fx = null;
|
|
1372
|
+
event.subject.fy = null;
|
|
1373
|
+
}
|
|
1374
|
+
mode = void 0;
|
|
1375
|
+
source = void 0;
|
|
1376
|
+
target = void 0;
|
|
1377
|
+
offset = void 0;
|
|
1378
|
+
if (moved) {
|
|
1379
|
+
projector.refresh(false);
|
|
1380
|
+
moved = false;
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
// src/graph/projector/graph-force-projector.ts
|
|
1386
|
+
import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
|
|
1387
|
+
import { log as log4 } from "@dxos/log";
|
|
1388
|
+
|
|
1389
|
+
// src/graph/projector/graph-forces.ts
|
|
1390
|
+
import { forceX, forceY } from "d3";
|
|
1391
|
+
var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
1392
|
+
const fx = x != null ? forceX(x).strength(strength) : void 0;
|
|
1393
|
+
const fy = y != null ? forceY(y).strength(strength) : void 0;
|
|
1394
|
+
const force = (alpha) => {
|
|
1395
|
+
fx?.(alpha);
|
|
1396
|
+
fy?.(alpha);
|
|
1397
|
+
};
|
|
1398
|
+
force.initialize = (nodes, random) => {
|
|
1399
|
+
fx?.initialize(nodes, random);
|
|
1400
|
+
fy?.initialize(nodes, random);
|
|
1401
|
+
};
|
|
1402
|
+
return force;
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
// src/graph/projector/graph-force-projector.ts
|
|
1406
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
1407
|
+
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
1408
|
+
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
1409
|
+
};
|
|
1410
|
+
var maybeForce = (options, cb, defaultValue = void 0) => {
|
|
1411
|
+
const value = typeof options === "boolean" ? options ? {} : void 0 : options ?? defaultValue;
|
|
1412
|
+
if (value) {
|
|
1413
|
+
return cb(value);
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
var defaultForceOptions = {
|
|
1417
|
+
link: true,
|
|
1418
|
+
manyBody: true,
|
|
1419
|
+
// center: true,
|
|
1420
|
+
point: true
|
|
1421
|
+
};
|
|
1422
|
+
var GraphForceProjector = class extends GraphProjector {
|
|
1423
|
+
// https://github.com/d3/d3-force
|
|
1424
|
+
_simulation = forceSimulation();
|
|
1425
|
+
_timeout;
|
|
1426
|
+
get forces() {
|
|
1427
|
+
return this.options.forces ?? defaultForceOptions;
|
|
1428
|
+
}
|
|
1429
|
+
get simulation() {
|
|
1430
|
+
return this._simulation;
|
|
1431
|
+
}
|
|
1432
|
+
restart() {
|
|
1433
|
+
this._simulation.alpha(1).restart();
|
|
1434
|
+
}
|
|
1435
|
+
findNode(x, y, radius) {
|
|
1436
|
+
return this._simulation.find(x, y, radius);
|
|
1437
|
+
}
|
|
1438
|
+
async onStart() {
|
|
1439
|
+
clearTimeout(this._timeout);
|
|
1440
|
+
let propagating = true;
|
|
1441
|
+
const { radial, ...forces } = this.forces;
|
|
1442
|
+
const delay = typeof radial === "object" ? radial.delay : void 0;
|
|
1443
|
+
if (delay) {
|
|
1444
|
+
propagating = false;
|
|
1445
|
+
this.updateForces(forces);
|
|
1446
|
+
this._timeout = setTimeout(() => {
|
|
1447
|
+
this.updateForces(this.forces);
|
|
1448
|
+
this.restart();
|
|
1449
|
+
this._timeout = setTimeout(() => {
|
|
1450
|
+
propagating = true;
|
|
1451
|
+
}, delay);
|
|
1452
|
+
}, delay);
|
|
1453
|
+
} else {
|
|
1454
|
+
this.updateForces(this.forces);
|
|
1455
|
+
}
|
|
1456
|
+
this._simulation.on("tick", () => propagating && this.emitUpdate("positions")).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
|
|
1457
|
+
}
|
|
1458
|
+
async onStop() {
|
|
1459
|
+
clearTimeout(this._timeout);
|
|
1460
|
+
this._simulation.stop();
|
|
1461
|
+
}
|
|
1462
|
+
onRefresh(dragging = false) {
|
|
1463
|
+
if (this.forces.center) {
|
|
1464
|
+
if (dragging) {
|
|
1465
|
+
this._simulation.force("center", null);
|
|
1466
|
+
} else {
|
|
1467
|
+
this.updateForces(this.forces);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
this.restart();
|
|
1471
|
+
}
|
|
1472
|
+
onUpdate(graph) {
|
|
1473
|
+
log4("onUpdate", {
|
|
1474
|
+
graph: {
|
|
1475
|
+
nodes: graph?.nodes.length,
|
|
1476
|
+
edges: graph?.edges.length
|
|
1477
|
+
}
|
|
1478
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 91, S: this });
|
|
1479
|
+
this._simulation.stop();
|
|
1480
|
+
this.mergeData(graph);
|
|
1481
|
+
this.updateLayout();
|
|
1482
|
+
this.updateForces(this.forces);
|
|
1483
|
+
this.emitUpdate("topology");
|
|
1484
|
+
this.restart();
|
|
1485
|
+
}
|
|
1486
|
+
updateLayout() {
|
|
1487
|
+
this.layout.guides = this.options.guides ? [
|
|
1488
|
+
{
|
|
1489
|
+
id: "g-1",
|
|
1490
|
+
type: "circle",
|
|
1491
|
+
cx: 0,
|
|
1492
|
+
cy: 0,
|
|
1493
|
+
r: this.context.scale.model.toValue([
|
|
1494
|
+
10,
|
|
1495
|
+
1
|
|
1496
|
+
])
|
|
1497
|
+
}
|
|
1498
|
+
] : void 0;
|
|
1499
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
1500
|
+
if (!node.initialized) {
|
|
1501
|
+
const a = 2 * Math.PI * Math.random();
|
|
1502
|
+
const r = this.options.radius ?? 200;
|
|
1503
|
+
Object.assign(node, {
|
|
1504
|
+
initialized: true,
|
|
1505
|
+
// TODO(burdon): Only when new nodes added to initial layout.
|
|
1506
|
+
// Position around center or parent; must have delta to avoid spike.
|
|
1507
|
+
// x: edge?.source?.x ?? Math.cos(a) * r,
|
|
1508
|
+
// y: edge?.source?.y ?? Math.sin(a) * r,
|
|
1509
|
+
x: Math.cos(a) * r,
|
|
1510
|
+
y: Math.sin(a) * r
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
Object.assign(node, {
|
|
1514
|
+
r: getValue(this.options?.attributes?.radius, (fn) => fn(node, this.numChildren(node)), 6)
|
|
1515
|
+
});
|
|
1516
|
+
});
|
|
1517
|
+
this.layout.graph.edges.forEach((edge) => {
|
|
1518
|
+
Object.assign(edge, {
|
|
1519
|
+
linkForce: getValue(this.options.attributes?.linkForce, (fn) => fn(edge), true)
|
|
1520
|
+
});
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Update all forces.
|
|
1525
|
+
*/
|
|
1526
|
+
updateForces(forces) {
|
|
1527
|
+
log4("updateForces", {
|
|
1528
|
+
forces
|
|
1529
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 153, S: this });
|
|
1530
|
+
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
1006
1531
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
1007
1532
|
if (config.distance != null) {
|
|
1008
1533
|
force.distance(config.distance);
|
|
@@ -1065,203 +1590,364 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
1065
1590
|
};
|
|
1066
1591
|
|
|
1067
1592
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
1068
|
-
import { log as
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
import { easeCubic, timer } from "d3";
|
|
1072
|
-
import { log as log2 } from "@dxos/log";
|
|
1073
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
1074
|
-
var GraphRadialProjector = class extends GraphProjector {
|
|
1075
|
-
_timer;
|
|
1076
|
-
findNode(x, y, radius) {
|
|
1077
|
-
return void 0;
|
|
1078
|
-
}
|
|
1593
|
+
import { log as log5 } from "@dxos/log";
|
|
1594
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
1595
|
+
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
1079
1596
|
onUpdate(graph) {
|
|
1080
|
-
|
|
1597
|
+
log5("onUpdate", {
|
|
1081
1598
|
graph: {
|
|
1082
1599
|
nodes: graph?.nodes.length,
|
|
1083
1600
|
edges: graph?.edges.length
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
L: 31,
|
|
1088
|
-
S: this,
|
|
1089
|
-
C: (f, a) => f(...a)
|
|
1090
|
-
});
|
|
1601
|
+
},
|
|
1602
|
+
selection: this.selection?.getSelectedIds()
|
|
1603
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 8, S: this });
|
|
1091
1604
|
this.mergeData(graph);
|
|
1605
|
+
this.emitUpdate("topology");
|
|
1606
|
+
const selected = this.selection?.getSelectedIds()[0];
|
|
1607
|
+
if (selected) {
|
|
1608
|
+
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
1609
|
+
if (node) {
|
|
1610
|
+
this.doHierarchicalLayout(node);
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1092
1614
|
this.doRadialLayout();
|
|
1093
1615
|
}
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1616
|
+
doHierarchicalLayout(selected) {
|
|
1617
|
+
if (!this.context.size) {
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
const r2 = this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80);
|
|
1621
|
+
const r1 = r2 / 2;
|
|
1622
|
+
const children = this.layout.graph.edges.filter((edge) => edge.source.id === selected.id).map((edge) => edge.target);
|
|
1623
|
+
updateNode(selected, [
|
|
1624
|
+
0,
|
|
1625
|
+
0
|
|
1626
|
+
], 20);
|
|
1627
|
+
{
|
|
1628
|
+
const radial = layoutRadial(0, 0, r1, children.length);
|
|
1629
|
+
children.forEach((node, i) => {
|
|
1630
|
+
const [tx, ty] = radial(i);
|
|
1631
|
+
updateNode(node, [
|
|
1632
|
+
tx,
|
|
1633
|
+
ty
|
|
1634
|
+
]);
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
{
|
|
1638
|
+
const radial = layoutRadial(0, 0, r2, this.layout.graph.nodes.length - 1 - children.length);
|
|
1639
|
+
this.layout.graph.nodes.filter((node) => node.id !== selected.id && !children.includes(node)).forEach((node, i) => {
|
|
1640
|
+
const [tx, ty] = radial(i);
|
|
1641
|
+
updateNode(node, [
|
|
1642
|
+
tx,
|
|
1643
|
+
ty
|
|
1644
|
+
]);
|
|
1110
1645
|
});
|
|
1111
|
-
} else {
|
|
1112
|
-
this.emitUpdate();
|
|
1113
1646
|
}
|
|
1647
|
+
this.animate();
|
|
1114
1648
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1649
|
+
};
|
|
1650
|
+
|
|
1651
|
+
// src/graph/projector/graph-lattice-projector.ts
|
|
1652
|
+
import { log as log6 } from "@dxos/log";
|
|
1653
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-lattice-projector.ts";
|
|
1654
|
+
var GraphLatticeProjector = class extends GraphRadialProjector {
|
|
1655
|
+
onUpdate(graph) {
|
|
1656
|
+
log6("onUpdate", {
|
|
1657
|
+
graph: {
|
|
1658
|
+
nodes: graph?.nodes.length,
|
|
1659
|
+
edges: graph?.edges.length
|
|
1660
|
+
}
|
|
1661
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 14, S: this });
|
|
1662
|
+
this.mergeData(graph);
|
|
1663
|
+
this.doLatticeLayout();
|
|
1664
|
+
this.emitUpdate("topology");
|
|
1665
|
+
this.animate();
|
|
1118
1666
|
}
|
|
1119
|
-
|
|
1667
|
+
doLatticeLayout() {
|
|
1120
1668
|
if (!this.context.size) {
|
|
1121
1669
|
return;
|
|
1122
1670
|
}
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1125
|
-
|
|
1671
|
+
const nodes = this.layout.graph.nodes;
|
|
1672
|
+
const count = nodes.length;
|
|
1673
|
+
if (!count) {
|
|
1674
|
+
return;
|
|
1675
|
+
}
|
|
1676
|
+
const sortBy = this.options.sortBy ?? ((n) => n.data?.label ?? n.id);
|
|
1677
|
+
nodes.sort((a, b) => sortBy(a).localeCompare(sortBy(b)));
|
|
1678
|
+
const columns = Math.max(1, Math.ceil(Math.sqrt(count)));
|
|
1679
|
+
const rows = Math.ceil(count / columns);
|
|
1680
|
+
const margin = this.options.margin ?? 16;
|
|
1681
|
+
const { width, height } = this.context.size;
|
|
1682
|
+
const innerW = Math.max(0, width - 2 * margin);
|
|
1683
|
+
const innerH = Math.max(0, height - 2 * margin);
|
|
1684
|
+
const r = this.options.radius ?? 6;
|
|
1685
|
+
const fit = Math.min(innerW / columns, innerH / rows);
|
|
1686
|
+
const cellSize = Math.max(0, Math.min(fit, r * 6));
|
|
1687
|
+
const gridW = cellSize * columns;
|
|
1688
|
+
const gridH = cellSize * rows;
|
|
1689
|
+
const offsetX = -gridW / 2 + cellSize / 2;
|
|
1690
|
+
const offsetY = -gridH / 2 + cellSize / 2;
|
|
1691
|
+
nodes.forEach((node, i) => {
|
|
1692
|
+
const tx = offsetX + i % columns * cellSize;
|
|
1693
|
+
const ty = offsetY + Math.floor(i / columns) * cellSize;
|
|
1126
1694
|
updateNode(node, [
|
|
1127
1695
|
tx,
|
|
1128
1696
|
ty
|
|
1129
|
-
]);
|
|
1697
|
+
], r);
|
|
1130
1698
|
});
|
|
1131
|
-
this.animate();
|
|
1132
1699
|
}
|
|
1133
1700
|
};
|
|
1134
|
-
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
1135
|
-
const sx = node.x ?? tx;
|
|
1136
|
-
const sy = node.y ?? ty;
|
|
1137
|
-
const sr = node.r ?? tr;
|
|
1138
|
-
Object.assign(node, {
|
|
1139
|
-
initialized: true,
|
|
1140
|
-
// Start.
|
|
1141
|
-
sx,
|
|
1142
|
-
sy,
|
|
1143
|
-
sr,
|
|
1144
|
-
// Target.
|
|
1145
|
-
tx,
|
|
1146
|
-
ty,
|
|
1147
|
-
tr,
|
|
1148
|
-
// Current.
|
|
1149
|
-
x: sx,
|
|
1150
|
-
y: sy,
|
|
1151
|
-
r: sr
|
|
1152
|
-
});
|
|
1153
|
-
};
|
|
1154
|
-
var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
|
|
1155
|
-
const da = 2 * Math.PI / n;
|
|
1156
|
-
return (i) => {
|
|
1157
|
-
const a = start + i * da;
|
|
1158
|
-
return [
|
|
1159
|
-
x + Math.cos(a) * r,
|
|
1160
|
-
y + Math.sin(a) * r
|
|
1161
|
-
];
|
|
1162
|
-
};
|
|
1163
|
-
};
|
|
1164
|
-
var layoutHorizontal = (x, y, w, n) => {
|
|
1165
|
-
const dx = n > 1 ? w / (n - 1) : 0;
|
|
1166
|
-
const sx = x - (n - 1) * dx / 2;
|
|
1167
|
-
return (i) => {
|
|
1168
|
-
return [
|
|
1169
|
-
sx + i * dx,
|
|
1170
|
-
y
|
|
1171
|
-
];
|
|
1172
|
-
};
|
|
1173
|
-
};
|
|
1174
|
-
var layoutVertical = (x, y, h, n) => {
|
|
1175
|
-
const dy = n > 1 ? h / (n - 1) : 0;
|
|
1176
|
-
const sy = y - (n - 1) * dy / 2;
|
|
1177
|
-
return (i) => {
|
|
1178
|
-
return [
|
|
1179
|
-
x,
|
|
1180
|
-
sy + i * dy
|
|
1181
|
-
];
|
|
1182
|
-
};
|
|
1183
|
-
};
|
|
1184
1701
|
|
|
1185
|
-
// src/graph/projector/graph-
|
|
1186
|
-
|
|
1187
|
-
|
|
1702
|
+
// src/graph/projector/graph-plexus-projector.ts
|
|
1703
|
+
import { cluster as d3Cluster3, hierarchy as hierarchy3, linkRadial as linkRadial2 } from "d3";
|
|
1704
|
+
import { log as log7 } from "@dxos/log";
|
|
1705
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-plexus-projector.ts";
|
|
1706
|
+
var RELATION_PREFIX = "__plexus_relation__:";
|
|
1707
|
+
var HIER_EDGE_PREFIX2 = "__plexus_hier__:";
|
|
1708
|
+
var PLEXUS_NODE_TYPE_FOCUS = "plexus-focus";
|
|
1709
|
+
var PLEXUS_NODE_TYPE_RELATION = "plexus-relation";
|
|
1710
|
+
var PLEXUS_NODE_TYPE_OBJECT = "plexus-object";
|
|
1711
|
+
var linkPath2 = linkRadial2().angle((d) => d.x).radius((d) => d.y);
|
|
1712
|
+
var cartesianToPolar3 = (x, y) => ({
|
|
1713
|
+
angle: Math.atan2(x, -y),
|
|
1714
|
+
radius: Math.hypot(x, y)
|
|
1715
|
+
});
|
|
1716
|
+
var GraphPlexusProjector = class extends GraphRadialProjector {
|
|
1717
|
+
// Full node / edge snapshots taken right after mergeData — doPlexusLayout reads from
|
|
1718
|
+
// these because it overwrites layout.graph with the filtered focus-centric view.
|
|
1719
|
+
#dataNodes = [];
|
|
1720
|
+
#dataEdges = [];
|
|
1188
1721
|
onUpdate(graph) {
|
|
1189
|
-
|
|
1722
|
+
log7("onUpdate", {
|
|
1190
1723
|
graph: {
|
|
1191
1724
|
nodes: graph?.nodes.length,
|
|
1192
1725
|
edges: graph?.edges.length
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
}, {
|
|
1196
|
-
F: __dxlog_file5,
|
|
1197
|
-
L: 23,
|
|
1198
|
-
S: this,
|
|
1199
|
-
C: (f, a) => f(...a)
|
|
1200
|
-
});
|
|
1726
|
+
}
|
|
1727
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 48, S: this });
|
|
1201
1728
|
this.mergeData(graph);
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1729
|
+
this.#dataNodes = [
|
|
1730
|
+
...this.layout.graph.nodes
|
|
1731
|
+
];
|
|
1732
|
+
this.#dataEdges = [
|
|
1733
|
+
...this.layout.graph.edges
|
|
1734
|
+
];
|
|
1735
|
+
this.doPlexusLayout();
|
|
1736
|
+
this.emitUpdate("topology");
|
|
1737
|
+
this.animate();
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Recompute each hierarchy edge's `path` from current cartesian endpoints so curves track
|
|
1741
|
+
* moving nodes during the tween (identical strategy to the cluster projector).
|
|
1742
|
+
*/
|
|
1743
|
+
onTickFrame(_t) {
|
|
1744
|
+
for (const edge of this.layout.graph.edges) {
|
|
1745
|
+
if (edge.type !== "hierarchy") {
|
|
1746
|
+
continue;
|
|
1208
1747
|
}
|
|
1748
|
+
const { source, target } = edge;
|
|
1749
|
+
const s = cartesianToPolar3(source.x ?? 0, source.y ?? 0);
|
|
1750
|
+
const t = cartesianToPolar3(target.x ?? 0, target.y ?? 0);
|
|
1751
|
+
edge.path = linkPath2({
|
|
1752
|
+
source: {
|
|
1753
|
+
x: s.angle,
|
|
1754
|
+
y: s.radius
|
|
1755
|
+
},
|
|
1756
|
+
target: {
|
|
1757
|
+
x: t.angle,
|
|
1758
|
+
y: t.radius
|
|
1759
|
+
}
|
|
1760
|
+
});
|
|
1209
1761
|
}
|
|
1210
|
-
this.doRadialLayout();
|
|
1211
1762
|
}
|
|
1212
|
-
|
|
1763
|
+
doPlexusLayout() {
|
|
1213
1764
|
if (!this.context.size) {
|
|
1214
1765
|
return;
|
|
1215
1766
|
}
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
updateNode(selected, [
|
|
1220
|
-
0,
|
|
1221
|
-
0
|
|
1222
|
-
], 20);
|
|
1223
|
-
{
|
|
1224
|
-
const radial = layoutRadial(0, 0, r1, children.length);
|
|
1225
|
-
children.forEach((node, i) => {
|
|
1226
|
-
const [tx, ty] = radial(i);
|
|
1227
|
-
updateNode(node, [
|
|
1228
|
-
tx,
|
|
1229
|
-
ty
|
|
1230
|
-
]);
|
|
1231
|
-
});
|
|
1767
|
+
const dataNodes = this.#dataNodes;
|
|
1768
|
+
if (!dataNodes.length) {
|
|
1769
|
+
return;
|
|
1232
1770
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1771
|
+
const focusId = this.options.focus;
|
|
1772
|
+
const focusNode = focusId ? dataNodes.find((node) => node.id === focusId) : void 0;
|
|
1773
|
+
if (!focusNode) {
|
|
1774
|
+
const radial = layoutRadial(0, 0, Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 100), dataNodes.length);
|
|
1775
|
+
dataNodes.forEach((node, index) => updateNode(node, radial(index), this.options.leafRadius ?? 5));
|
|
1776
|
+
this.layout.graph.nodes = dataNodes;
|
|
1777
|
+
this.layout.graph.edges = [];
|
|
1778
|
+
this.animate();
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
const relationOf = this.options.relationOf ?? defaultRelationOf;
|
|
1782
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1783
|
+
const placed = /* @__PURE__ */ new Set([
|
|
1784
|
+
focusId
|
|
1785
|
+
]);
|
|
1786
|
+
for (const edge of this.#dataEdges) {
|
|
1787
|
+
const relation = relationOf(edge, focusId);
|
|
1788
|
+
if (!relation) {
|
|
1789
|
+
continue;
|
|
1790
|
+
}
|
|
1791
|
+
const neighbour = edge.source.id === focusId ? edge.target : edge.source;
|
|
1792
|
+
if (placed.has(neighbour.id)) {
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1795
|
+
placed.add(neighbour.id);
|
|
1796
|
+
let group = groups.get(relation.key);
|
|
1797
|
+
if (!group) {
|
|
1798
|
+
group = {
|
|
1799
|
+
id: `${RELATION_PREFIX}${relation.key}`,
|
|
1800
|
+
label: relation.label,
|
|
1801
|
+
leaves: []
|
|
1802
|
+
};
|
|
1803
|
+
groups.set(relation.key, group);
|
|
1804
|
+
}
|
|
1805
|
+
group.leaves.push(neighbour);
|
|
1806
|
+
}
|
|
1807
|
+
const items = [
|
|
1808
|
+
{
|
|
1809
|
+
id: focusId,
|
|
1810
|
+
node: focusNode
|
|
1811
|
+
}
|
|
1812
|
+
];
|
|
1813
|
+
for (const group of groups.values()) {
|
|
1814
|
+
items.push({
|
|
1815
|
+
id: group.id,
|
|
1816
|
+
parent: focusId,
|
|
1817
|
+
relationLabel: group.label
|
|
1241
1818
|
});
|
|
1819
|
+
for (const leaf of group.leaves) {
|
|
1820
|
+
items.push({
|
|
1821
|
+
id: leaf.id,
|
|
1822
|
+
parent: group.id,
|
|
1823
|
+
node: leaf
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1242
1826
|
}
|
|
1243
|
-
|
|
1827
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
1828
|
+
for (const item of items) {
|
|
1829
|
+
if (item.parent) {
|
|
1830
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
1831
|
+
list.push(item);
|
|
1832
|
+
childrenByParent.set(item.parent, list);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
const root = hierarchy3({
|
|
1836
|
+
id: focusId,
|
|
1837
|
+
node: focusNode
|
|
1838
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1839
|
+
const { width, height } = this.context.size;
|
|
1840
|
+
const margin = this.options.margin ?? 100;
|
|
1841
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1842
|
+
d3Cluster3().size([
|
|
1843
|
+
2 * Math.PI,
|
|
1844
|
+
ringRadius
|
|
1845
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1846
|
+
const leafR = this.options.leafRadius ?? 5;
|
|
1847
|
+
const relationR = this.options.relationRadius ?? leafR;
|
|
1848
|
+
const focusR = this.options.focusRadius ?? leafR * 2;
|
|
1849
|
+
const prevStubsById = /* @__PURE__ */ new Map();
|
|
1850
|
+
for (const node of this.layout.graph.nodes) {
|
|
1851
|
+
if (node.type === PLEXUS_NODE_TYPE_RELATION) {
|
|
1852
|
+
prevStubsById.set(node.id, node);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
const relationStubs = /* @__PURE__ */ new Map();
|
|
1856
|
+
root.each((d) => {
|
|
1857
|
+
const angle = d.x;
|
|
1858
|
+
const radius = d.y;
|
|
1859
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1860
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1861
|
+
const id = d.data.id;
|
|
1862
|
+
if (id === focusId) {
|
|
1863
|
+
updateNode(focusNode, [
|
|
1864
|
+
x,
|
|
1865
|
+
y
|
|
1866
|
+
], focusR);
|
|
1867
|
+
focusNode.type = PLEXUS_NODE_TYPE_FOCUS;
|
|
1868
|
+
focusNode.hidden = false;
|
|
1869
|
+
} else if (d.data.node) {
|
|
1870
|
+
updateNode(d.data.node, [
|
|
1871
|
+
x,
|
|
1872
|
+
y
|
|
1873
|
+
], leafR);
|
|
1874
|
+
d.data.node.type = PLEXUS_NODE_TYPE_OBJECT;
|
|
1875
|
+
d.data.node.hidden = false;
|
|
1876
|
+
} else {
|
|
1877
|
+
const stub = prevStubsById.get(id) ?? {
|
|
1878
|
+
id,
|
|
1879
|
+
x: 0,
|
|
1880
|
+
y: 0
|
|
1881
|
+
};
|
|
1882
|
+
updateNode(stub, [
|
|
1883
|
+
x,
|
|
1884
|
+
y
|
|
1885
|
+
], relationR);
|
|
1886
|
+
stub.type = PLEXUS_NODE_TYPE_RELATION;
|
|
1887
|
+
stub.label = d.data.relationLabel;
|
|
1888
|
+
relationStubs.set(id, stub);
|
|
1889
|
+
}
|
|
1890
|
+
});
|
|
1891
|
+
const nextNodes = [];
|
|
1892
|
+
for (const stub of relationStubs.values()) {
|
|
1893
|
+
nextNodes.push(stub);
|
|
1894
|
+
}
|
|
1895
|
+
for (const group of groups.values()) {
|
|
1896
|
+
for (const leaf of group.leaves) {
|
|
1897
|
+
nextNodes.push(leaf);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
nextNodes.push(focusNode);
|
|
1901
|
+
this.layout.graph.nodes = nextNodes;
|
|
1902
|
+
const edges = [];
|
|
1903
|
+
root.links().forEach((link) => {
|
|
1904
|
+
const sid = link.source.data.id;
|
|
1905
|
+
const tid = link.target.data.id;
|
|
1906
|
+
const sourceNode = sid === focusId ? focusNode : link.source.data.node ?? relationStubs.get(sid);
|
|
1907
|
+
const targetNode = link.target.data.node ?? relationStubs.get(tid);
|
|
1908
|
+
if (!sourceNode || !targetNode) {
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
edges.push({
|
|
1912
|
+
id: `${HIER_EDGE_PREFIX2}${sid}->${tid}`,
|
|
1913
|
+
type: "hierarchy",
|
|
1914
|
+
source: sourceNode,
|
|
1915
|
+
target: targetNode,
|
|
1916
|
+
data: void 0
|
|
1917
|
+
});
|
|
1918
|
+
});
|
|
1919
|
+
this.layout.graph.edges = edges;
|
|
1920
|
+
this.onTickFrame(0);
|
|
1244
1921
|
}
|
|
1245
1922
|
};
|
|
1923
|
+
var defaultRelationOf = (edge, focusId) => {
|
|
1924
|
+
const outgoing = edge.source.id === focusId;
|
|
1925
|
+
const incoming = edge.target.id === focusId;
|
|
1926
|
+
if (!outgoing && !incoming) {
|
|
1927
|
+
return void 0;
|
|
1928
|
+
}
|
|
1929
|
+
const type = edge.type ?? "edge";
|
|
1930
|
+
const arrow = outgoing ? "\u2192" : "\u2190";
|
|
1931
|
+
return {
|
|
1932
|
+
key: `${type}:${outgoing ? "out" : "in"}`,
|
|
1933
|
+
label: `${type} ${arrow}`
|
|
1934
|
+
};
|
|
1935
|
+
};
|
|
1246
1936
|
|
|
1247
1937
|
// src/graph/projector/graph-relational-projector.ts
|
|
1248
|
-
import { log as
|
|
1249
|
-
var
|
|
1938
|
+
import { log as log8 } from "@dxos/log";
|
|
1939
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
1250
1940
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
1251
1941
|
onUpdate(graph) {
|
|
1252
|
-
|
|
1942
|
+
log8("onUpdate", {
|
|
1253
1943
|
graph: {
|
|
1254
1944
|
nodes: graph?.nodes.length,
|
|
1255
1945
|
edges: graph?.edges.length
|
|
1256
1946
|
},
|
|
1257
1947
|
selection: this.selection?.getSelectedIds()
|
|
1258
|
-
}, {
|
|
1259
|
-
F: __dxlog_file6,
|
|
1260
|
-
L: 23,
|
|
1261
|
-
S: this,
|
|
1262
|
-
C: (f, a) => f(...a)
|
|
1263
|
-
});
|
|
1948
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 8, S: this });
|
|
1264
1949
|
this.mergeData(graph);
|
|
1950
|
+
this.emitUpdate("topology");
|
|
1265
1951
|
const selected = this.selection?.getSelectedIds()[0];
|
|
1266
1952
|
if (selected) {
|
|
1267
1953
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
@@ -1333,10 +2019,267 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
1333
2019
|
}
|
|
1334
2020
|
};
|
|
1335
2021
|
|
|
2022
|
+
// src/graph/projector/graph-swarm-projector.ts
|
|
2023
|
+
import { timer as timer2 } from "d3";
|
|
2024
|
+
import { log as log9 } from "@dxos/log";
|
|
2025
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-swarm-projector.ts";
|
|
2026
|
+
var SWARMMATE_RADIUS = 60;
|
|
2027
|
+
var SEPARATION_DISTANCE = 30;
|
|
2028
|
+
var DEFAULTS = {
|
|
2029
|
+
spawnRadius: 200,
|
|
2030
|
+
maxVelocity: 1.2,
|
|
2031
|
+
alignment: 3,
|
|
2032
|
+
cohesion: 3,
|
|
2033
|
+
separation: 3,
|
|
2034
|
+
cursorRepel: 120,
|
|
2035
|
+
avoidance: 3,
|
|
2036
|
+
trailLength: 30
|
|
2037
|
+
};
|
|
2038
|
+
var GraphSwarmProjector = class extends GraphProjector {
|
|
2039
|
+
#timer;
|
|
2040
|
+
/** Cursor in SVG model coordinates, or null when the pointer is outside the surface. */
|
|
2041
|
+
#cursor = null;
|
|
2042
|
+
findNode() {
|
|
2043
|
+
return void 0;
|
|
2044
|
+
}
|
|
2045
|
+
/**
|
|
2046
|
+
* Tell the projector where the pointer is, in SVG model coordinates (the same space
|
|
2047
|
+
* `node.x/y` live in — center origin, post-zoom). Pass `null` (or omit args) on
|
|
2048
|
+
* pointer-leave to disable cursor avoidance.
|
|
2049
|
+
*/
|
|
2050
|
+
setCursor(x, y) {
|
|
2051
|
+
if (x == null || y == null) {
|
|
2052
|
+
this.#cursor = null;
|
|
2053
|
+
} else {
|
|
2054
|
+
this.#cursor = {
|
|
2055
|
+
x,
|
|
2056
|
+
y
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
onUpdate(graph) {
|
|
2061
|
+
log9("onUpdate", {
|
|
2062
|
+
graph: {
|
|
2063
|
+
nodes: graph?.nodes.length,
|
|
2064
|
+
edges: graph?.edges.length
|
|
2065
|
+
}
|
|
2066
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 54, S: this });
|
|
2067
|
+
this.mergeData(graph);
|
|
2068
|
+
this.initializeNodes();
|
|
2069
|
+
this.emitUpdate("topology");
|
|
2070
|
+
}
|
|
2071
|
+
async onStart() {
|
|
2072
|
+
this.startTimer();
|
|
2073
|
+
}
|
|
2074
|
+
async onStop() {
|
|
2075
|
+
this.stopTimer();
|
|
2076
|
+
}
|
|
2077
|
+
onRefresh() {
|
|
2078
|
+
if (!this.#timer) {
|
|
2079
|
+
this.startTimer();
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
#opt(key) {
|
|
2083
|
+
return this.options[key] ?? DEFAULTS[key];
|
|
2084
|
+
}
|
|
2085
|
+
initializeNodes() {
|
|
2086
|
+
const spawnRadius = this.#opt("spawnRadius");
|
|
2087
|
+
const maxVelocity = this.#opt("maxVelocity");
|
|
2088
|
+
for (const node of this.layout.graph.nodes) {
|
|
2089
|
+
if (!node.initialized) {
|
|
2090
|
+
const theta = Math.random() * 2 * Math.PI;
|
|
2091
|
+
const r = Math.random() * spawnRadius;
|
|
2092
|
+
node.x = Math.cos(theta) * r;
|
|
2093
|
+
node.y = Math.sin(theta) * r;
|
|
2094
|
+
const phi = Math.random() * 2 * Math.PI;
|
|
2095
|
+
const speed = (0.3 + Math.random() * 0.7) * maxVelocity;
|
|
2096
|
+
node.vx = Math.cos(phi) * speed;
|
|
2097
|
+
node.vy = Math.sin(phi) * speed;
|
|
2098
|
+
node.ax = 0;
|
|
2099
|
+
node.ay = 0;
|
|
2100
|
+
node.initialized = true;
|
|
2101
|
+
} else {
|
|
2102
|
+
node.vx ??= 0;
|
|
2103
|
+
node.vy ??= 0;
|
|
2104
|
+
node.ax ??= 0;
|
|
2105
|
+
node.ay ??= 0;
|
|
2106
|
+
}
|
|
2107
|
+
node.r ??= 6;
|
|
2108
|
+
node.history = [
|
|
2109
|
+
{
|
|
2110
|
+
x: node.x ?? 0,
|
|
2111
|
+
y: node.y ?? 0
|
|
2112
|
+
}
|
|
2113
|
+
];
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
startTimer() {
|
|
2117
|
+
this.stopTimer();
|
|
2118
|
+
this.#timer = timer2(() => this.tick());
|
|
2119
|
+
}
|
|
2120
|
+
stopTimer() {
|
|
2121
|
+
this.#timer?.stop();
|
|
2122
|
+
this.#timer = void 0;
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* One simulation step. Modeled on `tick` in Swarm.tsx, but operating in the
|
|
2126
|
+
* SVG centered-origin coordinate space and writing to `node.x/y` directly so
|
|
2127
|
+
* the existing `GraphRenderer.applyPositions` reads them unchanged.
|
|
2128
|
+
*/
|
|
2129
|
+
tick() {
|
|
2130
|
+
const size = this.context.size;
|
|
2131
|
+
if (!size) {
|
|
2132
|
+
return;
|
|
2133
|
+
}
|
|
2134
|
+
const { width, height } = size;
|
|
2135
|
+
const halfW = width / 2;
|
|
2136
|
+
const halfH = height / 2;
|
|
2137
|
+
const nodes = this.layout.graph.nodes;
|
|
2138
|
+
const maxVelocity = this.#opt("maxVelocity");
|
|
2139
|
+
const alignmentW = this.#opt("alignment") / 100;
|
|
2140
|
+
const cohesionW = this.#opt("cohesion") / 100;
|
|
2141
|
+
const separationW = this.#opt("separation") / 100;
|
|
2142
|
+
const avoidanceW = this.#opt("avoidance") / 10;
|
|
2143
|
+
const cursorRepel = this.#opt("cursorRepel");
|
|
2144
|
+
const cursor = cursorRepel > 0 ? this.#cursor : null;
|
|
2145
|
+
for (const b1 of nodes) {
|
|
2146
|
+
let ax = 0;
|
|
2147
|
+
let ay = 0;
|
|
2148
|
+
let alignX = 0;
|
|
2149
|
+
let alignY = 0;
|
|
2150
|
+
let alignActive = false;
|
|
2151
|
+
let cohX = 0;
|
|
2152
|
+
let cohY = 0;
|
|
2153
|
+
let cohActive = false;
|
|
2154
|
+
let sepX = 0;
|
|
2155
|
+
let sepY = 0;
|
|
2156
|
+
let sepActive = false;
|
|
2157
|
+
let avoidX = 0;
|
|
2158
|
+
let avoidY = 0;
|
|
2159
|
+
let avoidActive = false;
|
|
2160
|
+
if (cursor) {
|
|
2161
|
+
const dx = cursor.x - (b1.x ?? 0);
|
|
2162
|
+
const dy = cursor.y - (b1.y ?? 0);
|
|
2163
|
+
const distSq = dx * dx + dy * dy;
|
|
2164
|
+
if (distSq > 0 && distSq < cursorRepel * cursorRepel) {
|
|
2165
|
+
const dist = Math.sqrt(distSq);
|
|
2166
|
+
avoidX = -dx / dist * (1 / dist);
|
|
2167
|
+
avoidY = -dy / dist * (1 / dist);
|
|
2168
|
+
avoidActive = true;
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
if (!avoidActive) {
|
|
2172
|
+
for (const b2 of nodes) {
|
|
2173
|
+
if (b1 === b2) {
|
|
2174
|
+
continue;
|
|
2175
|
+
}
|
|
2176
|
+
const dx = (b2.x ?? 0) - (b1.x ?? 0);
|
|
2177
|
+
const dy = (b2.y ?? 0) - (b1.y ?? 0);
|
|
2178
|
+
const distSq = dx * dx + dy * dy;
|
|
2179
|
+
if (distSq === 0) {
|
|
2180
|
+
continue;
|
|
2181
|
+
}
|
|
2182
|
+
const dist = Math.sqrt(distSq);
|
|
2183
|
+
if (dist < SEPARATION_DISTANCE) {
|
|
2184
|
+
sepX += -dx / dist * (1 / dist);
|
|
2185
|
+
sepY += -dy / dist * (1 / dist);
|
|
2186
|
+
sepActive = true;
|
|
2187
|
+
}
|
|
2188
|
+
if (dist < SWARMMATE_RADIUS) {
|
|
2189
|
+
cohX += dx;
|
|
2190
|
+
cohY += dy;
|
|
2191
|
+
cohActive = true;
|
|
2192
|
+
alignX += b2.vx ?? 0;
|
|
2193
|
+
alignY += b2.vy ?? 0;
|
|
2194
|
+
alignActive = true;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
const applyForce = (fx, fy, weight, active) => {
|
|
2199
|
+
if (!active || weight === 0) {
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
const len = Math.sqrt(fx * fx + fy * fy);
|
|
2203
|
+
if (len === 0) {
|
|
2204
|
+
return;
|
|
2205
|
+
}
|
|
2206
|
+
const sx = fx * maxVelocity / len - (b1.vx ?? 0);
|
|
2207
|
+
const sy = fy * maxVelocity / len - (b1.vy ?? 0);
|
|
2208
|
+
const slen = Math.sqrt(sx * sx + sy * sy);
|
|
2209
|
+
if (slen > weight) {
|
|
2210
|
+
ax += sx * weight / slen;
|
|
2211
|
+
ay += sy * weight / slen;
|
|
2212
|
+
} else {
|
|
2213
|
+
ax += sx;
|
|
2214
|
+
ay += sy;
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2217
|
+
applyForce(alignX, alignY, alignmentW, alignActive);
|
|
2218
|
+
applyForce(cohX, cohY, cohesionW, cohActive);
|
|
2219
|
+
applyForce(sepX, sepY, separationW, sepActive);
|
|
2220
|
+
applyForce(avoidX, avoidY, avoidanceW, avoidActive);
|
|
2221
|
+
b1.ax = ax;
|
|
2222
|
+
b1.ay = ay;
|
|
2223
|
+
}
|
|
2224
|
+
const trailLength = Math.max(0, Math.round(this.#opt("trailLength")));
|
|
2225
|
+
for (const b of nodes) {
|
|
2226
|
+
let vx = (b.vx ?? 0) + (b.ax ?? 0);
|
|
2227
|
+
let vy = (b.vy ?? 0) + (b.ay ?? 0);
|
|
2228
|
+
const vlen = Math.sqrt(vx * vx + vy * vy);
|
|
2229
|
+
if (vlen > maxVelocity) {
|
|
2230
|
+
vx = vx * maxVelocity / vlen;
|
|
2231
|
+
vy = vy * maxVelocity / vlen;
|
|
2232
|
+
}
|
|
2233
|
+
b.vx = vx;
|
|
2234
|
+
b.vy = vy;
|
|
2235
|
+
if (trailLength > 0) {
|
|
2236
|
+
const history = b.history ?? (b.history = []);
|
|
2237
|
+
history.push({
|
|
2238
|
+
x: b.x ?? 0,
|
|
2239
|
+
y: b.y ?? 0
|
|
2240
|
+
});
|
|
2241
|
+
if (history.length > trailLength) {
|
|
2242
|
+
history.splice(0, history.length - trailLength);
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
let x = (b.x ?? 0) + vx;
|
|
2246
|
+
let y = (b.y ?? 0) + vy;
|
|
2247
|
+
let wrapped = false;
|
|
2248
|
+
if (x > halfW) {
|
|
2249
|
+
x -= width;
|
|
2250
|
+
wrapped = true;
|
|
2251
|
+
} else if (x < -halfW) {
|
|
2252
|
+
x += width;
|
|
2253
|
+
wrapped = true;
|
|
2254
|
+
}
|
|
2255
|
+
if (y > halfH) {
|
|
2256
|
+
y -= height;
|
|
2257
|
+
wrapped = true;
|
|
2258
|
+
} else if (y < -halfH) {
|
|
2259
|
+
y += height;
|
|
2260
|
+
wrapped = true;
|
|
2261
|
+
}
|
|
2262
|
+
if (wrapped && b.history) {
|
|
2263
|
+
b.history.length = 0;
|
|
2264
|
+
}
|
|
2265
|
+
b.x = x;
|
|
2266
|
+
b.y = y;
|
|
2267
|
+
}
|
|
2268
|
+
for (const edge of this.layout.graph.edges) {
|
|
2269
|
+
const sx = edge.source.x ?? 0;
|
|
2270
|
+
const sy = edge.source.y ?? 0;
|
|
2271
|
+
const tx = edge.target.x ?? 0;
|
|
2272
|
+
const ty = edge.target.y ?? 0;
|
|
2273
|
+
edge.path = `M ${sx} ${sy} Q 0 0 ${tx} ${ty}`;
|
|
2274
|
+
}
|
|
2275
|
+
this.emitUpdate("positions");
|
|
2276
|
+
}
|
|
2277
|
+
};
|
|
2278
|
+
|
|
1336
2279
|
// src/graph/renderer/graph-renderer.ts
|
|
1337
2280
|
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
1338
2281
|
import * as Clipper from "js-clipper";
|
|
1339
|
-
import { log as
|
|
2282
|
+
import { log as log10 } from "@dxos/log";
|
|
1340
2283
|
|
|
1341
2284
|
// src/graph/renderer/bullets.ts
|
|
1342
2285
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
@@ -1369,8 +2312,6 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
1369
2312
|
};
|
|
1370
2313
|
|
|
1371
2314
|
// src/graph/renderer/renderer.ts
|
|
1372
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1373
|
-
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
1374
2315
|
var Renderer = class {
|
|
1375
2316
|
_context;
|
|
1376
2317
|
_root;
|
|
@@ -1385,34 +2326,48 @@ var Renderer = class {
|
|
|
1385
2326
|
get context() {
|
|
1386
2327
|
return this._context;
|
|
1387
2328
|
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Returns the SVG group root if mounted.
|
|
2331
|
+
* The ref may be null between mount/unmount cycles or before the SVG container has sized.
|
|
2332
|
+
* Callers should treat null as "skip this render" rather than as an error.
|
|
2333
|
+
*/
|
|
1388
2334
|
get root() {
|
|
1389
|
-
invariant3(this._root.current, "SVG root is not initialized", {
|
|
1390
|
-
F: __dxlog_file7,
|
|
1391
|
-
L: 40,
|
|
1392
|
-
S: this,
|
|
1393
|
-
A: [
|
|
1394
|
-
"this._root.current",
|
|
1395
|
-
"'SVG root is not initialized'"
|
|
1396
|
-
]
|
|
1397
|
-
});
|
|
1398
2335
|
return this._root.current;
|
|
1399
2336
|
}
|
|
1400
2337
|
get options() {
|
|
1401
2338
|
return this._options;
|
|
1402
2339
|
}
|
|
2340
|
+
/**
|
|
2341
|
+
* Fast path invoked when only positions changed.
|
|
2342
|
+
* Default falls back to a full `render`; subclasses can override to skip
|
|
2343
|
+
* enter/exit joins and attribute callbacks for per-tick updates.
|
|
2344
|
+
*/
|
|
2345
|
+
applyPositions(layout) {
|
|
2346
|
+
this.render(layout);
|
|
2347
|
+
}
|
|
1403
2348
|
};
|
|
1404
2349
|
|
|
1405
2350
|
// src/graph/renderer/graph-renderer.ts
|
|
1406
|
-
var
|
|
2351
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
1407
2352
|
var createLine2 = line2();
|
|
2353
|
+
var EDGE_FADE_MS = 300;
|
|
2354
|
+
var NODE_HIDE_MS = 500;
|
|
1408
2355
|
var GraphRenderer = class extends Renderer {
|
|
2356
|
+
// First render of this instance — used to clear DOM left behind by a previous
|
|
2357
|
+
// renderer pointing at the same `<g>` (e.g. when the consumer swaps projectors
|
|
2358
|
+
// and a new renderer is constructed for the same SVG root). Without this, the
|
|
2359
|
+
// previous variant's node shapes (e.g. circles) would persist as d3.join sees
|
|
2360
|
+
// them in the `update` set instead of `enter`.
|
|
2361
|
+
#firstRender = true;
|
|
1409
2362
|
render(layout) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
2363
|
+
if (!this.root) {
|
|
2364
|
+
return;
|
|
2365
|
+
}
|
|
2366
|
+
if (this.#firstRender) {
|
|
2367
|
+
this.#firstRender = false;
|
|
2368
|
+
this.root.replaceChildren();
|
|
2369
|
+
}
|
|
2370
|
+
log10("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 35, S: this });
|
|
1416
2371
|
const root = select4(this.root);
|
|
1417
2372
|
if (layout.guides) {
|
|
1418
2373
|
root.selectAll("g.dx-guides").data([
|
|
@@ -1470,37 +2425,92 @@ var GraphRenderer = class extends Renderer {
|
|
|
1470
2425
|
{
|
|
1471
2426
|
id: "edges"
|
|
1472
2427
|
}
|
|
1473
|
-
], (d) => d.id).join("g").classed("dx-edges", true);
|
|
2428
|
+
], (d) => d.id).join("g").classed("dx-edges", true).style("opacity", this.options.edgeOpacity != null ? String(this.options.edgeOpacity) : null);
|
|
1474
2429
|
const nodeGroup = root.selectAll("g.dx-nodes").data([
|
|
1475
2430
|
{
|
|
1476
2431
|
id: "nodes"
|
|
1477
2432
|
}
|
|
1478
2433
|
], (d) => d.id).join("g").classed("dx-nodes", true);
|
|
1479
|
-
nodeGroup.selectAll("g.dx-node").data(layout.graph?.nodes ?? [], (d) => d.id).join((enter) => enter.append("g").attr("data-id", (d) => d.id).attr("opacity", 1).classed("dx-node", true).call(createNode, this.options), (update) => update
|
|
2434
|
+
nodeGroup.selectAll("g.dx-node").data(layout.graph?.nodes ?? [], (d) => d.id).join((enter) => enter.append("g").attr("data-id", (d) => d.id).attr("opacity", (d) => d.hidden ? 0 : 1).classed("dx-node", true).call(createNode, this.options), (update) => update, (exit) => {
|
|
1480
2435
|
return exit.transition().ease(easeCubicOut).duration(300).attr("opacity", 0).on("end", function(d) {
|
|
1481
2436
|
select4(this).remove();
|
|
1482
2437
|
});
|
|
1483
|
-
}).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
1484
|
-
edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
|
|
1485
|
-
|
|
2438
|
+
}).call(updateNode2, this.options).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
2439
|
+
edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
|
|
2440
|
+
(enter) => enter.append("g").attr("data-id", (d) => d.id).classed("dx-edge", true).call(createEdge, this.options),
|
|
2441
|
+
(update) => update,
|
|
2442
|
+
// Exit fade: edges removed by a topology change (e.g. variant switch from cluster
|
|
2443
|
+
// back to force replaces hierarchy edges with data edges) ease out rather than pop.
|
|
2444
|
+
(exit) => exit.transition().ease(easeCubicOut).duration(EDGE_FADE_MS).attr("opacity", 0).on("end", function() {
|
|
2445
|
+
select4(this).remove();
|
|
2446
|
+
})
|
|
2447
|
+
).call(updateEdge, this.options, nodeGroup).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* Fast positions-only update. Skips enter/exit, attribute callbacks, label sizing,
|
|
2451
|
+
* and the subgraph hull pass; just writes `transform` per node and `d` per edge.
|
|
2452
|
+
* Called per simulation tick / animation frame.
|
|
2453
|
+
*/
|
|
2454
|
+
applyPositions(layout) {
|
|
2455
|
+
if (!this.root) {
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2458
|
+
const root = select4(this.root);
|
|
2459
|
+
const applyNode = this.options.applyNode;
|
|
2460
|
+
root.select("g.dx-nodes").selectAll("g.dx-node").attr("transform", (d) => d.x != null && d.y != null ? `translate(${d.x},${d.y})` : null).each(applyNode ? function(d) {
|
|
2461
|
+
applyNode(this, d);
|
|
2462
|
+
} : () => {
|
|
2463
|
+
});
|
|
2464
|
+
root.select("g.dx-edges").selectAll("g.dx-edge").selectAll("path").attr("d", function() {
|
|
2465
|
+
const edge = select4(this.parentElement).datum();
|
|
2466
|
+
if (edge.path) {
|
|
2467
|
+
return edge.path;
|
|
2468
|
+
}
|
|
2469
|
+
const { source, target } = edge;
|
|
2470
|
+
if (!source.initialized || !target.initialized) {
|
|
2471
|
+
return null;
|
|
2472
|
+
}
|
|
2473
|
+
return createLine2(getCircumferencePoints([
|
|
2474
|
+
source.x,
|
|
2475
|
+
source.y
|
|
2476
|
+
], [
|
|
2477
|
+
target.x,
|
|
2478
|
+
target.y
|
|
2479
|
+
], source.r, target.r));
|
|
2480
|
+
});
|
|
1486
2481
|
}
|
|
1487
2482
|
/**
|
|
1488
2483
|
* Trigger path bullets.
|
|
1489
2484
|
* @param node
|
|
1490
2485
|
*/
|
|
1491
2486
|
fireBullet(node) {
|
|
2487
|
+
if (!this.root) {
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
1492
2490
|
select4(this.root).selectAll("g.dx-edges").selectAll("path").call(createBullets(this.root, node.id));
|
|
1493
2491
|
}
|
|
1494
2492
|
};
|
|
2493
|
+
var SHAPE_CLASS = "dx-shape";
|
|
2494
|
+
var renderCustomShape = (group, options) => {
|
|
2495
|
+
group.each(function(d) {
|
|
2496
|
+
const g = select4(this);
|
|
2497
|
+
g.selectAll(`.${SHAPE_CLASS}`).remove();
|
|
2498
|
+
const shapeGroup = g.append("g").classed(SHAPE_CLASS, true);
|
|
2499
|
+
options.renderNode(shapeGroup, d);
|
|
2500
|
+
});
|
|
2501
|
+
};
|
|
1495
2502
|
var createNode = (group, options) => {
|
|
1496
|
-
const
|
|
2503
|
+
const useCustom = !!options.renderNode;
|
|
2504
|
+
if (useCustom) {
|
|
2505
|
+
renderCustomShape(group, options);
|
|
2506
|
+
}
|
|
2507
|
+
const hitTarget = useCustom ? group : group.append("circle");
|
|
1497
2508
|
if (options.drag) {
|
|
1498
|
-
|
|
2509
|
+
hitTarget.call(options.drag);
|
|
1499
2510
|
}
|
|
1500
2511
|
if (options.onNodeClick) {
|
|
1501
|
-
group.on("click", (event) => {
|
|
1502
|
-
|
|
1503
|
-
options.onNodeClick(node, event);
|
|
2512
|
+
group.on("click", (event, d) => {
|
|
2513
|
+
options.onNodeClick(d, event);
|
|
1504
2514
|
});
|
|
1505
2515
|
}
|
|
1506
2516
|
if (options.labels && !options.onNodePointerEnter) {
|
|
@@ -1509,24 +2519,34 @@ var createNode = (group, options) => {
|
|
|
1509
2519
|
g.append("rect");
|
|
1510
2520
|
g.append("text").style("dominant-baseline", "middle");
|
|
1511
2521
|
}
|
|
1512
|
-
if (options.onNodePointerEnter) {
|
|
1513
|
-
|
|
1514
|
-
const node = select4(this.parentElement).datum();
|
|
1515
|
-
options.onNodePointerEnter(node, event);
|
|
2522
|
+
if (options.onNodePointerEnter || options.onNodePointerLeave || options.highlightOnHover) {
|
|
2523
|
+
hitTarget.on("pointerenter", function(event) {
|
|
2524
|
+
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2525
|
+
options.onNodePointerEnter?.(node, event);
|
|
2526
|
+
if (options.highlightOnHover) {
|
|
2527
|
+
applyHoverHighlight(this.closest("g.dx-graph"), node.id);
|
|
2528
|
+
}
|
|
2529
|
+
});
|
|
2530
|
+
hitTarget.on("pointerleave", function(event) {
|
|
2531
|
+
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2532
|
+
options.onNodePointerLeave?.(node, event);
|
|
2533
|
+
if (options.highlightOnHover) {
|
|
2534
|
+
applyHoverHighlight(this.closest("g.dx-graph"), null);
|
|
2535
|
+
}
|
|
1516
2536
|
});
|
|
1517
2537
|
group.attr("data-hover", "handled");
|
|
1518
|
-
} else if (options.highlight !== false) {
|
|
1519
|
-
|
|
2538
|
+
} else if (options.highlight !== false && !useCustom) {
|
|
2539
|
+
hitTarget.on("pointerenter", function() {
|
|
1520
2540
|
select4(this.closest("g.dx-node")).raise();
|
|
1521
2541
|
if (options.labels) {
|
|
1522
|
-
select4(this.parentElement).classed("dx-active", true).classed("dx-highlight", true);
|
|
2542
|
+
select4(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
|
|
1523
2543
|
}
|
|
1524
2544
|
});
|
|
1525
2545
|
group.on("pointerleave", function() {
|
|
1526
2546
|
if (options.labels) {
|
|
1527
|
-
select4(this).classed("dx-active", false);
|
|
2547
|
+
select4(this).classed("dx-node-active", false);
|
|
1528
2548
|
setTimeout(() => {
|
|
1529
|
-
if (!select4(this).classed("dx-active")) {
|
|
2549
|
+
if (!select4(this).classed("dx-node-active")) {
|
|
1530
2550
|
select4(this).classed("dx-highlight", false);
|
|
1531
2551
|
}
|
|
1532
2552
|
}, 300);
|
|
@@ -1538,6 +2558,11 @@ var updateNode2 = (group, options) => {
|
|
|
1538
2558
|
group.attr("transform", (d) => {
|
|
1539
2559
|
return d.x != null && d.y != null ? `translate(${d.x},${d.y})` : void 0;
|
|
1540
2560
|
});
|
|
2561
|
+
group.classed("dx-hidden", (d) => d.hidden ?? false);
|
|
2562
|
+
group.transition("hide").ease(easeCubicOut).duration(NODE_HIDE_MS).attr("opacity", (d) => d.hidden ? 0 : 1);
|
|
2563
|
+
if (options.renderNode) {
|
|
2564
|
+
renderCustomShape(group, options);
|
|
2565
|
+
}
|
|
1541
2566
|
if (options.attributes?.node) {
|
|
1542
2567
|
try {
|
|
1543
2568
|
group.each((d, i, nodes) => {
|
|
@@ -1553,18 +2578,15 @@ var updateNode2 = (group, options) => {
|
|
|
1553
2578
|
}
|
|
1554
2579
|
});
|
|
1555
2580
|
} catch (error) {
|
|
1556
|
-
|
|
2581
|
+
log10.error("updateNode", {
|
|
1557
2582
|
error: error?.message
|
|
1558
|
-
}, {
|
|
1559
|
-
F: __dxlog_file8,
|
|
1560
|
-
L: 304,
|
|
1561
|
-
S: void 0,
|
|
1562
|
-
C: (f, a) => f(...a)
|
|
1563
|
-
});
|
|
2583
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 303, S: void 0 });
|
|
1564
2584
|
}
|
|
1565
2585
|
}
|
|
1566
2586
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1567
|
-
|
|
2587
|
+
if (!options.renderNode) {
|
|
2588
|
+
groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
|
|
2589
|
+
}
|
|
1568
2590
|
if (options.labels) {
|
|
1569
2591
|
const bx = 1;
|
|
1570
2592
|
const px = 4;
|
|
@@ -1609,18 +2631,17 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1609
2631
|
}
|
|
1610
2632
|
});
|
|
1611
2633
|
} catch (error) {
|
|
1612
|
-
|
|
2634
|
+
log10.error("updateEdge", {
|
|
1613
2635
|
error: error?.message
|
|
1614
|
-
}, {
|
|
1615
|
-
F: __dxlog_file8,
|
|
1616
|
-
L: 416,
|
|
1617
|
-
S: void 0,
|
|
1618
|
-
C: (f, a) => f(...a)
|
|
1619
|
-
});
|
|
2636
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 371, S: void 0 });
|
|
1620
2637
|
}
|
|
1621
2638
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1622
2639
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
1623
|
-
const
|
|
2640
|
+
const edge = select4(this.parentElement).datum();
|
|
2641
|
+
if (edge.path) {
|
|
2642
|
+
return edge.path;
|
|
2643
|
+
}
|
|
2644
|
+
const { source, target } = edge;
|
|
1624
2645
|
if (!source.initialized || !target.initialized) {
|
|
1625
2646
|
return;
|
|
1626
2647
|
}
|
|
@@ -1633,6 +2654,62 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1633
2654
|
], source.r, target.r));
|
|
1634
2655
|
});
|
|
1635
2656
|
};
|
|
2657
|
+
var applyHoverHighlight = (root, focusedId) => {
|
|
2658
|
+
if (!root) {
|
|
2659
|
+
return;
|
|
2660
|
+
}
|
|
2661
|
+
const r = select4(root);
|
|
2662
|
+
const on = focusedId != null;
|
|
2663
|
+
const outgoing = /* @__PURE__ */ new Set();
|
|
2664
|
+
const incoming = /* @__PURE__ */ new Set();
|
|
2665
|
+
if (on) {
|
|
2666
|
+
r.select("g.dx-edges").selectAll("g.dx-edge").each((edge) => {
|
|
2667
|
+
if (edge.source.id === focusedId) {
|
|
2668
|
+
outgoing.add(edge.target.id);
|
|
2669
|
+
}
|
|
2670
|
+
if (edge.target.id === focusedId) {
|
|
2671
|
+
incoming.add(edge.source.id);
|
|
2672
|
+
}
|
|
2673
|
+
});
|
|
2674
|
+
}
|
|
2675
|
+
r.select("g.dx-edges").selectAll("g.dx-edge").each(function(edge) {
|
|
2676
|
+
const path = select4(this).select("path:not(.dx-click)");
|
|
2677
|
+
if (!on) {
|
|
2678
|
+
path.style("stroke", null).style("stroke-width", null).style("opacity", null);
|
|
2679
|
+
return;
|
|
2680
|
+
}
|
|
2681
|
+
if (edge.source.id === focusedId) {
|
|
2682
|
+
path.style("stroke", "var(--color-orange-500)").style("stroke-width", "1.5px").style("opacity", null);
|
|
2683
|
+
} else if (edge.target.id === focusedId) {
|
|
2684
|
+
path.style("stroke", "var(--color-sky-500)").style("stroke-width", "1.5px").style("opacity", null);
|
|
2685
|
+
} else {
|
|
2686
|
+
path.style("stroke", null).style("stroke-width", null).style("opacity", "0.8");
|
|
2687
|
+
}
|
|
2688
|
+
});
|
|
2689
|
+
r.select("g.dx-nodes").selectAll("g.dx-node").each(function(node) {
|
|
2690
|
+
const groupSel = select4(this);
|
|
2691
|
+
const shape = groupSel.select("circle, rect");
|
|
2692
|
+
if (node.hidden) {
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
if (!on) {
|
|
2696
|
+
groupSel.style("opacity", null);
|
|
2697
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
const connected = outgoing.has(node.id) || incoming.has(node.id);
|
|
2701
|
+
if (node.id === focusedId) {
|
|
2702
|
+
groupSel.style("opacity", null);
|
|
2703
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2704
|
+
} else if (connected) {
|
|
2705
|
+
groupSel.style("opacity", null);
|
|
2706
|
+
shape.style("stroke", "var(--color-orange-400)").style("stroke-width", "2.5px");
|
|
2707
|
+
} else {
|
|
2708
|
+
groupSel.style("opacity", "0.4");
|
|
2709
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2710
|
+
}
|
|
2711
|
+
});
|
|
2712
|
+
};
|
|
1636
2713
|
var applyClasses = (el, classes) => {
|
|
1637
2714
|
for (const [className, value] of Object.entries(classes)) {
|
|
1638
2715
|
el.classed(className, value);
|
|
@@ -1671,6 +2748,45 @@ var findConnectedComponents = (graph) => {
|
|
|
1671
2748
|
return components;
|
|
1672
2749
|
};
|
|
1673
2750
|
|
|
2751
|
+
// src/graph/renderer/labels.ts
|
|
2752
|
+
var DEFAULT_DURATION = 200;
|
|
2753
|
+
var DEFAULT_OFFSET = 4;
|
|
2754
|
+
var getTarget = (node) => {
|
|
2755
|
+
const tx = node.tx;
|
|
2756
|
+
const ty = node.ty;
|
|
2757
|
+
return {
|
|
2758
|
+
x: tx ?? node.x ?? 0,
|
|
2759
|
+
y: ty ?? node.y ?? 0
|
|
2760
|
+
};
|
|
2761
|
+
};
|
|
2762
|
+
var appendRadialLeafLabel = (group, node, label, r, options = {}) => {
|
|
2763
|
+
if (!label) {
|
|
2764
|
+
return;
|
|
2765
|
+
}
|
|
2766
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label" } = options;
|
|
2767
|
+
const { x: targetX, y: targetY } = getTarget(node);
|
|
2768
|
+
const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
|
|
2769
|
+
const flipped = angleDeg > 90 || angleDeg < -90;
|
|
2770
|
+
group.append("text").attr("class", className).attr("dy", "0.32em").attr("transform", `rotate(${flipped ? angleDeg + 180 : angleDeg})`).attr("x", flipped ? -(r + offset) : r + offset).attr("text-anchor", flipped ? "end" : "start").attr("opacity", 0).style("cursor", "pointer").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2771
|
+
};
|
|
2772
|
+
var appendRadialGroupLabel = (group, node, label, r, options = {}) => {
|
|
2773
|
+
if (!label) {
|
|
2774
|
+
return;
|
|
2775
|
+
}
|
|
2776
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label dx-cluster-label-group" } = options;
|
|
2777
|
+
const { x: targetX, y: targetY } = getTarget(node);
|
|
2778
|
+
const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
|
|
2779
|
+
const flipped = angleDeg > 90 || angleDeg < -90;
|
|
2780
|
+
group.append("text").attr("class", className).attr("dy", "0.32em").attr("transform", `rotate(${flipped ? angleDeg + 180 : angleDeg})`).attr("x", flipped ? r + offset : -(r + offset)).attr("text-anchor", flipped ? "start" : "end").attr("opacity", 0).style("pointer-events", "none").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2781
|
+
};
|
|
2782
|
+
var appendRootLabel = (group, label, r, options = {}) => {
|
|
2783
|
+
if (!label) {
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = 6, className = "dx-cluster-label dx-cluster-label-root" } = options;
|
|
2787
|
+
group.append("text").attr("class", className).attr("text-anchor", "middle").attr("y", -(r + offset)).attr("opacity", 0).style("pointer-events", "none").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2788
|
+
};
|
|
2789
|
+
|
|
1674
2790
|
// src/graph/renderer/linker.ts
|
|
1675
2791
|
import { line as line3 } from "d3";
|
|
1676
2792
|
var createLine3 = line3();
|
|
@@ -2013,8 +3129,8 @@ var useZoom = (options = defaultZoomOptions) => {
|
|
|
2013
3129
|
};
|
|
2014
3130
|
|
|
2015
3131
|
// src/components/Graph/Graph.tsx
|
|
2016
|
-
var
|
|
2017
|
-
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
3132
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
3133
|
+
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, onPointerMove, onPointerLeave, ...props }, forwardedRef) => {
|
|
2018
3134
|
const context = useSvgContext();
|
|
2019
3135
|
const graphRef = useRef3(null);
|
|
2020
3136
|
const { projector, renderer } = useMemo3(() => {
|
|
@@ -2031,8 +3147,18 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2031
3147
|
arrows: {
|
|
2032
3148
|
end: arrows
|
|
2033
3149
|
},
|
|
2034
|
-
|
|
2035
|
-
|
|
3150
|
+
// Projector intercept first so built-in interactions (e.g. cluster collapse) can
|
|
3151
|
+
// run without consumers wiring them. Returning true suppresses the user handler.
|
|
3152
|
+
onNodeClick: (node, event) => {
|
|
3153
|
+
if (projector2.handleNodeClick(node, event)) {
|
|
3154
|
+
return;
|
|
3155
|
+
}
|
|
3156
|
+
onSelect?.(node, event);
|
|
3157
|
+
},
|
|
3158
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0,
|
|
3159
|
+
// Pair pointerenter with leave so consumers can clear hover-driven previews.
|
|
3160
|
+
// The callback receives `null` on leave (event still carries the source).
|
|
3161
|
+
onNodePointerLeave: onInspect ? (_node, event) => onInspect(null, event) : void 0
|
|
2036
3162
|
});
|
|
2037
3163
|
}
|
|
2038
3164
|
return {
|
|
@@ -2043,7 +3169,17 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2043
3169
|
context,
|
|
2044
3170
|
projectorProp,
|
|
2045
3171
|
rendererProp,
|
|
2046
|
-
drag2
|
|
3172
|
+
drag2,
|
|
3173
|
+
arrows,
|
|
3174
|
+
onSelect,
|
|
3175
|
+
onInspect,
|
|
3176
|
+
props.labels,
|
|
3177
|
+
props.subgraphs,
|
|
3178
|
+
props.attributes,
|
|
3179
|
+
props.renderNode,
|
|
3180
|
+
props.highlightOnHover,
|
|
3181
|
+
props.applyNode,
|
|
3182
|
+
props.edgeOpacity
|
|
2047
3183
|
]);
|
|
2048
3184
|
useImperativeHandle(forwardedRef, () => ({
|
|
2049
3185
|
refresh: () => {
|
|
@@ -2061,23 +3197,26 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2061
3197
|
renderer
|
|
2062
3198
|
]);
|
|
2063
3199
|
useEffect3(() => {
|
|
3200
|
+
const cleanup = combine(
|
|
3201
|
+
// Subscribe to model changes if reactive model.
|
|
3202
|
+
model ? model.subscribe(() => {
|
|
3203
|
+
projector.updateData(model?.graph);
|
|
3204
|
+
}) : void 0,
|
|
3205
|
+
projector.updated.on(({ layout, kind }) => {
|
|
3206
|
+
try {
|
|
3207
|
+
if (kind === "positions") {
|
|
3208
|
+
renderer.applyPositions(layout);
|
|
3209
|
+
} else {
|
|
3210
|
+
renderer.render(layout);
|
|
3211
|
+
}
|
|
3212
|
+
} catch (error) {
|
|
3213
|
+
log11.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 95, S: void 0 });
|
|
3214
|
+
void projector.stop();
|
|
3215
|
+
}
|
|
3216
|
+
})
|
|
3217
|
+
);
|
|
2064
3218
|
projector.updateData(model?.graph);
|
|
2065
|
-
|
|
2066
|
-
projector.updateData(model?.graph);
|
|
2067
|
-
}) : void 0;
|
|
2068
|
-
return combine(unsubscribeModel, projector.updated.on(({ layout }) => {
|
|
2069
|
-
try {
|
|
2070
|
-
renderer.render(layout);
|
|
2071
|
-
} catch (error) {
|
|
2072
|
-
void projector.stop();
|
|
2073
|
-
log6.catch(error, void 0, {
|
|
2074
|
-
F: __dxlog_file9,
|
|
2075
|
-
L: 116,
|
|
2076
|
-
S: void 0,
|
|
2077
|
-
C: (f, a) => f(...a)
|
|
2078
|
-
});
|
|
2079
|
-
}
|
|
2080
|
-
}));
|
|
3219
|
+
return cleanup;
|
|
2081
3220
|
}, [
|
|
2082
3221
|
model,
|
|
2083
3222
|
projector,
|
|
@@ -2091,6 +3230,49 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2091
3230
|
}, [
|
|
2092
3231
|
projector
|
|
2093
3232
|
]);
|
|
3233
|
+
useEffect3(() => {
|
|
3234
|
+
if (!onPointerMove && !onPointerLeave) {
|
|
3235
|
+
return;
|
|
3236
|
+
}
|
|
3237
|
+
const svg = context.svg;
|
|
3238
|
+
if (!svg) {
|
|
3239
|
+
return;
|
|
3240
|
+
}
|
|
3241
|
+
const previousPointerEvents = svg.style.pointerEvents;
|
|
3242
|
+
svg.style.pointerEvents = "all";
|
|
3243
|
+
const handleMove = (event) => {
|
|
3244
|
+
if (!onPointerMove) {
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
const target = graphRef.current;
|
|
3248
|
+
const ctm = target?.getScreenCTM();
|
|
3249
|
+
if (!target || !ctm) {
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
const point = svg.createSVGPoint();
|
|
3253
|
+
point.x = event.clientX;
|
|
3254
|
+
point.y = event.clientY;
|
|
3255
|
+
const modelPoint = point.matrixTransform(ctm.inverse());
|
|
3256
|
+
onPointerMove({
|
|
3257
|
+
x: modelPoint.x,
|
|
3258
|
+
y: modelPoint.y
|
|
3259
|
+
}, event);
|
|
3260
|
+
};
|
|
3261
|
+
const handleLeave = (event) => {
|
|
3262
|
+
onPointerLeave?.(event);
|
|
3263
|
+
};
|
|
3264
|
+
svg.addEventListener("pointermove", handleMove);
|
|
3265
|
+
svg.addEventListener("pointerleave", handleLeave);
|
|
3266
|
+
return () => {
|
|
3267
|
+
svg.removeEventListener("pointermove", handleMove);
|
|
3268
|
+
svg.removeEventListener("pointerleave", handleLeave);
|
|
3269
|
+
svg.style.pointerEvents = previousPointerEvents;
|
|
3270
|
+
};
|
|
3271
|
+
}, [
|
|
3272
|
+
context,
|
|
3273
|
+
onPointerMove,
|
|
3274
|
+
onPointerLeave
|
|
3275
|
+
]);
|
|
2094
3276
|
return /* @__PURE__ */ React.createElement("g", {
|
|
2095
3277
|
ref: graphRef,
|
|
2096
3278
|
className: mx("dx-graph", classNames)
|
|
@@ -2105,21 +3287,27 @@ import { feature, mesh } from "topojson-client";
|
|
|
2105
3287
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
2106
3288
|
const { svg, size } = useSvgContext();
|
|
2107
3289
|
useEffect4(() => {
|
|
2108
|
-
if (size) {
|
|
2109
|
-
|
|
2110
|
-
const projection = hexProjection(radius);
|
|
2111
|
-
const path = geoPath().projection(projection);
|
|
2112
|
-
select7(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);
|
|
2113
|
-
select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
2114
|
-
const redraw = (border) => {
|
|
2115
|
-
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
2116
|
-
};
|
|
2117
|
-
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
3290
|
+
if (!size) {
|
|
3291
|
+
return;
|
|
2118
3292
|
}
|
|
3293
|
+
const topology = hexTopology(size, radius, value);
|
|
3294
|
+
const projection = hexProjection(radius);
|
|
3295
|
+
const path = geoPath().projection(projection);
|
|
3296
|
+
const root = select7(svg).selectAll("g.dx-mesh-root").data([
|
|
3297
|
+
null
|
|
3298
|
+
]).join("g").classed("dx-mesh-root", true);
|
|
3299
|
+
root.selectAll("*").remove();
|
|
3300
|
+
root.append("g").attr("class", "hexagon").selectAll("path").data(topology.objects.hexagons.geometries).enter().append("path").attr("d", (d) => path(feature(topology, d))).attr("class", (d) => d.properties?.fill ? "fill" : null);
|
|
3301
|
+
root.append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
3302
|
+
const redraw = (border) => {
|
|
3303
|
+
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
3304
|
+
};
|
|
3305
|
+
root.append("path").attr("class", "border").call(redraw);
|
|
2119
3306
|
}, [
|
|
2120
3307
|
svg,
|
|
2121
3308
|
size,
|
|
2122
|
-
value
|
|
3309
|
+
value,
|
|
3310
|
+
radius
|
|
2123
3311
|
]);
|
|
2124
3312
|
return null;
|
|
2125
3313
|
};
|
|
@@ -2230,30 +3418,86 @@ var hexProjection = (radius) => {
|
|
|
2230
3418
|
};
|
|
2231
3419
|
};
|
|
2232
3420
|
|
|
2233
|
-
// src/components/SVG/
|
|
2234
|
-
import React2 from "react";
|
|
3421
|
+
// src/components/SVG/FPS.tsx
|
|
3422
|
+
import React2, { useEffect as useEffect5, useState } from "react";
|
|
2235
3423
|
import { mx as mx2 } from "@dxos/ui-theme";
|
|
3424
|
+
var PADDING = 8;
|
|
3425
|
+
var FPS = ({ classNames, corner = "top-right", margin = PADDING }) => {
|
|
3426
|
+
const context = useSvgContext();
|
|
3427
|
+
const [size, setSize] = useState(context.size);
|
|
3428
|
+
const [fps, setFps] = useState(null);
|
|
3429
|
+
useEffect5(() => {
|
|
3430
|
+
setSize(context.size);
|
|
3431
|
+
return context.resized.on((ctx) => setSize(ctx.size));
|
|
3432
|
+
}, [
|
|
3433
|
+
context
|
|
3434
|
+
]);
|
|
3435
|
+
useEffect5(() => {
|
|
3436
|
+
let frames = 0;
|
|
3437
|
+
let windowStart = performance.now();
|
|
3438
|
+
let rafId = 0;
|
|
3439
|
+
const loop = (now) => {
|
|
3440
|
+
frames++;
|
|
3441
|
+
const elapsed = now - windowStart;
|
|
3442
|
+
if (elapsed >= 1e3) {
|
|
3443
|
+
setFps(frames * 1e3 / elapsed);
|
|
3444
|
+
frames = 0;
|
|
3445
|
+
windowStart = now;
|
|
3446
|
+
}
|
|
3447
|
+
rafId = requestAnimationFrame(loop);
|
|
3448
|
+
};
|
|
3449
|
+
rafId = requestAnimationFrame(loop);
|
|
3450
|
+
return () => cancelAnimationFrame(rafId);
|
|
3451
|
+
}, []);
|
|
3452
|
+
if (!size) {
|
|
3453
|
+
return null;
|
|
3454
|
+
}
|
|
3455
|
+
const halfW = size.width / 2;
|
|
3456
|
+
const halfH = size.height / 2;
|
|
3457
|
+
const left = corner === "top-left" || corner === "bottom-left";
|
|
3458
|
+
const top = corner === "top-left" || corner === "top-right";
|
|
3459
|
+
const x = left ? -halfW + margin : halfW - margin;
|
|
3460
|
+
const y = top ? -halfH + margin : halfH - margin;
|
|
3461
|
+
const textAnchor = left ? "start" : "end";
|
|
3462
|
+
const dominantBaseline = top ? "hanging" : "alphabetic";
|
|
3463
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
3464
|
+
className: "dx-fps",
|
|
3465
|
+
style: {
|
|
3466
|
+
pointerEvents: "none"
|
|
3467
|
+
}
|
|
3468
|
+
}, /* @__PURE__ */ React2.createElement("text", {
|
|
3469
|
+
x,
|
|
3470
|
+
y,
|
|
3471
|
+
textAnchor,
|
|
3472
|
+
dominantBaseline,
|
|
3473
|
+
className: mx2("font-mono text-xs fill-neutral-500 tabular-nums", classNames)
|
|
3474
|
+
}, fps == null ? "\u2014 fps" : `${fps.toFixed(0)} fps`));
|
|
3475
|
+
};
|
|
3476
|
+
|
|
3477
|
+
// src/components/SVG/Grid.tsx
|
|
3478
|
+
import React3 from "react";
|
|
3479
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
2236
3480
|
var Grid = ({ classNames, ...props }) => {
|
|
2237
3481
|
const { ref } = useGrid(props);
|
|
2238
|
-
return /* @__PURE__ */
|
|
3482
|
+
return /* @__PURE__ */ React3.createElement("g", {
|
|
2239
3483
|
ref,
|
|
2240
|
-
className:
|
|
3484
|
+
className: mx3("dx-grid", classNames)
|
|
2241
3485
|
});
|
|
2242
3486
|
};
|
|
2243
3487
|
|
|
2244
3488
|
// src/components/SVG/Markers.tsx
|
|
2245
3489
|
import { select as select8 } from "d3";
|
|
2246
|
-
import
|
|
3490
|
+
import React4, { useEffect as useEffect6, useRef as useRef4 } from "react";
|
|
2247
3491
|
var Markers = ({ arrowSize, className }) => {
|
|
2248
3492
|
const ref = useRef4(null);
|
|
2249
|
-
|
|
3493
|
+
useEffect6(() => {
|
|
2250
3494
|
select8(ref.current).call(createMarkers({
|
|
2251
3495
|
arrowSize
|
|
2252
3496
|
}));
|
|
2253
3497
|
}, [
|
|
2254
3498
|
ref
|
|
2255
3499
|
]);
|
|
2256
|
-
return /* @__PURE__ */
|
|
3500
|
+
return /* @__PURE__ */ React4.createElement("defs", {
|
|
2257
3501
|
ref,
|
|
2258
3502
|
className
|
|
2259
3503
|
});
|
|
@@ -2261,13 +3505,41 @@ var Markers = ({ arrowSize, className }) => {
|
|
|
2261
3505
|
|
|
2262
3506
|
// src/components/SVG/Root.tsx
|
|
2263
3507
|
import { select as select9 } from "d3";
|
|
2264
|
-
import
|
|
2265
|
-
import {
|
|
2266
|
-
import {
|
|
3508
|
+
import React5, { forwardRef as forwardRef2, useEffect as useEffect7, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4, useState as useState2 } from "react";
|
|
3509
|
+
import { composableProps } from "@dxos/react-ui";
|
|
3510
|
+
import { mx as mx4 } from "@dxos/ui-theme";
|
|
2267
3511
|
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
2268
|
-
const
|
|
2269
|
-
|
|
3512
|
+
const [container, setContainer] = useState2(null);
|
|
3513
|
+
const [size, setSize] = useState2({
|
|
3514
|
+
width: 0,
|
|
3515
|
+
height: 0
|
|
2270
3516
|
});
|
|
3517
|
+
useEffect7(() => {
|
|
3518
|
+
if (!container) {
|
|
3519
|
+
return;
|
|
3520
|
+
}
|
|
3521
|
+
const rect = container.getBoundingClientRect();
|
|
3522
|
+
setSize({
|
|
3523
|
+
width: rect.width,
|
|
3524
|
+
height: rect.height
|
|
3525
|
+
});
|
|
3526
|
+
const observer = new ResizeObserver((entries) => {
|
|
3527
|
+
const entry = entries[0];
|
|
3528
|
+
if (!entry) {
|
|
3529
|
+
return;
|
|
3530
|
+
}
|
|
3531
|
+
const { width: width2, height: height2 } = entry.contentRect;
|
|
3532
|
+
setSize((prev) => prev.width === width2 && prev.height === height2 ? prev : {
|
|
3533
|
+
width: width2,
|
|
3534
|
+
height: height2
|
|
3535
|
+
});
|
|
3536
|
+
});
|
|
3537
|
+
observer.observe(container);
|
|
3538
|
+
return () => observer.disconnect();
|
|
3539
|
+
}, [
|
|
3540
|
+
container
|
|
3541
|
+
]);
|
|
3542
|
+
const { width, height } = size;
|
|
2271
3543
|
const context = useMemo4(() => {
|
|
2272
3544
|
return new SVGContext({
|
|
2273
3545
|
scale,
|
|
@@ -2280,7 +3552,7 @@ var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props },
|
|
|
2280
3552
|
useImperativeHandle2(ref, () => context, [
|
|
2281
3553
|
context
|
|
2282
3554
|
]);
|
|
2283
|
-
|
|
3555
|
+
useEffect7(() => {
|
|
2284
3556
|
if (width && height) {
|
|
2285
3557
|
context.setSize({
|
|
2286
3558
|
width,
|
|
@@ -2294,22 +3566,22 @@ var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props },
|
|
|
2294
3566
|
height
|
|
2295
3567
|
]);
|
|
2296
3568
|
const ready = width !== 0 && height !== 0;
|
|
2297
|
-
return /* @__PURE__ */
|
|
3569
|
+
return /* @__PURE__ */ React5.createElement(SVGContextProvider, {
|
|
2298
3570
|
value: context
|
|
2299
|
-
}, /* @__PURE__ */
|
|
3571
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
2300
3572
|
...composableProps(props, {
|
|
2301
3573
|
classNames: "dx-expander"
|
|
2302
3574
|
}),
|
|
2303
|
-
ref:
|
|
2304
|
-
}, /* @__PURE__ */
|
|
3575
|
+
ref: setContainer
|
|
3576
|
+
}, /* @__PURE__ */ React5.createElement("svg", {
|
|
2305
3577
|
xmlns: "http://www.w3.org/2000/svg",
|
|
2306
3578
|
ref: context.ref,
|
|
2307
|
-
className:
|
|
3579
|
+
className: mx4("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
2308
3580
|
}, ready && children)));
|
|
2309
3581
|
});
|
|
2310
3582
|
|
|
2311
3583
|
// src/components/SVG/Zoom.tsx
|
|
2312
|
-
import
|
|
3584
|
+
import React6, { memo, useMemo as useMemo5 } from "react";
|
|
2313
3585
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
2314
3586
|
const options = useMemo5(() => ({
|
|
2315
3587
|
extent
|
|
@@ -2317,7 +3589,7 @@ var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
|
2317
3589
|
JSON.stringify(extent)
|
|
2318
3590
|
]);
|
|
2319
3591
|
const zoom2 = useZoom(options);
|
|
2320
|
-
return /* @__PURE__ */
|
|
3592
|
+
return /* @__PURE__ */ React6.createElement("g", {
|
|
2321
3593
|
ref: zoom2.ref,
|
|
2322
3594
|
className
|
|
2323
3595
|
}, children);
|
|
@@ -2330,7 +3602,8 @@ var SVG = {
|
|
|
2330
3602
|
Markers,
|
|
2331
3603
|
Mesh,
|
|
2332
3604
|
Zoom,
|
|
2333
|
-
Graph
|
|
3605
|
+
Graph,
|
|
3606
|
+
FPS
|
|
2334
3607
|
};
|
|
2335
3608
|
|
|
2336
3609
|
// src/fx/pulsar.ts
|
|
@@ -2358,17 +3631,28 @@ var startAnimation = (pulsar, r, options = {}) => {
|
|
|
2358
3631
|
};
|
|
2359
3632
|
var Pulsar;
|
|
2360
3633
|
export {
|
|
3634
|
+
CLUSTER_NODE_TYPE_GROUP,
|
|
3635
|
+
CLUSTER_NODE_TYPE_LEAF,
|
|
3636
|
+
CLUSTER_NODE_TYPE_ROOT,
|
|
2361
3637
|
EventEmitter,
|
|
2362
3638
|
FractionUtil,
|
|
2363
3639
|
Graph,
|
|
3640
|
+
GraphBundleProjector,
|
|
3641
|
+
GraphClusterProjector,
|
|
2364
3642
|
GraphForceProjector,
|
|
2365
3643
|
GraphHierarchicalProjector,
|
|
3644
|
+
GraphLatticeProjector,
|
|
3645
|
+
GraphPlexusProjector,
|
|
2366
3646
|
GraphProjector,
|
|
2367
3647
|
GraphRadialProjector,
|
|
2368
3648
|
GraphRelationalProjector,
|
|
2369
3649
|
GraphRenderer,
|
|
3650
|
+
GraphSwarmProjector,
|
|
2370
3651
|
GridController,
|
|
2371
3652
|
Mesh,
|
|
3653
|
+
PLEXUS_NODE_TYPE_FOCUS,
|
|
3654
|
+
PLEXUS_NODE_TYPE_OBJECT,
|
|
3655
|
+
PLEXUS_NODE_TYPE_RELATION,
|
|
2372
3656
|
Projector,
|
|
2373
3657
|
Pulsar,
|
|
2374
3658
|
Renderer,
|
|
@@ -2379,6 +3663,9 @@ export {
|
|
|
2379
3663
|
Screen,
|
|
2380
3664
|
Vector,
|
|
2381
3665
|
ZoomHandler,
|
|
3666
|
+
appendRadialGroupLabel,
|
|
3667
|
+
appendRadialLeafLabel,
|
|
3668
|
+
appendRootLabel,
|
|
2382
3669
|
createGraphDrag,
|
|
2383
3670
|
createMarkers,
|
|
2384
3671
|
defaultForceOptions,
|