@dxos/react-ui-graph 0.8.4-main.422d1c7879 → 0.8.4-main.43cb759274

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 (116) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/{chunk-LKC455GK.mjs → chunk-EASNZZ7B.mjs} +1 -1
  3. package/dist/lib/browser/{chunk-LKC455GK.mjs.map → chunk-EASNZZ7B.mjs.map} +2 -2
  4. package/dist/lib/browser/index.mjs +1783 -496
  5. package/dist/lib/browser/index.mjs.map +4 -4
  6. package/dist/lib/browser/meta.json +1 -1
  7. package/dist/lib/browser/testing/index.mjs +1 -1
  8. package/dist/lib/browser/testing/index.mjs.map +2 -2
  9. package/dist/lib/node-esm/{chunk-JE4KZCUF.mjs → chunk-JSE2X4ML.mjs} +1 -1
  10. package/dist/lib/node-esm/{chunk-JE4KZCUF.mjs.map → chunk-JSE2X4ML.mjs.map} +2 -2
  11. package/dist/lib/node-esm/index.mjs +1783 -496
  12. package/dist/lib/node-esm/index.mjs.map +4 -4
  13. package/dist/lib/node-esm/meta.json +1 -1
  14. package/dist/lib/node-esm/testing/index.mjs +1 -1
  15. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  16. package/dist/types/src/components/Graph/Graph.d.ts +20 -2
  17. package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
  18. package/dist/types/src/components/Graph/Graph.stories.d.ts +3 -3
  19. package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
  21. package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
  22. package/dist/types/src/components/SVG/FPS.d.ts +20 -0
  23. package/dist/types/src/components/SVG/FPS.d.ts.map +1 -0
  24. package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
  25. package/dist/types/src/components/SVG/Markers.d.ts.map +1 -1
  26. package/dist/types/src/components/SVG/Root.d.ts +5 -1
  27. package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
  28. package/dist/types/src/components/SVG/SVG.d.ts +3 -1
  29. package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
  30. package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
  31. package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
  32. package/dist/types/src/fx/pulsar.d.ts.map +1 -1
  33. package/dist/types/src/graph/markers.d.ts.map +1 -1
  34. package/dist/types/src/graph/projector/graph-bundle-projector.d.ts +47 -0
  35. package/dist/types/src/graph/projector/graph-bundle-projector.d.ts.map +1 -0
  36. package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +65 -0
  37. package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -0
  38. package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
  39. package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
  40. package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
  41. package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
  42. package/dist/types/src/graph/projector/graph-lattice-projector.d.ts +23 -0
  43. package/dist/types/src/graph/projector/graph-lattice-projector.d.ts.map +1 -0
  44. package/dist/types/src/graph/projector/graph-plexus-projector.d.ts +67 -0
  45. package/dist/types/src/graph/projector/graph-plexus-projector.d.ts.map +1 -0
  46. package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts +2 -0
  47. package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts.map +1 -0
  48. package/dist/types/src/graph/projector/graph-projector.d.ts +8 -0
  49. package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
  50. package/dist/types/src/graph/projector/graph-radial-projector.d.ts +6 -0
  51. package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
  52. package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
  53. package/dist/types/src/graph/projector/graph-swarm-projector.d.ts +72 -0
  54. package/dist/types/src/graph/projector/graph-swarm-projector.d.ts.map +1 -0
  55. package/dist/types/src/graph/projector/index.d.ts +5 -0
  56. package/dist/types/src/graph/projector/index.d.ts.map +1 -1
  57. package/dist/types/src/graph/projector/projector.d.ts +10 -1
  58. package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
  59. package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
  60. package/dist/types/src/graph/renderer/graph-renderer.d.ts +41 -1
  61. package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
  62. package/dist/types/src/graph/renderer/index.d.ts +1 -0
  63. package/dist/types/src/graph/renderer/index.d.ts.map +1 -1
  64. package/dist/types/src/graph/renderer/labels.d.ts +33 -0
  65. package/dist/types/src/graph/renderer/labels.d.ts.map +1 -0
  66. package/dist/types/src/graph/renderer/renderer.d.ts +12 -1
  67. package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
  68. package/dist/types/src/graph/types.d.ts +14 -0
  69. package/dist/types/src/graph/types.d.ts.map +1 -1
  70. package/dist/types/src/hooks/useGrid.d.ts.map +1 -1
  71. package/dist/types/src/hooks/useStateRef.d.ts.map +1 -1
  72. package/dist/types/src/hooks/useSvgContext.d.ts.map +1 -1
  73. package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
  74. package/dist/types/src/stories/experimental.stories.d.ts +7 -0
  75. package/dist/types/src/stories/experimental.stories.d.ts.map +1 -0
  76. package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
  77. package/dist/types/src/testing/data.d.ts +1 -1
  78. package/dist/types/src/testing/data.d.ts.map +1 -1
  79. package/dist/types/src/testing/hooks.d.ts.map +1 -1
  80. package/dist/types/src/testing/model.d.ts.map +1 -1
  81. package/dist/types/src/util/events.d.ts.map +1 -1
  82. package/dist/types/src/util/fraction.d.ts.map +1 -1
  83. package/dist/types/src/util/points.d.ts.map +1 -1
  84. package/dist/types/src/util/scale.d.ts.map +1 -1
  85. package/dist/types/src/util/screen.d.ts.map +1 -1
  86. package/dist/types/src/util/vector.d.ts.map +1 -1
  87. package/dist/types/tsconfig.tsbuildinfo +1 -1
  88. package/package.json +19 -19
  89. package/src/components/Graph/Graph.stories.tsx +5 -5
  90. package/src/components/Graph/Graph.tsx +116 -21
  91. package/src/components/Mesh/Mesh.stories.tsx +6 -4
  92. package/src/components/Mesh/Mesh.tsx +43 -35
  93. package/src/components/SVG/FPS.tsx +91 -0
  94. package/src/components/SVG/Root.tsx +30 -4
  95. package/src/components/SVG/SVG.tsx +4 -1
  96. package/src/graph/projector/graph-bundle-projector.ts +210 -0
  97. package/src/graph/projector/graph-cluster-projector.ts +337 -0
  98. package/src/graph/projector/graph-force-projector.ts +6 -1
  99. package/src/graph/projector/graph-hierarchical-projector.ts +1 -0
  100. package/src/graph/projector/graph-lattice-projector.ts +86 -0
  101. package/src/graph/projector/graph-plexus-projector.test.ts +102 -0
  102. package/src/graph/projector/graph-plexus-projector.ts +309 -0
  103. package/src/graph/projector/graph-projector.ts +22 -1
  104. package/src/graph/projector/graph-radial-projector.ts +30 -2
  105. package/src/graph/projector/graph-relational-projector.ts +1 -0
  106. package/src/graph/projector/graph-swarm-projector.ts +373 -0
  107. package/src/graph/projector/index.ts +5 -0
  108. package/src/graph/projector/projector.ts +12 -3
  109. package/src/graph/renderer/graph-renderer.ts +289 -30
  110. package/src/graph/renderer/index.ts +1 -0
  111. package/src/graph/renderer/labels.ts +138 -0
  112. package/src/graph/renderer/renderer.ts +15 -4
  113. package/src/graph/types.ts +14 -0
  114. package/src/stories/experimental.stories.tsx +446 -0
  115. package/src/stories/hooks.stories.tsx +6 -1
  116. package/styles/graph.css +51 -2
