@graphty/layout 1.2.5 → 1.2.7

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 (151) hide show
  1. package/README.md +109 -3
  2. package/dist/layout.js +1762 -0
  3. package/dist/layout.js.map +1 -0
  4. package/package.json +4 -3
  5. package/dist/src/algorithms/index.d.ts +0 -5
  6. package/dist/src/algorithms/index.js +0 -6
  7. package/dist/src/algorithms/index.js.map +0 -1
  8. package/dist/src/algorithms/optimization/index.d.ts +0 -7
  9. package/dist/src/algorithms/optimization/index.js +0 -7
  10. package/dist/src/algorithms/optimization/index.js.map +0 -1
  11. package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts +0 -32
  12. package/dist/src/algorithms/optimization/kamada-kawai-solver.js +0 -176
  13. package/dist/src/algorithms/optimization/kamada-kawai-solver.js.map +0 -1
  14. package/dist/src/algorithms/optimization/lbfgs.d.ts +0 -13
  15. package/dist/src/algorithms/optimization/lbfgs.js +0 -56
  16. package/dist/src/algorithms/optimization/lbfgs.js.map +0 -1
  17. package/dist/src/algorithms/optimization/line-search.d.ts +0 -15
  18. package/dist/src/algorithms/optimization/line-search.js +0 -37
  19. package/dist/src/algorithms/optimization/line-search.js.map +0 -1
  20. package/dist/src/algorithms/optimization/types.d.ts +0 -5
  21. package/dist/src/algorithms/optimization/types.js +0 -5
  22. package/dist/src/algorithms/optimization/types.js.map +0 -1
  23. package/dist/src/algorithms/planarity/check.d.ts +0 -17
  24. package/dist/src/algorithms/planarity/check.js +0 -30
  25. package/dist/src/algorithms/planarity/check.js.map +0 -1
  26. package/dist/src/algorithms/planarity/embedding.d.ts +0 -29
  27. package/dist/src/algorithms/planarity/embedding.js +0 -179
  28. package/dist/src/algorithms/planarity/embedding.js.map +0 -1
  29. package/dist/src/algorithms/planarity/index.d.ts +0 -7
  30. package/dist/src/algorithms/planarity/index.js +0 -8
  31. package/dist/src/algorithms/planarity/index.js.map +0 -1
  32. package/dist/src/algorithms/planarity/lr-test.d.ts +0 -15
  33. package/dist/src/algorithms/planarity/lr-test.js +0 -54
  34. package/dist/src/algorithms/planarity/lr-test.js.map +0 -1
  35. package/dist/src/algorithms/planarity/special-graphs.d.ts +0 -28
  36. package/dist/src/algorithms/planarity/special-graphs.js +0 -108
  37. package/dist/src/algorithms/planarity/special-graphs.js.map +0 -1
  38. package/dist/src/generators/basic.d.ts +0 -28
  39. package/dist/src/generators/basic.js +0 -79
  40. package/dist/src/generators/basic.js.map +0 -1
  41. package/dist/src/generators/bipartite.d.ts +0 -16
  42. package/dist/src/generators/bipartite.js +0 -40
  43. package/dist/src/generators/bipartite.js.map +0 -1
  44. package/dist/src/generators/grid.d.ts +0 -11
  45. package/dist/src/generators/grid.js +0 -37
  46. package/dist/src/generators/grid.js.map +0 -1
  47. package/dist/src/generators/index.d.ts +0 -8
  48. package/dist/src/generators/index.js +0 -9
  49. package/dist/src/generators/index.js.map +0 -1
  50. package/dist/src/generators/random.d.ts +0 -12
  51. package/dist/src/generators/random.js +0 -34
  52. package/dist/src/generators/random.js.map +0 -1
  53. package/dist/src/generators/scale-free.d.ts +0 -12
  54. package/dist/src/generators/scale-free.js +0 -62
  55. package/dist/src/generators/scale-free.js.map +0 -1
  56. package/dist/src/index.d.ts +0 -10
  57. package/dist/src/index.js +0 -15
  58. package/dist/src/index.js.map +0 -1
  59. package/dist/src/layouts/basic/index.d.ts +0 -4
  60. package/dist/src/layouts/basic/index.js +0 -5
  61. package/dist/src/layouts/basic/index.js.map +0 -1
  62. package/dist/src/layouts/basic/random.d.ts +0 -14
  63. package/dist/src/layouts/basic/random.js +0 -27
  64. package/dist/src/layouts/basic/random.js.map +0 -1
  65. package/dist/src/layouts/force-directed/arf.d.ts +0 -13
  66. package/dist/src/layouts/force-directed/arf.js +0 -103
  67. package/dist/src/layouts/force-directed/arf.js.map +0 -1
  68. package/dist/src/layouts/force-directed/forceatlas2.d.ts +0 -22
  69. package/dist/src/layouts/force-directed/forceatlas2.js +0 -340
  70. package/dist/src/layouts/force-directed/forceatlas2.js.map +0 -1
  71. package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts +0 -19
  72. package/dist/src/layouts/force-directed/fruchterman-reingold.js +0 -131
  73. package/dist/src/layouts/force-directed/fruchterman-reingold.js.map +0 -1
  74. package/dist/src/layouts/force-directed/index.d.ts +0 -8
  75. package/dist/src/layouts/force-directed/index.js +0 -9
  76. package/dist/src/layouts/force-directed/index.js.map +0 -1
  77. package/dist/src/layouts/force-directed/kamada-kawai.d.ts +0 -15
  78. package/dist/src/layouts/force-directed/kamada-kawai.js +0 -87
  79. package/dist/src/layouts/force-directed/kamada-kawai.js.map +0 -1
  80. package/dist/src/layouts/force-directed/spring.d.ts +0 -19
  81. package/dist/src/layouts/force-directed/spring.js +0 -23
  82. package/dist/src/layouts/force-directed/spring.js.map +0 -1
  83. package/dist/src/layouts/geometric/circular.d.ts +0 -14
  84. package/dist/src/layouts/geometric/circular.js +0 -67
  85. package/dist/src/layouts/geometric/circular.js.map +0 -1
  86. package/dist/src/layouts/geometric/index.d.ts +0 -6
  87. package/dist/src/layouts/geometric/index.js +0 -7
  88. package/dist/src/layouts/geometric/index.js.map +0 -1
  89. package/dist/src/layouts/geometric/shell.d.ts +0 -15
  90. package/dist/src/layouts/geometric/shell.js +0 -67
  91. package/dist/src/layouts/geometric/shell.js.map +0 -1
  92. package/dist/src/layouts/geometric/spiral.d.ts +0 -16
  93. package/dist/src/layouts/geometric/spiral.js +0 -73
  94. package/dist/src/layouts/geometric/spiral.js.map +0 -1
  95. package/dist/src/layouts/hierarchical/bfs.d.ts +0 -12
  96. package/dist/src/layouts/hierarchical/bfs.js +0 -62
  97. package/dist/src/layouts/hierarchical/bfs.js.map +0 -1
  98. package/dist/src/layouts/hierarchical/bipartite.d.ts +0 -16
  99. package/dist/src/layouts/hierarchical/bipartite.js +0 -72
  100. package/dist/src/layouts/hierarchical/bipartite.js.map +0 -1
  101. package/dist/src/layouts/hierarchical/index.d.ts +0 -6
  102. package/dist/src/layouts/hierarchical/index.js +0 -7
  103. package/dist/src/layouts/hierarchical/index.js.map +0 -1
  104. package/dist/src/layouts/hierarchical/multipartite.d.ts +0 -12
  105. package/dist/src/layouts/hierarchical/multipartite.js +0 -73
  106. package/dist/src/layouts/hierarchical/multipartite.js.map +0 -1
  107. package/dist/src/layouts/index.d.ts +0 -8
  108. package/dist/src/layouts/index.js +0 -9
  109. package/dist/src/layouts/index.js.map +0 -1
  110. package/dist/src/layouts/specialized/index.d.ts +0 -5
  111. package/dist/src/layouts/specialized/index.js +0 -6
  112. package/dist/src/layouts/specialized/index.js.map +0 -1
  113. package/dist/src/layouts/specialized/planar.d.ts +0 -14
  114. package/dist/src/layouts/specialized/planar.js +0 -47
  115. package/dist/src/layouts/specialized/planar.js.map +0 -1
  116. package/dist/src/layouts/specialized/spectral.d.ts +0 -14
  117. package/dist/src/layouts/specialized/spectral.js +0 -106
  118. package/dist/src/layouts/specialized/spectral.js.map +0 -1
  119. package/dist/src/types/embedding.d.ts +0 -9
  120. package/dist/src/types/embedding.js +0 -5
  121. package/dist/src/types/embedding.js.map +0 -1
  122. package/dist/src/types/graph.d.ts +0 -10
  123. package/dist/src/types/graph.js +0 -5
  124. package/dist/src/types/graph.js.map +0 -1
  125. package/dist/src/types/index.d.ts +0 -6
  126. package/dist/src/types/index.js +0 -7
  127. package/dist/src/types/index.js.map +0 -1
  128. package/dist/src/types/layout.d.ts +0 -6
  129. package/dist/src/types/layout.js +0 -5
  130. package/dist/src/types/layout.js.map +0 -1
  131. package/dist/src/utils/graph.d.ts +0 -34
  132. package/dist/src/utils/graph.js +0 -69
  133. package/dist/src/utils/graph.js.map +0 -1
  134. package/dist/src/utils/index.d.ts +0 -8
  135. package/dist/src/utils/index.js +0 -9
  136. package/dist/src/utils/index.js.map +0 -1
  137. package/dist/src/utils/numpy.d.ts +0 -17
  138. package/dist/src/utils/numpy.js +0 -101
  139. package/dist/src/utils/numpy.js.map +0 -1
  140. package/dist/src/utils/params.d.ts +0 -17
  141. package/dist/src/utils/params.js +0 -22
  142. package/dist/src/utils/params.js.map +0 -1
  143. package/dist/src/utils/random.d.ts +0 -14
  144. package/dist/src/utils/random.js +0 -42
  145. package/dist/src/utils/random.js.map +0 -1
  146. package/dist/src/utils/rescale.d.ts +0 -21
  147. package/dist/src/utils/rescale.js +0 -194
  148. package/dist/src/utils/rescale.js.map +0 -1
  149. package/dist/vitest.config.d.ts +0 -2
  150. package/dist/vitest.config.js +0 -30
  151. package/dist/vitest.config.js.map +0 -1
