@dxos/react-ui-graph 0.9.0 → 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.
Files changed (57) hide show
  1. package/dist/lib/browser/index.mjs +753 -15
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +753 -15
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/Graph/Graph.stories.d.ts +2 -2
  8. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  9. package/dist/types/src/components/SVG/SVG.d.ts +1 -1
  10. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  11. package/dist/types/src/components/Tree/Tree.d.ts +26 -0
  12. package/dist/types/src/components/Tree/Tree.d.ts.map +1 -0
  13. package/dist/types/src/components/Tree/index.d.ts +4 -0
  14. package/dist/types/src/components/Tree/index.d.ts.map +1 -0
  15. package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts +40 -0
  16. package/dist/types/src/components/Tree/layout/HierarchicalEdgeBundling.d.ts.map +1 -0
  17. package/dist/types/src/components/Tree/layout/RadialTree.d.ts +37 -0
  18. package/dist/types/src/components/Tree/layout/RadialTree.d.ts.map +1 -0
  19. package/dist/types/src/components/Tree/layout/TidyTree.d.ts +26 -0
  20. package/dist/types/src/components/Tree/layout/TidyTree.d.ts.map +1 -0
  21. package/dist/types/src/components/Tree/layout/hierarchy.d.ts +17 -0
  22. package/dist/types/src/components/Tree/layout/hierarchy.d.ts.map +1 -0
  23. package/dist/types/src/components/Tree/layout/index.d.ts +7 -0
  24. package/dist/types/src/components/Tree/layout/index.d.ts.map +1 -0
  25. package/dist/types/src/components/Tree/layout/slots.d.ts +13 -0
  26. package/dist/types/src/components/Tree/layout/slots.d.ts.map +1 -0
  27. package/dist/types/src/components/Tree/layout/useContainerSize.d.ts +15 -0
  28. package/dist/types/src/components/Tree/layout/useContainerSize.d.ts.map +1 -0
  29. package/dist/types/src/components/Tree/types.d.ts +11 -0
  30. package/dist/types/src/components/Tree/types.d.ts.map +1 -0
  31. package/dist/types/src/components/index.d.ts +1 -0
  32. package/dist/types/src/components/index.d.ts.map +1 -1
  33. package/dist/types/src/fx/fx.stories.d.ts +2 -2
  34. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  35. package/dist/types/src/graph/projector/graph-tree-projector.d.ts +40 -0
  36. package/dist/types/src/graph/projector/graph-tree-projector.d.ts.map +1 -0
  37. package/dist/types/src/graph/projector/index.d.ts +1 -0
  38. package/dist/types/src/graph/projector/index.d.ts.map +1 -1
  39. package/dist/types/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +21 -22
  41. package/src/components/Graph/Graph.stories.tsx +2 -2
  42. package/src/components/SVG/SVG.tsx +1 -1
  43. package/src/components/Tree/Tree.tsx +85 -0
  44. package/src/components/Tree/index.ts +7 -0
  45. package/src/components/Tree/layout/HierarchicalEdgeBundling.tsx +332 -0
  46. package/src/components/Tree/layout/RadialTree.tsx +240 -0
  47. package/src/components/Tree/layout/TidyTree.tsx +246 -0
  48. package/src/components/Tree/layout/hierarchy.ts +32 -0
  49. package/src/components/Tree/layout/index.ts +10 -0
  50. package/src/components/Tree/layout/slots.ts +25 -0
  51. package/src/components/Tree/layout/useContainerSize.ts +43 -0
  52. package/src/components/Tree/types.ts +14 -0
  53. package/src/components/index.ts +1 -0
  54. package/src/fx/fx.stories.tsx +3 -3
  55. package/src/graph/projector/graph-bundle-projector.ts +1 -1
  56. package/src/graph/projector/graph-tree-projector.ts +251 -0
  57. package/src/graph/projector/index.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-graph",
3
- "version": "0.9.0",
3
+ "version": "0.9.1-staging.ee54ba693a",
4
4
  "description": "GEM Graph.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -44,40 +44,39 @@
44
44
  "lodash.defaultsdeep": "^4.6.1",
45
45
  "react-resize-detector": "^11.0.1",
46
46
  "topojson-client": "^3.1.0",
