@graphty/layout 1.2.3 → 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.
Files changed (201) hide show
  1. package/dist/src/algorithms/index.d.ts +5 -0
  2. package/dist/src/algorithms/index.js +6 -0
  3. package/dist/src/algorithms/index.js.map +1 -0
  4. package/dist/src/algorithms/optimization/index.d.ts +7 -0
  5. package/dist/src/algorithms/optimization/index.js +7 -0
  6. package/dist/src/algorithms/optimization/index.js.map +1 -0
  7. package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts +32 -0
  8. package/dist/src/algorithms/optimization/kamada-kawai-solver.js +176 -0
  9. package/dist/src/algorithms/optimization/kamada-kawai-solver.js.map +1 -0
  10. package/dist/src/algorithms/optimization/lbfgs.d.ts +13 -0
  11. package/dist/src/algorithms/optimization/lbfgs.js +56 -0
  12. package/dist/src/algorithms/optimization/lbfgs.js.map +1 -0
  13. package/dist/src/algorithms/optimization/line-search.d.ts +15 -0
  14. package/dist/src/algorithms/optimization/line-search.js +37 -0
  15. package/dist/src/algorithms/optimization/line-search.js.map +1 -0
  16. package/dist/src/algorithms/optimization/types.d.ts +5 -0
  17. package/dist/src/algorithms/optimization/types.js +5 -0
  18. package/dist/src/algorithms/optimization/types.js.map +1 -0
  19. package/dist/src/algorithms/planarity/check.d.ts +17 -0
  20. package/dist/src/algorithms/planarity/check.js +30 -0
  21. package/dist/src/algorithms/planarity/check.js.map +1 -0
  22. package/dist/src/algorithms/planarity/embedding.d.ts +29 -0
  23. package/dist/src/algorithms/planarity/embedding.js +179 -0
  24. package/dist/src/algorithms/planarity/embedding.js.map +1 -0
  25. package/dist/src/algorithms/planarity/index.d.ts +7 -0
  26. package/dist/src/algorithms/planarity/index.js +8 -0
  27. package/dist/src/algorithms/planarity/index.js.map +1 -0
  28. package/dist/src/algorithms/planarity/lr-test.d.ts +15 -0
  29. package/dist/src/algorithms/planarity/lr-test.js +54 -0
  30. package/dist/src/algorithms/planarity/lr-test.js.map +1 -0
  31. package/dist/src/algorithms/planarity/special-graphs.d.ts +28 -0
  32. package/dist/src/algorithms/planarity/special-graphs.js +108 -0
  33. package/dist/src/algorithms/planarity/special-graphs.js.map +1 -0
  34. package/dist/src/generators/basic.d.ts +28 -0
  35. package/dist/src/generators/basic.js +79 -0
  36. package/dist/src/generators/basic.js.map +1 -0
  37. package/dist/src/generators/bipartite.d.ts +16 -0
  38. package/dist/src/generators/bipartite.js +40 -0
  39. package/dist/src/generators/bipartite.js.map +1 -0
  40. package/dist/src/generators/grid.d.ts +11 -0
  41. package/dist/src/generators/grid.js +37 -0
  42. package/dist/src/generators/grid.js.map +1 -0
  43. package/dist/src/generators/index.d.ts +8 -0
  44. package/dist/src/generators/index.js +9 -0
  45. package/dist/src/generators/index.js.map +1 -0
  46. package/dist/src/generators/random.d.ts +12 -0
  47. package/dist/src/generators/random.js +34 -0
  48. package/dist/src/generators/random.js.map +1 -0
  49. package/dist/src/generators/scale-free.d.ts +12 -0
  50. package/dist/src/generators/scale-free.js +62 -0
  51. package/dist/src/generators/scale-free.js.map +1 -0
  52. package/dist/src/index.d.ts +10 -0
  53. package/dist/src/index.js +15 -0
  54. package/dist/src/index.js.map +1 -0
  55. package/dist/src/layouts/basic/index.d.ts +4 -0
  56. package/dist/src/layouts/basic/index.js +5 -0
  57. package/dist/src/layouts/basic/index.js.map +1 -0
  58. package/dist/src/layouts/basic/random.d.ts +14 -0
  59. package/dist/src/layouts/basic/random.js +27 -0
  60. package/dist/src/layouts/basic/random.js.map +1 -0
  61. package/dist/src/layouts/force-directed/arf.d.ts +13 -0
  62. package/dist/src/layouts/force-directed/arf.js +103 -0
  63. package/dist/src/layouts/force-directed/arf.js.map +1 -0
  64. package/dist/src/layouts/force-directed/forceatlas2.d.ts +22 -0
  65. package/dist/src/layouts/force-directed/forceatlas2.js +322 -0
  66. package/dist/src/layouts/force-directed/forceatlas2.js.map +1 -0
  67. package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts +19 -0
  68. package/dist/src/layouts/force-directed/fruchterman-reingold.js +131 -0
  69. package/dist/src/layouts/force-directed/fruchterman-reingold.js.map +1 -0
  70. package/dist/src/layouts/force-directed/index.d.ts +8 -0
  71. package/dist/src/layouts/force-directed/index.js +9 -0
  72. package/dist/src/layouts/force-directed/index.js.map +1 -0
  73. package/dist/src/layouts/force-directed/kamada-kawai.d.ts +15 -0
  74. package/dist/src/layouts/force-directed/kamada-kawai.js +87 -0
  75. package/dist/src/layouts/force-directed/kamada-kawai.js.map +1 -0
  76. package/dist/src/layouts/force-directed/spring.d.ts +19 -0
  77. package/dist/src/layouts/force-directed/spring.js +23 -0
  78. package/dist/src/layouts/force-directed/spring.js.map +1 -0
  79. package/dist/src/layouts/geometric/circular.d.ts +14 -0
  80. package/dist/src/layouts/geometric/circular.js +67 -0
  81. package/dist/src/layouts/geometric/circular.js.map +1 -0
  82. package/dist/src/layouts/geometric/index.d.ts +6 -0
  83. package/dist/src/layouts/geometric/index.js +7 -0
  84. package/dist/src/layouts/geometric/index.js.map +1 -0
  85. package/dist/src/layouts/geometric/shell.d.ts +15 -0
  86. package/dist/src/layouts/geometric/shell.js +67 -0
  87. package/dist/src/layouts/geometric/shell.js.map +1 -0
  88. package/dist/src/layouts/geometric/spiral.d.ts +16 -0
  89. package/dist/src/layouts/geometric/spiral.js +73 -0
  90. package/dist/src/layouts/geometric/spiral.js.map +1 -0
  91. package/dist/src/layouts/hierarchical/bfs.d.ts +12 -0
  92. package/dist/src/layouts/hierarchical/bfs.js +62 -0
  93. package/dist/src/layouts/hierarchical/bfs.js.map +1 -0
  94. package/dist/src/layouts/hierarchical/bipartite.d.ts +16 -0
  95. package/dist/src/layouts/hierarchical/bipartite.js +72 -0
  96. package/dist/src/layouts/hierarchical/bipartite.js.map +1 -0
  97. package/dist/src/layouts/hierarchical/index.d.ts +6 -0
  98. package/dist/src/layouts/hierarchical/index.js +7 -0
  99. package/dist/src/layouts/hierarchical/index.js.map +1 -0
  100. package/dist/src/layouts/hierarchical/multipartite.d.ts +12 -0
  101. package/dist/src/layouts/hierarchical/multipartite.js +73 -0
  102. package/dist/src/layouts/hierarchical/multipartite.js.map +1 -0
  103. package/dist/src/layouts/index.d.ts +8 -0
  104. package/dist/src/layouts/index.js +9 -0
  105. package/dist/src/layouts/index.js.map +1 -0
  106. package/dist/src/layouts/specialized/index.d.ts +5 -0
  107. package/dist/src/layouts/specialized/index.js +6 -0
  108. package/dist/src/layouts/specialized/index.js.map +1 -0
  109. package/dist/src/layouts/specialized/planar.d.ts +14 -0
  110. package/dist/src/layouts/specialized/planar.js +47 -0
  111. package/dist/src/layouts/specialized/planar.js.map +1 -0
  112. package/dist/src/layouts/specialized/spectral.d.ts +14 -0
  113. package/dist/src/layouts/specialized/spectral.js +106 -0
  114. package/dist/src/layouts/specialized/spectral.js.map +1 -0
  115. package/dist/src/types/embedding.d.ts +9 -0
  116. package/dist/src/types/embedding.js +5 -0
  117. package/dist/src/types/embedding.js.map +1 -0
  118. package/dist/src/types/graph.d.ts +10 -0
  119. package/dist/src/types/graph.js +5 -0
  120. package/dist/src/types/graph.js.map +1 -0
  121. package/dist/src/types/index.d.ts +6 -0
  122. package/dist/src/types/index.js +7 -0
  123. package/dist/src/types/index.js.map +1 -0
  124. package/dist/src/types/layout.d.ts +6 -0
  125. package/dist/src/types/layout.js +5 -0
  126. package/dist/src/types/layout.js.map +1 -0
  127. package/dist/src/utils/graph.d.ts +34 -0
  128. package/dist/src/utils/graph.js +69 -0
  129. package/dist/src/utils/graph.js.map +1 -0
  130. package/dist/src/utils/index.d.ts +8 -0
  131. package/dist/src/utils/index.js +9 -0
  132. package/dist/src/utils/index.js.map +1 -0
  133. package/dist/src/utils/numpy.d.ts +17 -0
  134. package/dist/src/utils/numpy.js +101 -0
  135. package/dist/src/utils/numpy.js.map +1 -0
  136. package/dist/src/utils/params.d.ts +17 -0
  137. package/dist/src/utils/params.js +22 -0
  138. package/dist/src/utils/params.js.map +1 -0
  139. package/dist/src/utils/random.d.ts +14 -0
  140. package/dist/src/utils/random.js +42 -0
  141. package/dist/src/utils/random.js.map +1 -0
  142. package/dist/src/utils/rescale.d.ts +21 -0
  143. package/dist/src/utils/rescale.js +119 -0
  144. package/dist/src/utils/rescale.js.map +1 -0
  145. package/dist/vitest.config.js +1 -1
  146. package/dist/vitest.config.js.map +1 -1
  147. package/package.json +14 -1
  148. package/.env.example +0 -11
  149. package/.github/workflows/ci.yml +0 -101
  150. package/.releaserc.json +0 -22
  151. package/CHANGELOG.md +0 -52
  152. package/CLAUDE.md +0 -104
  153. package/CONTRIBUTING.md +0 -1
  154. package/DEPLOYMENT.md +0 -59
  155. package/build-examples-script.js +0 -26
  156. package/commitlint.config.js +0 -37
  157. package/examples/3d-force-directed.html +0 -611
  158. package/examples/3d-kamada-kawai.html +0 -379
  159. package/examples/3d-layout-comparison.html +0 -448
  160. package/examples/3d-spherical-layout.html +0 -319
  161. package/examples/arf-layout.html +0 -524
  162. package/examples/bfs-layout.html +0 -487
  163. package/examples/bipartite-layout.html +0 -382
  164. package/examples/circular-layout.html +0 -292
  165. package/examples/forceatlas2-layout.html +0 -588
  166. package/examples/index.html +0 -241
  167. package/examples/kamada-kawai-layout.html +0 -425
  168. package/examples/layout-helpers.js +0 -23
  169. package/examples/layout.js +0 -2304
  170. package/examples/multipartite-layout.html +0 -410
  171. package/examples/planar-layout.html +0 -388
  172. package/examples/random-layout.html +0 -328
  173. package/examples/shell-layout.html +0 -323
  174. package/examples/spectral-layout.html +0 -335
  175. package/examples/spiral-layout.html +0 -447
  176. package/examples/spring-layout.html +0 -313
  177. package/test/arf-layout.test.ts +0 -443
  178. package/test/bfs-layout.test.ts +0 -427
  179. package/test/bipartite-layout.test.ts +0 -344
  180. package/test/circular-layout.test.ts +0 -442
  181. package/test/forceatlas2-layout.test.ts +0 -405
  182. package/test/fruchterman-reingold-layout.test.ts +0 -477
  183. package/test/graph-generators.test.ts +0 -450
  184. package/test/kamada-kawai-layout.test.ts +0 -623
  185. package/test/multipartite-layout.test.ts +0 -404
  186. package/test/planar-layout.test.ts +0 -266
  187. package/test/random-layout.test.ts +0 -254
  188. package/test/rescale-layout.test.ts +0 -373
  189. package/test/shell-layout.test.ts +0 -347
  190. package/test/spectral-layout.test.ts +0 -378
  191. package/test/spiral-layout.test.ts +0 -338
  192. package/test/spring-layout.test.ts +0 -241
  193. package/test/test-utils.ts +0 -34
  194. package/test/utils-graph.test.ts +0 -155
  195. package/test/utils-index.test.ts +0 -77
  196. package/test/utils-numpy.test.ts +0 -272
  197. package/test/utils-params.test.ts +0 -99
  198. package/test/utils-random.test.ts +0 -229
  199. package/tsconfig.json +0 -16
  200. package/vite.config.js +0 -36
  201. package/vitest.config.ts +0 -30
