@graphty/layout 1.2.9 → 1.4.0
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.
- package/README.md +400 -409
- package/dist/layout.js +884 -817
- package/dist/layout.js.map +1 -1
- package/dist/src/algorithms/index.d.ts +3 -2
- package/dist/src/algorithms/index.d.ts.map +1 -0
- package/dist/src/algorithms/index.js +2 -2
- package/dist/src/algorithms/index.js.map +1 -1
- package/dist/src/algorithms/optimization/index.d.ts +5 -4
- package/dist/src/algorithms/optimization/index.d.ts.map +1 -0
- package/dist/src/algorithms/optimization/index.js +3 -3
- package/dist/src/algorithms/optimization/index.js.map +1 -1
- package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts +3 -5
- package/dist/src/algorithms/optimization/kamada-kawai-solver.d.ts.map +1 -0
- package/dist/src/algorithms/optimization/kamada-kawai-solver.js +6 -9
- package/dist/src/algorithms/optimization/kamada-kawai-solver.js.map +1 -1
- package/dist/src/algorithms/optimization/lbfgs.d.ts +3 -3
- package/dist/src/algorithms/optimization/lbfgs.d.ts.map +1 -0
- package/dist/src/algorithms/optimization/lbfgs.js +5 -7
- package/dist/src/algorithms/optimization/lbfgs.js.map +1 -1
- package/dist/src/algorithms/optimization/line-search.d.ts +1 -1
- package/dist/src/algorithms/optimization/line-search.d.ts.map +1 -0
- package/dist/src/algorithms/optimization/line-search.js +0 -1
- package/dist/src/algorithms/optimization/line-search.js.map +1 -1
- package/dist/src/algorithms/optimization/types.d.ts +2 -1
- package/dist/src/algorithms/optimization/types.d.ts.map +1 -0
- package/dist/src/algorithms/planarity/check.d.ts +5 -4
- package/dist/src/algorithms/planarity/check.d.ts.map +1 -0
- package/dist/src/algorithms/planarity/check.js +6 -6
- package/dist/src/algorithms/planarity/check.js.map +1 -1
- package/dist/src/algorithms/planarity/embedding.d.ts +5 -6
- package/dist/src/algorithms/planarity/embedding.d.ts.map +1 -0
- package/dist/src/algorithms/planarity/embedding.js +15 -14
- package/dist/src/algorithms/planarity/embedding.js.map +1 -1
- package/dist/src/algorithms/planarity/index.d.ts +5 -4
- package/dist/src/algorithms/planarity/index.d.ts.map +1 -0
- package/dist/src/algorithms/planarity/index.js +4 -4
- package/dist/src/algorithms/planarity/index.js.map +1 -1
- package/dist/src/algorithms/planarity/lr-test.d.ts +3 -2
- package/dist/src/algorithms/planarity/lr-test.d.ts.map +1 -0
- package/dist/src/algorithms/planarity/lr-test.js +2 -2
- package/dist/src/algorithms/planarity/lr-test.js.map +1 -1
- package/dist/src/algorithms/planarity/special-graphs.d.ts +2 -4
- package/dist/src/algorithms/planarity/special-graphs.d.ts.map +1 -0
- package/dist/src/algorithms/planarity/special-graphs.js +18 -15
- package/dist/src/algorithms/planarity/special-graphs.js.map +1 -1
- package/dist/src/generators/basic.d.ts +2 -1
- package/dist/src/generators/basic.d.ts.map +1 -0
- package/dist/src/generators/basic.js +4 -4
- package/dist/src/generators/basic.js.map +1 -1
- package/dist/src/generators/bipartite.d.ts +2 -1
- package/dist/src/generators/bipartite.d.ts.map +1 -0
- package/dist/src/generators/bipartite.js +2 -2
- package/dist/src/generators/bipartite.js.map +1 -1
- package/dist/src/generators/grid.d.ts +2 -1
- package/dist/src/generators/grid.d.ts.map +1 -0
- package/dist/src/generators/grid.js +1 -1
- package/dist/src/generators/grid.js.map +1 -1
- package/dist/src/generators/index.d.ts +6 -5
- package/dist/src/generators/index.d.ts.map +1 -0
- package/dist/src/generators/index.js +5 -5
- package/dist/src/generators/index.js.map +1 -1
- package/dist/src/generators/random.d.ts +2 -1
- package/dist/src/generators/random.d.ts.map +1 -0
- package/dist/src/generators/random.js +2 -2
- package/dist/src/generators/random.js.map +1 -1
- package/dist/src/generators/scale-free.d.ts +2 -1
- package/dist/src/generators/scale-free.d.ts.map +1 -0
- package/dist/src/generators/scale-free.js +4 -4
- package/dist/src/generators/scale-free.js.map +1 -1
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +4 -4
- package/dist/src/layouts/basic/index.d.ts +2 -1
- package/dist/src/layouts/basic/index.d.ts.map +1 -0
- package/dist/src/layouts/basic/index.js +1 -1
- package/dist/src/layouts/basic/random.d.ts +2 -2
- package/dist/src/layouts/basic/random.d.ts.map +1 -0
- package/dist/src/layouts/basic/random.js +4 -5
- package/dist/src/layouts/basic/random.js.map +1 -1
- package/dist/src/layouts/force-directed/arf.d.ts +2 -2
- package/dist/src/layouts/force-directed/arf.d.ts.map +1 -0
- package/dist/src/layouts/force-directed/arf.js +13 -8
- package/dist/src/layouts/force-directed/arf.js.map +1 -1
- package/dist/src/layouts/force-directed/forceatlas2.d.ts +4 -4
- package/dist/src/layouts/force-directed/forceatlas2.d.ts.map +1 -0
- package/dist/src/layouts/force-directed/forceatlas2.js +83 -51
- package/dist/src/layouts/force-directed/forceatlas2.js.map +1 -1
- package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts +12 -12
- package/dist/src/layouts/force-directed/fruchterman-reingold.d.ts.map +1 -0
- package/dist/src/layouts/force-directed/fruchterman-reingold.js +18 -18
- package/dist/src/layouts/force-directed/fruchterman-reingold.js.map +1 -1
- package/dist/src/layouts/force-directed/index.d.ts +6 -5
- package/dist/src/layouts/force-directed/index.d.ts.map +1 -0
- package/dist/src/layouts/force-directed/index.js +5 -5
- package/dist/src/layouts/force-directed/index.js.map +1 -1
- package/dist/src/layouts/force-directed/kamada-kawai.d.ts +3 -3
- package/dist/src/layouts/force-directed/kamada-kawai.d.ts.map +1 -0
- package/dist/src/layouts/force-directed/kamada-kawai.js +13 -11
- package/dist/src/layouts/force-directed/kamada-kawai.js.map +1 -1
- package/dist/src/layouts/force-directed/spring.d.ts +12 -12
- package/dist/src/layouts/force-directed/spring.d.ts.map +1 -0
- package/dist/src/layouts/force-directed/spring.js +11 -12
- package/dist/src/layouts/force-directed/spring.js.map +1 -1
- package/dist/src/layouts/geometric/circular.d.ts +2 -2
- package/dist/src/layouts/geometric/circular.d.ts.map +1 -0
- package/dist/src/layouts/geometric/circular.js +11 -10
- package/dist/src/layouts/geometric/circular.js.map +1 -1
- package/dist/src/layouts/geometric/index.d.ts +4 -3
- package/dist/src/layouts/geometric/index.d.ts.map +1 -0
- package/dist/src/layouts/geometric/index.js +3 -3
- package/dist/src/layouts/geometric/shell.d.ts +2 -2
- package/dist/src/layouts/geometric/shell.d.ts.map +1 -0
- package/dist/src/layouts/geometric/shell.js +6 -6
- package/dist/src/layouts/geometric/shell.js.map +1 -1
- package/dist/src/layouts/geometric/spiral.d.ts +2 -2
- package/dist/src/layouts/geometric/spiral.d.ts.map +1 -0
- package/dist/src/layouts/geometric/spiral.js +6 -10
- package/dist/src/layouts/geometric/spiral.js.map +1 -1
- package/dist/src/layouts/hierarchical/bfs.d.ts +3 -3
- package/dist/src/layouts/hierarchical/bfs.d.ts.map +1 -0
- package/dist/src/layouts/hierarchical/bfs.js +6 -7
- package/dist/src/layouts/hierarchical/bfs.js.map +1 -1
- package/dist/src/layouts/hierarchical/bipartite.d.ts +3 -3
- package/dist/src/layouts/hierarchical/bipartite.d.ts.map +1 -0
- package/dist/src/layouts/hierarchical/bipartite.js +9 -10
- package/dist/src/layouts/hierarchical/bipartite.js.map +1 -1
- package/dist/src/layouts/hierarchical/index.d.ts +4 -3
- package/dist/src/layouts/hierarchical/index.d.ts.map +1 -0
- package/dist/src/layouts/hierarchical/index.js +3 -3
- package/dist/src/layouts/hierarchical/index.js.map +1 -1
- package/dist/src/layouts/hierarchical/multipartite.d.ts +3 -3
- package/dist/src/layouts/hierarchical/multipartite.d.ts.map +1 -0
- package/dist/src/layouts/hierarchical/multipartite.js +9 -10
- package/dist/src/layouts/hierarchical/multipartite.js.map +1 -1
- package/dist/src/layouts/index.d.ts +6 -5
- package/dist/src/layouts/index.d.ts.map +1 -0
- package/dist/src/layouts/index.js +5 -5
- package/dist/src/layouts/index.js.map +1 -1
- package/dist/src/layouts/specialized/index.d.ts +3 -2
- package/dist/src/layouts/specialized/index.d.ts.map +1 -0
- package/dist/src/layouts/specialized/index.js +2 -2
- package/dist/src/layouts/specialized/index.js.map +1 -1
- package/dist/src/layouts/specialized/planar.d.ts +2 -2
- package/dist/src/layouts/specialized/planar.d.ts.map +1 -0
- package/dist/src/layouts/specialized/planar.js +6 -7
- package/dist/src/layouts/specialized/planar.js.map +1 -1
- package/dist/src/layouts/specialized/spectral.d.ts +2 -2
- package/dist/src/layouts/specialized/spectral.d.ts.map +1 -0
- package/dist/src/layouts/specialized/spectral.js +31 -21
- package/dist/src/layouts/specialized/spectral.js.map +1 -1
- package/dist/src/types/embedding.d.ts +2 -1
- package/dist/src/types/embedding.d.ts.map +1 -0
- package/dist/src/types/graph.d.ts +2 -1
- package/dist/src/types/graph.d.ts.map +1 -0
- package/dist/src/types/index.d.ts +4 -3
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +3 -3
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/types/layout.d.ts +2 -1
- package/dist/src/types/layout.d.ts.map +1 -0
- package/dist/src/utils/graph.d.ts +2 -5
- package/dist/src/utils/graph.d.ts.map +1 -0
- package/dist/src/utils/graph.js +4 -6
- package/dist/src/utils/graph.js.map +1 -1
- package/dist/src/utils/index.d.ts +6 -5
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +5 -5
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/utils/numpy.d.ts +5 -4
- package/dist/src/utils/numpy.d.ts.map +1 -0
- package/dist/src/utils/numpy.js +22 -16
- package/dist/src/utils/numpy.js.map +1 -1
- package/dist/src/utils/params.d.ts +2 -2
- package/dist/src/utils/params.d.ts.map +1 -0
- package/dist/src/utils/params.js +0 -1
- package/dist/src/utils/params.js.map +1 -1
- package/dist/src/utils/random.d.ts +18 -0
- package/dist/src/utils/random.d.ts.map +1 -0
- package/dist/src/utils/random.js +18 -1
- package/dist/src/utils/random.js.map +1 -1
- package/dist/src/utils/rescale.d.ts +2 -3
- package/dist/src/utils/rescale.d.ts.map +1 -0
- package/dist/src/utils/rescale.js +12 -10
- package/dist/src/utils/rescale.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +35 -34
- package/src/algorithms/index.ts +2 -2
- package/src/algorithms/optimization/index.ts +4 -8
- package/src/algorithms/optimization/kamada-kawai-solver.ts +170 -179
- package/src/algorithms/optimization/lbfgs.ts +42 -49
- package/src/algorithms/optimization/line-search.ts +27 -28
- package/src/algorithms/optimization/types.ts +2 -2
- package/src/algorithms/planarity/check.ts +23 -23
- package/src/algorithms/planarity/embedding.ts +160 -171
- package/src/algorithms/planarity/index.ts +4 -8
- package/src/algorithms/planarity/lr-test.ts +46 -46
- package/src/algorithms/planarity/special-graphs.ts +73 -83
- package/src/generators/basic.ts +57 -57
- package/src/generators/bipartite.ts +37 -31
- package/src/generators/grid.ts +28 -28
- package/src/generators/index.ts +5 -11
- package/src/generators/random.ts +26 -25
- package/src/generators/scale-free.ts +56 -55
- package/src/index.ts +5 -5
- package/src/layouts/basic/index.ts +1 -1
- package/src/layouts/basic/random.ts +20 -16
- package/src/layouts/force-directed/arf.ts +107 -105
- package/src/layouts/force-directed/forceatlas2.ts +374 -352
- package/src/layouts/force-directed/fruchterman-reingold.ts +133 -134
- package/src/layouts/force-directed/index.ts +5 -5
- package/src/layouts/force-directed/kamada-kawai.ts +77 -80
- package/src/layouts/force-directed/spring.ts +24 -25
- package/src/layouts/geometric/circular.ts +63 -57
- package/src/layouts/geometric/index.ts +3 -3
- package/src/layouts/geometric/shell.ts +58 -53
- package/src/layouts/geometric/spiral.ts +60 -64
- package/src/layouts/hierarchical/bfs.ts +58 -59
- package/src/layouts/hierarchical/bipartite.ts +62 -63
- package/src/layouts/hierarchical/index.ts +3 -3
- package/src/layouts/hierarchical/multipartite.ts +62 -63
- package/src/layouts/index.ts +5 -5
- package/src/layouts/specialized/index.ts +2 -2
- package/src/layouts/specialized/planar.ts +41 -42
- package/src/layouts/specialized/spectral.ts +110 -99
- package/src/types/embedding.ts +5 -5
- package/src/types/graph.ts +4 -4
- package/src/types/index.ts +3 -3
- package/src/types/layout.ts +2 -2
- package/src/utils/graph.ts +31 -35
- package/src/utils/index.ts +5 -5
- package/src/utils/numpy.ts +96 -92
- package/src/utils/params.ts +14 -11
- package/src/utils/random.ts +57 -40
- package/src/utils/rescale.ts +169 -174
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -30
- package/dist/vitest.config.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bipartite.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/bipartite.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"bipartite.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/bipartite.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAC3B,CAAQ,EACR,QAAuB,IAAI,EAC3B,QAAmC,UAAU,EAC7C,QAAgB,CAAC,EACjB,SAA0B,IAAI,EAC9B,cAAsB,CAAC,GAAG,CAAC;IAE3B,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACnE,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,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IAEzB,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK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|
+
export { multipartiteLayout } from "./multipartite";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hierarchical layout algorithms
|
|
3
3
|
*/
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
4
|
+
export { bfsLayout } from "./bfs";
|
|
5
|
+
export { bipartiteLayout } from "./bipartite";
|
|
6
|
+
export { multipartiteLayout } from "./multipartite";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Graph, Node, PositionMap } from
|
|
1
|
+
import type { Graph, Node, PositionMap } from "../../types";
|
|
2
2
|
/**
|
|
3
3
|
* Position nodes in layers of straight lines (multipartite layout).
|
|
4
|
-
*
|
|
5
4
|
* @param G - Graph or list of nodes
|
|
6
5
|
* @param subsetKey - Object mapping layers to node sets, or node attribute name
|
|
7
6
|
* @param align - The alignment of nodes: 'vertical' or 'horizontal'
|
|
@@ -9,4 +8,5 @@ import type { Graph, Node, PositionMap } from '../../types';
|
|
|
9
8
|
* @param center - Coordinate pair around which to center the layout
|
|
10
9
|
* @returns Positions dictionary keyed by node
|
|
11
10
|
*/
|
|
12
|
-
export declare function multipartiteLayout(G: Graph, subsetKey?: Record<number | string, Node | Node[]> | string, align?:
|
|
11
|
+
export declare function multipartiteLayout(G: Graph, subsetKey?: Record<number | string, Node | Node[]> | string, align?: "vertical" | "horizontal", scale?: number, center?: number[] | null): PositionMap;
|
|
12
|
+
//# sourceMappingURL=multipartite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipartite.d.ts","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/multipartite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK5D;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAC9B,CAAC,EAAE,KAAK,EACR,SAAS,GAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC,GAAG,MAAiB,EACrE,KAAK,GAAE,UAAU,GAAG,YAAyB,EAC7C,KAAK,GAAE,MAAU,EACjB,MAAM,GAAE,MAAM,EAAE,GAAG,IAAW,GAC/B,WAAW,CAkEb"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getNodesFromGraph } from
|
|
2
|
-
import { _processParams } from
|
|
3
|
-
import { rescaleLayout } from
|
|
1
|
+
import { getNodesFromGraph } from "../../utils/graph";
|
|
2
|
+
import { _processParams } from "../../utils/params";
|
|
3
|
+
import { rescaleLayout } from "../../utils/rescale";
|
|
4
4
|
/**
|
|
5
5
|
* Position nodes in layers of straight lines (multipartite layout).
|
|
6
|
-
*
|
|
7
6
|
* @param G - Graph or list of nodes
|
|
8
7
|
* @param subsetKey - Object mapping layers to node sets, or node attribute name
|
|
9
8
|
* @param align - The alignment of nodes: 'vertical' or 'horizontal'
|
|
@@ -11,20 +10,20 @@ import { rescaleLayout } from '../../utils/rescale';
|
|
|
11
10
|
* @param center - Coordinate pair around which to center the layout
|
|
12
11
|
* @returns Positions dictionary keyed by node
|
|
13
12
|
*/
|
|
14
|
-
export function multipartiteLayout(G, subsetKey =
|
|
15
|
-
if (align !==
|
|
13
|
+
export function multipartiteLayout(G, subsetKey = "subset", align = "vertical", scale = 1, center = null) {
|
|
14
|
+
if (align !== "vertical" && align !== "horizontal") {
|
|
16
15
|
throw new Error("align must be either vertical or horizontal");
|
|
17
16
|
}
|
|
18
17
|
const processed = _processParams(G, center || [0, 0], 2);
|
|
19
18
|
const graph = processed.G;
|
|
20
|
-
center = processed
|
|
19
|
+
({ center } = processed);
|
|
21
20
|
const allNodes = getNodesFromGraph(graph);
|
|
22
21
|
if (allNodes.length === 0) {
|
|
23
22
|
return {};
|
|
24
23
|
}
|
|
25
24
|
// Convert subsetKey to a layer mapping if it's a string
|
|
26
25
|
let layers = {};
|
|
27
|
-
if (typeof subsetKey ===
|
|
26
|
+
if (typeof subsetKey === "string") {
|
|
28
27
|
// In JS we don't have access to node attributes directly
|
|
29
28
|
// This is a simplification - in a real implementation we would need
|
|
30
29
|
// to access node attributes from the graph
|
|
@@ -47,7 +46,7 @@ export function multipartiteLayout(G, subsetKey = 'subset', align = 'vertical',
|
|
|
47
46
|
const layerCount = Object.keys(layers).length;
|
|
48
47
|
let pos = {};
|
|
49
48
|
// Process each layer
|
|
50
|
-
Object.entries(layers).forEach(([
|
|
49
|
+
Object.entries(layers).forEach(([_layer, nodes], layerIdx) => {
|
|
51
50
|
const layerNodes = Array.isArray(nodes) ? nodes : [nodes];
|
|
52
51
|
const layerSize = layerNodes.length;
|
|
53
52
|
layerNodes.forEach((node, nodeIdx) => {
|
|
@@ -61,7 +60,7 @@ export function multipartiteLayout(G, subsetKey = 'subset', align = 'vertical',
|
|
|
61
60
|
// Rescale positions
|
|
62
61
|
pos = rescaleLayout(pos, scale, center);
|
|
63
62
|
// Handle horizontal alignment
|
|
64
|
-
if (align ===
|
|
63
|
+
if (align === "horizontal") {
|
|
65
64
|
for (const node in pos) {
|
|
66
65
|
const temp = pos[node][0];
|
|
67
66
|
pos[node][0] = pos[node][1];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipartite.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/multipartite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"multipartite.js","sourceRoot":"","sources":["../../../../src/layouts/hierarchical/multipartite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAC9B,CAAQ,EACR,YAA6D,QAAQ,EACrE,QAAmC,UAAU,EAC7C,QAAgB,CAAC,EACjB,SAA0B,IAAI;IAE9B,IAAI,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,YAAY,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACnE,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,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IAEzB,MAAM,QAAQ,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAE1C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC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AC,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YAC1C,MAAM,CAAC,GAAG,OAAO,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;YACxC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACP,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;QACzB,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;YACrB,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;QACxB,CAAC;IACL,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Re-export all layout algorithms
|
|
3
3
|
*/
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
4
|
+
export * from "./basic";
|
|
5
|
+
export * from "./force-directed";
|
|
6
|
+
export * from "./geometric";
|
|
7
|
+
export * from "./hierarchical";
|
|
8
|
+
export * from "./specialized";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/layouts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Re-export all layout algorithms
|
|
3
3
|
*/
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
4
|
+
export * from "./basic";
|
|
5
|
+
export * from "./force-directed";
|
|
6
|
+
export * from "./geometric";
|
|
7
|
+
export * from "./hierarchical";
|
|
8
|
+
export * from "./specialized";
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/layouts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/layouts/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/layouts/specialized/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Planar layout algorithm
|
|
3
3
|
*/
|
|
4
|
-
import { Graph, PositionMap } from
|
|
4
|
+
import type { Graph, PositionMap } from "../../types";
|
|
5
5
|
/**
|
|
6
6
|
* Position nodes without edge intersections (planar layout).
|
|
7
|
-
*
|
|
8
7
|
* @param G - Graph
|
|
9
8
|
* @param scale - Scale factor for positions
|
|
10
9
|
* @param center - Coordinate pair around which to center the layout
|
|
@@ -13,3 +12,4 @@ import { Graph, PositionMap } from '../../types';
|
|
|
13
12
|
* @returns Positions dictionary keyed by node
|
|
14
13
|
*/
|
|
15
14
|
export declare function planarLayout(G: Graph, scale?: number, center?: number[] | null, dim?: number, seed?: number | null): PositionMap;
|
|
15
|
+
//# sourceMappingURL=planar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planar.d.ts","sourceRoot":"","sources":["../../../../src/layouts/specialized/planar.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAKtD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CACxB,CAAC,EAAE,KAAK,EACR,KAAK,GAAE,MAAU,EACjB,MAAM,GAAE,MAAM,EAAE,GAAG,IAAW,EAC9B,GAAG,GAAE,MAAU,EACf,IAAI,GAAE,MAAM,GAAG,IAAW,GAC3B,WAAW,CAwCb"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Planar layout algorithm
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { checkPlanarity, combinatorialEmbeddingToPos } from "../../algorithms/planarity";
|
|
5
|
+
import { getEdgesFromGraph, getNodesFromGraph } from "../../utils/graph";
|
|
6
|
+
import { _processParams } from "../../utils/params";
|
|
7
|
+
import { rescaleLayout } from "../../utils/rescale";
|
|
8
8
|
/**
|
|
9
9
|
* Position nodes without edge intersections (planar layout).
|
|
10
|
-
*
|
|
11
10
|
* @param G - Graph
|
|
12
11
|
* @param scale - Scale factor for positions
|
|
13
12
|
* @param center - Coordinate pair around which to center the layout
|
|
@@ -22,10 +21,10 @@ export function planarLayout(G, scale = 1, center = null, dim = 2, seed = null)
|
|
|
22
21
|
const processed = _processParams(G, center || [0, 0], dim);
|
|
23
22
|
// Planar layout requires a proper Graph, not just a list of nodes
|
|
24
23
|
if (Array.isArray(processed.G)) {
|
|
25
|
-
throw new Error(
|
|
24
|
+
throw new Error("Planar layout requires a Graph with edges, not just a list of nodes");
|
|
26
25
|
}
|
|
27
26
|
const graph = processed.G;
|
|
28
|
-
center = processed
|
|
27
|
+
({ center } = processed);
|
|
29
28
|
const nodes = getNodesFromGraph(graph);
|
|
30
29
|
const edges = getEdgesFromGraph(graph);
|
|
31
30
|
if (nodes.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planar.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/planar.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"planar.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/planar.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAEzF,OAAO,EAAE,iBAAiB,EAAC,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CACxB,CAAQ,EACR,QAAgB,CAAC,EACjB,SAA0B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O,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Spectral layout algorithm using eigenvectors of the graph Laplacian
|
|
3
3
|
*/
|
|
4
|
-
import { Graph, PositionMap } from
|
|
4
|
+
import type { Graph, PositionMap } from "../../types";
|
|
5
5
|
/**
|
|
6
6
|
* Position nodes in a spectral layout using eigenvectors of the graph Laplacian.
|
|
7
|
-
*
|
|
8
7
|
* @param G - Graph
|
|
9
8
|
* @param scale - Scale factor for positions
|
|
10
9
|
* @param center - Coordinate pair around which to center the layout
|
|
@@ -12,3 +11,4 @@ import { Graph, PositionMap } from '../../types';
|
|
|
12
11
|
* @returns Positions dictionary keyed by node
|
|
13
12
|
*/
|
|
14
13
|
export declare function spectralLayout(G: Graph, scale?: number, center?: number[] | null, dim?: number): PositionMap;
|
|
14
|
+
//# sourceMappingURL=spectral.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spectral.d.ts","sourceRoot":"","sources":["../../../../src/layouts/specialized/spectral.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAQ,WAAW,EAAE,MAAM,aAAa,CAAC;AAK5D;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC1B,CAAC,EAAE,KAAK,EACR,KAAK,GAAE,MAAU,EACjB,MAAM,GAAE,MAAM,EAAE,GAAG,IAAW,EAC9B,GAAG,GAAE,MAAU,GAChB,WAAW,CAoHb"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Spectral layout algorithm using eigenvectors of the graph Laplacian
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { rescaleLayout } from
|
|
4
|
+
import { getEdgesFromGraph, getNodesFromGraph } from "../../utils/graph";
|
|
5
|
+
import { _processParams } from "../../utils/params";
|
|
6
|
+
import { rescaleLayout } from "../../utils/rescale";
|
|
7
7
|
/**
|
|
8
8
|
* Position nodes in a spectral layout using eigenvectors of the graph Laplacian.
|
|
9
|
-
*
|
|
10
9
|
* @param G - Graph
|
|
11
10
|
* @param scale - Scale factor for positions
|
|
12
11
|
* @param center - Coordinate pair around which to center the layout
|
|
@@ -16,7 +15,7 @@ import { rescaleLayout } from '../../utils/rescale';
|
|
|
16
15
|
export function spectralLayout(G, scale = 1, center = null, dim = 2) {
|
|
17
16
|
const processed = _processParams(G, center, dim);
|
|
18
17
|
const graph = processed.G;
|
|
19
|
-
center = processed
|
|
18
|
+
({ center } = processed);
|
|
20
19
|
const nodes = getNodesFromGraph(graph);
|
|
21
20
|
if (nodes.length <= 2) {
|
|
22
21
|
if (nodes.length === 0) {
|
|
@@ -25,18 +24,20 @@ export function spectralLayout(G, scale = 1, center = null, dim = 2) {
|
|
|
25
24
|
else if (nodes.length === 1) {
|
|
26
25
|
return { [nodes[0]]: center };
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
};
|
|
33
|
-
}
|
|
27
|
+
return {
|
|
28
|
+
[nodes[0]]: center.map((v) => v - scale),
|
|
29
|
+
[nodes[1]]: center.map((v) => v + scale),
|
|
30
|
+
};
|
|
34
31
|
}
|
|
35
32
|
// Create adjacency matrix
|
|
36
33
|
const N = nodes.length;
|
|
37
34
|
const nodeIndices = {};
|
|
38
|
-
nodes.forEach((node, i) => {
|
|
39
|
-
|
|
35
|
+
nodes.forEach((node, i) => {
|
|
36
|
+
nodeIndices[node] = i;
|
|
37
|
+
});
|
|
38
|
+
const A = Array(N)
|
|
39
|
+
.fill(0)
|
|
40
|
+
.map(() => Array(N).fill(0));
|
|
40
41
|
const edges = getEdgesFromGraph(graph);
|
|
41
42
|
for (const [source, target] of edges) {
|
|
42
43
|
const i = nodeIndices[source];
|
|
@@ -45,7 +46,9 @@ export function spectralLayout(G, scale = 1, center = null, dim = 2) {
|
|
|
45
46
|
A[j][i] = 1; // Make symmetric for undirected graphs
|
|
46
47
|
}
|
|
47
48
|
// Create Laplacian matrix: L = D - A where D is degree matrix
|
|
48
|
-
const L = Array(N)
|
|
49
|
+
const L = Array(N)
|
|
50
|
+
.fill(0)
|
|
51
|
+
.map(() => Array(N).fill(0));
|
|
49
52
|
for (let i = 0; i < N; i++) {
|
|
50
53
|
// Compute degree (sum of row)
|
|
51
54
|
L[i][i] = A[i].reduce((sum, val) => sum + val, 0);
|
|
@@ -58,7 +61,9 @@ export function spectralLayout(G, scale = 1, center = null, dim = 2) {
|
|
|
58
61
|
const eigenvectors = [];
|
|
59
62
|
// For each dimension, find an eigenvector
|
|
60
63
|
for (let d = 0; d < dim; d++) {
|
|
61
|
-
let vector = Array(N)
|
|
64
|
+
let vector = Array(N)
|
|
65
|
+
.fill(0)
|
|
66
|
+
.map(() => Math.random() - 0.5);
|
|
62
67
|
// Orthogonalize against previous eigenvectors
|
|
63
68
|
for (const ev of eigenvectors) {
|
|
64
69
|
const dot = vector.reduce((acc, val, idx) => acc + val * ev[idx], 0);
|
|
@@ -66,7 +71,7 @@ export function spectralLayout(G, scale = 1, center = null, dim = 2) {
|
|
|
66
71
|
}
|
|
67
72
|
// Normalize
|
|
68
73
|
const norm = Math.sqrt(vector.reduce((acc, val) => acc + val * val, 0));
|
|
69
|
-
vector = vector.map(val => val / norm);
|
|
74
|
+
vector = vector.map((val) => val / norm);
|
|
70
75
|
// Apply shifted inverse iteration to find smallest non-zero eigenvector
|
|
71
76
|
// This is a simplification of the actual algorithm
|
|
72
77
|
for (let iter = 0; iter < 100; iter++) {
|
|
@@ -79,17 +84,22 @@ export function spectralLayout(G, scale = 1, center = null, dim = 2) {
|
|
|
79
84
|
}
|
|
80
85
|
// Orthogonalize against the constant vector (eigenvector with eigenvalue 0)
|
|
81
86
|
const mean = newVec.reduce((acc, val) => acc + val, 0) / N;
|
|
82
|
-
newVec.forEach((val, idx, arr) => {
|
|
87
|
+
newVec.forEach((val, idx, arr) => {
|
|
88
|
+
arr[idx] = val - mean;
|
|
89
|
+
});
|
|
83
90
|
// Normalize
|
|
84
91
|
const newNorm = Math.sqrt(newVec.reduce((acc, val) => acc + val * val, 0));
|
|
85
|
-
if (newNorm < 1e-10)
|
|
86
|
-
continue;
|
|
87
|
-
|
|
92
|
+
if (newNorm < 1e-10) {
|
|
93
|
+
continue;
|
|
94
|
+
} // Skip if vector is close to zero
|
|
95
|
+
vector = newVec.map((val) => val / newNorm);
|
|
88
96
|
}
|
|
89
97
|
eigenvectors.push(vector);
|
|
90
98
|
}
|
|
91
99
|
// Create position array from eigenvectors
|
|
92
|
-
const positions = Array(N)
|
|
100
|
+
const positions = Array(N)
|
|
101
|
+
.fill(0)
|
|
102
|
+
.map(() => Array(dim).fill(0));
|
|
93
103
|
for (let i = 0; i < N; i++) {
|
|
94
104
|
for (let d = 0; d < dim; d++) {
|
|
95
105
|
positions[i][d] = eigenvectors[d][i];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spectral.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/spectral.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"spectral.js","sourceRoot":"","sources":["../../../../src/layouts/specialized/spectral.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAC,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC1B,CAAQ,EACR,QAAgB,CAAC,EACjB,SAA0B,IAAI,EAC9B,MAAc,CAAC;IAEf,MAAM,SAAS,GAAG,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC;IAC1B,CAAC,EAAE,MAAM,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AC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC;IACL,CAAC;IAED,yCAAyC;IACzC,MAAM,eAAe,GAAG,aAAa,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACxD,MAAM,GAAG,GAAgB,EAAE,CAAC;IAC5B,KAAK,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,CAAS,EAAE,EAAE;QACpC,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;IACpG,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Embedding type for planar layout algorithms
|
|
3
3
|
*/
|
|
4
|
-
import { Node, Position } from
|
|
4
|
+
import { Node, Position } from "./index";
|
|
5
5
|
export interface Embedding {
|
|
6
6
|
nodeOrder: Node[];
|
|
7
7
|
faceList: Node[][];
|
|
8
8
|
nodePositions: Record<Node, Position>;
|
|
9
9
|
}
|
|
10
|
+
//# sourceMappingURL=embedding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../../../src/types/embedding.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,SAAS;IACtB,SAAS,EAAE,IAAI,EAAE,CAAC;IAClB,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;CACzC"}
|
|
@@ -6,5 +6,6 @@ export type Edge = [Node, Node];
|
|
|
6
6
|
export type Graph = {
|
|
7
7
|
nodes: () => Node[];
|
|
8
8
|
edges: () => Edge[];
|
|
9
|
-
getEdgeData?: (source: Node, target: Node, attr: string) =>
|
|
9
|
+
getEdgeData?: (source: Node, target: Node, attr: string) => number | undefined;
|
|
10
10
|
};
|
|
11
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../src/types/graph.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnC,MAAM,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAEhC,MAAM,MAAM,KAAK,GAAG;IAChB,KAAK,EAAE,MAAM,IAAI,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,IAAI,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAClF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
package/dist/src/types/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../src/types/layout.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,MAAM,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;AAEhC,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Graph utility functions
|
|
3
3
|
*/
|
|
4
|
-
import { Graph, Node
|
|
4
|
+
import { Edge, Graph, Node } from "../types";
|
|
5
5
|
/**
|
|
6
6
|
* Extract nodes from a graph object
|
|
7
|
-
*
|
|
8
7
|
* @param G - Graph or list of nodes
|
|
9
8
|
* @returns Array of nodes
|
|
10
9
|
*/
|
|
11
10
|
export declare function getNodesFromGraph(G: Graph | Node[]): Node[];
|
|
12
11
|
/**
|
|
13
12
|
* Extract edges from a graph object
|
|
14
|
-
*
|
|
15
13
|
* @param G - Graph or list of nodes
|
|
16
14
|
* @returns Array of edges
|
|
17
15
|
*/
|
|
18
16
|
export declare function getEdgesFromGraph(G: Graph | Node[]): Edge[];
|
|
19
17
|
/**
|
|
20
18
|
* Get the degree of a node in the graph
|
|
21
|
-
*
|
|
22
19
|
* @param graph - Graph object
|
|
23
20
|
* @param node - Node to get degree for
|
|
24
21
|
* @returns Degree of the node
|
|
@@ -26,9 +23,9 @@ export declare function getEdgesFromGraph(G: Graph | Node[]): Edge[];
|
|
|
26
23
|
export declare function getNodeDegree(graph: Graph, node: Node): number;
|
|
27
24
|
/**
|
|
28
25
|
* Get the neighbors of a node in the graph
|
|
29
|
-
*
|
|
30
26
|
* @param graph - Graph object
|
|
31
27
|
* @param node - Node to get neighbors for
|
|
32
28
|
* @returns Array of neighbor nodes
|
|
33
29
|
*/
|
|
34
30
|
export declare function getNeighbors(graph: Graph, node: Node): Node[];
|
|
31
|
+
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../../src/utils/graph.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,IAAI,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,CAK3D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,CAK3D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAa9D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAe7D"}
|
package/dist/src/utils/graph.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
5
|
* Extract nodes from a graph object
|
|
6
|
-
*
|
|
7
6
|
* @param G - Graph or list of nodes
|
|
8
7
|
* @returns Array of nodes
|
|
9
8
|
*/
|
|
@@ -15,7 +14,6 @@ export function getNodesFromGraph(G) {
|
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
16
|
* Extract edges from a graph object
|
|
18
|
-
*
|
|
19
17
|
* @param G - Graph or list of nodes
|
|
20
18
|
* @returns Array of edges
|
|
21
19
|
*/
|
|
@@ -27,14 +25,14 @@ export function getEdgesFromGraph(G) {
|
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Get the degree of a node in the graph
|
|
30
|
-
*
|
|
31
28
|
* @param graph - Graph object
|
|
32
29
|
* @param node - Node to get degree for
|
|
33
30
|
* @returns Degree of the node
|
|
34
31
|
*/
|
|
35
32
|
export function getNodeDegree(graph, node) {
|
|
36
|
-
if (!graph.edges)
|
|
33
|
+
if (!graph.edges) {
|
|
37
34
|
return 0;
|
|
35
|
+
}
|
|
38
36
|
const edges = graph.edges();
|
|
39
37
|
let degree = 0;
|
|
40
38
|
for (const [source, target] of edges) {
|
|
@@ -46,14 +44,14 @@ export function getNodeDegree(graph, node) {
|
|
|
46
44
|
}
|
|
47
45
|
/**
|
|
48
46
|
* Get the neighbors of a node in the graph
|
|
49
|
-
*
|
|
50
47
|
* @param graph - Graph object
|
|
51
48
|
* @param node - Node to get neighbors for
|
|
52
49
|
* @returns Array of neighbor nodes
|
|
53
50
|
*/
|
|
54
51
|
export function getNeighbors(graph, node) {
|
|
55
|
-
if (!graph.edges)
|
|
52
|
+
if (!graph.edges) {
|
|
56
53
|
return [];
|
|
54
|
+
}
|
|
57
55
|
const neighbors = new Set();
|
|
58
56
|
const edges = graph.edges();
|
|
59
57
|
for (const [source, target] of edges) {
|