@statelyai/graph 0.9.0 → 0.10.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/dist/{algorithms-3xvCxHzo.mjs → algorithms-C-S7u40k.mjs} +89 -6
- package/dist/{algorithms-g2uWmPrb.d.mts → algorithms-DdjFO-ft.d.mts} +3 -2
- package/dist/algorithms.d.mts +1 -1
- package/dist/algorithms.mjs +1 -1
- package/dist/formats/adjacency-list/index.d.mts +1 -1
- package/dist/formats/converter/index.d.mts +1 -1
- package/dist/formats/cytoscape/index.d.mts +1 -1
- package/dist/formats/d3/index.d.mts +1 -1
- package/dist/formats/dot/index.d.mts +1 -1
- package/dist/formats/edge-list/index.d.mts +1 -1
- package/dist/formats/elk/index.d.mts +1 -1
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gml/index.d.mts +1 -1
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/jgf/index.d.mts +1 -1
- package/dist/formats/mermaid/index.d.mts +1 -1
- package/dist/formats/tgf/index.d.mts +1 -1
- package/dist/formats/xyflow/index.d.mts +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +3 -3
- package/dist/queries.d.mts +14 -14
- package/dist/queries.mjs +16 -9
- package/dist/{types-BzckPChi.d.mts → types-F3j-sr2X.d.mts} +31 -16
- package/package.json +1 -1
|
@@ -49,7 +49,7 @@ function createGraphNode(config) {
|
|
|
49
49
|
id: config.id,
|
|
50
50
|
...config.parentId !== void 0 && { parentId: config.parentId ?? null },
|
|
51
51
|
...config.initialNodeId !== void 0 && { initialNodeId: config.initialNodeId ?? null },
|
|
52
|
-
label: config.label ??
|
|
52
|
+
label: config.label ?? null,
|
|
53
53
|
data: config.data
|
|
54
54
|
};
|
|
55
55
|
if (config.ports !== void 0 && config.ports.length > 0) {
|
|
@@ -1775,8 +1775,9 @@ function getNeighborEdges(graph, nodeId) {
|
|
|
1775
1775
|
* Returns all paths of equal minimum length per target (not just one).
|
|
1776
1776
|
* Uses BFS when all edges are unweighted; Dijkstra otherwise.
|
|
1777
1777
|
*/
|
|
1778
|
-
/** Compute distance + prev maps via BFS or
|
|
1779
|
-
function computeShortestDistances(graph, sourceId, getWeight) {
|
|
1778
|
+
/** Compute distance + prev maps via BFS, Dijkstra, or Bellman-Ford. */
|
|
1779
|
+
function computeShortestDistances(graph, sourceId, getWeight, algorithm) {
|
|
1780
|
+
if (algorithm === "bellman-ford") return bellmanFord(graph, sourceId, getWeight);
|
|
1780
1781
|
const dist = /* @__PURE__ */ new Map();
|
|
1781
1782
|
const prev = /* @__PURE__ */ new Map();
|
|
1782
1783
|
dist.set(sourceId, 0);
|
|
@@ -1839,6 +1840,73 @@ function computeShortestDistances(graph, sourceId, getWeight) {
|
|
|
1839
1840
|
prev
|
|
1840
1841
|
};
|
|
1841
1842
|
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Bellman-Ford single-source shortest paths.
|
|
1845
|
+
* **O(VE)** time. Handles negative edge weights.
|
|
1846
|
+
* Throws if a negative-weight cycle is reachable from the source.
|
|
1847
|
+
*/
|
|
1848
|
+
function bellmanFord(graph, sourceId, getWeight) {
|
|
1849
|
+
const dist = /* @__PURE__ */ new Map();
|
|
1850
|
+
const prev = /* @__PURE__ */ new Map();
|
|
1851
|
+
const effectiveWeight = getWeight ?? ((e) => e.weight ?? 1);
|
|
1852
|
+
const isUndirected = graph.type === "undirected";
|
|
1853
|
+
for (const node of graph.nodes) {
|
|
1854
|
+
dist.set(node.id, Infinity);
|
|
1855
|
+
prev.set(node.id, []);
|
|
1856
|
+
}
|
|
1857
|
+
dist.set(sourceId, 0);
|
|
1858
|
+
const V = graph.nodes.length;
|
|
1859
|
+
const directedEdges = [];
|
|
1860
|
+
for (const edge of graph.edges) {
|
|
1861
|
+
directedEdges.push({
|
|
1862
|
+
fromId: edge.sourceId,
|
|
1863
|
+
toId: edge.targetId,
|
|
1864
|
+
edge
|
|
1865
|
+
});
|
|
1866
|
+
if (isUndirected) directedEdges.push({
|
|
1867
|
+
fromId: edge.targetId,
|
|
1868
|
+
toId: edge.sourceId,
|
|
1869
|
+
edge
|
|
1870
|
+
});
|
|
1871
|
+
}
|
|
1872
|
+
for (let i = 0; i < V - 1; i++) {
|
|
1873
|
+
let changed = false;
|
|
1874
|
+
for (const { fromId, toId, edge } of directedEdges) {
|
|
1875
|
+
const d = dist.get(fromId);
|
|
1876
|
+
if (d === Infinity) continue;
|
|
1877
|
+
const newDist = d + effectiveWeight(edge);
|
|
1878
|
+
const existing = dist.get(toId);
|
|
1879
|
+
if (newDist < existing) {
|
|
1880
|
+
dist.set(toId, newDist);
|
|
1881
|
+
prev.set(toId, [{
|
|
1882
|
+
from: fromId,
|
|
1883
|
+
edge
|
|
1884
|
+
}]);
|
|
1885
|
+
changed = true;
|
|
1886
|
+
} else if (newDist === existing && existing !== Infinity) {
|
|
1887
|
+
const preds = prev.get(toId);
|
|
1888
|
+
if (!preds.some((p) => p.from === fromId && p.edge === edge)) preds.push({
|
|
1889
|
+
from: fromId,
|
|
1890
|
+
edge
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
if (!changed) break;
|
|
1895
|
+
}
|
|
1896
|
+
for (const { fromId, toId, edge } of directedEdges) {
|
|
1897
|
+
const d = dist.get(fromId);
|
|
1898
|
+
if (d === Infinity) continue;
|
|
1899
|
+
if (d + effectiveWeight(edge) < dist.get(toId)) throw new Error("Graph contains a negative-weight cycle reachable from the source node");
|
|
1900
|
+
}
|
|
1901
|
+
for (const [id, d] of dist) if (d === Infinity) {
|
|
1902
|
+
dist.delete(id);
|
|
1903
|
+
prev.delete(id);
|
|
1904
|
+
}
|
|
1905
|
+
return {
|
|
1906
|
+
dist,
|
|
1907
|
+
prev
|
|
1908
|
+
};
|
|
1909
|
+
}
|
|
1842
1910
|
/** Reconstruct all shortest paths to a target by backtracking through prev map. */
|
|
1843
1911
|
function* reconstructPaths(graph, prev, sourceNode, targetId) {
|
|
1844
1912
|
if (targetId === sourceNode.id) {
|
|
@@ -1888,7 +1956,7 @@ function* reconstructPaths(graph, prev, sourceNode, targetId) {
|
|
|
1888
1956
|
function* genShortestPaths(graph, opts) {
|
|
1889
1957
|
const idx = getIndex(graph);
|
|
1890
1958
|
const sourceId = resolveFrom(graph, opts);
|
|
1891
|
-
const { dist, prev } = computeShortestDistances(graph, sourceId, opts?.getWeight);
|
|
1959
|
+
const { dist, prev } = computeShortestDistances(graph, sourceId, opts?.getWeight, opts?.algorithm);
|
|
1892
1960
|
const targets = opts?.to ? [opts.to].filter((id) => dist.has(id)) : [...dist.keys()].filter((id) => id !== sourceId);
|
|
1893
1961
|
const sourceNi = idx.nodeById.get(sourceId);
|
|
1894
1962
|
const sourceNode = sourceNi !== void 0 ? graph.nodes[sourceNi] : graph.nodes.find((n) => n.id === sourceId);
|
|
@@ -2678,9 +2746,10 @@ function kruskalMST(graph, getWeight) {
|
|
|
2678
2746
|
/**
|
|
2679
2747
|
* Returns shortest paths between all pairs of nodes.
|
|
2680
2748
|
* Algorithm 'dijkstra' (default): runs getShortestPaths per source node.
|
|
2749
|
+
* Algorithm 'bellman-ford': handles negative weights, throws on negative cycles.
|
|
2681
2750
|
* Algorithm 'floyd-warshall': classic dynamic programming.
|
|
2682
2751
|
*
|
|
2683
|
-
* **O(V · (V + E) log V)** (Dijkstra) or **O(V³)** (Floyd-Warshall).
|
|
2752
|
+
* **O(V · (V + E) log V)** (Dijkstra), **O(V²E)** (Bellman-Ford), or **O(V³)** (Floyd-Warshall).
|
|
2684
2753
|
*
|
|
2685
2754
|
* @example
|
|
2686
2755
|
* ```ts
|
|
@@ -2699,9 +2768,23 @@ function kruskalMST(graph, getWeight) {
|
|
|
2699
2768
|
* ```
|
|
2700
2769
|
*/
|
|
2701
2770
|
function getAllPairsShortestPaths(graph, opts) {
|
|
2702
|
-
|
|
2771
|
+
const algorithm = opts?.algorithm ?? "dijkstra";
|
|
2772
|
+
if (algorithm === "floyd-warshall") return floydWarshallAllPaths(graph, opts?.getWeight);
|
|
2773
|
+
if (algorithm === "bellman-ford") return bellmanFordAllPaths(graph, opts?.getWeight);
|
|
2703
2774
|
return dijkstraAllPaths(graph, opts?.getWeight);
|
|
2704
2775
|
}
|
|
2776
|
+
function bellmanFordAllPaths(graph, getWeight) {
|
|
2777
|
+
const results = [];
|
|
2778
|
+
for (const node of graph.nodes) {
|
|
2779
|
+
const paths = getShortestPaths(graph, {
|
|
2780
|
+
from: node.id,
|
|
2781
|
+
getWeight,
|
|
2782
|
+
algorithm: "bellman-ford"
|
|
2783
|
+
});
|
|
2784
|
+
results.push(...paths);
|
|
2785
|
+
}
|
|
2786
|
+
return results;
|
|
2787
|
+
}
|
|
2705
2788
|
function dijkstraAllPaths(graph, getWeight) {
|
|
2706
2789
|
const results = [];
|
|
2707
2790
|
for (const node of graph.nodes) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as SinglePathOptions, g as GraphNode, k as TraversalOptions, n as AllPairsShortestPathsOptions, p as GraphEdge, t as AStarOptions, u as Graph, v as GraphPath, w as PathOptions, x as MSTOptions } from "./types-F3j-sr2X.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/algorithms/centrality.d.ts
|
|
4
4
|
interface IterativeCentralityOptions {
|
|
@@ -697,9 +697,10 @@ declare function getMinimumSpanningTree<N, E>(graph: Graph<N, E>, opts?: MSTOpti
|
|
|
697
697
|
/**
|
|
698
698
|
* Returns shortest paths between all pairs of nodes.
|
|
699
699
|
* Algorithm 'dijkstra' (default): runs getShortestPaths per source node.
|
|
700
|
+
* Algorithm 'bellman-ford': handles negative weights, throws on negative cycles.
|
|
700
701
|
* Algorithm 'floyd-warshall': classic dynamic programming.
|
|
701
702
|
*
|
|
702
|
-
* **O(V · (V + E) log V)** (Dijkstra) or **O(V³)** (Floyd-Warshall).
|
|
703
|
+
* **O(V · (V + E) log V)** (Dijkstra), **O(V²E)** (Bellman-Ford), or **O(V³)** (Floyd-Warshall).
|
|
703
704
|
*
|
|
704
705
|
* @example
|
|
705
706
|
* ```ts
|
package/dist/algorithms.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as getArticulationPoints, B as HITSResult, C as hasPath, D as joinPaths, E as isTree, F as genGirvanNewmanCommunities, G as getEigenvectorCentrality, H as getBetweennessCentrality, I as getGirvanNewmanCommunities, J as getOutDegreeCentrality, K as getHITS, L as getGreedyModularityCommunities, M as getBridges, N as GirvanNewmanOptions, O as IsomorphismOptions, P as LabelPropagationOptions, R as getLabelPropagationCommunities, S as getTopologicalSort, T as isConnected, U as getClosenessCentrality, V as IterativeCentralityOptions, W as getDegreeCentrality, Y as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBiconnectedComponents, k as isIsomorphic, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, q as getInDegreeCentrality, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getModularity } from "./algorithms-
|
|
1
|
+
import { A as getArticulationPoints, B as HITSResult, C as hasPath, D as joinPaths, E as isTree, F as genGirvanNewmanCommunities, G as getEigenvectorCentrality, H as getBetweennessCentrality, I as getGirvanNewmanCommunities, J as getOutDegreeCentrality, K as getHITS, L as getGreedyModularityCommunities, M as getBridges, N as GirvanNewmanOptions, O as IsomorphismOptions, P as LabelPropagationOptions, R as getLabelPropagationCommunities, S as getTopologicalSort, T as isConnected, U as getClosenessCentrality, V as IterativeCentralityOptions, W as getDegreeCentrality, Y as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBiconnectedComponents, k as isIsomorphic, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, q as getInDegreeCentrality, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getModularity } from "./algorithms-DdjFO-ft.mjs";
|
|
2
2
|
export { GirvanNewmanOptions, HITSResult, IsomorphismOptions, IterativeCentralityOptions, LabelPropagationOptions, bfs, dfs, genCycles, genGirvanNewmanCommunities, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getClosenessCentrality, getConnectedComponents, getCycles, getDegreeCentrality, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegreeCentrality, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getOutDegreeCentrality, getPageRank, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isIsomorphic, isTree, joinPaths };
|
package/dist/algorithms.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as getBiconnectedComponents, B as getEigenvectorCentrality, C as hasPath, D as joinPaths, E as isTree, F as getLabelPropagationCommunities, H as getInDegreeCentrality, I as getModularity, L as getBetweennessCentrality, M as genGirvanNewmanCommunities, N as getGirvanNewmanCommunities, O as isIsomorphic, P as getGreedyModularityCommunities, R as getClosenessCentrality, S as getTopologicalSort, T as isConnected, U as getOutDegreeCentrality, V as getHITS, W as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBridges, k as getArticulationPoints, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getDegreeCentrality } from "./algorithms-
|
|
1
|
+
import { A as getBiconnectedComponents, B as getEigenvectorCentrality, C as hasPath, D as joinPaths, E as isTree, F as getLabelPropagationCommunities, H as getInDegreeCentrality, I as getModularity, L as getBetweennessCentrality, M as genGirvanNewmanCommunities, N as getGirvanNewmanCommunities, O as isIsomorphic, P as getGreedyModularityCommunities, R as getClosenessCentrality, S as getTopologicalSort, T as isConnected, U as getOutDegreeCentrality, V as getHITS, W as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBridges, k as getArticulationPoints, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getDegreeCentrality } from "./algorithms-C-S7u40k.mjs";
|
|
2
2
|
|
|
3
3
|
export { bfs, dfs, genCycles, genGirvanNewmanCommunities, genPostorders, genPreorders, genShortestPaths, genSimplePaths, getAStarPath, getAllPairsShortestPaths, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getClosenessCentrality, getConnectedComponents, getCycles, getDegreeCentrality, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegreeCentrality, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getOutDegreeCentrality, getPageRank, getPostorder, getPostorders, getPreorder, getPreorders, getShortestPath, getShortestPaths, getSimplePath, getSimplePaths, getStronglyConnectedComponents, getTopologicalSort, hasPath, isAcyclic, isConnected, isIsomorphic, isTree, joinPaths };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as VisualGraphFormatConverter, j as VisualGraph } from "../../types-F3j-sr2X.mjs";
|
|
2
2
|
import { ElkEdge, ElkEdgeSection, ElkExtendedEdge, ElkGraphElement, ElkLabel, ElkNode, ElkNode as ElkNode$1, ElkPoint, ElkPort, ElkPrimitiveEdge, ElkShape, LayoutOptions } from "elkjs/lib/elk-api";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/elk/index.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { P as VisualGraphFormatConverter, j as VisualGraph } from "../../types-F3j-sr2X.mjs";
|
|
2
2
|
import { EdgeBase, NodeBase } from "@xyflow/system";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/xyflow/index.d.ts
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { A as getArticulationPoints, B as HITSResult, C as hasPath, D as joinPaths, E as isTree, F as genGirvanNewmanCommunities, G as getEigenvectorCentrality, H as getBetweennessCentrality, I as getGirvanNewmanCommunities, J as getOutDegreeCentrality, K as getHITS, L as getGreedyModularityCommunities, M as getBridges, N as GirvanNewmanOptions, O as IsomorphismOptions, P as LabelPropagationOptions, R as getLabelPropagationCommunities, S as getTopologicalSort, T as isConnected, U as getClosenessCentrality, V as IterativeCentralityOptions, W as getDegreeCentrality, Y as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBiconnectedComponents, k as isIsomorphic, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, q as getInDegreeCentrality, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getModularity } from "./algorithms-
|
|
1
|
+
import { A as VisualEdge, C as NodeConfig, D as SinglePathOptions, E as PortDirection, F as VisualNode, I as VisualPort, L as WalkContext, M as VisualGraphConfig, N as VisualGraphEntity, O as TransitionOptions, P as VisualGraphFormatConverter, R as WalkOptions, S as NodeChange, T as PortConfig, _ as GraphPatch, a as EdgeChange, b as GraphStep, c as EntitiesUpdate, d as GraphConfig, f as GraphDiff, g as GraphNode, h as GraphFormatConverter, i as DeleteNodeOptions, j as VisualGraph, k as TraversalOptions, l as EntityRect, m as GraphEntity, n as AllPairsShortestPathsOptions, o as EdgeConfig, p as GraphEdge, r as CoverageStats, s as EntitiesConfig, t as AStarOptions, u as Graph, v as GraphPath, w as PathOptions, x as MSTOptions, y as GraphPort, z as WeightedWalkOptions } from "./types-F3j-sr2X.mjs";
|
|
2
|
+
import { A as getArticulationPoints, B as HITSResult, C as hasPath, D as joinPaths, E as isTree, F as genGirvanNewmanCommunities, G as getEigenvectorCentrality, H as getBetweennessCentrality, I as getGirvanNewmanCommunities, J as getOutDegreeCentrality, K as getHITS, L as getGreedyModularityCommunities, M as getBridges, N as GirvanNewmanOptions, O as IsomorphismOptions, P as LabelPropagationOptions, R as getLabelPropagationCommunities, S as getTopologicalSort, T as isConnected, U as getClosenessCentrality, V as IterativeCentralityOptions, W as getDegreeCentrality, Y as getPageRank, _ as getShortestPath, a as genPreorders, b as getSimplePaths, c as getAStarPath, d as getCycles, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, j as getBiconnectedComponents, k as isIsomorphic, l as getAllPairsShortestPaths, m as getPostorders, n as dfs, o as genShortestPaths, p as getPostorder, q as getInDegreeCentrality, r as genCycles, s as genSimplePaths, t as bfs, u as getConnectedComponents, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getModularity } from "./algorithms-DdjFO-ft.mjs";
|
|
3
3
|
import { createFormatConverter } from "./formats/converter/index.mjs";
|
|
4
|
-
import { getAncestors, getChildren, getDegree, getDepth, getDescendants,
|
|
4
|
+
import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf } from "./queries.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/graph.d.ts
|
|
7
7
|
|
|
@@ -112,7 +112,7 @@ declare function getNode<N>(graph: Graph<N>, id: string): GraphNode<N> | undefin
|
|
|
112
112
|
* const missing = getEdge(graph, 'z'); // undefined
|
|
113
113
|
* ```
|
|
114
114
|
*/
|
|
115
|
-
declare function getEdge<E>(graph: Graph<
|
|
115
|
+
declare function getEdge<N, E>(graph: Graph<N, E>, id: string): GraphEdge<E> | undefined;
|
|
116
116
|
/**
|
|
117
117
|
* Check if a node exists in the graph.
|
|
118
118
|
*
|
|
@@ -161,7 +161,7 @@ declare function addNode<N, P = any>(graph: Graph<N, any, any, P>, config: NodeC
|
|
|
161
161
|
* // graph.edges.length === 1
|
|
162
162
|
* ```
|
|
163
163
|
*/
|
|
164
|
-
declare function addEdge<E>(graph: Graph<
|
|
164
|
+
declare function addEdge<N, E>(graph: Graph<N, E>, config: EdgeConfig<E>): GraphEdge<E>;
|
|
165
165
|
/**
|
|
166
166
|
* **Mutable.** Delete a node and its connected edges. Mutates `graph.nodes`
|
|
167
167
|
* and `graph.edges` in place.
|
|
@@ -220,7 +220,7 @@ declare function updateNode<N, P = any>(graph: Graph<N, any, any, P>, id: string
|
|
|
220
220
|
* // updated.label === 'new'
|
|
221
221
|
* ```
|
|
222
222
|
*/
|
|
223
|
-
declare function updateEdge<E>(graph: Graph<
|
|
223
|
+
declare function updateEdge<N, E>(graph: Graph<N, E>, id: string, update: Partial<Omit<EdgeConfig<E>, 'id'>>): GraphEdge<E>;
|
|
224
224
|
/**
|
|
225
225
|
* **Mutable.** Add multiple nodes and edges to the graph.
|
|
226
226
|
* Nodes are added first, then edges (so edges can reference new nodes).
|
|
@@ -628,4 +628,4 @@ declare function getCoverage<N, E>(graph: Graph<N, E>, steps: GraphStep<N, E>[],
|
|
|
628
628
|
from?: string;
|
|
629
629
|
}): CoverageStats;
|
|
630
630
|
//#endregion
|
|
631
|
-
export { type AStarOptions, type AllPairsShortestPathsOptions, type CoverageStats, type DeleteNodeOptions, type EdgeChange, type EdgeConfig, type EntitiesConfig, type EntitiesUpdate, type GirvanNewmanOptions, type Graph, type GraphConfig, type GraphDiff, type GraphEdge, type GraphEntity, type
|
|
631
|
+
export { type AStarOptions, type AllPairsShortestPathsOptions, type CoverageStats, type DeleteNodeOptions, type EdgeChange, type EdgeConfig, type EntitiesConfig, type EntitiesUpdate, type EntityRect, type GirvanNewmanOptions, type Graph, type GraphConfig, type GraphDiff, type GraphEdge, type GraphEntity, type GraphFormatConverter, GraphInstance, type GraphNode, type GraphPatch, type GraphPath, type GraphPort, type GraphStep, type HITSResult, type IsomorphismOptions, type IterativeCentralityOptions, LAYOUT_KEYS, type LabelPropagationOptions, type MSTOptions, type NodeChange, type NodeConfig, type PathOptions, type PortConfig, type PortDirection, type SinglePathOptions, type TransitionOptions, type TraversalOptions, type VisualEdge, type VisualGraph, type VisualGraphConfig, type VisualGraphEntity, type VisualGraphFormatConverter, type VisualNode, type VisualPort, type WalkContext, type WalkOptions, type WeightedWalkOptions, addEdge, addEntities, addNode, applyPatches, areEntitiesEqual, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, createGraphPort, createVisualGraph, deleteEdge, deleteEntities, deleteNode, dfs, flatten, genCycles, genGirvanNewmanCommunities, genPostorders, genPredefinedWalk, genPreorders, genQuickRandomWalk, genRandomWalk, genShortestPaths, genSimplePaths, genWeightedRandomWalk, getAStarPath, getAllPairsShortestPaths, getAncestors, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getChildren, getClosenessCentrality, getConnectedComponents, getCoverage, getCycles, getDegree, getDegreeCentrality, getDepth, getDescendants, getDiff, getEdge, getEdgesBetween, getEdgesByPort, getEdgesOf, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegree, getInDegreeCentrality, getInEdges, getLCA, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getNeighbors, getNode, getOutDegree, getOutDegreeCentrality, getOutEdges, getPageRank, getParent, getPatches, getPort, getPorts, getPostorder, getPostorders, getPredecessors, getPreorder, getPreorders, getRelativeDistance, getRelativeDistanceMap, getRoots, getShortestPath, getShortestPaths, getSiblings, getSimplePath, getSimplePaths, getSinks, getSources, getStronglyConnectedComponents, getSubgraph, getSuccessors, getTopologicalSort, hasEdge, hasNode, hasPath, invalidateIndex, invertDiff, isAcyclic, isCompound, isConnected, isEmptyDiff, isIsomorphic, isLayoutEqual, isLeaf, isNonLayoutEqual, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { o as invalidateIndex, t as getIndex } from "./indexing-DyfgLuzw.mjs";
|
|
2
|
-
import { $ as createGraphPort, A as getBiconnectedComponents, B as getEigenvectorCentrality, C as hasPath, D as joinPaths, E as isTree, F as getLabelPropagationCommunities, G as GraphInstance, H as getInDegreeCentrality, I as getModularity, J as addNode, K as addEdge, L as getBetweennessCentrality, M as genGirvanNewmanCommunities, N as getGirvanNewmanCommunities, O as isIsomorphic, P as getGreedyModularityCommunities, Q as createGraphNode, R as getClosenessCentrality, S as getTopologicalSort, T as isConnected, U as getOutDegreeCentrality, V as getHITS, W as getPageRank, X as createGraphEdge, Y as createGraph, Z as createGraphFromTransition, _ as getShortestPath, a as genPreorders, at as getNode, b as getSimplePaths, c as getAStarPath, ct as updateEdge, d as getCycles, et as createVisualGraph, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, it as getEdge, j as getBridges, k as getArticulationPoints, l as getAllPairsShortestPaths, lt as updateEntities, m as getPostorders, n as dfs, nt as deleteEntities, o as genShortestPaths, ot as hasEdge, p as getPostorder, q as addEntities, r as genCycles, rt as deleteNode, s as genSimplePaths, st as hasNode, t as bfs, tt as deleteEdge, u as getConnectedComponents, ut as updateNode, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getDegreeCentrality } from "./algorithms-
|
|
3
|
-
import { getAncestors, getChildren, getDegree, getDepth, getDescendants,
|
|
2
|
+
import { $ as createGraphPort, A as getBiconnectedComponents, B as getEigenvectorCentrality, C as hasPath, D as joinPaths, E as isTree, F as getLabelPropagationCommunities, G as GraphInstance, H as getInDegreeCentrality, I as getModularity, J as addNode, K as addEdge, L as getBetweennessCentrality, M as genGirvanNewmanCommunities, N as getGirvanNewmanCommunities, O as isIsomorphic, P as getGreedyModularityCommunities, Q as createGraphNode, R as getClosenessCentrality, S as getTopologicalSort, T as isConnected, U as getOutDegreeCentrality, V as getHITS, W as getPageRank, X as createGraphEdge, Y as createGraph, Z as createGraphFromTransition, _ as getShortestPath, a as genPreorders, at as getNode, b as getSimplePaths, c as getAStarPath, ct as updateEdge, d as getCycles, et as createVisualGraph, f as getMinimumSpanningTree, g as getPreorders, h as getPreorder, i as genPostorders, it as getEdge, j as getBridges, k as getArticulationPoints, l as getAllPairsShortestPaths, lt as updateEntities, m as getPostorders, n as dfs, nt as deleteEntities, o as genShortestPaths, ot as hasEdge, p as getPostorder, q as addEntities, r as genCycles, rt as deleteNode, s as genSimplePaths, st as hasNode, t as bfs, tt as deleteEdge, u as getConnectedComponents, ut as updateNode, v as getShortestPaths, w as isAcyclic, x as getStronglyConnectedComponents, y as getSimplePath, z as getDegreeCentrality } from "./algorithms-C-S7u40k.mjs";
|
|
3
|
+
import { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf } from "./queries.mjs";
|
|
4
4
|
import { n as createFormatConverter } from "./converter-B5CUD0r9.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/equivalence.ts
|
|
@@ -905,4 +905,4 @@ function getCoverage(graph, steps, options) {
|
|
|
905
905
|
}
|
|
906
906
|
|
|
907
907
|
//#endregion
|
|
908
|
-
export { GraphInstance, LAYOUT_KEYS, addEdge, addEntities, addNode, applyPatches, areEntitiesEqual, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, createGraphPort, createVisualGraph, deleteEdge, deleteEntities, deleteNode, dfs, flatten, genCycles, genGirvanNewmanCommunities, genPostorders, genPredefinedWalk, genPreorders, genQuickRandomWalk, genRandomWalk, genShortestPaths, genSimplePaths, genWeightedRandomWalk, getAStarPath, getAllPairsShortestPaths, getAncestors, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getChildren, getClosenessCentrality, getConnectedComponents, getCoverage, getCycles, getDegree, getDegreeCentrality, getDepth, getDescendants, getDiff, getEdge,
|
|
908
|
+
export { GraphInstance, LAYOUT_KEYS, addEdge, addEntities, addNode, applyPatches, areEntitiesEqual, bfs, createFormatConverter, createGraph, createGraphEdge, createGraphFromTransition, createGraphNode, createGraphPort, createVisualGraph, deleteEdge, deleteEntities, deleteNode, dfs, flatten, genCycles, genGirvanNewmanCommunities, genPostorders, genPredefinedWalk, genPreorders, genQuickRandomWalk, genRandomWalk, genShortestPaths, genSimplePaths, genWeightedRandomWalk, getAStarPath, getAllPairsShortestPaths, getAncestors, getArticulationPoints, getBetweennessCentrality, getBiconnectedComponents, getBridges, getChildren, getClosenessCentrality, getConnectedComponents, getCoverage, getCycles, getDegree, getDegreeCentrality, getDepth, getDescendants, getDiff, getEdge, getEdgesBetween, getEdgesByPort, getEdgesOf, getEigenvectorCentrality, getGirvanNewmanCommunities, getGreedyModularityCommunities, getHITS, getInDegree, getInDegreeCentrality, getInEdges, getLCA, getLabelPropagationCommunities, getMinimumSpanningTree, getModularity, getNeighbors, getNode, getOutDegree, getOutDegreeCentrality, getOutEdges, getPageRank, getParent, getPatches, getPort, getPorts, getPostorder, getPostorders, getPredecessors, getPreorder, getPreorders, getRelativeDistance, getRelativeDistanceMap, getRoots, getShortestPath, getShortestPaths, getSiblings, getSimplePath, getSimplePaths, getSinks, getSources, getStronglyConnectedComponents, getSubgraph, getSuccessors, getTopologicalSort, hasEdge, hasNode, hasPath, invalidateIndex, invertDiff, isAcyclic, isCompound, isConnected, isEmptyDiff, isIsomorphic, isLayoutEqual, isLeaf, isNonLayoutEqual, isTree, joinPaths, reverseGraph, takeSteps, takeUntilEdge, takeUntilEdgeCoverage, takeUntilNode, takeUntilNodeCoverage, toDiff, toPatches, updateEdge, updateEntities, updateNode };
|
package/dist/queries.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as GraphNode, p as GraphEdge, u as Graph, y as GraphPort } from "./types-F3j-sr2X.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/queries.d.ts
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ import { _ as GraphNode, b as GraphPort, p as GraphEdge, u as Graph } from "./ty
|
|
|
18
18
|
* // => [edge e1, edge e2]
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
|
-
declare function getEdgesOf<E>(graph: Graph<
|
|
21
|
+
declare function getEdgesOf<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
|
|
22
22
|
/**
|
|
23
23
|
* Returns incoming edges to a node.
|
|
24
24
|
*
|
|
@@ -34,7 +34,7 @@ declare function getEdgesOf<E>(graph: Graph<any, E>, nodeId: string): GraphEdge<
|
|
|
34
34
|
* // => []
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
declare function getInEdges<E>(graph: Graph<
|
|
37
|
+
declare function getInEdges<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
|
|
38
38
|
/**
|
|
39
39
|
* Returns outgoing edges from a node.
|
|
40
40
|
*
|
|
@@ -50,9 +50,9 @@ declare function getInEdges<E>(graph: Graph<any, E>, nodeId: string): GraphEdge<
|
|
|
50
50
|
* // => []
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
declare function getOutEdges<E>(graph: Graph<
|
|
53
|
+
declare function getOutEdges<N, E>(graph: Graph<N, E>, nodeId: string): GraphEdge<E>[];
|
|
54
54
|
/**
|
|
55
|
-
* Returns
|
|
55
|
+
* Returns all edges from `sourceId` to `targetId`.
|
|
56
56
|
* For undirected graphs, checks both directions.
|
|
57
57
|
*
|
|
58
58
|
* @example
|
|
@@ -61,13 +61,13 @@ declare function getOutEdges<E>(graph: Graph<any, E>, nodeId: string): GraphEdge
|
|
|
61
61
|
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
62
62
|
* edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
|
|
63
63
|
* });
|
|
64
|
-
*
|
|
65
|
-
* // => edge e1
|
|
66
|
-
*
|
|
67
|
-
* // =>
|
|
64
|
+
* getEdgesBetween(graph, 'a', 'b');
|
|
65
|
+
* // => [edge e1]
|
|
66
|
+
* getEdgesBetween(graph, 'b', 'a');
|
|
67
|
+
* // => [] (directed graph)
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
|
-
declare function
|
|
70
|
+
declare function getEdgesBetween<N, E>(graph: Graph<N, E>, sourceId: string, targetId: string): GraphEdge<E>[];
|
|
71
71
|
/**
|
|
72
72
|
* Returns direct successor nodes (targets of outgoing edges).
|
|
73
73
|
*
|
|
@@ -469,7 +469,7 @@ declare function getSinks<N>(graph: Graph<N>): GraphNode<N>[];
|
|
|
469
469
|
* getPort(graph, 'a', 'missing'); // => undefined
|
|
470
470
|
* ```
|
|
471
471
|
*/
|
|
472
|
-
declare function getPort<
|
|
472
|
+
declare function getPort<N, E, G, P>(graph: Graph<N, E, G, P>, nodeId: string, portName: string): GraphPort<P> | undefined;
|
|
473
473
|
/**
|
|
474
474
|
* Get all ports on a node. Returns `[]` if the node has no ports or doesn't exist.
|
|
475
475
|
*
|
|
@@ -487,7 +487,7 @@ declare function getPort<P = any>(graph: Graph<any, any, any, P>, nodeId: string
|
|
|
487
487
|
* getPorts(graph, 'a'); // => [port in, port out]
|
|
488
488
|
* ```
|
|
489
489
|
*/
|
|
490
|
-
declare function getPorts<
|
|
490
|
+
declare function getPorts<N, E, G, P>(graph: Graph<N, E, G, P>, nodeId: string): GraphPort<P>[];
|
|
491
491
|
/**
|
|
492
492
|
* Get all edges connected to a specific port on a node.
|
|
493
493
|
*
|
|
@@ -510,6 +510,6 @@ declare function getPorts<P = any>(graph: Graph<any, any, any, P>, nodeId: strin
|
|
|
510
510
|
* getEdgesByPort(graph, 'a', 'out'); // => [edge e1]
|
|
511
511
|
* ```
|
|
512
512
|
*/
|
|
513
|
-
declare function getEdgesByPort<E
|
|
513
|
+
declare function getEdgesByPort<N, E>(graph: Graph<N, E>, nodeId: string, portName: string): GraphEdge<E>[];
|
|
514
514
|
//#endregion
|
|
515
|
-
export { getAncestors, getChildren, getDegree, getDepth, getDescendants,
|
|
515
|
+
export { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf };
|
package/dist/queries.mjs
CHANGED
|
@@ -73,7 +73,7 @@ function getOutEdges(graph, nodeId) {
|
|
|
73
73
|
return (idx.outEdges.get(nodeId) ?? []).map((eid) => graph.edges[idx.edgeById.get(eid)]);
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
|
-
* Returns
|
|
76
|
+
* Returns all edges from `sourceId` to `targetId`.
|
|
77
77
|
* For undirected graphs, checks both directions.
|
|
78
78
|
*
|
|
79
79
|
* @example
|
|
@@ -82,28 +82,35 @@ function getOutEdges(graph, nodeId) {
|
|
|
82
82
|
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
83
83
|
* edges: [{ id: 'e1', sourceId: 'a', targetId: 'b' }],
|
|
84
84
|
* });
|
|
85
|
-
*
|
|
86
|
-
* // => edge e1
|
|
87
|
-
*
|
|
88
|
-
* // =>
|
|
85
|
+
* getEdgesBetween(graph, 'a', 'b');
|
|
86
|
+
* // => [edge e1]
|
|
87
|
+
* getEdgesBetween(graph, 'b', 'a');
|
|
88
|
+
* // => [] (directed graph)
|
|
89
89
|
* ```
|
|
90
90
|
*/
|
|
91
|
-
function
|
|
91
|
+
function getEdgesBetween(graph, sourceId, targetId) {
|
|
92
92
|
const idx = getIndex(graph);
|
|
93
|
+
const result = [];
|
|
94
|
+
const seen = /* @__PURE__ */ new Set();
|
|
93
95
|
const outIds = idx.outEdges.get(sourceId) ?? [];
|
|
94
96
|
for (const eid of outIds) {
|
|
95
97
|
const ai = idx.edgeById.get(eid);
|
|
96
98
|
const e = graph.edges[ai];
|
|
97
|
-
if (e.targetId === targetId)
|
|
99
|
+
if (e.targetId === targetId) {
|
|
100
|
+
seen.add(eid);
|
|
101
|
+
result.push(e);
|
|
102
|
+
}
|
|
98
103
|
}
|
|
99
104
|
if (graph.type === "undirected") {
|
|
100
105
|
const outIds2 = idx.outEdges.get(targetId) ?? [];
|
|
101
106
|
for (const eid of outIds2) {
|
|
107
|
+
if (seen.has(eid)) continue;
|
|
102
108
|
const ai = idx.edgeById.get(eid);
|
|
103
109
|
const e = graph.edges[ai];
|
|
104
|
-
if (e.targetId === sourceId)
|
|
110
|
+
if (e.targetId === sourceId) result.push(e);
|
|
105
111
|
}
|
|
106
112
|
}
|
|
113
|
+
return result;
|
|
107
114
|
}
|
|
108
115
|
/**
|
|
109
116
|
* Returns direct successor nodes (targets of outgoing edges).
|
|
@@ -758,4 +765,4 @@ function getEdgesByPort(graph, nodeId, portName) {
|
|
|
758
765
|
}
|
|
759
766
|
|
|
760
767
|
//#endregion
|
|
761
|
-
export { getAncestors, getChildren, getDegree, getDepth, getDescendants,
|
|
768
|
+
export { getAncestors, getChildren, getDegree, getDepth, getDescendants, getEdgesBetween, getEdgesByPort, getEdgesOf, getInDegree, getInEdges, getLCA, getNeighbors, getOutDegree, getOutEdges, getParent, getPort, getPorts, getPredecessors, getRelativeDistance, getRelativeDistanceMap, getRoots, getSiblings, getSinks, getSources, getSuccessors, isCompound, isLeaf };
|
|
@@ -5,16 +5,14 @@ interface EntityRect {
|
|
|
5
5
|
width: number;
|
|
6
6
|
height: number;
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
interface
|
|
8
|
+
/** Shared optional visual/style props for nodes, edges, ports. */
|
|
9
|
+
interface GraphEntity {
|
|
10
10
|
x?: number;
|
|
11
11
|
y?: number;
|
|
12
12
|
width?: number;
|
|
13
13
|
height?: number;
|
|
14
14
|
style?: Record<string, string | number>;
|
|
15
15
|
}
|
|
16
|
-
/** Resolved entity base — optional visual props (non-visual graphs may omit). */
|
|
17
|
-
interface GraphEntity extends GraphEntityConfig {}
|
|
18
16
|
/** Visual entity base — required position/size. */
|
|
19
17
|
interface VisualGraphEntity {
|
|
20
18
|
x: number;
|
|
@@ -24,7 +22,7 @@ interface VisualGraphEntity {
|
|
|
24
22
|
style?: Record<string, string | number>;
|
|
25
23
|
}
|
|
26
24
|
type PortDirection = 'in' | 'out' | 'inout';
|
|
27
|
-
interface PortConfig<TPortData = any> extends
|
|
25
|
+
interface PortConfig<TPortData = any> extends GraphEntity {
|
|
28
26
|
name: string;
|
|
29
27
|
direction?: PortDirection;
|
|
30
28
|
label?: string;
|
|
@@ -36,7 +34,12 @@ interface GraphPort<TPortData = any> extends GraphEntity {
|
|
|
36
34
|
label?: string;
|
|
37
35
|
data: TPortData;
|
|
38
36
|
}
|
|
39
|
-
interface VisualPort<TPortData = any> extends
|
|
37
|
+
interface VisualPort<TPortData = any> extends GraphPort<TPortData> {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
}
|
|
40
43
|
interface GraphConfig<TNodeData = any, TEdgeData = any, TGraphData = any, TPortData = any> {
|
|
41
44
|
id?: string;
|
|
42
45
|
type?: 'directed' | 'undirected';
|
|
@@ -47,17 +50,17 @@ interface GraphConfig<TNodeData = any, TEdgeData = any, TGraphData = any, TPortD
|
|
|
47
50
|
direction?: 'up' | 'down' | 'left' | 'right';
|
|
48
51
|
style?: Record<string, string | number>;
|
|
49
52
|
}
|
|
50
|
-
interface NodeConfig<TNodeData = any, TPortData = any> extends
|
|
53
|
+
interface NodeConfig<TNodeData = any, TPortData = any> extends GraphEntity {
|
|
51
54
|
id: string;
|
|
52
55
|
parentId?: string | null;
|
|
53
56
|
initialNodeId?: string;
|
|
54
|
-
label?: string;
|
|
57
|
+
label?: string | null;
|
|
55
58
|
data?: TNodeData;
|
|
56
59
|
ports?: PortConfig<TPortData>[];
|
|
57
60
|
shape?: string;
|
|
58
61
|
color?: string;
|
|
59
62
|
}
|
|
60
|
-
interface EdgeConfig<TEdgeData = any> extends
|
|
63
|
+
interface EdgeConfig<TEdgeData = any> extends GraphEntity {
|
|
61
64
|
/**
|
|
62
65
|
* The id of the edge.
|
|
63
66
|
*/
|
|
@@ -102,7 +105,7 @@ interface GraphNode<TNodeData = any, TPortData = any> extends GraphEntity {
|
|
|
102
105
|
id: string;
|
|
103
106
|
parentId?: string | null;
|
|
104
107
|
initialNodeId?: string | null;
|
|
105
|
-
label?: string;
|
|
108
|
+
label?: string | null;
|
|
106
109
|
data: TNodeData;
|
|
107
110
|
ports?: GraphPort<TPortData>[];
|
|
108
111
|
shape?: string;
|
|
@@ -127,11 +130,19 @@ interface GraphEdge<TEdgeData = any> extends GraphEntity {
|
|
|
127
130
|
data: TEdgeData;
|
|
128
131
|
color?: string;
|
|
129
132
|
}
|
|
130
|
-
interface VisualNode<TNodeData = any, TPortData = any> extends
|
|
131
|
-
|
|
133
|
+
interface VisualNode<TNodeData = any, TPortData = any> extends GraphNode<TNodeData, TPortData> {
|
|
134
|
+
x: number;
|
|
135
|
+
y: number;
|
|
136
|
+
width: number;
|
|
137
|
+
height: number;
|
|
132
138
|
ports?: VisualPort<TPortData>[];
|
|
133
139
|
}
|
|
134
|
-
interface VisualEdge<TEdgeData = any> extends
|
|
140
|
+
interface VisualEdge<TEdgeData = any> extends GraphEdge<TEdgeData> {
|
|
141
|
+
x: number;
|
|
142
|
+
y: number;
|
|
143
|
+
width: number;
|
|
144
|
+
height: number;
|
|
145
|
+
}
|
|
135
146
|
interface VisualGraph<TNodeData = any, TEdgeData = any, TGraphData = any, TPortData = any> extends Omit<Graph<TNodeData, TEdgeData, TGraphData, TPortData>, 'nodes' | 'edges'> {
|
|
136
147
|
nodes: VisualNode<TNodeData, TPortData>[];
|
|
137
148
|
edges: VisualEdge<TEdgeData>[];
|
|
@@ -176,6 +187,8 @@ interface PathOptions<TEdgeData = any> {
|
|
|
176
187
|
to?: string;
|
|
177
188
|
/** Edge weight function. Default: `(e) => e.weight ?? 1`. */
|
|
178
189
|
getWeight?: (edge: GraphEdge<TEdgeData>) => number;
|
|
190
|
+
/** Algorithm to use. Default: 'dijkstra'. Use 'bellman-ford' for negative weights. */
|
|
191
|
+
algorithm?: 'dijkstra' | 'bellman-ford';
|
|
179
192
|
}
|
|
180
193
|
interface SinglePathOptions<TEdgeData = any> {
|
|
181
194
|
/** Source node ID. Default: graph.initialNodeId, else sole inDegree-0 node */
|
|
@@ -184,6 +197,8 @@ interface SinglePathOptions<TEdgeData = any> {
|
|
|
184
197
|
to: string;
|
|
185
198
|
/** Edge weight function. Default: `(e) => e.weight ?? 1`. */
|
|
186
199
|
getWeight?: (edge: GraphEdge<TEdgeData>) => number;
|
|
200
|
+
/** Algorithm to use. Default: 'dijkstra'. Use 'bellman-ford' for negative weights. */
|
|
201
|
+
algorithm?: 'dijkstra' | 'bellman-ford';
|
|
187
202
|
}
|
|
188
203
|
interface AStarOptions<TEdgeData = any> {
|
|
189
204
|
/** Source node ID. */
|
|
@@ -209,8 +224,8 @@ interface MSTOptions<TEdgeData = any> {
|
|
|
209
224
|
getWeight?: (edge: GraphEdge<TEdgeData>) => number;
|
|
210
225
|
}
|
|
211
226
|
interface AllPairsShortestPathsOptions<TEdgeData = any> {
|
|
212
|
-
/** Algorithm to use. Default: 'dijkstra'. */
|
|
213
|
-
algorithm?: 'floyd-warshall' | 'dijkstra';
|
|
227
|
+
/** Algorithm to use. Default: 'dijkstra'. Use 'bellman-ford' for negative weights. */
|
|
228
|
+
algorithm?: 'floyd-warshall' | 'dijkstra' | 'bellman-ford';
|
|
214
229
|
/** Edge weight function. Default: `(e) => e.weight ?? 1`. */
|
|
215
230
|
getWeight?: (edge: GraphEdge<TEdgeData>) => number;
|
|
216
231
|
}
|
|
@@ -337,4 +352,4 @@ interface TransitionOptions<TState, TEvent> {
|
|
|
337
352
|
id?: string;
|
|
338
353
|
}
|
|
339
354
|
//#endregion
|
|
340
|
-
export {
|
|
355
|
+
export { VisualEdge as A, NodeConfig as C, SinglePathOptions as D, PortDirection as E, VisualNode as F, VisualPort as I, WalkContext as L, VisualGraphConfig as M, VisualGraphEntity as N, TransitionOptions as O, VisualGraphFormatConverter as P, WalkOptions as R, NodeChange as S, PortConfig as T, GraphPatch as _, EdgeChange as a, GraphStep as b, EntitiesUpdate as c, GraphConfig as d, GraphDiff as f, GraphNode as g, GraphFormatConverter as h, DeleteNodeOptions as i, VisualGraph as j, TraversalOptions as k, EntityRect as l, GraphEntity as m, AllPairsShortestPathsOptions as n, EdgeConfig as o, GraphEdge as p, CoverageStats as r, EntitiesConfig as s, AStarOptions as t, Graph as u, GraphPath as v, PathOptions as w, MSTOptions as x, GraphPort as y, WeightedWalkOptions as z };
|
package/package.json
CHANGED