@dxos/react-ui-graph 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731
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/dist/lib/browser/index.mjs +781 -43
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +781 -43
- 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 +15 -1
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/SVG/FPS.d.ts +20 -0
- package/dist/types/src/components/SVG/FPS.d.ts.map +1 -0
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +3 -1
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +5 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts +67 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts +2 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts +8 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-swarm-projector.d.ts +72 -0
- package/dist/types/src/graph/projector/graph-swarm-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/index.d.ts +2 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +20 -0
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/index.d.ts +1 -0
- package/dist/types/src/graph/renderer/index.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/labels.d.ts +33 -0
- package/dist/types/src/graph/renderer/labels.d.ts.map +1 -0
- package/dist/types/src/stories/experimental.stories.d.ts +7 -0
- package/dist/types/src/stories/experimental.stories.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/components/Graph/Graph.tsx +70 -2
- package/src/components/SVG/FPS.tsx +91 -0
- package/src/components/SVG/Root.tsx +2 -1
- package/src/components/SVG/SVG.tsx +4 -1
- package/src/graph/projector/graph-cluster-projector.ts +12 -0
- package/src/graph/projector/graph-force-projector.ts +1 -0
- package/src/graph/projector/graph-plexus-projector.test.ts +102 -0
- package/src/graph/projector/graph-plexus-projector.ts +309 -0
- package/src/graph/projector/graph-projector.ts +15 -1
- package/src/graph/projector/graph-swarm-projector.ts +373 -0
- package/src/graph/projector/index.ts +2 -0
- package/src/graph/renderer/graph-renderer.ts +116 -3
- package/src/graph/renderer/index.ts +1 -0
- package/src/graph/renderer/labels.ts +138 -0
- package/src/stories/experimental.stories.tsx +446 -0
- package/styles/graph.css +1 -1
|
@@ -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 log11 } from "@dxos/log";
|
|
11
11
|
import { mx } from "@dxos/ui-theme";
|
|
12
12
|
|
|
13
13
|
// src/graph/markers.ts
|
|
@@ -746,6 +746,7 @@ var GraphProjector = class extends Projector {
|
|
|
746
746
|
});
|
|
747
747
|
const edges = data.edges.map((edge) => ({
|
|
748
748
|
id: edge.id,
|
|
749
|
+
type: edge.type,
|
|
749
750
|
source: nodes.find((n) => n.id === edge.source),
|
|
750
751
|
target: nodes.find((n) => n.id === edge.target),
|
|
751
752
|
data: edge.data
|
|
@@ -760,6 +761,16 @@ var GraphProjector = class extends Projector {
|
|
|
760
761
|
async onClear() {
|
|
761
762
|
this.reset();
|
|
762
763
|
}
|
|
764
|
+
/**
|
|
765
|
+
* Optional projector-owned click intercept. The Graph component invokes this BEFORE
|
|
766
|
+
* forwarding to the consumer's `onSelect`, so projectors can implement built-in
|
|
767
|
+
* interactions (e.g. cluster collapse) without each consumer wiring them. Returning
|
|
768
|
+
* `true` indicates the click was handled — consumer's `onSelect` is suppressed.
|
|
769
|
+
* Default no-op returns `false` so consumer handlers still run.
|
|
770
|
+
*/
|
|
771
|
+
handleNodeClick(_node, _event) {
|
|
772
|
+
return false;
|
|
773
|
+
}
|
|
763
774
|
};
|
|
764
775
|
|
|
765
776
|
// src/graph/projector/graph-radial-projector.ts
|
|
@@ -1071,6 +1082,17 @@ var GraphClusterProjector = class extends GraphRadialProjector {
|
|
|
1071
1082
|
// drops hidden leaves so the renderer doesn't see them), so re-reading from there
|
|
1072
1083
|
// would permanently lose the hidden leaves and they couldn't reappear on expand.
|
|
1073
1084
|
#dataNodes = [];
|
|
1085
|
+
/**
|
|
1086
|
+
* Built-in click semantics: clicking a synthetic root / group node toggles its subtree.
|
|
1087
|
+
* Leaf clicks fall through to the consumer's `onSelect` (returns `false`).
|
|
1088
|
+
*/
|
|
1089
|
+
handleNodeClick(node, _event) {
|
|
1090
|
+
if (node.type !== CLUSTER_NODE_TYPE_ROOT && node.type !== CLUSTER_NODE_TYPE_GROUP) {
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
this.toggleCollapsed(node.id);
|
|
1094
|
+
return true;
|
|
1095
|
+
}
|
|
1074
1096
|
/** Toggle collapse state for a synthetic node id. Triggers a topology re-emit. */
|
|
1075
1097
|
toggleCollapsed(id) {
|
|
1076
1098
|
if (this.#collapsed.has(id)) {
|
|
@@ -1092,7 +1114,7 @@ var GraphClusterProjector = class extends GraphRadialProjector {
|
|
|
1092
1114
|
nodes: graph?.nodes.length,
|
|
1093
1115
|
edges: graph?.edges.length
|
|
1094
1116
|
}
|
|
1095
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L:
|
|
1117
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file5, L: 79, S: this });
|
|
1096
1118
|
this.mergeData(graph);
|
|
1097
1119
|
this.#dataNodes = [
|
|
1098
1120
|
...this.layout.graph.nodes
|
|
@@ -1453,7 +1475,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
1453
1475
|
nodes: graph?.nodes.length,
|
|
1454
1476
|
edges: graph?.edges.length
|
|
1455
1477
|
}
|
|
1456
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L:
|
|
1478
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 91, S: this });
|
|
1457
1479
|
this._simulation.stop();
|
|
1458
1480
|
this.mergeData(graph);
|
|
1459
1481
|
this.updateLayout();
|
|
@@ -1504,7 +1526,7 @@ var GraphForceProjector = class extends GraphProjector {
|
|
|
1504
1526
|
updateForces(forces) {
|
|
1505
1527
|
log4("updateForces", {
|
|
1506
1528
|
forces
|
|
1507
|
-
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L:
|
|
1529
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file6, L: 153, S: this });
|
|
1508
1530
|
this._simulation.nodes(this.layout.graph.nodes).force("link", maybeForce(forces?.link, (config) => {
|
|
1509
1531
|
const force = forceLink().id((d) => d.id).links(this.layout.graph.edges.filter((edge) => edge.linkForce));
|
|
1510
1532
|
if (config.distance != null) {
|
|
@@ -1677,18 +1699,253 @@ var GraphLatticeProjector = class extends GraphRadialProjector {
|
|
|
1677
1699
|
}
|
|
1678
1700
|
};
|
|
1679
1701
|
|
|
1680
|
-
// src/graph/projector/graph-
|
|
1702
|
+
// src/graph/projector/graph-plexus-projector.ts
|
|
1703
|
+
import { cluster as d3Cluster3, hierarchy as hierarchy3, linkRadial as linkRadial2 } from "d3";
|
|
1681
1704
|
import { log as log7 } from "@dxos/log";
|
|
1682
|
-
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-
|
|
1683
|
-
var
|
|
1705
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-plexus-projector.ts";
|
|
1706
|
+
var RELATION_PREFIX = "__plexus_relation__:";
|
|
1707
|
+
var HIER_EDGE_PREFIX2 = "__plexus_hier__:";
|
|
1708
|
+
var PLEXUS_NODE_TYPE_FOCUS = "plexus-focus";
|
|
1709
|
+
var PLEXUS_NODE_TYPE_RELATION = "plexus-relation";
|
|
1710
|
+
var PLEXUS_NODE_TYPE_OBJECT = "plexus-object";
|
|
1711
|
+
var linkPath2 = linkRadial2().angle((d) => d.x).radius((d) => d.y);
|
|
1712
|
+
var cartesianToPolar3 = (x, y) => ({
|
|
1713
|
+
angle: Math.atan2(x, -y),
|
|
1714
|
+
radius: Math.hypot(x, y)
|
|
1715
|
+
});
|
|
1716
|
+
var GraphPlexusProjector = class extends GraphRadialProjector {
|
|
1717
|
+
// Full node / edge snapshots taken right after mergeData — doPlexusLayout reads from
|
|
1718
|
+
// these because it overwrites layout.graph with the filtered focus-centric view.
|
|
1719
|
+
#dataNodes = [];
|
|
1720
|
+
#dataEdges = [];
|
|
1684
1721
|
onUpdate(graph) {
|
|
1685
1722
|
log7("onUpdate", {
|
|
1723
|
+
graph: {
|
|
1724
|
+
nodes: graph?.nodes.length,
|
|
1725
|
+
edges: graph?.edges.length
|
|
1726
|
+
}
|
|
1727
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file9, L: 48, S: this });
|
|
1728
|
+
this.mergeData(graph);
|
|
1729
|
+
this.#dataNodes = [
|
|
1730
|
+
...this.layout.graph.nodes
|
|
1731
|
+
];
|
|
1732
|
+
this.#dataEdges = [
|
|
1733
|
+
...this.layout.graph.edges
|
|
1734
|
+
];
|
|
1735
|
+
this.doPlexusLayout();
|
|
1736
|
+
this.emitUpdate("topology");
|
|
1737
|
+
this.animate();
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Recompute each hierarchy edge's `path` from current cartesian endpoints so curves track
|
|
1741
|
+
* moving nodes during the tween (identical strategy to the cluster projector).
|
|
1742
|
+
*/
|
|
1743
|
+
onTickFrame(_t) {
|
|
1744
|
+
for (const edge of this.layout.graph.edges) {
|
|
1745
|
+
if (edge.type !== "hierarchy") {
|
|
1746
|
+
continue;
|
|
1747
|
+
}
|
|
1748
|
+
const { source, target } = edge;
|
|
1749
|
+
const s = cartesianToPolar3(source.x ?? 0, source.y ?? 0);
|
|
1750
|
+
const t = cartesianToPolar3(target.x ?? 0, target.y ?? 0);
|
|
1751
|
+
edge.path = linkPath2({
|
|
1752
|
+
source: {
|
|
1753
|
+
x: s.angle,
|
|
1754
|
+
y: s.radius
|
|
1755
|
+
},
|
|
1756
|
+
target: {
|
|
1757
|
+
x: t.angle,
|
|
1758
|
+
y: t.radius
|
|
1759
|
+
}
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
doPlexusLayout() {
|
|
1764
|
+
if (!this.context.size) {
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
const dataNodes = this.#dataNodes;
|
|
1768
|
+
if (!dataNodes.length) {
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
const focusId = this.options.focus;
|
|
1772
|
+
const focusNode = focusId ? dataNodes.find((node) => node.id === focusId) : void 0;
|
|
1773
|
+
if (!focusNode) {
|
|
1774
|
+
const radial = layoutRadial(0, 0, Math.min(this.context.size.width, this.context.size.height) / 2 - (this.options.margin ?? 100), dataNodes.length);
|
|
1775
|
+
dataNodes.forEach((node, index) => updateNode(node, radial(index), this.options.leafRadius ?? 5));
|
|
1776
|
+
this.layout.graph.nodes = dataNodes;
|
|
1777
|
+
this.layout.graph.edges = [];
|
|
1778
|
+
this.animate();
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
const relationOf = this.options.relationOf ?? defaultRelationOf;
|
|
1782
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1783
|
+
const placed = /* @__PURE__ */ new Set([
|
|
1784
|
+
focusId
|
|
1785
|
+
]);
|
|
1786
|
+
for (const edge of this.#dataEdges) {
|
|
1787
|
+
const relation = relationOf(edge, focusId);
|
|
1788
|
+
if (!relation) {
|
|
1789
|
+
continue;
|
|
1790
|
+
}
|
|
1791
|
+
const neighbour = edge.source.id === focusId ? edge.target : edge.source;
|
|
1792
|
+
if (placed.has(neighbour.id)) {
|
|
1793
|
+
continue;
|
|
1794
|
+
}
|
|
1795
|
+
placed.add(neighbour.id);
|
|
1796
|
+
let group = groups.get(relation.key);
|
|
1797
|
+
if (!group) {
|
|
1798
|
+
group = {
|
|
1799
|
+
id: `${RELATION_PREFIX}${relation.key}`,
|
|
1800
|
+
label: relation.label,
|
|
1801
|
+
leaves: []
|
|
1802
|
+
};
|
|
1803
|
+
groups.set(relation.key, group);
|
|
1804
|
+
}
|
|
1805
|
+
group.leaves.push(neighbour);
|
|
1806
|
+
}
|
|
1807
|
+
const items = [
|
|
1808
|
+
{
|
|
1809
|
+
id: focusId,
|
|
1810
|
+
node: focusNode
|
|
1811
|
+
}
|
|
1812
|
+
];
|
|
1813
|
+
for (const group of groups.values()) {
|
|
1814
|
+
items.push({
|
|
1815
|
+
id: group.id,
|
|
1816
|
+
parent: focusId,
|
|
1817
|
+
relationLabel: group.label
|
|
1818
|
+
});
|
|
1819
|
+
for (const leaf of group.leaves) {
|
|
1820
|
+
items.push({
|
|
1821
|
+
id: leaf.id,
|
|
1822
|
+
parent: group.id,
|
|
1823
|
+
node: leaf
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
const childrenByParent = /* @__PURE__ */ new Map();
|
|
1828
|
+
for (const item of items) {
|
|
1829
|
+
if (item.parent) {
|
|
1830
|
+
const list = childrenByParent.get(item.parent) ?? [];
|
|
1831
|
+
list.push(item);
|
|
1832
|
+
childrenByParent.set(item.parent, list);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
const root = hierarchy3({
|
|
1836
|
+
id: focusId,
|
|
1837
|
+
node: focusNode
|
|
1838
|
+
}, (d) => childrenByParent.get(d.id) ?? []);
|
|
1839
|
+
const { width, height } = this.context.size;
|
|
1840
|
+
const margin = this.options.margin ?? 100;
|
|
1841
|
+
const ringRadius = Math.max(0, Math.min(width, height) / 2 - margin);
|
|
1842
|
+
d3Cluster3().size([
|
|
1843
|
+
2 * Math.PI,
|
|
1844
|
+
ringRadius
|
|
1845
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
1846
|
+
const leafR = this.options.leafRadius ?? 5;
|
|
1847
|
+
const relationR = this.options.relationRadius ?? leafR;
|
|
1848
|
+
const focusR = this.options.focusRadius ?? leafR * 2;
|
|
1849
|
+
const prevStubsById = /* @__PURE__ */ new Map();
|
|
1850
|
+
for (const node of this.layout.graph.nodes) {
|
|
1851
|
+
if (node.type === PLEXUS_NODE_TYPE_RELATION) {
|
|
1852
|
+
prevStubsById.set(node.id, node);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
const relationStubs = /* @__PURE__ */ new Map();
|
|
1856
|
+
root.each((d) => {
|
|
1857
|
+
const angle = d.x;
|
|
1858
|
+
const radius = d.y;
|
|
1859
|
+
const x = Math.cos(angle - Math.PI / 2) * radius;
|
|
1860
|
+
const y = Math.sin(angle - Math.PI / 2) * radius;
|
|
1861
|
+
const id = d.data.id;
|
|
1862
|
+
if (id === focusId) {
|
|
1863
|
+
updateNode(focusNode, [
|
|
1864
|
+
x,
|
|
1865
|
+
y
|
|
1866
|
+
], focusR);
|
|
1867
|
+
focusNode.type = PLEXUS_NODE_TYPE_FOCUS;
|
|
1868
|
+
focusNode.hidden = false;
|
|
1869
|
+
} else if (d.data.node) {
|
|
1870
|
+
updateNode(d.data.node, [
|
|
1871
|
+
x,
|
|
1872
|
+
y
|
|
1873
|
+
], leafR);
|
|
1874
|
+
d.data.node.type = PLEXUS_NODE_TYPE_OBJECT;
|
|
1875
|
+
d.data.node.hidden = false;
|
|
1876
|
+
} else {
|
|
1877
|
+
const stub = prevStubsById.get(id) ?? {
|
|
1878
|
+
id,
|
|
1879
|
+
x: 0,
|
|
1880
|
+
y: 0
|
|
1881
|
+
};
|
|
1882
|
+
updateNode(stub, [
|
|
1883
|
+
x,
|
|
1884
|
+
y
|
|
1885
|
+
], relationR);
|
|
1886
|
+
stub.type = PLEXUS_NODE_TYPE_RELATION;
|
|
1887
|
+
stub.label = d.data.relationLabel;
|
|
1888
|
+
relationStubs.set(id, stub);
|
|
1889
|
+
}
|
|
1890
|
+
});
|
|
1891
|
+
const nextNodes = [];
|
|
1892
|
+
for (const stub of relationStubs.values()) {
|
|
1893
|
+
nextNodes.push(stub);
|
|
1894
|
+
}
|
|
1895
|
+
for (const group of groups.values()) {
|
|
1896
|
+
for (const leaf of group.leaves) {
|
|
1897
|
+
nextNodes.push(leaf);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
nextNodes.push(focusNode);
|
|
1901
|
+
this.layout.graph.nodes = nextNodes;
|
|
1902
|
+
const edges = [];
|
|
1903
|
+
root.links().forEach((link) => {
|
|
1904
|
+
const sid = link.source.data.id;
|
|
1905
|
+
const tid = link.target.data.id;
|
|
1906
|
+
const sourceNode = sid === focusId ? focusNode : link.source.data.node ?? relationStubs.get(sid);
|
|
1907
|
+
const targetNode = link.target.data.node ?? relationStubs.get(tid);
|
|
1908
|
+
if (!sourceNode || !targetNode) {
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
edges.push({
|
|
1912
|
+
id: `${HIER_EDGE_PREFIX2}${sid}->${tid}`,
|
|
1913
|
+
type: "hierarchy",
|
|
1914
|
+
source: sourceNode,
|
|
1915
|
+
target: targetNode,
|
|
1916
|
+
data: void 0
|
|
1917
|
+
});
|
|
1918
|
+
});
|
|
1919
|
+
this.layout.graph.edges = edges;
|
|
1920
|
+
this.onTickFrame(0);
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
var defaultRelationOf = (edge, focusId) => {
|
|
1924
|
+
const outgoing = edge.source.id === focusId;
|
|
1925
|
+
const incoming = edge.target.id === focusId;
|
|
1926
|
+
if (!outgoing && !incoming) {
|
|
1927
|
+
return void 0;
|
|
1928
|
+
}
|
|
1929
|
+
const type = edge.type ?? "edge";
|
|
1930
|
+
const arrow = outgoing ? "\u2192" : "\u2190";
|
|
1931
|
+
return {
|
|
1932
|
+
key: `${type}:${outgoing ? "out" : "in"}`,
|
|
1933
|
+
label: `${type} ${arrow}`
|
|
1934
|
+
};
|
|
1935
|
+
};
|
|
1936
|
+
|
|
1937
|
+
// src/graph/projector/graph-relational-projector.ts
|
|
1938
|
+
import { log as log8 } from "@dxos/log";
|
|
1939
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-relational-projector.ts";
|
|
1940
|
+
var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
1941
|
+
onUpdate(graph) {
|
|
1942
|
+
log8("onUpdate", {
|
|
1686
1943
|
graph: {
|
|
1687
1944
|
nodes: graph?.nodes.length,
|
|
1688
1945
|
edges: graph?.edges.length
|
|
1689
1946
|
},
|
|
1690
1947
|
selection: this.selection?.getSelectedIds()
|
|
1691
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
1948
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file10, L: 8, S: this });
|
|
1692
1949
|
this.mergeData(graph);
|
|
1693
1950
|
this.emitUpdate("topology");
|
|
1694
1951
|
const selected = this.selection?.getSelectedIds()[0];
|
|
@@ -1762,10 +2019,267 @@ var GraphRelationalProjector = class extends GraphRadialProjector {
|
|
|
1762
2019
|
}
|
|
1763
2020
|
};
|
|
1764
2021
|
|
|
2022
|
+
// src/graph/projector/graph-swarm-projector.ts
|
|
2023
|
+
import { timer as timer2 } from "d3";
|
|
2024
|
+
import { log as log9 } from "@dxos/log";
|
|
2025
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-swarm-projector.ts";
|
|
2026
|
+
var SWARMMATE_RADIUS = 60;
|
|
2027
|
+
var SEPARATION_DISTANCE = 30;
|
|
2028
|
+
var DEFAULTS = {
|
|
2029
|
+
spawnRadius: 200,
|
|
2030
|
+
maxVelocity: 1.2,
|
|
2031
|
+
alignment: 3,
|
|
2032
|
+
cohesion: 3,
|
|
2033
|
+
separation: 3,
|
|
2034
|
+
cursorRepel: 120,
|
|
2035
|
+
avoidance: 3,
|
|
2036
|
+
trailLength: 30
|
|
2037
|
+
};
|
|
2038
|
+
var GraphSwarmProjector = class extends GraphProjector {
|
|
2039
|
+
#timer;
|
|
2040
|
+
/** Cursor in SVG model coordinates, or null when the pointer is outside the surface. */
|
|
2041
|
+
#cursor = null;
|
|
2042
|
+
findNode() {
|
|
2043
|
+
return void 0;
|
|
2044
|
+
}
|
|
2045
|
+
/**
|
|
2046
|
+
* Tell the projector where the pointer is, in SVG model coordinates (the same space
|
|
2047
|
+
* `node.x/y` live in — center origin, post-zoom). Pass `null` (or omit args) on
|
|
2048
|
+
* pointer-leave to disable cursor avoidance.
|
|
2049
|
+
*/
|
|
2050
|
+
setCursor(x, y) {
|
|
2051
|
+
if (x == null || y == null) {
|
|
2052
|
+
this.#cursor = null;
|
|
2053
|
+
} else {
|
|
2054
|
+
this.#cursor = {
|
|
2055
|
+
x,
|
|
2056
|
+
y
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
onUpdate(graph) {
|
|
2061
|
+
log9("onUpdate", {
|
|
2062
|
+
graph: {
|
|
2063
|
+
nodes: graph?.nodes.length,
|
|
2064
|
+
edges: graph?.edges.length
|
|
2065
|
+
}
|
|
2066
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file11, L: 54, S: this });
|
|
2067
|
+
this.mergeData(graph);
|
|
2068
|
+
this.initializeNodes();
|
|
2069
|
+
this.emitUpdate("topology");
|
|
2070
|
+
}
|
|
2071
|
+
async onStart() {
|
|
2072
|
+
this.startTimer();
|
|
2073
|
+
}
|
|
2074
|
+
async onStop() {
|
|
2075
|
+
this.stopTimer();
|
|
2076
|
+
}
|
|
2077
|
+
onRefresh() {
|
|
2078
|
+
if (!this.#timer) {
|
|
2079
|
+
this.startTimer();
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
#opt(key) {
|
|
2083
|
+
return this.options[key] ?? DEFAULTS[key];
|
|
2084
|
+
}
|
|
2085
|
+
initializeNodes() {
|
|
2086
|
+
const spawnRadius = this.#opt("spawnRadius");
|
|
2087
|
+
const maxVelocity = this.#opt("maxVelocity");
|
|
2088
|
+
for (const node of this.layout.graph.nodes) {
|
|
2089
|
+
if (!node.initialized) {
|
|
2090
|
+
const theta = Math.random() * 2 * Math.PI;
|
|
2091
|
+
const r = Math.random() * spawnRadius;
|
|
2092
|
+
node.x = Math.cos(theta) * r;
|
|
2093
|
+
node.y = Math.sin(theta) * r;
|
|
2094
|
+
const phi = Math.random() * 2 * Math.PI;
|
|
2095
|
+
const speed = (0.3 + Math.random() * 0.7) * maxVelocity;
|
|
2096
|
+
node.vx = Math.cos(phi) * speed;
|
|
2097
|
+
node.vy = Math.sin(phi) * speed;
|
|
2098
|
+
node.ax = 0;
|
|
2099
|
+
node.ay = 0;
|
|
2100
|
+
node.initialized = true;
|
|
2101
|
+
} else {
|
|
2102
|
+
node.vx ??= 0;
|
|
2103
|
+
node.vy ??= 0;
|
|
2104
|
+
node.ax ??= 0;
|
|
2105
|
+
node.ay ??= 0;
|
|
2106
|
+
}
|
|
2107
|
+
node.r ??= 6;
|
|
2108
|
+
node.history = [
|
|
2109
|
+
{
|
|
2110
|
+
x: node.x ?? 0,
|
|
2111
|
+
y: node.y ?? 0
|
|
2112
|
+
}
|
|
2113
|
+
];
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
startTimer() {
|
|
2117
|
+
this.stopTimer();
|
|
2118
|
+
this.#timer = timer2(() => this.tick());
|
|
2119
|
+
}
|
|
2120
|
+
stopTimer() {
|
|
2121
|
+
this.#timer?.stop();
|
|
2122
|
+
this.#timer = void 0;
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* One simulation step. Modeled on `tick` in Swarm.tsx, but operating in the
|
|
2126
|
+
* SVG centered-origin coordinate space and writing to `node.x/y` directly so
|
|
2127
|
+
* the existing `GraphRenderer.applyPositions` reads them unchanged.
|
|
2128
|
+
*/
|
|
2129
|
+
tick() {
|
|
2130
|
+
const size = this.context.size;
|
|
2131
|
+
if (!size) {
|
|
2132
|
+
return;
|
|
2133
|
+
}
|
|
2134
|
+
const { width, height } = size;
|
|
2135
|
+
const halfW = width / 2;
|
|
2136
|
+
const halfH = height / 2;
|
|
2137
|
+
const nodes = this.layout.graph.nodes;
|
|
2138
|
+
const maxVelocity = this.#opt("maxVelocity");
|
|
2139
|
+
const alignmentW = this.#opt("alignment") / 100;
|
|
2140
|
+
const cohesionW = this.#opt("cohesion") / 100;
|
|
2141
|
+
const separationW = this.#opt("separation") / 100;
|
|
2142
|
+
const avoidanceW = this.#opt("avoidance") / 10;
|
|
2143
|
+
const cursorRepel = this.#opt("cursorRepel");
|
|
2144
|
+
const cursor = cursorRepel > 0 ? this.#cursor : null;
|
|
2145
|
+
for (const b1 of nodes) {
|
|
2146
|
+
let ax = 0;
|
|
2147
|
+
let ay = 0;
|
|
2148
|
+
let alignX = 0;
|
|
2149
|
+
let alignY = 0;
|
|
2150
|
+
let alignActive = false;
|
|
2151
|
+
let cohX = 0;
|
|
2152
|
+
let cohY = 0;
|
|
2153
|
+
let cohActive = false;
|
|
2154
|
+
let sepX = 0;
|
|
2155
|
+
let sepY = 0;
|
|
2156
|
+
let sepActive = false;
|
|
2157
|
+
let avoidX = 0;
|
|
2158
|
+
let avoidY = 0;
|
|
2159
|
+
let avoidActive = false;
|
|
2160
|
+
if (cursor) {
|
|
2161
|
+
const dx = cursor.x - (b1.x ?? 0);
|
|
2162
|
+
const dy = cursor.y - (b1.y ?? 0);
|
|
2163
|
+
const distSq = dx * dx + dy * dy;
|
|
2164
|
+
if (distSq > 0 && distSq < cursorRepel * cursorRepel) {
|
|
2165
|
+
const dist = Math.sqrt(distSq);
|
|
2166
|
+
avoidX = -dx / dist * (1 / dist);
|
|
2167
|
+
avoidY = -dy / dist * (1 / dist);
|
|
2168
|
+
avoidActive = true;
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
if (!avoidActive) {
|
|
2172
|
+
for (const b2 of nodes) {
|
|
2173
|
+
if (b1 === b2) {
|
|
2174
|
+
continue;
|
|
2175
|
+
}
|
|
2176
|
+
const dx = (b2.x ?? 0) - (b1.x ?? 0);
|
|
2177
|
+
const dy = (b2.y ?? 0) - (b1.y ?? 0);
|
|
2178
|
+
const distSq = dx * dx + dy * dy;
|
|
2179
|
+
if (distSq === 0) {
|
|
2180
|
+
continue;
|
|
2181
|
+
}
|
|
2182
|
+
const dist = Math.sqrt(distSq);
|
|
2183
|
+
if (dist < SEPARATION_DISTANCE) {
|
|
2184
|
+
sepX += -dx / dist * (1 / dist);
|
|
2185
|
+
sepY += -dy / dist * (1 / dist);
|
|
2186
|
+
sepActive = true;
|
|
2187
|
+
}
|
|
2188
|
+
if (dist < SWARMMATE_RADIUS) {
|
|
2189
|
+
cohX += dx;
|
|
2190
|
+
cohY += dy;
|
|
2191
|
+
cohActive = true;
|
|
2192
|
+
alignX += b2.vx ?? 0;
|
|
2193
|
+
alignY += b2.vy ?? 0;
|
|
2194
|
+
alignActive = true;
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
const applyForce = (fx, fy, weight, active) => {
|
|
2199
|
+
if (!active || weight === 0) {
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
const len = Math.sqrt(fx * fx + fy * fy);
|
|
2203
|
+
if (len === 0) {
|
|
2204
|
+
return;
|
|
2205
|
+
}
|
|
2206
|
+
const sx = fx * maxVelocity / len - (b1.vx ?? 0);
|
|
2207
|
+
const sy = fy * maxVelocity / len - (b1.vy ?? 0);
|
|
2208
|
+
const slen = Math.sqrt(sx * sx + sy * sy);
|
|
2209
|
+
if (slen > weight) {
|
|
2210
|
+
ax += sx * weight / slen;
|
|
2211
|
+
ay += sy * weight / slen;
|
|
2212
|
+
} else {
|
|
2213
|
+
ax += sx;
|
|
2214
|
+
ay += sy;
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2217
|
+
applyForce(alignX, alignY, alignmentW, alignActive);
|
|
2218
|
+
applyForce(cohX, cohY, cohesionW, cohActive);
|
|
2219
|
+
applyForce(sepX, sepY, separationW, sepActive);
|
|
2220
|
+
applyForce(avoidX, avoidY, avoidanceW, avoidActive);
|
|
2221
|
+
b1.ax = ax;
|
|
2222
|
+
b1.ay = ay;
|
|
2223
|
+
}
|
|
2224
|
+
const trailLength = Math.max(0, Math.round(this.#opt("trailLength")));
|
|
2225
|
+
for (const b of nodes) {
|
|
2226
|
+
let vx = (b.vx ?? 0) + (b.ax ?? 0);
|
|
2227
|
+
let vy = (b.vy ?? 0) + (b.ay ?? 0);
|
|
2228
|
+
const vlen = Math.sqrt(vx * vx + vy * vy);
|
|
2229
|
+
if (vlen > maxVelocity) {
|
|
2230
|
+
vx = vx * maxVelocity / vlen;
|
|
2231
|
+
vy = vy * maxVelocity / vlen;
|
|
2232
|
+
}
|
|
2233
|
+
b.vx = vx;
|
|
2234
|
+
b.vy = vy;
|
|
2235
|
+
if (trailLength > 0) {
|
|
2236
|
+
const history = b.history ?? (b.history = []);
|
|
2237
|
+
history.push({
|
|
2238
|
+
x: b.x ?? 0,
|
|
2239
|
+
y: b.y ?? 0
|
|
2240
|
+
});
|
|
2241
|
+
if (history.length > trailLength) {
|
|
2242
|
+
history.splice(0, history.length - trailLength);
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
let x = (b.x ?? 0) + vx;
|
|
2246
|
+
let y = (b.y ?? 0) + vy;
|
|
2247
|
+
let wrapped = false;
|
|
2248
|
+
if (x > halfW) {
|
|
2249
|
+
x -= width;
|
|
2250
|
+
wrapped = true;
|
|
2251
|
+
} else if (x < -halfW) {
|
|
2252
|
+
x += width;
|
|
2253
|
+
wrapped = true;
|
|
2254
|
+
}
|
|
2255
|
+
if (y > halfH) {
|
|
2256
|
+
y -= height;
|
|
2257
|
+
wrapped = true;
|
|
2258
|
+
} else if (y < -halfH) {
|
|
2259
|
+
y += height;
|
|
2260
|
+
wrapped = true;
|
|
2261
|
+
}
|
|
2262
|
+
if (wrapped && b.history) {
|
|
2263
|
+
b.history.length = 0;
|
|
2264
|
+
}
|
|
2265
|
+
b.x = x;
|
|
2266
|
+
b.y = y;
|
|
2267
|
+
}
|
|
2268
|
+
for (const edge of this.layout.graph.edges) {
|
|
2269
|
+
const sx = edge.source.x ?? 0;
|
|
2270
|
+
const sy = edge.source.y ?? 0;
|
|
2271
|
+
const tx = edge.target.x ?? 0;
|
|
2272
|
+
const ty = edge.target.y ?? 0;
|
|
2273
|
+
edge.path = `M ${sx} ${sy} Q 0 0 ${tx} ${ty}`;
|
|
2274
|
+
}
|
|
2275
|
+
this.emitUpdate("positions");
|
|
2276
|
+
}
|
|
2277
|
+
};
|
|
2278
|
+
|
|
1765
2279
|
// src/graph/renderer/graph-renderer.ts
|
|
1766
2280
|
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
1767
2281
|
import * as Clipper from "js-clipper";
|
|
1768
|
-
import { log as
|
|
2282
|
+
import { log as log10 } from "@dxos/log";
|
|
1769
2283
|
|
|
1770
2284
|
// src/graph/renderer/bullets.ts
|
|
1771
2285
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
@@ -1834,7 +2348,7 @@ var Renderer = class {
|
|
|
1834
2348
|
};
|
|
1835
2349
|
|
|
1836
2350
|
// src/graph/renderer/graph-renderer.ts
|
|
1837
|
-
var
|
|
2351
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
1838
2352
|
var createLine2 = line2();
|
|
1839
2353
|
var EDGE_FADE_MS = 300;
|
|
1840
2354
|
var NODE_HIDE_MS = 500;
|
|
@@ -1853,7 +2367,7 @@ var GraphRenderer = class extends Renderer {
|
|
|
1853
2367
|
this.#firstRender = false;
|
|
1854
2368
|
this.root.replaceChildren();
|
|
1855
2369
|
}
|
|
1856
|
-
|
|
2370
|
+
log10("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 35, S: this });
|
|
1857
2371
|
const root = select4(this.root);
|
|
1858
2372
|
if (layout.guides) {
|
|
1859
2373
|
root.selectAll("g.dx-guides").data([
|
|
@@ -1911,7 +2425,7 @@ var GraphRenderer = class extends Renderer {
|
|
|
1911
2425
|
{
|
|
1912
2426
|
id: "edges"
|
|
1913
2427
|
}
|
|
1914
|
-
], (d) => d.id).join("g").classed("dx-edges", true);
|
|
2428
|
+
], (d) => d.id).join("g").classed("dx-edges", true).style("opacity", this.options.edgeOpacity != null ? String(this.options.edgeOpacity) : null);
|
|
1915
2429
|
const nodeGroup = root.selectAll("g.dx-nodes").data([
|
|
1916
2430
|
{
|
|
1917
2431
|
id: "nodes"
|
|
@@ -1942,7 +2456,11 @@ var GraphRenderer = class extends Renderer {
|
|
|
1942
2456
|
return;
|
|
1943
2457
|
}
|
|
1944
2458
|
const root = select4(this.root);
|
|
1945
|
-
|
|
2459
|
+
const applyNode = this.options.applyNode;
|
|
2460
|
+
root.select("g.dx-nodes").selectAll("g.dx-node").attr("transform", (d) => d.x != null && d.y != null ? `translate(${d.x},${d.y})` : null).each(applyNode ? function(d) {
|
|
2461
|
+
applyNode(this, d);
|
|
2462
|
+
} : () => {
|
|
2463
|
+
});
|
|
1946
2464
|
root.select("g.dx-edges").selectAll("g.dx-edge").selectAll("path").attr("d", function() {
|
|
1947
2465
|
const edge = select4(this.parentElement).datum();
|
|
1948
2466
|
if (edge.path) {
|
|
@@ -2001,14 +2519,20 @@ var createNode = (group, options) => {
|
|
|
2001
2519
|
g.append("rect");
|
|
2002
2520
|
g.append("text").style("dominant-baseline", "middle");
|
|
2003
2521
|
}
|
|
2004
|
-
if (options.onNodePointerEnter || options.onNodePointerLeave) {
|
|
2522
|
+
if (options.onNodePointerEnter || options.onNodePointerLeave || options.highlightOnHover) {
|
|
2005
2523
|
hitTarget.on("pointerenter", function(event) {
|
|
2006
2524
|
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2007
2525
|
options.onNodePointerEnter?.(node, event);
|
|
2526
|
+
if (options.highlightOnHover) {
|
|
2527
|
+
applyHoverHighlight(this.closest("g.dx-graph"), node.id);
|
|
2528
|
+
}
|
|
2008
2529
|
});
|
|
2009
2530
|
hitTarget.on("pointerleave", function(event) {
|
|
2010
2531
|
const node = select4(useCustom ? this : this.parentElement).datum();
|
|
2011
2532
|
options.onNodePointerLeave?.(node, event);
|
|
2533
|
+
if (options.highlightOnHover) {
|
|
2534
|
+
applyHoverHighlight(this.closest("g.dx-graph"), null);
|
|
2535
|
+
}
|
|
2012
2536
|
});
|
|
2013
2537
|
group.attr("data-hover", "handled");
|
|
2014
2538
|
} else if (options.highlight !== false && !useCustom) {
|
|
@@ -2054,9 +2578,9 @@ var updateNode2 = (group, options) => {
|
|
|
2054
2578
|
}
|
|
2055
2579
|
});
|
|
2056
2580
|
} catch (error) {
|
|
2057
|
-
|
|
2581
|
+
log10.error("updateNode", {
|
|
2058
2582
|
error: error?.message
|
|
2059
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
2583
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 303, S: void 0 });
|
|
2060
2584
|
}
|
|
2061
2585
|
}
|
|
2062
2586
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
@@ -2107,9 +2631,9 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
2107
2631
|
}
|
|
2108
2632
|
});
|
|
2109
2633
|
} catch (error) {
|
|
2110
|
-
|
|
2634
|
+
log10.error("updateEdge", {
|
|
2111
2635
|
error: error?.message
|
|
2112
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
2636
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 371, S: void 0 });
|
|
2113
2637
|
}
|
|
2114
2638
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
2115
2639
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
@@ -2130,6 +2654,62 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
2130
2654
|
], source.r, target.r));
|
|
2131
2655
|
});
|
|
2132
2656
|
};
|
|
2657
|
+
var applyHoverHighlight = (root, focusedId) => {
|
|
2658
|
+
if (!root) {
|
|
2659
|
+
return;
|
|
2660
|
+
}
|
|
2661
|
+
const r = select4(root);
|
|
2662
|
+
const on = focusedId != null;
|
|
2663
|
+
const outgoing = /* @__PURE__ */ new Set();
|
|
2664
|
+
const incoming = /* @__PURE__ */ new Set();
|
|
2665
|
+
if (on) {
|
|
2666
|
+
r.select("g.dx-edges").selectAll("g.dx-edge").each((edge) => {
|
|
2667
|
+
if (edge.source.id === focusedId) {
|
|
2668
|
+
outgoing.add(edge.target.id);
|
|
2669
|
+
}
|
|
2670
|
+
if (edge.target.id === focusedId) {
|
|
2671
|
+
incoming.add(edge.source.id);
|
|
2672
|
+
}
|
|
2673
|
+
});
|
|
2674
|
+
}
|
|
2675
|
+
r.select("g.dx-edges").selectAll("g.dx-edge").each(function(edge) {
|
|
2676
|
+
const path = select4(this).select("path:not(.dx-click)");
|
|
2677
|
+
if (!on) {
|
|
2678
|
+
path.style("stroke", null).style("stroke-width", null).style("opacity", null);
|
|
2679
|
+
return;
|
|
2680
|
+
}
|
|
2681
|
+
if (edge.source.id === focusedId) {
|
|
2682
|
+
path.style("stroke", "var(--color-orange-500)").style("stroke-width", "1.5px").style("opacity", null);
|
|
2683
|
+
} else if (edge.target.id === focusedId) {
|
|
2684
|
+
path.style("stroke", "var(--color-sky-500)").style("stroke-width", "1.5px").style("opacity", null);
|
|
2685
|
+
} else {
|
|
2686
|
+
path.style("stroke", null).style("stroke-width", null).style("opacity", "0.8");
|
|
2687
|
+
}
|
|
2688
|
+
});
|
|
2689
|
+
r.select("g.dx-nodes").selectAll("g.dx-node").each(function(node) {
|
|
2690
|
+
const groupSel = select4(this);
|
|
2691
|
+
const shape = groupSel.select("circle, rect");
|
|
2692
|
+
if (node.hidden) {
|
|
2693
|
+
return;
|
|
2694
|
+
}
|
|
2695
|
+
if (!on) {
|
|
2696
|
+
groupSel.style("opacity", null);
|
|
2697
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
const connected = outgoing.has(node.id) || incoming.has(node.id);
|
|
2701
|
+
if (node.id === focusedId) {
|
|
2702
|
+
groupSel.style("opacity", null);
|
|
2703
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2704
|
+
} else if (connected) {
|
|
2705
|
+
groupSel.style("opacity", null);
|
|
2706
|
+
shape.style("stroke", "var(--color-orange-400)").style("stroke-width", "2.5px");
|
|
2707
|
+
} else {
|
|
2708
|
+
groupSel.style("opacity", "0.4");
|
|
2709
|
+
shape.style("stroke", null).style("stroke-width", null);
|
|
2710
|
+
}
|
|
2711
|
+
});
|
|
2712
|
+
};
|
|
2133
2713
|
var applyClasses = (el, classes) => {
|
|
2134
2714
|
for (const [className, value] of Object.entries(classes)) {
|
|
2135
2715
|
el.classed(className, value);
|
|
@@ -2168,6 +2748,45 @@ var findConnectedComponents = (graph) => {
|
|
|
2168
2748
|
return components;
|
|
2169
2749
|
};
|
|
2170
2750
|
|
|
2751
|
+
// src/graph/renderer/labels.ts
|
|
2752
|
+
var DEFAULT_DURATION = 200;
|
|
2753
|
+
var DEFAULT_OFFSET = 4;
|
|
2754
|
+
var getTarget = (node) => {
|
|
2755
|
+
const tx = node.tx;
|
|
2756
|
+
const ty = node.ty;
|
|
2757
|
+
return {
|
|
2758
|
+
x: tx ?? node.x ?? 0,
|
|
2759
|
+
y: ty ?? node.y ?? 0
|
|
2760
|
+
};
|
|
2761
|
+
};
|
|
2762
|
+
var appendRadialLeafLabel = (group, node, label, r, options = {}) => {
|
|
2763
|
+
if (!label) {
|
|
2764
|
+
return;
|
|
2765
|
+
}
|
|
2766
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label" } = options;
|
|
2767
|
+
const { x: targetX, y: targetY } = getTarget(node);
|
|
2768
|
+
const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
|
|
2769
|
+
const flipped = angleDeg > 90 || angleDeg < -90;
|
|
2770
|
+
group.append("text").attr("class", className).attr("dy", "0.32em").attr("transform", `rotate(${flipped ? angleDeg + 180 : angleDeg})`).attr("x", flipped ? -(r + offset) : r + offset).attr("text-anchor", flipped ? "end" : "start").attr("opacity", 0).style("cursor", "pointer").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2771
|
+
};
|
|
2772
|
+
var appendRadialGroupLabel = (group, node, label, r, options = {}) => {
|
|
2773
|
+
if (!label) {
|
|
2774
|
+
return;
|
|
2775
|
+
}
|
|
2776
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = DEFAULT_OFFSET, className = "dx-cluster-label dx-cluster-label-group" } = options;
|
|
2777
|
+
const { x: targetX, y: targetY } = getTarget(node);
|
|
2778
|
+
const angleDeg = Math.atan2(targetY, targetX) * 180 / Math.PI;
|
|
2779
|
+
const flipped = angleDeg > 90 || angleDeg < -90;
|
|
2780
|
+
group.append("text").attr("class", className).attr("dy", "0.32em").attr("transform", `rotate(${flipped ? angleDeg + 180 : angleDeg})`).attr("x", flipped ? r + offset : -(r + offset)).attr("text-anchor", flipped ? "start" : "end").attr("opacity", 0).style("pointer-events", "none").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2781
|
+
};
|
|
2782
|
+
var appendRootLabel = (group, label, r, options = {}) => {
|
|
2783
|
+
if (!label) {
|
|
2784
|
+
return;
|
|
2785
|
+
}
|
|
2786
|
+
const { delay = 0, duration = DEFAULT_DURATION, offset = 6, className = "dx-cluster-label dx-cluster-label-root" } = options;
|
|
2787
|
+
group.append("text").attr("class", className).attr("text-anchor", "middle").attr("y", -(r + offset)).attr("opacity", 0).style("pointer-events", "none").text(label).transition().delay(delay).duration(duration).attr("opacity", 1);
|
|
2788
|
+
};
|
|
2789
|
+
|
|
2171
2790
|
// src/graph/renderer/linker.ts
|
|
2172
2791
|
import { line as line3 } from "d3";
|
|
2173
2792
|
var createLine3 = line3();
|
|
@@ -2510,8 +3129,8 @@ var useZoom = (options = defaultZoomOptions) => {
|
|
|
2510
3129
|
};
|
|
2511
3130
|
|
|
2512
3131
|
// src/components/Graph/Graph.tsx
|
|
2513
|
-
var
|
|
2514
|
-
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, ...props }, forwardedRef) => {
|
|
3132
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
3133
|
+
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, onPointerMove, onPointerLeave, ...props }, forwardedRef) => {
|
|
2515
3134
|
const context = useSvgContext();
|
|
2516
3135
|
const graphRef = useRef3(null);
|
|
2517
3136
|
const { projector, renderer } = useMemo3(() => {
|
|
@@ -2528,7 +3147,14 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2528
3147
|
arrows: {
|
|
2529
3148
|
end: arrows
|
|
2530
3149
|
},
|
|
2531
|
-
|
|
3150
|
+
// Projector intercept first so built-in interactions (e.g. cluster collapse) can
|
|
3151
|
+
// run without consumers wiring them. Returning true suppresses the user handler.
|
|
3152
|
+
onNodeClick: (node, event) => {
|
|
3153
|
+
if (projector2.handleNodeClick(node, event)) {
|
|
3154
|
+
return;
|
|
3155
|
+
}
|
|
3156
|
+
onSelect?.(node, event);
|
|
3157
|
+
},
|
|
2532
3158
|
onNodePointerEnter: onInspect ? (node, event) => onInspect(node, event) : void 0,
|
|
2533
3159
|
// Pair pointerenter with leave so consumers can clear hover-driven previews.
|
|
2534
3160
|
// The callback receives `null` on leave (event still carries the source).
|
|
@@ -2550,7 +3176,10 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2550
3176
|
props.labels,
|
|
2551
3177
|
props.subgraphs,
|
|
2552
3178
|
props.attributes,
|
|
2553
|
-
props.renderNode
|
|
3179
|
+
props.renderNode,
|
|
3180
|
+
props.highlightOnHover,
|
|
3181
|
+
props.applyNode,
|
|
3182
|
+
props.edgeOpacity
|
|
2554
3183
|
]);
|
|
2555
3184
|
useImperativeHandle(forwardedRef, () => ({
|
|
2556
3185
|
refresh: () => {
|
|
@@ -2581,7 +3210,7 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2581
3210
|
renderer.render(layout);
|
|
2582
3211
|
}
|
|
2583
3212
|
} catch (error) {
|
|
2584
|
-
|
|
3213
|
+
log11.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 95, S: void 0 });
|
|
2585
3214
|
void projector.stop();
|
|
2586
3215
|
}
|
|
2587
3216
|
})
|
|
@@ -2601,6 +3230,49 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
2601
3230
|
}, [
|
|
2602
3231
|
projector
|
|
2603
3232
|
]);
|
|
3233
|
+
useEffect3(() => {
|
|
3234
|
+
if (!onPointerMove && !onPointerLeave) {
|
|
3235
|
+
return;
|
|
3236
|
+
}
|
|
3237
|
+
const svg = context.svg;
|
|
3238
|
+
if (!svg) {
|
|
3239
|
+
return;
|
|
3240
|
+
}
|
|
3241
|
+
const previousPointerEvents = svg.style.pointerEvents;
|
|
3242
|
+
svg.style.pointerEvents = "all";
|
|
3243
|
+
const handleMove = (event) => {
|
|
3244
|
+
if (!onPointerMove) {
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
const target = graphRef.current;
|
|
3248
|
+
const ctm = target?.getScreenCTM();
|
|
3249
|
+
if (!target || !ctm) {
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
const point = svg.createSVGPoint();
|
|
3253
|
+
point.x = event.clientX;
|
|
3254
|
+
point.y = event.clientY;
|
|
3255
|
+
const modelPoint = point.matrixTransform(ctm.inverse());
|
|
3256
|
+
onPointerMove({
|
|
3257
|
+
x: modelPoint.x,
|
|
3258
|
+
y: modelPoint.y
|
|
3259
|
+
}, event);
|
|
3260
|
+
};
|
|
3261
|
+
const handleLeave = (event) => {
|
|
3262
|
+
onPointerLeave?.(event);
|
|
3263
|
+
};
|
|
3264
|
+
svg.addEventListener("pointermove", handleMove);
|
|
3265
|
+
svg.addEventListener("pointerleave", handleLeave);
|
|
3266
|
+
return () => {
|
|
3267
|
+
svg.removeEventListener("pointermove", handleMove);
|
|
3268
|
+
svg.removeEventListener("pointerleave", handleLeave);
|
|
3269
|
+
svg.style.pointerEvents = previousPointerEvents;
|
|
3270
|
+
};
|
|
3271
|
+
}, [
|
|
3272
|
+
context,
|
|
3273
|
+
onPointerMove,
|
|
3274
|
+
onPointerLeave
|
|
3275
|
+
]);
|
|
2604
3276
|
return /* @__PURE__ */ React.createElement("g", {
|
|
2605
3277
|
ref: graphRef,
|
|
2606
3278
|
className: mx("dx-graph", classNames)
|
|
@@ -2746,30 +3418,86 @@ var hexProjection = (radius) => {
|
|
|
2746
3418
|
};
|
|
2747
3419
|
};
|
|
2748
3420
|
|
|
2749
|
-
// src/components/SVG/
|
|
2750
|
-
import React2 from "react";
|
|
3421
|
+
// src/components/SVG/FPS.tsx
|
|
3422
|
+
import React2, { useEffect as useEffect5, useState } from "react";
|
|
2751
3423
|
import { mx as mx2 } from "@dxos/ui-theme";
|
|
3424
|
+
var PADDING = 8;
|
|
3425
|
+
var FPS = ({ classNames, corner = "top-right", margin = PADDING }) => {
|
|
3426
|
+
const context = useSvgContext();
|
|
3427
|
+
const [size, setSize] = useState(context.size);
|
|
3428
|
+
const [fps, setFps] = useState(null);
|
|
3429
|
+
useEffect5(() => {
|
|
3430
|
+
setSize(context.size);
|
|
3431
|
+
return context.resized.on((ctx) => setSize(ctx.size));
|
|
3432
|
+
}, [
|
|
3433
|
+
context
|
|
3434
|
+
]);
|
|
3435
|
+
useEffect5(() => {
|
|
3436
|
+
let frames = 0;
|
|
3437
|
+
let windowStart = performance.now();
|
|
3438
|
+
let rafId = 0;
|
|
3439
|
+
const loop = (now) => {
|
|
3440
|
+
frames++;
|
|
3441
|
+
const elapsed = now - windowStart;
|
|
3442
|
+
if (elapsed >= 1e3) {
|
|
3443
|
+
setFps(frames * 1e3 / elapsed);
|
|
3444
|
+
frames = 0;
|
|
3445
|
+
windowStart = now;
|
|
3446
|
+
}
|
|
3447
|
+
rafId = requestAnimationFrame(loop);
|
|
3448
|
+
};
|
|
3449
|
+
rafId = requestAnimationFrame(loop);
|
|
3450
|
+
return () => cancelAnimationFrame(rafId);
|
|
3451
|
+
}, []);
|
|
3452
|
+
if (!size) {
|
|
3453
|
+
return null;
|
|
3454
|
+
}
|
|
3455
|
+
const halfW = size.width / 2;
|
|
3456
|
+
const halfH = size.height / 2;
|
|
3457
|
+
const left = corner === "top-left" || corner === "bottom-left";
|
|
3458
|
+
const top = corner === "top-left" || corner === "top-right";
|
|
3459
|
+
const x = left ? -halfW + margin : halfW - margin;
|
|
3460
|
+
const y = top ? -halfH + margin : halfH - margin;
|
|
3461
|
+
const textAnchor = left ? "start" : "end";
|
|
3462
|
+
const dominantBaseline = top ? "hanging" : "alphabetic";
|
|
3463
|
+
return /* @__PURE__ */ React2.createElement("g", {
|
|
3464
|
+
className: "dx-fps",
|
|
3465
|
+
style: {
|
|
3466
|
+
pointerEvents: "none"
|
|
3467
|
+
}
|
|
3468
|
+
}, /* @__PURE__ */ React2.createElement("text", {
|
|
3469
|
+
x,
|
|
3470
|
+
y,
|
|
3471
|
+
textAnchor,
|
|
3472
|
+
dominantBaseline,
|
|
3473
|
+
className: mx2("font-mono text-xs fill-neutral-500 tabular-nums", classNames)
|
|
3474
|
+
}, fps == null ? "\u2014 fps" : `${fps.toFixed(0)} fps`));
|
|
3475
|
+
};
|
|
3476
|
+
|
|
3477
|
+
// src/components/SVG/Grid.tsx
|
|
3478
|
+
import React3 from "react";
|
|
3479
|
+
import { mx as mx3 } from "@dxos/ui-theme";
|
|
2752
3480
|
var Grid = ({ classNames, ...props }) => {
|
|
2753
3481
|
const { ref } = useGrid(props);
|
|
2754
|
-
return /* @__PURE__ */
|
|
3482
|
+
return /* @__PURE__ */ React3.createElement("g", {
|
|
2755
3483
|
ref,
|
|
2756
|
-
className:
|
|
3484
|
+
className: mx3("dx-grid", classNames)
|
|
2757
3485
|
});
|
|
2758
3486
|
};
|
|
2759
3487
|
|
|
2760
3488
|
// src/components/SVG/Markers.tsx
|
|
2761
3489
|
import { select as select8 } from "d3";
|
|
2762
|
-
import
|
|
3490
|
+
import React4, { useEffect as useEffect6, useRef as useRef4 } from "react";
|
|
2763
3491
|
var Markers = ({ arrowSize, className }) => {
|
|
2764
3492
|
const ref = useRef4(null);
|
|
2765
|
-
|
|
3493
|
+
useEffect6(() => {
|
|
2766
3494
|
select8(ref.current).call(createMarkers({
|
|
2767
3495
|
arrowSize
|
|
2768
3496
|
}));
|
|
2769
3497
|
}, [
|
|
2770
3498
|
ref
|
|
2771
3499
|
]);
|
|
2772
|
-
return /* @__PURE__ */
|
|
3500
|
+
return /* @__PURE__ */ React4.createElement("defs", {
|
|
2773
3501
|
ref,
|
|
2774
3502
|
className
|
|
2775
3503
|
});
|
|
@@ -2777,15 +3505,16 @@ var Markers = ({ arrowSize, className }) => {
|
|
|
2777
3505
|
|
|
2778
3506
|
// src/components/SVG/Root.tsx
|
|
2779
3507
|
import { select as select9 } from "d3";
|
|
2780
|
-
import
|
|
2781
|
-
import { composableProps
|
|
3508
|
+
import React5, { forwardRef as forwardRef2, useEffect as useEffect7, useImperativeHandle as useImperativeHandle2, useMemo as useMemo4, useState as useState2 } from "react";
|
|
3509
|
+
import { composableProps } from "@dxos/react-ui";
|
|
3510
|
+
import { mx as mx4 } from "@dxos/ui-theme";
|
|
2782
3511
|
var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props }, ref) => {
|
|
2783
|
-
const [container, setContainer] =
|
|
2784
|
-
const [size, setSize] =
|
|
3512
|
+
const [container, setContainer] = useState2(null);
|
|
3513
|
+
const [size, setSize] = useState2({
|
|
2785
3514
|
width: 0,
|
|
2786
3515
|
height: 0
|
|
2787
3516
|
});
|
|
2788
|
-
|
|
3517
|
+
useEffect7(() => {
|
|
2789
3518
|
if (!container) {
|
|
2790
3519
|
return;
|
|
2791
3520
|
}
|
|
@@ -2823,7 +3552,7 @@ var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props },
|
|
|
2823
3552
|
useImperativeHandle2(ref, () => context, [
|
|
2824
3553
|
context
|
|
2825
3554
|
]);
|
|
2826
|
-
|
|
3555
|
+
useEffect7(() => {
|
|
2827
3556
|
if (width && height) {
|
|
2828
3557
|
context.setSize({
|
|
2829
3558
|
width,
|
|
@@ -2837,22 +3566,22 @@ var Root = /* @__PURE__ */ forwardRef2(({ children, scale, centered, ...props },
|
|
|
2837
3566
|
height
|
|
2838
3567
|
]);
|
|
2839
3568
|
const ready = width !== 0 && height !== 0;
|
|
2840
|
-
return /* @__PURE__ */
|
|
3569
|
+
return /* @__PURE__ */ React5.createElement(SVGContextProvider, {
|
|
2841
3570
|
value: context
|
|
2842
|
-
}, /* @__PURE__ */
|
|
3571
|
+
}, /* @__PURE__ */ React5.createElement("div", {
|
|
2843
3572
|
...composableProps(props, {
|
|
2844
3573
|
classNames: "dx-expander"
|
|
2845
3574
|
}),
|
|
2846
3575
|
ref: setContainer
|
|
2847
|
-
}, /* @__PURE__ */
|
|
3576
|
+
}, /* @__PURE__ */ React5.createElement("svg", {
|
|
2848
3577
|
xmlns: "http://www.w3.org/2000/svg",
|
|
2849
3578
|
ref: context.ref,
|
|
2850
|
-
className:
|
|
3579
|
+
className: mx4("transition-opacity opacity-0 duration-1000", ready && "opacity-100")
|
|
2851
3580
|
}, ready && children)));
|
|
2852
3581
|
});
|
|
2853
3582
|
|
|
2854
3583
|
// src/components/SVG/Zoom.tsx
|
|
2855
|
-
import
|
|
3584
|
+
import React6, { memo, useMemo as useMemo5 } from "react";
|
|
2856
3585
|
var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
2857
3586
|
const options = useMemo5(() => ({
|
|
2858
3587
|
extent
|
|
@@ -2860,7 +3589,7 @@ var Zoom = /* @__PURE__ */ memo(({ extent, className, children }) => {
|
|
|
2860
3589
|
JSON.stringify(extent)
|
|
2861
3590
|
]);
|
|
2862
3591
|
const zoom2 = useZoom(options);
|
|
2863
|
-
return /* @__PURE__ */
|
|
3592
|
+
return /* @__PURE__ */ React6.createElement("g", {
|
|
2864
3593
|
ref: zoom2.ref,
|
|
2865
3594
|
className
|
|
2866
3595
|
}, children);
|
|
@@ -2873,7 +3602,8 @@ var SVG = {
|
|
|
2873
3602
|
Markers,
|
|
2874
3603
|
Mesh,
|
|
2875
3604
|
Zoom,
|
|
2876
|
-
Graph
|
|
3605
|
+
Graph,
|
|
3606
|
+
FPS
|
|
2877
3607
|
};
|
|
2878
3608
|
|
|
2879
3609
|
// src/fx/pulsar.ts
|
|
@@ -2912,12 +3642,17 @@ export {
|
|
|
2912
3642
|
GraphForceProjector,
|
|
2913
3643
|
GraphHierarchicalProjector,
|
|
2914
3644
|
GraphLatticeProjector,
|
|
3645
|
+
GraphPlexusProjector,
|
|
2915
3646
|
GraphProjector,
|
|
2916
3647
|
GraphRadialProjector,
|
|
2917
3648
|
GraphRelationalProjector,
|
|
2918
3649
|
GraphRenderer,
|
|
3650
|
+
GraphSwarmProjector,
|
|
2919
3651
|
GridController,
|
|
2920
3652
|
Mesh,
|
|
3653
|
+
PLEXUS_NODE_TYPE_FOCUS,
|
|
3654
|
+
PLEXUS_NODE_TYPE_OBJECT,
|
|
3655
|
+
PLEXUS_NODE_TYPE_RELATION,
|
|
2921
3656
|
Projector,
|
|
2922
3657
|
Pulsar,
|
|
2923
3658
|
Renderer,
|
|
@@ -2928,6 +3663,9 @@ export {
|
|
|
2928
3663
|
Screen,
|
|
2929
3664
|
Vector,
|
|
2930
3665
|
ZoomHandler,
|
|
3666
|
+
appendRadialGroupLabel,
|
|
3667
|
+
appendRadialLeafLabel,
|
|
3668
|
+
appendRootLabel,
|
|
2931
3669
|
createGraphDrag,
|
|
2932
3670
|
createMarkers,
|
|
2933
3671
|
defaultForceOptions,
|