@dxos/plugin-explorer 0.8.4-main.abd8ff62ef → 0.8.4-main.bc2380dfbc
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/neutral/ExplorerArticle-EW2MBCRK.mjs +141 -0
- package/dist/lib/neutral/ExplorerArticle-EW2MBCRK.mjs.map +7 -0
- package/dist/lib/neutral/ExplorerPlugin.mjs +10 -0
- package/dist/lib/neutral/capabilities/index.mjs +11 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/{browser/types/index.mjs → neutral/chunk-7SPMPHRS.mjs} +7 -7
- package/dist/lib/neutral/chunk-7SPMPHRS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-GRJXLL4Z.mjs +25 -0
- package/dist/lib/neutral/chunk-GRJXLL4Z.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/components/index.mjs +661 -297
- package/dist/lib/{browser → neutral}/components/index.mjs.map +4 -4
- package/dist/lib/neutral/containers/index.mjs +9 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/neutral/create-object-F6TKVAGV.mjs +39 -0
- package/dist/lib/neutral/create-object-F6TKVAGV.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/hooks/index.mjs +11 -6
- package/dist/lib/neutral/hooks/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +14 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/{browser/index.mjs → neutral/plugin.mjs} +3 -4
- package/dist/lib/{browser/index.mjs.map → neutral/plugin.mjs.map} +3 -3
- package/dist/lib/neutral/react-surface-APBW2VQG.mjs +26 -0
- package/dist/lib/neutral/react-surface-APBW2VQG.mjs.map +7 -0
- package/dist/lib/neutral/testing.mjs +8 -0
- package/dist/lib/neutral/testing.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +33 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +10 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/types/src/ExplorerPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/create-object.d.ts +11 -0
- package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +6 -0
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/components/Chart/Chart.stories.d.ts +4 -1
- package/dist/types/src/components/Chart/Chart.stories.d.ts.map +1 -1
- package/dist/types/src/components/Globe/Globe.stories.d.ts +5 -2
- package/dist/types/src/components/Globe/Globe.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/CanvasForceGraph.d.ts +13 -0
- package/dist/types/src/components/Graph/CanvasForceGraph.d.ts.map +1 -0
- package/dist/types/src/components/Graph/{D3ForceGraph.stories.d.ts → CanvasForceGraph.stories.d.ts} +2 -2
- package/dist/types/src/components/Graph/CanvasForceGraph.stories.d.ts.map +1 -0
- package/dist/types/src/components/Graph/ForceGraph.d.ts +12 -5
- package/dist/types/src/components/Graph/ForceGraph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/ForceGraph.stories.d.ts +3 -1
- package/dist/types/src/components/Graph/ForceGraph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Graph/{adapter.d.ts → graph-adapter.d.ts} +1 -1
- package/dist/types/src/components/Graph/graph-adapter.d.ts.map +1 -0
- package/dist/types/src/components/Graph/index.d.ts +1 -1
- package/dist/types/src/components/Graph/index.d.ts.map +1 -1
- package/dist/types/src/components/Tree/EdgeBundling.stories.d.ts +21 -0
- package/dist/types/src/components/Tree/EdgeBundling.stories.d.ts.map +1 -0
- package/dist/types/src/components/Tree/Tree.d.ts +20 -23
- package/dist/types/src/components/Tree/Tree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.stories.d.ts +5 -12
- package/dist/types/src/components/Tree/Tree.stories.d.ts.map +1 -1
- package/dist/types/src/components/Tree/index.d.ts +3 -0
- package/dist/types/src/components/Tree/index.d.ts.map +1 -1
- package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts +35 -2
- package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts.map +1 -1
- package/dist/types/src/components/Tree/layout/RadialTree.d.ts +35 -2
- package/dist/types/src/components/Tree/layout/RadialTree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/layout/TidyTree.d.ts +24 -2
- package/dist/types/src/components/Tree/layout/TidyTree.d.ts.map +1 -1
- package/dist/types/src/components/Tree/layout/hierarchy.d.ts +17 -0
- package/dist/types/src/components/Tree/layout/hierarchy.d.ts.map +1 -0
- package/dist/types/src/components/Tree/layout/index.d.ts +5 -4
- package/dist/types/src/components/Tree/layout/index.d.ts.map +1 -1
- package/dist/types/src/components/Tree/layout/slots.d.ts +7 -0
- package/dist/types/src/components/Tree/layout/slots.d.ts.map +1 -0
- package/dist/types/src/components/Tree/layout/useContainerSize.d.ts +15 -0
- package/dist/types/src/components/Tree/layout/useContainerSize.d.ts.map +1 -0
- package/dist/types/src/components/Tree/space-graph-adapter.d.ts +32 -0
- package/dist/types/src/components/Tree/space-graph-adapter.d.ts.map +1 -0
- package/dist/types/src/components/Tree/testing/index.d.ts +1 -0
- package/dist/types/src/components/Tree/testing/index.d.ts.map +1 -1
- package/dist/types/src/components/Tree/testing/relations.d.ts +47 -0
- package/dist/types/src/components/Tree/testing/relations.d.ts.map +1 -0
- package/dist/types/src/components/Tree/types/types.d.ts +14 -4
- package/dist/types/src/components/Tree/types/types.d.ts.map +1 -1
- package/dist/types/src/containers/ExplorerArticle/ExplorerArticle.d.ts +8 -0
- package/dist/types/src/containers/ExplorerArticle/ExplorerArticle.d.ts.map +1 -0
- package/dist/types/src/containers/ExplorerArticle/ExplorerArticle.stories.d.ts +24 -0
- package/dist/types/src/containers/ExplorerArticle/ExplorerArticle.stories.d.ts.map +1 -0
- package/dist/types/src/containers/ExplorerArticle/index.d.ts +2 -0
- package/dist/types/src/containers/ExplorerArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +1 -1
- package/dist/types/src/containers/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useGraphModel.d.ts +2 -2
- package/dist/types/src/hooks/useGraphModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +3 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +2 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/types/Graph.d.ts +1 -2
- package/dist/types/src/types/Graph.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +94 -67
- package/src/ExplorerPlugin.test.ts +2 -2
- package/src/ExplorerPlugin.tsx +3 -33
- package/src/capabilities/create-object.ts +36 -0
- package/src/capabilities/index.ts +1 -0
- package/src/capabilities/react-surface.tsx +2 -2
- package/src/components/Chart/Chart.stories.tsx +14 -20
- package/src/components/Globe/Globe.stories.tsx +17 -19
- package/src/components/Graph/CanvasForceGraph.stories.tsx +83 -0
- package/src/components/Graph/CanvasForceGraph.tsx +124 -0
- package/src/components/Graph/ForceGraph.stories.tsx +69 -37
- package/src/components/Graph/ForceGraph.tsx +104 -85
- package/src/components/Graph/index.ts +1 -1
- package/src/components/Tree/EdgeBundling.stories.tsx +144 -0
- package/src/components/Tree/Tree.stories.tsx +17 -38
- package/src/components/Tree/Tree.tsx +69 -100
- package/src/components/Tree/index.ts +3 -0
- package/src/components/Tree/layout/HierarchicalEdgeBundling.tsx +277 -0
- package/src/components/Tree/layout/RadialTree.tsx +237 -0
- package/src/components/Tree/layout/TidyTree.tsx +246 -0
- package/src/components/Tree/layout/hierarchy.ts +32 -0
- package/src/components/Tree/layout/index.ts +5 -5
- package/src/components/Tree/layout/slots.ts +19 -0
- package/src/components/Tree/layout/useContainerSize.ts +43 -0
- package/src/components/Tree/space-graph-adapter.ts +96 -0
- package/src/components/Tree/testing/index.ts +1 -0
- package/src/components/Tree/testing/relations.ts +182 -0
- package/src/components/Tree/types/types.ts +38 -29
- package/src/containers/ExplorerArticle/ExplorerArticle.stories.tsx +119 -0
- package/src/containers/ExplorerArticle/ExplorerArticle.tsx +153 -0
- package/src/containers/ExplorerArticle/index.ts +5 -0
- package/src/containers/index.ts +1 -1
- package/src/hooks/useGraphModel.ts +10 -6
- package/src/index.ts +1 -6
- package/src/plugin.ts +9 -0
- package/src/testing.ts +7 -0
- package/src/types/ExplorerAction.ts +1 -1
- package/src/types/Graph.ts +1 -2
- package/dist/lib/browser/hooks/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/types/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6EUBRHHX.mjs +0 -26
- package/dist/lib/node-esm/chunk-6EUBRHHX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/components/index.mjs +0 -11255
- package/dist/lib/node-esm/components/index.mjs.map +0 -7
- package/dist/lib/node-esm/hooks/index.mjs +0 -41
- package/dist/lib/node-esm/hooks/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -14
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/meta.mjs +0 -9
- package/dist/lib/node-esm/types/index.mjs +0 -73
- package/dist/lib/node-esm/types/index.mjs.map +0 -7
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts +0 -15
- package/dist/types/src/components/Graph/D3ForceGraph.d.ts.map +0 -1
- package/dist/types/src/components/Graph/D3ForceGraph.stories.d.ts.map +0 -1
- package/dist/types/src/components/Graph/adapter.d.ts.map +0 -1
- package/dist/types/src/components/Graph/testing.d.ts +0 -14
- package/dist/types/src/components/Graph/testing.d.ts.map +0 -1
- package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts +0 -6
- package/dist/types/src/containers/ExplorerContainer/ExplorerContainer.d.ts.map +0 -1
- package/dist/types/src/containers/ExplorerContainer/index.d.ts +0 -2
- package/dist/types/src/containers/ExplorerContainer/index.d.ts.map +0 -1
- package/src/components/Graph/D3ForceGraph.stories.tsx +0 -83
- package/src/components/Graph/D3ForceGraph.tsx +0 -108
- package/src/components/Graph/testing.ts +0 -58
- package/src/components/Tree/layout/HierarchicalEdgeBundling.ts +0 -162
- package/src/components/Tree/layout/RadialTree.ts +0 -94
- package/src/components/Tree/layout/TidyTree.ts +0 -101
- package/src/containers/ExplorerContainer/ExplorerContainer.tsx +0 -53
- package/src/containers/ExplorerContainer/index.ts +0 -5
- /package/dist/lib/{browser/chunk-J5LGTIGS.mjs.map → neutral/ExplorerPlugin.mjs.map} +0 -0
- /package/dist/lib/{browser → neutral}/chunk-HPIS2WXY.mjs +0 -0
- /package/dist/lib/{browser → neutral}/chunk-HPIS2WXY.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
- /package/dist/lib/{browser/meta.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/{node-esm/chunk-HSLMI22Q.mjs.map → neutral/index.mjs.map} +0 -0
- /package/dist/lib/{browser → neutral}/meta.mjs +0 -0
- /package/dist/lib/{node-esm → neutral}/meta.mjs.map +0 -0
- /package/src/components/Graph/{adapter.ts → graph-adapter.ts} +0 -0
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
// Copyright 2022 Observable, Inc.
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { cluster, curveBundle, hierarchy, lineRadial, select } from 'd3';
|
|
7
|
-
import { type HierarchyNode } from 'd3-hierarchy';
|
|
8
|
-
|
|
9
|
-
import { type TreeOptions } from '../Tree';
|
|
10
|
-
import { type TreeNode } from '../types';
|
|
11
|
-
|
|
12
|
-
// Create hierarchical ID.
|
|
13
|
-
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
14
|
-
const getId = (node: HierarchyNode<TreeNode>): string =>
|
|
15
|
-
`${node.parent ? getId(node.parent) + '/' : ''}${node.data.id.slice(0, 4)}`;
|
|
16
|
-
|
|
17
|
-
// https://github.com/d3/d3-hierarchy
|
|
18
|
-
// https://observablehq.com/@d3/hierarchical-edge-bundling?intent=fork
|
|
19
|
-
const HierarchicalEdgeBundling = (s: SVGSVGElement, data: TreeNode, options: TreeOptions) => {
|
|
20
|
-
const svg = select(s);
|
|
21
|
-
svg.selectAll('*').remove();
|
|
22
|
-
|
|
23
|
-
const { radius = 600, padding = 100, slots } = options;
|
|
24
|
-
|
|
25
|
-
// https://d3js.org/d3-hierarchy/hierarchy
|
|
26
|
-
const root = hierarchy(flatten(data));
|
|
27
|
-
// .sort((a, b) => ascending(a.height, b.height) || ascending(getName(a.data), getName(b.data)));
|
|
28
|
-
|
|
29
|
-
const tree = cluster<TreeNode>().size([2 * Math.PI, radius - padding]);
|
|
30
|
-
const layout = tree(addLinks(root));
|
|
31
|
-
|
|
32
|
-
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
33
|
-
const node = svg
|
|
34
|
-
.append('g')
|
|
35
|
-
.selectAll()
|
|
36
|
-
.data(layout.leaves())
|
|
37
|
-
.join('g')
|
|
38
|
-
.attr('transform', (d) => `rotate(${d.x * (180 / Math.PI) - 90}) translate(${d.y},0)`)
|
|
39
|
-
.append('text')
|
|
40
|
-
.attr('class', slots?.text ?? '')
|
|
41
|
-
.attr('dy', '0.31em') // TODO(burdon): Based on font size.
|
|
42
|
-
.attr('x', (d) => (d.x < Math.PI ? 6 : -6))
|
|
43
|
-
.attr('text-anchor', (d) => (d.x < Math.PI ? 'start' : 'end'))
|
|
44
|
-
.attr('transform', (d) => (d.x >= Math.PI ? 'rotate(180)' : null))
|
|
45
|
-
// .text((d: any) => d.data.id)
|
|
46
|
-
// .each(function (d: any) {
|
|
47
|
-
// d.text = this;
|
|
48
|
-
// })
|
|
49
|
-
// .on('mouseover', overed)
|
|
50
|
-
// .on('mouseout', outed)
|
|
51
|
-
.call(
|
|
52
|
-
(text) => text.text((d: any) => d.data.id.slice(0, 8)),
|
|
53
|
-
// .text((d: any) => `${getId(d)} [${[(d as any).outgoing?.length ?? 0]}]`),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
// https://d3js.org/d3-shape/radial-line
|
|
57
|
-
const line = lineRadial()
|
|
58
|
-
.curve(curveBundle.beta(0.85))
|
|
59
|
-
.radius((d: any) => d.y)
|
|
60
|
-
.angle((d: any) => d.x);
|
|
61
|
-
|
|
62
|
-
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
63
|
-
const links = svg
|
|
64
|
-
.append('g')
|
|
65
|
-
.selectAll()
|
|
66
|
-
.data(layout.leaves().flatMap((leaf: any) => leaf.outgoing))
|
|
67
|
-
.join('path')
|
|
68
|
-
.style('mix-blend-mode', 'multiply')
|
|
69
|
-
.attr('class', slots?.path ?? '')
|
|
70
|
-
.attr('d', ([i, o]) => {
|
|
71
|
-
return line(i.path(o));
|
|
72
|
-
})
|
|
73
|
-
.each(function (d) {
|
|
74
|
-
d.path = this;
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// function overed(event: any, d: X) {
|
|
78
|
-
// link.style('mix-blend-mode', null);
|
|
79
|
-
// select(this).attr('font-weight', 'bold');
|
|
80
|
-
// selectAll(d.incoming.map((d) => d.path))
|
|
81
|
-
// .attr('stroke', color.in)
|
|
82
|
-
// .raise();
|
|
83
|
-
// selectAll((d as any).incoming.map(([d]) => d.text))
|
|
84
|
-
// .attr('fill', color.in)
|
|
85
|
-
// .attr('font-weight', 'bold');
|
|
86
|
-
// selectAll(d.outgoing.map((d) => d.path))
|
|
87
|
-
// .attr('stroke', color.out)
|
|
88
|
-
// .raise();
|
|
89
|
-
// selectAll(d.outgoing.map(([, d]) => d.text))
|
|
90
|
-
// .attr('fill', color.out)
|
|
91
|
-
// .attr('font-weight', 'bold');
|
|
92
|
-
// }
|
|
93
|
-
|
|
94
|
-
// function outed(event: any, d: HierarchyNode<Datum>) {
|
|
95
|
-
// // @ts-ignore
|
|
96
|
-
// select(this).attr('font-weight', null);
|
|
97
|
-
// selectAll(d.incoming.map((d) => d.path)).attr('stroke', null);
|
|
98
|
-
// selectAll(d.incoming.map(([d]) => d.text))
|
|
99
|
-
// .attr('fill', null)
|
|
100
|
-
// .attr('font-weight', null);
|
|
101
|
-
// selectAll(d.outgoing.map((d) => d.path)).attr('stroke', null);
|
|
102
|
-
// selectAll(d.outgoing.map(([, d]) => d.text))
|
|
103
|
-
// .attr('fill', null)
|
|
104
|
-
// .attr('font-weight', null);
|
|
105
|
-
// }
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// Monkey-patch with incoming/outgoing nodes.
|
|
109
|
-
const addLinks = (root: HierarchyNode<TreeNode>) => {
|
|
110
|
-
// Map of nodes indexed by ID.
|
|
111
|
-
const nodes = new Map(root.descendants().map((d) => [d.data.id, d]));
|
|
112
|
-
const parents = root.descendants().reduce((map, d) => {
|
|
113
|
-
if (d.children?.length) {
|
|
114
|
-
map.set(d.data.id, d);
|
|
115
|
-
}
|
|
116
|
-
return map;
|
|
117
|
-
}, new Map<string, HierarchyNode<TreeNode>>());
|
|
118
|
-
|
|
119
|
-
for (const d of root.leaves()) {
|
|
120
|
-
// (d as any).incoming = [];
|
|
121
|
-
const parent = parents.get(d.data.id);
|
|
122
|
-
if (parent) {
|
|
123
|
-
// Skip the first node which is a placeholder created by flatten().
|
|
124
|
-
(d as any).outgoing =
|
|
125
|
-
parent.data.children?.slice(1).map((child) => {
|
|
126
|
-
return [d, nodes.get(child.id)!];
|
|
127
|
-
}) ?? [];
|
|
128
|
-
} else {
|
|
129
|
-
(d as any).outgoing = [];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// for (const d of root.leaves()) {
|
|
134
|
-
// for (const [_, o] of (d as any).outgoing) {
|
|
135
|
-
// o.incoming.push(o);
|
|
136
|
-
// }
|
|
137
|
-
// }
|
|
138
|
-
|
|
139
|
-
return root;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* We are using a hierarchy in order to group nodes by parent, but we want the parent
|
|
144
|
-
* nodes to be positioned at the first level along with all descendents.
|
|
145
|
-
* So we add a placeholder for all parents at the head of each group.
|
|
146
|
-
* @param node
|
|
147
|
-
*/
|
|
148
|
-
const flatten = (node: TreeNode) => {
|
|
149
|
-
const clone: TreeNode = {
|
|
150
|
-
id: node.id,
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// TODO(burdon): NOTE: Should exclude schema (since requires a tree).
|
|
154
|
-
if (node.children?.length) {
|
|
155
|
-
const children = node.children.map((child) => flatten(child));
|
|
156
|
-
clone.children = [{ id: node.id }, ...children];
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return clone;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export default HierarchicalEdgeBundling;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
// Copyright 2022 Observable, Inc.
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { hierarchy, linkRadial, select, tree } from 'd3';
|
|
7
|
-
|
|
8
|
-
import { type TreeOptions } from '../Tree';
|
|
9
|
-
|
|
10
|
-
// Released under the ISC license.
|
|
11
|
-
// https://observablehq.com/@d3/radial-tree
|
|
12
|
-
// https://observablehq.com/@d3/tree
|
|
13
|
-
const RadialTree = (s: SVGSVGElement, data: any, options: TreeOptions) => {
|
|
14
|
-
const svg = select(s);
|
|
15
|
-
svg.selectAll('*').remove();
|
|
16
|
-
|
|
17
|
-
const {
|
|
18
|
-
label, // given a node d, returns the display name
|
|
19
|
-
radius = 400,
|
|
20
|
-
r = 4, // radius of nodes
|
|
21
|
-
slots,
|
|
22
|
-
} = options;
|
|
23
|
-
|
|
24
|
-
const arc = 2 * Math.PI;
|
|
25
|
-
|
|
26
|
-
const root = hierarchy(data);
|
|
27
|
-
|
|
28
|
-
// Sort the nodes.
|
|
29
|
-
// if (sort) {
|
|
30
|
-
// root.sort(sort);
|
|
31
|
-
// }
|
|
32
|
-
|
|
33
|
-
// Compute labels and titles.
|
|
34
|
-
const descendants = root.descendants();
|
|
35
|
-
const getLabel = label === null ? null : descendants.map((d) => label(d.data));
|
|
36
|
-
|
|
37
|
-
// Compute the layout.
|
|
38
|
-
const layout = tree()
|
|
39
|
-
.size([arc, radius])
|
|
40
|
-
.separation((a: any, b: any) => (a.parent === b.parent ? 1 : 2) / a.depth);
|
|
41
|
-
layout(root);
|
|
42
|
-
|
|
43
|
-
// Links.
|
|
44
|
-
svg
|
|
45
|
-
.append('g')
|
|
46
|
-
.selectAll('path')
|
|
47
|
-
.data(root.links())
|
|
48
|
-
.join('path')
|
|
49
|
-
.attr('class', slots?.path ?? '')
|
|
50
|
-
.attr(
|
|
51
|
-
'd',
|
|
52
|
-
linkRadial()
|
|
53
|
-
.angle((d: any) => d.x + Math.PI / 2)
|
|
54
|
-
.radius((d: any) => d.y) as any,
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
// Nodes.
|
|
58
|
-
const node = svg
|
|
59
|
-
.append('g')
|
|
60
|
-
.selectAll('a')
|
|
61
|
-
.data(root.descendants())
|
|
62
|
-
.join('a')
|
|
63
|
-
// .attr('xlink:href', link == null ? null : (d) => link(d.data, d))
|
|
64
|
-
// .attr('target', link == null ? null : linkTarget)
|
|
65
|
-
.attr('transform', (d: any) => `rotate(${(d.x * 180) / Math.PI}) translate(${d.y},0)`);
|
|
66
|
-
|
|
67
|
-
node
|
|
68
|
-
.append('circle')
|
|
69
|
-
.attr('class', slots?.node ?? '')
|
|
70
|
-
.attr('r', r);
|
|
71
|
-
|
|
72
|
-
// if (title != null) {
|
|
73
|
-
// node.append('title').text((d) => title(d.data, d));
|
|
74
|
-
// }
|
|
75
|
-
|
|
76
|
-
// Text.
|
|
77
|
-
if (getLabel) {
|
|
78
|
-
node
|
|
79
|
-
.append('text')
|
|
80
|
-
.attr('transform', (d: any) => `rotate(${d.x >= Math.PI ? 180 : 0})`)
|
|
81
|
-
.attr('dy', '0.32em')
|
|
82
|
-
// eslint-disable-next-line no-mixed-operators
|
|
83
|
-
.attr('x', (d: any) => (d.x < Math.PI === !d.children ? 6 : -6))
|
|
84
|
-
// eslint-disable-next-line no-mixed-operators
|
|
85
|
-
.attr('text-anchor', (d: any) => (d.x < Math.PI === !d.children ? 'start' : 'end'))
|
|
86
|
-
// .attr('paint-order', 'stroke')
|
|
87
|
-
.attr('class', slots?.text ?? '')
|
|
88
|
-
.text((d, i) => getLabel[i]);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return svg.node();
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export default RadialTree;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
// Copyright 2021 Observable, Inc.
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { curveBumpX, hierarchy, link, select, tree } from 'd3';
|
|
7
|
-
|
|
8
|
-
import { type TreeOptions } from '../Tree';
|
|
9
|
-
|
|
10
|
-
// Released under the ISC license.
|
|
11
|
-
// https://observablehq.com/@d3/tree
|
|
12
|
-
const TidyTree = (s: SVGSVGElement, data: any, options: TreeOptions) => {
|
|
13
|
-
const svg = select(s);
|
|
14
|
-
svg.selectAll('*').remove();
|
|
15
|
-
|
|
16
|
-
const { label, width, height, r = 4, padding = 4, margin = 60, slots } = options;
|
|
17
|
-
|
|
18
|
-
const root = hierarchy(data);
|
|
19
|
-
|
|
20
|
-
// Compute labels and titles.
|
|
21
|
-
const descendants = root.descendants();
|
|
22
|
-
const getLabel = label == null ? null : descendants.map((d) => label(d.data));
|
|
23
|
-
|
|
24
|
-
// Compute the layout.
|
|
25
|
-
const dx = 16;
|
|
26
|
-
const dy = width / (root.height + padding);
|
|
27
|
-
const layout = tree().nodeSize([dx, dy]);
|
|
28
|
-
layout(root);
|
|
29
|
-
|
|
30
|
-
// Center the tree.
|
|
31
|
-
let x0 = Infinity;
|
|
32
|
-
let x1 = -x0;
|
|
33
|
-
let y0 = Infinity;
|
|
34
|
-
let y1 = -y0;
|
|
35
|
-
root.each((d: any) => {
|
|
36
|
-
if (d.x > x1) {
|
|
37
|
-
x1 = d.x;
|
|
38
|
-
}
|
|
39
|
-
if (d.x < x0) {
|
|
40
|
-
x0 = d.x;
|
|
41
|
-
}
|
|
42
|
-
if (d.y > y1) {
|
|
43
|
-
y1 = d.y;
|
|
44
|
-
}
|
|
45
|
-
if (d.y < y0) {
|
|
46
|
-
y0 = d.y;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// TODO(burdon): Option to expand.
|
|
51
|
-
// NOTE: x and y are flipped.
|
|
52
|
-
const sx = Math.min(2, Math.max(1, (height - margin * 2) / (x1 - x0)));
|
|
53
|
-
const oy = -(width - (y1 - y0)) / 2;
|
|
54
|
-
|
|
55
|
-
// Links.
|
|
56
|
-
svg
|
|
57
|
-
.append('g')
|
|
58
|
-
.selectAll('path')
|
|
59
|
-
.data(root.links())
|
|
60
|
-
.join('path')
|
|
61
|
-
.attr('class', slots?.path ?? '')
|
|
62
|
-
.attr(
|
|
63
|
-
'd',
|
|
64
|
-
link(curveBumpX)
|
|
65
|
-
.x((d: any) => d.y + oy)
|
|
66
|
-
.y((d: any) => d.x * sx) as any,
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// Nodes.
|
|
70
|
-
const node = svg
|
|
71
|
-
.append('g')
|
|
72
|
-
.selectAll('a')
|
|
73
|
-
.data(root.descendants())
|
|
74
|
-
.join('a')
|
|
75
|
-
// .attr('xlink:href', link == null ? null : (d) => link(d.data, d))
|
|
76
|
-
// .attr('target', link == null ? null : linkTarget)
|
|
77
|
-
.attr('transform', (d: any) => `translate(${d.y + oy},${d.x * sx})`);
|
|
78
|
-
|
|
79
|
-
node
|
|
80
|
-
.append('circle')
|
|
81
|
-
.attr('class', slots?.node ?? '')
|
|
82
|
-
.attr('r', r);
|
|
83
|
-
|
|
84
|
-
// if (title != null) {
|
|
85
|
-
// node.append('title').text((d) => title(d.data, d));
|
|
86
|
-
// }
|
|
87
|
-
|
|
88
|
-
if (getLabel) {
|
|
89
|
-
node
|
|
90
|
-
.append('text')
|
|
91
|
-
|
|
92
|
-
.attr('dy', '0.32em')
|
|
93
|
-
.attr('x', (d) => (d.children ? -6 : 6))
|
|
94
|
-
.attr('text-anchor', (d) => (d.children ? 'end' : 'start'))
|
|
95
|
-
// .attr('paint-order', 'stroke')
|
|
96
|
-
.attr('class', slots?.text ?? '')
|
|
97
|
-
.text((d, i) => getLabel[i]);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export default TidyTree;
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
8
|
-
import { type Filter } from '@dxos/echo';
|
|
9
|
-
import { type View } from '@dxos/echo';
|
|
10
|
-
import { QueryBuilder } from '@dxos/echo-query';
|
|
11
|
-
import { useGlobalSearch } from '@dxos/plugin-search';
|
|
12
|
-
import { getSpace, useObject } from '@dxos/react-client/echo';
|
|
13
|
-
import { Panel, Toolbar } from '@dxos/react-ui';
|
|
14
|
-
import { QueryEditor, type QueryEditorProps } from '@dxos/react-ui-components';
|
|
15
|
-
|
|
16
|
-
import { D3ForceGraph } from '#components';
|
|
17
|
-
import { useGraphModel } from '#hooks';
|
|
18
|
-
|
|
19
|
-
export type ExplorerContainerProps = AppSurface.ObjectArticleProps<View.View>;
|
|
20
|
-
|
|
21
|
-
export const ExplorerContainer = ({ role, subject, attendableId: _attendableId }: ExplorerContainerProps) => {
|
|
22
|
-
const [view] = useObject(subject);
|
|
23
|
-
const space = view && getSpace(view);
|
|
24
|
-
const [filter, setFilter] = useState<Filter.Any>();
|
|
25
|
-
const model = useGraphModel(space, filter);
|
|
26
|
-
const { match } = useGlobalSearch();
|
|
27
|
-
|
|
28
|
-
const builder = useMemo(() => new QueryBuilder(), []);
|
|
29
|
-
const handleChange = useCallback<NonNullable<QueryEditorProps['onChange']>>((value) => {
|
|
30
|
-
setFilter(builder.build(value).filter);
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
const showToolbar = role === 'article';
|
|
34
|
-
|
|
35
|
-
if (!space || !model) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<Panel.Root role={role}>
|
|
41
|
-
{showToolbar && (
|
|
42
|
-
<Panel.Toolbar asChild>
|
|
43
|
-
<Toolbar.Root>
|
|
44
|
-
<QueryEditor db={space.db} onChange={handleChange} />
|
|
45
|
-
</Toolbar.Root>
|
|
46
|
-
</Panel.Toolbar>
|
|
47
|
-
)}
|
|
48
|
-
<Panel.Content asChild>
|
|
49
|
-
<D3ForceGraph model={model} match={match} />
|
|
50
|
-
</Panel.Content>
|
|
51
|
-
</Panel.Root>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|