@dxos/react-ui-graph 0.9.1-main.c7dcc2e112 → 0.9.1-staging.ee54ba693a
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 +753 -15
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +753 -15
- 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.stories.d.ts +2 -2
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/Tree/Tree.d.ts +26 -0
- package/dist/types/src/components/Tree/Tree.d.ts.map +1 -0
- package/dist/types/src/components/Tree/index.d.ts +4 -0
- package/dist/types/src/components/Tree/index.d.ts.map +1 -0
- package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts +40 -0
- package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts.map +1 -0
- package/dist/types/src/components/Tree/layout/RadialTree.d.ts +37 -0
- package/dist/types/src/components/Tree/layout/RadialTree.d.ts.map +1 -0
- package/dist/types/src/components/Tree/layout/TidyTree.d.ts +26 -0
- package/dist/types/src/components/Tree/layout/TidyTree.d.ts.map +1 -0
- 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 +7 -0
- package/dist/types/src/components/Tree/layout/index.d.ts.map +1 -0
- package/dist/types/src/components/Tree/layout/slots.d.ts +13 -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/types.d.ts +11 -0
- package/dist/types/src/components/Tree/types.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +2 -2
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-tree-projector.d.ts +40 -0
- package/dist/types/src/graph/projector/graph-tree-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/index.d.ts +1 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -22
- package/src/components/Graph/Graph.stories.tsx +2 -2
- package/src/components/SVG/SVG.tsx +1 -1
- package/src/components/Tree/Tree.tsx +85 -0
- package/src/components/Tree/index.ts +7 -0
- package/src/components/Tree/layout/HierarchicalEdgeBundling.tsx +332 -0
- package/src/components/Tree/layout/RadialTree.tsx +240 -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 +10 -0
- package/src/components/Tree/layout/slots.ts +25 -0
- package/src/components/Tree/layout/useContainerSize.ts +43 -0
- package/src/components/Tree/types.ts +14 -0
- package/src/components/index.ts +1 -0
- package/src/fx/fx.stories.tsx +3 -3
- package/src/graph/projector/graph-bundle-projector.ts +1 -1
- package/src/graph/projector/graph-tree-projector.ts +251 -0
- package/src/graph/projector/index.ts +1 -0
|
@@ -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 log12 } from "@dxos/log";
|
|
11
11
|
import { mx } from "@dxos/ui-theme";
|
|
12
12
|
|
|
13
13
|
// src/graph/markers.ts
|
|
@@ -62,7 +62,7 @@ var createMarkers = ({ arrowSize = 12 } = {}) => (group) => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
// src/graph/projector/graph-bundle-projector.ts
|
|
65
|
-
import { cluster as d3Cluster,
|
|
65
|
+
import { curveBundle, cluster as d3Cluster, hierarchy, lineRadial } from "d3";
|
|
66
66
|
import { log as log2 } from "@dxos/log";
|
|
67
67
|
|
|
68
68
|
// src/graph/projector/graph-radial-projector.ts
|
|
@@ -2276,10 +2276,212 @@ var GraphSwarmProjector = class extends GraphProjector {
|
|
|
2276
2276
|
}
|
|
2277
2277
|
};
|
|
2278
2278
|
|
|
2279
|
+
// src/graph/projector/graph-tree-projector.ts
|
|
2280
|
+
import { tree as d3Tree, hierarchy as hierarchy4, linkHorizontal } from "d3";
|
|
2281
|
+
import { log as log10 } from "@dxos/log";
|
|
2282
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/projector/graph-tree-projector.ts";
|
|
2283
|
+
var TREE_NODE_TYPE_ROOT = "tree-root";
|
|
2284
|
+
var TREE_NODE_TYPE_NODE = "tree-node";
|
|
2285
|
+
var TREE_NODE_TYPE_INBOUND = "tree-inbound";
|
|
2286
|
+
var HIER_EDGE_PREFIX3 = "__tree_hier__:";
|
|
2287
|
+
var linkPath3 = linkHorizontal().x((d) => d.x).y((d) => d.y);
|
|
2288
|
+
var GraphTreeProjector = class extends GraphRadialProjector {
|
|
2289
|
+
// Snapshots taken right after mergeData — doTreeLayout reads from these because it overwrites
|
|
2290
|
+
// layout.graph.edges with the synthesized hierarchy edges.
|
|
2291
|
+
#dataNodes = [];
|
|
2292
|
+
#dataEdges = [];
|
|
2293
|
+
#resizeCleanup;
|
|
2294
|
+
async onStart() {
|
|
2295
|
+
this.#resizeCleanup = this.context.resized.on(() => {
|
|
2296
|
+
if (this.#dataNodes.length) {
|
|
2297
|
+
this.doTreeLayout();
|
|
2298
|
+
this.emitUpdate("topology");
|
|
2299
|
+
this.animate();
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
async onStop() {
|
|
2304
|
+
this.#resizeCleanup?.();
|
|
2305
|
+
this.#resizeCleanup = void 0;
|
|
2306
|
+
await super.onStop();
|
|
2307
|
+
}
|
|
2308
|
+
onUpdate(graph) {
|
|
2309
|
+
log10("onUpdate", {
|
|
2310
|
+
graph: {
|
|
2311
|
+
nodes: graph?.nodes.length,
|
|
2312
|
+
edges: graph?.edges.length
|
|
2313
|
+
}
|
|
2314
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file12, L: 46, S: this });
|
|
2315
|
+
this.mergeData(graph);
|
|
2316
|
+
this.#dataNodes = [
|
|
2317
|
+
...this.layout.graph.nodes
|
|
2318
|
+
];
|
|
2319
|
+
this.#dataEdges = [
|
|
2320
|
+
...this.layout.graph.edges
|
|
2321
|
+
];
|
|
2322
|
+
this.doTreeLayout();
|
|
2323
|
+
this.emitUpdate("topology");
|
|
2324
|
+
this.animate();
|
|
2325
|
+
}
|
|
2326
|
+
onTickFrame(_t) {
|
|
2327
|
+
for (const edge of this.layout.graph.edges) {
|
|
2328
|
+
if (edge.type !== "hierarchy") {
|
|
2329
|
+
continue;
|
|
2330
|
+
}
|
|
2331
|
+
const { source, target } = edge;
|
|
2332
|
+
edge.path = linkPath3({
|
|
2333
|
+
source: {
|
|
2334
|
+
x: source.x ?? 0,
|
|
2335
|
+
y: source.y ?? 0
|
|
2336
|
+
},
|
|
2337
|
+
target: {
|
|
2338
|
+
x: target.x ?? 0,
|
|
2339
|
+
y: target.y ?? 0
|
|
2340
|
+
}
|
|
2341
|
+
}) ?? void 0;
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
doTreeLayout() {
|
|
2345
|
+
if (!this.context.size) {
|
|
2346
|
+
return;
|
|
2347
|
+
}
|
|
2348
|
+
const dataNodes = this.#dataNodes;
|
|
2349
|
+
if (!dataNodes.length) {
|
|
2350
|
+
return;
|
|
2351
|
+
}
|
|
2352
|
+
const focusId = this.options.focus;
|
|
2353
|
+
const focusNode = focusId ? dataNodes.find((node) => node.id === focusId) : void 0;
|
|
2354
|
+
if (!focusNode) {
|
|
2355
|
+
this.doRadialLayout();
|
|
2356
|
+
return;
|
|
2357
|
+
}
|
|
2358
|
+
const nodesById = new Map(dataNodes.map((node) => [
|
|
2359
|
+
node.id,
|
|
2360
|
+
node
|
|
2361
|
+
]));
|
|
2362
|
+
const makeDatum = (id) => ({
|
|
2363
|
+
id,
|
|
2364
|
+
node: nodesById.get(id)
|
|
2365
|
+
});
|
|
2366
|
+
const outgoing = /* @__PURE__ */ new Map();
|
|
2367
|
+
for (const edge of this.#dataEdges) {
|
|
2368
|
+
const list = outgoing.get(edge.source.id) ?? [];
|
|
2369
|
+
list.push(edge.target.id);
|
|
2370
|
+
outgoing.set(edge.source.id, list);
|
|
2371
|
+
}
|
|
2372
|
+
const rightChildren = /* @__PURE__ */ new Map();
|
|
2373
|
+
const visited = /* @__PURE__ */ new Set([
|
|
2374
|
+
focusId
|
|
2375
|
+
]);
|
|
2376
|
+
let frontier = [
|
|
2377
|
+
focusId
|
|
2378
|
+
];
|
|
2379
|
+
while (frontier.length) {
|
|
2380
|
+
const next = [];
|
|
2381
|
+
for (const id of frontier) {
|
|
2382
|
+
for (const target of outgoing.get(id) ?? []) {
|
|
2383
|
+
if (!visited.has(target)) {
|
|
2384
|
+
visited.add(target);
|
|
2385
|
+
const list = rightChildren.get(id) ?? [];
|
|
2386
|
+
list.push(target);
|
|
2387
|
+
rightChildren.set(id, list);
|
|
2388
|
+
next.push(target);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
frontier = next;
|
|
2393
|
+
}
|
|
2394
|
+
const leftSources = [];
|
|
2395
|
+
for (const edge of this.#dataEdges) {
|
|
2396
|
+
const source = edge.source.id;
|
|
2397
|
+
if (edge.target.id === focusId && source !== focusId && !visited.has(source)) {
|
|
2398
|
+
visited.add(source);
|
|
2399
|
+
leftSources.push(source);
|
|
2400
|
+
}
|
|
2401
|
+
}
|
|
2402
|
+
const rightRoot = hierarchy4(makeDatum(focusId), (d) => (rightChildren.get(d.id) ?? []).map(makeDatum));
|
|
2403
|
+
const leftRoot = hierarchy4(makeDatum(focusId), (d) => d.id === focusId ? leftSources.map(makeDatum) : []);
|
|
2404
|
+
const { width } = this.context.size;
|
|
2405
|
+
const margin = this.options.margin ?? 80;
|
|
2406
|
+
const rowGap = this.options.rowGap ?? 28;
|
|
2407
|
+
const maxColumnGap = this.options.maxColumnGap ?? 300;
|
|
2408
|
+
const sideDepth = Math.max(1, rightRoot.height, leftRoot.height);
|
|
2409
|
+
const columnGap = Math.min(maxColumnGap, Math.max(0, (width / 2 - margin) / sideDepth));
|
|
2410
|
+
const layoutTree = d3Tree().nodeSize([
|
|
2411
|
+
rowGap,
|
|
2412
|
+
columnGap
|
|
2413
|
+
]);
|
|
2414
|
+
const rightPoint = layoutTree(rightRoot);
|
|
2415
|
+
const leftPoint = layoutTree(leftRoot);
|
|
2416
|
+
const nodeR = this.options.nodeRadius ?? 6;
|
|
2417
|
+
const rootR = this.options.rootRadius ?? nodeR * 2;
|
|
2418
|
+
const placed = [];
|
|
2419
|
+
updateNode(focusNode, [
|
|
2420
|
+
0,
|
|
2421
|
+
0
|
|
2422
|
+
], rootR);
|
|
2423
|
+
focusNode.type = TREE_NODE_TYPE_ROOT;
|
|
2424
|
+
placed.push(focusNode);
|
|
2425
|
+
const rightBreadth = rightPoint.x;
|
|
2426
|
+
rightPoint.each((d) => {
|
|
2427
|
+
if (d.data.id === focusId || !d.data.node) {
|
|
2428
|
+
return;
|
|
2429
|
+
}
|
|
2430
|
+
updateNode(d.data.node, [
|
|
2431
|
+
d.y,
|
|
2432
|
+
d.x - rightBreadth
|
|
2433
|
+
], nodeR);
|
|
2434
|
+
d.data.node.type = TREE_NODE_TYPE_NODE;
|
|
2435
|
+
placed.push(d.data.node);
|
|
2436
|
+
});
|
|
2437
|
+
const leftBreadth = leftPoint.x;
|
|
2438
|
+
leftPoint.each((d) => {
|
|
2439
|
+
if (d.data.id === focusId || !d.data.node) {
|
|
2440
|
+
return;
|
|
2441
|
+
}
|
|
2442
|
+
updateNode(d.data.node, [
|
|
2443
|
+
-d.y,
|
|
2444
|
+
d.x - leftBreadth
|
|
2445
|
+
], nodeR);
|
|
2446
|
+
d.data.node.type = TREE_NODE_TYPE_INBOUND;
|
|
2447
|
+
placed.push(d.data.node);
|
|
2448
|
+
});
|
|
2449
|
+
this.layout.graph.nodes = placed;
|
|
2450
|
+
const edges = [];
|
|
2451
|
+
const addLinks = (root, reverse = false) => {
|
|
2452
|
+
root.links().forEach((link) => {
|
|
2453
|
+
const parent = link.source.data;
|
|
2454
|
+
const child = link.target.data;
|
|
2455
|
+
const [from, to] = reverse ? [
|
|
2456
|
+
child,
|
|
2457
|
+
parent
|
|
2458
|
+
] : [
|
|
2459
|
+
parent,
|
|
2460
|
+
child
|
|
2461
|
+
];
|
|
2462
|
+
if (!from.node || !to.node) {
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
edges.push({
|
|
2466
|
+
id: `${HIER_EDGE_PREFIX3}${from.id}->${to.id}`,
|
|
2467
|
+
type: "hierarchy",
|
|
2468
|
+
source: from.node,
|
|
2469
|
+
target: to.node,
|
|
2470
|
+
data: void 0
|
|
2471
|
+
});
|
|
2472
|
+
});
|
|
2473
|
+
};
|
|
2474
|
+
addLinks(rightPoint);
|
|
2475
|
+
addLinks(leftPoint, true);
|
|
2476
|
+
this.layout.graph.edges = edges;
|
|
2477
|
+
this.onTickFrame(0);
|
|
2478
|
+
}
|
|
2479
|
+
};
|
|
2480
|
+
|
|
2279
2481
|
// src/graph/renderer/graph-renderer.ts
|
|
2280
2482
|
import { easeCubicOut, line as line2, polygonHull, select as select4 } from "d3";
|
|
2281
2483
|
import * as Clipper from "js-clipper";
|
|
2282
|
-
import { log as
|
|
2484
|
+
import { log as log11 } from "@dxos/log";
|
|
2283
2485
|
|
|
2284
2486
|
// src/graph/renderer/bullets.ts
|
|
2285
2487
|
import { easeLinear, interpolate, select as select3 } from "d3";
|
|
@@ -2348,7 +2550,7 @@ var Renderer = class {
|
|
|
2348
2550
|
};
|
|
2349
2551
|
|
|
2350
2552
|
// src/graph/renderer/graph-renderer.ts
|
|
2351
|
-
var
|
|
2553
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/graph/renderer/graph-renderer.ts";
|
|
2352
2554
|
var createLine2 = line2();
|
|
2353
2555
|
var EDGE_FADE_MS = 300;
|
|
2354
2556
|
var NODE_HIDE_MS = 500;
|
|
@@ -2367,7 +2569,7 @@ var GraphRenderer = class extends Renderer {
|
|
|
2367
2569
|
this.#firstRender = false;
|
|
2368
2570
|
this.root.replaceChildren();
|
|
2369
2571
|
}
|
|
2370
|
-
|
|
2572
|
+
log11("render", layout, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 35, S: this });
|
|
2371
2573
|
const root = select4(this.root);
|
|
2372
2574
|
if (layout.guides) {
|
|
2373
2575
|
root.selectAll("g.dx-guides").data([
|
|
@@ -2578,9 +2780,9 @@ var updateNode2 = (group, options) => {
|
|
|
2578
2780
|
}
|
|
2579
2781
|
});
|
|
2580
2782
|
} catch (error) {
|
|
2581
|
-
|
|
2783
|
+
log11.error("updateNode", {
|
|
2582
2784
|
error: error?.message
|
|
2583
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
2785
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 303, S: void 0 });
|
|
2584
2786
|
}
|
|
2585
2787
|
}
|
|
2586
2788
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
@@ -2631,9 +2833,9 @@ var updateEdge = (group, options, nodeGroup) => {
|
|
|
2631
2833
|
}
|
|
2632
2834
|
});
|
|
2633
2835
|
} catch (error) {
|
|
2634
|
-
|
|
2836
|
+
log11.error("updateEdge", {
|
|
2635
2837
|
error: error?.message
|
|
2636
|
-
}, { "~LogMeta": "~LogMeta", F:
|
|
2838
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file13, L: 371, S: void 0 });
|
|
2637
2839
|
}
|
|
2638
2840
|
const groupOrTransition = options.transition ? group.transition(options.transition()) : group;
|
|
2639
2841
|
groupOrTransition.selectAll("path").attr("d", function() {
|
|
@@ -3129,7 +3331,7 @@ var useZoom = (options = defaultZoomOptions) => {
|
|
|
3129
3331
|
};
|
|
3130
3332
|
|
|
3131
3333
|
// src/components/Graph/Graph.tsx
|
|
3132
|
-
var
|
|
3334
|
+
var __dxlog_file14 = "/__w/dxos/dxos/packages/ui/react-ui-graph/src/components/Graph/Graph.tsx";
|
|
3133
3335
|
var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rendererProp, drag: drag2, arrows, onSelect, onInspect, onPointerMove, onPointerLeave, ...props }, forwardedRef) => {
|
|
3134
3336
|
const context = useSvgContext();
|
|
3135
3337
|
const graphRef = useRef3(null);
|
|
@@ -3210,7 +3412,7 @@ var GraphInner = ({ classNames, model, projector: projectorProp, renderer: rende
|
|
|
3210
3412
|
renderer.render(layout);
|
|
3211
3413
|
}
|
|
3212
3414
|
} catch (error) {
|
|
3213
|
-
|
|
3415
|
+
log12.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file14, L: 95, S: void 0 });
|
|
3214
3416
|
void projector.stop();
|
|
3215
3417
|
}
|
|
3216
3418
|
})
|
|
@@ -3606,8 +3808,531 @@ var SVG = {
|
|
|
3606
3808
|
FPS
|
|
3607
3809
|
};
|
|
3608
3810
|
|
|
3811
|
+
// src/components/Tree/Tree.tsx
|
|
3812
|
+
import React10, { useMemo as useMemo9 } from "react";
|
|
3813
|
+
|
|
3814
|
+
// src/components/Tree/layout/HierarchicalEdgeBundling.tsx
|
|
3815
|
+
import { cluster, curveBundle as curveBundle2, hierarchy as hierarchy5, lineRadial as lineRadial2, select as select10 } from "d3";
|
|
3816
|
+
import React7, { useEffect as useEffect9, useMemo as useMemo6, useRef as useRef5 } from "react";
|
|
3817
|
+
import { mx as mx5 } from "@dxos/ui-theme";
|
|
3818
|
+
|
|
3819
|
+
// src/components/Tree/layout/slots.ts
|
|
3820
|
+
var defaultTreeLayoutSlots = {
|
|
3821
|
+
// Cursor + transition so the hover swap reads clearly; SVG circles support the `:hover` pseudo-class
|
|
3822
|
+
// via Tailwind variants exactly like HTML elements.
|
|
3823
|
+
node: "fill-blue-600 hover:fill-orange-500 cursor-pointer transition-colors",
|
|
3824
|
+
// 0.5px is fine on a white background, but on a dark Storybook background the lines disappear.
|
|
3825
|
+
// Use stroke-1 with opacity 50% so they read in both themes; dx-bundle-dim/out/in further tune on hover.
|
|
3826
|
+
path: "fill-none stroke-blue-500/50 stroke-[1px] dark:stroke-blue-400/60",
|
|
3827
|
+
text: "fill-neutral-700 dark:fill-neutral-300 text-xs hover:fill-orange-500 cursor-pointer transition-colors"
|
|
3828
|
+
};
|
|
3829
|
+
|
|
3830
|
+
// src/components/Tree/layout/useContainerSize.ts
|
|
3831
|
+
import { useEffect as useEffect8, useState as useState3 } from "react";
|
|
3832
|
+
var useContainerSize = () => {
|
|
3833
|
+
const [el, setEl] = useState3(null);
|
|
3834
|
+
const [size, setSize] = useState3({
|
|
3835
|
+
width: 0,
|
|
3836
|
+
height: 0
|
|
3837
|
+
});
|
|
3838
|
+
useEffect8(() => {
|
|
3839
|
+
if (!el) {
|
|
3840
|
+
return;
|
|
3841
|
+
}
|
|
3842
|
+
const rect = el.getBoundingClientRect();
|
|
3843
|
+
setSize({
|
|
3844
|
+
width: rect.width,
|
|
3845
|
+
height: rect.height
|
|
3846
|
+
});
|
|
3847
|
+
const observer = new ResizeObserver((entries) => {
|
|
3848
|
+
const entry = entries[0];
|
|
3849
|
+
if (!entry) {
|
|
3850
|
+
return;
|
|
3851
|
+
}
|
|
3852
|
+
const { width, height } = entry.contentRect;
|
|
3853
|
+
setSize((prev) => prev.width === width && prev.height === height ? prev : {
|
|
3854
|
+
width,
|
|
3855
|
+
height
|
|
3856
|
+
});
|
|
3857
|
+
});
|
|
3858
|
+
observer.observe(el);
|
|
3859
|
+
return () => observer.disconnect();
|
|
3860
|
+
}, [
|
|
3861
|
+
el
|
|
3862
|
+
]);
|
|
3863
|
+
return {
|
|
3864
|
+
setRef: setEl,
|
|
3865
|
+
width: size.width,
|
|
3866
|
+
height: size.height
|
|
3867
|
+
};
|
|
3868
|
+
};
|
|
3869
|
+
|
|
3870
|
+
// src/components/Tree/layout/HierarchicalEdgeBundling.tsx
|
|
3871
|
+
var TRANSITION_MS = 350;
|
|
3872
|
+
var HierarchicalEdgeBundling = ({ classNames, data, edges = [], label = (d) => d.label ?? d.id, padding = 120, tension = 0.85, r = 4, slots = defaultTreeLayoutSlots, onNodeHover }) => {
|
|
3873
|
+
const svgRef = useRef5(null);
|
|
3874
|
+
const { setRef, width, height } = useContainerSize();
|
|
3875
|
+
const root = useMemo6(() => buildBundleHierarchy(data, edges), [
|
|
3876
|
+
data,
|
|
3877
|
+
edges
|
|
3878
|
+
]);
|
|
3879
|
+
const handleHoverRef = useRef5(() => {
|
|
3880
|
+
});
|
|
3881
|
+
handleHoverRef.current = (node, event) => onNodeHover?.(node, event);
|
|
3882
|
+
useEffect9(() => {
|
|
3883
|
+
if (!svgRef.current || !width || !height) {
|
|
3884
|
+
return;
|
|
3885
|
+
}
|
|
3886
|
+
const radius = Math.max(0, Math.min(width, height) / 2 - padding);
|
|
3887
|
+
renderBundling(svgRef.current, root, {
|
|
3888
|
+
radius,
|
|
3889
|
+
r,
|
|
3890
|
+
label,
|
|
3891
|
+
slots,
|
|
3892
|
+
tension,
|
|
3893
|
+
onNodeHover: (n, e) => handleHoverRef.current(n, e)
|
|
3894
|
+
});
|
|
3895
|
+
}, [
|
|
3896
|
+
root,
|
|
3897
|
+
width,
|
|
3898
|
+
height,
|
|
3899
|
+
padding,
|
|
3900
|
+
tension,
|
|
3901
|
+
r,
|
|
3902
|
+
label,
|
|
3903
|
+
slots
|
|
3904
|
+
]);
|
|
3905
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
3906
|
+
ref: setRef,
|
|
3907
|
+
className: mx5("dx-expander relative", classNames)
|
|
3908
|
+
}, width > 0 && height > 0 && /* @__PURE__ */ React7.createElement("svg", {
|
|
3909
|
+
ref: svgRef,
|
|
3910
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
3911
|
+
width,
|
|
3912
|
+
height,
|
|
3913
|
+
viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
|
|
3914
|
+
}));
|
|
3915
|
+
};
|
|
3916
|
+
var buildBundleHierarchy = (data, edges) => {
|
|
3917
|
+
const root = hierarchy5(data);
|
|
3918
|
+
const byId = /* @__PURE__ */ new Map();
|
|
3919
|
+
for (const node of root.descendants()) {
|
|
3920
|
+
byId.set(node.data.id, node);
|
|
3921
|
+
node.outgoing = [];
|
|
3922
|
+
node.incoming = [];
|
|
3923
|
+
}
|
|
3924
|
+
for (const edge of edges) {
|
|
3925
|
+
const source = byId.get(edge.source);
|
|
3926
|
+
const target = byId.get(edge.target);
|
|
3927
|
+
if (!source || !target || source === target) {
|
|
3928
|
+
continue;
|
|
3929
|
+
}
|
|
3930
|
+
source.outgoing.push([
|
|
3931
|
+
source,
|
|
3932
|
+
target,
|
|
3933
|
+
edge
|
|
3934
|
+
]);
|
|
3935
|
+
target.incoming.push([
|
|
3936
|
+
source,
|
|
3937
|
+
target,
|
|
3938
|
+
edge
|
|
3939
|
+
]);
|
|
3940
|
+
}
|
|
3941
|
+
return root;
|
|
3942
|
+
};
|
|
3943
|
+
var renderBundling = (svgElement, root, options) => {
|
|
3944
|
+
const { radius, r, tension, label, slots, onNodeHover } = options;
|
|
3945
|
+
const svg = select10(svgElement);
|
|
3946
|
+
if (!root.children?.length) {
|
|
3947
|
+
svg.selectAll("g.dx-bundle-root").remove();
|
|
3948
|
+
return;
|
|
3949
|
+
}
|
|
3950
|
+
cluster().size([
|
|
3951
|
+
2 * Math.PI,
|
|
3952
|
+
radius
|
|
3953
|
+
])(root);
|
|
3954
|
+
const g = svg.selectAll("g.dx-bundle-root").data([
|
|
3955
|
+
null
|
|
3956
|
+
]).join("g").classed("dx-bundle-root", true);
|
|
3957
|
+
const linksLayer = g.selectAll("g.dx-bundle-links").data([
|
|
3958
|
+
null
|
|
3959
|
+
]).join("g").classed("dx-bundle-links", true);
|
|
3960
|
+
const nodesLayer = g.selectAll("g.dx-bundle-nodes").data([
|
|
3961
|
+
null
|
|
3962
|
+
]).join("g").classed("dx-bundle-nodes", true);
|
|
3963
|
+
const line5 = lineRadial2().curve(curveBundle2.beta(tension)).radius((d) => d.y).angle((d) => d.x);
|
|
3964
|
+
const leaves = root.leaves();
|
|
3965
|
+
const flatEdges = leaves.flatMap((leaf) => leaf.outgoing ?? []);
|
|
3966
|
+
const paths = linksLayer.selectAll("path").data(flatEdges, (d) => `${d[0].data.id}->${d[1].data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.each(function() {
|
|
3967
|
+
select10(this).interrupt();
|
|
3968
|
+
}).transition().duration(TRANSITION_MS).attr("opacity", 0).remove());
|
|
3969
|
+
paths.each(function(d) {
|
|
3970
|
+
d[0].pathEl = this;
|
|
3971
|
+
}).transition().duration(TRANSITION_MS).attr("opacity", 1).attr("d", ([s, t]) => line5(s.path(t)));
|
|
3972
|
+
const labels = nodesLayer.selectAll("g.dx-bundle-leaf").data(leaves, (d) => d.data.id).join((enter) => {
|
|
3973
|
+
const ge = enter.append("g").classed("dx-bundle-leaf", true).attr("opacity", 0);
|
|
3974
|
+
ge.append("circle").style("cursor", "pointer");
|
|
3975
|
+
ge.append("text").attr("dy", "0.32em").attr("paint-order", "stroke").style("cursor", "pointer");
|
|
3976
|
+
return ge;
|
|
3977
|
+
}, (update) => update, (exit) => exit.each(function() {
|
|
3978
|
+
select10(this).interrupt();
|
|
3979
|
+
}).transition().duration(TRANSITION_MS).attr("opacity", 0).remove());
|
|
3980
|
+
labels.transition().duration(TRANSITION_MS).attr("opacity", 1).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`);
|
|
3981
|
+
const onEnter = function(event, d) {
|
|
3982
|
+
onNodeHover(d.data, event);
|
|
3983
|
+
hover(linksLayer, leaves, d, true);
|
|
3984
|
+
};
|
|
3985
|
+
const onLeave = function(event, d) {
|
|
3986
|
+
onNodeHover(null);
|
|
3987
|
+
hover(linksLayer, leaves, d, false);
|
|
3988
|
+
};
|
|
3989
|
+
labels.select("circle").attr("class", [
|
|
3990
|
+
slots.node ?? "",
|
|
3991
|
+
"dx-leaf"
|
|
3992
|
+
].filter(Boolean).join(" ")).attr("r", r).style("fill", (d) => slots.nodeFill?.(d.data.data) ?? null).each(function(d) {
|
|
3993
|
+
d.circle = this;
|
|
3994
|
+
}).on("pointerenter", onEnter).on("pointerleave", onLeave);
|
|
3995
|
+
labels.select("text").attr("class", slots.text ?? "").attr("x", (d) => d.x < Math.PI ? r + 4 : -(r + 4)).attr("text-anchor", (d) => d.x < Math.PI ? "start" : "end").attr("transform", (d) => d.x >= Math.PI ? "rotate(180)" : null).each(function(d) {
|
|
3996
|
+
d.text = this;
|
|
3997
|
+
}).text((d) => label(d.data)).on("pointerenter", onEnter).on("pointerleave", onLeave);
|
|
3998
|
+
};
|
|
3999
|
+
var hover = (linksLayer, leaves, focused, on) => {
|
|
4000
|
+
const outgoing = new Set((focused.outgoing ?? []).map(([, t]) => t));
|
|
4001
|
+
const incoming = new Set((focused.incoming ?? []).map(([s]) => s));
|
|
4002
|
+
linksLayer.selectAll("path").style("stroke", (d) => {
|
|
4003
|
+
if (!on) {
|
|
4004
|
+
return null;
|
|
4005
|
+
}
|
|
4006
|
+
if (d[0] === focused) {
|
|
4007
|
+
return "var(--color-orange-500)";
|
|
4008
|
+
}
|
|
4009
|
+
if (d[1] === focused) {
|
|
4010
|
+
return "var(--color-sky-500)";
|
|
4011
|
+
}
|
|
4012
|
+
return null;
|
|
4013
|
+
}).style("stroke-width", (d) => on && (d[0] === focused || d[1] === focused) ? "1.5px" : null).style("opacity", (d) => on && d[0] !== focused && d[1] !== focused ? "0.08" : null);
|
|
4014
|
+
for (const leaf of leaves) {
|
|
4015
|
+
const isOut = outgoing.has(leaf);
|
|
4016
|
+
const isIn = incoming.has(leaf);
|
|
4017
|
+
const isConnected = isOut || isIn;
|
|
4018
|
+
if (leaf.text) {
|
|
4019
|
+
select10(leaf.text).style("fill", () => {
|
|
4020
|
+
if (!on) {
|
|
4021
|
+
return null;
|
|
4022
|
+
}
|
|
4023
|
+
if (leaf === focused) {
|
|
4024
|
+
return "var(--color-neutral-900)";
|
|
4025
|
+
}
|
|
4026
|
+
if (isOut) {
|
|
4027
|
+
return "var(--color-orange-500)";
|
|
4028
|
+
}
|
|
4029
|
+
if (isIn) {
|
|
4030
|
+
return "var(--color-sky-500)";
|
|
4031
|
+
}
|
|
4032
|
+
return null;
|
|
4033
|
+
}).style("font-weight", () => on && leaf === focused ? "600" : null);
|
|
4034
|
+
}
|
|
4035
|
+
if (leaf.circle) {
|
|
4036
|
+
select10(leaf.circle).style("stroke", () => on && isConnected ? "var(--color-orange-400)" : null).style("stroke-width", () => on && isConnected ? "2.5px" : null).style("opacity", () => on && !isConnected && leaf !== focused ? "0.15" : null);
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
};
|
|
4040
|
+
|
|
4041
|
+
// src/components/Tree/layout/RadialTree.tsx
|
|
4042
|
+
import { cluster as d3Cluster4, tree as d3Tree2, linkRadial as linkRadial3, select as select11 } from "d3";
|
|
4043
|
+
import React8, { useCallback, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef6, useState as useState4 } from "react";
|
|
4044
|
+
import { mx as mx6 } from "@dxos/ui-theme";
|
|
4045
|
+
|
|
4046
|
+
// src/components/Tree/layout/hierarchy.ts
|
|
4047
|
+
import { hierarchy as d3Hierarchy } from "d3";
|
|
4048
|
+
var buildHierarchy = (data, collapsed = /* @__PURE__ */ new Set()) => {
|
|
4049
|
+
return d3Hierarchy(data, (d) => {
|
|
4050
|
+
if (!d.children?.length) {
|
|
4051
|
+
return void 0;
|
|
4052
|
+
}
|
|
4053
|
+
return collapsed.has(d.id) ? void 0 : d.children;
|
|
4054
|
+
});
|
|
4055
|
+
};
|
|
4056
|
+
var isCollapsed = (data, collapsed) => Boolean(data.children?.length) && collapsed.has(data.id);
|
|
4057
|
+
var isLeaf = (data) => !data.children?.length;
|
|
4058
|
+
|
|
4059
|
+
// src/components/Tree/layout/RadialTree.tsx
|
|
4060
|
+
var TRANSITION_MS2 = 350;
|
|
4061
|
+
var RadialTree = ({ classNames, data, label = (d) => d.label ?? d.id, slots = defaultTreeLayoutSlots, r = 4, padding = 80, initialCollapsed, cluster: cluster2 = false, onNodeClick, onNodeHover }) => {
|
|
4062
|
+
const svgRef = useRef6(null);
|
|
4063
|
+
const { setRef, width, height } = useContainerSize();
|
|
4064
|
+
const [collapsed, setCollapsed] = useState4(() => new Set(initialCollapsed ?? []));
|
|
4065
|
+
const toggle = useCallback((id) => {
|
|
4066
|
+
setCollapsed((prev) => {
|
|
4067
|
+
const next = new Set(prev);
|
|
4068
|
+
if (next.has(id)) {
|
|
4069
|
+
next.delete(id);
|
|
4070
|
+
} else {
|
|
4071
|
+
next.add(id);
|
|
4072
|
+
}
|
|
4073
|
+
return next;
|
|
4074
|
+
});
|
|
4075
|
+
}, []);
|
|
4076
|
+
const handleClickRef = useRef6(() => {
|
|
4077
|
+
});
|
|
4078
|
+
handleClickRef.current = (node) => {
|
|
4079
|
+
onNodeClick?.(node);
|
|
4080
|
+
if (node.children?.length) {
|
|
4081
|
+
toggle(node.id);
|
|
4082
|
+
}
|
|
4083
|
+
};
|
|
4084
|
+
const handleHoverRef = useRef6(() => {
|
|
4085
|
+
});
|
|
4086
|
+
handleHoverRef.current = (node, event) => onNodeHover?.(node, event);
|
|
4087
|
+
const root = useMemo7(() => buildHierarchy(data, collapsed), [
|
|
4088
|
+
data,
|
|
4089
|
+
collapsed
|
|
4090
|
+
]);
|
|
4091
|
+
useEffect10(() => {
|
|
4092
|
+
if (!svgRef.current || !width || !height) {
|
|
4093
|
+
return;
|
|
4094
|
+
}
|
|
4095
|
+
const radius = Math.max(0, Math.min(width, height) / 2 - padding);
|
|
4096
|
+
renderRadialTree(svgRef.current, root, {
|
|
4097
|
+
radius,
|
|
4098
|
+
r,
|
|
4099
|
+
label,
|
|
4100
|
+
slots,
|
|
4101
|
+
collapsed,
|
|
4102
|
+
cluster: cluster2,
|
|
4103
|
+
onNodeClick: (n) => handleClickRef.current(n),
|
|
4104
|
+
onNodeHover: (n, e) => handleHoverRef.current(n, e)
|
|
4105
|
+
});
|
|
4106
|
+
}, [
|
|
4107
|
+
root,
|
|
4108
|
+
width,
|
|
4109
|
+
height,
|
|
4110
|
+
r,
|
|
4111
|
+
padding,
|
|
4112
|
+
label,
|
|
4113
|
+
slots,
|
|
4114
|
+
collapsed,
|
|
4115
|
+
cluster2
|
|
4116
|
+
]);
|
|
4117
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
4118
|
+
ref: setRef,
|
|
4119
|
+
className: mx6("dx-expander relative", classNames)
|
|
4120
|
+
}, width > 0 && height > 0 && /* @__PURE__ */ React8.createElement("svg", {
|
|
4121
|
+
ref: svgRef,
|
|
4122
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
4123
|
+
width,
|
|
4124
|
+
height,
|
|
4125
|
+
viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
|
|
4126
|
+
}));
|
|
4127
|
+
};
|
|
4128
|
+
var renderRadialTree = (svgElement, root, options) => {
|
|
4129
|
+
const { radius, r, label, slots, collapsed, cluster: cluster2, onNodeClick, onNodeHover } = options;
|
|
4130
|
+
const svg = select11(svgElement);
|
|
4131
|
+
const layout = cluster2 ? d3Cluster4() : d3Tree2();
|
|
4132
|
+
layout.size([
|
|
4133
|
+
2 * Math.PI,
|
|
4134
|
+
radius
|
|
4135
|
+
]).separation((a, b) => (a.parent === b.parent ? 1 : 2) / Math.max(1, a.depth))(root);
|
|
4136
|
+
const g = svg.selectAll("g.dx-radial-root").data([
|
|
4137
|
+
null
|
|
4138
|
+
]).join("g").classed("dx-radial-root", true);
|
|
4139
|
+
const linksLayer = g.selectAll("g.dx-radial-links").data([
|
|
4140
|
+
null
|
|
4141
|
+
]).join("g").classed("dx-radial-links", true);
|
|
4142
|
+
const nodesLayer = g.selectAll("g.dx-radial-nodes").data([
|
|
4143
|
+
null
|
|
4144
|
+
]).join("g").classed("dx-radial-nodes", true);
|
|
4145
|
+
const linkPath4 = linkRadial3().angle((d) => d.x).radius((d) => d.y);
|
|
4146
|
+
linksLayer.selectAll("path").data(root.links(), (d) => `${d.source.data.id}->${d.target.data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.transition().duration(TRANSITION_MS2).attr("opacity", 0).remove()).transition().duration(TRANSITION_MS2).attr("opacity", 1).attr("d", linkPath4);
|
|
4147
|
+
const node = nodesLayer.selectAll("g.dx-radial-node").data(root.descendants(), (d) => d.data.id);
|
|
4148
|
+
const nodeEnter = node.enter().append("g").classed("dx-radial-node", true).attr("opacity", 0).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`).style("cursor", (d) => d.data.children?.length ? "pointer" : "default").on("click", (_, d) => onNodeClick(d.data));
|
|
4149
|
+
nodeEnter.append("circle").attr("r", r).on("pointerenter", (event, d) => onNodeHover(d.data, event)).on("pointerleave", (event) => onNodeHover(null, event));
|
|
4150
|
+
nodeEnter.append("text").attr("dy", "0.32em").attr("paint-order", "stroke").text((d) => label(d.data));
|
|
4151
|
+
const nodeMerge = nodeEnter.merge(node);
|
|
4152
|
+
nodeMerge.transition().duration(TRANSITION_MS2).attr("opacity", 1).attr("transform", (d) => `rotate(${d.x * 180 / Math.PI - 90}) translate(${d.y},0)`);
|
|
4153
|
+
nodeMerge.select("circle").attr("class", (d) => {
|
|
4154
|
+
const collapsedHere = isCollapsed(d.data, collapsed);
|
|
4155
|
+
const leaf = isLeaf(d.data);
|
|
4156
|
+
return [
|
|
4157
|
+
slots.node ?? "",
|
|
4158
|
+
collapsedHere ? "dx-collapsed" : leaf ? "dx-leaf" : "dx-branch"
|
|
4159
|
+
].filter(Boolean).join(" ");
|
|
4160
|
+
}).attr("r", r).style("fill", (d) => isLeaf(d.data) ? slots.nodeFill?.(d.data.data) ?? null : null);
|
|
4161
|
+
nodeMerge.select("text").attr("class", slots.text ?? "").attr("transform", (d) => d.x >= Math.PI ? "rotate(180)" : null).attr("x", (d) => d.x < Math.PI === !d.children ? r + 4 : -(r + 4)).attr("text-anchor", (d) => d.x < Math.PI === !d.children ? "start" : "end").text((d) => label(d.data));
|
|
4162
|
+
node.exit().transition().duration(TRANSITION_MS2).attr("opacity", 0).remove();
|
|
4163
|
+
};
|
|
4164
|
+
|
|
4165
|
+
// src/components/Tree/layout/TidyTree.tsx
|
|
4166
|
+
import { curveBumpX, link as d3Link, tree as d3Tree3, select as select12 } from "d3";
|
|
4167
|
+
import React9, { useCallback as useCallback2, useEffect as useEffect11, useMemo as useMemo8, useRef as useRef7, useState as useState5 } from "react";
|
|
4168
|
+
import { mx as mx7 } from "@dxos/ui-theme";
|
|
4169
|
+
var TRANSITION_MS3 = 350;
|
|
4170
|
+
var TidyTree = ({ classNames, data, label = (d) => d.label ?? d.id, slots = defaultTreeLayoutSlots, r = 4, margin = 24, initialCollapsed, onNodeClick }) => {
|
|
4171
|
+
const svgRef = useRef7(null);
|
|
4172
|
+
const { setRef, width, height } = useContainerSize();
|
|
4173
|
+
const [collapsed, setCollapsed] = useState5(() => new Set(initialCollapsed ?? []));
|
|
4174
|
+
const toggle = useCallback2((id) => {
|
|
4175
|
+
setCollapsed((prev) => {
|
|
4176
|
+
const next = new Set(prev);
|
|
4177
|
+
if (next.has(id)) {
|
|
4178
|
+
next.delete(id);
|
|
4179
|
+
} else {
|
|
4180
|
+
next.add(id);
|
|
4181
|
+
}
|
|
4182
|
+
return next;
|
|
4183
|
+
});
|
|
4184
|
+
}, []);
|
|
4185
|
+
const handleClickRef = useRef7(() => {
|
|
4186
|
+
});
|
|
4187
|
+
handleClickRef.current = (node) => {
|
|
4188
|
+
onNodeClick?.(node);
|
|
4189
|
+
if (node.children?.length) {
|
|
4190
|
+
toggle(node.id);
|
|
4191
|
+
}
|
|
4192
|
+
};
|
|
4193
|
+
const root = useMemo8(() => buildHierarchy(data, collapsed), [
|
|
4194
|
+
data,
|
|
4195
|
+
collapsed
|
|
4196
|
+
]);
|
|
4197
|
+
useEffect11(() => {
|
|
4198
|
+
if (!svgRef.current || !width || !height) {
|
|
4199
|
+
return;
|
|
4200
|
+
}
|
|
4201
|
+
renderTidyTree(svgRef.current, root, {
|
|
4202
|
+
width,
|
|
4203
|
+
height,
|
|
4204
|
+
r,
|
|
4205
|
+
margin,
|
|
4206
|
+
label,
|
|
4207
|
+
slots,
|
|
4208
|
+
collapsed,
|
|
4209
|
+
onNodeClick: (n) => handleClickRef.current(n)
|
|
4210
|
+
});
|
|
4211
|
+
}, [
|
|
4212
|
+
root,
|
|
4213
|
+
width,
|
|
4214
|
+
height,
|
|
4215
|
+
r,
|
|
4216
|
+
margin,
|
|
4217
|
+
label,
|
|
4218
|
+
slots,
|
|
4219
|
+
collapsed
|
|
4220
|
+
]);
|
|
4221
|
+
return /* @__PURE__ */ React9.createElement("div", {
|
|
4222
|
+
ref: setRef,
|
|
4223
|
+
className: mx7("dx-expander relative", classNames)
|
|
4224
|
+
}, width > 0 && height > 0 && /* @__PURE__ */ React9.createElement("svg", {
|
|
4225
|
+
ref: svgRef,
|
|
4226
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
4227
|
+
width,
|
|
4228
|
+
height,
|
|
4229
|
+
viewBox: `${-width / 2} ${-height / 2} ${width} ${height}`
|
|
4230
|
+
}));
|
|
4231
|
+
};
|
|
4232
|
+
var renderTidyTree = (svgElement, root, options) => {
|
|
4233
|
+
const { width, height, r, margin, label, slots, collapsed, onNodeClick } = options;
|
|
4234
|
+
const svg = select12(svgElement);
|
|
4235
|
+
const dx = 18;
|
|
4236
|
+
const dy = Math.max(60, (width - margin * 2) / Math.max(1, root.height + 1));
|
|
4237
|
+
d3Tree3().nodeSize([
|
|
4238
|
+
dx,
|
|
4239
|
+
dy
|
|
4240
|
+
])(root);
|
|
4241
|
+
let x0 = Infinity;
|
|
4242
|
+
let x1 = -x0;
|
|
4243
|
+
root.each((d) => {
|
|
4244
|
+
if (d.x > x1) {
|
|
4245
|
+
x1 = d.x;
|
|
4246
|
+
}
|
|
4247
|
+
if (d.x < x0) {
|
|
4248
|
+
x0 = d.x;
|
|
4249
|
+
}
|
|
4250
|
+
});
|
|
4251
|
+
const treeWidth = width - margin * 2;
|
|
4252
|
+
const treeHeight = x1 - x0;
|
|
4253
|
+
const scaleY = treeHeight > 0 ? Math.min(1, (height - margin * 2) / treeHeight) : 1;
|
|
4254
|
+
const offsetX = -treeWidth / 2;
|
|
4255
|
+
const offsetY = -(x0 + x1) / 2;
|
|
4256
|
+
const g = svg.selectAll("g.dx-tidy-root").data([
|
|
4257
|
+
null
|
|
4258
|
+
]).join("g").classed("dx-tidy-root", true);
|
|
4259
|
+
const linksLayer = g.selectAll("g.dx-tidy-links").data([
|
|
4260
|
+
null
|
|
4261
|
+
]).join("g").classed("dx-tidy-links", true);
|
|
4262
|
+
const nodesLayer = g.selectAll("g.dx-tidy-nodes").data([
|
|
4263
|
+
null
|
|
4264
|
+
]).join("g").classed("dx-tidy-nodes", true);
|
|
4265
|
+
const linkPath4 = d3Link(curveBumpX).x((d) => offsetX + d.y).y((d) => (d.x + offsetY) * scaleY);
|
|
4266
|
+
linksLayer.selectAll("path").data(root.links(), (d) => `${d.source.data.id}->${d.target.data.id}`).join((enter) => enter.append("path").attr("class", slots.path ?? "").attr("fill", "none").attr("opacity", 0), (update) => update, (exit) => exit.transition().duration(TRANSITION_MS3).attr("opacity", 0).remove()).transition().duration(TRANSITION_MS3).attr("opacity", 1).attr("d", linkPath4);
|
|
4267
|
+
const node = nodesLayer.selectAll("g.dx-tidy-node").data(root.descendants(), (d) => d.data.id);
|
|
4268
|
+
const nodeEnter = node.enter().append("g").classed("dx-tidy-node", true).attr("transform", (d) => `translate(${offsetX + d.y},${(d.x + offsetY) * scaleY})`).attr("opacity", 0).style("cursor", (d) => d.data.children?.length ? "pointer" : "default").on("click", (_, d) => onNodeClick(d.data));
|
|
4269
|
+
nodeEnter.append("circle").attr("r", r);
|
|
4270
|
+
nodeEnter.append("text").attr("dy", "0.32em").attr("x", (d) => d.children ? -(r + 4) : r + 4).attr("text-anchor", (d) => d.children ? "end" : "start").text((d) => label(d.data));
|
|
4271
|
+
const nodeMerge = nodeEnter.merge(node);
|
|
4272
|
+
nodeMerge.transition().duration(TRANSITION_MS3).attr("opacity", 1).attr("transform", (d) => `translate(${offsetX + d.y},${(d.x + offsetY) * scaleY})`);
|
|
4273
|
+
nodeMerge.select("circle").attr("class", (d) => {
|
|
4274
|
+
const collapsedHere = isCollapsed(d.data, collapsed);
|
|
4275
|
+
const leaf = isLeaf(d.data);
|
|
4276
|
+
return [
|
|
4277
|
+
slots.node ?? "",
|
|
4278
|
+
collapsedHere ? "dx-collapsed" : leaf ? "dx-leaf" : "dx-branch"
|
|
4279
|
+
].filter(Boolean).join(" ");
|
|
4280
|
+
}).attr("r", r);
|
|
4281
|
+
nodeMerge.select("text").attr("class", slots.text ?? "").attr("x", (d) => d.children ? -(r + 4) : r + 4).attr("text-anchor", (d) => d.children ? "end" : "start").text((d) => label(d.data));
|
|
4282
|
+
node.exit().each(function() {
|
|
4283
|
+
select12(this).interrupt();
|
|
4284
|
+
}).transition().duration(TRANSITION_MS3).attr("opacity", 0).remove();
|
|
4285
|
+
};
|
|
4286
|
+
|
|
4287
|
+
// src/components/Tree/Tree.tsx
|
|
4288
|
+
var Tree = ({ classNames, data, edges, variant = "tidy", label, slots, margin, initialCollapsed, onNodeClick, onNodeHover }) => {
|
|
4289
|
+
return useMemo9(() => {
|
|
4290
|
+
switch (variant) {
|
|
4291
|
+
case "tidy":
|
|
4292
|
+
return /* @__PURE__ */ React10.createElement(TidyTree, {
|
|
4293
|
+
classNames,
|
|
4294
|
+
data,
|
|
4295
|
+
label,
|
|
4296
|
+
slots,
|
|
4297
|
+
margin,
|
|
4298
|
+
initialCollapsed,
|
|
4299
|
+
onNodeClick
|
|
4300
|
+
});
|
|
4301
|
+
case "radial":
|
|
4302
|
+
return /* @__PURE__ */ React10.createElement(RadialTree, {
|
|
4303
|
+
classNames,
|
|
4304
|
+
data,
|
|
4305
|
+
label,
|
|
4306
|
+
slots,
|
|
4307
|
+
initialCollapsed,
|
|
4308
|
+
onNodeClick,
|
|
4309
|
+
onNodeHover
|
|
4310
|
+
});
|
|
4311
|
+
case "edge":
|
|
4312
|
+
return /* @__PURE__ */ React10.createElement(HierarchicalEdgeBundling, {
|
|
4313
|
+
classNames,
|
|
4314
|
+
data,
|
|
4315
|
+
edges: edges ?? [],
|
|
4316
|
+
label,
|
|
4317
|
+
slots,
|
|
4318
|
+
onNodeHover
|
|
4319
|
+
});
|
|
4320
|
+
}
|
|
4321
|
+
}, [
|
|
4322
|
+
variant,
|
|
4323
|
+
classNames,
|
|
4324
|
+
data,
|
|
4325
|
+
edges,
|
|
4326
|
+
label,
|
|
4327
|
+
slots,
|
|
4328
|
+
initialCollapsed,
|
|
4329
|
+
onNodeClick,
|
|
4330
|
+
onNodeHover
|
|
4331
|
+
]);
|
|
4332
|
+
};
|
|
4333
|
+
|
|
3609
4334
|
// src/fx/pulsar.ts
|
|
3610
|
-
import { easeCubicOut as easeCubicOut2, select as
|
|
4335
|
+
import { easeCubicOut as easeCubicOut2, select as select13 } from "d3";
|
|
3611
4336
|
var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
3612
4337
|
(function(Pulsar2) {
|
|
3613
4338
|
Pulsar2.has = (group) => group.select("circle.dx-pulsar").empty();
|
|
@@ -3622,10 +4347,10 @@ var PROP_PULSAR_ACTIVE = "dx-pulsar-active";
|
|
|
3622
4347
|
var startAnimation = (pulsar, r, options = {}) => {
|
|
3623
4348
|
const { period = 1e3, duration = 800, ratio = 3 } = options;
|
|
3624
4349
|
return pulsar.attr("r", r).attr("opacity", 1).transition("pulsar").delay(period - Date.now() % period).duration(Math.min(duration, period - 20)).ease(easeCubicOut2).attr("r", r * ratio).attr("opacity", -0.1).on("end", function() {
|
|
3625
|
-
if (
|
|
3626
|
-
startAnimation(
|
|
4350
|
+
if (select13(this).property(PROP_PULSAR_ACTIVE)) {
|
|
4351
|
+
startAnimation(select13(this), r, options);
|
|
3627
4352
|
} else {
|
|
3628
|
-
|
|
4353
|
+
select13(this).remove();
|
|
3629
4354
|
}
|
|
3630
4355
|
});
|
|
3631
4356
|
};
|
|
@@ -3648,30 +4373,42 @@ export {
|
|
|
3648
4373
|
GraphRelationalProjector,
|
|
3649
4374
|
GraphRenderer,
|
|
3650
4375
|
GraphSwarmProjector,
|
|
4376
|
+
GraphTreeProjector,
|
|
3651
4377
|
GridController,
|
|
4378
|
+
HierarchicalEdgeBundling,
|
|
3652
4379
|
Mesh,
|
|
3653
4380
|
PLEXUS_NODE_TYPE_FOCUS,
|
|
3654
4381
|
PLEXUS_NODE_TYPE_OBJECT,
|
|
3655
4382
|
PLEXUS_NODE_TYPE_RELATION,
|
|
3656
4383
|
Projector,
|
|
3657
4384
|
Pulsar,
|
|
4385
|
+
RadialTree,
|
|
3658
4386
|
Renderer,
|
|
3659
4387
|
SVG,
|
|
3660
4388
|
SVGContext,
|
|
3661
4389
|
SVGContextProvider,
|
|
3662
4390
|
Scale,
|
|
3663
4391
|
Screen,
|
|
4392
|
+
TREE_NODE_TYPE_INBOUND,
|
|
4393
|
+
TREE_NODE_TYPE_NODE,
|
|
4394
|
+
TREE_NODE_TYPE_ROOT,
|
|
4395
|
+
TidyTree,
|
|
4396
|
+
Tree,
|
|
3664
4397
|
Vector,
|
|
3665
4398
|
ZoomHandler,
|
|
3666
4399
|
appendRadialGroupLabel,
|
|
3667
4400
|
appendRadialLeafLabel,
|
|
3668
4401
|
appendRootLabel,
|
|
4402
|
+
buildHierarchy,
|
|
3669
4403
|
createGraphDrag,
|
|
3670
4404
|
createMarkers,
|
|
3671
4405
|
defaultForceOptions,
|
|
3672
4406
|
defaultIdAccessor,
|
|
4407
|
+
defaultTreeLayoutSlots,
|
|
3673
4408
|
emptyGraph,
|
|
3674
4409
|
getCircumferencePoints,
|
|
4410
|
+
isCollapsed,
|
|
4411
|
+
isLeaf,
|
|
3675
4412
|
layoutHorizontal,
|
|
3676
4413
|
layoutRadial,
|
|
3677
4414
|
layoutVertical,
|
|
@@ -3679,6 +4416,7 @@ export {
|
|
|
3679
4416
|
normal,
|
|
3680
4417
|
offsetPoints,
|
|
3681
4418
|
updateNode,
|
|
4419
|
+
useContainerSize,
|
|
3682
4420
|
useDynamicRef,
|
|
3683
4421
|
useGrid,
|
|
3684
4422
|
useStateRef,
|