@dxos/react-ui-graph 0.8.4-main.8360d9e660 → 0.8.4-main.8baae0fced
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/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 +914 -364
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +14 -14
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- 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 +914 -364
- 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 +14 -14
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/components/Graph/Graph.d.ts +8 -4
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +5 -5
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Markers.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +5 -1
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +3 -3
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/fx/pulsar.d.ts.map +1 -1
- package/dist/types/src/graph/markers.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts +47 -0
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +60 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.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-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/index.d.ts +3 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts +10 -1
- package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +21 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/renderer.d.ts +12 -1
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +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/hooks.stories.d.ts +1 -1
- 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 -26
- package/src/components/Graph/Graph.stories.tsx +21 -19
- package/src/components/Graph/Graph.tsx +47 -19
- package/src/components/Mesh/Mesh.stories.tsx +6 -5
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/Root.tsx +30 -5
- package/src/components/SVG/SVG.tsx +0 -1
- package/src/components/SVG/Svg.stories.tsx +2 -3
- package/src/fx/fx.stories.tsx +5 -6
- package/src/graph/projector/graph-bundle-projector.ts +210 -0
- package/src/graph/projector/graph-cluster-projector.ts +325 -0
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +5 -2
- package/src/graph/projector/graph-hierarchical-projector.ts +1 -1
- package/src/graph/projector/graph-lattice-projector.ts +86 -0
- package/src/graph/projector/graph-projector.ts +7 -1
- package/src/graph/projector/graph-radial-projector.ts +30 -3
- package/src/graph/projector/graph-relational-projector.ts +1 -1
- package/src/graph/projector/index.ts +3 -0
- package/src/graph/projector/projector.ts +12 -3
- package/src/graph/renderer/graph-renderer.ts +175 -30
- package/src/graph/renderer/renderer.ts +15 -4
- package/src/graph/types.ts +14 -0
- package/src/stories/hooks.stories.tsx +8 -3
- package/src/testing/data.ts +9 -9
- package/src/testing/hooks.ts +2 -3
- package/src/testing/model.ts +3 -3
- package/styles/graph.css +52 -3
|
@@ -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 log9 } 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() {
|
|
@@ -827,30 +740,629 @@ var GraphProjector = class extends Projector {
|
|
|
827
740
|
id: this.options.idAccessor(node)
|
|
828
741
|
};
|
|
829
742
|
}
|
|
830
|
-
current.data = node;
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
743
|
+
current.data = node;
|
|
744
|
+
current.hidden = false;
|
|
745
|
+
return current;
|
|
746
|
+
});
|
|
747
|
+
const edges = data.edges.map((edge) => ({
|
|
748
|
+
id: edge.id,
|
|
749
|
+
source: nodes.find((n) => n.id === edge.source),
|
|
750
|
+
target: nodes.find((n) => n.id === edge.target),
|
|
751
|
+
data: edge.data
|
|
752
|
+
})).filter((edge) => edge.source && edge.target);
|
|
753
|
+
Object.assign(this._layout, {
|
|
754
|
+
graph: {
|
|
755
|
+
nodes,
|
|
756
|
+
edges
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
async onClear() {
|
|
761
|
+
this.reset();
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
// src/graph/projector/graph-radial-projector.ts
|
|
766
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
767
|
+
var GraphRadialProjector = class extends GraphProjector {
|
|
768
|
+
_timer;
|
|
769
|
+
findNode(x, y, radius) {
|
|
770
|
+
return void 0;
|
|
771
|
+
}
|
|
772
|
+
onUpdate(graph) {
|
|
773
|
+
log("onUpdate", {
|
|
774
|
+
graph: {
|
|
775
|
+
nodes: graph?.nodes.length,
|
|
776
|
+
edges: graph?.edges.length
|
|
777
|
+
}
|
|
778
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 13, S: this });
|
|
779
|
+
this.mergeData(graph);
|
|
780
|
+
this.emitUpdate("topology");
|
|
781
|
+
this.doRadialLayout();
|
|
782
|
+
}
|
|
783
|
+
animate() {
|
|
784
|
+
this._timer?.stop();
|
|
785
|
+
this._timer = void 0;
|
|
786
|
+
const start = Date.now();
|
|
787
|
+
if (this.options.duration) {
|
|
788
|
+
this._timer = timer(() => {
|
|
789
|
+
const t = Math.min(1, (Date.now() - start) / this.options.duration);
|
|
790
|
+
const d = easeCubic(t);
|
|
791
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
792
|
+
node.x = node.sx + (node.tx - node.sx) * d;
|
|
793
|
+
node.y = node.sy + (node.ty - node.sy) * d;
|
|
794
|
+
node.r = node.sr + (node.tr - node.sr) * d;
|
|
795
|
+
});
|
|
796
|
+
this.onTickFrame(d);
|
|
797
|
+
this.emitUpdate("positions");
|
|
798
|
+
if (t >= 1) {
|
|
799
|
+
this._timer.stop();
|
|
800
|
+
this._timer = void 0;
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
} else {
|
|
804
|
+
this.layout.graph.nodes.forEach((node) => {
|
|
805
|
+
node.x = node.tx;
|
|
806
|
+
node.y = node.ty;
|
|
807
|
+
node.r = node.tr;
|
|
808
|
+
});
|
|
809
|
+
this.onTickFrame(1);
|
|
810
|
+
this.emitUpdate("positions");
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Per-frame hook called after node x/y/r are interpolated and before the
|
|
815
|
+
* 'positions' emit. Subclasses override to update edge geometry (`edge.path`)
|
|
816
|
+
* so curves stay glued to moving endpoints. `t` is the eased progress in [0, 1].
|
|
817
|
+
*/
|
|
818
|
+
onTickFrame(t) {
|
|
819
|
+
}
|
|
820
|
+
async onStop() {
|
|
821
|
+
this._timer?.stop();
|
|
822
|
+
this._timer = void 0;
|
|
823
|
+
}
|
|
824
|
+
doRadialLayout() {
|
|
825
|
+
if (!this.context.size) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const radial = layoutRadial(0, 0, this.options.radius ?? Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 80), this.layout.graph.nodes.length);
|
|
829
|
+
this.layout.graph.nodes.forEach((node, i) => {
|
|
830
|
+
const [tx, ty] = radial(i);
|
|
831
|
+
updateNode(node, [
|
|
832
|
+
tx,
|
|
833
|
+
ty
|
|
834
|
+
]);
|
|
835
|
+
});
|
|
836
|
+
this.animate();
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
840
|
+
const sx = node.x ?? tx;
|
|
841
|
+
const sy = node.y ?? ty;
|
|
842
|
+
const sr = node.r ?? tr;
|
|
843
|
+
Object.assign(node, {
|
|
844
|
+
initialized: true,
|
|
845
|
+
// Start.
|
|
846
|
+
sx,
|
|
847
|
+
sy,
|
|
848
|
+
sr,
|
|
849
|
+
// Target.
|
|
850
|
+
tx,
|
|
851
|
+
ty,
|
|
852
|
+
tr,
|
|
853
|
+
// Current.
|
|
854
|
+
x: sx,
|
|
855
|
+
y: sy,
|
|
856
|
+
r: sr
|
|
857
|
+
});
|
|
858
|
+
};
|
|
859
|
+
var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
|
|
860
|
+
const da = 2 * Math.PI / n;
|
|
861
|
+
return (i) => {
|
|
862
|
+
const a = start + i * da;
|
|
863
|
+
return [
|
|
864
|
+
x + Math.cos(a) * r,
|
|
865
|
+
y + Math.sin(a) * r
|
|
866
|
+
];
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
var layoutHorizontal = (x, y, w, n) => {
|
|
870
|
+
const dx = n > 1 ? w / (n - 1) : 0;
|
|
871
|
+
const sx = x - (n - 1) * dx / 2;
|
|
872
|
+
return (i) => {
|
|
873
|
+
return [
|
|
874
|
+
sx + i * dx,
|
|
875
|
+
y
|
|
876
|
+
];
|
|
877
|
+
};
|
|
878
|
+
};
|
|
879
|
+
var layoutVertical = (x, y, h, n) => {
|
|
880
|
+
const dy = n > 1 ? h / (n - 1) : 0;
|
|
881
|
+
const sy = y - (n - 1) * dy / 2;
|
|
882
|
+
return (i) => {
|
|
883
|
+
return [
|
|
884
|
+
x,
|
|
885
|
+
sy + i * dy
|
|
886
|
+
];
|
|
887
|
+
};
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
// src/graph/projector/graph-bundle-projector.ts
|
|
891
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-bundle-projector.ts";
|
|
892
|
+
var ROOT_ID = "__bundle_root__";
|
|
893
|
+
var GROUP_PREFIX = "__bundle_group__:";
|
|
894
|
+
var cartesianToPolar = (x, y) => ({
|
|
895
|
+
angle: Math.atan2(x, -y),
|
|
896
|
+
radius: Math.hypot(x, y)
|
|
897
|
+
});
|
|
898
|
+
var GraphBundleProjector = class extends GraphRadialProjector {
|
|
899
|
+
// Per-edge polar point arrays. Points 0 and N-1 are the source / target leaves and are
|
|
900
|
+
// overwritten from current cartesian on every tick; intermediate points stay fixed at
|
|
901
|
+
// their cluster-layout polar coordinates.
|
|
902
|
+
#edgePoints = /* @__PURE__ */ new Map();
|
|
903
|
+
#lineGen = lineRadial().radius((d) => d.radius).angle((d) => d.angle);
|
|
904
|
+
onUpdate(graph) {
|
|
905
|
+
log2("onUpdate", {
|
|
906
|
+
graph: {
|
|
907
|
+
nodes: graph?.nodes.length,
|
|
908
|
+
edges: graph?.edges.length
|
|
909
|
+
}
|
|
910
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 40, S: this });
|
|
911
|
+
this.mergeData(graph);
|
|
912
|
+
this.doBundleLayout();
|
|
913
|
+
this.emitUpdate("topology");
|
|
914
|
+
this.animate();
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Refresh leaf endpoint polar values from current cartesian so the curve tracks
|
|
918
|
+
* its endpoints during the tween. Internal hierarchy positions stay constant.
|
|
919
|
+
*/
|
|
920
|
+
onTickFrame(_t) {
|
|
921
|
+
for (const edge of this.layout.graph.edges) {
|
|
922
|
+
if (edge.type !== "bundle") {
|
|
923
|
+
continue;
|
|
924
|
+
}
|
|
925
|
+
const points = this.#edgePoints.get(edge.id);
|
|
926
|
+
if (!points || points.length < 2) {
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
const s = cartesianToPolar(edge.source.x ?? 0, edge.source.y ?? 0);
|
|
930
|
+
const t = cartesianToPolar(edge.target.x ?? 0, edge.target.y ?? 0);
|
|
931
|
+
points[0] = {
|
|
932
|
+
angle: s.angle,
|
|
933
|
+
radius: s.radius
|
|
934
|
+
};
|
|
935
|
+
points[points.length - 1] = {
|
|
936
|
+
angle: t.angle,
|
|
937
|
+
radius: t.radius
|
|
938
|
+
};
|
|
939
|
+
edge.path = this.#lineGen(points) ?? void 0;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
doBundleLayout() {
|
|
943
|
+
if (!this.context.size) {
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
const dataNodes = [
|
|
947
|
+
...this.layout.graph.nodes
|
|
948
|
+
];
|
|
949
|
+
if (!dataNodes.length) {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
const groupOf = this.options.groupOf;
|
|
953
|
+
const items = [
|
|
954
|
+
{
|
|
955
|
+
id: ROOT_ID
|
|
956
|
+
}
|
|
957
|
+
];
|
|
958
|
+
const groupIds = /* @__PURE__ */ new Map();
|
|
959
|
+
for (const node of dataNodes) {
|
|
960
|
+
const key = groupOf?.(node);
|
|
961
|
+
let parent = ROOT_ID;
|
|
962
|
+
if (key !== void 0) {
|
|
963
|
+
let groupId = groupIds.get(key);
|
|
964
|
+
if (!groupId) {
|
|
965
|
+
groupId = `${GROUP_PREFIX}${key}`;
|
|
966
|
+
groupIds.set(key, groupId);
|
|
967
|
+
items.push({
|
|
968
|
+
id: groupId,
|
|
969
|
+
parent: ROOT_ID
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
parent = groupId;
|
|
973
|
+
}
|
|
974
|
+
items.push({
|
|
975
|
+
id: node.id,
|
|
976
|
+
parent,
|
|
977
|
+
node
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
981
|
+
for (const item of items) {
|
|
982
|
+
if (item.parent) {
|
|
983
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
984
|
+
list.push(item);
|
|
985
|
+
childrenByParent.set(item.parent, list);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const root = hierarchy({
|
|
989
|
+
id: ROOT_ID
|
|
990
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
991
|
+
const { width, height } = this.context.size;
|
|
992
|
+
const margin = this.options.margin ?? 120;
|
|
993
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
994
|
+
d3Cluster().size([
|
|
995
|
+
2 * Math.PI,
|
|
996
|
+
ringRadius
|
|
997
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
998
|
+
const leafR = this.options.leafRadius ?? 4;
|
|
999
|
+
const tension = this.options.tension ?? 0.85;
|
|
1000
|
+
this.#lineGen = lineRadial().curve(curveBundle.beta(tension)).radius((d) => d.radius).angle((d) => d.angle);
|
|
1001
|
+
const hierById = /* @__PURE__ */ new Map();
|
|
1002
|
+
root.each((d) => {
|
|
1003
|
+
hierById.set(d.data.id, d);
|
|
1004
|
+
});
|
|
1005
|
+
root.leaves().forEach((d) => {
|
|
1006
|
+
const angle = d.x;
|
|
1007
|
+
const radius = d.y;
|
|
1008
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1009
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1010
|
+
if (d.data.node) {
|
|
1011
|
+
updateNode(d.data.node, [
|
|
1012
|
+
x,
|
|
1013
|
+
y
|
|
1014
|
+
], leafR);
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
this.layout.graph.nodes = dataNodes;
|
|
1018
|
+
this.#edgePoints.clear();
|
|
1019
|
+
const incomingEdges = [
|
|
1020
|
+
...this.layout.graph.edges
|
|
1021
|
+
];
|
|
1022
|
+
const bundleEdges = [];
|
|
1023
|
+
for (const edge of incomingEdges) {
|
|
1024
|
+
const sourceHier = hierById.get(edge.source.id);
|
|
1025
|
+
const targetHier = hierById.get(edge.target.id);
|
|
1026
|
+
if (!sourceHier || !targetHier || sourceHier === targetHier) {
|
|
1027
|
+
continue;
|
|
1028
|
+
}
|
|
1029
|
+
const pathNodes = sourceHier.path(targetHier);
|
|
1030
|
+
const points = pathNodes.map((n) => ({
|
|
1031
|
+
angle: n.x,
|
|
1032
|
+
radius: n.y
|
|
1033
|
+
}));
|
|
1034
|
+
this.#edgePoints.set(edge.id, points);
|
|
1035
|
+
bundleEdges.push({
|
|
1036
|
+
id: edge.id,
|
|
1037
|
+
type: "bundle",
|
|
1038
|
+
source: edge.source,
|
|
1039
|
+
target: edge.target,
|
|
1040
|
+
data: edge.data
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
this.layout.graph.edges = bundleEdges;
|
|
1044
|
+
this.onTickFrame(0);
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
|
|
1048
|
+
// src/graph/projector/graph-cluster-projector.ts
|
|
1049
|
+
import { cluster as d3Cluster2, hierarchy as hierarchy2, linkRadial } from "d3";
|
|
1050
|
+
import { log as log3 } from "@dxos/log";
|
|
1051
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-cluster-projector.ts";
|
|
1052
|
+
var ROOT_ID2 = "__cluster_root__";
|
|
1053
|
+
var GROUP_PREFIX2 = "__group__:";
|
|
1054
|
+
var HIER_EDGE_PREFIX = "__hier__:";
|
|
1055
|
+
var CLUSTER_NODE_TYPE_LEAF = "leaf";
|
|
1056
|
+
var CLUSTER_NODE_TYPE_GROUP = "group";
|
|
1057
|
+
var CLUSTER_NODE_TYPE_ROOT = "root";
|
|
1058
|
+
var linkPath = linkRadial().angle((d) => d.x).radius((d) => d.y);
|
|
1059
|
+
var cartesianToPolar2 = (x, y) => ({
|
|
1060
|
+
angle: Math.atan2(x, -y),
|
|
1061
|
+
radius: Math.hypot(x, y)
|
|
1062
|
+
});
|
|
1063
|
+
var GraphClusterProjector = class extends GraphRadialProjector {
|
|
1064
|
+
// Synthetic-node ids (root id, or `${GROUP_PREFIX}${key}`) whose subtree is currently
|
|
1065
|
+
// hidden. Clicking the corresponding rendered circle calls toggleCollapsed to flip
|
|
1066
|
+
// membership, then re-runs the layout so the renderer's exit transition fades the
|
|
1067
|
+
// hidden leaves + hierarchy edges out (and back in on expand).
|
|
1068
|
+
#collapsed = /* @__PURE__ */ new Set();
|
|
1069
|
+
// Snapshot of the full data-node set as of the last mergeData. doClusterLayout always
|
|
1070
|
+
// reads from this rather than `layout.graph.nodes` — the layout view is filtered (it
|
|
1071
|
+
// drops hidden leaves so the renderer doesn't see them), so re-reading from there
|
|
1072
|
+
// would permanently lose the hidden leaves and they couldn't reappear on expand.
|
|
1073
|
+
#dataNodes = [];
|
|
1074
|
+
/** Toggle collapse state for a synthetic node id. Triggers a topology re-emit. */
|
|
1075
|
+
toggleCollapsed(id) {
|
|
1076
|
+
if (this.#collapsed.has(id)) {
|
|
1077
|
+
this.#collapsed.delete(id);
|
|
1078
|
+
} else {
|
|
1079
|
+
this.#collapsed.add(id);
|
|
1080
|
+
}
|
|
1081
|
+
this.doClusterLayout();
|
|
1082
|
+
this.emitUpdate("topology");
|
|
1083
|
+
this.animate();
|
|
1084
|
+
}
|
|
1085
|
+
/** Whether a synthetic-node id is currently collapsed. */
|
|
1086
|
+
isCollapsed(id) {
|
|
1087
|
+
return this.#collapsed.has(id);
|
|
1088
|
+
}
|
|
1089
|
+
onUpdate(graph) {
|
|
1090
|
+
log3("onUpdate", {
|
|
1091
|
+
graph: {
|
|
1092
|
+
nodes: graph?.nodes.length,
|
|
1093
|
+
edges: graph?.edges.length
|
|
1094
|
+
}
|
|
1095
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 69, S: this });
|
|
1096
|
+
this.mergeData(graph);
|
|
1097
|
+
this.#dataNodes = [
|
|
1098
|
+
...this.layout.graph.nodes
|
|
1099
|
+
];
|
|
1100
|
+
this.doClusterLayout();
|
|
1101
|
+
this.emitUpdate("topology");
|
|
1102
|
+
this.animate();
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Recompute each hierarchy edge's `path` from current cartesian source/target positions,
|
|
1106
|
+
* so the curves track moving endpoints during a cross-variant tween (e.g. force → cluster)
|
|
1107
|
+
* instead of being pinned to the final polar layout.
|
|
1108
|
+
*/
|
|
1109
|
+
onTickFrame(_t) {
|
|
1110
|
+
for (const edge of this.layout.graph.edges) {
|
|
1111
|
+
if (edge.type !== "hierarchy") {
|
|
1112
|
+
continue;
|
|
1113
|
+
}
|
|
1114
|
+
const { source, target } = edge;
|
|
1115
|
+
const s = cartesianToPolar2(source.x ?? 0, source.y ?? 0);
|
|
1116
|
+
const t = cartesianToPolar2(target.x ?? 0, target.y ?? 0);
|
|
1117
|
+
edge.path = linkPath({
|
|
1118
|
+
source: {
|
|
1119
|
+
x: s.angle,
|
|
1120
|
+
y: s.radius
|
|
1121
|
+
},
|
|
1122
|
+
target: {
|
|
1123
|
+
x: t.angle,
|
|
1124
|
+
y: t.radius
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
doClusterLayout() {
|
|
1130
|
+
if (!this.context.size) {
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
const dataNodes = this.#dataNodes;
|
|
1134
|
+
if (!dataNodes.length) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
const groupOf = this.options.groupOf;
|
|
1138
|
+
const rootId = this.options.rootId ?? ROOT_ID2;
|
|
1139
|
+
const items = [
|
|
1140
|
+
{
|
|
1141
|
+
id: rootId
|
|
1142
|
+
}
|
|
1143
|
+
];
|
|
1144
|
+
const groupIds = /* @__PURE__ */ new Map();
|
|
1145
|
+
const rootCollapsed = this.#collapsed.has(rootId);
|
|
1146
|
+
if (!rootCollapsed) {
|
|
1147
|
+
for (const node of dataNodes) {
|
|
1148
|
+
const key = groupOf?.(node);
|
|
1149
|
+
let parent = rootId;
|
|
1150
|
+
if (key !== void 0) {
|
|
1151
|
+
let groupId = groupIds.get(key);
|
|
1152
|
+
if (!groupId) {
|
|
1153
|
+
groupId = `${GROUP_PREFIX2}${key}`;
|
|
1154
|
+
groupIds.set(key, groupId);
|
|
1155
|
+
items.push({
|
|
1156
|
+
id: groupId,
|
|
1157
|
+
parent: rootId,
|
|
1158
|
+
groupKey: key
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
parent = groupId;
|
|
1162
|
+
}
|
|
1163
|
+
if (this.#collapsed.has(parent)) {
|
|
1164
|
+
continue;
|
|
1165
|
+
}
|
|
1166
|
+
items.push({
|
|
1167
|
+
id: node.id,
|
|
1168
|
+
parent,
|
|
1169
|
+
node
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
1174
|
+
for (const item of items) {
|
|
1175
|
+
if (item.parent) {
|
|
1176
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
1177
|
+
list.push(item);
|
|
1178
|
+
childrenByParent.set(item.parent, list);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
const root = hierarchy2({
|
|
1182
|
+
id: rootId
|
|
1183
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1184
|
+
const { width, height } = this.context.size;
|
|
1185
|
+
const margin = this.options.margin ?? 80;
|
|
1186
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1187
|
+
d3Cluster2().size([
|
|
1188
|
+
2 * Math.PI,
|
|
1189
|
+
ringRadius
|
|
1190
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1191
|
+
const leafR = this.options.leafRadius ?? 4;
|
|
1192
|
+
const groupR = this.options.groupRadius ?? 3;
|
|
1193
|
+
const rootR = this.options.rootRadius ?? 5;
|
|
1194
|
+
const prevStubsById = /* @__PURE__ */ new Map();
|
|
1195
|
+
for (const node of this.layout.graph.nodes) {
|
|
1196
|
+
if (node.type === CLUSTER_NODE_TYPE_ROOT || node.type === CLUSTER_NODE_TYPE_GROUP) {
|
|
1197
|
+
prevStubsById.set(node.id, node);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
const syntheticNodes = /* @__PURE__ */ new Map();
|
|
1201
|
+
root.each((d) => {
|
|
1202
|
+
const id = d.data.id;
|
|
1203
|
+
const angle = d.x;
|
|
1204
|
+
const radius = d.y;
|
|
1205
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1206
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1207
|
+
if (d.data.node) {
|
|
1208
|
+
updateNode(d.data.node, [
|
|
1209
|
+
x,
|
|
1210
|
+
y
|
|
1211
|
+
], leafR);
|
|
1212
|
+
d.data.node.type = CLUSTER_NODE_TYPE_LEAF;
|
|
1213
|
+
d.data.node.hidden = false;
|
|
1214
|
+
} else {
|
|
1215
|
+
const isRoot = id === rootId;
|
|
1216
|
+
const stub = prevStubsById.get(id) ?? {
|
|
1217
|
+
id,
|
|
1218
|
+
x: 0,
|
|
1219
|
+
y: 0
|
|
1220
|
+
};
|
|
1221
|
+
updateNode(stub, [
|
|
1222
|
+
x,
|
|
1223
|
+
y
|
|
1224
|
+
], isRoot ? rootR : groupR);
|
|
1225
|
+
stub.type = isRoot ? CLUSTER_NODE_TYPE_ROOT : CLUSTER_NODE_TYPE_GROUP;
|
|
1226
|
+
if (isRoot) {
|
|
1227
|
+
stub.label = this.options.rootLabel;
|
|
1228
|
+
} else if (d.data.groupKey !== void 0) {
|
|
1229
|
+
stub.label = this.options.groupLabel ? this.options.groupLabel(d.data.groupKey) : d.data.groupKey;
|
|
1230
|
+
}
|
|
1231
|
+
syntheticNodes.set(id, stub);
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
const visibleLeafIds = /* @__PURE__ */ new Set();
|
|
1235
|
+
for (const item of items) {
|
|
1236
|
+
if (item.node) {
|
|
1237
|
+
visibleLeafIds.add(item.id);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
for (const node of dataNodes) {
|
|
1241
|
+
if (visibleLeafIds.has(node.id)) {
|
|
1242
|
+
continue;
|
|
1243
|
+
}
|
|
1244
|
+
const key = groupOf?.(node);
|
|
1245
|
+
const parentId = key !== void 0 && groupIds.has(key) ? groupIds.get(key) : rootId;
|
|
1246
|
+
const parentStub = syntheticNodes.get(parentId);
|
|
1247
|
+
const targetX = parentStub?.tx ?? 0;
|
|
1248
|
+
const targetY = parentStub?.ty ?? 0;
|
|
1249
|
+
updateNode(node, [
|
|
1250
|
+
targetX,
|
|
1251
|
+
targetY
|
|
1252
|
+
], leafR);
|
|
1253
|
+
node.type = CLUSTER_NODE_TYPE_LEAF;
|
|
1254
|
+
node.hidden = true;
|
|
1255
|
+
}
|
|
1256
|
+
const nextNodes = [];
|
|
1257
|
+
for (const stub of syntheticNodes.values()) {
|
|
1258
|
+
nextNodes.push(stub);
|
|
1259
|
+
}
|
|
1260
|
+
for (const node of dataNodes) {
|
|
1261
|
+
nextNodes.push(node);
|
|
1262
|
+
}
|
|
1263
|
+
this.layout.graph.nodes = nextNodes;
|
|
1264
|
+
const hierarchyEdges = [];
|
|
1265
|
+
root.links().forEach((link) => {
|
|
1266
|
+
const sid = link.source.data.id;
|
|
1267
|
+
const tid = link.target.data.id;
|
|
1268
|
+
const sourceNode = link.source.data.node ?? syntheticNodes.get(sid);
|
|
1269
|
+
const targetNode = link.target.data.node ?? syntheticNodes.get(tid);
|
|
1270
|
+
hierarchyEdges.push({
|
|
1271
|
+
id: `${HIER_EDGE_PREFIX}${sid}->${tid}`,
|
|
1272
|
+
type: "hierarchy",
|
|
1273
|
+
source: sourceNode,
|
|
1274
|
+
target: targetNode,
|
|
1275
|
+
data: void 0
|
|
1276
|
+
});
|
|
1277
|
+
});
|
|
1278
|
+
this.layout.graph.edges = hierarchyEdges;
|
|
1279
|
+
this.onTickFrame(0);
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
|
|
1283
|
+
// src/graph/projector/graph-drag.ts
|
|
1284
|
+
import { drag, pointer, select as select2 } from "d3";
|
|
1285
|
+
var defaultDragOptions = {
|
|
1286
|
+
linkMod: "metaKey",
|
|
1287
|
+
freezeMod: "shiftKey"
|
|
1288
|
+
};
|
|
1289
|
+
var createGraphDrag = (context, projector, options = defaultDragOptions) => {
|
|
1290
|
+
let mode;
|
|
1291
|
+
let source;
|
|
1292
|
+
let target;
|
|
1293
|
+
let offset;
|
|
1294
|
+
let moved = false;
|
|
1295
|
+
const keyMod = (event, key) => {
|
|
1296
|
+
const modKey = options?.[key] ?? defaultDragOptions[key];
|
|
1297
|
+
return modKey === void 0 || event[modKey];
|
|
1298
|
+
};
|
|
1299
|
+
return drag().filter((event) => !event.ctrlKey).on("start", function(event, d) {
|
|
1300
|
+
source = d;
|
|
1301
|
+
offset = pointer(event, this.parentElement);
|
|
1302
|
+
if (options?.onDrop && keyMod(event.sourceEvent, "linkMod")) {
|
|
1303
|
+
mode = 1;
|
|
1304
|
+
} else if (keyMod(event.sourceEvent, "dragMod")) {
|
|
1305
|
+
mode = 0;
|
|
1306
|
+
}
|
|
1307
|
+
}).on("drag", function(event, d) {
|
|
1308
|
+
const parent = this.closest("g.node");
|
|
1309
|
+
select2(parent).classed("dragging", true).raise();
|
|
1310
|
+
const [dx, dy] = pointer(event, this.parentElement);
|
|
1311
|
+
const x = d.x + dx - offset[0];
|
|
1312
|
+
const y = d.y + dy - offset[1];
|
|
1313
|
+
const point = [
|
|
1314
|
+
x,
|
|
1315
|
+
y
|
|
1316
|
+
];
|
|
1317
|
+
switch (mode) {
|
|
1318
|
+
case 0: {
|
|
1319
|
+
select2(context.svg).attr("cursor", "grabbing");
|
|
1320
|
+
event.subject.x = event.subject.fx = point[0];
|
|
1321
|
+
event.subject.y = event.subject.fy = point[1];
|
|
1322
|
+
projector.refresh(true);
|
|
1323
|
+
moved = true;
|
|
1324
|
+
break;
|
|
1325
|
+
}
|
|
1326
|
+
case 1: {
|
|
1327
|
+
if (options?.onDrag) {
|
|
1328
|
+
target = projector.findNode(event.x, event.y, 16);
|
|
1329
|
+
if (source === target) {
|
|
1330
|
+
select2(context.svg).attr("cursor", void 0);
|
|
1331
|
+
options?.onDrag?.();
|
|
1332
|
+
} else {
|
|
1333
|
+
select2(context.svg).attr("cursor", target ? "alias" : "cell");
|
|
1334
|
+
options?.onDrag?.(source, target, point);
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
843
1337
|
}
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
this.
|
|
848
|
-
|
|
1338
|
+
}
|
|
1339
|
+
}).on("end", function(event) {
|
|
1340
|
+
select2(context.svg).attr("cursor", void 0);
|
|
1341
|
+
select2(this.parentElement).classed("dragging", false);
|
|
1342
|
+
switch (mode) {
|
|
1343
|
+
case 1: {
|
|
1344
|
+
options?.onDrop?.(source, target);
|
|
1345
|
+
break;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
if (!keyMod(event.sourceEvent, "freezeMod")) {
|
|
1349
|
+
event.subject.fx = null;
|
|
1350
|
+
event.subject.fy = null;
|
|
1351
|
+
}
|
|
1352
|
+
mode = void 0;
|
|
1353
|
+
source = void 0;
|
|
1354
|
+
target = void 0;
|
|
1355
|
+
offset = void 0;
|
|
1356
|
+
if (moved) {
|
|
1357
|
+
projector.refresh(false);
|
|
1358
|
+
moved = false;
|
|
1359
|
+
}
|
|
1360
|
+
});
|
|
849
1361
|
};
|
|
850
1362
|
|
|
851
1363
|
// src/graph/projector/graph-force-projector.ts
|
|
852
1364
|
import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
|
|
853
|
-
import { log } from "@dxos/log";
|
|
1365
|
+
import { log as log4 } from "@dxos/log";
|
|
854
1366
|
|
|
855
1367
|
// src/graph/projector/graph-forces.ts
|
|
856
1368
|
import { forceX, forceY } from "d3";
|
|
@@ -869,7 +1381,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
869
1381
|
};
|
|
870
1382
|
|
|
871
1383
|
// src/graph/projector/graph-force-projector.ts
|
|
872
|
-
var
|
|
1384
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
873
1385
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
874
1386
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
875
1387
|
};
|
|
@@ -919,7 +1431,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
919
1431
|
} else {
|
|
920
1432
|
this.updateForces(this.forces);
|
|
921
1433
|
}
|
|
922
|
-
this._simulation.on("tick", () => propagating && this.emitUpdate()).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
|
|
1434
|
+
this._simulation.on("tick", () => propagating && this.emitUpdate("positions")).velocityDecay(0.3).alphaDecay(1 - Math.pow(1e-3, 1 / 300)).alpha(1).restart();
|
|
923
1435
|
}
|
|
924
1436
|
async onStop() {
|
|
925
1437
|
clearTimeout(this._timeout);
|
|
@@ -936,21 +1448,17 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
936
1448
|
this.restart();
|
|
937
1449
|
}
|
|
938
1450
|
onUpdate(graph) {
|
|
939
|
-
|
|
1451
|
+
log4("onUpdate", {
|
|
940
1452
|
graph: {
|
|
941
1453
|
nodes: graph?.nodes.length,
|
|
942
1454
|
edges: graph?.edges.length
|
|
943
1455
|
}
|
|
944
|
-
}, {
|
|
945
|
-
F: __dxlog_file3,
|
|
946
|
-
L: 227,
|
|
947
|
-
S: this,
|
|
948
|
-
C: (f, a) => f(...a)
|
|
949
|
-
});
|
|
1456
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 90, S: this });
|
|
950
1457
|
this._simulation.stop();
|
|
951
1458
|
this.mergeData(graph);
|
|
952
1459
|
this.updateLayout();
|
|
953
1460
|
this.updateForces(this.forces);
|
|
1461
|
+
this.emitUpdate("topology");
|
|
954
1462
|
this.restart();
|
|
955
1463
|
}
|
|
956
1464
|
updateLayout() {
|
|
@@ -994,14 +1502,9 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
994
1502
|
* Update all forces.
|
|
995
1503
|
*/
|
|
996
1504
|
updateForces(forces) {
|
|
997
|
-
|
|
1505
|
+
log4("updateForces", {
|
|
998
1506
|
forces
|
|
999
|
-
}, {
|
|
1000
|
-
F: __dxlog_file3,
|
|
1001
|
-
L: 288,
|
|
1002
|
-
S: this,
|
|
1003
|
-
C: (f, a) => f(...a)
|
|
1004
|
-
});
|
|
1507
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 152, S: this });
|
|
1005
1508
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
1006
1509
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
1007
1510
|
if (config.distance != null) {
|
|
@@ -1065,140 +1568,19 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
1065
1568
|
};
|
|
1066
1569
|
|
|
1067
1570
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
1068
|
-
import { log as
|
|
1069
|
-
|
|
1070
|
-
// src/graph/projector/graph-radial-projector.ts
|
|
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
|
-
}
|
|
1079
|
-
onUpdate(graph) {
|
|
1080
|
-
log2("onUpdate", {
|
|
1081
|
-
graph: {
|
|
1082
|
-
nodes: graph?.nodes.length,
|
|
1083
|
-
edges: graph?.edges.length
|
|
1084
|
-
}
|
|
1085
|
-
}, {
|
|
1086
|
-
F: __dxlog_file4,
|
|
1087
|
-
L: 32,
|
|
1088
|
-
S: this,
|
|
1089
|
-
C: (f, a) => f(...a)
|
|
1090
|
-
});
|
|
1091
|
-
this.mergeData(graph);
|
|
1092
|
-
this.doRadialLayout();
|
|
1093
|
-
}
|
|
1094
|
-
animate() {
|
|
1095
|
-
const start = Date.now();
|
|
1096
|
-
if (this.options.duration) {
|
|
1097
|
-
this._timer = timer(() => {
|
|
1098
|
-
const t = Math.min(1, (Date.now() - start) / this.options.duration);
|
|
1099
|
-
const d = easeCubic(t);
|
|
1100
|
-
this.layout.graph.nodes.forEach((node) => {
|
|
1101
|
-
node.x = node.sx + (node.tx - node.sx) * d;
|
|
1102
|
-
node.y = node.sy + (node.ty - node.sy) * d;
|
|
1103
|
-
node.r = node.sr + (node.tr - node.sr) * d;
|
|
1104
|
-
});
|
|
1105
|
-
this.emitUpdate();
|
|
1106
|
-
if (t >= 1) {
|
|
1107
|
-
this._timer.stop();
|
|
1108
|
-
this._timer = void 0;
|
|
1109
|
-
}
|
|
1110
|
-
});
|
|
1111
|
-
} else {
|
|
1112
|
-
this.emitUpdate();
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
async onStop() {
|
|
1116
|
-
this._timer?.stop();
|
|
1117
|
-
this._timer = void 0;
|
|
1118
|
-
}
|
|
1119
|
-
doRadialLayout() {
|
|
1120
|
-
if (!this.context.size) {
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
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);
|
|
1124
|
-
this.layout.graph.nodes.forEach((node, i) => {
|
|
1125
|
-
const [tx, ty] = radial(i);
|
|
1126
|
-
updateNode(node, [
|
|
1127
|
-
tx,
|
|
1128
|
-
ty
|
|
1129
|
-
]);
|
|
1130
|
-
});
|
|
1131
|
-
this.animate();
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
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
|
-
|
|
1185
|
-
// src/graph/projector/graph-hierarchical-projector.ts
|
|
1186
|
-
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
1571
|
+
import { log as log5 } from "@dxos/log";
|
|
1572
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-hierarchical-projector.ts";
|
|
1187
1573
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
1188
1574
|
onUpdate(graph) {
|
|
1189
|
-
|
|
1575
|
+
log5("onUpdate", {
|
|
1190
1576
|
graph: {
|
|
1191
1577
|
nodes: graph?.nodes.length,
|
|
1192
1578
|
edges: graph?.edges.length
|
|
1193
1579
|
},
|
|
1194
1580
|
selection: this.selection?.getSelectedIds()
|
|
1195
|
-
}, {
|
|
1196
|
-
F: __dxlog_file5,
|
|
1197
|
-
L: 24,
|
|
1198
|
-
S: this,
|
|
1199
|
-
C: (f, a) => f(...a)
|
|
1200
|
-
});
|
|
1581
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 8, S: this });
|
|
1201
1582
|
this.mergeData(graph);
|
|
1583
|
+
this.emitUpdate("topology");
|
|
1202
1584
|
const selected = this.selection?.getSelectedIds()[0];
|
|
1203
1585
|
if (selected) {
|
|
1204
1586
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
@@ -1244,24 +1626,71 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
1244
1626
|
}
|
|
1245
1627
|
};
|
|
1246
1628
|
|
|
1629
|
+
// src/graph/projector/graph-lattice-projector.ts
|
|
1630
|
+
import { log as log6 } from "@dxos/log";
|
|
1631
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-lattice-projector.ts";
|
|
1632
|
+
var GraphLatticeProjector = class extends GraphRadialProjector {
|
|
1633
|
+
onUpdate(graph) {
|
|
1634
|
+
log6("onUpdate", {
|
|
1635
|
+
graph: {
|
|
1636
|
+
nodes: graph?.nodes.length,
|
|
1637
|
+
edges: graph?.edges.length
|
|
1638
|
+
}
|
|
1639
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file8, L: 14, S: this });
|
|
1640
|
+
this.mergeData(graph);
|
|
1641
|
+
this.doLatticeLayout();
|
|
1642
|
+
this.emitUpdate("topology");
|
|
1643
|
+
this.animate();
|
|
1644
|
+
}
|
|
1645
|
+
doLatticeLayout() {
|
|
1646
|
+
if (!this.context.size) {
|
|
1647
|
+
return;
|
|
1648
|
+
}
|
|
1649
|
+
const nodes = this.layout.graph.nodes;
|
|
1650
|
+
const count = nodes.length;
|
|
1651
|
+
if (!count) {
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
const sortBy = this.options.sortBy ?? ((n) => n.data?.label ?? n.id);
|
|
1655
|
+
nodes.sort((a, b) => sortBy(a).localeCompare(sortBy(b)));
|
|
1656
|
+
const columns = Math.max(1, Math.ceil(Math.sqrt(count)));
|
|
1657
|
+
const rows = Math.ceil(count / columns);
|
|
1658
|
+
const margin = this.options.margin ?? 16;
|
|
1659
|
+
const { width, height } = this.context.size;
|
|
1660
|
+
const innerW = Math.max(0, width - 2 * margin);
|
|
1661
|
+
const innerH = Math.max(0, height - 2 * margin);
|
|
1662
|
+
const r = this.options.radius ?? 6;
|
|
1663
|
+
const fit = Math.min(innerW / columns, innerH / rows);
|
|
1664
|
+
const cellSize = Math.max(0, Math.min(fit, r * 6));
|
|
1665
|
+
const gridW = cellSize * columns;
|
|
1666
|
+
const gridH = cellSize * rows;
|
|
1667
|
+
const offsetX = -gridW / 2 + cellSize / 2;
|
|
1668
|
+
const offsetY = -gridH / 2 + cellSize / 2;
|
|
1669
|
+
nodes.forEach((node, i) => {
|
|
1670
|
+
const tx = offsetX + i % columns * cellSize;
|
|
1671
|
+
const ty = offsetY + Math.floor(i / columns) * cellSize;
|
|
1672
|
+
updateNode(node, [
|
|
1673
|
+
tx,
|
|
1674
|
+
ty
|
|
1675
|
+
], r);
|
|
1676
|
+
});
|
|
1677
|
+
}
|
|
1678
|
+
};
|
|
1679
|
+
|
|
1247
1680
|
// src/graph/projector/graph-relational-projector.ts
|
|
1248
|
-
import { log as
|
|
1249
|
-
var
|
|
1681
|
+
import { log as log7 } from "@dxos/log";
|
|
1682
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
1250
1683
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
1251
1684
|
onUpdate(graph) {
|
|
1252
|
-
|
|
1685
|
+
log7("onUpdate", {
|
|
1253
1686
|
graph: {
|
|
1254
1687
|
nodes: graph?.nodes.length,
|
|
1255
1688
|
edges: graph?.edges.length
|
|
1256
1689
|
},
|
|
1257
1690
|
selection: this.selection?.getSelectedIds()
|
|
1258
|
-
}, {
|
|
1259
|
-
F: __dxlog_file6,
|
|
1260
|
-
L: 24,
|
|
1261
|
-
S: this,
|
|
1262
|
-
C: (f, a) => f(...a)
|
|
1263
|
-
});
|
|
1691
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 8, S: this });
|
|
1264
1692
|
this.mergeData(graph);
|
|
1693
|
+
this.emitUpdate("topology");
|
|
1265
1694
|
const selected = this.selection?.getSelectedIds()[0];
|
|
1266
1695
|
if (selected) {
|
|
1267
1696
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
@@ -1336,7 +1765,7 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
1336
1765
|
// src/graph/renderer/graph-renderer.ts
|
|
1337
1766
|
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
1338
1767
|
import * as Clipper from "js-clipper";
|
|
1339
|
-
import { log as
|
|
1768
|
+
import { log as log8 } from "@dxos/log";
|
|
1340
1769
|
|
|
1341
1770
|
// src/graph/renderer/bullets.ts
|
|
1342
1771
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
@@ -1369,8 +1798,6 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
1369
1798
|
};
|
|
1370
1799
|
|
|
1371
1800
|
// 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
1801
|
var Renderer = class {
|
|
1375
1802
|
_context;
|
|
1376
1803
|
_root;
|
|
@@ -1385,34 +1812,48 @@ var Renderer = class {
|
|
|
1385
1812
|
get context() {
|
|
1386
1813
|
return this._context;
|
|
1387
1814
|
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Returns the SVG group root if mounted.
|
|
1817
|
+
* The ref may be null between mount/unmount cycles or before the SVG container has sized.
|
|
1818
|
+
* Callers should treat null as "skip this render" rather than as an error.
|
|
1819
|
+
*/
|
|
1388
1820
|
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
1821
|
return this._root.current;
|
|
1399
1822
|
}
|
|
1400
1823
|
get options() {
|
|
1401
1824
|
return this._options;
|
|
1402
1825
|
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Fast path invoked when only positions changed.
|
|
1828
|
+
* Default falls back to a full `render`; subclasses can override to skip
|
|
1829
|
+
* enter/exit joins and attribute callbacks for per-tick updates.
|
|
1830
|
+
*/
|
|
1831
|
+
applyPositions(layout) {
|
|
1832
|
+
this.render(layout);
|
|
1833
|
+
}
|
|
1403
1834
|
};
|
|
1404
1835
|
|
|
1405
1836
|
// src/graph/renderer/graph-renderer.ts
|
|
1406
|
-
var
|
|
1837
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
1407
1838
|
var createLine2 = line2();
|
|
1839
|
+
var EDGE_FADE_MS = 300;
|
|
1840
|
+
var NODE_HIDE_MS = 500;
|
|
1408
1841
|
var GraphRenderer = class extends Renderer {
|
|
1842
|
+
// First render of this instance — used to clear DOM left behind by a previous
|
|
1843
|
+
// renderer pointing at the same `<g>` (e.g. when the consumer swaps projectors
|
|
1844
|
+
// and a new renderer is constructed for the same SVG root). Without this, the
|
|
1845
|
+
// previous variant's node shapes (e.g. circles) would persist as d3.join sees
|
|
1846
|
+
// them in the `update` set instead of `enter`.
|
|
1847
|
+
#firstRender = true;
|
|
1409
1848
|
render(layout) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1849
|
+
if (!this.root) {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
if (this.#firstRender) {
|
|
1853
|
+
this.#firstRender = false;
|
|
1854
|
+
this.root.replaceChildren();
|
|
1855
|
+
}
|
|
1856
|
+
log8("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 35, S: this });
|
|
1416
1857
|
const root = select4(this.root);
|
|
1417
1858
|
if (layout.guides) {
|
|
1418
1859
|
root.selectAll("g.dx-guides").data([
|
|
@@ -1476,31 +1917,82 @@ var GraphRenderer = class extends Renderer {
|
|
|
1476
1917
|
id: "nodes"
|
|
1477
1918
|
}
|
|
1478
1919
|
], (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
|
|
1920
|
+
nodeGroup.selectAll("g.dx-node").data(layout.graph?.nodes ?? [], (d) => d.id).join((enter) => enter.append("g").attr("data-id", (d) => d.id).attr("opacity", (d) => d.hidden ? 0 : 1).classed("dx-node", true).call(createNode, this.options), (update) => update, (exit) => {
|
|
1480
1921
|
return exit.transition().ease(easeCubicOut).duration(300).attr("opacity", 0).on("end", function(d) {
|
|
1481
1922
|
select4(this).remove();
|
|
1482
1923
|
});
|
|
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
|
-
|
|
1924
|
+
}).call(updateNode2, this.options).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
1925
|
+
edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
|
|
1926
|
+
(enter) => enter.append("g").attr("data-id", (d) => d.id).classed("dx-edge", true).call(createEdge, this.options),
|
|
1927
|
+
(update) => update,
|
|
1928
|
+
// Exit fade: edges removed by a topology change (e.g. variant switch from cluster
|
|
1929
|
+
// back to force replaces hierarchy edges with data edges) ease out rather than pop.
|
|
1930
|
+
(exit) => exit.transition().ease(easeCubicOut).duration(EDGE_FADE_MS).attr("opacity", 0).on("end", function() {
|
|
1931
|
+
select4(this).remove();
|
|
1932
|
+
})
|
|
1933
|
+
).call(updateEdge, this.options, nodeGroup).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
1934
|
+
}
|
|
1935
|
+
/**
|
|
1936
|
+
* Fast positions-only update. Skips enter/exit, attribute callbacks, label sizing,
|
|
1937
|
+
* and the subgraph hull pass; just writes `transform` per node and `d` per edge.
|
|
1938
|
+
* Called per simulation tick / animation frame.
|
|
1939
|
+
*/
|
|
1940
|
+
applyPositions(layout) {
|
|
1941
|
+
if (!this.root) {
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
const root = select4(this.root);
|
|
1945
|
+
root.select("g.dx-nodes").selectAll("g.dx-node").attr("transform", (d) => d.x != null && d.y != null ? `translate(${d.x},${d.y})` : null);
|
|
1946
|
+
root.select("g.dx-edges").selectAll("g.dx-edge").selectAll("path").attr("d", function() {
|
|
1947
|
+
const edge = select4(this.parentElement).datum();
|
|
1948
|
+
if (edge.path) {
|
|
1949
|
+
return edge.path;
|
|
1950
|
+
}
|
|
1951
|
+
const { source, target } = edge;
|
|
1952
|
+
if (!source.initialized || !target.initialized) {
|
|
1953
|
+
return null;
|
|
1954
|
+
}
|
|
1955
|
+
return createLine2(getCircumferencePoints([
|
|
1956
|
+
source.x,
|
|
1957
|
+
source.y
|
|
1958
|
+
], [
|
|
1959
|
+
target.x,
|
|
1960
|
+
target.y
|
|
1961
|
+
], source.r, target.r));
|
|
1962
|
+
});
|
|
1486
1963
|
}
|
|
1487
1964
|
/**
|
|
1488
1965
|
* Trigger path bullets.
|
|
1489
1966
|
* @param node
|
|
1490
1967
|
*/
|
|
1491
1968
|
fireBullet(node) {
|
|
1969
|
+
if (!this.root) {
|
|
1970
|
+
return;
|
|
1971
|
+
}
|
|
1492
1972
|
select4(this.root).selectAll("g.dx-edges").selectAll("path").call(createBullets(this.root, node.id));
|
|
1493
1973
|
}
|
|
1494
1974
|
};
|
|
1975
|
+
var SHAPE_CLASS = "dx-shape";
|
|
1976
|
+
var renderCustomShape = (group, options) => {
|
|
1977
|
+
group.each(function(d) {
|
|
1978
|
+
const g = select4(this);
|
|
1979
|
+
g.selectAll(`.${SHAPE_CLASS}`).remove();
|
|
1980
|
+
const shapeGroup = g.append("g").classed(SHAPE_CLASS, true);
|
|
1981
|
+
options.renderNode(shapeGroup, d);
|
|
1982
|
+
});
|
|
1983
|
+
};
|
|
1495
1984
|
var createNode = (group, options) => {
|
|
1496
|
-
const
|
|
1985
|
+
const useCustom = !!options.renderNode;
|
|
1986
|
+
if (useCustom) {
|
|
1987
|
+
renderCustomShape(group, options);
|
|
1988
|
+
}
|
|
1989
|
+
const hitTarget = useCustom ? group : group.append("circle");
|
|
1497
1990
|
if (options.drag) {
|
|
1498
|
-
|
|
1991
|
+
hitTarget.call(options.drag);
|
|
1499
1992
|
}
|
|
1500
1993
|
if (options.onNodeClick) {
|
|
1501
|
-
group.on("click", (event) => {
|
|
1502
|
-
|
|
1503
|
-
options.onNodeClick(node, event);
|
|
1994
|
+
group.on("click", (event, d) => {
|
|
1995
|
+
options.onNodeClick(d, event);
|
|
1504
1996
|
});
|
|
1505
1997
|
}
|
|
1506
1998
|
if (options.labels && !options.onNodePointerEnter) {
|
|
@@ -1509,24 +2001,28 @@ var createNode = (group, options) => {
|
|
|
1509
2001
|
g.append("rect");
|
|
1510
2002
|
g.append("text").style("dominant-baseline", "middle");
|
|
1511
2003
|
}
|
|
1512
|
-
if (options.onNodePointerEnter) {
|
|
1513
|
-
|
|
1514
|
-
const node = select4(this.parentElement).datum();
|
|
1515
|
-
options.onNodePointerEnter(node, event);
|
|
2004
|
+
if (options.onNodePointerEnter || options.onNodePointerLeave) {
|
|
2005
|
+
hitTarget.on("pointerenter", function(event) {
|
|
2006
|
+
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2007
|
+
options.onNodePointerEnter?.(node, event);
|
|
2008
|
+
});
|
|
2009
|
+
hitTarget.on("pointerleave", function(event) {
|
|
2010
|
+
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2011
|
+
options.onNodePointerLeave?.(node, event);
|
|
1516
2012
|
});
|
|
1517
2013
|
group.attr("data-hover", "handled");
|
|
1518
|
-
} else if (options.highlight !== false) {
|
|
1519
|
-
|
|
2014
|
+
} else if (options.highlight !== false && !useCustom) {
|
|
2015
|
+
hitTarget.on("pointerenter", function() {
|
|
1520
2016
|
select4(this.closest("g.dx-node")).raise();
|
|
1521
2017
|
if (options.labels) {
|
|
1522
|
-
select4(this.parentElement).classed("dx-active", true).classed("dx-highlight", true);
|
|
2018
|
+
select4(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
|
|
1523
2019
|
}
|
|
1524
2020
|
});
|
|
1525
2021
|
group.on("pointerleave", function() {
|
|
1526
2022
|
if (options.labels) {
|
|
1527
|
-
select4(this).classed("dx-active", false);
|
|
2023
|
+
select4(this).classed("dx-node-active", false);
|
|
1528
2024
|
setTimeout(() => {
|
|
1529
|
-
if (!select4(this).classed("dx-active")) {
|
|
2025
|
+
if (!select4(this).classed("dx-node-active")) {
|
|
1530
2026
|
select4(this).classed("dx-highlight", false);
|
|
1531
2027
|
}
|
|
1532
2028
|
}, 300);
|
|
@@ -1538,6 +2034,11 @@ var updateNode2 = (group, options) => {
|
|
|
1538
2034
|
group.attr("transform", (d) => {
|
|
1539
2035
|
return d.x != null && d.y != null ? `translate(${d.x},${d.y})` : void 0;
|
|
1540
2036
|
});
|
|
2037
|
+
group.classed("dx-hidden", (d) => d.hidden ?? false);
|
|
2038
|
+
group.transition("hide").ease(easeCubicOut).duration(NODE_HIDE_MS).attr("opacity", (d) => d.hidden ? 0 : 1);
|
|
2039
|
+
if (options.renderNode) {
|
|
2040
|
+
renderCustomShape(group, options);
|
|
2041
|
+
}
|
|
1541
2042
|
if (options.attributes?.node) {
|
|
1542
2043
|
try {
|
|
1543
2044
|
group.each((d, i, nodes) => {
|
|
@@ -1553,18 +2054,15 @@ var updateNode2 = (group, options) => {
|
|
|
1553
2054
|
}
|
|
1554
2055
|
});
|
|
1555
2056
|
} catch (error) {
|
|
1556
|
-
|
|
2057
|
+
log8.error("updateNode", {
|
|
1557
2058
|
error: error?.message
|
|
1558
|
-
}, {
|
|
1559
|
-
F: __dxlog_file8,
|
|
1560
|
-
L: 305,
|
|
1561
|
-
S: void 0,
|
|
1562
|
-
C: (f, a) => f(...a)
|
|
1563
|
-
});
|
|
2059
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 292, S: void 0 });
|
|
1564
2060
|
}
|
|
1565
2061
|
}
|
|
1566
2062
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1567
|
-
|
|
2063
|
+
if (!options.renderNode) {
|
|
2064
|
+
groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
|
|
2065
|
+
}
|
|
1568
2066
|
if (options.labels) {
|
|
1569
2067
|
const bx = 1;
|
|
1570
2068
|
const px = 4;
|
|
@@ -1609,18 +2107,17 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1609
2107
|
}
|
|
1610
2108
|
});
|
|
1611
2109
|
} catch (error) {
|
|
1612
|
-
|
|
2110
|
+
log8.error("updateEdge", {
|
|
1613
2111
|
error: error?.message
|
|
1614
|
-
}, {
|
|
1615
|
-
F: __dxlog_file8,
|
|
1616
|
-
L: 417,
|
|
1617
|
-
S: void 0,
|
|
1618
|
-
C: (f, a) => f(...a)
|
|
1619
|
-
});
|
|
2112
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 360, S: void 0 });
|
|
1620
2113
|
}
|
|
1621
2114
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1622
2115
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
1623
|
-
const
|
|
2116
|
+
const edge = select4(this.parentElement).datum();
|
|
2117
|
+
if (edge.path) {
|
|
2118
|
+
return edge.path;
|
|
2119
|
+
}
|
|
2120
|
+
const { source, target } = edge;
|
|
1624
2121
|
if (!source.initialized || !target.initialized) {
|
|
1625
2122
|
return;
|
|
1626
2123
|
}
|
|
@@ -2013,7 +2510,7 @@ var useZoom = (options = defaultZoomOptions) => {
|
|
|
2013
2510
|
};
|
|
2014
2511
|
|
|
2015
2512
|
// src/components/Graph/Graph.tsx
|
|
2016
|
-
var
|
|
2513
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
2017
2514
|
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
2018
2515
|
const context = useSvgContext();
|
|
2019
2516
|
const graphRef = useRef3(null);
|
|
@@ -2031,8 +2528,11 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2031
2528
|
arrows: {
|
|
2032
2529
|
end: arrows
|
|
2033
2530
|
},
|
|
2034
|
-
onNodeClick: onSelect
|
|
2035
|
-
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0
|
|
2531
|
+
onNodeClick: onSelect,
|
|
2532
|
+
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0,
|
|
2533
|
+
// Pair pointerenter with leave so consumers can clear hover-driven previews.
|
|
2534
|
+
// The callback receives `null` on leave (event still carries the source).
|
|
2535
|
+
onNodePointerLeave: onInspect ? (_node, event) => onInspect(null, event) : void 0
|
|
2036
2536
|
});
|
|
2037
2537
|
}
|
|
2038
2538
|
return {
|
|
@@ -2043,7 +2543,14 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2043
2543
|
context,
|
|
2044
2544
|
projectorProp,
|
|
2045
2545
|
rendererProp,
|
|
2046
|
-
drag2
|
|
2546
|
+
drag2,
|
|
2547
|
+
arrows,
|
|
2548
|
+
onSelect,
|
|
2549
|
+
onInspect,
|
|
2550
|
+
props.labels,
|
|
2551
|
+
props.subgraphs,
|
|
2552
|
+
props.attributes,
|
|
2553
|
+
props.renderNode
|
|
2047
2554
|
]);
|
|
2048
2555
|
useImperativeHandle(forwardedRef, () => ({
|
|
2049
2556
|
refresh: () => {
|
|
@@ -2061,23 +2568,26 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2061
2568
|
renderer
|
|
2062
2569
|
]);
|
|
2063
2570
|
useEffect3(() => {
|
|
2571
|
+
const cleanup = combine(
|
|
2572
|
+
// Subscribe to model changes if reactive model.
|
|
2573
|
+
model ? model.subscribe(() => {
|
|
2574
|
+
projector.updateData(model?.graph);
|
|
2575
|
+
}) : void 0,
|
|
2576
|
+
projector.updated.on(({ layout, kind }) => {
|
|
2577
|
+
try {
|
|
2578
|
+
if (kind === "positions") {
|
|
2579
|
+
renderer.applyPositions(layout);
|
|
2580
|
+
} else {
|
|
2581
|
+
renderer.render(layout);
|
|
2582
|
+
}
|
|
2583
|
+
} catch (error) {
|
|
2584
|
+
log9.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 85, S: void 0 });
|
|
2585
|
+
void projector.stop();
|
|
2586
|
+
}
|
|
2587
|
+
})
|
|
2588
|
+
);
|
|
2064
2589
|
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: 115,
|
|
2076
|
-
S: void 0,
|
|
2077
|
-
C: (f, a) => f(...a)
|
|
2078
|
-
});
|
|
2079
|
-
}
|
|
2080
|
-
}));
|
|
2590
|
+
return cleanup;
|
|
2081
2591
|
}, [
|
|
2082
2592
|
model,
|
|
2083
2593
|
projector,
|
|
@@ -2105,21 +2615,27 @@ import { feature, mesh } from "topojson-client";
|
|
|
2105
2615
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
2106
2616
|
const { svg, size } = useSvgContext();
|
|
2107
2617
|
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);
|
|
2618
|
+
if (!size) {
|
|
2619
|
+
return;
|
|
2118
2620
|
}
|
|
2621
|
+
const topology = hexTopology(size, radius, value);
|
|
2622
|
+
const projection = hexProjection(radius);
|
|
2623
|
+
const path = geoPath().projection(projection);
|
|
2624
|
+
const root = select7(svg).selectAll("g.dx-mesh-root").data([
|
|
2625
|
+
null
|
|
2626
|
+
]).join("g").classed("dx-mesh-root", true);
|
|
2627
|
+
root.selectAll("*").remove();
|
|
2628
|
+
root.append("g").attr("class", "hexagon").selectAll("path").data(topology.objects.hexagons.geometries).enter().append("path").attr("d", (d) => path(feature(topology, d))).attr("class", (d) => d.properties?.fill ? "fill" : null);
|
|
2629
|
+
root.append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
2630
|
+
const redraw = (border) => {
|
|
2631
|
+
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
2632
|
+
};
|
|
2633
|
+
root.append("path").attr("class", "border").call(redraw);
|
|
2119
2634
|
}, [
|
|
2120
2635
|
svg,
|
|
2121
2636
|
size,
|
|
2122
|
-
value
|
|
2637
|
+
value,
|
|
2638
|
+
radius
|
|
2123
2639
|
]);
|
|
2124
2640
|
return null;
|
|
2125
2641
|
};
|
|
@@ -2261,13 +2777,40 @@ var Markers = ({ arrowSize, className }) => {
|
|
|
2261
2777
|
|
|
2262
2778
|
// src/components/SVG/Root.tsx
|
|
2263
2779
|
import { select as select9 } from "d3";
|
|
2264
|
-
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
|
|
2265
|
-
import {
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
const
|
|
2269
|
-
|
|
2780
|
+
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4, useState } from "react";
|
|
2781
|
+
import { composableProps, mx as mx3 } from "@dxos/ui-theme";
|
|
2782
|
+
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
2783
|
+
const [container, setContainer] = useState(null);
|
|
2784
|
+
const [size, setSize] = useState({
|
|
2785
|
+
width: 0,
|
|
2786
|
+
height: 0
|
|
2270
2787
|
});
|
|
2788
|
+
useEffect6(() => {
|
|
2789
|
+
if (!container) {
|
|
2790
|
+
return;
|
|
2791
|
+
}
|
|
2792
|
+
const rect = container.getBoundingClientRect();
|
|
2793
|
+
setSize({
|
|
2794
|
+
width: rect.width,
|
|
2795
|
+
height: rect.height
|
|
2796
|
+
});
|
|
2797
|
+
const observer = new ResizeObserver((entries) => {
|
|
2798
|
+
const entry = entries[0];
|
|
2799
|
+
if (!entry) {
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
const { width: width2, height: height2 } = entry.contentRect;
|
|
2803
|
+
setSize((prev) => prev.width === width2 && prev.height === height2 ? prev : {
|
|
2804
|
+
width: width2,
|
|
2805
|
+
height: height2
|
|
2806
|
+
});
|
|
2807
|
+
});
|
|
2808
|
+
observer.observe(container);
|
|
2809
|
+
return () => observer.disconnect();
|
|
2810
|
+
}, [
|
|
2811
|
+
container
|
|
2812
|
+
]);
|
|
2813
|
+
const { width, height } = size;
|
|
2271
2814
|
const context = useMemo4(() => {
|
|
2272
2815
|
return new SVGContext({
|
|
2273
2816
|
scale,
|
|
@@ -2297,9 +2840,10 @@ var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, scale, centered,
|
|
|
2297
2840
|
return /* @__PURE__ */ React4.createElement(SVGContextProvider, {
|
|
2298
2841
|
value: context
|
|
2299
2842
|
}, /* @__PURE__ */ React4.createElement("div", {
|
|
2300
|
-
...props,
|
|
2301
|
-
|
|
2302
|
-
|
|
2843
|
+
...composableProps(props, {
|
|
2844
|
+
classNames: "dx-expander"
|
|
2845
|
+
}),
|
|
2846
|
+
ref: setContainer
|
|
2303
2847
|
}, /* @__PURE__ */ React4.createElement("svg", {
|
|
2304
2848
|
xmlns: "http://www.w3.org/2000/svg",
|
|
2305
2849
|
ref: context.ref,
|
|
@@ -2357,11 +2901,17 @@ var startAnimation = (pulsar, r, options = {}) => {
|
|
|
2357
2901
|
};
|
|
2358
2902
|
var Pulsar;
|
|
2359
2903
|
export {
|
|
2904
|
+
CLUSTER_NODE_TYPE_GROUP,
|
|
2905
|
+
CLUSTER_NODE_TYPE_LEAF,
|
|
2906
|
+
CLUSTER_NODE_TYPE_ROOT,
|
|
2360
2907
|
EventEmitter,
|
|
2361
2908
|
FractionUtil,
|
|
2362
2909
|
Graph,
|
|
2910
|
+
GraphBundleProjector,
|
|
2911
|
+
GraphClusterProjector,
|
|
2363
2912
|
GraphForceProjector,
|
|
2364
2913
|
GraphHierarchicalProjector,
|
|
2914
|
+
GraphLatticeProjector,
|
|
2365
2915
|
GraphProjector,
|
|
2366
2916
|
GraphRadialProjector,
|
|
2367
2917
|
GraphRelationalProjector,
|