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