47
- "@dxos/async": "0.9.0",
48
- "@dxos/debug": "0.9.0",
49
- "@dxos/graph": "0.9.0",
50
- "@dxos/log": "0.9.0",
51
- "@dxos/node-std": "0.9.0",
52
- "@dxos/invariant": "0.9.0",
53
- "@dxos/react-ui-mosaic": "0.9.0"
47
+ "@dxos/async": "0.9.1-staging.ee54ba693a",
48
+ "@dxos/graph": "0.9.1-staging.ee54ba693a",
49
+ "@dxos/debug": "0.9.1-staging.ee54ba693a",
50
+ "@dxos/invariant": "0.9.1-staging.ee54ba693a",
51
+ "@dxos/node-std": "0.9.1-staging.ee54ba693a",
52
+ "@dxos/log": "0.9.1-staging.ee54ba693a",
53
+ "@dxos/react-ui-mosaic": "0.9.1-staging.ee54ba693a"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@babel/core": "^7.18.13",
57
57
  "@types/d3": "^7.4.3",
58
58
  "@types/lodash.defaultsdeep": "^4.6.6",
59
- "@types/react": "~19.2.7",
59
+ "@types/react": "~19.2.17",
60
60
  "@types/react-dom": "~19.2.3",
61
61
  "@types/topojson-client": "^3.1.4",
62
62
  "@types/topojson-specification": "^1.0.5",
63
63
  "postcss": "^8.5.12",
64
- "react": "~19.2.3",
65
- "react-dom": "~19.2.3",
66
- "@dxos/random": "0.9.0",
67
- "@dxos/react-ui": "0.9.0",
68
- "@dxos/react-ui-syntax-highlighter": "0.9.0",
69
- "@dxos/storybook-utils": "0.9.0",
70
- "@dxos/ui-theme": "0.9.0",
71
- "@dxos/react-ui-stack": "0.9.0"
64
+ "react": "~19.2.7",
65
+ "react-dom": "~19.2.7",
66
+ "@dxos/random": "0.9.1-staging.ee54ba693a",
67
+ "@dxos/storybook-utils": "0.9.1-staging.ee54ba693a",
68
+ "@dxos/react-ui-syntax-highlighter": "0.9.1-staging.ee54ba693a",
69
+ "@dxos/react-ui": "0.9.1-staging.ee54ba693a",
70
+ "@dxos/ui-theme": "0.9.1-staging.ee54ba693a"
72
71
  },
73
72
  "peerDependencies": {
74
- "react": "~19.2.3",
75
- "react-dom": "~19.2.3",
76
- "@dxos/ui-theme": "0.9.0",
77
- "@dxos/react-ui": "0.9.0"
73
+ "react": "~19.2.7",
74
+ "react-dom": "~19.2.7",
75
+ "@dxos/react-ui": "0.9.1-staging.ee54ba693a",
76
+ "@dxos/ui-theme": "0.9.1-staging.ee54ba693a"
78
77
  },
79
78
  "optionalDependencies": {
80
- "@dxos/random": "0.9.0"
79
+ "@dxos/random": "0.9.1-staging.ee54ba693a"
81
80
  },