package/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
  [![Coverage Status](https://coveralls.io/repos/github/graphty-org/layout/badge.svg?branch=main)](https://coveralls.io/github/graphty-org/layout?branch=main)
5
5
  [![npm version](https://badge.fury.io/js/%40graphty%2Flayout.svg)](https://badge.fury.io/js/%40graphty%2Flayout)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![GitHub Pages](https://img.shields.io/badge/demo-github%20pages-blue)](https://graphty-org.github.io/layout/examples/index.html)
7
8
 
8
9
  **[View Interactive Examples →](https://graphty-org.github.io/layout/examples/index.html)**
9
10
 
@@ -50,6 +51,12 @@ Additionally, the library includes:
50
51
  - **combineLayouts** - Blend multiple layout algorithms
51
52
  - **interpolateLayouts** - Smooth animation between layouts
52
53
 
54
+ ## Installation
55
+
56
+ ```bash
57
+ npm install @graphty/layout
58
+ ```
59
+
53
60
  ## How to Use
54
61
 
55
62
  Import the library in your TypeScript/JavaScript project:
@@ -90,7 +97,7 @@ import {
90
97
  layoutQuality,
91
98
  combineLayouts,
92
99
  interpolateLayouts
93
- } from './layout.js'
100
+ } from '@graphty/layout'
94
101
  ```
95
102
 
96
103
  ## Quick Start
@@ -475,12 +482,30 @@ if (detected) {
475
482
  }
476
483
  ```
477
484
 
485
+ ## 3D Support
486
+
487
+ All layout algorithms support 3D positioning by setting the `dim` parameter to 3:
488
+
489
+ ```typescript
490
+ // Any layout algorithm in 3D
491
+ const positions3D = springLayout(graph, null, null, null, 50, 1, [0, 0, 0], 3)
492
+ // Returns: { node1: [x, y, z], node2: [x, y, z], ... }
493
+
494
+ // ForceAtlas2 in 3D
495
+ const fa3D = forceatlas2Layout(graph, null, 100, 1, 2, 1, false, false, null, null, null, false, false, 42, 3)
496
+
497
+ // Circular layout in 3D (creates a sphere)
498
+ const circular3D = circularLayout(graph, 1, [0, 0, 0], 3)
499
+ ```
500
+
501
+ When using 3D layouts, positions will have three coordinates `[x, y, z]` instead of two.
502
+
478
503
  ## Common Parameters
479
504
 
480
505
  Most layout functions share these parameters:
481
506
 
482
507
  - **scale** (number): Scale factor for positions (default: 1)
483
- - **center** (number[]): Center coordinates around which to center the layout (default: [0, 0])
508
+ - **center** (number[]): Center coordinates around which to center the layout (default: [0, 0] for 2D, [0, 0, 0] for 3D)
484
509
  - **dim** (number): Layout dimension - 2D or 3D (default: 2)
485
510
  - **seed** (number): Seed for random generation (for reproducible layouts)
486
511
 
@@ -721,7 +746,26 @@ const positions = forceatlas2Layout(
721
746
  true, // dissuadeHubs: good for scale-free
722
747
  false, // linlog: logarithmic attraction
723
748
  42, // seed
724
- 2 // dim
749
+ 2 // dim: 2 for 2D, 3 for 3D
750
+ )
751
+
752
+ // 3D layout example
753
+ const positions3D = forceatlas2Layout(
754
+ graph,
755
+ null,
756
+ 100,
757
+ 1.0,
758
+ 2.0,
759
+ 1.0,
760
+ false,
761
+ false,
762
+ null,
763
+ null,
764
+ null,
765
+ false,
766
+ false,
767
+ 42,
768
+ 3 // 3D mode - returns [x, y, z] coordinates
725
769
  )
726
770
  ```
727
771
 
@@ -1042,6 +1086,68 @@ The module includes complete implementations of:
1042
1086
  }
1043
1087
  ```
1044
1088
 
1089
+ ## Development
1090
+
1091
+ ### Building the Project
1092
+
1093
+ The project uses a unified build system:
1094
+
1095
+ ```bash
1096
+ # Build TypeScript to JavaScript
1097
+ npm run build
1098
+
1099
+ # Build the bundled ES module (dist/layout.js)
1100
+ npm run build:bundle
1101
+
1102
+ # Build everything
1103
+ npm run build:all
1104
+ ```
1105
+
1106
+ ### Running Examples Locally
1107
+
1108
+ ```bash
1109
+ # Start development server with examples
1110
+ npm run examples
1111
+ # or
1112
+ npm run serve
1113
+ ```
1114
+
1115
+ This will:
1116
+ 1. Build the bundled `dist/layout.js`
1117
+ 2. Start a Vite dev server at http://localhost:3000
1118
+ 3. Automatically redirect imports to use the bundled version
1119
+
1120
+ ### Building for GitHub Pages
1121
+
1122
+ To build a static site for GitHub Pages deployment:
1123
+
1124
+ ```bash
1125
+ # Build static site in gh-pages/ directory
1126
+ npm run build:gh-pages
1127
+ ```
1128
+
1129
+ This creates a `gh-pages/` directory with:
1130
+ - All example HTML files
1131
+ - The bundled `layout.js`
1132
+ - All necessary assets
1133
+
1134
+ To deploy to GitHub Pages, see `gh-pages/DEPLOY.md` after building.
1135
+
1136
+ ### Development Workflow
1137
+
1138
+ 1. **Make changes** to TypeScript source files in `src/`
1139
+ 2. **Test locally** with `npm run examples`
1140
+ 3. **Run tests** with `npm test`
1141
+ 4. **Build for production** with `npm run build:all`
1142
+ 5. **Deploy examples** with `npm run build:gh-pages`
1143
+
1144
+ ## Recent Updates
1145
+
1146
+ ### Version 1.2.7 (Latest)
1147
+ - **Fixed**: ForceAtlas2 now correctly returns numeric Z coordinates in 3D mode (previously returned NaN)
1148
+ - **Fixed**: NPM package now uses the correct bundled entry point (`dist/layout.js`)
1149
+ - **Added**: Full 3D support documentation and examples
1150
+
1045
1151
  ## Contributing
1046
1152
 
1047
1153
  This project is a TypeScript port of the NetworkX Python library. For contributions and issues, visit the [GitHub repository](https://github.com/graphty-org/layout).