@@ -0,0 +1,446 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import { linkRadial } from 'd3';
7
+ import React from 'react';
8
+
9
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
+
11
+ const meta: Meta = {
12
+ title: 'ui/react-ui-graph/experimental',
13
+ decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
14
+ parameters: {
15
+ layout: 'fullscreen',
16
+ },
17
+ };
18
+
19
+ export default meta;
20
+
21
+ type Story = StoryObj;
22
+
23
+ // ---------------------------------------------------------------------------
24
+ // PathProbe — renders a fixed set of example bezier paths the cluster layout
25
+ // might emit, side-by-side across five columns:
26
+ // 1. Baked path strings (cubic / quadratic) as the cluster projector once
27
+ // emitted them.
28
+ // 2. linkRadial output from polar coordinates — should match column 1.
29
+ // 3. radialQuadratic — Q with control at (target.angle, source.radius).
30
+ // 4. radialElbow — sharp 2-segment elbow through the same knee.
31
+ // 5. radialSmoothElbow — cubic with both controls at the knee.
32
+ //
33
+ // Kept around so future curve experiments can compare candidate generators
34
+ // at a glance without touching the production cluster projector.
35
+ // ---------------------------------------------------------------------------
36
+
37
+ const PROBE_PATHS = [
38
+ // Source group at M(-174.87, -44.729). All three paths share that origin.
39
+ {
40
+ label: 'good (target angle 5.19, clockwise)',
41
+ color: 'lime',
42
+ d: 'M-174.87,-44.729 C-262.305,-67.094, -240.395,-124.563, -320.527,-166.083',
43
+ target: [-320.527, -166.083] as [number, number],
44
+ },
45
+ {
46
+ label: 'good (target angle 5.55, clockwise)',
47
+ color: 'cyan',
48
+ d: 'M-174.87,-44.729 C-262.305,-67.094, -180.249,-202.029, -240.332,-269.372',
49
+ target: [-240.332, -269.372] as [number, number],
50
+ },
51
+ {
52
+ label: 'bad (target angle 4.28, counter-clockwise)',
53
+ color: 'orange',
54
+ d: 'M-174.87,-44.729 C-262.305,-67.094, -245.815,113.492, -327.754,151.323',
55
+ target: [-327.754, 151.323] as [number, number],
56
+ },
57
+ // Live path the user reports as not rendering correctly in the full cluster.
58
+ // Source polar ≈ (1.14, 190.5); target polar ≈ (1.82, 380.9). Clockwise direction.
59
+ {
60
+ label: 'live broken (clockwise, source.x=1.14 → target.x=1.82)',
61
+ color: 'magenta',
62
+ d: 'M172.95585588832455,-79.85312713937451Q184.55815606041466,47.20738323164743 369.1163121208293,94.41476646329485',
63
+ target: [369.1163121208293, 94.41476646329485] as [number, number],
64
+ },
65
+ ];
66
+
67
+ const SOURCE_XY: [number, number] = [-174.87, -44.729];
68
+
69
+ // Reverse-engineered polar coords from the user's reported path strings.
70
+ // Source group: polar (4.96 rad, 181) → cartesian (-174.87, -44.729).
71
+ // We use linkRadial here directly to verify the strings d3 produces match what we expect.
72
+ const SOURCE_POLAR = { x: 4.96, y: 181 } as { x: number; y: number };
73
+ const PROBE_POLAR_TARGETS = [
74
+ { label: 'target 5.19 (clockwise)', color: 'lime', polar: { x: 5.19, y: 360 } },
75
+ { label: 'target 5.55 (clockwise)', color: 'cyan', polar: { x: 5.55, y: 361 } },
76
+ { label: 'target 4.28 (counter-clockwise)', color: 'orange', polar: { x: 4.28, y: 361 } },
77
+ ];
78
+
79
+ /** Convert d3-cluster polar (angle from 12 o'clock, sweeping clockwise) to cartesian. */
80
+ const polarToCartesian = (angle: number, radius: number): [number, number] => [
81
+ Math.cos(angle - Math.PI / 2) * radius,
82
+ Math.sin(angle - Math.PI / 2) * radius,
83
+ ];
84
+
85
+ /**
86
+ * Alternative curve: quadratic bezier from source to target with a single control point at
87
+ * (target.angle, source.radius). This makes the curve emerge from source heading TOWARD
88
+ * the target's angular direction (vs. linkRadial's curveBumpPolar, which emerges along
89
+ * source's angle and may bow far away from the target on the way).
90
+ */
91
+ const radialQuadratic = (source: { x: number; y: number }, target: { x: number; y: number }) => {
92
+ const [sx, sy] = polarToCartesian(source.x, source.y);
93
+ const [tx, ty] = polarToCartesian(target.x, target.y);
94
+ const [cx, cy] = polarToCartesian(target.x, source.y);
95
+ return `M${sx},${sy}Q${cx},${cy} ${tx},${ty}`;
96
+ };
97
+
98
+ /** Sharp elbow: M source L (target.angle, source.radius) L target. Hard-corner radial elbow. */
99
+ const radialElbow = (source: { x: number; y: number }, target: { x: number; y: number }) => {
100
+ const [sx, sy] = polarToCartesian(source.x, source.y);
101
+ const [tx, ty] = polarToCartesian(target.x, target.y);
102
+ const [cx, cy] = polarToCartesian(target.x, source.y);
103
+ return `M${sx},${sy}L${cx},${cy}L${tx},${ty}`;
104
+ };
105
+
106
+ /**
107
+ * Smoothed radial elbow: cubic bezier whose control points sit at the elbow knee. Curve
108
+ * emerges from source TOWARD the target angle (around the source ring), then bends OUT to
109
+ * target's radius. Eliminates the wide-ear from linkRadial AND the missing-stub from the
110
+ * pure quadratic — both halves of the curve are visible and follow the radial layout.
111
+ */
112
+ const radialSmoothElbow = (source: { x: number; y: number }, target: { x: number; y: number }) => {
113
+ const [sx, sy] = polarToCartesian(source.x, source.y);
114
+ const [tx, ty] = polarToCartesian(target.x, target.y);
115
+ const [kx, ky] = polarToCartesian(target.x, source.y); // "knee" — at source radius, target angle
116
+ // Both control points near the knee so the curve hugs the elbow.
117
+ return `M${sx},${sy}C${kx},${ky} ${kx},${ky} ${tx},${ty}`;
118
+ };
119
+
120
+ const PathProbe = () => {
121
+ const radialLink = linkRadial<any, any>()
122
+ .angle((d) => d.x)
123
+ .radius((d) => d.y);
124
+
125
+ return (
126
+ <div style={{ width: '100vw', height: '100vh', background: '#0c0c0c', position: 'relative' }}>
127
+ <svg
128
+ xmlns='http://www.w3.org/2000/svg'
129
+ width='100%'
130
+ height='100%'
131
+ viewBox='-450 -350 4000 700'
132
+ style={{ display: 'block' }}
133
+ >
134
+ {/* Center reference (column 1: baked paths) */}
135
+ <line x1={-450} y1={0} x2={450} y2={0} stroke='#222' />
136
+ <line x1={0} y1={-350} x2={0} y2={350} stroke='#222' />
137
+
138
+ {/* Origin marker */}
139
+ <circle cx={0} cy={0} r={3} fill='#444' />
140
+ <text x={-440} y={-330} fill='#666' fontSize={11}>
141
+ baked path strings (left)
142
+ </text>
143
+
144
+ {/* Source group circle */}
145
+ <circle cx={SOURCE_XY[0]} cy={SOURCE_XY[1]} r={5} fill='#888' />
146
+
147
+ {/* Pre-baked path strings (left column visualization). Handles both cubic (C) and
148
+ quadratic (Q) bezier commands. */}
149
+ {PROBE_PATHS.map((p, i) => {
150
+ const cubic = p.d.match(
151
+ /M\s*([-\d.]+),\s*([-\d.]+)\s*C\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+)/,
152
+ );
153
+ const quad = p.d.match(/M\s*([-\d.]+),\s*([-\d.]+)\s*Q\s*([-\d.]+),\s*([-\d.]+)\s+([-\d.]+),\s*([-\d.]+)/);
154
+ const controls: Array<[number, number]> = [];
155
+ let mx = 0,
156
+ my = 0,
157
+ ex = 0,
158
+ ey = 0;
159
+ if (cubic) {
160
+ const v = cubic.map(parseFloat);
161
+ mx = v[1];
162
+ my = v[2];
163
+ controls.push([v[3], v[4]], [v[5], v[6]]);
164
+ ex = v[7];
165
+ ey = v[8];
166
+ } else if (quad) {
167
+ const v = quad.map(parseFloat);
168
+ mx = v[1];
169
+ my = v[2];
170
+ controls.push([v[3], v[4]]);
171
+ ex = v[5];
172
+ ey = v[6];
173
+ }
174
+ return (
175
+ <g key={`baked-${i}`}>
176
+ <path d={p.d} fill='none' stroke={p.color} strokeWidth={2} />
177
+ <polyline
178
+ points={[`${mx},${my}`, ...controls.map(([x, y]) => `${x},${y}`), `${ex},${ey}`].join(' ')}
179
+ fill='none'
180
+ stroke={p.color}
181
+ strokeOpacity={0.3}
182
+ strokeWidth={1}
183
+ strokeDasharray='2 3'
184
+ />
185
+ {controls.map(([x, y], j) => (
186
+ <circle key={j} cx={x} cy={y} r={3} fill={p.color} opacity={0.5} />
187
+ ))}
188
+ <circle cx={p.target[0]} cy={p.target[1]} r={5} fill={p.color} />
189
+ <text x={p.target[0] + 8} y={p.target[1]} fill={p.color} fontSize={11}>
190
+ {p.label}
191
+ </text>
192
+ </g>
193
+ );
194
+ })}
195
+
196
+ {/* Re-generate the same paths via linkRadial from polar coords. Shift right by 700 so they
197
+ sit in a second column for direct visual comparison. */}
198
+ <g transform='translate(750, 0)'>
199
+ <line x1={-450} y1={0} x2={450} y2={0} stroke='#222' />
200
+ <line x1={0} y1={-350} x2={0} y2={350} stroke='#222' />
201
+ <circle cx={0} cy={0} r={3} fill='#444' />
202
+ <circle cx={SOURCE_XY[0]} cy={SOURCE_XY[1]} r={5} fill='#888' />
203
+ <text x={-440} y={-330} fill='#666' fontSize={11}>
204
+ linkRadial output from polar (middle)
205
+ </text>
206
+ {PROBE_POLAR_TARGETS.map((p, i) => {
207
+ const d = radialLink({ source: SOURCE_POLAR, target: p.polar }) ?? '';
208
+ const m = d.match(
209
+ /M\s*([-\d.]+),\s*([-\d.]+)\s*C\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+),\s*([-\d.]+)/,
210
+ );
211
+ if (!m) {
212
+ return null;
213
+ }
214
+ const [, , , c1x, c1y, c2x, c2y, ex, ey] = m.map(parseFloat);
215
+ return (
216
+ <g key={`fresh-${i}`}>
217
+ <path d={d} fill='none' stroke={p.color} strokeWidth={2} />
218
+ <circle cx={c1x} cy={c1y} r={3} fill={p.color} opacity={0.5} />
219
+ <circle cx={c2x} cy={c2y} r={3} fill={p.color} opacity={0.5} />
220
+ <circle cx={ex} cy={ey} r={5} fill={p.color} />
221
+ <text x={ex + 8} y={ey} fill={p.color} fontSize={11}>
222
+ {p.label}
223
+ </text>
224
+ </g>
225
+ );
226
+ })}
227
+ </g>
228
+
229
+ {/* Alternative A: quadratic with control at (target.angle, source.radius). */}
230
+ <g transform='translate(1500, 0)'>
231
+ <line x1={-450} y1={0} x2={450} y2={0} stroke='#222' />
232
+ <line x1={0} y1={-350} x2={0} y2={350} stroke='#222' />
233
+ <circle cx={0} cy={0} r={3} fill='#444' />
234
+ <circle cx={SOURCE_XY[0]} cy={SOURCE_XY[1]} r={5} fill='#888' />
235
+ <text x={-440} y={-330} fill='#666' fontSize={11}>
236
+ radialQuadratic — control at (target.angle, source.radius)
237
+ </text>
238
+ {PROBE_POLAR_TARGETS.map((p, i) => {
239
+ const d = radialQuadratic(SOURCE_POLAR, p.polar);
240
+ const [tx, ty] = polarToCartesian(p.polar.x, p.polar.y);
241
+ const [cx, cy] = polarToCartesian(p.polar.x, SOURCE_POLAR.y);
242
+ return (
243
+ <g key={`alt-${i}`}>
244
+ <path d={d} fill='none' stroke={p.color} strokeWidth={2} />
245
+ <circle cx={cx} cy={cy} r={3} fill={p.color} opacity={0.5} />
246
+ <circle cx={tx} cy={ty} r={5} fill={p.color} />
247
+ <text x={tx + 8} y={ty} fill={p.color} fontSize={11}>
248
+ {p.label}
249
+ </text>
250
+ </g>
251
+ );
252
+ })}
253
+ </g>
254
+
255
+ {/* Alternative B: sharp elbow — two line segments. */}
256
+ <g transform='translate(2250, 0)'>
257
+ <line x1={-450} y1={0} x2={450} y2={0} stroke='#222' />
258
+ <line x1={0} y1={-350} x2={0} y2={350} stroke='#222' />
259
+ <circle cx={0} cy={0} r={3} fill='#444' />
260
+ <circle cx={SOURCE_XY[0]} cy={SOURCE_XY[1]} r={5} fill='#888' />
261
+ <text x={-440} y={-330} fill='#666' fontSize={11}>
262
+ radialElbow — sharp 2-segment elbow
263
+ </text>
264
+ {PROBE_POLAR_TARGETS.map((p, i) => {
265
+ const d = radialElbow(SOURCE_POLAR, p.polar);
266
+ const [tx, ty] = polarToCartesian(p.polar.x, p.polar.y);
267
+ return (
268
+ <g key={`elbow-${i}`}>
269
+ <path d={d} fill='none' stroke={p.color} strokeWidth={2} />
270
+ <circle cx={tx} cy={ty} r={5} fill={p.color} />
271
+ <text x={tx + 8} y={ty} fill={p.color} fontSize={11}>
272
+ {p.label}
273
+ </text>
274
+ </g>
275
+ );
276
+ })}
277
+ </g>
278
+
279
+ {/* Alternative C: smoothed elbow — cubic with both controls at the knee. */}
280
+ <g transform='translate(3000, 0)'>
281
+ <line x1={-450} y1={0} x2={450} y2={0} stroke='#222' />
282
+ <line x1={0} y1={-350} x2={0} y2={350} stroke='#222' />
283
+ <circle cx={0} cy={0} r={3} fill='#444' />
284
+ <circle cx={SOURCE_XY[0]} cy={SOURCE_XY[1]} r={5} fill='#888' />
285
+ <text x={-440} y={-330} fill='#666' fontSize={11}>
286
+ radialSmoothElbow — cubic with both controls at the knee
287
+ </text>
288
+ {PROBE_POLAR_TARGETS.map((p, i) => {
289
+ const d = radialSmoothElbow(SOURCE_POLAR, p.polar);
290
+ const [tx, ty] = polarToCartesian(p.polar.x, p.polar.y);
291
+ return (
292
+ <g key={`smooth-${i}`}>
293
+ <path d={d} fill='none' stroke={p.color} strokeWidth={2} />
294
+ <circle cx={tx} cy={ty} r={5} fill={p.color} />
295
+ <text x={tx + 8} y={ty} fill={p.color} fontSize={11}>
296
+ {p.label}
297
+ </text>
298
+ </g>
299
+ );
300
+ })}
301
+ </g>
302
+ </svg>
303
+ </div>
304
+ );
305
+ };
306
+
307
+ export const PathProbeStory: Story = {
308
+ name: 'PathProbe',
309
+ render: () => <PathProbe />,
310
+ };
311
+
312
+ // ---------------------------------------------------------------------------
313
+ // PathInspector — paste any `d` string, click Diagnose. The path is rendered
314
+ // in an SVG and the same diagnostics (bbox, pathLength, computed CSS) we'd
315
+ // otherwise pull from the console are printed alongside. Loops to avoid the
316
+ // console-snippet ping-pong when debugging "this path doesn't render."
317
+ // ---------------------------------------------------------------------------
318
+
319
+ const PathInspector = () => {
320
+ const [input, setInput] = React.useState(
321
+ 'M172.95585588832455,-79.85312713937451Q184.55815606041466,47.20738323164743 369.1163121208293,94.41476646329485',
322
+ );
323
+ const [info, setInfo] = React.useState<Record<string, unknown> | null>(null);
324
+ const pathRef = React.useRef<SVGPathElement | null>(null);
325
+
326
+ const diagnose = React.useCallback(() => {
327
+ const el = pathRef.current;
328
+ if (!el) {
329
+ setInfo({ error: 'no path element' });
330
+ return;
331
+ }
332
+ const cs = getComputedStyle(el);
333
+ let bbox: any = null;
334
+ try {
335
+ const b = el.getBBox();
336
+ bbox = { x: b.x, y: b.y, width: b.width, height: b.height };
337
+ } catch (e: any) {
338
+ bbox = `error: ${e?.message}`;
339
+ }
340
+ let len: number | string = 0;
341
+ try {
342
+ len = el.getTotalLength();
343
+ } catch (e: any) {
344
+ len = `error: ${e?.message}`;
345
+ }
346
+ setInfo({
347
+ d: el.getAttribute('d'),
348
+ bbox,
349
+ pathLength: len,
350
+ stroke: cs.stroke,
351
+ strokeWidth: cs.strokeWidth,
352
+ strokeOpacity: cs.strokeOpacity,
353
+ opacity: cs.opacity,
354
+ visibility: cs.visibility,
355
+ display: cs.display,
356
+ clipPath: cs.clipPath,
357
+ transform: cs.transform,
358
+ });
359
+ }, []);
360
+
361
+ // Run on mount.
362
+ React.useEffect(() => {
363
+ diagnose();
364
+ // eslint-disable-next-line react-hooks/exhaustive-deps
365
+ }, []);
366
+
367
+ return (
368
+ <div
369
+ style={{
370
+ width: '100vw',
371
+ height: '100vh',
372
+ background: '#0c0c0c',
373
+ color: '#ddd',
374
+ fontFamily: 'monospace',
375
+ padding: 12,
376
+ boxSizing: 'border-box',
377
+ display: 'flex',
378
+ flexDirection: 'column',
379
+ gap: 8,
380
+ }}
381
+ >
382
+ <div style={{ display: 'flex', gap: 8, alignItems: 'flex-start' }}>
383
+ <textarea
384
+ value={input}
385
+ onChange={(e) => setInput(e.target.value)}
386
+ rows={3}
387
+ style={{
388
+ flex: 1,
389
+ background: '#111',
390
+ color: '#ddd',
391
+ border: '1px solid #333',
392
+ padding: 6,
393
+ fontFamily: 'monospace',
394
+ fontSize: 12,
395
+ }}
396
+ placeholder='paste a `d` attribute string (M ... C/Q ...)'
397
+ />
398
+ <button
399
+ onClick={diagnose}
400
+ style={{
401
+ background: '#222',
402
+ color: '#ddd',
403
+ border: '1px solid #444',
404
+ padding: '8px 14px',
405
+ cursor: 'pointer',
406
+ }}
407
+ >
408
+ Diagnose
409
+ </button>
410
+ </div>
411
+
412
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 8, flex: 1, minHeight: 0 }}>
413
+ <svg
414
+ xmlns='http://www.w3.org/2000/svg'
415
+ width='100%'
416
+ height='100%'
417
+ viewBox='-450 -350 900 700'
418
+ style={{ background: '#000', border: '1px solid #222' }}
419
+ >
420
+ <line x1={-450} y1={0} x2={450} y2={0} stroke='#222' />
421
+ <line x1={0} y1={-350} x2={0} y2={350} stroke='#222' />
422
+ <circle cx={0} cy={0} r={3} fill='#444' />
423
+ <path ref={pathRef} d={input} fill='none' stroke='magenta' strokeWidth={2} />
424
+ </svg>
425
+
426
+ <pre
427
+ style={{
428
+ background: '#111',
429
+ padding: 10,
430
+ overflow: 'auto',
431
+ fontSize: 12,
432
+ margin: 0,
433
+ border: '1px solid #222',
434
+ }}
435
+ >
436
+ {info ? JSON.stringify(info, null, 2) : '(click Diagnose)'}
437
+ </pre>
438
+ </div>
439
+ </div>
440
+ );
441
+ };
442
+
443
+ export const PathInspectorStory: Story = {
444
+ name: 'PathInspector',
445
+ render: () => <PathInspector />,
446
+ };
@@ -109,9 +109,14 @@ const Component = ({
109
109
  }, [markersRef]);