@@ -1,388 +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>Planar 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
- .info-box {
96
- background: #f0f7ff;
97
- border: 1px solid #c0d7f0;
98
- border-radius: 4px;
99
- padding: 10px;
100
- margin-top: 15px;
101
- font-size: 0.85em;
102
- }
103
- .error-message {
104
- color: #d32f2f;
105
- background: #ffebee;
106
- padding: 10px;
107
- border-radius: 4px;
108
- margin-top: 10px;
109
- font-size: 0.9em;
110
- display: none;
111
- }
112
- </style>
113
- </head>
114
- <body>
115
- <div class="back-link">
116
- <a href="index.html">← Back to Index</a>
117
- </div>
118
-
119
- <h1>Planar Layout Test</h1>
120
-
121
- <div class="container">
122
- <div class="graph-controls">
123
- <h3>Graph Settings</h3>
124
-
125
- <div class="control-group">
126
- <label for="graph-type">Graph type:</label>
127
- <select id="graph-type">
128
- <option value="triangulated">Triangulated</option>
129
- <option value="outerplanar">Outerplanar</option>
130
- <option value="grid">Grid</option>
131
- <option value="tree">Tree</option>
132
- </select>
133
- </div>
134
-
135
- <div class="control-group">
136
- <label for="num-nodes">Number of nodes:</label>
137
- <input type="range" id="num-nodes" min="4" max="20" value="10">
138
- <span id="num-nodes-value">10</span>
139
- </div>
140
-
141
- <button onclick="newGraph()">New Graph</button>
142
- <div id="error-message" class="error-message"></div>
143
- </div>
144
-
145
- <div class="visualization">
146
- <svg id="graph-svg" width="800" height="600"></svg>
147
- </div>
148
-
149
- <div class="layout-controls">
150
- <h3>Layout Parameters</h3>
151
-
152
- <div class="control-group">
153
- <label for="center-x">Center X:</label>
154
- <input type="range" id="center-x" min="-2" max="2" step="0.1" value="0">
155
- <span id="center-x-value">0.0</span>
156
- </div>
157
-
158
- <div class="control-group">
159
- <label for="center-y">Center Y:</label>
160
- <input type="range" id="center-y" min="-2" max="2" step="0.1" value="0">
161
- <span id="center-y-value">0.0</span>
162
- </div>
163
-
164
- <button onclick="applyLayout()">Apply Layout</button>
165
-
166
- <div class="info-box">
167
- <strong>Planar Layout:</strong> Positions nodes without edge intersections.
168
- Note that only planar graphs (graphs that can be drawn without edge crossings)
169
- can be processed by this algorithm. K5 (complete graph with 5 nodes) and K3,3
170
- (complete bipartite with 3,3 nodes) are examples of non-planar graphs.
171
- </div>
172
- </div>
173
- </div>
174
-
175
- <script type="module">
176
- import { planarLayout } from "./layout.js";
177
-
178
- let currentGraph = null;
179
-
180
- function generatePlanarGraph(type, numNodes) {
181
- const nodes = Array.from({length: numNodes}, (_, i) => i);
182
- const edges = [];
183
-
184
- switch(type) {
185
- case 'triangulated':
186
- // Create a planar triangulated graph (maximal planar)
187
- // Start with a triangle
188
- if (numNodes >= 3) {
189
- edges.push([0, 1], [1, 2], [2, 0]);
190
-
191
- // Add nodes one by one, connecting to visible edges
192
- for (let i = 3; i < numNodes; i++) {
193
- // Choose a face (for simplicity, we'll add to the outer face)
194
- // Select two or three nodes to connect to
195
- const connectCount = Math.min(3, i);
196
- const connectedNodes = [];
197
-
198
- // Connect to previous nodes (ensuring planarity)
199
- for (let j = 0; j < connectCount; j++) {
200
- connectedNodes.push(i - j - 1);
201
- edges.push([i, i - j - 1]);
202
- }
203
- }
204
- }
205
- break;
206
-
207
- case 'outerplanar':
208
- // Create an outerplanar graph (all vertices on outer face)
209
- // Start with a cycle
210
- for (let i = 0; i < numNodes; i++) {
211
- edges.push([i, (i + 1) % numNodes]);
212
- }
213
-
214
- // Add some non-crossing chords
215
- if (numNodes >= 5) {
216
- // Add diagonals that don't cross
217
- for (let i = 0; i < numNodes - 2; i++) {
218
- edges.push([i, (i + 2) % numNodes]);
219
- }
220
- }
221
- break;
222
-
223
- case 'grid':
224
- // Create a grid graph (always planar)
225
- const gridSize = Math.ceil(Math.sqrt(numNodes));
226
- for (let i = 0; i < numNodes; i++) {
227
- const row = Math.floor(i / gridSize);
228
- const col = i % gridSize;
229
-
230
- // Connect right
231
- if (col < gridSize - 1 && i + 1 < numNodes) {
232
- edges.push([i, i + 1]);
233
- }
234
-
235
- // Connect down
236
- if (row < gridSize - 1 && i + gridSize < numNodes) {
237
- edges.push([i, i + gridSize]);
238
- }
239
- }
240
- break;
241
-
242
- case 'tree':
243
- default:
244
- // Create a tree (always planar)
245
- for (let i = 1; i < numNodes; i++) {
246
- const parent = Math.floor(Math.random() * i);
247
- edges.push([parent, i]);
248
- }
249
- break;
250
- }
251
-
252
- return { nodes: () => nodes, edges: () => edges };
253
- }
254
-
255
- function visualizeGraph(graph, positions) {
256
- const svg = document.getElementById('graph-svg');
257
- const svgRect = svg.getBoundingClientRect();
258
- const width = svgRect.width;
259
- const height = svgRect.height;
260
-
261
- svg.innerHTML = '';
262
-
263
- const margin = 50;
264
- const scaleX = (width - 2 * margin);
265
- const scaleY = (height - 2 * margin);
266
-
267
- const nodes = graph.nodes();
268
- const posValues = nodes.map(n => positions[n]);
269
- const minX = Math.min(...posValues.map(p => p[0]));
270
- const maxX = Math.max(...posValues.map(p => p[0]));
271
- const minY = Math.min(...posValues.map(p => p[1]));
272
- const maxY = Math.max(...posValues.map(p => p[1]));
273
-
274
- const rangeX = maxX - minX || 1;
275
- const rangeY = maxY - minY || 1;
276
-
277
- // Draw edges
278
- const edges = graph.edges();
279
- edges.forEach(([source, target]) => {
280
- const sourcePos = positions[source];
281
- const targetPos = positions[target];
282
-
283
- const x1 = margin + (sourcePos[0] - minX) / rangeX * scaleX;
284
- const y1 = margin + (sourcePos[1] - minY) / rangeY * scaleY;
285
- const x2 = margin + (targetPos[0] - minX) / rangeX * scaleX;
286
- const y2 = margin + (targetPos[1] - minY) / rangeY * scaleY;
287
-
288
- const line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
289
- line.setAttribute('x1', x1);
290
- line.setAttribute('y1', y1);
291
- line.setAttribute('x2', x2);
292
- line.setAttribute('y2', y2);
293
- line.setAttribute('stroke', '#999');
294
- line.setAttribute('stroke-width', '2');
295
- svg.appendChild(line);
296
- });
297
-
298
- // Draw faces (for visual verification of planarity)
299
- const faceColor = 'rgba(200, 220, 240, 0.2)';
300
-
301
- // Draw nodes
302
- nodes.forEach(node => {
303
- const pos = positions[node];
304
- const x = margin + (pos[0] - minX) / rangeX * scaleX;
305
- const y = margin + (pos[1] - minY) / rangeY * scaleY;
306
-
307
- const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
308
- circle.setAttribute('cx', x);
309
- circle.setAttribute('cy', y);
310
- circle.setAttribute('r', '8');
311
- circle.setAttribute('fill', '#4CAF50');
312
- circle.setAttribute('stroke', '#333');
313
- circle.setAttribute('stroke-width', '2');
314
- svg.appendChild(circle);
315
-
316
- const text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
317
- text.setAttribute('x', x);
318
- text.setAttribute('y', y + 4);
319
- text.setAttribute('text-anchor', 'middle');
320
- text.setAttribute('font-size', '11');
321
- text.setAttribute('fill', 'white');
322
- text.textContent = node;
323
- svg.appendChild(text);
324
- });
325
- }
326
-
327
- window.newGraph = function() {
328
- const graphType = document.getElementById('graph-type').value;
329
- const numNodes = parseInt(document.getElementById('num-nodes').value);
330
-
331
- const errorMessageElement = document.getElementById('error-message');
332
- errorMessageElement.style.display = 'none';
333
-
334
- try {
335
- currentGraph = generatePlanarGraph(graphType, numNodes);
336
-
337
- // Just visualize with random positions initially
338
- const positions = {};
339
- currentGraph.nodes().forEach(node => {
340
- positions[node] = [
341
- (Math.random() - 0.5) * 1.5,
342
- (Math.random() - 0.5) * 1.5
343
- ];
344
- });
345
-
346
- visualizeGraph(currentGraph, positions);
347
- } catch (error) {
348
- console.error('Error generating graph:', error);
349
- errorMessageElement.textContent = `Error: ${error.message}`;
350
- errorMessageElement.style.display = 'block';
351
- }
352
- };
353
-
354
- window.applyLayout = function() {
355
- if(!currentGraph) return;
356
-
357
- const centerX = parseFloat(document.getElementById('center-x').value);
358
- const centerY = parseFloat(document.getElementById('center-y').value);
359
-
360
- const errorMessageElement = document.getElementById('error-message');
361
- errorMessageElement.style.display = 'none';
362
-
363
- try {
364
- const positions = planarLayout(currentGraph, 1, [centerX, centerY], 2);
365
- visualizeGraph(currentGraph, positions);
366
- } catch (error) {
367
- console.error('Error in planar layout:', error);
368
- errorMessageElement.textContent = `Error: ${error.message}`;
369
- errorMessageElement.style.display = 'block';
370
- }
371
- };
372
-
373
- function setupControls() {
374
- const controls = ['num-nodes', 'center-x', 'center-y'];
375
- controls.forEach(id => {
376
- const slider = document.getElementById(id);
377
- const valueSpan = document.getElementById(id + '-value');
378
- slider.oninput = function() {
379
- valueSpan.textContent = this.value;
380
- };
381
- });
382
- }
383
-
384
- setupControls();
385
- newGraph();
386
- </script>
387
- </body>
388
- </html>