@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.
Files changed (200) hide show
  1. package/README.md +317 -237
  2. package/dist/src/algorithms/index.d.ts +5 -0
  3. package/dist/src/algorithms/index.js +6 -0
  4. package/dist/src/algorithms/index.js.map +1 -0
  5. package/dist/src/algorithms/optimization/index.d.ts +7 -0
  6. package/dist/src/algorithms/optimization/index.js +7 -0
  7. package/dist/src/algorithms/optimization/index.js.map +1 -0
  8. package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts +32 -0
  9. package/dist/src/algorithms/optimization/kamada-kawai-solver.js +176 -0
  10. package/dist/src/algorithms/optimization/kamada-kawai-solver.js.map +1 -0
  11. package/dist/src/algorithms/optimization/lbfgs.d.ts +13 -0
  12. package/dist/src/algorithms/optimization/lbfgs.js +56 -0
  13. package/dist/src/algorithms/optimization/lbfgs.js.map +1 -0
  14. package/dist/src/algorithms/optimization/line-search.d.ts +15 -0
  15. package/dist/src/algorithms/optimization/line-search.js +37 -0
  16. package/dist/src/algorithms/optimization/line-search.js.map +1 -0
  17. package/dist/src/algorithms/optimization/types.d.ts +5 -0
  18. package/dist/src/algorithms/optimization/types.js +5 -0
  19. package/dist/src/algorithms/optimization/types.js.map +1 -0
  20. package/dist/src/algorithms/planarity/check.d.ts +17 -0
  21. package/dist/src/algorithms/planarity/check.js +30 -0
  22. package/dist/src/algorithms/planarity/check.js.map +1 -0
  23. package/dist/src/algorithms/planarity/embedding.d.ts +29 -0
  24. package/dist/src/algorithms/planarity/embedding.js +179 -0
  25. package/dist/src/algorithms/planarity/embedding.js.map +1 -0
  26. package/dist/src/algorithms/planarity/index.d.ts +7 -0
  27. package/dist/src/algorithms/planarity/index.js +8 -0
  28. package/dist/src/algorithms/planarity/index.js.map +1 -0
  29. package/dist/src/algorithms/planarity/lr-test.d.ts +15 -0
  30. package/dist/src/algorithms/planarity/lr-test.js +54 -0
  31. package/dist/src/algorithms/planarity/lr-test.js.map +1 -0
  32. package/dist/src/algorithms/planarity/special-graphs.d.ts +28 -0
  33. package/dist/src/algorithms/planarity/special-graphs.js +108 -0
  34. package/dist/src/algorithms/planarity/special-graphs.js.map +1 -0
  35. package/dist/src/generators/basic.d.ts +28 -0
  36. package/dist/src/generators/basic.js +79 -0
  37. package/dist/src/generators/basic.js.map +1 -0
  38. package/dist/src/generators/bipartite.d.ts +16 -0
  39. package/dist/src/generators/bipartite.js +40 -0
  40. package/dist/src/generators/bipartite.js.map +1 -0
  41. package/dist/src/generators/grid.d.ts +11 -0
  42. package/dist/src/generators/grid.js +37 -0
  43. package/dist/src/generators/grid.js.map +1 -0
  44. package/dist/src/generators/index.d.ts +8 -0
  45. package/dist/src/generators/index.js +9 -0
  46. package/dist/src/generators/index.js.map +1 -0
  47. package/dist/src/generators/random.d.ts +12 -0
  48. package/dist/src/generators/random.js +34 -0
  49. package/dist/src/generators/random.js.map +1 -0
  50. package/dist/src/generators/scale-free.d.ts +12 -0
  51. package/dist/src/generators/scale-free.js +62 -0
  52. package/dist/src/generators/scale-free.js.map +1 -0
  53. package/dist/src/index.d.ts +10 -0
  54. package/dist/src/index.js +15 -0
  55. package/dist/src/index.js.map +1 -0
  56. package/dist/src/layouts/basic/index.d.ts +4 -0
  57. package/dist/src/layouts/basic/index.js +5 -0
  58. package/dist/src/layouts/basic/index.js.map +1 -0
  59. package/dist/src/layouts/basic/random.d.ts +14 -0
  60. package/dist/src/layouts/basic/random.js +27 -0
  61. package/dist/src/layouts/basic/random.js.map +1 -0
  62. package/dist/src/layouts/force-directed/arf.d.ts +13 -0
  63. package/dist/src/layouts/force-directed/arf.js +103 -0
  64. package/dist/src/layouts/force-directed/arf.js.map +1 -0
  65. package/dist/src/layouts/force-directed/forceatlas2.d.ts +22 -0
  66. package/dist/src/layouts/force-directed/forceatlas2.js +322 -0
  67. package/dist/src/layouts/force-directed/forceatlas2.js.map +1 -0
  68. package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts +19 -0
  69. package/dist/src/layouts/force-directed/fruchterman-reingold.js +131 -0
  70. package/dist/src/layouts/force-directed/fruchterman-reingold.js.map +1 -0
  71. package/dist/src/layouts/force-directed/index.d.ts +8 -0
  72. package/dist/src/layouts/force-directed/index.js +9 -0
  73. package/dist/src/layouts/force-directed/index.js.map +1 -0
  74. package/dist/src/layouts/force-directed/kamada-kawai.d.ts +15 -0
  75. package/dist/src/layouts/force-directed/kamada-kawai.js +87 -0
  76. package/dist/src/layouts/force-directed/kamada-kawai.js.map +1 -0
  77. package/dist/src/layouts/force-directed/spring.d.ts +19 -0
  78. package/dist/src/layouts/force-directed/spring.js +23 -0
  79. package/dist/src/layouts/force-directed/spring.js.map +1 -0
  80. package/dist/src/layouts/geometric/circular.d.ts +14 -0
  81. package/dist/src/layouts/geometric/circular.js +67 -0
  82. package/dist/src/layouts/geometric/circular.js.map +1 -0
  83. package/dist/src/layouts/geometric/index.d.ts +6 -0
  84. package/dist/src/layouts/geometric/index.js +7 -0
  85. package/dist/src/layouts/geometric/index.js.map +1 -0
  86. package/dist/src/layouts/geometric/shell.d.ts +15 -0
  87. package/dist/src/layouts/geometric/shell.js +67 -0
  88. package/dist/src/layouts/geometric/shell.js.map +1 -0
  89. package/dist/src/layouts/geometric/spiral.d.ts +16 -0
  90. package/dist/src/layouts/geometric/spiral.js +73 -0
  91. package/dist/src/layouts/geometric/spiral.js.map +1 -0
  92. package/dist/src/layouts/hierarchical/bfs.d.ts +12 -0
  93. package/dist/src/layouts/hierarchical/bfs.js +62 -0
  94. package/dist/src/layouts/hierarchical/bfs.js.map +1 -0
  95. package/dist/src/layouts/hierarchical/bipartite.d.ts +16 -0
  96. package/dist/src/layouts/hierarchical/bipartite.js +72 -0
  97. package/dist/src/layouts/hierarchical/bipartite.js.map +1 -0
  98. package/dist/src/layouts/hierarchical/index.d.ts +6 -0
  99. package/dist/src/layouts/hierarchical/index.js +7 -0
  100. package/dist/src/layouts/hierarchical/index.js.map +1 -0
  101. package/dist/src/layouts/hierarchical/multipartite.d.ts +12 -0
  102. package/dist/src/layouts/hierarchical/multipartite.js +73 -0
  103. package/dist/src/layouts/hierarchical/multipartite.js.map +1 -0
  104. package/dist/src/layouts/index.d.ts +8 -0
  105. package/dist/src/layouts/index.js +9 -0
  106. package/dist/src/layouts/index.js.map +1 -0
  107. package/dist/src/layouts/specialized/index.d.ts +5 -0
  108. package/dist/src/layouts/specialized/index.js +6 -0
  109. package/dist/src/layouts/specialized/index.js.map +1 -0
  110. package/dist/src/layouts/specialized/planar.d.ts +14 -0
  111. package/dist/src/layouts/specialized/planar.js +47 -0
  112. package/dist/src/layouts/specialized/planar.js.map +1 -0
  113. package/dist/src/layouts/specialized/spectral.d.ts +14 -0
  114. package/dist/src/layouts/specialized/spectral.js +106 -0
  115. package/dist/src/layouts/specialized/spectral.js.map +1 -0
  116. package/dist/src/types/embedding.d.ts +9 -0
  117. package/dist/src/types/embedding.js +5 -0
  118. package/dist/src/types/embedding.js.map +1 -0
  119. package/dist/src/types/graph.d.ts +10 -0
  120. package/dist/src/types/graph.js +5 -0
  121. package/dist/src/types/graph.js.map +1 -0
  122. package/dist/src/types/index.d.ts +6 -0
  123. package/dist/src/types/index.js +7 -0
  124. package/dist/src/types/index.js.map +1 -0
  125. package/dist/src/types/layout.d.ts +6 -0
  126. package/dist/src/types/layout.js +5 -0
  127. package/dist/src/types/layout.js.map +1 -0
  128. package/dist/src/utils/graph.d.ts +34 -0
  129. package/dist/src/utils/graph.js +69 -0
  130. package/dist/src/utils/graph.js.map +1 -0
  131. package/dist/src/utils/index.d.ts +8 -0
  132. package/dist/src/utils/index.js +9 -0
  133. package/dist/src/utils/index.js.map +1 -0
  134. package/dist/src/utils/numpy.d.ts +17 -0
  135. package/dist/src/utils/numpy.js +101 -0
  136. package/dist/src/utils/numpy.js.map +1 -0
  137. package/dist/src/utils/params.d.ts +17 -0
  138. package/dist/src/utils/params.js +22 -0
  139. package/dist/src/utils/params.js.map +1 -0
  140. package/dist/src/utils/random.d.ts +14 -0
  141. package/dist/src/utils/random.js +42 -0
  142. package/dist/src/utils/random.js.map +1 -0
  143. package/dist/src/utils/rescale.d.ts +21 -0
  144. package/dist/src/utils/rescale.js +119 -0
  145. package/dist/src/utils/rescale.js.map +1 -0
  146. package/dist/vitest.config.js +1 -1
  147. package/dist/vitest.config.js.map +1 -1
  148. package/package.json +15 -1
  149. package/.env.example +0 -11
  150. package/.github/workflows/ci.yml +0 -101
  151. package/.releaserc.json +0 -22
  152. package/CHANGELOG.md +0 -45
  153. package/CLAUDE.md +0 -104
  154. package/CONTRIBUTING.md +0 -1
  155. package/DEPLOYMENT.md +0 -59
  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 -486
  169. package/examples/multipartite-layout.html +0 -410
  170. package/examples/planar-layout.html +0 -388
  171. package/examples/random-layout.html +0 -328
  172. package/examples/shell-layout.html +0 -323
  173. package/examples/spectral-layout.html +0 -335
  174. package/examples/spiral-layout.html +0 -447
  175. package/examples/spring-layout.html +0 -313
  176. package/test/arf-layout.test.ts +0 -443
  177. package/test/bfs-layout.test.ts +0 -427
  178. package/test/bipartite-layout.test.ts +0 -344
  179. package/test/circular-layout.test.ts +0 -442
  180. package/test/forceatlas2-layout.test.ts +0 -405
  181. package/test/fruchterman-reingold-layout.test.ts +0 -477
  182. package/test/graph-generators.test.ts +0 -450
  183. package/test/kamada-kawai-layout.test.ts +0 -623
  184. package/test/multipartite-layout.test.ts +0 -404
  185. package/test/planar-layout.test.ts +0 -266
  186. package/test/random-layout.test.ts +0 -254
  187. package/test/rescale-layout.test.ts +0 -373
  188. package/test/shell-layout.test.ts +0 -347
  189. package/test/spectral-layout.test.ts +0 -378
  190. package/test/spiral-layout.test.ts +0 -338
  191. package/test/spring-layout.test.ts +0 -241
  192. package/test/test-utils.ts +0 -34
  193. package/test/utils-graph.test.ts +0 -155
  194. package/test/utils-index.test.ts +0 -77
  195. package/test/utils-numpy.test.ts +0 -272
  196. package/test/utils-params.test.ts +0 -99
  197. package/test/utils-random.test.ts +0 -229
  198. package/tsconfig.json +0 -16
  199. package/vite.config.js +0 -36
  200. package/vitest.config.ts +0 -30
@@ -1,319 +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>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>