@graphty/layout 1.2.6 → 1.2.8

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 (150) hide show
  1. package/README.md +55 -5
  2. package/dist/layout.d.ts +17 -0
  3. package/dist/src/algorithms/index.d.ts +5 -0
  4. package/dist/src/algorithms/index.js +6 -0
  5. package/dist/src/algorithms/index.js.map +1 -0
  6. package/dist/src/algorithms/optimization/index.d.ts +7 -0
  7. package/dist/src/algorithms/optimization/index.js +7 -0
  8. package/dist/src/algorithms/optimization/index.js.map +1 -0
  9. package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts +32 -0
  10. package/dist/src/algorithms/optimization/kamada-kawai-solver.js +176 -0
  11. package/dist/src/algorithms/optimization/kamada-kawai-solver.js.map +1 -0
  12. package/dist/src/algorithms/optimization/lbfgs.d.ts +13 -0
  13. package/dist/src/algorithms/optimization/lbfgs.js +56 -0
  14. package/dist/src/algorithms/optimization/lbfgs.js.map +1 -0
  15. package/dist/src/algorithms/optimization/line-search.d.ts +15 -0
  16. package/dist/src/algorithms/optimization/line-search.js +37 -0
  17. package/dist/src/algorithms/optimization/line-search.js.map +1 -0
  18. package/dist/src/algorithms/optimization/types.d.ts +5 -0
  19. package/dist/src/algorithms/optimization/types.js +5 -0
  20. package/dist/src/algorithms/optimization/types.js.map +1 -0
  21. package/dist/src/algorithms/planarity/check.d.ts +17 -0
  22. package/dist/src/algorithms/planarity/check.js +30 -0
  23. package/dist/src/algorithms/planarity/check.js.map +1 -0
  24. package/dist/src/algorithms/planarity/embedding.d.ts +29 -0
  25. package/dist/src/algorithms/planarity/embedding.js +179 -0
  26. package/dist/src/algorithms/planarity/embedding.js.map +1 -0
  27. package/dist/src/algorithms/planarity/index.d.ts +7 -0
  28. package/dist/src/algorithms/planarity/index.js +8 -0
  29. package/dist/src/algorithms/planarity/index.js.map +1 -0
  30. package/dist/src/algorithms/planarity/lr-test.d.ts +15 -0
  31. package/dist/src/algorithms/planarity/lr-test.js +54 -0
  32. package/dist/src/algorithms/planarity/lr-test.js.map +1 -0
  33. package/dist/src/algorithms/planarity/special-graphs.d.ts +28 -0
  34. package/dist/src/algorithms/planarity/special-graphs.js +108 -0
  35. package/dist/src/algorithms/planarity/special-graphs.js.map +1 -0
  36. package/dist/src/generators/basic.d.ts +28 -0
  37. package/dist/src/generators/basic.js +79 -0
  38. package/dist/src/generators/basic.js.map +1 -0
  39. package/dist/src/generators/bipartite.d.ts +16 -0
  40. package/dist/src/generators/bipartite.js +40 -0
  41. package/dist/src/generators/bipartite.js.map +1 -0
  42. package/dist/src/generators/grid.d.ts +11 -0
  43. package/dist/src/generators/grid.js +37 -0
  44. package/dist/src/generators/grid.js.map +1 -0
  45. package/dist/src/generators/index.d.ts +8 -0
  46. package/dist/src/generators/index.js +9 -0
  47. package/dist/src/generators/index.js.map +1 -0
  48. package/dist/src/generators/random.d.ts +12 -0
  49. package/dist/src/generators/random.js +34 -0
  50. package/dist/src/generators/random.js.map +1 -0
  51. package/dist/src/generators/scale-free.d.ts +12 -0
  52. package/dist/src/generators/scale-free.js +62 -0
  53. package/dist/src/generators/scale-free.js.map +1 -0
  54. package/dist/src/index.d.ts +10 -0
  55. package/dist/src/index.js +15 -0
  56. package/dist/src/index.js.map +1 -0
  57. package/dist/src/layouts/basic/index.d.ts +4 -0
  58. package/dist/src/layouts/basic/index.js +5 -0
  59. package/dist/src/layouts/basic/index.js.map +1 -0
  60. package/dist/src/layouts/basic/random.d.ts +14 -0
  61. package/dist/src/layouts/basic/random.js +27 -0
  62. package/dist/src/layouts/basic/random.js.map +1 -0
  63. package/dist/src/layouts/force-directed/arf.d.ts +13 -0
  64. package/dist/src/layouts/force-directed/arf.js +103 -0
  65. package/dist/src/layouts/force-directed/arf.js.map +1 -0
  66. package/dist/src/layouts/force-directed/forceatlas2.d.ts +22 -0
  67. package/dist/src/layouts/force-directed/forceatlas2.js +340 -0
  68. package/dist/src/layouts/force-directed/forceatlas2.js.map +1 -0
  69. package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts +19 -0
  70. package/dist/src/layouts/force-directed/fruchterman-reingold.js +131 -0
  71. package/dist/src/layouts/force-directed/fruchterman-reingold.js.map +1 -0
  72. package/dist/src/layouts/force-directed/index.d.ts +8 -0
  73. package/dist/src/layouts/force-directed/index.js +9 -0
  74. package/dist/src/layouts/force-directed/index.js.map +1 -0
  75. package/dist/src/layouts/force-directed/kamada-kawai.d.ts +15 -0
  76. package/dist/src/layouts/force-directed/kamada-kawai.js +87 -0
  77. package/dist/src/layouts/force-directed/kamada-kawai.js.map +1 -0
  78. package/dist/src/layouts/force-directed/spring.d.ts +19 -0
  79. package/dist/src/layouts/force-directed/spring.js +23 -0
  80. package/dist/src/layouts/force-directed/spring.js.map +1 -0
  81. package/dist/src/layouts/geometric/circular.d.ts +14 -0
  82. package/dist/src/layouts/geometric/circular.js +67 -0
  83. package/dist/src/layouts/geometric/circular.js.map +1 -0
  84. package/dist/src/layouts/geometric/index.d.ts +6 -0
  85. package/dist/src/layouts/geometric/index.js +7 -0
  86. package/dist/src/layouts/geometric/index.js.map +1 -0
  87. package/dist/src/layouts/geometric/shell.d.ts +15 -0
  88. package/dist/src/layouts/geometric/shell.js +67 -0
  89. package/dist/src/layouts/geometric/shell.js.map +1 -0
  90. package/dist/src/layouts/geometric/spiral.d.ts +16 -0
  91. package/dist/src/layouts/geometric/spiral.js +73 -0
  92. package/dist/src/layouts/geometric/spiral.js.map +1 -0
  93. package/dist/src/layouts/hierarchical/bfs.d.ts +12 -0
  94. package/dist/src/layouts/hierarchical/bfs.js +62 -0
  95. package/dist/src/layouts/hierarchical/bfs.js.map +1 -0
  96. package/dist/src/layouts/hierarchical/bipartite.d.ts +16 -0
  97. package/dist/src/layouts/hierarchical/bipartite.js +72 -0
  98. package/dist/src/layouts/hierarchical/bipartite.js.map +1 -0
  99. package/dist/src/layouts/hierarchical/index.d.ts +6 -0
  100. package/dist/src/layouts/hierarchical/index.js +7 -0
  101. package/dist/src/layouts/hierarchical/index.js.map +1 -0
  102. package/dist/src/layouts/hierarchical/multipartite.d.ts +12 -0
  103. package/dist/src/layouts/hierarchical/multipartite.js +73 -0
  104. package/dist/src/layouts/hierarchical/multipartite.js.map +1 -0
  105. package/dist/src/layouts/index.d.ts +8 -0
  106. package/dist/src/layouts/index.js +9 -0
  107. package/dist/src/layouts/index.js.map +1 -0
  108. package/dist/src/layouts/specialized/index.d.ts +5 -0
  109. package/dist/src/layouts/specialized/index.js +6 -0
  110. package/dist/src/layouts/specialized/index.js.map +1 -0
  111. package/dist/src/layouts/specialized/planar.d.ts +14 -0
  112. package/dist/src/layouts/specialized/planar.js +47 -0
  113. package/dist/src/layouts/specialized/planar.js.map +1 -0
  114. package/dist/src/layouts/specialized/spectral.d.ts +14 -0
  115. package/dist/src/layouts/specialized/spectral.js +106 -0
  116. package/dist/src/layouts/specialized/spectral.js.map +1 -0
  117. package/dist/src/types/embedding.d.ts +9 -0
  118. package/dist/src/types/embedding.js +5 -0
  119. package/dist/src/types/embedding.js.map +1 -0
  120. package/dist/src/types/graph.d.ts +10 -0
  121. package/dist/src/types/graph.js +5 -0
  122. package/dist/src/types/graph.js.map +1 -0
  123. package/dist/src/types/index.d.ts +6 -0
  124. package/dist/src/types/index.js +7 -0
  125. package/dist/src/types/index.js.map +1 -0
  126. package/dist/src/types/layout.d.ts +6 -0
  127. package/dist/src/types/layout.js +5 -0
  128. package/dist/src/types/layout.js.map +1 -0
  129. package/dist/src/utils/graph.d.ts +34 -0
  130. package/dist/src/utils/graph.js +69 -0
  131. package/dist/src/utils/graph.js.map +1 -0
  132. package/dist/src/utils/index.d.ts +8 -0
  133. package/dist/src/utils/index.js +9 -0
  134. package/dist/src/utils/index.js.map +1 -0
  135. package/dist/src/utils/numpy.d.ts +17 -0
  136. package/dist/src/utils/numpy.js +101 -0
  137. package/dist/src/utils/numpy.js.map +1 -0
  138. package/dist/src/utils/params.d.ts +17 -0
  139. package/dist/src/utils/params.js +22 -0
  140. package/dist/src/utils/params.js.map +1 -0
  141. package/dist/src/utils/random.d.ts +14 -0
  142. package/dist/src/utils/random.js +42 -0
  143. package/dist/src/utils/random.js.map +1 -0
  144. package/dist/src/utils/rescale.d.ts +21 -0
  145. package/dist/src/utils/rescale.js +194 -0
  146. package/dist/src/utils/rescale.js.map +1 -0
  147. package/dist/vitest.config.d.ts +2 -0
  148. package/dist/vitest.config.js +30 -0
  149. package/dist/vitest.config.js.map +1 -0
  150. package/package.json +5 -5
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Re-export all graph generation functions
3
+ */
4
+ export { completeGraph, cycleGraph, starGraph, wheelGraph } from './basic';
5
+ export { gridGraph } from './grid';
6
+ export { randomGraph } from './random';
7
+ export { bipartiteGraph } from './bipartite';
8
+ export { scaleFreeGraph } from './scale-free';
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Re-export all graph generation functions
3
+ */
4
+ export { completeGraph, cycleGraph, starGraph, wheelGraph } from './basic';
5
+ export { gridGraph } from './grid';
6
+ export { randomGraph } from './random';
7
+ export { bipartiteGraph } from './bipartite';
8
+ export { scaleFreeGraph } from './scale-free';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/generators/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,EACX,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Random graph generation function
3
+ */
4
+ import { Graph } from '../types';
5
+ /**
6
+ * Create a random graph with n nodes and given edge probability
7
+ * @param n - Number of nodes
8
+ * @param p - Probability of edge between any two nodes (0-1)
9
+ * @param seed - Random seed for reproducibility
10
+ * @returns Graph object with random edges
11
+ */
12
+ export declare function randomGraph(n: number, p: number, seed?: number): Graph;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Random graph generation function
3
+ */
4
+ /**
5
+ * Create a random graph with n nodes and given edge probability
6
+ * @param n - Number of nodes
7
+ * @param p - Probability of edge between any two nodes (0-1)
8
+ * @param seed - Random seed for reproducibility
9
+ * @returns Graph object with random edges
10
+ */
11
+ export function randomGraph(n, p, seed) {
12
+ const nodes = Array.from({ length: n }, (_, i) => i);
13
+ const edges = [];
14
+ // Simple deterministic pseudo-random if seed provided
15
+ let currentSeed = seed;
16
+ let random = seed !== undefined
17
+ ? () => {
18
+ currentSeed = (currentSeed * 9301 + 49297) % 233280;
19
+ return currentSeed / 233280;
20
+ }
21
+ : Math.random;
22
+ for (let i = 0; i < n; i++) {
23
+ for (let j = i + 1; j < n; j++) {
24
+ if (random() < p) {
25
+ edges.push([i, j]);
26
+ }
27
+ }
28
+ }
29
+ return {
30
+ nodes: () => nodes,
31
+ edges: () => edges
32
+ };
33
+ }
34
+ //# sourceMappingURL=random.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.js","sourceRoot":"","sources":["../../../src/generators/random.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,IAAa;IAC7D,MAAM,KAAK,GAAW,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAW,EAAE,CAAC;IAEzB,sDAAsD;IACtD,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,MAAM,GAAG,IAAI,KAAK,SAAS;QAC7B,CAAC,CAAC,GAAG,EAAE;YACH,WAAW,GAAG,CAAC,WAAY,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,MAAM,CAAC;YACrD,OAAO,WAAW,GAAG,MAAM,CAAC;QAC9B,CAAC;QACH,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/B,IAAI,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;gBACjB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK;QAClB,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Scale-free graph generation function
3
+ */
4
+ import { Graph } from '../types';
5
+ /**
6
+ * Create a scale-free graph using Barabási-Albert model
7
+ * @param n - Total number of nodes
8
+ * @param m - Number of edges to attach from new node
9
+ * @param seed - Random seed for reproducibility
10
+ * @returns Graph object with scale-free properties
11
+ */
12
+ export declare function scaleFreeGraph(n: number, m: number, seed?: number): Graph;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Scale-free graph generation function
3
+ */
4
+ /**
5
+ * Create a scale-free graph using Barabási-Albert model
6
+ * @param n - Total number of nodes
7
+ * @param m - Number of edges to attach from new node
8
+ * @param seed - Random seed for reproducibility
9
+ * @returns Graph object with scale-free properties
10
+ */
11
+ export function scaleFreeGraph(n, m, seed) {
12
+ if (m >= n) {
13
+ throw new Error('m must be less than n');
14
+ }
15
+ const nodes = Array.from({ length: n }, (_, i) => i);
16
+ const edges = [];
17
+ const degrees = new Array(n).fill(0);
18
+ // Simple deterministic pseudo-random if seed provided
19
+ let currentSeed = seed;
20
+ let random = seed !== undefined
21
+ ? () => {
22
+ currentSeed = (currentSeed * 9301 + 49297) % 233280;
23
+ return currentSeed / 233280;
24
+ }
25
+ : Math.random;
26
+ // Start with complete graph of m+1 nodes
27
+ for (let i = 0; i <= m; i++) {
28
+ for (let j = i + 1; j <= m; j++) {
29
+ edges.push([i, j]);
30
+ degrees[i]++;
31
+ degrees[j]++;
32
+ }
33
+ }
34
+ // Add remaining nodes
35
+ for (let i = m + 1; i < n; i++) {
36
+ const targets = new Set();
37
+ const totalDegree = degrees.reduce((sum, d) => sum + d, 0);
38
+ // Choose m targets based on preferential attachment
39
+ while (targets.size < m) {
40
+ let r = random() * totalDegree;
41
+ let cumSum = 0;
42
+ for (let j = 0; j < i; j++) {
43
+ cumSum += degrees[j];
44
+ if (r <= cumSum && !targets.has(j)) {
45
+ targets.add(j);
46
+ break;
47
+ }
48
+ }
49
+ }
50
+ // Add edges to targets
51
+ for (const target of targets) {
52
+ edges.push([i, target]);
53
+ degrees[i]++;
54
+ degrees[target]++;
55
+ }
56
+ }
57
+ return {
58
+ nodes: () => nodes,
59
+ edges: () => edges
60
+ };
61
+ }
62
+ //# sourceMappingURL=scale-free.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale-free.js","sourceRoot":"","sources":["../../../src/generators/scale-free.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,CAAS,EAAE,CAAS,EAAE,IAAa;IAChE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,KAAK,GAAW,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7D,MAAM,KAAK,GAAW,EAAE,CAAC;I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AAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC3B,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;gBACrB,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBACf,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,uBAAuB;QACvB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YACxB,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;YACb,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK;QAClB,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Main entry point for @graphty/layout
3
+ *
4
+ * This file exports the complete public API, maintaining
5
+ * compatibility with the original layout.ts file.
6
+ */
7
+ export * from './types';
8
+ export { rescaleLayout, rescaleLayoutDict } from './utils/rescale';
9
+ export * from './layouts';
10
+ export * from './generators';
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Main entry point for @graphty/layout
3
+ *
4
+ * This file exports the complete public API, maintaining
5
+ * compatibility with the original layout.ts file.
6
+ */
7
+ // Re-export all types
8
+ export * from './types';
9
+ // Re-export utilities that are part of the public API
10
+ export { rescaleLayout, rescaleLayoutDict } from './utils/rescale';
11
+ // Re-export all layout algorithms
12
+ export * from './layouts';
13
+ // Re-export all graph generation functions
14
+ export * from './generators';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,sBAAsB;AACtB,cAAc,SAAS,CAAC;AAExB,sDAAsD;AACtD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEnE,kCAAkC;AAClC,cAAc,WAAW,CAAC;AAE1B,2CAA2C;AAC3C,cAAc,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Basic layout algorithms
3
+ */
4
+ export { randomLayout } from './random';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Basic layout algorithms
3
+ */
4
+ export { randomLayout } from './random';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layouts/basic/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Random layout algorithm
3
+ */
4
+ import { Graph, Node, PositionMap } from '../../types';
5
+ /**
6
+ * Position nodes uniformly at random in the unit square.
7
+ *
8
+ * @param G - Graph or list of nodes
9
+ * @param center - Coordinate pair around which to center the layout
10
+ * @param dim - Dimension of layout
11
+ * @param seed - Random seed for reproducible layouts
12
+ * @returns Positions dictionary keyed by node
13
+ */
14
+ export declare function randomLayout(G: Graph | Node[], center?: number[] | null, dim?: number, seed?: number | null): PositionMap;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Random layout algorithm
3
+ */
4
+ import { _processParams } from '../../utils/params';
5
+ import { getNodesFromGraph } from '../../utils/graph';
6
+ import { RandomNumberGenerator } from '../../utils/random';
7
+ /**
8
+ * Position nodes uniformly at random in the unit square.
9
+ *
10
+ * @param G - Graph or list of nodes
11
+ * @param center - Coordinate pair around which to center the layout
12
+ * @param dim - Dimension of layout
13
+ * @param seed - Random seed for reproducible layouts
14
+ * @returns Positions dictionary keyed by node
15
+ */
16
+ export function randomLayout(G, center = null, dim = 2, seed = null) {
17
+ const processed = _processParams(G, center, dim);
18
+ const nodes = getNodesFromGraph(processed.G);
19
+ center = processed.center;
20
+ const rng = new RandomNumberGenerator(seed ?? undefined);
21
+ const pos = {};
22
+ nodes.forEach((node) => {
23
+ pos[node] = rng.rand(dim).map((val, i) => val + center[i]);
24
+ });
25
+ return pos;
26
+ }
27
+ //# sourceMappingURL=random.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../src/layouts/basic/random.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,CAAiB,EAAE,SAA0B,IAAI,EAAE,MAAc,CAAC,EAAE,OAAsB,IAAI;IACzH,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC7C,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAE1B,MAAM,GAAG,GAAG,IAAI,qBAAqB,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC;IACzD,MAAM,GAAG,GAAgB,EAAE,CAAC;IAE5B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,EAAE;QAC3B,GAAG,CAAC,IAAI,CAAC,GAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAc,CAAC,GAAG,CAAC,CAAC,GAAW,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3F,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Graph, PositionMap } from '../../types';
2
+ /**
3
+ * Layout algorithm with attractive and repulsive forces (ARF).
4
+ *
5
+ * @param G - Graph
6
+ * @param pos - Initial positions for nodes
7
+ * @param scaling - Scale factor for positions
8
+ * @param a - Strength of springs between connected nodes (should be > 1)
9
+ * @param maxIter - Maximum number of iterations
10
+ * @param seed - Random seed for initial positions
11
+ * @returns Positions dictionary keyed by node
12
+ */
13
+ export declare function arfLayout(G: Graph, pos?: PositionMap | null, scaling?: number, a?: number, maxIter?: number, seed?: number | null): PositionMap;
@@ -0,0 +1,103 @@
1
+ import { getNodesFromGraph, getEdgesFromGraph } from '../../utils/graph';
2
+ import { RandomNumberGenerator } from '../../utils/random';
3
+ import { randomLayout } from '../basic/random';
4
+ /**
5
+ * Layout algorithm with attractive and repulsive forces (ARF).
6
+ *
7
+ * @param G - Graph
8
+ * @param pos - Initial positions for nodes
9
+ * @param scaling - Scale factor for positions
10
+ * @param a - Strength of springs between connected nodes (should be > 1)
11
+ * @param maxIter - Maximum number of iterations
12
+ * @param seed - Random seed for initial positions
13
+ * @returns Positions dictionary keyed by node
14
+ */
15
+ export function arfLayout(G, pos = null, scaling = 1, a = 1.1, maxIter = 1000, seed = null) {
16
+ if (a <= 1) {
17
+ throw new Error("The parameter a should be larger than 1");
18
+ }
19
+ const nodes = getNodesFromGraph(G);
20
+ const edges = getEdgesFromGraph(G);
21
+ if (nodes.length === 0) {
22
+ return {};
23
+ }
24
+ // Initialize positions if not provided
25
+ if (!pos) {
26
+ pos = randomLayout(G, null, 2, seed);
27
+ }
28
+ else {
29
+ // Make sure all nodes have positions
30
+ const rng = new RandomNumberGenerator(seed ?? undefined);
31
+ const defaultPos = {};
32
+ nodes.forEach((node) => {
33
+ if (!pos[node]) {
34
+ defaultPos[node] = [rng.rand(), rng.rand()];
35
+ }
36
+ });
37
+ pos = { ...pos, ...defaultPos };
38
+ }
39
+ // Create node index mapping
40
+ const nodeIndex = {};
41
+ nodes.forEach((node, i) => {
42
+ nodeIndex[node] = i;
43
+ });
44
+ // Create positions array
45
+ const positions = nodes.map((node) => [...pos[node]]);
46
+ // Initialize spring constant matrix
47
+ const N = nodes.length;
48
+ const K = Array(N).fill(0).map(() => Array(N).fill(1));
49
+ // Set diagonal to zero (no self-attraction)
50
+ for (let i = 0; i < N; i++) {
51
+ K[i][i] = 0;
52
+ }
53
+ // Set stronger attraction between connected nodes
54
+ for (const [source, target] of edges) {
55
+ if (source === target)
56
+ continue;
57
+ const i = nodeIndex[source];
58
+ const j = nodeIndex[target];
59
+ K[i][j] = a;
60
+ K[j][i] = a;
61
+ }
62
+ // Calculate rho (scale factor)
63
+ const rho = scaling * Math.sqrt(N);
64
+ // Optimization loop
65
+ const dt = 1e-3; // Time step
66
+ const etol = 1e-6; // Error tolerance
67
+ let error = etol + 1;
68
+ let nIter = 0;
69
+ while (error > etol && nIter < maxIter) {
70
+ // Calculate changes for each node
71
+ const change = Array(N).fill(0).map(() => [0, 0]);
72
+ for (let i = 0; i < N; i++) {
73
+ for (let j = 0; j < N; j++) {
74
+ if (i === j)
75
+ continue;
76
+ // Calculate difference vector
77
+ const diff = positions[i].map((coord, dim) => coord - positions[j][dim]);
78
+ // Calculate distance (with minimum to avoid division by zero)
79
+ const dist = Math.sqrt(diff.reduce((sum, d) => sum + d * d, 0)) || 0.01;
80
+ // Calculate attractive and repulsive forces
81
+ for (let d = 0; d < diff.length; d++) {
82
+ change[i][d] += K[i][j] * diff[d] - (rho / dist) * diff[d];
83
+ }
84
+ }
85
+ }
86
+ // Update positions
87
+ for (let i = 0; i < N; i++) {
88
+ for (let d = 0; d < positions[i].length; d++) {
89
+ positions[i][d] += change[i][d] * dt;
90
+ }
91
+ }
92
+ // Calculate error (sum of force magnitudes)
93
+ error = change.reduce((sum, c) => sum + Math.sqrt(c.reduce((s, v) => s + v * v, 0)), 0);
94
+ nIter++;
95
+ }
96
+ // Convert positions array back to object
97
+ const finalPos = {};
98
+ nodes.forEach((node, i) => {
99
+ finalPos[node] = positions[i];
100
+ });
101
+ return finalPos;
102
+ }
103
+ //# sourceMappingURL=arf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arf.js","sourceRoot":"","sources":["../../../../src/layouts/force-directed/arf.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CACvB,CAAQ,EACR,MAA0B,IAAI,EAC9B,UAAkB,CAAC,EACnB,IAAY,GAAG,EACf,UAAkB,IAAI,EACtB,OAAsB,IAAI;IAE1B,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAEnC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,uCAAuC;IACvC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACN,qCAAqC;QACrC,MAAM,GAAG,GAAG,IAAI,qBAAqB,CAAC,IAAI,IAAI,SAAS,CAAC,CAAC;QACzD,MAAM,UAAU,GAAgB,EAAE,CAAC;QACnC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,EAAE;YAC3B,IAAI,CAAC,GAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChB,UAAU,CAAC,IAAI,CAAC,G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C,CAAC,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Graph, Node, PositionMap } from '../../types';
2
+ /**
3
+ * Position nodes using the ForceAtlas2 force-directed algorithm.
4
+ *
5
+ * @param G - Graph
6
+ * @param pos - Initial positions for nodes
7
+ * @param maxIter - Maximum number of iterations
8
+ * @param jitterTolerance - Controls tolerance for node speed adjustments
9
+ * @param scalingRatio - Scaling of attraction and repulsion forces
10
+ * @param gravity - Attraction to center to prevent disconnected components from drifting
11
+ * @param distributedAction - Distributes attraction force among nodes
12
+ * @param strongGravity - Uses a stronger gravity model
13
+ * @param nodeMass - Dictionary mapping nodes to their masses
14
+ * @param nodeSize - Dictionary mapping nodes to their sizes
15
+ * @param weight - Edge attribute for weight
16
+ * @param dissuadeHubs - Whether to prevent hub nodes from clustering
17
+ * @param linlog - Whether to use logarithmic attraction
18
+ * @param seed - Random seed for initial positions
19
+ * @param dim - Dimension of layout
20
+ * @returns Positions dictionary keyed by node
21
+ */
22
+ export declare function forceatlas2Layout(G: Graph, pos?: PositionMap | null, maxIter?: number, jitterTolerance?: number, scalingRatio?: number, gravity?: number, distributedAction?: boolean, strongGravity?: boolean, nodeMass?: Record<Node, number> | null, nodeSize?: Record<Node, number> | null, weight?: string | null, dissuadeHubs?: boolean, linlog?: boolean, seed?: number | null, dim?: number): PositionMap;