110
110
 
111
111
  useEffect(() => {
112
+ // Prime the projector with the initial graph — `model.subscribe` only fires on changes by default,
113
+ // so without this the simulation starts empty and the renderer never sees any nodes.
114
+ // The subscribe callback receives `(model, graph)` from GraphModel; use the model reference
115
+ // we already have to fetch the current snapshot.
116
+ projector.updateData(model.graph);
112
117
  void projector.start();
113
118
  return combine(
114
- model.subscribe((graph) => projector.updateData(graph)),
119
+ model.subscribe(() => projector.updateData(model.graph)),
115
120
  projector.updated.on(({ layout }) => renderer.render(layout)),
116
121
  () => projector.stop(),
117
122
  );
package/styles/graph.css CHANGED
@@ -65,6 +65,20 @@ svg {
65
65
 
66
66
  g.dx-nodes {
67
67
  g.dx-node {
68
+ /* Hover feedback — every variant (force / lattice / cluster / bundle) wraps its
69
+ consumer-drawn shape in `g.dx-node`, so a single rule covers all four. Dim the
70
+ whole node group on hover; the `transition` smooths the in/out. */
71
+ cursor: pointer;
72
+ transition: opacity 150ms ease-out;
73
+ &:hover {
74
+ opacity: 0.65;
75
+ }
76
+ /* Cluster collapse: hidden leaves stay in the layout (so they tween to/from their
77
+ parent), but the d3 hide-transition fades their opacity attribute to 0 and we
78
+ drop pointer events so they don't catch clicks during the fade. */
79
+ &.dx-hidden {
80
+ pointer-events: none;
81
+ }
68
82
  circle {
69
83
  @apply fill-neutral-300 stroke-neutral-800;
70
84
 
@@ -72,6 +86,37 @@ svg {
72
86
  @apply fill-neutral-600 stroke-none;
73
87
  }
74
88
  }
89
+ /* Radial cluster labels — small, neutral, no fill swatch since these are SVG
90
+ text nodes (not HTML). Stroke + paint-order halos the text for legibility against
91
+ edges or color-coded nodes drawn beneath it. */
92
+ text.dx-cluster-label {
93
+ @apply fill-neutral-700 text-[10px];
94
+ paint-order: stroke;
95
+ stroke: var(--surface-bg, white);
96
+ stroke-width: 3px;
97
+ stroke-linejoin: round;
98
+
99
+ .dark & {
100
+ @apply fill-neutral-300;
101
+ }
102
+ }
103
+ /* Group label sits inward of the ring — slightly stronger so the typename labels
104
+ the cluster of leaves they introduce. */
105
+ text.dx-cluster-label-group {
106
+ @apply fill-neutral-500 text-[11px] font-medium;
107
+
108
+ .dark & {
109
+ @apply fill-neutral-400;
110
+ }
111
+ }
112
+ /* Root label is a centered caption — larger, slightly bolder. */
113
+ text.dx-cluster-label-root {
114
+ @apply fill-neutral-600 text-xs font-semibold;
115
+
116
+ .dark & {
117
+ @apply fill-neutral-300;
118
+ }
119
+ }
75
120
  &.dx-selected {
76
121
  circle {
77
122
  @apply !fill-red-500 stroke-2 stroke-neutral-950;
@@ -228,7 +273,7 @@ svg {
228
273
  @apply stroke-1 stroke-neutral-500 fill-inverse-surface;
229
274
  }
230
275
  text {
231
- @apply fill-inverse-surface-text;
276
+ @apply fill-inverse-fg;
232
277
  }
233
278
  }
234
279
  }
@@ -238,7 +283,11 @@ svg {
238
283
  g.dx-edge {
239
284
  path {
240
285
  /** NOTE: Set text- so that current color is picked up by marker. */
241
- @apply stroke-1 stroke-neutral-700;
286
+ @apply stroke-1 stroke-neutral-700 fill-none;
287
+ /* Force higher-quality tessellation. Some browsers' default `auto` shape-rendering
288
+ produces visible gaps in stroked bezier curves at certain curvature / stroke-width
289
+ combinations — geometricPrecision avoids the heuristic and uses precise math. */
290
+ shape-rendering: geometricPrecision;
242
291
 
243
292
  .dark & {
244
293
  @apply stroke-neutral-700;