82
81
  "publishConfig": {
83
82
  "access": "public"
@@ -49,7 +49,7 @@ const projectorTypes: Record<ProjectorType, Factory> = {
49
49
  relational: GraphRelationalProjector as Factory,
50
50
  };
51
51
 
52
- type DefaultStoryProps = GraphProps & {
52
+ type StoryArgs = GraphProps & {
53
53
  debug?: boolean;
54
54
  grid?: boolean | SVGGridProps;
55
55
  inspect?: boolean;
@@ -72,7 +72,7 @@ const DefaultStory = ({
72
72
  projectorType: _projectorType = 'force',
73
73
  projectorOptions,
74
74
  ...props
75
- }: DefaultStoryProps) => {
75
+ }: StoryArgs) => {
76
76
  const graphRef = useRef<GraphController | null>(null);
77
77
  const context = useRef<SVGContext>(null);
78
78
  const registry = useContext(RegistryContext);
@@ -36,4 +36,4 @@ export const SVG: SVG = {
36
36
  FPS,
37
37
  };
38
38
 
39
- export type { SVGRootProps, SVGGridProps, SVGMarkersProps, SVGZoomProps, SVGGraphProps, SVGMeshProps, SVGFPSProps };
39
+ export type { SVGFPSProps, SVGGraphProps, SVGGridProps, SVGMarkersProps, SVGMeshProps, SVGRootProps, SVGZoomProps };
@@ -0,0 +1,85 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { useMemo } from 'react';
6
+
7
+ import { type ThemedClassName } from '@dxos/react-ui';
8
+
9
+ import { type BundleEdge, HierarchicalEdgeBundling, RadialTree, TidyTree, type TreeLayoutSlots } from './layout';
10
+ import { type TreeNode } from './types';
11
+
12
+ export type LayoutVariant = 'tidy' | 'radial' | 'edge';
13
+
14
+ export type TreeComponentProps = ThemedClassName<{
15
+ data: TreeNode;
16
+ /** Optional edges for the `edge` variant (hierarchical edge bundling). */
17
+ edges?: BundleEdge[];
18
+ variant?: LayoutVariant;
19
+ label?: (node: TreeNode) => string;
20
+ slots?: TreeLayoutSlots;
21
+ /** Margin in screen pixels reserved around the layout (forwarded to the `tidy` layout). */
22
+ margin?: number;
23
+ initialCollapsed?: Iterable<string>;
24
+ onNodeClick?: (node: TreeNode) => void;
25
+ onNodeHover?: (node: TreeNode | null, event?: MouseEvent) => void;
26
+ }>;
27
+
28
+ /**
29
+ * Tree visualization wrapping the three layout variants.
30
+ * - `tidy` — horizontal tidy tree (collapsible)
31
+ * - `radial` — radial tree (collapsible)
32
+ * - `edge` — hierarchical edge bundling (`edges` connect leaves)
33
+ */
34
+ export const Tree = ({
35
+ classNames,
36
+ data,
37
+ edges,
38
+ variant = 'tidy',
39
+ label,
40
+ slots,
41
+ margin,
42
+ initialCollapsed,
43
+ onNodeClick,
44
+ onNodeHover,
45
+ }: TreeComponentProps) => {
46
+ return useMemo(() => {
47
+ switch (variant) {
48
+ case 'tidy':
49
+ return (
50
+ <TidyTree
51
+ classNames={classNames}
52
+ data={data}
53
+ label={label}
54
+ slots={slots}
55
+ margin={margin}
56
+ initialCollapsed={initialCollapsed}
57
+ onNodeClick={onNodeClick}
58
+ />
59
+ );
60
+ case 'radial':
61
+ return (
62
+ <RadialTree
63
+ classNames={classNames}
64
+ data={data}
65
+ label={label}
66
+ slots={slots}
67
+ initialCollapsed={initialCollapsed}
68
+ onNodeClick={onNodeClick}
69
+ onNodeHover={onNodeHover}
70
+ />
71
+ );
72
+ case 'edge':
73
+ return (
74
+ <HierarchicalEdgeBundling
75
+ classNames={classNames}
76
+ data={data}
77
+ edges={edges ?? []}
78
+ label={label}
79
+ slots={slots}
80
+ onNodeHover={onNodeHover}
81
+ />
82
+ );
83
+ }
84
+ }, [variant, classNames, data, edges, label, slots, initialCollapsed, onNodeClick, onNodeHover]);
85
+ };
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ export * from './Tree';
6
+ export * from './layout';
7
+ export type { TreeNode } from './types';
@@ -0,0 +1,332 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ // Copyright 2024 Observable, Inc.
4
+ //
5
+
6
+ import { type HierarchyNode, cluster, curveBundle, hierarchy, lineRadial, select } from 'd3';
7
+ import React, { useEffect, useMemo, useRef } from 'react';
8
+
9
+ import { type ThemedClassName } from '@dxos/react-ui';
10
+ import { mx } from '@dxos/ui-theme';
11
+
12
+ import { type TreeNode } from '../types';
13
+ import { type TreeLayoutSlots, defaultTreeLayoutSlots } from './slots';
14
+ import { useContainerSize } from './useContainerSize';
15
+
16
+ const TRANSITION_MS = 350;
17
+
18
+ /** A directed edge between two leaves of the hierarchy, identified by node id. */
19
+ export type BundleEdge = {
20
+ source: string;
21
+ target: string;
22
+ kind?: string;
23
+ };
24
+
25
+ export type HierarchicalEdgeBundlingProps = ThemedClassName<{
26
+ /** Hierarchical data; leaves are the connectable entities. */
27
+ data: TreeNode;
28
+ /** Edges between leaves (by id). Bundled through the hierarchy. */
29
+ edges?: BundleEdge[];
30
+ /** Label accessor for leaf nodes. */
31
+ label?: (d: TreeNode) => string;
32
+ /** Padding (in screen pixels) reserved around the radial layout. */
33
+ padding?: number;
34
+ /** Bundling tension; 0 = straight, 1 = maximally bundled. */
35
+ tension?: number;
36
+ /** Leaf node circle radius (matches the cluster layout's `r`). */
37
+ r?: number;
38
+ slots?: TreeLayoutSlots;
39
+ /**
40
+ * Called when the user hovers a leaf node (with the event so callers can dispatch
41
+ * `DxAnchorActivate` for previews). Receives `null` on leave.
42
+ */
43
+ onNodeHover?: (node: TreeNode | null, event?: MouseEvent) => void;
44
+ }>;
45
+
46
+ /**
47
+ * Hierarchical edge bundling.
48
+ * https://observablehq.com/@d3/hierarchical-edge-bundling?intent=fork
49
+ *
50
+ * Leaves are placed on a circle, grouped by their parent in the hierarchy.
51
+ * Edges between leaves are drawn as bundled curves that route through their lowest common ancestor.
52
+ */
53
+ export const HierarchicalEdgeBundling = ({
54
+ classNames,
55
+ data,
56
+ edges = [],
57
+ label = (d) => d.label ?? d.id,
58
+ padding = 120,
59
+ tension = 0.85,
60
+ r = 4,
61
+ slots = defaultTreeLayoutSlots,
62
+ onNodeHover,
63
+ }: HierarchicalEdgeBundlingProps) => {
64
+ const svgRef = useRef<SVGSVGElement | null>(null);
65
+ const { setRef, width, height } = useContainerSize();
66
+
67
+ const root = useMemo(() => buildBundleHierarchy(data, edges), [data, edges]);
68
+
69
+ // Stable hover ref so the effect doesn't rebind handlers on every render.
70
+ const handleHoverRef = useRef<(node: TreeNode | null, event?: MouseEvent) => void>(() => {});
71
+ handleHoverRef.current = (node, event) => onNodeHover?.(node, event);
72
+
73
+ useEffect(() => {
74
+ if (!svgRef.current || !width || !height) {
75
+ return;
76
+ }
77
+
78
+ const radius = Math.max(0, Math.min(width, height) / 2 - padding);
79
+ renderBundling(svgRef.current, root, {
80
+ radius,
81
+ r,
82
+ label,
83
+ slots,
84
+ tension,
85
+ onNodeHover: (n, e) => handleHoverRef.current(n, e),
86
+ });
87
+ }, [root, width, height, padding, tension, r, label, slots]);
88
+
89
+ return (
90
+ <div ref={setRef} className={mx('dx-expander relative', classNames)}>
91
+ {width > 0 && height > 0 && (
92
+ <svg
93
+ ref={svgRef}
94
+ xmlns='http://www.w3.org/2000/svg'
95
+ width={width}
96
+ height={height}
97
+ viewBox={`${-width / 2} ${-height / 2} ${width} ${height}`}
98
+ />
99
+ )}
100
+ </div>
101
+ );
102
+ };
103
+
104
+ type BundleHierarchy = HierarchyNode<TreeNode> & {
105
+ outgoing?: Array<[BundleHierarchy, BundleHierarchy, BundleEdge]>;
106
+ incoming?: Array<[BundleHierarchy, BundleHierarchy, BundleEdge]>;
107
+ pathEl?: SVGPathElement | null;
108
+ text?: SVGTextElement | null;
109
+ circle?: SVGCircleElement | null;
110
+ };
111
+
112
+ /**
113
+ * Build the bundling hierarchy from data + edges.
114
+ * Edges connect leaves (by id); the cluster layout places leaves on the circle.
115
+ */
116
+ const buildBundleHierarchy = (data: TreeNode, edges: BundleEdge[]): BundleHierarchy => {
117
+ const root = hierarchy<TreeNode>(data) as BundleHierarchy;
118
+ const byId = new Map<string, BundleHierarchy>();
119
+ for (const node of root.descendants() as BundleHierarchy[]) {
120
+ byId.set(node.data.id, node);
121
+ node.outgoing = [];
122
+ node.incoming = [];
123
+ }
124
+
125
+ for (const edge of edges) {
126
+ const source = byId.get(edge.source);
127
+ const target = byId.get(edge.target);
128
+ if (!source || !target || source === target) {
129
+ continue;
130
+ }
131
+ source.outgoing!.push([source, target, edge]);
132
+ target.incoming!.push([source, target, edge]);
133
+ }
134
+
135
+ return root;
136
+ };
137
+
138
+ type RenderOptions = {
139
+ radius: number;
140
+ r: number;
141
+ tension: number;
142
+ label: (d: TreeNode) => string;
143
+ slots: TreeLayoutSlots;
144
+ onNodeHover: (node: TreeNode | null, event?: MouseEvent) => void;
145
+ };
146
+
147
+ const renderBundling = (svgElement: SVGSVGElement, root: BundleHierarchy, options: RenderOptions) => {
148
+ const { radius, r, tension, label, slots, onNodeHover } = options;
149
+ const svg = select(svgElement);
150
+
151
+ // Degenerate root (no descendants yet): clear any previously rendered bundle so a stale
152
+ // graph doesn't linger after the hierarchy empties out, then no-op.
153
+ if (!root.children?.length) {
154
+ svg.selectAll('g.dx-bundle-root').remove();
155
+ return;
156
+ }
157
+
158
+ cluster<TreeNode>().size([2 * Math.PI, radius])(root);
159
+
160
+ const g = svg.selectAll<SVGGElement, null>('g.dx-bundle-root').data([null]).join('g').classed('dx-bundle-root', true);
161
+
162
+ const linksLayer = g
163
+ .selectAll<SVGGElement, null>('g.dx-bundle-links')
164
+ .data([null])
165
+ .join('g')
166
+ .classed('dx-bundle-links', true);
167
+
168
+ const nodesLayer = g
169
+ .selectAll<SVGGElement, null>('g.dx-bundle-nodes')
170
+ .data([null])
171
+ .join('g')
172
+ .classed('dx-bundle-nodes', true);
173
+
174
+ const line = lineRadial<any>()
175
+ .curve(curveBundle.beta(tension))
176
+ .radius((d: any) => d.y)
177
+ .angle((d: any) => d.x);
178
+
179
+ // Each edge: route through the lowest common ancestor via hierarchy.path().
180
+ const leaves = root.leaves() as BundleHierarchy[];
181
+ const flatEdges = leaves.flatMap((leaf) => leaf.outgoing ?? []);
182
+
183
+ const paths = linksLayer
184
+ .selectAll<SVGPathElement, any>('path')
185
+ .data(flatEdges, (d: any) => `${d[0].data.id}->${d[1].data.id}`)
186
+ .join(
187
+ (enter) =>
188
+ enter
189
+ .append('path')
190
+ .attr('class', slots.path ?? '')
191
+ .attr('fill', 'none')
192
+ .attr('opacity', 0),
193
+ (update) => update,
194
+ (exit) =>
195
+ exit
196
+ .each(function () {
197
+ select(this).interrupt();
198
+ })
199
+ .transition()
200
+ .duration(TRANSITION_MS)
201
+ .attr('opacity', 0)
202
+ .remove(),
203
+ );
204
+
205
+ paths
206
+ .each(function (d: any) {
207
+ d[0].pathEl = this;
208
+ })
209
+ .transition()
210
+ .duration(TRANSITION_MS)
211
+ .attr('opacity', 1)
212
+ .attr('d', ([s, t]) => line(s.path(t)));
213
+
214
+ // Render a circle + label per leaf along the perimeter (matches the cluster layout).
215
+ const labels = nodesLayer
216
+ .selectAll<SVGGElement, any>('g.dx-bundle-leaf')
217
+ .data(leaves, (d: any) => d.data.id)
218
+ .join(
219
+ (enter) => {
220
+ const ge = enter.append('g').classed('dx-bundle-leaf', true).attr('opacity', 0);
221
+ ge.append('circle').style('cursor', 'pointer');
222
+ ge.append('text').attr('dy', '0.32em').attr('paint-order', 'stroke').style('cursor', 'pointer');
223
+ return ge;
224
+ },
225
+ (update) => update,
226
+ (exit) =>
227
+ exit
228
+ .each(function () {
229
+ select(this).interrupt();
230
+ })
231
+ .transition()
232
+ .duration(TRANSITION_MS)
233
+ .attr('opacity', 0)
234
+ .remove(),
235
+ );
236
+
237
+ labels
238
+ .transition()
239
+ .duration(TRANSITION_MS)
240
+ .attr('opacity', 1)
241
+ .attr('transform', (d: any) => `rotate(${(d.x * 180) / Math.PI - 90}) translate(${d.y},0)`);
242
+
243
+ const onEnter = function (this: SVGElement, event: MouseEvent, d: BundleHierarchy) {
244
+ onNodeHover(d.data, event);
245
+ hover(linksLayer, leaves, d, true);
246
+ };
247
+ const onLeave = function (this: SVGElement, event: MouseEvent, d: BundleHierarchy) {
248
+ onNodeHover(null);
249
+ hover(linksLayer, leaves, d, false);
250
+ };
251
+
252
+ labels
253
+ .select<SVGCircleElement>('circle')
254
+ .attr('class', [slots.node ?? '', 'dx-leaf'].filter(Boolean).join(' '))
255
+ .attr('r', r)
256
+ .style('fill', (d: BundleHierarchy) => slots.nodeFill?.(d.data.data) ?? null)
257
+ .each(function (d: BundleHierarchy) {
258
+ d.circle = this;
259
+ })
260
+ .on('pointerenter', onEnter)
261
+ .on('pointerleave', onLeave);
262
+
263
+ labels
264
+ .select<SVGTextElement>('text')
265
+ .attr('class', slots.text ?? '')
266
+ .attr('x', (d: any) => (d.x < Math.PI ? r + 4 : -(r + 4)))
267
+ .attr('text-anchor', (d: any) => (d.x < Math.PI ? 'start' : 'end'))
268
+ .attr('transform', (d: any) => (d.x >= Math.PI ? 'rotate(180)' : null))
269
+ .each(function (d: BundleHierarchy) {
270
+ d.text = this;
271
+ })
272
+ .text((d: any) => label(d.data))
273
+ .on('pointerenter', onEnter)
274
+ .on('pointerleave', onLeave);
275
+ };
276
+
277
+ const hover = (linksLayer: any, leaves: BundleHierarchy[], focused: BundleHierarchy, on: boolean) => {
278
+ const outgoing = new Set((focused.outgoing ?? []).map(([, t]) => t));
279
+ const incoming = new Set((focused.incoming ?? []).map(([s]) => s));
280
+
281
+ // Use D3 inline styles (highest specificity) so results are visible regardless of CSS cascade.
282
+ // Inline styles set to `null` are removed, restoring the element's default appearance.
283
+ (linksLayer.selectAll('path') as any)
284
+ .style('stroke', (d: any) => {
285
+ if (!on) {
286
+ return null;
287
+ }
288
+ if (d[0] === focused) {
289
+ return 'var(--color-orange-500)';
290
+ }
291
+ if (d[1] === focused) {
292
+ return 'var(--color-sky-500)';
293
+ }
294
+ return null;
295
+ })
296
+ .style('stroke-width', (d: any) => (on && (d[0] === focused || d[1] === focused) ? '1.5px' : null))
297
+ .style('opacity', (d: any) => (on && d[0] !== focused && d[1] !== focused ? '0.08' : null));
298
+
299
+ for (const leaf of leaves) {
300
+ const isOut = outgoing.has(leaf);
301
+ const isIn = incoming.has(leaf);
302
+ const isConnected = isOut || isIn;
303
+
304
+ if (leaf.text) {
305
+ select(leaf.text)
306
+ .style('fill', () => {
307
+ if (!on) {
308
+ return null;
309
+ }
310
+ if (leaf === focused) {
311
+ return 'var(--color-neutral-900)';
312
+ }
313
+ if (isOut) {
314
+ return 'var(--color-orange-500)';
315
+ }
316
+ if (isIn) {
317
+ return 'var(--color-sky-500)';
318
+ }
319
+ return null;
320
+ })
321
+ .style('font-weight', () => (on && leaf === focused ? '600' : null));
322
+ }
323
+ if (leaf.circle) {
324
+ select(leaf.circle)
325
+ .style('stroke', () => (on && isConnected ? 'var(--color-orange-400)' : null))
326
+ .style('stroke-width', () => (on && isConnected ? '2.5px' : null))
327
+ .style('opacity', () => (on && !isConnected && leaf !== focused ? '0.15' : null));
328
+ }
329
+ }
330
+ };
331
+
332
+ export default HierarchicalEdgeBundling;