@graphty/layout 1.2.4 → 1.2.6

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 (153) hide show
  1. package/README.md +57 -1
  2. package/dist/layout.js +1762 -0
  3. package/dist/layout.js.map +1 -0
  4. package/package.json +7 -4
  5. package/src/layouts/force-directed/forceatlas2.ts +23 -4
  6. package/src/utils/rescale.ts +90 -15
  7. package/dist/src/algorithms/index.d.ts +0 -5
  8. package/dist/src/algorithms/index.js +0 -6
  9. package/dist/src/algorithms/index.js.map +0 -1
  10. package/dist/src/algorithms/optimization/index.d.ts +0 -7
  11. package/dist/src/algorithms/optimization/index.js +0 -7
  12. package/dist/src/algorithms/optimization/index.js.map +0 -1
  13. package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts +0 -32
  14. package/dist/src/algorithms/optimization/kamada-kawai-solver.js +0 -176
  15. package/dist/src/algorithms/optimization/kamada-kawai-solver.js.map +0 -1
  16. package/dist/src/algorithms/optimization/lbfgs.d.ts +0 -13
  17. package/dist/src/algorithms/optimization/lbfgs.js +0 -56
  18. package/dist/src/algorithms/optimization/lbfgs.js.map +0 -1
  19. package/dist/src/algorithms/optimization/line-search.d.ts +0 -15
  20. package/dist/src/algorithms/optimization/line-search.js +0 -37
  21. package/dist/src/algorithms/optimization/line-search.js.map +0 -1
  22. package/dist/src/algorithms/optimization/types.d.ts +0 -5
  23. package/dist/src/algorithms/optimization/types.js +0 -5
  24. package/dist/src/algorithms/optimization/types.js.map +0 -1
  25. package/dist/src/algorithms/planarity/check.d.ts +0 -17
  26. package/dist/src/algorithms/planarity/check.js +0 -30
  27. package/dist/src/algorithms/planarity/check.js.map +0 -1
  28. package/dist/src/algorithms/planarity/embedding.d.ts +0 -29
  29. package/dist/src/algorithms/planarity/embedding.js +0 -179
  30. package/dist/src/algorithms/planarity/embedding.js.map +0 -1
  31. package/dist/src/algorithms/planarity/index.d.ts +0 -7
  32. package/dist/src/algorithms/planarity/index.js +0 -8
  33. package/dist/src/algorithms/planarity/index.js.map +0 -1
  34. package/dist/src/algorithms/planarity/lr-test.d.ts +0 -15
  35. package/dist/src/algorithms/planarity/lr-test.js +0 -54
  36. package/dist/src/algorithms/planarity/lr-test.js.map +0 -1
  37. package/dist/src/algorithms/planarity/special-graphs.d.ts +0 -28
  38. package/dist/src/algorithms/planarity/special-graphs.js +0 -108
  39. package/dist/src/algorithms/planarity/special-graphs.js.map +0 -1
  40. package/dist/src/generators/basic.d.ts +0 -28
  41. package/dist/src/generators/basic.js +0 -79
  42. package/dist/src/generators/basic.js.map +0 -1
  43. package/dist/src/generators/bipartite.d.ts +0 -16
  44. package/dist/src/generators/bipartite.js +0 -40
  45. package/dist/src/generators/bipartite.js.map +0 -1
  46. package/dist/src/generators/grid.d.ts +0 -11
  47. package/dist/src/generators/grid.js +0 -37
  48. package/dist/src/generators/grid.js.map +0 -1
  49. package/dist/src/generators/index.d.ts +0 -8
  50. package/dist/src/generators/index.js +0 -9
  51. package/dist/src/generators/index.js.map +0 -1
  52. package/dist/src/generators/random.d.ts +0 -12
  53. package/dist/src/generators/random.js +0 -34
  54. package/dist/src/generators/random.js.map +0 -1
  55. package/dist/src/generators/scale-free.d.ts +0 -12
  56. package/dist/src/generators/scale-free.js +0 -62
  57. package/dist/src/generators/scale-free.js.map +0 -1
  58. package/dist/src/index.d.ts +0 -10
  59. package/dist/src/index.js +0 -15
  60. package/dist/src/index.js.map +0 -1
  61. package/dist/src/layouts/basic/index.d.ts +0 -4
  62. package/dist/src/layouts/basic/index.js +0 -5
  63. package/dist/src/layouts/basic/index.js.map +0 -1
  64. package/dist/src/layouts/basic/random.d.ts +0 -14
  65. package/dist/src/layouts/basic/random.js +0 -27
  66. package/dist/src/layouts/basic/random.js.map +0 -1
  67. package/dist/src/layouts/force-directed/arf.d.ts +0 -13
  68. package/dist/src/layouts/force-directed/arf.js +0 -103
  69. package/dist/src/layouts/force-directed/arf.js.map +0 -1
  70. package/dist/src/layouts/force-directed/forceatlas2.d.ts +0 -22
  71. package/dist/src/layouts/force-directed/forceatlas2.js +0 -322
  72. package/dist/src/layouts/force-directed/forceatlas2.js.map +0 -1
  73. package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts +0 -19
  74. package/dist/src/layouts/force-directed/fruchterman-reingold.js +0 -131
  75. package/dist/src/layouts/force-directed/fruchterman-reingold.js.map +0 -1
  76. package/dist/src/layouts/force-directed/index.d.ts +0 -8
  77. package/dist/src/layouts/force-directed/index.js +0 -9
  78. package/dist/src/layouts/force-directed/index.js.map +0 -1
  79. package/dist/src/layouts/force-directed/kamada-kawai.d.ts +0 -15
  80. package/dist/src/layouts/force-directed/kamada-kawai.js +0 -87
  81. package/dist/src/layouts/force-directed/kamada-kawai.js.map +0 -1
  82. package/dist/src/layouts/force-directed/spring.d.ts +0 -19
  83. package/dist/src/layouts/force-directed/spring.js +0 -23
  84. package/dist/src/layouts/force-directed/spring.js.map +0 -1
  85. package/dist/src/layouts/geometric/circular.d.ts +0 -14
  86. package/dist/src/layouts/geometric/circular.js +0 -67
  87. package/dist/src/layouts/geometric/circular.js.map +0 -1
  88. package/dist/src/layouts/geometric/index.d.ts +0 -6
  89. package/dist/src/layouts/geometric/index.js +0 -7
  90. package/dist/src/layouts/geometric/index.js.map +0 -1
  91. package/dist/src/layouts/geometric/shell.d.ts +0 -15
  92. package/dist/src/layouts/geometric/shell.js +0 -67
  93. package/dist/src/layouts/geometric/shell.js.map +0 -1
  94. package/dist/src/layouts/geometric/spiral.d.ts +0 -16
  95. package/dist/src/layouts/geometric/spiral.js +0 -73
  96. package/dist/src/layouts/geometric/spiral.js.map +0 -1
  97. package/dist/src/layouts/hierarchical/bfs.d.ts +0 -12
  98. package/dist/src/layouts/hierarchical/bfs.js +0 -62
  99. package/dist/src/layouts/hierarchical/bfs.js.map +0 -1
  100. package/dist/src/layouts/hierarchical/bipartite.d.ts +0 -16
  101. package/dist/src/layouts/hierarchical/bipartite.js +0 -72
  102. package/dist/src/layouts/hierarchical/bipartite.js.map +0 -1
  103. package/dist/src/layouts/hierarchical/index.d.ts +0 -6
  104. package/dist/src/layouts/hierarchical/index.js +0 -7
  105. package/dist/src/layouts/hierarchical/index.js.map +0 -1
  106. package/dist/src/layouts/hierarchical/multipartite.d.ts +0 -12
  107. package/dist/src/layouts/hierarchical/multipartite.js +0 -73
  108. package/dist/src/layouts/hierarchical/multipartite.js.map +0 -1
  109. package/dist/src/layouts/index.d.ts +0 -8
  110. package/dist/src/layouts/index.js +0 -9
  111. package/dist/src/layouts/index.js.map +0 -1
  112. package/dist/src/layouts/specialized/index.d.ts +0 -5
  113. package/dist/src/layouts/specialized/index.js +0 -6
  114. package/dist/src/layouts/specialized/index.js.map +0 -1
  115. package/dist/src/layouts/specialized/planar.d.ts +0 -14
  116. package/dist/src/layouts/specialized/planar.js +0 -47
  117. package/dist/src/layouts/specialized/planar.js.map +0 -1
  118. package/dist/src/layouts/specialized/spectral.d.ts +0 -14
  119. package/dist/src/layouts/specialized/spectral.js +0 -106
  120. package/dist/src/layouts/specialized/spectral.js.map +0 -1
  121. package/dist/src/types/embedding.d.ts +0 -9
  122. package/dist/src/types/embedding.js +0 -5
  123. package/dist/src/types/embedding.js.map +0 -1
  124. package/dist/src/types/graph.d.ts +0 -10
  125. package/dist/src/types/graph.js +0 -5
  126. package/dist/src/types/graph.js.map +0 -1
  127. package/dist/src/types/index.d.ts +0 -6
  128. package/dist/src/types/index.js +0 -7
  129. package/dist/src/types/index.js.map +0 -1
  130. package/dist/src/types/layout.d.ts +0 -6
  131. package/dist/src/types/layout.js +0 -5
  132. package/dist/src/types/layout.js.map +0 -1
  133. package/dist/src/utils/graph.d.ts +0 -34
  134. package/dist/src/utils/graph.js +0 -69
  135. package/dist/src/utils/graph.js.map +0 -1
  136. package/dist/src/utils/index.d.ts +0 -8
  137. package/dist/src/utils/index.js +0 -9
  138. package/dist/src/utils/index.js.map +0 -1
  139. package/dist/src/utils/numpy.d.ts +0 -17
  140. package/dist/src/utils/numpy.js +0 -101
  141. package/dist/src/utils/numpy.js.map +0 -1
  142. package/dist/src/utils/params.d.ts +0 -17
  143. package/dist/src/utils/params.js +0 -22
  144. package/dist/src/utils/params.js.map +0 -1
  145. package/dist/src/utils/random.d.ts +0 -14
  146. package/dist/src/utils/random.js +0 -42
  147. package/dist/src/utils/random.js.map +0 -1
  148. package/dist/src/utils/rescale.d.ts +0 -21
  149. package/dist/src/utils/rescale.js +0 -119
  150. package/dist/src/utils/rescale.js.map +0 -1
  151. package/dist/vitest.config.d.ts +0 -2
  152. package/dist/vitest.config.js +0 -30
  153. package/dist/vitest.config.js.map +0 -1
