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