@graphty/layout 1.1.1 → 1.2.1
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/.env.example +11 -0
- package/.github/workflows/ci.yml +3 -7
- package/CHANGELOG.md +14 -0
- package/DEPLOYMENT.md +59 -0
- package/README.md +54 -1
- package/dist/vitest.config.js +2 -2
- package/dist/vitest.config.js.map +1 -1
- package/examples/3d-force-directed.html +611 -0
- package/examples/3d-kamada-kawai.html +379 -0
- package/examples/3d-layout-comparison.html +448 -0
- package/examples/3d-spherical-layout.html +319 -0
- package/examples/arf-layout.html +13 -1
- package/examples/bfs-layout.html +38 -32
- package/examples/bipartite-layout.html +16 -4
- package/examples/circular-layout.html +14 -2
- package/examples/forceatlas2-layout.html +118 -151
- package/examples/index.html +75 -0
- package/examples/kamada-kawai-layout.html +13 -1
- package/{dist → examples}/layout-helpers.js +58 -29
- package/examples/multipartite-layout.html +44 -54
- package/examples/planar-layout.html +13 -1
- package/examples/random-layout.html +13 -1
- package/examples/shell-layout.html +16 -2
- package/examples/spectral-layout.html +13 -1
- package/examples/spiral-layout.html +13 -1
- package/examples/spring-layout.html +15 -13
- package/package.json +6 -3
- package/src/algorithms/index.ts +6 -0
- package/src/algorithms/optimization/index.ts +12 -0
- package/src/algorithms/optimization/kamada-kawai-solver.ts +231 -0
- package/src/algorithms/optimization/lbfgs.ts +68 -0
- package/src/algorithms/optimization/line-search.ts +50 -0
- package/src/algorithms/optimization/types.ts +8 -0
- package/src/algorithms/planarity/check.ts +38 -0
- package/src/algorithms/planarity/embedding.ts +216 -0
- package/src/algorithms/planarity/index.ts +12 -0
- package/src/algorithms/planarity/lr-test.ts +70 -0
- package/src/algorithms/planarity/special-graphs.ts +126 -0
- package/src/generators/basic.ts +93 -0
- package/src/generators/bipartite.ts +45 -0
- package/src/generators/grid.ts +42 -0
- package/src/generators/index.ts +15 -0
- package/src/generators/random.ts +39 -0
- package/src/generators/scale-free.ts +72 -0
- package/src/index.ts +18 -0
- package/src/layouts/basic/index.ts +5 -0
- package/src/layouts/basic/random.ts +32 -0
- package/src/layouts/force-directed/arf.ts +130 -0
- package/src/layouts/force-directed/forceatlas2.ts +407 -0
- package/src/layouts/force-directed/fruchterman-reingold.ts +164 -0
- package/src/layouts/force-directed/index.ts +9 -0
- package/src/layouts/force-directed/kamada-kawai.ts +112 -0
- package/src/layouts/force-directed/spring.ts +35 -0
- package/src/layouts/geometric/circular.ts +77 -0
- package/src/layouts/geometric/index.ts +7 -0
- package/src/layouts/geometric/shell.ts +80 -0
- package/src/layouts/geometric/spiral.ts +93 -0
- package/src/layouts/hierarchical/bfs.ts +81 -0
- package/src/layouts/hierarchical/bipartite.ts +94 -0
- package/src/layouts/hierarchical/index.ts +7 -0
- package/src/layouts/hierarchical/multipartite.ts +88 -0
- package/src/layouts/index.ts +9 -0
- package/src/layouts/specialized/index.ts +6 -0
- package/src/layouts/specialized/planar.ts +65 -0
- package/src/layouts/specialized/spectral.ts +128 -0
- package/src/types/embedding.ts +11 -0
- package/src/types/graph.ts +13 -0
- package/src/types/index.ts +7 -0
- package/src/types/layout.ts +9 -0
- package/src/utils/graph.ts +77 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/numpy.ts +108 -0
- package/src/utils/params.ts +26 -0
- package/src/utils/random.ts +53 -0
- package/src/utils/rescale.ts +137 -0
- package/test/arf-layout.test.ts +1 -1
- package/test/bfs-layout.test.ts +1 -1
- package/test/bipartite-layout.test.ts +1 -1
- package/test/circular-layout.test.ts +145 -3
- package/test/forceatlas2-layout.test.ts +1 -1
- package/test/fruchterman-reingold-layout.test.ts +1 -1
- package/test/graph-generators.test.ts +1 -1
- package/test/kamada-kawai-layout.test.ts +273 -1
- package/test/multipartite-layout.test.ts +1 -1
- package/test/planar-layout.test.ts +1 -1
- package/test/random-layout.test.ts +1 -1
- package/test/rescale-layout.test.ts +1 -1
- package/test/shell-layout.test.ts +1 -1
- package/test/spectral-layout.test.ts +1 -1
- package/test/spiral-layout.test.ts +1 -1
- package/test/spring-layout.test.ts +1 -1
- package/vite.config.js +36 -0
- package/vitest.config.ts +2 -2
- package/dist/layout-helpers.d.ts +0 -123
- package/dist/layout-helpers.js.map +0 -1
- package/dist/layout.d.ts +0 -275
- package/dist/layout.js +0 -2280
- package/dist/layout.js.map +0 -1
- package/layout-helpers.ts +0 -559
- package/layout.ts +0 -2867
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<!-- Eruda Mobile Console -->
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/eruda@3/eruda.min.js"></script>
|
|
6
|
+
<script>
|
|
7
|
+
// Initialize Eruda console for mobile debugging
|
|
8
|
+
if (typeof eruda !== "undefined") {
|
|
9
|
+
eruda.init();
|
|
10
|
+
// Auto-show on mobile devices
|
|
11
|
+
if (/mobile|android|ios|iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())) {
|
|
12
|
+
eruda.show();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
16
|
+
<meta charset="UTF-8">
|
|
17
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
18
|
+
<title>3D Spherical Layout - @graphty/layout</title>
|
|
19
|
+
<style>
|
|
20
|
+
body {
|
|
21
|
+
margin: 0;
|
|
22
|
+
font-family: Arial, sans-serif;
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
}
|
|
25
|
+
#container {
|
|
26
|
+
width: 100vw;
|
|
27
|
+
height: 100vh;
|
|
28
|
+
}
|
|
29
|
+
#info {
|
|
30
|
+
position: absolute;
|
|
31
|
+
top: 10px;
|
|
32
|
+
left: 10px;
|
|
33
|
+
color: white;
|
|
34
|
+
background: rgba(0, 0, 0, 0.7);
|
|
35
|
+
padding: 10px;
|
|
36
|
+
border-radius: 5px;
|
|
37
|
+
}
|
|
38
|
+
#controls {
|
|
39
|
+
position: absolute;
|
|
40
|
+
top: 10px;
|
|
41
|
+
right: 10px;
|
|
42
|
+
background: rgba(0, 0, 0, 0.7);
|
|
43
|
+
padding: 10px;
|
|
44
|
+
border-radius: 5px;
|
|
45
|
+
color: white;
|
|
46
|
+
}
|
|
47
|
+
button {
|
|
48
|
+
display: block;
|
|
49
|
+
margin: 5px 0;
|
|
50
|
+
padding: 5px 10px;
|
|
51
|
+
cursor: pointer;
|
|
52
|
+
}
|
|
53
|
+
label {
|
|
54
|
+
display: block;
|
|
55
|
+
margin: 5px 0;
|
|
56
|
+
}
|
|
57
|
+
</style>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<div id="container"></div>
|
|
61
|
+
<div id="info">
|
|
62
|
+
<h2>3D Spherical Layout</h2>
|
|
63
|
+
<p>Nodes distributed evenly on a sphere using Fibonacci spiral</p>
|
|
64
|
+
<p>Drag to rotate • Scroll to zoom</p>
|
|
65
|
+
</div>
|
|
66
|
+
<div id="controls">
|
|
67
|
+
<label>
|
|
68
|
+
Graph Type:
|
|
69
|
+
<select id="graphType">
|
|
70
|
+
<option value="complete">Complete Graph</option>
|
|
71
|
+
<option value="cycle">Cycle Graph</option>
|
|
72
|
+
<option value="star">Star Graph</option>
|
|
73
|
+
<option value="wheel">Wheel Graph</option>
|
|
74
|
+
<option value="grid">Grid Graph</option>
|
|
75
|
+
<option value="random">Random Graph</option>
|
|
76
|
+
</select>
|
|
77
|
+
</label>
|
|
78
|
+
<label>
|
|
79
|
+
Node Count: <span id="nodeCountLabel">20</span>
|
|
80
|
+
<input type="range" id="nodeCount" min="5" max="50" value="20">
|
|
81
|
+
</label>
|
|
82
|
+
<label>
|
|
83
|
+
Sphere Radius: <span id="radiusLabel">200</span>
|
|
84
|
+
<input type="range" id="radius" min="50" max="300" value="200">
|
|
85
|
+
</label>
|
|
86
|
+
<button id="regenerate">Regenerate Graph</button>
|
|
87
|
+
<label>
|
|
88
|
+
<input type="checkbox" id="showSphere" checked> Show Sphere
|
|
89
|
+
</label>
|
|
90
|
+
<label>
|
|
91
|
+
<input type="checkbox" id="animateRotation" checked> Auto Rotate
|
|
92
|
+
</label>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<!-- Import map for module resolution -->
|
|
96
|
+
<script type="importmap">
|
|
97
|
+
{
|
|
98
|
+
"imports": {
|
|
99
|
+
"three": "https://unpkg.com/three@0.157.0/build/three.module.js",
|
|
100
|
+
"three/addons/": "https://unpkg.com/three@0.157.0/examples/jsm/"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<script type="module">
|
|
106
|
+
import * as THREE from 'https://unpkg.com/three@0.157.0/build/three.module.js';
|
|
107
|
+
import { OrbitControls } from 'https://unpkg.com/three@0.157.0/examples/jsm/controls/OrbitControls.js';
|
|
108
|
+
import {
|
|
109
|
+
circularLayout,
|
|
110
|
+
completeGraph,
|
|
111
|
+
cycleGraph,
|
|
112
|
+
starGraph,
|
|
113
|
+
wheelGraph,
|
|
114
|
+
gridGraph,
|
|
115
|
+
randomGraph
|
|
116
|
+
} from './layout.js';
|
|
117
|
+
|
|
118
|
+
// Three.js setup
|
|
119
|
+
const scene = new THREE.Scene();
|
|
120
|
+
scene.background = new THREE.Color(0x0a0a0a);
|
|
121
|
+
|
|
122
|
+
const camera = new THREE.PerspectiveCamera(
|
|
123
|
+
75,
|
|
124
|
+
window.innerWidth / window.innerHeight,
|
|
125
|
+
0.1,
|
|
126
|
+
2000
|
|
127
|
+
);
|
|
128
|
+
camera.position.set(400, 300, 500);
|
|
129
|
+
|
|
130
|
+
const renderer = new THREE.WebGLRenderer({ antialias: true });
|
|
131
|
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
132
|
+
document.getElementById('container').appendChild(renderer.domElement);
|
|
133
|
+
|
|
134
|
+
const controls = new OrbitControls(camera, renderer.domElement);
|
|
135
|
+
controls.enableDamping = true;
|
|
136
|
+
controls.dampingFactor = 0.05;
|
|
137
|
+
|
|
138
|
+
// Lighting
|
|
139
|
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
|
|
140
|
+
scene.add(ambientLight);
|
|
141
|
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.4);
|
|
142
|
+
directionalLight.position.set(1, 1, 1);
|
|
143
|
+
scene.add(directionalLight);
|
|
144
|
+
|
|
145
|
+
// Graph visualization
|
|
146
|
+
let nodeGroup = new THREE.Group();
|
|
147
|
+
let edgeGroup = new THREE.Group();
|
|
148
|
+
let sphereMesh = null;
|
|
149
|
+
scene.add(nodeGroup);
|
|
150
|
+
scene.add(edgeGroup);
|
|
151
|
+
|
|
152
|
+
// Create sphere mesh
|
|
153
|
+
function createSphereMesh(radius) {
|
|
154
|
+
const geometry = new THREE.SphereGeometry(radius, 32, 32);
|
|
155
|
+
const material = new THREE.MeshBasicMaterial({
|
|
156
|
+
color: 0x444444,
|
|
157
|
+
wireframe: true,
|
|
158
|
+
transparent: true,
|
|
159
|
+
opacity: 0.2
|
|
160
|
+
});
|
|
161
|
+
return new THREE.Mesh(geometry, material);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Create graph based on type
|
|
165
|
+
function createGraph(type, nodeCount) {
|
|
166
|
+
switch (type) {
|
|
167
|
+
case 'complete':
|
|
168
|
+
return completeGraph(nodeCount);
|
|
169
|
+
case 'cycle':
|
|
170
|
+
return cycleGraph(nodeCount);
|
|
171
|
+
case 'star':
|
|
172
|
+
return starGraph(nodeCount);
|
|
173
|
+
case 'wheel':
|
|
174
|
+
return wheelGraph(nodeCount);
|
|
175
|
+
case 'grid':
|
|
176
|
+
const size = Math.floor(Math.sqrt(nodeCount));
|
|
177
|
+
return gridGraph(size, size);
|
|
178
|
+
case 'random':
|
|
179
|
+
return randomGraph(nodeCount, 0.3, Date.now());
|
|
180
|
+
default:
|
|
181
|
+
return completeGraph(nodeCount);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Visualize graph in 3D
|
|
186
|
+
function visualizeGraph(graph, radius) {
|
|
187
|
+
// Clear previous visualization
|
|
188
|
+
nodeGroup.clear();
|
|
189
|
+
edgeGroup.clear();
|
|
190
|
+
|
|
191
|
+
// Get 3D spherical layout
|
|
192
|
+
const positions = circularLayout(graph, radius, [0, 0, 0], 3);
|
|
193
|
+
|
|
194
|
+
// Create nodes
|
|
195
|
+
const nodeGeometry = new THREE.SphereGeometry(8, 16, 16);
|
|
196
|
+
const nodes = graph.nodes();
|
|
197
|
+
const nodeMeshes = {};
|
|
198
|
+
|
|
199
|
+
nodes.forEach((node, i) => {
|
|
200
|
+
const color = new THREE.Color();
|
|
201
|
+
color.setHSL(i / nodes.length, 0.7, 0.5);
|
|
202
|
+
|
|
203
|
+
const material = new THREE.MeshPhongMaterial({
|
|
204
|
+
color: color,
|
|
205
|
+
emissive: color,
|
|
206
|
+
emissiveIntensity: 0.3
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const mesh = new THREE.Mesh(nodeGeometry, material);
|
|
210
|
+
const [x, y, z] = positions[node];
|
|
211
|
+
mesh.position.set(x, y, z);
|
|
212
|
+
|
|
213
|
+
nodeGroup.add(mesh);
|
|
214
|
+
nodeMeshes[node] = mesh;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
// Create edges
|
|
218
|
+
const edges = graph.edges();
|
|
219
|
+
edges.forEach(([source, target]) => {
|
|
220
|
+
const sourcePos = positions[source];
|
|
221
|
+
const targetPos = positions[target];
|
|
222
|
+
|
|
223
|
+
const points = [
|
|
224
|
+
new THREE.Vector3(sourcePos[0], sourcePos[1], sourcePos[2]),
|
|
225
|
+
new THREE.Vector3(targetPos[0], targetPos[1], targetPos[2])
|
|
226
|
+
];
|
|
227
|
+
|
|
228
|
+
const geometry = new THREE.BufferGeometry().setFromPoints(points);
|
|
229
|
+
const material = new THREE.LineBasicMaterial({
|
|
230
|
+
color: 0x4444ff,
|
|
231
|
+
transparent: true,
|
|
232
|
+
opacity: 0.6
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const line = new THREE.Line(geometry, material);
|
|
236
|
+
edgeGroup.add(line);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Initial graph
|
|
241
|
+
let currentGraph = createGraph('complete', 20);
|
|
242
|
+
visualizeGraph(currentGraph, 200);
|
|
243
|
+
|
|
244
|
+
// Add sphere
|
|
245
|
+
sphereMesh = createSphereMesh(200);
|
|
246
|
+
scene.add(sphereMesh);
|
|
247
|
+
|
|
248
|
+
// Controls
|
|
249
|
+
const graphTypeSelect = document.getElementById('graphType');
|
|
250
|
+
const nodeCountSlider = document.getElementById('nodeCount');
|
|
251
|
+
const nodeCountLabel = document.getElementById('nodeCountLabel');
|
|
252
|
+
const radiusSlider = document.getElementById('radius');
|
|
253
|
+
const radiusLabel = document.getElementById('radiusLabel');
|
|
254
|
+
const regenerateBtn = document.getElementById('regenerate');
|
|
255
|
+
const showSphereCheckbox = document.getElementById('showSphere');
|
|
256
|
+
const animateCheckbox = document.getElementById('animateRotation');
|
|
257
|
+
|
|
258
|
+
nodeCountSlider.addEventListener('input', (e) => {
|
|
259
|
+
nodeCountLabel.textContent = e.target.value;
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
radiusSlider.addEventListener('input', (e) => {
|
|
263
|
+
radiusLabel.textContent = e.target.value;
|
|
264
|
+
const radius = parseInt(e.target.value);
|
|
265
|
+
visualizeGraph(currentGraph, radius);
|
|
266
|
+
if (sphereMesh) {
|
|
267
|
+
scene.remove(sphereMesh);
|
|
268
|
+
sphereMesh = createSphereMesh(radius);
|
|
269
|
+
sphereMesh.visible = showSphereCheckbox.checked;
|
|
270
|
+
scene.add(sphereMesh);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
regenerateBtn.addEventListener('click', () => {
|
|
275
|
+
const type = graphTypeSelect.value;
|
|
276
|
+
const nodeCount = parseInt(nodeCountSlider.value);
|
|
277
|
+
const radius = parseInt(radiusSlider.value);
|
|
278
|
+
|
|
279
|
+
currentGraph = createGraph(type, nodeCount);
|
|
280
|
+
visualizeGraph(currentGraph, radius);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
graphTypeSelect.addEventListener('change', () => {
|
|
284
|
+
regenerateBtn.click();
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
showSphereCheckbox.addEventListener('change', (e) => {
|
|
288
|
+
if (sphereMesh) {
|
|
289
|
+
sphereMesh.visible = e.target.checked;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// Animation
|
|
294
|
+
function animate() {
|
|
295
|
+
requestAnimationFrame(animate);
|
|
296
|
+
|
|
297
|
+
if (animateCheckbox.checked) {
|
|
298
|
+
nodeGroup.rotation.y += 0.002;
|
|
299
|
+
edgeGroup.rotation.y += 0.002;
|
|
300
|
+
if (sphereMesh) {
|
|
301
|
+
sphereMesh.rotation.y += 0.002;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
controls.update();
|
|
306
|
+
renderer.render(scene, camera);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Handle window resize
|
|
310
|
+
window.addEventListener('resize', () => {
|
|
311
|
+
camera.aspect = window.innerWidth / window.innerHeight;
|
|
312
|
+
camera.updateProjectionMatrix();
|
|
313
|
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
animate();
|
|
317
|
+
</script>
|
|
318
|
+
</body>
|
|
319
|
+
</html>
|
package/examples/arf-layout.html
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
+
<!-- Eruda Mobile Console -->
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/eruda@3/eruda.min.js"></script>
|
|
6
|
+
<script>
|
|
7
|
+
// Initialize Eruda console for mobile debugging
|
|
8
|
+
if (typeof eruda !== "undefined") {
|
|
9
|
+
eruda.init();
|
|
10
|
+
// Auto-show on mobile devices
|
|
11
|
+
if (/mobile|android|ios|iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())) {
|
|
12
|
+
eruda.show();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
4
16
|
<meta charset="UTF-8">
|
|
5
17
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
18
|
<title>ARF Layout Test</title>
|
|
@@ -178,7 +190,7 @@
|
|
|
178
190
|
</div>
|
|
179
191
|
|
|
180
192
|
<script type="module">
|
|
181
|
-
import { arfLayout } from
|
|
193
|
+
import { arfLayout } from "./layout.js";
|
|
182
194
|
|
|
183
195
|
let currentGraph = null;
|
|
184
196
|
let currentSeed = Math.floor(Math.random() * 1000);
|
package/examples/bfs-layout.html
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
+
<!-- Eruda Mobile Console -->
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/eruda@3/eruda.min.js"></script>
|
|
6
|
+
<script>
|
|
7
|
+
// Initialize Eruda console for mobile debugging
|
|
8
|
+
if (typeof eruda !== "undefined") {
|
|
9
|
+
eruda.init();
|
|
10
|
+
// Auto-show on mobile devices
|
|
11
|
+
if (/mobile|android|ios|iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())) {
|
|
12
|
+
eruda.show();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
4
16
|
<meta charset="UTF-8">
|
|
5
17
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
18
|
<title>BFS Layout Test</title>
|
|
@@ -157,61 +169,55 @@
|
|
|
157
169
|
</div>
|
|
158
170
|
|
|
159
171
|
<script type="module">
|
|
160
|
-
import {
|
|
161
|
-
bfsLayout,
|
|
162
|
-
starGraph,
|
|
163
|
-
gridGraph,
|
|
164
|
-
randomGraph,
|
|
165
|
-
scaleFreeGraph,
|
|
166
|
-
findBestRoot
|
|
167
|
-
} from '../dist/layout.js';
|
|
172
|
+
import { bfsLayout, scaleFreeGraph, randomGraph, gridGraph, starGraph } from "./layout.js";
|
|
168
173
|
|
|
169
174
|
let currentGraph = null;
|
|
170
175
|
let bestRoot = null;
|
|
171
176
|
|
|
172
177
|
function generateGraph(type, numNodes) {
|
|
178
|
+
let graph;
|
|
173
179
|
switch(type) {
|
|
174
180
|
case 'tree':
|
|
175
181
|
// Generate tree-like structure using scale-free with low m
|
|
176
|
-
|
|
182
|
+
graph = scaleFreeGraph(numNodes, 1, Date.now());
|
|
183
|
+
break;
|
|
177
184
|
|
|
178
185
|
case 'connected':
|
|
179
186
|
// Generate connected random graph
|
|
180
|
-
|
|
187
|
+
graph = randomGraph(numNodes, 0.15, Date.now());
|
|
188
|
+
break;
|
|
181
189
|
|
|
182
190
|
case 'grid':
|
|
183
191
|
// Create grid
|
|
184
192
|
const size = Math.ceil(Math.sqrt(numNodes));
|
|
185
|
-
|
|
193
|
+
const gridG = gridGraph(size, size);
|
|
194
|
+
// Convert string node IDs to numbers for consistency
|
|
195
|
+
const nodeMap = new Map();
|
|
196
|
+
gridG.nodes().forEach((node, i) => nodeMap.set(node, i));
|
|
197
|
+
graph = {
|
|
198
|
+
nodes: () => Array.from({length: gridG.nodes().length}, (_, i) => i),
|
|
199
|
+
edges: () => gridG.edges().map(([u, v]) => [nodeMap.get(u), nodeMap.get(v)])
|
|
200
|
+
};
|
|
201
|
+
break;
|
|
186
202
|
|
|
187
203
|
case 'star':
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
default:
|
|
191
|
-
return randomGraph(numNodes, 0.2, Date.now());
|
|
192
|
-
edges.push([i, i + gridSize]);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
204
|
+
graph = starGraph(numNodes);
|
|
195
205
|
break;
|
|
196
206
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
for (let i = 1; i < numNodes; i++) {
|
|
200
|
-
edges.push([0, i]);
|
|
201
|
-
}
|
|
207
|
+
default:
|
|
208
|
+
graph = randomGraph(numNodes, 0.2, Date.now());
|
|
202
209
|
break;
|
|
203
210
|
}
|
|
204
211
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
edges
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
.filter(([s, t]) => s === node || t === node)
|
|
212
|
-
.map(([s, t]) => s === node ? t : s);
|
|
213
|
-
}
|
|
212
|
+
// Add getNeighbors method to the graph
|
|
213
|
+
graph.getNeighbors = function(node) {
|
|
214
|
+
const edges = this.edges();
|
|
215
|
+
return edges
|
|
216
|
+
.filter(([s, t]) => s === node || t === node)
|
|
217
|
+
.map(([s, t]) => s === node ? t : s);
|
|
214
218
|
};
|
|
219
|
+
|
|
220
|
+
return graph;
|
|
215
221
|
}
|
|
216
222
|
|
|
217
223
|
function updateStartNodeOptions() {
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
+
<!-- Eruda Mobile Console -->
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/eruda@3/eruda.min.js"></script>
|
|
6
|
+
<script>
|
|
7
|
+
// Initialize Eruda console for mobile debugging
|
|
8
|
+
if (typeof eruda !== "undefined") {
|
|
9
|
+
eruda.init();
|
|
10
|
+
// Auto-show on mobile devices
|
|
11
|
+
if (/mobile|android|ios|iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())) {
|
|
12
|
+
eruda.show();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
4
16
|
<meta charset="UTF-8">
|
|
5
17
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
18
|
<title>Bipartite Layout Test</title>
|
|
@@ -153,9 +165,9 @@
|
|
|
153
165
|
import {
|
|
154
166
|
bipartiteLayout,
|
|
155
167
|
bipartiteGraph,
|
|
156
|
-
detectBipartite,
|
|
157
168
|
randomGraph
|
|
158
|
-
} from
|
|
169
|
+
} from "./layout.js";
|
|
170
|
+
import { detectBipartite } from "./layout-helpers.js";
|
|
159
171
|
|
|
160
172
|
let currentGraph = null;
|
|
161
173
|
let detectedBipartite = null;
|
|
@@ -323,7 +335,7 @@
|
|
|
323
335
|
document.getElementById('alignment').onchange = null;
|
|
324
336
|
}
|
|
325
337
|
|
|
326
|
-
window.generateMixedGraph = function() {
|
|
338
|
+
window.generateMixedGraph = async function() {
|
|
327
339
|
const totalNodes = parseInt(document.getElementById('set-a-size').value) +
|
|
328
340
|
parseInt(document.getElementById('set-b-size').value);
|
|
329
341
|
const edgeDensity = parseFloat(document.getElementById('edge-density').value);
|
|
@@ -348,7 +360,7 @@
|
|
|
348
360
|
`;
|
|
349
361
|
} else {
|
|
350
362
|
// Not bipartite - show with spring layout instead
|
|
351
|
-
const { springLayout } = await import('
|
|
363
|
+
const { springLayout } = await import('./layout.js');
|
|
352
364
|
const positions = springLayout(currentGraph);
|
|
353
365
|
visualizeGraph(currentGraph, positions);
|
|
354
366
|
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
+
<!-- Eruda Mobile Console -->
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/eruda@3/eruda.min.js"></script>
|
|
6
|
+
<script>
|
|
7
|
+
// Initialize Eruda console for mobile debugging
|
|
8
|
+
if (typeof eruda !== "undefined") {
|
|
9
|
+
eruda.init();
|
|
10
|
+
// Auto-show on mobile devices
|
|
11
|
+
if (/mobile|android|ios|iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase())) {
|
|
12
|
+
eruda.show();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
</script>
|
|
4
16
|
<meta charset="UTF-8">
|
|
5
17
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
18
|
<title>Circular Layout Test</title>
|
|
@@ -142,7 +154,7 @@
|
|
|
142
154
|
cycleGraph,
|
|
143
155
|
wheelGraph,
|
|
144
156
|
randomGraph
|
|
145
|
-
} from
|
|
157
|
+
} from "./layout.js";
|
|
146
158
|
|
|
147
159
|
let currentGraph = null;
|
|
148
160
|
|
|
@@ -277,4 +289,4 @@
|
|
|
277
289
|
newGraph();
|
|
278
290
|
</script>
|
|
279
291
|
</body>
|
|
280
|
-
</html>
|
|
292
|
+
</html>
|