@dxos/react-ui-graph 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +102 -5
- package/README.md +5 -7
- package/dist/lib/browser/chunk-EASNZZ7B.mjs +52 -0
- package/dist/lib/browser/chunk-EASNZZ7B.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2729 -593
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +16 -16
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs +54 -0
- package/dist/lib/node-esm/chunk-JSE2X4ML.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2729 -593
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +16 -16
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/components/Graph/Graph.d.ts +23 -6
- package/dist/types/src/components/Graph/Graph.d.ts.map +1 -1
- package/dist/types/src/components/Graph/Graph.stories.d.ts +19 -10
- package/dist/types/src/components/Graph/Graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.d.ts.map +1 -1
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts +9 -5
- package/dist/types/src/components/Mesh/Mesh.stories.d.ts.map +1 -1
- package/dist/types/src/components/SVG/FPS.d.ts +20 -0
- package/dist/types/src/components/SVG/FPS.d.ts.map +1 -0
- package/dist/types/src/components/SVG/Grid.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Markers.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Root.d.ts +8 -4
- package/dist/types/src/components/SVG/Root.d.ts.map +1 -1
- package/dist/types/src/components/SVG/SVG.d.ts +17 -18
- package/dist/types/src/components/SVG/SVG.d.ts.map +1 -1
- package/dist/types/src/components/SVG/Svg.stories.d.ts +11 -9
- package/dist/types/src/components/SVG/Svg.stories.d.ts.map +1 -1
- package/dist/types/src/fx/fx.stories.d.ts +16 -15
- package/dist/types/src/fx/fx.stories.d.ts.map +1 -1
- package/dist/types/src/fx/pulsar.d.ts.map +1 -1
- package/dist/types/src/graph/markers.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts +47 -0
- package/dist/types/src/graph/projector/graph-bundle-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts +65 -0
- package/dist/types/src/graph/projector/graph-cluster-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-drag.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-force-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-forces.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-hierarchical-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts +23 -0
- package/dist/types/src/graph/projector/graph-lattice-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts +67 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts +2 -0
- package/dist/types/src/graph/projector/graph-plexus-projector.test.d.ts.map +1 -0
- package/dist/types/src/graph/projector/graph-projector.d.ts +10 -2
- package/dist/types/src/graph/projector/graph-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts +7 -1
- package/dist/types/src/graph/projector/graph-radial-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts +1 -1
- package/dist/types/src/graph/projector/graph-relational-projector.d.ts.map +1 -1
- package/dist/types/src/graph/projector/graph-swarm-projector.d.ts +72 -0
- package/dist/types/src/graph/projector/graph-swarm-projector.d.ts.map +1 -0
- package/dist/types/src/graph/projector/index.d.ts +5 -0
- package/dist/types/src/graph/projector/index.d.ts.map +1 -1
- package/dist/types/src/graph/projector/projector.d.ts +10 -1
- package/dist/types/src/graph/projector/projector.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/bullets.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts +41 -1
- package/dist/types/src/graph/renderer/graph-renderer.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/index.d.ts +1 -0
- package/dist/types/src/graph/renderer/index.d.ts.map +1 -1
- package/dist/types/src/graph/renderer/labels.d.ts +33 -0
- package/dist/types/src/graph/renderer/labels.d.ts.map +1 -0
- package/dist/types/src/graph/renderer/renderer.d.ts +12 -1
- package/dist/types/src/graph/renderer/renderer.d.ts.map +1 -1
- package/dist/types/src/graph/types.d.ts +15 -1
- package/dist/types/src/graph/types.d.ts.map +1 -1
- package/dist/types/src/hooks/useGrid.d.ts.map +1 -1
- package/dist/types/src/hooks/useStateRef.d.ts.map +1 -1
- package/dist/types/src/hooks/useSvgContext.d.ts.map +1 -1
- package/dist/types/src/hooks/useZoom.d.ts.map +1 -1
- package/dist/types/src/stories/experimental.stories.d.ts +7 -0
- package/dist/types/src/stories/experimental.stories.d.ts.map +1 -0
- package/dist/types/src/stories/hooks.stories.d.ts +14 -9
- package/dist/types/src/stories/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +5 -5
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/hooks.d.ts +2 -16
- package/dist/types/src/testing/hooks.d.ts.map +1 -1
- package/dist/types/src/testing/model.d.ts +4 -8
- package/dist/types/src/testing/model.d.ts.map +1 -1
- package/dist/types/src/util/events.d.ts.map +1 -1
- package/dist/types/src/util/fraction.d.ts +1 -1
- package/dist/types/src/util/fraction.d.ts.map +1 -1
- package/dist/types/src/util/points.d.ts.map +1 -1
- package/dist/types/src/util/scale.d.ts.map +1 -1
- package/dist/types/src/util/screen.d.ts.map +1 -1
- package/dist/types/src/util/vector.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +33 -35
- package/src/components/Graph/Graph.stories.tsx +68 -65
- package/src/components/Graph/Graph.tsx +127 -24
- package/src/components/Mesh/Mesh.stories.tsx +15 -13
- package/src/components/Mesh/Mesh.tsx +43 -35
- package/src/components/SVG/FPS.tsx +91 -0
- package/src/components/SVG/Grid.tsx +1 -1
- package/src/components/SVG/Markers.tsx +1 -1
- package/src/components/SVG/Root.tsx +42 -9
- package/src/components/SVG/SVG.tsx +14 -3
- package/src/components/SVG/Svg.stories.tsx +22 -19
- package/src/fx/fx.stories.tsx +17 -15
- package/src/graph/projector/graph-bundle-projector.ts +210 -0
- package/src/graph/projector/graph-cluster-projector.ts +337 -0
- package/src/graph/projector/graph-drag.ts +0 -1
- package/src/graph/projector/graph-force-projector.ts +7 -3
- package/src/graph/projector/graph-hierarchical-projector.ts +4 -4
- package/src/graph/projector/graph-lattice-projector.ts +86 -0
- package/src/graph/projector/graph-plexus-projector.test.ts +102 -0
- package/src/graph/projector/graph-plexus-projector.ts +309 -0
- package/src/graph/projector/graph-projector.ts +24 -4
- package/src/graph/projector/graph-radial-projector.ts +31 -4
- package/src/graph/projector/graph-relational-projector.ts +4 -4
- package/src/graph/projector/graph-swarm-projector.ts +373 -0
- package/src/graph/projector/index.ts +5 -0
- package/src/graph/projector/projector.ts +12 -3
- package/src/graph/renderer/graph-renderer.ts +289 -31
- package/src/graph/renderer/index.ts +1 -0
- package/src/graph/renderer/labels.ts +138 -0
- package/src/graph/renderer/renderer.ts +15 -4
- package/src/graph/types.ts +15 -1
- package/src/hooks/useStateRef.ts +1 -1
- package/src/stories/experimental.stories.tsx +446 -0
- package/src/stories/hooks.stories.tsx +44 -32
- package/src/testing/data.ts +14 -14
- package/src/testing/hooks.ts +3 -4
- package/src/testing/model.ts +6 -6
- package/src/util/fraction.ts +1 -1
- package/styles/graph.css +341 -43
- package/dist/lib/browser/chunk-HLAKLUDC.mjs +0 -958
- package/dist/lib/browser/chunk-HLAKLUDC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-O6GWCXDC.mjs +0 -960
- package/dist/lib/node-esm/chunk-O6GWCXDC.mjs.map +0 -7
|
@@ -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
|
+
};
|
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '
|
|
5
|
+
import '../../styles/graph.css';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
8
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
9
|
import { select } from 'd3';
|
|
9
|
-
import React, { type PropsWithChildren, useEffect, useMemo, useRef } from 'react';
|
|
10
|
+
import React, { type PropsWithChildren, useContext, useEffect, useMemo, useRef } from 'react';
|
|
10
11
|
|
|
11
12
|
import { combine } from '@dxos/async';
|
|
13
|
+
import { type Graph } from '@dxos/graph';
|
|
12
14
|
import { log } from '@dxos/log';
|
|
13
|
-
import {
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
14
17
|
|
|
15
18
|
import { SVG } from '../components';
|
|
16
19
|
import {
|
|
@@ -26,10 +29,8 @@ import {
|
|
|
26
29
|
import { useGrid, useSvgContext, useZoom } from '../hooks';
|
|
27
30
|
import { TestGraphModel, type TestNode, convertTreeToGraph, createTree } from '../testing';
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type StoryProps = PropsWithChildren<{
|
|
32
|
-
model: TestGraphModel;
|
|
32
|
+
type ComponentProps = PropsWithChildren<{
|
|
33
|
+
graph: () => Graph.Graph<TestNode, Graph.Edge.Any>;
|
|
33
34
|
projectorOptions?: GraphForceProjectorOptions;
|
|
34
35
|
count?: number;
|
|
35
36
|
interval?: number;
|
|
@@ -37,28 +38,20 @@ type StoryProps = PropsWithChildren<{
|
|
|
37
38
|
grid?: boolean;
|
|
38
39
|
}>;
|
|
39
40
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
<>
|
|
43
|
-
<SVG.Root>
|
|
44
|
-
<StoryComponent {...props} />
|
|
45
|
-
</SVG.Root>
|
|
46
|
-
{children && <div className='absolute left-4 bottom-4 font-mono text-green-500 text-xs'>{children}</div>}
|
|
47
|
-
</>
|
|
48
|
-
);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const StoryComponent = ({
|
|
52
|
-
model,
|
|
41
|
+
const Component = ({
|
|
42
|
+
graph: graphFactory,
|
|
53
43
|
projectorOptions,
|
|
54
44
|
count = 0,
|
|
55
45
|
interval = 200,
|
|
56
46
|
link = false,
|
|
57
47
|
grid: showGrid = false,
|
|
58
|
-
}:
|
|
48
|
+
}: ComponentProps) => {
|
|
49
|
+
const registry = useContext(RegistryContext);
|
|
50
|
+
const model = useMemo(() => new TestGraphModel(registry, graphFactory()), [registry, graphFactory]);
|
|
51
|
+
|
|
59
52
|
const context = useSvgContext();
|
|
60
|
-
const graphRef = useRef<SVGGElement>();
|
|
61
|
-
const markersRef = useRef<SVGGElement>();
|
|
53
|
+
const graphRef = useRef<SVGGElement>(null);
|
|
54
|
+
const markersRef = useRef<SVGGElement>(null);
|
|
62
55
|
const grid = useGrid({ visible: showGrid });
|
|
63
56
|
const zoom = useZoom();
|
|
64
57
|
|
|
@@ -94,7 +87,7 @@ const StoryComponent = ({
|
|
|
94
87
|
labels: {
|
|
95
88
|
text: (node: GraphLayoutNode<TestNode>) => node.id.substring(0, 4),
|
|
96
89
|
},
|
|
97
|
-
onNodeClick: (node: GraphLayoutNode<TestNode
|
|
90
|
+
onNodeClick: (node: GraphLayoutNode<TestNode>) => {
|
|
98
91
|
renderer.fireBullet(node);
|
|
99
92
|
},
|
|
100
93
|
onLinkClick: (edge: GraphLayoutEdge<TestNode>, event: MouseEvent) => {
|
|
@@ -116,9 +109,14 @@ const StoryComponent = ({
|
|
|
116
109
|
}, [markersRef]);
|
|
117
110
|
|
|
118
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);
|
|
119
117
|
void projector.start();
|
|
120
118
|
return combine(
|
|
121
|
-
model.subscribe((
|
|
119
|
+
model.subscribe(() => projector.updateData(model.graph)),
|
|
122
120
|
projector.updated.on(({ layout }) => renderer.render(layout)),
|
|
123
121
|
() => projector.stop(),
|
|
124
122
|
);
|
|
@@ -151,19 +149,33 @@ const StoryComponent = ({
|
|
|
151
149
|
);
|
|
152
150
|
};
|
|
153
151
|
|
|
154
|
-
const
|
|
152
|
+
const DefaultStory = ({ children, ...props }: ComponentProps) => {
|
|
153
|
+
return (
|
|
154
|
+
<>
|
|
155
|
+
<SVG.Root>
|
|
156
|
+
<Component {...props} />
|
|
157
|
+
</SVG.Root>
|
|
158
|
+
{children && <div className='absolute left-4 bottom-4 font-mono text-green-500 text-xs'>{children}</div>}
|
|
159
|
+
</>
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const meta = {
|
|
155
164
|
title: 'ui/react-ui-graph/hooks',
|
|
156
165
|
render: DefaultStory,
|
|
157
|
-
decorators: [withTheme, withLayout({
|
|
158
|
-
|
|
166
|
+
decorators: [withRegistry, withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
167
|
+
parameters: {
|
|
168
|
+
layout: 'fullscreen',
|
|
169
|
+
},
|
|
170
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
159
171
|
|
|
160
172
|
export default meta;
|
|
161
173
|
|
|
162
|
-
type Story = StoryObj<typeof
|
|
174
|
+
type Story = StoryObj<typeof meta>;
|
|
163
175
|
|
|
164
176
|
export const Default: Story = {
|
|
165
177
|
args: {
|
|
166
|
-
|
|
178
|
+
graph: () => convertTreeToGraph(createTree({ depth: 3 })),
|
|
167
179
|
grid: true,
|
|
168
180
|
count: 300,
|
|
169
181
|
interval: 20,
|
|
@@ -188,7 +200,7 @@ export const Default: Story = {
|
|
|
188
200
|
|
|
189
201
|
export const Bullets: Story = {
|
|
190
202
|
args: {
|
|
191
|
-
|
|
203
|
+
graph: () => convertTreeToGraph(createTree({ depth: 4 })),
|
|
192
204
|
children: <span>⌘-DRAG to edge or create node; ⌘-CLICK to delete edge.</span>,
|
|
193
205
|
link: true,
|
|
194
206
|
grid: false,
|
package/src/testing/data.ts
CHANGED
|
@@ -2,28 +2,28 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
6
|
-
import {
|
|
5
|
+
import { type Graph } from '@dxos/graph';
|
|
6
|
+
import { random } from '@dxos/random';
|
|
7
7
|
|
|
8
8
|
import { type TestNode } from './model';
|
|
9
9
|
|
|
10
|
-
// https://www.npmjs.com/package/
|
|
11
|
-
export const seed = (seed: number) =>
|
|
10
|
+
// https://www.npmjs.com/package/random#setting-a-randomness-seed
|
|
11
|
+
export const seed = (seed: number) => random.seed(seed);
|
|
12
12
|
|
|
13
13
|
//
|
|
14
14
|
// Create data.
|
|
15
15
|
//
|
|
16
16
|
|
|
17
17
|
export const createNode = (type: string = undefined): TestNode => ({
|
|
18
|
-
id:
|
|
18
|
+
id: random.string.uuid(),
|
|
19
19
|
type,
|
|
20
|
-
label:
|
|
20
|
+
label: random.lorem.words(3).replace(/ /g, '-'),
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
export const createNodes = (n = 0, types?: string[]): TestNode[] =>
|
|
24
|
-
Array.from({ length: n }, () => createNode(types ?
|
|
24
|
+
Array.from({ length: n }, () => createNode(types ? random.helpers.arrayElement(types) : undefined));
|
|
25
25
|
|
|
26
|
-
export const createEdge = (source: TestNode, target: TestNode):
|
|
26
|
+
export const createEdge = (source: TestNode, target: TestNode): Graph.Edge.Any => ({
|
|
27
27
|
id: `${source.id}-${target.id}`,
|
|
28
28
|
source: source.id,
|
|
29
29
|
target: target.id,
|
|
@@ -38,7 +38,7 @@ export const createTree = ({ depth = 2, children = 3 } = {}): TestNode => {
|
|
|
38
38
|
const createChildren = (root: TestNode, d = 0) => {
|
|
39
39
|
if (d < depth) {
|
|
40
40
|
const max = Math.round(Math.log(depth + 1 - d) * children);
|
|
41
|
-
const num =
|
|
41
|
+
const num = random.number.int({ min: 1, max });
|
|
42
42
|
root.children = [...new Array(num)].map(() => {
|
|
43
43
|
return createChildren(createNode(), d + 1);
|
|
44
44
|
});
|
|
@@ -54,8 +54,8 @@ export const createTree = ({ depth = 2, children = 3 } = {}): TestNode => {
|
|
|
54
54
|
* Converts a tree into a graph.
|
|
55
55
|
* @param root
|
|
56
56
|
*/
|
|
57
|
-
export const convertTreeToGraph = (root: TestNode): Graph => {
|
|
58
|
-
const traverse = (node: TestNode, graph: Graph) => {
|
|
57
|
+
export const convertTreeToGraph = (root: TestNode): Graph.Any => {
|
|
58
|
+
const traverse = (node: TestNode, graph: Graph.Any) => {
|
|
59
59
|
graph.nodes.push(node);
|
|
60
60
|
node.children?.forEach((child) => {
|
|
61
61
|
graph.edges.push(createEdge(node, child));
|
|
@@ -76,14 +76,14 @@ export const convertTreeToGraph = (root: TestNode): Graph => {
|
|
|
76
76
|
* @param numNodes
|
|
77
77
|
* @param numEdges
|
|
78
78
|
*/
|
|
79
|
-
export const createGraph = (numNodes = 0, numEdges = 0, types?: string[]): Graph => {
|
|
79
|
+
export const createGraph = (numNodes = 0, numEdges = 0, types?: string[]): Graph.Any => {
|
|
80
80
|
const nodes = createNodes(numNodes, types);
|
|
81
81
|
|
|
82
82
|
const edges = new Map();
|
|
83
83
|
if (numEdges && nodes.length >= 2) {
|
|
84
84
|
for (let i = 0; i < numEdges; i++) {
|
|
85
|
-
const source =
|
|
86
|
-
const target =
|
|
85
|
+
const source = random.helpers.arrayElement(nodes);
|
|
86
|
+
const target = random.helpers.arrayElement(nodes);
|
|
87
87
|
if (source.id !== target.id) {
|
|
88
88
|
const edge = createEdge(source, target);
|
|
89
89
|
if (!edges.get(edge.id)) {
|