@graphty/layout 1.2.2 → 1.2.4
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/README.md +317 -237
- package/dist/src/algorithms/index.d.ts +5 -0
- package/dist/src/algorithms/index.js +6 -0
- package/dist/src/algorithms/index.js.map +1 -0
- package/dist/src/algorithms/optimization/index.d.ts +7 -0
- package/dist/src/algorithms/optimization/index.js +7 -0
- package/dist/src/algorithms/optimization/index.js.map +1 -0
- package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts +32 -0
- package/dist/src/algorithms/optimization/kamada-kawai-solver.js +176 -0
- package/dist/src/algorithms/optimization/kamada-kawai-solver.js.map +1 -0
- package/dist/src/algorithms/optimization/lbfgs.d.ts +13 -0
- package/dist/src/algorithms/optimization/lbfgs.js +56 -0
- package/dist/src/algorithms/optimization/lbfgs.js.map +1 -0
- package/dist/src/algorithms/optimization/line-search.d.ts +15 -0
- package/dist/src/algorithms/optimization/line-search.js +37 -0
- package/dist/src/algorithms/optimization/line-search.js.map +1 -0
- package/dist/src/algorithms/optimization/types.d.ts +5 -0
- package/dist/src/algorithms/optimization/types.js +5 -0
- package/dist/src/algorithms/optimization/types.js.map +1 -0
- package/dist/src/algorithms/planarity/check.d.ts +17 -0
- package/dist/src/algorithms/planarity/check.js +30 -0
- package/dist/src/algorithms/planarity/check.js.map +1 -0
- package/dist/src/algorithms/planarity/embedding.d.ts +29 -0
- package/dist/src/algorithms/planarity/embedding.js +179 -0
- package/dist/src/algorithms/planarity/embedding.js.map +1 -0
- package/dist/src/algorithms/planarity/index.d.ts +7 -0
- package/dist/src/algorithms/planarity/index.js +8 -0
- package/dist/src/algorithms/planarity/index.js.map +1 -0
- package/dist/src/algorithms/planarity/lr-test.d.ts +15 -0
- package/dist/src/algorithms/planarity/lr-test.js +54 -0
- package/dist/src/algorithms/planarity/lr-test.js.map +1 -0
- package/dist/src/algorithms/planarity/special-graphs.d.ts +28 -0
- package/dist/src/algorithms/planarity/special-graphs.js +108 -0
- package/dist/src/algorithms/planarity/special-graphs.js.map +1 -0
- package/dist/src/generators/basic.d.ts +28 -0
- package/dist/src/generators/basic.js +79 -0
- package/dist/src/generators/basic.js.map +1 -0
- package/dist/src/generators/bipartite.d.ts +16 -0
- package/dist/src/generators/bipartite.js +40 -0
- package/dist/src/generators/bipartite.js.map +1 -0
- package/dist/src/generators/grid.d.ts +11 -0
- package/dist/src/generators/grid.js +37 -0
- package/dist/src/generators/grid.js.map +1 -0
- package/dist/src/generators/index.d.ts +8 -0
- package/dist/src/generators/index.js +9 -0
- package/dist/src/generators/index.js.map +1 -0
- package/dist/src/generators/random.d.ts +12 -0
- package/dist/src/generators/random.js +34 -0
- package/dist/src/generators/random.js.map +1 -0
- package/dist/src/generators/scale-free.d.ts +12 -0
- package/dist/src/generators/scale-free.js +62 -0
- package/dist/src/generators/scale-free.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +15 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/layouts/basic/index.d.ts +4 -0
- package/dist/src/layouts/basic/index.js +5 -0
- package/dist/src/layouts/basic/index.js.map +1 -0
- package/dist/src/layouts/basic/random.d.ts +14 -0
- package/dist/src/layouts/basic/random.js +27 -0
- package/dist/src/layouts/basic/random.js.map +1 -0
- package/dist/src/layouts/force-directed/arf.d.ts +13 -0
- package/dist/src/layouts/force-directed/arf.js +103 -0
- package/dist/src/layouts/force-directed/arf.js.map +1 -0
- package/dist/src/layouts/force-directed/forceatlas2.d.ts +22 -0
- package/dist/src/layouts/force-directed/forceatlas2.js +322 -0
- package/dist/src/layouts/force-directed/forceatlas2.js.map +1 -0
- package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts +19 -0
- package/dist/src/layouts/force-directed/fruchterman-reingold.js +131 -0
- package/dist/src/layouts/force-directed/fruchterman-reingold.js.map +1 -0
- package/dist/src/layouts/force-directed/index.d.ts +8 -0
- package/dist/src/layouts/force-directed/index.js +9 -0
- package/dist/src/layouts/force-directed/index.js.map +1 -0
- package/dist/src/layouts/force-directed/kamada-kawai.d.ts +15 -0
- package/dist/src/layouts/force-directed/kamada-kawai.js +87 -0
- package/dist/src/layouts/force-directed/kamada-kawai.js.map +1 -0
- package/dist/src/layouts/force-directed/spring.d.ts +19 -0
- package/dist/src/layouts/force-directed/spring.js +23 -0
- package/dist/src/layouts/force-directed/spring.js.map +1 -0
- package/dist/src/layouts/geometric/circular.d.ts +14 -0
- package/dist/src/layouts/geometric/circular.js +67 -0
- package/dist/src/layouts/geometric/circular.js.map +1 -0
- package/dist/src/layouts/geometric/index.d.ts +6 -0
- package/dist/src/layouts/geometric/index.js +7 -0
- package/dist/src/layouts/geometric/index.js.map +1 -0
- package/dist/src/layouts/geometric/shell.d.ts +15 -0
- package/dist/src/layouts/geometric/shell.js +67 -0
- package/dist/src/layouts/geometric/shell.js.map +1 -0
- package/dist/src/layouts/geometric/spiral.d.ts +16 -0
- package/dist/src/layouts/geometric/spiral.js +73 -0
- package/dist/src/layouts/geometric/spiral.js.map +1 -0
- package/dist/src/layouts/hierarchical/bfs.d.ts +12 -0
- package/dist/src/layouts/hierarchical/bfs.js +62 -0
- package/dist/src/layouts/hierarchical/bfs.js.map +1 -0
- package/dist/src/layouts/hierarchical/bipartite.d.ts +16 -0
- package/dist/src/layouts/hierarchical/bipartite.js +72 -0
- package/dist/src/layouts/hierarchical/bipartite.js.map +1 -0
- package/dist/src/layouts/hierarchical/index.d.ts +6 -0
- package/dist/src/layouts/hierarchical/index.js +7 -0
- package/dist/src/layouts/hierarchical/index.js.map +1 -0
- package/dist/src/layouts/hierarchical/multipartite.d.ts +12 -0
- package/dist/src/layouts/hierarchical/multipartite.js +73 -0
- package/dist/src/layouts/hierarchical/multipartite.js.map +1 -0
- package/dist/src/layouts/index.d.ts +8 -0
- package/dist/src/layouts/index.js +9 -0
- package/dist/src/layouts/index.js.map +1 -0
- package/dist/src/layouts/specialized/index.d.ts +5 -0
- package/dist/src/layouts/specialized/index.js +6 -0
- package/dist/src/layouts/specialized/index.js.map +1 -0
- package/dist/src/layouts/specialized/planar.d.ts +14 -0
- package/dist/src/layouts/specialized/planar.js +47 -0
- package/dist/src/layouts/specialized/planar.js.map +1 -0
- package/dist/src/layouts/specialized/spectral.d.ts +14 -0
- package/dist/src/layouts/specialized/spectral.js +106 -0
- package/dist/src/layouts/specialized/spectral.js.map +1 -0
- package/dist/src/types/embedding.d.ts +9 -0
- package/dist/src/types/embedding.js +5 -0
- package/dist/src/types/embedding.js.map +1 -0
- package/dist/src/types/graph.d.ts +10 -0
- package/dist/src/types/graph.js +5 -0
- package/dist/src/types/graph.js.map +1 -0
- package/dist/src/types/index.d.ts +6 -0
- package/dist/src/types/index.js +7 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/layout.d.ts +6 -0
- package/dist/src/types/layout.js +5 -0
- package/dist/src/types/layout.js.map +1 -0
- package/dist/src/utils/graph.d.ts +34 -0
- package/dist/src/utils/graph.js +69 -0
- package/dist/src/utils/graph.js.map +1 -0
- package/dist/src/utils/index.d.ts +8 -0
- package/dist/src/utils/index.js +9 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/numpy.d.ts +17 -0
- package/dist/src/utils/numpy.js +101 -0
- package/dist/src/utils/numpy.js.map +1 -0
- package/dist/src/utils/params.d.ts +17 -0
- package/dist/src/utils/params.js +22 -0
- package/dist/src/utils/params.js.map +1 -0
- package/dist/src/utils/random.d.ts +14 -0
- package/dist/src/utils/random.js +42 -0
- package/dist/src/utils/random.js.map +1 -0
- package/dist/src/utils/rescale.d.ts +21 -0
- package/dist/src/utils/rescale.js +119 -0
- package/dist/src/utils/rescale.js.map +1 -0
- package/dist/vitest.config.js +1 -1
- package/dist/vitest.config.js.map +1 -1
- package/package.json +15 -1
- package/.env.example +0 -11
- package/.github/workflows/ci.yml +0 -101
- package/.releaserc.json +0 -22
- package/CHANGELOG.md +0 -45
- package/CLAUDE.md +0 -104
- package/CONTRIBUTING.md +0 -1
- package/DEPLOYMENT.md +0 -59
- package/commitlint.config.js +0 -37
- package/examples/3d-force-directed.html +0 -611
- package/examples/3d-kamada-kawai.html +0 -379
- package/examples/3d-layout-comparison.html +0 -448
- package/examples/3d-spherical-layout.html +0 -319
- package/examples/arf-layout.html +0 -524
- package/examples/bfs-layout.html +0 -487
- package/examples/bipartite-layout.html +0 -382
- package/examples/circular-layout.html +0 -292
- package/examples/forceatlas2-layout.html +0 -588
- package/examples/index.html +0 -241
- package/examples/kamada-kawai-layout.html +0 -425
- package/examples/layout-helpers.js +0 -486
- package/examples/multipartite-layout.html +0 -410
- package/examples/planar-layout.html +0 -388
- package/examples/random-layout.html +0 -328
- package/examples/shell-layout.html +0 -323
- package/examples/spectral-layout.html +0 -335
- package/examples/spiral-layout.html +0 -447
- package/examples/spring-layout.html +0 -313
- package/test/arf-layout.test.ts +0 -443
- package/test/bfs-layout.test.ts +0 -427
- package/test/bipartite-layout.test.ts +0 -344
- package/test/circular-layout.test.ts +0 -442
- package/test/forceatlas2-layout.test.ts +0 -405
- package/test/fruchterman-reingold-layout.test.ts +0 -477
- package/test/graph-generators.test.ts +0 -450
- package/test/kamada-kawai-layout.test.ts +0 -623
- package/test/multipartite-layout.test.ts +0 -404
- package/test/planar-layout.test.ts +0 -266
- package/test/random-layout.test.ts +0 -254
- package/test/rescale-layout.test.ts +0 -373
- package/test/shell-layout.test.ts +0 -347
- package/test/spectral-layout.test.ts +0 -378
- package/test/spiral-layout.test.ts +0 -338
- package/test/spring-layout.test.ts +0 -241
- package/test/test-utils.ts +0 -34
- package/test/utils-graph.test.ts +0 -155
- package/test/utils-index.test.ts +0 -77
- package/test/utils-numpy.test.ts +0 -272
- package/test/utils-params.test.ts +0 -99
- package/test/utils-random.test.ts +0 -229
- package/tsconfig.json +0 -16
- package/vite.config.js +0 -36
- package/vitest.config.ts +0 -30
|
@@ -1,313 +0,0 @@
|
|
|
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>Spring Layout Test</title>
|
|
19
|
-
<style>
|
|
20
|
-
body {
|
|
21
|
-
font-family: Arial, sans-serif;
|
|
22
|
-
margin: 0;
|
|
23
|
-
padding: 20px;
|
|
24
|
-
background-color: #f5f5f5;
|
|
25
|
-
}
|
|
26
|
-
.container {
|
|
27
|
-
max-width: 1400px;
|
|
28
|
-
margin: 0 auto;
|
|
29
|
-
display: grid;
|
|
30
|
-
grid-template-columns: 250px 1fr 250px;
|
|
31
|
-
gap: 20px;
|
|
32
|
-
}
|
|
33
|
-
.graph-controls {
|
|
34
|
-
background: white;
|
|
35
|
-
padding: 20px;
|
|
36
|
-
border-radius: 8px;
|
|
37
|
-
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
38
|
-
height: fit-content;
|
|
39
|
-
}
|
|
40
|
-
.layout-controls {
|
|
41
|
-
background: white;
|
|
42
|
-
padding: 20px;
|
|
43
|
-
border-radius: 8px;
|
|
44
|
-
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
45
|
-
height: fit-content;
|
|
46
|
-
}
|
|
47
|
-
.visualization {
|
|
48
|
-
background: white;
|
|
49
|
-
border-radius: 8px;
|
|
50
|
-
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
51
|
-
padding: 20px;
|
|
52
|
-
}
|
|
53
|
-
.control-group {
|
|
54
|
-
margin-bottom: 15px;
|
|
55
|
-
}
|
|
56
|
-
label {
|
|
57
|
-
display: block;
|
|
58
|
-
margin-bottom: 5px;
|
|
59
|
-
font-weight: bold;
|
|
60
|
-
color: #333;
|
|
61
|
-
}
|
|
62
|
-
input[type="range"], input[type="number"], select {
|
|
63
|
-
width: 100%;
|
|
64
|
-
padding: 5px;
|
|
65
|
-
border: 1px solid #ddd;
|
|
66
|
-
border-radius: 4px;
|
|
67
|
-
}
|
|
68
|
-
button {
|
|
69
|
-
background: #4CAF50;
|
|
70
|
-
color: white;
|
|
71
|
-
border: none;
|
|
72
|
-
padding: 10px 15px;
|
|
73
|
-
border-radius: 4px;
|
|
74
|
-
cursor: pointer;
|
|
75
|
-
width: 100%;
|
|
76
|
-
margin: 5px 0;
|
|
77
|
-
}
|
|
78
|
-
button:hover {
|
|
79
|
-
background: #45a049;
|
|
80
|
-
}
|
|
81
|
-
#graph-svg {
|
|
82
|
-
border: 1px solid #ddd;
|
|
83
|
-
border-radius: 4px;
|
|
84
|
-
}
|
|
85
|
-
.back-link {
|
|
86
|
-
margin-bottom: 20px;
|
|
87
|
-
}
|
|
88
|
-
.back-link a {
|
|
89
|
-
color: #2c5aa0;
|
|
90
|
-
text-decoration: none;
|
|
91
|
-
}
|
|
92
|
-
.back-link a:hover {
|
|
93
|
-
text-decoration: underline;
|
|
94
|
-
}
|
|
95
|
-
.loading {
|
|
96
|
-
text-align: center;
|
|
97
|
-
color: #666;
|
|
98
|
-
font-style: italic;
|
|
99
|
-
}
|
|
100
|
-
</style>
|
|
101
|
-
</head>
|
|
102
|
-
<body>
|
|
103
|
-
<div class="back-link">
|
|
104
|
-
<a href="index.html">← Back to Index</a>
|
|
105
|
-
</div>
|
|
106
|
-
|
|
107
|
-
<h1>Spring Layout Test</h1>
|
|
108
|
-
|
|
109
|
-
<div class="container">
|
|
110
|
-
<div class="graph-controls">
|
|
111
|
-
<h3>Graph Settings</h3>
|
|
112
|
-
|
|
113
|
-
<div class="control-group">
|
|
114
|
-
<label for="num-nodes">Number of nodes:</label>
|
|
115
|
-
<input type="range" id="num-nodes" min="5" max="30" value="15">
|
|
116
|
-
<span id="num-nodes-value">15</span>
|
|
117
|
-
</div>
|
|
118
|
-
|
|
119
|
-
<div class="control-group">
|
|
120
|
-
<label for="graph-type">Graph type:</label>
|
|
121
|
-
<select id="graph-type">
|
|
122
|
-
<option value="random">Random</option>
|
|
123
|
-
<option value="complete">Complete</option>
|
|
124
|
-
<option value="cycle">Cycle</option>
|
|
125
|
-
<option value="star">Star</option>
|
|
126
|
-
</select>
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
<button onclick="newGraph()">New Graph</button>
|
|
130
|
-
</div>
|
|
131
|
-
|
|
132
|
-
<div class="visualization">
|
|
133
|
-
<svg id="graph-svg" width="800" height="600"></svg>
|
|
134
|
-
</div>
|
|
135
|
-
|
|
136
|
-
<div class="layout-controls">
|
|
137
|
-
<h3>Layout Parameters</h3>
|
|
138
|
-
|
|
139
|
-
<div class="control-group">
|
|
140
|
-
<label for="iterations">Iterations:</label>
|
|
141
|
-
<input type="range" id="iterations" min="10" max="200" value="50">
|
|
142
|
-
<span id="iterations-value">50</span>
|
|
143
|
-
</div>
|
|
144
|
-
|
|
145
|
-
<div class="control-group">
|
|
146
|
-
<label for="k-value">K parameter:</label>
|
|
147
|
-
<input type="range" id="k-value" min="0.1" max="2" step="0.1" value="1">
|
|
148
|
-
<span id="k-value-value">1.0</span>
|
|
149
|
-
</div>
|
|
150
|
-
|
|
151
|
-
<button onclick="applyLayout()">Apply Layout</button>
|
|
152
|
-
</div>
|
|
153
|
-
</div>
|
|
154
|
-
|
|
155
|
-
<script type="module">
|
|
156
|
-
import { springLayout } from "./layout.js";
|
|
157
|
-
|
|
158
|
-
let currentGraph = null;
|
|
159
|
-
|
|
160
|
-
function generateGraph(type, numNodes) {
|
|
161
|
-
const nodes = Array.from({length: numNodes}, (_, i) => i);
|
|
162
|
-
const edges = [];
|
|
163
|
-
|
|
164
|
-
switch(type) {
|
|
165
|
-
case 'complete':
|
|
166
|
-
for(let i = 0; i < numNodes; i++) {
|
|
167
|
-
for(let j = i + 1; j < numNodes; j++) {
|
|
168
|
-
edges.push([i, j]);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
break;
|
|
172
|
-
case 'cycle':
|
|
173
|
-
for(let i = 0; i < numNodes; i++) {
|
|
174
|
-
edges.push([i, (i + 1) % numNodes]);
|
|
175
|
-
}
|
|
176
|
-
break;
|
|
177
|
-
case 'star':
|
|
178
|
-
for(let i = 1; i < numNodes; i++) {
|
|
179
|
-
edges.push([0, i]);
|
|
180
|
-
}
|
|
181
|
-
break;
|
|
182
|
-
case 'random':
|
|
183
|
-
default:
|
|
184
|
-
const numEdges = Math.floor(numNodes * 1.5);
|
|
185
|
-
for(let i = 0; i < numEdges; i++) {
|
|
186
|
-
const a = Math.floor(Math.random() * numNodes);
|
|
187
|
-
const b = Math.floor(Math.random() * numNodes);
|
|
188
|
-
if(a !== b && !edges.some(e => (e[0] === a && e[1] === b) || (e[0] === b && e[1] === a))) {
|
|
189
|
-
edges.push([a, b]);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return { nodes: () => nodes, edges: () => edges };
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function visualizeGraph(graph, positions) {
|
|
199
|
-
const svg = document.getElementById('graph-svg');
|
|
200
|
-
const svgRect = svg.getBoundingClientRect();
|
|
201
|
-
const width = svgRect.width;
|
|
202
|
-
const height = svgRect.height;
|
|
203
|
-
|
|
204
|
-
svg.innerHTML = '';
|
|
205
|
-
|
|
206
|
-
const margin = 50;
|
|
207
|
-
const scaleX = (width - 2 * margin);
|
|
208
|
-
const scaleY = (height - 2 * margin);
|
|
209
|
-
|
|
210
|
-
const nodes = graph.nodes();
|
|
211
|
-
const posValues = nodes.map(n => positions[n]);
|
|
212
|
-
const minX = Math.min(...posValues.map(p => p[0]));
|
|
213
|
-
const maxX = Math.max(...posValues.map(p => p[0]));
|
|
214
|
-
const minY = Math.min(...posValues.map(p => p[1]));
|
|
215
|
-
const maxY = Math.max(...posValues.map(p => p[1]));
|
|
216
|
-
|
|
217
|
-
const rangeX = maxX - minX || 1;
|
|
218
|
-
const rangeY = maxY - minY || 1;
|
|
219
|
-
|
|
220
|
-
// Draw edges
|
|
221
|
-
const edges = graph.edges();
|
|
222
|
-
edges.forEach(([source, target]) => {
|
|
223
|
-
const sourcePos = positions[source];
|
|
224
|
-
const targetPos = positions[target];
|
|
225
|
-
|
|
226
|
-
const x1 = margin + (sourcePos[0] - minX) / rangeX * scaleX;
|
|
227
|
-
const y1 = margin + (sourcePos[1] - minY) / rangeY * scaleY;
|
|
228
|
-
const x2 = margin + (targetPos[0] - minX) / rangeX * scaleX;
|
|
229
|
-
const y2 = margin + (targetPos[1] - minY) / rangeY * scaleY;
|
|
230
|
-
|
|
231
|
-
const line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
|
|
232
|
-
line.setAttribute('x1', x1);
|
|
233
|
-
line.setAttribute('y1', y1);
|
|
234
|
-
line.setAttribute('x2', x2);
|
|
235
|
-
line.setAttribute('y2', y2);
|
|
236
|
-
line.setAttribute('stroke', '#999');
|
|
237
|
-
line.setAttribute('stroke-width', '2');
|
|
238
|
-
svg.appendChild(line);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
// Draw nodes
|
|
242
|
-
nodes.forEach(node => {
|
|
243
|
-
const pos = positions[node];
|
|
244
|
-
const x = margin + (pos[0] - minX) / rangeX * scaleX;
|
|
245
|
-
const y = margin + (pos[1] - minY) / rangeY * scaleY;
|
|
246
|
-
|
|
247
|
-
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
248
|
-
circle.setAttribute('cx', x);
|
|
249
|
-
circle.setAttribute('cy', y);
|
|
250
|
-
circle.setAttribute('r', '8');
|
|
251
|
-
circle.setAttribute('fill', '#4CAF50');
|
|
252
|
-
circle.setAttribute('stroke', '#333');
|
|
253
|
-
circle.setAttribute('stroke-width', '2');
|
|
254
|
-
svg.appendChild(circle);
|
|
255
|
-
|
|
256
|
-
const text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
|
|
257
|
-
text.setAttribute('x', x);
|
|
258
|
-
text.setAttribute('y', y + 4);
|
|
259
|
-
text.setAttribute('text-anchor', 'middle');
|
|
260
|
-
text.setAttribute('font-size', '11');
|
|
261
|
-
text.setAttribute('fill', 'white');
|
|
262
|
-
text.textContent = node;
|
|
263
|
-
svg.appendChild(text);
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
window.newGraph = function() {
|
|
268
|
-
const numNodes = parseInt(document.getElementById('num-nodes').value);
|
|
269
|
-
const graphType = document.getElementById('graph-type').value;
|
|
270
|
-
|
|
271
|
-
currentGraph = generateGraph(graphType, numNodes);
|
|
272
|
-
|
|
273
|
-
// Just visualize with random positions initially
|
|
274
|
-
const positions = {};
|
|
275
|
-
currentGraph.nodes().forEach(node => {
|
|
276
|
-
positions[node] = [
|
|
277
|
-
(Math.random() - 0.5) * 1.5,
|
|
278
|
-
(Math.random() - 0.5) * 1.5
|
|
279
|
-
];
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
visualizeGraph(currentGraph, positions);
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
window.applyLayout = function() {
|
|
286
|
-
if(!currentGraph) return;
|
|
287
|
-
|
|
288
|
-
const iterations = parseInt(document.getElementById('iterations').value);
|
|
289
|
-
const k = parseFloat(document.getElementById('k-value').value);
|
|
290
|
-
|
|
291
|
-
const positions = springLayout(currentGraph, k, null, null, iterations, 1, [0, 0], 2);
|
|
292
|
-
|
|
293
|
-
visualizeGraph(currentGraph, positions);
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
function setupControls() {
|
|
297
|
-
const controls = ['num-nodes', 'iterations', 'k-value'];
|
|
298
|
-
controls.forEach(id => {
|
|
299
|
-
const slider = document.getElementById(id);
|
|
300
|
-
const valueSpan = document.getElementById(id + '-value');
|
|
301
|
-
slider.oninput = function() {
|
|
302
|
-
valueSpan.textContent = this.value;
|
|
303
|
-
};
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
document.getElementById('graph-type').onchange = null;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
setupControls();
|
|
310
|
-
newGraph();
|
|
311
|
-
</script>
|
|
312
|
-
</body>
|
|
313
|
-
</html>
|