@dxos/react-ui-graph 0.8.4-main.cb12b3f963 → 0.8.4-main.d05539e30a
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/index.mjs +903 -285
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +903 -285
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Graph/Graph.d.ts +6 -2
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +3 -3
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +4 -0
- package/dist/types/src/components/SVG/Root.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-force-projector.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/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/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -18
- package/src/components/Graph/Graph.stories.tsx +5 -5
- package/src/components/Graph/Graph.tsx +48 -21
- package/src/components/Mesh/Mesh.stories.tsx +6 -4
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/Root.tsx +28 -3
- 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-force-projector.ts +5 -1
- package/src/graph/projector/graph-hierarchical-projector.ts +1 -0
- package/src/graph/projector/graph-lattice-projector.ts +86 -0
- package/src/graph/projector/graph-projector.ts +7 -0
- package/src/graph/projector/graph-radial-projector.ts +30 -2
- package/src/graph/projector/graph-relational-projector.ts +1 -0
- package/src/graph/projector/index.ts +3 -0
- package/src/graph/projector/projector.ts +12 -3
- package/src/graph/renderer/graph-renderer.ts +172 -32
- package/src/graph/renderer/renderer.ts +15 -4
- package/src/graph/types.ts +14 -0
- package/src/stories/hooks.stories.tsx +6 -1
- package/styles/graph.css +51 -2
|
@@ -8,7 +8,7 @@ import {
|
|
|
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,85 +62,13 @@ 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";
|
|
@@ -741,9 +669,10 @@ var Projector = class {
|
|
|
741
669
|
updateData(data) {
|
|
742
670
|
this.onUpdate(data);
|
|
743
671
|
}
|
|
744
|
-
emitUpdate() {
|
|
672
|
+
emitUpdate(kind = "topology") {
|
|
745
673
|
this.updated.emit({
|
|
746
|
-
layout: this.layout
|
|
674
|
+
layout: this.layout,
|
|
675
|
+
kind
|
|
747
676
|
});
|
|
748
677
|
}
|
|
749
678
|
async clear() {
|
|
@@ -812,30 +741,629 @@ var GraphProjector = class extends Projector {
|
|
|
812
741
|
id: this.options.idAccessor(node)
|
|
813
742
|
};
|
|
814
743
|
}
|
|
815
|
-
current.data = node;
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
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
|
+
}
|
|
828
1338
|
}
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
this.
|
|
833
|
-
|
|
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
|
+
});
|
|
834
1362
|
};
|
|
835
1363
|
|
|
836
1364
|
// src/graph/projector/graph-force-projector.ts
|
|
837
1365
|
import { forceCenter, forceCollide, forceLink, forceManyBody, forceRadial, forceSimulation, forceX as forceX2, forceY as forceY2 } from "d3";
|
|
838
|
-
import { log } from "@dxos/log";
|
|
1366
|
+
import { log as log4 } from "@dxos/log";
|
|
839
1367
|
|
|
840
1368
|
// src/graph/projector/graph-forces.ts
|
|
841
1369
|
import { forceX, forceY } from "d3";
|
|
@@ -854,7 +1382,7 @@ var forcePoint = ({ x, y, strength = 0.01 }) => {
|
|
|
854
1382
|
};
|
|
855
1383
|
|
|
856
1384
|
// src/graph/projector/graph-force-projector.ts
|
|
857
|
-
var
|
|
1385
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-force-projector.ts";
|
|
858
1386
|
var getValue = (valueOrFunction, invoker, defaultValue) => {
|
|
859
1387
|
return (typeof valueOrFunction === "function" ? invoker(valueOrFunction) : valueOrFunction) ?? defaultValue;
|
|
860
1388
|
};
|
|
@@ -904,7 +1432,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
904
1432
|
} else {
|
|
905
1433
|
this.updateForces(this.forces);
|
|
906
1434
|
}
|
|
907
|
-
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();
|
|
908
1436
|
}
|
|
909
1437
|
async onStop() {
|
|
910
1438
|
clearTimeout(this._timeout);
|
|
@@ -921,16 +1449,17 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
921
1449
|
this.restart();
|
|
922
1450
|
}
|
|
923
1451
|
onUpdate(graph) {
|
|
924
|
-
|
|
1452
|
+
log4("onUpdate", {
|
|
925
1453
|
graph: {
|
|
926
1454
|
nodes: graph?.nodes.length,
|
|
927
1455
|
edges: graph?.edges.length
|
|
928
1456
|
}
|
|
929
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1457
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 90, S: this });
|
|
930
1458
|
this._simulation.stop();
|
|
931
1459
|
this.mergeData(graph);
|
|
932
1460
|
this.updateLayout();
|
|
933
1461
|
this.updateForces(this.forces);
|
|
1462
|
+
this.emitUpdate("topology");
|
|
934
1463
|
this.restart();
|
|
935
1464
|
}
|
|
936
1465
|
updateLayout() {
|
|
@@ -974,9 +1503,9 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
974
1503
|
* Update all forces.
|
|
975
1504
|
*/
|
|
976
1505
|
updateForces(forces) {
|
|
977
|
-
|
|
1506
|
+
log4("updateForces", {
|
|
978
1507
|
forces
|
|
979
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1508
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 152, S: this });
|
|
980
1509
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
981
1510
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
982
1511
|
if (config.distance != null) {
|
|
@@ -1040,130 +1569,19 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
1040
1569
|
};
|
|
1041
1570
|
|
|
1042
1571
|
// src/graph/projector/graph-hierarchical-projector.ts
|
|
1043
|
-
import { log as
|
|
1044
|
-
|
|
1045
|
-
// src/graph/projector/graph-radial-projector.ts
|
|
1046
|
-
import { easeCubic, timer } from "d3";
|
|
1047
|
-
import { log as log2 } from "@dxos/log";
|
|
1048
|
-
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-radial-projector.ts";
|
|
1049
|
-
var GraphRadialProjector = class extends GraphProjector {
|
|
1050
|
-
_timer;
|
|
1051
|
-
findNode(x, y, radius) {
|
|
1052
|
-
return void 0;
|
|
1053
|
-
}
|
|
1054
|
-
onUpdate(graph) {
|
|
1055
|
-
log2("onUpdate", {
|
|
1056
|
-
graph: {
|
|
1057
|
-
nodes: graph?.nodes.length,
|
|
1058
|
-
edges: graph?.edges.length
|
|
1059
|
-
}
|
|
1060
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 13, S: this });
|
|
1061
|
-
this.mergeData(graph);
|
|
1062
|
-
this.doRadialLayout();
|
|
1063
|
-
}
|
|
1064
|
-
animate() {
|
|
1065
|
-
const start = Date.now();
|
|
1066
|
-
if (this.options.duration) {
|
|
1067
|
-
this._timer = timer(() => {
|
|
1068
|
-
const t = Math.min(1, (Date.now() - start) / this.options.duration);
|
|
1069
|
-
const d = easeCubic(t);
|
|
1070
|
-
this.layout.graph.nodes.forEach((node) => {
|
|
1071
|
-
node.x = node.sx + (node.tx - node.sx) * d;
|
|
1072
|
-
node.y = node.sy + (node.ty - node.sy) * d;
|
|
1073
|
-
node.r = node.sr + (node.tr - node.sr) * d;
|
|
1074
|
-
});
|
|
1075
|
-
this.emitUpdate();
|
|
1076
|
-
if (t >= 1) {
|
|
1077
|
-
this._timer.stop();
|
|
1078
|
-
this._timer = void 0;
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1081
|
-
} else {
|
|
1082
|
-
this.emitUpdate();
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
async onStop() {
|
|
1086
|
-
this._timer?.stop();
|
|
1087
|
-
this._timer = void 0;
|
|
1088
|
-
}
|
|
1089
|
-
doRadialLayout() {
|
|
1090
|
-
if (!this.context.size) {
|
|
1091
|
-
return;
|
|
1092
|
-
}
|
|
1093
|
-
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);
|
|
1094
|
-
this.layout.graph.nodes.forEach((node, i) => {
|
|
1095
|
-
const [tx, ty] = radial(i);
|
|
1096
|
-
updateNode(node, [
|
|
1097
|
-
tx,
|
|
1098
|
-
ty
|
|
1099
|
-
]);
|
|
1100
|
-
});
|
|
1101
|
-
this.animate();
|
|
1102
|
-
}
|
|
1103
|
-
};
|
|
1104
|
-
var updateNode = (node, [tx, ty], tr = 8) => {
|
|
1105
|
-
const sx = node.x ?? tx;
|
|
1106
|
-
const sy = node.y ?? ty;
|
|
1107
|
-
const sr = node.r ?? tr;
|
|
1108
|
-
Object.assign(node, {
|
|
1109
|
-
initialized: true,
|
|
1110
|
-
// Start.
|
|
1111
|
-
sx,
|
|
1112
|
-
sy,
|
|
1113
|
-
sr,
|
|
1114
|
-
// Target.
|
|
1115
|
-
tx,
|
|
1116
|
-
ty,
|
|
1117
|
-
tr,
|
|
1118
|
-
// Current.
|
|
1119
|
-
x: sx,
|
|
1120
|
-
y: sy,
|
|
1121
|
-
r: sr
|
|
1122
|
-
});
|
|
1123
|
-
};
|
|
1124
|
-
var layoutRadial = (x, y, r, n, start = -Math.PI / 2) => {
|
|
1125
|
-
const da = 2 * Math.PI / n;
|
|
1126
|
-
return (i) => {
|
|
1127
|
-
const a = start + i * da;
|
|
1128
|
-
return [
|
|
1129
|
-
x + Math.cos(a) * r,
|
|
1130
|
-
y + Math.sin(a) * r
|
|
1131
|
-
];
|
|
1132
|
-
};
|
|
1133
|
-
};
|
|
1134
|
-
var layoutHorizontal = (x, y, w, n) => {
|
|
1135
|
-
const dx = n > 1 ? w / (n - 1) : 0;
|
|
1136
|
-
const sx = x - (n - 1) * dx / 2;
|
|
1137
|
-
return (i) => {
|
|
1138
|
-
return [
|
|
1139
|
-
sx + i * dx,
|
|
1140
|
-
y
|
|
1141
|
-
];
|
|
1142
|
-
};
|
|
1143
|
-
};
|
|
1144
|
-
var layoutVertical = (x, y, h, n) => {
|
|
1145
|
-
const dy = n > 1 ? h / (n - 1) : 0;
|
|
1146
|
-
const sy = y - (n - 1) * dy / 2;
|
|
1147
|
-
return (i) => {
|
|
1148
|
-
return [
|
|
1149
|
-
x,
|
|
1150
|
-
sy + i * dy
|
|
1151
|
-
];
|
|
1152
|
-
};
|
|
1153
|
-
};
|
|
1154
|
-
|
|
1155
|
-
// src/graph/projector/graph-hierarchical-projector.ts
|
|
1156
|
-
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";
|
|
1157
1574
|
var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
1158
1575
|
onUpdate(graph) {
|
|
1159
|
-
|
|
1576
|
+
log5("onUpdate", {
|
|
1160
1577
|
graph: {
|
|
1161
1578
|
nodes: graph?.nodes.length,
|
|
1162
1579
|
edges: graph?.edges.length
|
|
1163
1580
|
},
|
|
1164
1581
|
selection: this.selection?.getSelectedIds()
|
|
1165
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1582
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 8, S: this });
|
|
1166
1583
|
this.mergeData(graph);
|
|
1584
|
+
this.emitUpdate("topology");
|
|
1167
1585
|
const selected = this.selection?.getSelectedIds()[0];
|
|
1168
1586
|
if (selected) {
|
|
1169
1587
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
@@ -1209,19 +1627,71 @@ var GraphHierarchicalProjector = class extends GraphRadialProjector {
|
|
|
1209
1627
|
}
|
|
1210
1628
|
};
|
|
1211
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
|
+
|
|
1212
1681
|
// src/graph/projector/graph-relational-projector.ts
|
|
1213
|
-
import { log as
|
|
1214
|
-
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";
|
|
1215
1684
|
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
1216
1685
|
onUpdate(graph) {
|
|
1217
|
-
|
|
1686
|
+
log7("onUpdate", {
|
|
1218
1687
|
graph: {
|
|
1219
1688
|
nodes: graph?.nodes.length,
|
|
1220
1689
|
edges: graph?.edges.length
|
|
1221
1690
|
},
|
|
1222
1691
|
selection: this.selection?.getSelectedIds()
|
|
1223
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1692
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 8, S: this });
|
|
1224
1693
|
this.mergeData(graph);
|
|
1694
|
+
this.emitUpdate("topology");
|
|
1225
1695
|
const selected = this.selection?.getSelectedIds()[0];
|
|
1226
1696
|
if (selected) {
|
|
1227
1697
|
const node = this.layout.graph.nodes.find((node2) => node2.id === selected);
|
|
@@ -1296,7 +1766,7 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
1296
1766
|
// src/graph/renderer/graph-renderer.ts
|
|
1297
1767
|
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
1298
1768
|
import * as Clipper from "js-clipper";
|
|
1299
|
-
import { log as
|
|
1769
|
+
import { log as log8 } from "@dxos/log";
|
|
1300
1770
|
|
|
1301
1771
|
// src/graph/renderer/bullets.ts
|
|
1302
1772
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
@@ -1329,8 +1799,6 @@ var createBullets = (group, nodeId, options = {}) => {
|
|
|
1329
1799
|
};
|
|
1330
1800
|
|
|
1331
1801
|
// src/graph/renderer/renderer.ts
|
|
1332
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1333
|
-
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/renderer.ts";
|
|
1334
1802
|
var Renderer = class {
|
|
1335
1803
|
_context;
|
|
1336
1804
|
_root;
|
|
@@ -1345,21 +1813,48 @@ var Renderer = class {
|
|
|
1345
1813
|
get context() {
|
|
1346
1814
|
return this._context;
|
|
1347
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
|
+
*/
|
|
1348
1821
|
get root() {
|
|
1349
|
-
invariant3(this._root.current, "SVG root is not initialized", { "~LogMeta": "~LogMeta", F: __dxlog_file7, L: 23, S: this, A: ["this._root.current", "'SVG root is not initialized'"] });
|
|
1350
1822
|
return this._root.current;
|
|
1351
1823
|
}
|
|
1352
1824
|
get options() {
|
|
1353
1825
|
return this._options;
|
|
1354
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
|
+
}
|
|
1355
1835
|
};
|
|
1356
1836
|
|
|
1357
1837
|
// src/graph/renderer/graph-renderer.ts
|
|
1358
|
-
var
|
|
1838
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
1359
1839
|
var createLine2 = line2();
|
|
1840
|
+
var EDGE_FADE_MS = 300;
|
|
1841
|
+
var NODE_HIDE_MS = 500;
|
|
1360
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;
|
|
1361
1849
|
render(layout) {
|
|
1362
|
-
|
|
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 });
|
|
1363
1858
|
const root = select4(this.root);
|
|
1364
1859
|
if (layout.guides) {
|
|
1365
1860
|
root.selectAll("g.dx-guides").data([
|
|
@@ -1423,31 +1918,82 @@ var GraphRenderer = class extends Renderer {
|
|
|
1423
1918
|
id: "nodes"
|
|
1424
1919
|
}
|
|
1425
1920
|
], (d) => d.id).join("g").classed("dx-nodes", true);
|
|
1426
|
-
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) => {
|
|
1427
1922
|
return exit.transition().ease(easeCubicOut).duration(300).attr("opacity", 0).on("end", function(d) {
|
|
1428
1923
|
select4(this).remove();
|
|
1429
1924
|
});
|
|
1430
|
-
}).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
1431
|
-
edgeGroup.selectAll("g.dx-edge").data(layout.graph?.edges ?? [], (d) => d.id).join(
|
|
1432
|
-
|
|
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
|
+
});
|
|
1433
1964
|
}
|
|
1434
1965
|
/**
|
|
1435
1966
|
* Trigger path bullets.
|
|
1436
1967
|
* @param node
|
|
1437
1968
|
*/
|
|
1438
1969
|
fireBullet(node) {
|
|
1970
|
+
if (!this.root) {
|
|
1971
|
+
return;
|
|
1972
|
+
}
|
|
1439
1973
|
select4(this.root).selectAll("g.dx-edges").selectAll("path").call(createBullets(this.root, node.id));
|
|
1440
1974
|
}
|
|
1441
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
|
+
};
|
|
1442
1985
|
var createNode = (group, options) => {
|
|
1443
|
-
const
|
|
1986
|
+
const useCustom = !!options.renderNode;
|
|
1987
|
+
if (useCustom) {
|
|
1988
|
+
renderCustomShape(group, options);
|
|
1989
|
+
}
|
|
1990
|
+
const hitTarget = useCustom ? group : group.append("circle");
|
|
1444
1991
|
if (options.drag) {
|
|
1445
|
-
|
|
1992
|
+
hitTarget.call(options.drag);
|
|
1446
1993
|
}
|
|
1447
1994
|
if (options.onNodeClick) {
|
|
1448
|
-
group.on("click", (event) => {
|
|
1449
|
-
|
|
1450
|
-
options.onNodeClick(node, event);
|
|
1995
|
+
group.on("click", (event, d) => {
|
|
1996
|
+
options.onNodeClick(d, event);
|
|
1451
1997
|
});
|
|
1452
1998
|
}
|
|
1453
1999
|
if (options.labels && !options.onNodePointerEnter) {
|
|
@@ -1456,14 +2002,18 @@ var createNode = (group, options) => {
|
|
|
1456
2002
|
g.append("rect");
|
|
1457
2003
|
g.append("text").style("dominant-baseline", "middle");
|
|
1458
2004
|
}
|
|
1459
|
-
if (options.onNodePointerEnter) {
|
|
1460
|
-
|
|
1461
|
-
const node = select4(this.parentElement).datum();
|
|
1462
|
-
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);
|
|
1463
2013
|
});
|
|
1464
2014
|
group.attr("data-hover", "handled");
|
|
1465
|
-
} else if (options.highlight !== false) {
|
|
1466
|
-
|
|
2015
|
+
} else if (options.highlight !== false && !useCustom) {
|
|
2016
|
+
hitTarget.on("pointerenter", function() {
|
|
1467
2017
|
select4(this.closest("g.dx-node")).raise();
|
|
1468
2018
|
if (options.labels) {
|
|
1469
2019
|
select4(this.parentElement).classed("dx-node-active", true).classed("dx-highlight", true);
|
|
@@ -1485,6 +2035,11 @@ var updateNode2 = (group, options) => {
|
|
|
1485
2035
|
group.attr("transform", (d) => {
|
|
1486
2036
|
return d.x != null && d.y != null ? `translate(${d.x},${d.y})` : void 0;
|
|
1487
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
|
+
}
|
|
1488
2043
|
if (options.attributes?.node) {
|
|
1489
2044
|
try {
|
|
1490
2045
|
group.each((d, i, nodes) => {
|
|
@@ -1500,13 +2055,15 @@ var updateNode2 = (group, options) => {
|
|
|
1500
2055
|
}
|
|
1501
2056
|
});
|
|
1502
2057
|
} catch (error) {
|
|
1503
|
-
|
|
2058
|
+
log8.error("updateNode", {
|
|
1504
2059
|
error: error?.message
|
|
1505
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
2060
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 292, S: void 0 });
|
|
1506
2061
|
}
|
|
1507
2062
|
}
|
|
1508
2063
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1509
|
-
|
|
2064
|
+
if (!options.renderNode) {
|
|
2065
|
+
groupOrTransition.select("circle").attr("r", (d) => d.r ?? 16);
|
|
2066
|
+
}
|
|
1510
2067
|
if (options.labels) {
|
|
1511
2068
|
const bx = 1;
|
|
1512
2069
|
const px = 4;
|
|
@@ -1551,13 +2108,17 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
1551
2108
|
}
|
|
1552
2109
|
});
|
|
1553
2110
|
} catch (error) {
|
|
1554
|
-
|
|
2111
|
+
log8.error("updateEdge", {
|
|
1555
2112
|
error: error?.message
|
|
1556
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
2113
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 360, S: void 0 });
|
|
1557
2114
|
}
|
|
1558
2115
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
1559
2116
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
1560
|
-
const
|
|
2117
|
+
const edge = select4(this.parentElement).datum();
|
|
2118
|
+
if (edge.path) {
|
|
2119
|
+
return edge.path;
|
|
2120
|
+
}
|
|
2121
|
+
const { source, target } = edge;
|
|
1561
2122
|
if (!source.initialized || !target.initialized) {
|
|
1562
2123
|
return;
|
|
1563
2124
|
}
|
|
@@ -1950,7 +2511,7 @@ var useZoom = (options = defaultZoomOptions) => {
|
|
|
1950
2511
|
};
|
|
1951
2512
|
|
|
1952
2513
|
// src/components/Graph/Graph.tsx
|
|
1953
|
-
var
|
|
2514
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
1954
2515
|
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
1955
2516
|
const context = useSvgContext();
|
|
1956
2517
|
const graphRef = useRef3(null);
|
|
@@ -1968,8 +2529,11 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
1968
2529
|
arrows: {
|
|
1969
2530
|
end: arrows
|
|
1970
2531
|
},
|
|
1971
|
-
onNodeClick: onSelect
|
|
1972
|
-
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
|
|
1973
2537
|
});
|
|
1974
2538
|
}
|
|
1975
2539
|
return {
|
|
@@ -1980,7 +2544,14 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
1980
2544
|
context,
|
|
1981
2545
|
projectorProp,
|
|
1982
2546
|
rendererProp,
|
|
1983
|
-
drag2
|
|
2547
|
+
drag2,
|
|
2548
|
+
arrows,
|
|
2549
|
+
onSelect,
|
|
2550
|
+
onInspect,
|
|
2551
|
+
props.labels,
|
|
2552
|
+
props.subgraphs,
|
|
2553
|
+
props.attributes,
|
|
2554
|
+
props.renderNode
|
|
1984
2555
|
]);
|
|
1985
2556
|
useImperativeHandle(forwardedRef, () => ({
|
|
1986
2557
|
refresh: () => {
|
|
@@ -1998,18 +2569,26 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
1998
2569
|
renderer
|
|
1999
2570
|
]);
|
|
2000
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
|
+
);
|
|
2001
2590
|
projector.updateData(model?.graph);
|
|
2002
|
-
|
|
2003
|
-
projector.updateData(model?.graph);
|
|
2004
|
-
}) : void 0;
|
|
2005
|
-
return combine(unsubscribeModel, projector.updated.on(({ layout }) => {
|
|
2006
|
-
try {
|
|
2007
|
-
renderer.render(layout);
|
|
2008
|
-
} catch (error) {
|
|
2009
|
-
void projector.stop();
|
|
2010
|
-
log6.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 71, S: void 0 });
|
|
2011
|
-
}
|
|
2012
|
-
}));
|
|
2591
|
+
return cleanup;
|
|
2013
2592
|
}, [
|
|
2014
2593
|
model,
|
|
2015
2594
|
projector,
|
|
@@ -2037,21 +2616,27 @@ import { feature, mesh } from "topojson-client";
|
|
|
2037
2616
|
var Mesh = ({ radius = 16, value = 0.5 }) => {
|
|
2038
2617
|
const { svg, size } = useSvgContext();
|
|
2039
2618
|
useEffect4(() => {
|
|
2040
|
-
if (size) {
|
|
2041
|
-
|
|
2042
|
-
const projection = hexProjection(radius);
|
|
2043
|
-
const path = geoPath().projection(projection);
|
|
2044
|
-
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);
|
|
2045
|
-
select7(svg).append("path").datum(mesh(topology, topology.objects.hexagons)).attr("class", "mesh").attr("d", path);
|
|
2046
|
-
const redraw = (border) => {
|
|
2047
|
-
border.attr("d", path(mesh(topology, topology.objects.hexagons, (a, b) => a.properties.fill !== b.properties.fill)));
|
|
2048
|
-
};
|
|
2049
|
-
select7(svg).append("path").attr("class", "border").call(redraw);
|
|
2619
|
+
if (!size) {
|
|
2620
|
+
return;
|
|
2050
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);
|
|
2051
2635
|
}, [
|
|
2052
2636
|
svg,
|
|
2053
2637
|
size,
|
|
2054
|
-
value
|
|
2638
|
+
value,
|
|
2639
|
+
radius
|
|
2055
2640
|
]);
|
|
2056
2641
|
return null;
|
|
2057
2642
|
};
|
|
@@ -2193,13 +2778,40 @@ var Markers = ({ arrowSize, className }) => {
|
|
|
2193
2778
|
|
|
2194
2779
|
// src/components/SVG/Root.tsx
|
|
2195
2780
|
import { select as select9 } from "d3";
|
|
2196
|
-
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4 } from "react";
|
|
2197
|
-
import { useResizeDetector } from "react-resize-detector";
|
|
2781
|
+
import React4, { forwardRef as forwardRef2, useEffect as useEffect6, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4, useState } from "react";
|
|
2198
2782
|
import { composableProps, mx as mx3 } from "@dxos/ui-theme";
|
|
2199
2783
|
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
2200
|
-
const
|
|
2201
|
-
|
|
2784
|
+
const [container, setContainer] = useState(null);
|
|
2785
|
+
const [size, setSize] = useState({
|
|
2786
|
+
width: 0,
|
|
2787
|
+
height: 0
|
|
2202
2788
|
});
|
|
2789
|
+
useEffect6(() => {
|
|
2790
|
+
if (!container) {
|
|
2791
|
+
return;
|
|
2792
|
+
}
|
|
2793
|
+
const rect = container.getBoundingClientRect();
|
|
2794
|
+
setSize({
|
|
2795
|
+
width: rect.width,
|
|
2796
|
+
height: rect.height
|
|
2797
|
+
});
|
|
2798
|
+
const observer = new ResizeObserver((entries) => {
|
|
2799
|
+
const entry = entries[0];
|
|
2800
|
+
if (!entry) {
|
|
2801
|
+
return;
|
|
2802
|
+
}
|
|
2803
|
+
const { width: width2, height: height2 } = entry.contentRect;
|
|
2804
|
+
setSize((prev) => prev.width === width2 && prev.height === height2 ? prev : {
|
|
2805
|
+
width: width2,
|
|
2806
|
+
height: height2
|
|
2807
|
+
});
|
|
2808
|
+
});
|
|
2809
|
+
observer.observe(container);
|
|
2810
|
+
return () => observer.disconnect();
|
|
2811
|
+
}, [
|
|
2812
|
+
container
|
|
2813
|
+
]);
|
|
2814
|
+
const { width, height } = size;
|
|
2203
2815
|
const context = useMemo4(() => {
|
|
2204
2816
|
return new SVGContext({
|
|
2205
2817
|
scale,
|
|
@@ -2232,7 +2844,7 @@ var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props },
|
|
|
2232
2844
|
...composableProps(props, {
|
|
2233
2845
|
classNames: "dx-expander"
|
|
2234
2846
|
}),
|
|
2235
|
-
ref:
|
|
2847
|
+
ref: setContainer
|
|
2236
2848
|
}, /* @__PURE__ */ React4.createElement("svg", {
|
|
2237
2849
|
xmlns: "http://www.w3.org/2000/svg",
|
|
2238
2850
|
ref: context.ref,
|
|
@@ -2290,11 +2902,17 @@ var startAnimation = (pulsar, r, options = {}) => {
|
|
|
2290
2902
|
};
|
|
2291
2903
|
var Pulsar;
|
|
2292
2904
|
export {
|
|
2905
|
+
CLUSTER_NODE_TYPE_GROUP,
|
|
2906
|
+
CLUSTER_NODE_TYPE_LEAF,
|
|
2907
|
+
CLUSTER_NODE_TYPE_ROOT,
|
|
2293
2908
|
EventEmitter,
|
|
2294
2909
|
FractionUtil,
|
|
2295
2910
|
Graph,
|
|
2911
|
+
GraphBundleProjector,
|
|
2912
|
+
GraphClusterProjector,
|
|
2296
2913
|
GraphForceProjector,
|
|
2297
2914
|
GraphHierarchicalProjector,
|
|
2915
|
+
GraphLatticeProjector,
|
|
2298
2916
|
GraphProjector,
|
|
2299
2917
|
GraphRadialProjector,
|
|
2300
2918
|
GraphRelationalProjector,
|