@@ -1,62 +0,0 @@
1
- import { getNodesFromGraph, getNeighbors } from '../../utils/graph';
2
- import { _processParams } from '../../utils/params';
3
- import { multipartiteLayout } from './multipartite';
4
- /**
5
- * Position nodes according to breadth-first search algorithm.
6
- *
7
- * @param G - Graph
8
- * @param start - Starting node for bfs
9
- * @param align - The alignment of layers: 'vertical' or 'horizontal'
10
- * @param scale - Scale factor for positions
11
- * @param center - Coordinate pair around which to center the layout
12
- * @returns Positions dictionary keyed by node
13
- */
14
- export function bfsLayout(G, start, align = 'vertical', scale = 1, center = null) {
15
- const processed = _processParams(G, center || [0, 0], 2);
16
- // BFS layout requires a proper Graph, not just a list of nodes
17
- if (Array.isArray(processed.G)) {
18
- throw new Error('BFS layout requires a Graph with edges, not just a list of nodes');
19
- }
20
- const graph = processed.G;
21
- center = processed.center;
22
- const allNodes = getNodesFromGraph(graph);
23
- if (allNodes.length === 0) {
24
- return {};
25
- }
26
- // Compute BFS layers
27
- const layers = {};
28
- const visited = new Set();
29
- let currentLayer = 0;
30
- // Starting layer
31
- layers[currentLayer] = [start];
32
- visited.add(start);
33
- // BFS traversal
34
- while (Object.values(layers).flat().length < allNodes.length) {
35
- const nextLayer = [];
36
- const currentNodes = layers[currentLayer];
37
- for (const node of currentNodes) {
38
- // Get neighbors - this is a simplified approach
39
- // In a real implementation, we would get neighbors from the graph
40
- const neighbors = getNeighbors(graph, node);
41
- for (const neighbor of neighbors) {
42
- if (!visited.has(neighbor)) {
43
- nextLayer.push(neighbor);
44
- visited.add(neighbor);
45
- }
46
- }
47
- }
48
- if (nextLayer.length === 0) {
49
- // No more connected nodes
50
- const unvisited = allNodes.filter((node) => !visited.has(node));
51
- if (unvisited.length > 0) {
52
- throw new Error("bfs_layout didn't include all nodes. Graph may be disconnected.");
53
- }
54
- break;
55
- }
56
- currentLayer++;
57
- layers[currentLayer] = nextLayer;
58
- }
59
- // Use multipartite_layout to position the layers
60
- return multipartiteLayout(graph, layers, align, scale, center);
61
- }
62
- //# sourceMappingURL=bfs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bfs.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/bfs.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CACvB,CAAQ,EACR,KAAW,EACX,QAAmC,UAAU,EAC7C,QAAgB,CAAC,EACjB,SAA0B,IAAI;IAE9B,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEzD,+DAA+D;IAC/D,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;IAC1B,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAE1B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAE1C,IAAI,QAAQ,CAA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,KAAK,CAAC,iEAAiE,CAAC,CAAC;YACrF,CAAC;YACD,MAAM;QACR,CAAC;QAED,YAAY,EAAE,CAAC;QACf,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IACnC,CAAC;IAED,iDAAiD;IACjD,OAAO,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AACjE,CAAC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Bipartite layout algorithm
3
- */
4
- import { Graph, Node, PositionMap } from '../../types';
5
- /**
6
- * Position nodes in two straight lines (bipartite layout).
7
- *
8
- * @param G - Graph or list of nodes
9
- * @param nodes - Nodes in one node set of the graph
10
- * @param align - The alignment of nodes: 'vertical' or 'horizontal'
11
- * @param scale - Scale factor for positions
12
- * @param center - Coordinate pair around which to center the layout
13
- * @param aspectRatio - The ratio of the width to the height of the layout
14
- * @returns Positions dictionary keyed by node
15
- */
16
- export declare function bipartiteLayout(G: Graph, nodes?: Node[] | null, align?: 'vertical' | 'horizontal', scale?: number, center?: number[] | null, aspectRatio?: number): PositionMap;
@@ -1,72 +0,0 @@
1
- /**
2
- * Bipartite layout algorithm
3
- */
4
- import { _processParams } from '../../utils/params';
5
- import { getNodesFromGraph } from '../../utils/graph';
6
- import { rescaleLayout } from '../../utils/rescale';
7
- /**
8
- * Position nodes in two straight lines (bipartite layout).
9
- *
10
- * @param G - Graph or list of nodes
11
- * @param nodes - Nodes in one node set of the graph
12
- * @param align - The alignment of nodes: 'vertical' or 'horizontal'
13
- * @param scale - Scale factor for positions
14
- * @param center - Coordinate pair around which to center the layout
15
- * @param aspectRatio - The ratio of the width to the height of the layout
16
- * @returns Positions dictionary keyed by node
17
- */
18
- export function bipartiteLayout(G, nodes = null, align = 'vertical', scale = 1, center = null, aspectRatio = 4 / 3) {
19
- if (align !== 'vertical' && align !== 'horizontal') {
20
- throw new Error("align must be either vertical or horizontal");
21
- }
22
- const processed = _processParams(G, center || [0, 0], 2);
23
- const graph = processed.G;
24
- center = processed.center;
25
- const allNodes = getNodesFromGraph(graph);
26
- if (allNodes.length === 0) {
27
- return {};
28
- }
29
- // If nodes not provided, try to determine bipartite sets
30
- if (!nodes) {
31
- // A simple heuristic for bipartite detection: use nodes with even/odd indices
32
- // This is a simplification, in Python NetworkX has bipartite.sets()
33
- nodes = allNodes.filter((_, i) => i % 2 === 0);
34
- }
35
- const left = new Set(nodes);
36
- const right = new Set(allNodes.filter((n) => !left.has(n)));
37
- const height = 1;
38
- const width = aspectRatio * height;
39
- const offset = [width / 2, height / 2];
40
- const pos = {};
41
- // Position nodes in the left set
42
- const leftNodes = [...left];
43
- leftNodes.forEach((node, i) => {
44
- const x = 0;
45
- const y = i * height / (leftNodes.length || 1);
46
- pos[node] = [x, y];
47
- });
48
- // Position nodes in the right set
49
- const rightNodes = [...right];
50
- rightNodes.forEach((node, i) => {
51
- const x = width;
52
- const y = i * height / (rightNodes.length || 1);
53
- pos[node] = [x, y];
54
- });
55
- // Center positions around the origin and apply offset
56
- for (const node in pos) {
57
- pos[node][0] -= offset[0];
58
- pos[node][1] -= offset[1];
59
- }
60
- // Rescale positions
61
- const scaledPos = rescaleLayout(pos, scale, center);
62
- // Handle horizontal alignment
63
- if (align === 'horizontal') {
64
- for (const node in scaledPos) {
65
- const temp = scaledPos[node][0];
66
- scaledPos[node][0] = scaledPos[node][1];
67
- scaledPos[node][1] = temp;
68
- }
69
- }
70
- return scaledPos;
71
- }
72
- //# sourceMappingURL=bipartite.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bipartite.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/bipartite.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;;;;;GAUG;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B,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAChC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Hierarchical layout algorithms
3
- */
4
- export { bipartiteLayout } from './bipartite';
5
- export { multipartiteLayout } from './multipartite';
6
- export { bfsLayout } from './bfs';
@@ -1,7 +0,0 @@
1
- /**
2
- * Hierarchical layout algorithms
3
- */
4
- export { bipartiteLayout } from './bipartite';
5
- export { multipartiteLayout } from './multipartite';
6
- export { bfsLayout } from './bfs';
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC"}
@@ -1,12 +0,0 @@
1
- import type { Graph, Node, PositionMap } from '../../types';
2
- /**
3
- * Position nodes in layers of straight lines (multipartite layout).
4
- *
5
- * @param G - Graph or list of nodes
6
- * @param subsetKey - Object mapping layers to node sets, or node attribute name
7
- * @param align - The alignment of nodes: 'vertical' or 'horizontal'
8
- * @param scale - Scale factor for positions
9
- * @param center - Coordinate pair around which to center the layout
10
- * @returns Positions dictionary keyed by node
11
- */
12
- export declare function multipartiteLayout(G: Graph, subsetKey?: Record<number | string, Node | Node[]> | string, align?: 'vertical' | 'horizontal', scale?: number, center?: number[] | null): PositionMap;
@@ -1,73 +0,0 @@
1
- import { getNodesFromGraph } from '../../utils/graph';
2
- import { _processParams } from '../../utils/params';
3
- import { rescaleLayout } from '../../utils/rescale';
4
- /**
5
- * Position nodes in layers of straight lines (multipartite layout).
6
- *
7
- * @param G - Graph or list of nodes
8
- * @param subsetKey - Object mapping layers to node sets, or node attribute name
9
- * @param align - The alignment of nodes: 'vertical' or 'horizontal'
10
- * @param scale - Scale factor for positions
11
- * @param center - Coordinate pair around which to center the layout
12
- * @returns Positions dictionary keyed by node
13
- */
14
- export function multipartiteLayout(G, subsetKey = 'subset', align = 'vertical', scale = 1, center = null) {
15
- if (align !== 'vertical' && align !== 'horizontal') {
16
- throw new Error("align must be either vertical or horizontal");
17
- }
18
- const processed = _processParams(G, center || [0, 0], 2);
19
- const graph = processed.G;
20
- center = processed.center;
21
- const allNodes = getNodesFromGraph(graph);
22
- if (allNodes.length === 0) {
23
- return {};
24
- }
25
- // Convert subsetKey to a layer mapping if it's a string
26
- let layers = {};
27
- if (typeof subsetKey === 'string') {
28
- // In JS we don't have access to node attributes directly
29
- // This is a simplification - in a real implementation we would need
30
- // to access node attributes from the graph
31
- console.warn("Using string subsetKey requires node attributes, using default partitioning");
32
- // Create a simple partitioning as fallback
33
- layers = { 0: allNodes };
34
- }
35
- else {
36
- // subsetKey is already a mapping of layers to nodes
37
- // Convert single nodes to arrays
38
- for (const [key, value] of Object.entries(subsetKey)) {
39
- if (Array.isArray(value)) {
40
- layers[key] = value;
41
- }
42
- else {
43
- layers[key] = [value];
44
- }
45
- }
46
- }
47
- const layerCount = Object.keys(layers).length;
48
- let pos = {};
49
- // Process each layer
50
- Object.entries(layers).forEach(([layer, nodes], layerIdx) => {
51
- const layerNodes = Array.isArray(nodes) ? nodes : [nodes];
52
- const layerSize = layerNodes.length;
53
- layerNodes.forEach((node, nodeIdx) => {
54
- // Place nodes in a grid: layerIdx determines x-coordinate (column)
55
- // nodeIdx determines y-coordinate (row position within column)
56
- const x = layerIdx - (layerCount - 1) / 2;
57
- const y = nodeIdx - (layerSize - 1) / 2;
58
- pos[node] = [x, y];
59
- });
60
- });
61
- // Rescale positions
62
- pos = rescaleLayout(pos, scale, center);
63
- // Handle horizontal alignment
64
- if (align === 'horizontal') {
65
- for (const node in pos) {
66
- const temp = pos[node][0];
67
- pos[node][0] = pos[node][1];
68
- pos[node][1] = temp;
69
- }
70
- }
71
- return pos;
72
- }
73
- //# sourceMappingURL=multipartite.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multipartite.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/multipartite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAgB,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAChC,CAAQ,EACR,YAA6D,QAAQ,EACrE,QAAmC,UAAU,EAC7C,QAAgB,CAAC,EACjB,SAA0B,IAAI;IAE9B,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACzD,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;IAC1B,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAE1B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAE1C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,wDAAwD;IACxD,IAAI,MAAM,GAAoC,EAAE,CAAC;IACjD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,C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AC,GAAG,CAAC,CAAC;YACxC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,oBAAoB;IACpB,GAAG,GAAG,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAgB,CAAC;IAEvD,8BAA8B;IAC9B,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;QAC3B,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5B,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,8 +0,0 @@
1
- /**
2
- * Re-export all layout algorithms
3
- */
4
- export * from './basic';
5
- export * from './geometric';
6
- export * from './force-directed';
7
- export * from './hierarchical';
8
- export * from './specialized';
@@ -1,9 +0,0 @@
1
- /**
2
- * Re-export all layout algorithms
3
- */
4
- export * from './basic';
5
- export * from './geometric';
6
- export * from './force-directed';
7
- export * from './hierarchical';
8
- export * from './specialized';
9
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/layouts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Specialized layout algorithms
3
- */
4
- export { spectralLayout } from './spectral';
5
- export { planarLayout } from './planar';
@@ -1,6 +0,0 @@
1
- /**
2
- * Specialized layout algorithms
3
- */
4
- export { spectralLayout } from './spectral';
5
- export { planarLayout } from './planar';
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
@@ -1,14 +0,0 @@
1
- /**
2
- * Planar layout algorithm
3
- */
4
- import { Graph, PositionMap } from '../../types';
5
- /**
6
- * Position nodes without edge intersections (planar layout).
7
- *
8
- * @param G - Graph
9
- * @param scale - Scale factor for positions
10
- * @param center - Coordinate pair around which to center the layout
11
- * @param dim - Dimension of layout (must be 2)
12
- * @returns Positions dictionary keyed by node
13
- */
14
- export declare function planarLayout(G: Graph, scale?: number, center?: number[] | null, dim?: number): PositionMap;
@@ -1,47 +0,0 @@
1
- /**
2
- * Planar layout algorithm
3
- */
4
- import { _processParams } from '../../utils/params';
5
- import { getNodesFromGraph, getEdgesFromGraph } from '../../utils/graph';
6
- import { rescaleLayout } from '../../utils/rescale';
7
- import { checkPlanarity, combinatorialEmbeddingToPos } from '../../algorithms/planarity';
8
- /**
9
- * Position nodes without edge intersections (planar layout).
10
- *
11
- * @param G - Graph
12
- * @param scale - Scale factor for positions
13
- * @param center - Coordinate pair around which to center the layout
14
- * @param dim - Dimension of layout (must be 2)
15
- * @returns Positions dictionary keyed by node
16
- */
17
- export function planarLayout(G, scale = 1, center = null, dim = 2) {
18
- if (dim !== 2) {
19
- throw new Error("can only handle 2 dimensions");
20
- }
21
- const processed = _processParams(G, center || [0, 0], dim);
22
- // Planar layout requires a proper Graph, not just a list of nodes
23
- if (Array.isArray(processed.G)) {
24
- throw new Error('Planar layout requires a Graph with edges, not just a list of nodes');
25
- }
26
- const graph = processed.G;
27
- center = processed.center;
28
- const nodes = getNodesFromGraph(graph);
29
- const edges = getEdgesFromGraph(graph);
30
- if (nodes.length === 0) {
31
- return {};
32
- }
33
- // Check if graph is planar and get embedding
34
- const { isPlanar, embedding } = checkPlanarity(graph, nodes, edges);
35
- if (!isPlanar) {
36
- throw new Error("G is not planar.");
37
- }
38
- if (!embedding) {
39
- throw new Error("Failed to generate planar embedding.");
40
- }
41
- // Convert embedding to positions
42
- let pos = combinatorialEmbeddingToPos(embedding, nodes);
43
- // Rescale the positions
44
- pos = rescaleLayout(pos, scale, center);
45
- return pos;
46
- }
47
- //# sourceMappingURL=planar.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"planar.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/planar.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAEzF;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,CAAQ,EACR,QAAgB,CAAC,EACjB,SAA0B,IAAI,EAC9B,MAAc,CAAC;IAEf,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE3D,kEAAkE;IAClE,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACzF,CAAC;IAED,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;IAC1B,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAE1B,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAEvC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,6CAA6C;IAC7C,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAEpE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,iCAAiC;IACjC,IAAI,GAAG,GAAG,2BAA2B,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAExD,wBAAwB;IACxB,GAAG,GAAG,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAgB,CAAC;IAEvD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,14 +0,0 @@
1
- /**
2
- * Spectral layout algorithm using eigenvectors of the graph Laplacian
3
- */
4
- import { Graph, PositionMap } from '../../types';
5
- /**
6
- * Position nodes in a spectral layout using eigenvectors of the graph Laplacian.
7
- *
8
- * @param G - Graph
9
- * @param scale - Scale factor for positions
10
- * @param center - Coordinate pair around which to center the layout
11
- * @param dim - Dimension of layout
12
- * @returns Positions dictionary keyed by node
13
- */
14
- export declare function spectralLayout(G: Graph, scale?: number, center?: number[] | null, dim?: number): PositionMap;
@@ -1,106 +0,0 @@
1
- /**
2
- * Spectral layout algorithm using eigenvectors of the graph Laplacian
3
- */
4
- import { _processParams } from '../../utils/params';
5
- import { getNodesFromGraph, getEdgesFromGraph } from '../../utils/graph';
6
- import { rescaleLayout } from '../../utils/rescale';
7
- /**
8
- * Position nodes in a spectral layout using eigenvectors of the graph Laplacian.
9
- *
10
- * @param G - Graph
11
- * @param scale - Scale factor for positions
12
- * @param center - Coordinate pair around which to center the layout
13
- * @param dim - Dimension of layout
14
- * @returns Positions dictionary keyed by node
15
- */
16
- export function spectralLayout(G, scale = 1, center = null, dim = 2) {
17
- const processed = _processParams(G, center, dim);
18
- const graph = processed.G;
19
- center = processed.center;
20
- const nodes = getNodesFromGraph(graph);
21
- if (nodes.length <= 2) {
22
- if (nodes.length === 0) {
23
- return {};
24
- }
25
- else if (nodes.length === 1) {
26
- return { [nodes[0]]: center };
27
- }
28
- else {
29
- return {
30
- [nodes[0]]: center.map(v => v - scale),
31
- [nodes[1]]: center.map(v => v + scale)
32
- };
33
- }
34
- }
35
- // Create adjacency matrix
36
- const N = nodes.length;
37
- const nodeIndices = {};
38
- nodes.forEach((node, i) => { nodeIndices[node] = i; });
39
- const A = Array(N).fill(0).map(() => Array(N).fill(0));
40
- const edges = getEdgesFromGraph(graph);
41
- for (const [source, target] of edges) {
42
- const i = nodeIndices[source];
43
- const j = nodeIndices[target];
44
- A[i][j] = 1;
45
- A[j][i] = 1; // Make symmetric for undirected graphs
46
- }
47
- // Create Laplacian matrix: L = D - A where D is degree matrix
48
- const L = Array(N).fill(0).map(() => Array(N).fill(0));
49
- for (let i = 0; i < N; i++) {
50
- // Compute degree (sum of row)
51
- L[i][i] = A[i].reduce((sum, val) => sum + val, 0);
52
- for (let j = 0; j < N; j++) {
53
- L[i][j] -= A[i][j];
54
- }
55
- }
56
- // Compute eigenvectors using power iteration method
57
- // We need the smallest non-zero eigenvectors of L
58
- const eigenvectors = [];
59
- // For each dimension, find an eigenvector
60
- for (let d = 0; d < dim; d++) {
61
- let vector = Array(N).fill(0).map(() => Math.random() - 0.5);
62
- // Orthogonalize against previous eigenvectors
63
- for (const ev of eigenvectors) {
64
- const dot = vector.reduce((acc, val, idx) => acc + val * ev[idx], 0);
65
- vector = vector.map((val, idx) => val - dot * ev[idx]);
66
- }
67
- // Normalize
68
- const norm = Math.sqrt(vector.reduce((acc, val) => acc + val * val, 0));
69
- vector = vector.map(val => val / norm);
70
- // Apply shifted inverse iteration to find smallest non-zero eigenvector
71
- // This is a simplification of the actual algorithm
72
- for (let iter = 0; iter < 100; iter++) {
73
- // Apply Laplacian
74
- const newVec = Array(N).fill(0);
75
- for (let i = 0; i < N; i++) {
76
- for (let j = 0; j < N; j++) {
77
- newVec[i] += L[i][j] * vector[j];
78
- }
79
- }
80
- // Orthogonalize against the constant vector (eigenvector with eigenvalue 0)
81
- const mean = newVec.reduce((acc, val) => acc + val, 0) / N;
82
- newVec.forEach((val, idx, arr) => { arr[idx] = val - mean; });
83
- // Normalize
84
- const newNorm = Math.sqrt(newVec.reduce((acc, val) => acc + val * val, 0));
85
- if (newNorm < 1e-10)
86
- continue; // Skip if vector is close to zero
87
- vector = newVec.map(val => val / newNorm);
88
- }
89
- eigenvectors.push(vector);
90
- }
91
- // Create position array from eigenvectors
92
- const positions = Array(N).fill(0).map(() => Array(dim).fill(0));
93
- for (let i = 0; i < N; i++) {
94
- for (let d = 0; d < dim; d++) {
95
- positions[i][d] = eigenvectors[d][i];
96
- }
97
- }
98
- // Rescale and create position dictionary
99
- const scaledPositions = rescaleLayout(positions, scale);
100
- const pos = {};
101
- nodes.forEach((node, i) => {
102
- pos[node] = scaledPositions[i].map((val, j) => val + center[j]);
103
- });
104
- return pos;
105
- }
106
- //# sourceMappingURL=spectral.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spectral.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/spectral.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,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C,CAAC,CAAC,CAAC;IAC7E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IAED,yCAAyC;IACzC,MAAM,eAAe,GAAG,aAAa,CAAC,SAAgB,EAAE,KAAK,CAAC,CAAC;IAC/D,MAAM,GAAG,GAAgB,EAAE,CAAC;IAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,CAAS,EAAE,EAAE;QACtC,GAAG,CAAC,IAAI,CAAC,GAAI,eAA8B,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAW,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAClG,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Embedding type for planar layout algorithms
3
- */
4
- import { Node, Position } from './index';
5
- export interface Embedding {
6
- nodeOrder: Node[];
7
- faceList: Node[][];
8
- nodePositions: Record<Node, Position>;
9
- }
@@ -1,5 +0,0 @@
1
- /**
2
- * Embedding type for planar layout algorithms
3
- */
4
- export {};
5
- //# sourceMappingURL=embedding.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"embedding.js","sourceRoot":"","sources":["../../../src/types/embedding.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -1,10 +0,0 @@
1
- /**
2
- * Core graph type definitions
3
- */
4
- export type Node = string | number;
5
- export type Edge = [Node, Node];
6
- export type Graph = {
7
- nodes: () => Node[];
8
- edges: () => Edge[];
9
- getEdgeData?: (source: Node, target: Node, attr: string) => any;
10
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * Core graph type definitions
3
- */
4
- export {};
5
- //# sourceMappingURL=graph.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../../src/types/graph.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Re-export all type definitions
3
- */
4
- export * from './graph';
5
- export * from './layout';
6
- export * from './embedding';
@@ -1,7 +0,0 @@
1
- /**
2
- * Re-export all type definitions
3
- */
4
- export * from './graph';
5
- export * from './layout';
6
- export * from './embedding';
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Layout-specific type definitions
3
- */
4
- import { Node } from './graph';
5
- export type Position = number[];
6
- export type PositionMap = Record<Node, Position>;
@@ -1,5 +0,0 @@
1
- /**
2
- * Layout-specific type definitions
3
- */
4
- export {};
5
- //# sourceMappingURL=layout.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"layout.js","sourceRoot":"","sources":["../../../src/types/layout.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -1,34 +0,0 @@
1
- /**
2
- * Graph utility functions
3
- */
4
- import { Graph, Node, Edge } from '../types';
5
- /**
6
- * Extract nodes from a graph object
7
- *
8
- * @param G - Graph or list of nodes
9
- * @returns Array of nodes
10
- */
11
- export declare function getNodesFromGraph(G: Graph | Node[]): Node[];
12
- /**
13
- * Extract edges from a graph object
14
- *
15
- * @param G - Graph or list of nodes
16
- * @returns Array of edges
17
- */
18
- export declare function getEdgesFromGraph(G: Graph | Node[]): Edge[];
19
- /**
20
- * Get the degree of a node in the graph
21
- *
22
- * @param graph - Graph object
23
- * @param node - Node to get degree for
24
- * @returns Degree of the node
25
- */
26
- export declare function getNodeDegree(graph: Graph, node: Node): number;
27
- /**
28
- * Get the neighbors of a node in the graph
29
- *
30
- * @param graph - Graph object
31
- * @param node - Node to get neighbors for
32
- * @returns Array of neighbor nodes
33
- */
34
- export declare function getNeighbors(graph: Graph, node: Node): Node[];