@statelyai/graph 0.3.0 → 0.3.1
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/{adjacency-list-A4_Eiwj3.mjs → adjacency-list-ITO40kmn.mjs} +33 -0
- package/dist/{algorithms-DBU7nmIV.mjs → algorithms-NWSB2RWj.mjs} +672 -19
- package/dist/algorithms.d.mts +479 -10
- package/dist/algorithms.mjs +1 -1
- package/dist/converter-CchokMDg.mjs +67 -0
- package/dist/{edge-list-DuHMz8hf.mjs → edge-list-CgX6bBIF.mjs} +32 -0
- package/dist/formats/adjacency-list/index.d.mts +35 -1
- package/dist/formats/adjacency-list/index.mjs +1 -1
- package/dist/formats/converter/index.d.mts +37 -3
- package/dist/formats/converter/index.mjs +1 -1
- package/dist/formats/cytoscape/index.d.mts +50 -2
- package/dist/formats/cytoscape/index.mjs +50 -2
- package/dist/formats/d3/index.d.mts +48 -2
- package/dist/formats/d3/index.mjs +48 -2
- package/dist/formats/dot/index.d.mts +56 -2
- package/dist/formats/dot/index.mjs +55 -2
- package/dist/formats/edge-list/index.d.mts +34 -1
- package/dist/formats/edge-list/index.mjs +1 -1
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gexf/index.mjs +1 -1
- package/dist/formats/gml/index.d.mts +58 -2
- package/dist/formats/gml/index.mjs +57 -2
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/graphml/index.mjs +1 -1
- package/dist/formats/jgf/index.d.mts +51 -2
- package/dist/formats/jgf/index.mjs +51 -2
- package/dist/formats/mermaid/index.d.mts +201 -8
- package/dist/formats/mermaid/index.mjs +361 -22
- package/dist/formats/tgf/index.d.mts +47 -2
- package/dist/formats/tgf/index.mjs +46 -2
- package/dist/index.d.mts +320 -14
- package/dist/index.mjs +115 -7
- package/dist/{indexing-BFFVMnjF.mjs → indexing-eNDrXdDA.mjs} +31 -2
- package/dist/queries.d.mts +353 -8
- package/dist/queries.mjs +352 -8
- package/dist/{types-B6Tpeerk.d.mts → types-BDXC1O5b.d.mts} +1 -1
- package/package.json +1 -1
- package/dist/converter-DnbeyE_p.mjs +0 -33
|
@@ -1,7 +1,41 @@
|
|
|
1
|
-
import { c as Graph } from "../../types-
|
|
1
|
+
import { c as Graph } from "../../types-BDXC1O5b.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/adjacency-list/index.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a graph to an adjacency list representation.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createGraph, toAdjacencyList } from '@statelyai/graph';
|
|
11
|
+
*
|
|
12
|
+
* const graph = createGraph({
|
|
13
|
+
* nodes: { a: {}, b: {}, c: {} },
|
|
14
|
+
* edges: [{ source: 'a', target: 'b' }, { source: 'a', target: 'c' }],
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* toAdjacencyList(graph);
|
|
18
|
+
* // { a: ['b', 'c'], b: [], c: [] }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
declare function toAdjacencyList(graph: Graph): Record<string, string[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Parses an adjacency list into a graph.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { fromAdjacencyList } from '@statelyai/graph';
|
|
28
|
+
*
|
|
29
|
+
* const graph = fromAdjacencyList({
|
|
30
|
+
* a: ['b', 'c'],
|
|
31
|
+
* b: ['c'],
|
|
32
|
+
* c: [],
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* graph.nodes; // [{id: 'a', ...}, {id: 'b', ...}, {id: 'c', ...}]
|
|
36
|
+
* graph.edges; // [{sourceId: 'a', targetId: 'b', ...}, ...]
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
5
39
|
declare function fromAdjacencyList(adj: Record<string, string[]>, options?: {
|
|
6
40
|
directed?: boolean;
|
|
7
41
|
id?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Graph, f as GraphFormatConverter } from "../../types-
|
|
1
|
+
import { c as Graph, f as GraphFormatConverter } from "../../types-BDXC1O5b.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/converter/index.d.ts
|
|
4
4
|
|
|
@@ -19,9 +19,43 @@ import { c as Graph, f as GraphFormatConverter } from "../../types-B6Tpeerk.mjs"
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
declare function createFormatConverter<TSerial>(to: (graph: Graph) => TSerial, from: (input: TSerial) => Graph): GraphFormatConverter<TSerial>;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Bidirectional converter for adjacency-list format (`Record<string, string[]>`).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { adjacencyListConverter, createGraph } from '@statelyai/graph';
|
|
28
|
+
*
|
|
29
|
+
* const graph = createGraph({
|
|
30
|
+
* nodes: { a: {}, b: {} },
|
|
31
|
+
* edges: [{ source: 'a', target: 'b' }],
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const adj = adjacencyListConverter.to(graph);
|
|
35
|
+
* // { a: ['b'], b: [] }
|
|
36
|
+
*
|
|
37
|
+
* const roundTripped = adjacencyListConverter.from(adj);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
23
40
|
declare const adjacencyListConverter: GraphFormatConverter<Record<string, string[]>>;
|
|
24
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* Bidirectional converter for edge-list format (`[source, target][]`).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { edgeListConverter, createGraph } from '@statelyai/graph';
|
|
47
|
+
*
|
|
48
|
+
* const graph = createGraph({
|
|
49
|
+
* nodes: { a: {}, b: {} },
|
|
50
|
+
* edges: [{ source: 'a', target: 'b' }],
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* const edges = edgeListConverter.to(graph);
|
|
54
|
+
* // [['a', 'b']]
|
|
55
|
+
*
|
|
56
|
+
* const roundTripped = edgeListConverter.from(edges);
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
25
59
|
declare const edgeListConverter: GraphFormatConverter<[string, string][]>;
|
|
26
60
|
//#endregion
|
|
27
61
|
export { adjacencyListConverter, createFormatConverter, edgeListConverter };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter, r as edgeListConverter, t as adjacencyListConverter } from "../../converter-CchokMDg.mjs";
|
|
2
2
|
|
|
3
3
|
export { adjacencyListConverter, createFormatConverter, edgeListConverter };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Graph, f as GraphFormatConverter } from "../../types-
|
|
1
|
+
import { c as Graph, f as GraphFormatConverter } from "../../types-BDXC1O5b.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/cytoscape/index.d.ts
|
|
4
4
|
interface CytoscapeNode {
|
|
@@ -27,9 +27,57 @@ interface CytoscapeJSON {
|
|
|
27
27
|
edges: CytoscapeEdge[];
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a graph to Cytoscape.js JSON format.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createGraph } from '@statelyai/graph';
|
|
36
|
+
* import { toCytoscapeJSON } from '@statelyai/graph/formats/cytoscape';
|
|
37
|
+
*
|
|
38
|
+
* const graph = createGraph({
|
|
39
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
40
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* const cyto = toCytoscapeJSON(graph);
|
|
44
|
+
* // { elements: { nodes: [...], edges: [...] } }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
30
47
|
declare function toCytoscapeJSON(graph: Graph): CytoscapeJSON;
|
|
48
|
+
/**
|
|
49
|
+
* Parses a Cytoscape.js JSON object into a graph.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { fromCytoscapeJSON } from '@statelyai/graph/formats/cytoscape';
|
|
54
|
+
*
|
|
55
|
+
* const graph = fromCytoscapeJSON({
|
|
56
|
+
* elements: {
|
|
57
|
+
* nodes: [{ data: { id: 'a' } }, { data: { id: 'b' } }],
|
|
58
|
+
* edges: [{ data: { id: 'e0', source: 'a', target: 'b' } }],
|
|
59
|
+
* },
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
31
63
|
declare function fromCytoscapeJSON(cyto: CytoscapeJSON): Graph;
|
|
32
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Bidirectional converter for Cytoscape.js JSON format.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { createGraph } from '@statelyai/graph';
|
|
70
|
+
* import { cytoscapeConverter } from '@statelyai/graph/formats/cytoscape';
|
|
71
|
+
*
|
|
72
|
+
* const graph = createGraph({
|
|
73
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
74
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* const cyto = cytoscapeConverter.to(graph);
|
|
78
|
+
* const roundTripped = cytoscapeConverter.from(cyto);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
33
81
|
declare const cytoscapeConverter: GraphFormatConverter<CytoscapeJSON>;
|
|
34
82
|
//#endregion
|
|
35
83
|
export { CytoscapeEdge, CytoscapeJSON, CytoscapeNode, cytoscapeConverter, fromCytoscapeJSON, toCytoscapeJSON };
|
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-CchokMDg.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/cytoscape/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a graph to Cytoscape.js JSON format.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createGraph } from '@statelyai/graph';
|
|
10
|
+
* import { toCytoscapeJSON } from '@statelyai/graph/formats/cytoscape';
|
|
11
|
+
*
|
|
12
|
+
* const graph = createGraph({
|
|
13
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
14
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const cyto = toCytoscapeJSON(graph);
|
|
18
|
+
* // { elements: { nodes: [...], edges: [...] } }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
function toCytoscapeJSON(graph) {
|
|
5
22
|
const graphData = {};
|
|
6
23
|
if (graph.id) graphData.id = graph.id;
|
|
@@ -42,6 +59,21 @@ function toCytoscapeJSON(graph) {
|
|
|
42
59
|
}
|
|
43
60
|
};
|
|
44
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Parses a Cytoscape.js JSON object into a graph.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { fromCytoscapeJSON } from '@statelyai/graph/formats/cytoscape';
|
|
68
|
+
*
|
|
69
|
+
* const graph = fromCytoscapeJSON({
|
|
70
|
+
* elements: {
|
|
71
|
+
* nodes: [{ data: { id: 'a' } }, { data: { id: 'b' } }],
|
|
72
|
+
* edges: [{ data: { id: 'e0', source: 'a', target: 'b' } }],
|
|
73
|
+
* },
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
45
77
|
function fromCytoscapeJSON(cyto) {
|
|
46
78
|
if (!cyto || typeof cyto !== "object") throw new Error("Cytoscape: expected an object");
|
|
47
79
|
if (!cyto.elements || typeof cyto.elements !== "object") throw new Error("Cytoscape: missing \"elements\" property");
|
|
@@ -80,7 +112,23 @@ function fromCytoscapeJSON(cyto) {
|
|
|
80
112
|
}))
|
|
81
113
|
};
|
|
82
114
|
}
|
|
83
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Bidirectional converter for Cytoscape.js JSON format.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { createGraph } from '@statelyai/graph';
|
|
121
|
+
* import { cytoscapeConverter } from '@statelyai/graph/formats/cytoscape';
|
|
122
|
+
*
|
|
123
|
+
* const graph = createGraph({
|
|
124
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
125
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* const cyto = cytoscapeConverter.to(graph);
|
|
129
|
+
* const roundTripped = cytoscapeConverter.from(cyto);
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
84
132
|
const cytoscapeConverter = createFormatConverter(toCytoscapeJSON, fromCytoscapeJSON);
|
|
85
133
|
|
|
86
134
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Graph, f as GraphFormatConverter } from "../../types-
|
|
1
|
+
import { c as Graph, f as GraphFormatConverter } from "../../types-BDXC1O5b.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/d3/index.d.ts
|
|
4
4
|
interface D3Node {
|
|
@@ -14,9 +14,55 @@ interface D3Graph {
|
|
|
14
14
|
nodes: D3Node[];
|
|
15
15
|
links: D3Link[];
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Converts a graph to D3.js force-directed format.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { createGraph } from '@statelyai/graph';
|
|
23
|
+
* import { toD3Graph } from '@statelyai/graph/formats/d3';
|
|
24
|
+
*
|
|
25
|
+
* const graph = createGraph({
|
|
26
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
27
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const d3 = toD3Graph(graph);
|
|
31
|
+
* // { nodes: [{ id: 'a' }, { id: 'b' }], links: [{ source: 'a', target: 'b' }] }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
17
34
|
declare function toD3Graph(graph: Graph): D3Graph;
|
|
35
|
+
/**
|
|
36
|
+
* Parses a D3.js force-directed JSON object into a graph.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { fromD3Graph } from '@statelyai/graph/formats/d3';
|
|
41
|
+
*
|
|
42
|
+
* const graph = fromD3Graph({
|
|
43
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
44
|
+
* links: [{ source: 'a', target: 'b' }],
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
18
48
|
declare function fromD3Graph(d3: D3Graph): Graph;
|
|
19
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* Bidirectional converter for D3.js force-directed JSON format.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { createGraph } from '@statelyai/graph';
|
|
55
|
+
* import { d3Converter } from '@statelyai/graph/formats/d3';
|
|
56
|
+
*
|
|
57
|
+
* const graph = createGraph({
|
|
58
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
59
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* const d3 = d3Converter.to(graph);
|
|
63
|
+
* const roundTripped = d3Converter.from(d3);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
20
66
|
declare const d3Converter: GraphFormatConverter<D3Graph>;
|
|
21
67
|
//#endregion
|
|
22
68
|
export { D3Graph, D3Link, D3Node, d3Converter, fromD3Graph, toD3Graph };
|
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-CchokMDg.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/d3/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a graph to D3.js force-directed format.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createGraph } from '@statelyai/graph';
|
|
10
|
+
* import { toD3Graph } from '@statelyai/graph/formats/d3';
|
|
11
|
+
*
|
|
12
|
+
* const graph = createGraph({
|
|
13
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
14
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const d3 = toD3Graph(graph);
|
|
18
|
+
* // { nodes: [{ id: 'a' }, { id: 'b' }], links: [{ source: 'a', target: 'b' }] }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
function toD3Graph(graph) {
|
|
5
22
|
return {
|
|
6
23
|
nodes: graph.nodes.map((n) => {
|
|
@@ -26,6 +43,19 @@ function toD3Graph(graph) {
|
|
|
26
43
|
})
|
|
27
44
|
};
|
|
28
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Parses a D3.js force-directed JSON object into a graph.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { fromD3Graph } from '@statelyai/graph/formats/d3';
|
|
52
|
+
*
|
|
53
|
+
* const graph = fromD3Graph({
|
|
54
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
55
|
+
* links: [{ source: 'a', target: 'b' }],
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
29
59
|
function fromD3Graph(d3) {
|
|
30
60
|
if (!d3 || typeof d3 !== "object") throw new Error("D3: expected an object");
|
|
31
61
|
if (!Array.isArray(d3.nodes)) throw new Error("D3: \"nodes\" must be an array");
|
|
@@ -58,7 +88,23 @@ function fromD3Graph(d3) {
|
|
|
58
88
|
}))
|
|
59
89
|
};
|
|
60
90
|
}
|
|
61
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Bidirectional converter for D3.js force-directed JSON format.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { createGraph } from '@statelyai/graph';
|
|
97
|
+
* import { d3Converter } from '@statelyai/graph/formats/d3';
|
|
98
|
+
*
|
|
99
|
+
* const graph = createGraph({
|
|
100
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
101
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
102
|
+
* });
|
|
103
|
+
*
|
|
104
|
+
* const d3 = d3Converter.to(graph);
|
|
105
|
+
* const roundTripped = d3Converter.from(d3);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
62
108
|
const d3Converter = createFormatConverter(toD3Graph, fromD3Graph);
|
|
63
109
|
|
|
64
110
|
//#endregion
|
|
@@ -1,9 +1,63 @@
|
|
|
1
|
-
import { c as Graph, f as GraphFormatConverter } from "../../types-
|
|
1
|
+
import { c as Graph, f as GraphFormatConverter } from "../../types-BDXC1O5b.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/dot/index.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a graph to a DOT (Graphviz) format string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createGraph, toDOT } from '@statelyai/graph';
|
|
11
|
+
*
|
|
12
|
+
* const graph = createGraph({
|
|
13
|
+
* nodes: { a: {}, b: {} },
|
|
14
|
+
* edges: [{ source: 'a', target: 'b' }],
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* const dot = toDOT(graph);
|
|
18
|
+
* // digraph "" {
|
|
19
|
+
* // a;
|
|
20
|
+
* // b;
|
|
21
|
+
* // a -> b;
|
|
22
|
+
* // }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
4
25
|
declare function toDOT(graph: Graph): string;
|
|
26
|
+
/**
|
|
27
|
+
* Parses a DOT (Graphviz) format string into a graph.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { fromDOT } from '@statelyai/graph';
|
|
32
|
+
*
|
|
33
|
+
* const graph = fromDOT(`
|
|
34
|
+
* digraph {
|
|
35
|
+
* a -> b;
|
|
36
|
+
* b -> c;
|
|
37
|
+
* }
|
|
38
|
+
* `);
|
|
39
|
+
*
|
|
40
|
+
* graph.nodes; // [{id: 'a', ...}, {id: 'b', ...}, {id: 'c', ...}]
|
|
41
|
+
* graph.edges; // [{sourceId: 'a', targetId: 'b', ...}, ...]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
5
44
|
declare function fromDOT(dot: string): Graph;
|
|
6
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* Bidirectional converter for DOT (Graphviz) format.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { dotConverter, createGraph } from '@statelyai/graph';
|
|
51
|
+
*
|
|
52
|
+
* const graph = createGraph({
|
|
53
|
+
* nodes: { a: {}, b: {} },
|
|
54
|
+
* edges: [{ source: 'a', target: 'b' }],
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* const dot = dotConverter.to(graph);
|
|
58
|
+
* const roundTripped = dotConverter.from(dot);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
7
61
|
declare const dotConverter: GraphFormatConverter<string>;
|
|
8
62
|
//#endregion
|
|
9
63
|
export { dotConverter, fromDOT, toDOT };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-CchokMDg.mjs";
|
|
2
2
|
import parse from "dotparser";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/dot/index.ts
|
|
@@ -26,6 +26,26 @@ const SHAPE_TO_DOT = {
|
|
|
26
26
|
cylinder: "cylinder",
|
|
27
27
|
parallelogram: "parallelogram"
|
|
28
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Converts a graph to a DOT (Graphviz) format string.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { createGraph, toDOT } from '@statelyai/graph';
|
|
35
|
+
*
|
|
36
|
+
* const graph = createGraph({
|
|
37
|
+
* nodes: { a: {}, b: {} },
|
|
38
|
+
* edges: [{ source: 'a', target: 'b' }],
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const dot = toDOT(graph);
|
|
42
|
+
* // digraph "" {
|
|
43
|
+
* // a;
|
|
44
|
+
* // b;
|
|
45
|
+
* // a -> b;
|
|
46
|
+
* // }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
29
49
|
function toDOT(graph) {
|
|
30
50
|
const isDirected = graph.type === "directed";
|
|
31
51
|
const keyword = isDirected ? "digraph" : "graph";
|
|
@@ -100,6 +120,24 @@ function nodeFromAttrs(id, attrs, defaults, parentId) {
|
|
|
100
120
|
...color && { color }
|
|
101
121
|
};
|
|
102
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Parses a DOT (Graphviz) format string into a graph.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { fromDOT } from '@statelyai/graph';
|
|
129
|
+
*
|
|
130
|
+
* const graph = fromDOT(`
|
|
131
|
+
* digraph {
|
|
132
|
+
* a -> b;
|
|
133
|
+
* b -> c;
|
|
134
|
+
* }
|
|
135
|
+
* `);
|
|
136
|
+
*
|
|
137
|
+
* graph.nodes; // [{id: 'a', ...}, {id: 'b', ...}, {id: 'c', ...}]
|
|
138
|
+
* graph.edges; // [{sourceId: 'a', targetId: 'b', ...}, ...]
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
103
141
|
function fromDOT(dot) {
|
|
104
142
|
if (typeof dot !== "string") throw new Error("DOT: expected a string");
|
|
105
143
|
if (!dot.trim()) throw new Error("DOT: input is empty");
|
|
@@ -228,7 +266,22 @@ function fromDOT(dot) {
|
|
|
228
266
|
...direction && { direction }
|
|
229
267
|
};
|
|
230
268
|
}
|
|
231
|
-
/**
|
|
269
|
+
/**
|
|
270
|
+
* Bidirectional converter for DOT (Graphviz) format.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* import { dotConverter, createGraph } from '@statelyai/graph';
|
|
275
|
+
*
|
|
276
|
+
* const graph = createGraph({
|
|
277
|
+
* nodes: { a: {}, b: {} },
|
|
278
|
+
* edges: [{ source: 'a', target: 'b' }],
|
|
279
|
+
* });
|
|
280
|
+
*
|
|
281
|
+
* const dot = dotConverter.to(graph);
|
|
282
|
+
* const roundTripped = dotConverter.from(dot);
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
232
285
|
const dotConverter = createFormatConverter(toDOT, fromDOT);
|
|
233
286
|
|
|
234
287
|
//#endregion
|
|
@@ -1,7 +1,40 @@
|
|
|
1
|
-
import { c as Graph } from "../../types-
|
|
1
|
+
import { c as Graph } from "../../types-BDXC1O5b.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/edge-list/index.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a graph to an edge list of `[source, target]` tuples.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createGraph, toEdgeList } from '@statelyai/graph';
|
|
11
|
+
*
|
|
12
|
+
* const graph = createGraph({
|
|
13
|
+
* nodes: { a: {}, b: {}, c: {} },
|
|
14
|
+
* edges: [{ source: 'a', target: 'b' }, { source: 'b', target: 'c' }],
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* toEdgeList(graph);
|
|
18
|
+
* // [['a', 'b'], ['b', 'c']]
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
declare function toEdgeList(graph: Graph): [string, string][];
|
|
22
|
+
/**
|
|
23
|
+
* Parses an edge list of `[source, target]` tuples into a graph.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { fromEdgeList } from '@statelyai/graph';
|
|
28
|
+
*
|
|
29
|
+
* const graph = fromEdgeList([
|
|
30
|
+
* ['a', 'b'],
|
|
31
|
+
* ['b', 'c'],
|
|
32
|
+
* ]);
|
|
33
|
+
*
|
|
34
|
+
* graph.nodes; // [{id: 'a', ...}, {id: 'b', ...}, {id: 'c', ...}]
|
|
35
|
+
* graph.edges; // [{sourceId: 'a', targetId: 'b', ...}, ...]
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
5
38
|
declare function fromEdgeList(edges: [string, string][], options?: {
|
|
6
39
|
directed?: boolean;
|
|
7
40
|
id?: string;
|
|
@@ -1,9 +1,65 @@
|
|
|
1
|
-
import { c as Graph, f as GraphFormatConverter } from "../../types-
|
|
1
|
+
import { c as Graph, f as GraphFormatConverter } from "../../types-BDXC1O5b.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/gml/index.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a graph to GML (Graph Modelling Language) string.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createGraph } from '@statelyai/graph';
|
|
11
|
+
* import { toGML } from '@statelyai/graph/formats/gml';
|
|
12
|
+
*
|
|
13
|
+
* const graph = createGraph({
|
|
14
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
15
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const gml = toGML(graph);
|
|
19
|
+
* // graph [
|
|
20
|
+
* // directed 1
|
|
21
|
+
* // node [ id "a" ]
|
|
22
|
+
* // node [ id "b" ]
|
|
23
|
+
* // edge [ id "e0" source "a" target "b" ]
|
|
24
|
+
* // ]
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
4
27
|
declare function toGML(graph: Graph): string;
|
|
28
|
+
/**
|
|
29
|
+
* Parses a GML (Graph Modelling Language) string into a graph.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { fromGML } from '@statelyai/graph/formats/gml';
|
|
34
|
+
*
|
|
35
|
+
* const graph = fromGML(`
|
|
36
|
+
* graph [
|
|
37
|
+
* directed 1
|
|
38
|
+
* node [ id "a" ]
|
|
39
|
+
* node [ id "b" ]
|
|
40
|
+
* edge [ source "a" target "b" ]
|
|
41
|
+
* ]
|
|
42
|
+
* `);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
5
45
|
declare function fromGML(gml: string): Graph;
|
|
6
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Bidirectional converter for GML (Graph Modelling Language) format.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { createGraph } from '@statelyai/graph';
|
|
52
|
+
* import { gmlConverter } from '@statelyai/graph/formats/gml';
|
|
53
|
+
*
|
|
54
|
+
* const graph = createGraph({
|
|
55
|
+
* nodes: [{ id: 'a' }, { id: 'b' }],
|
|
56
|
+
* edges: [{ id: 'e0', sourceId: 'a', targetId: 'b' }],
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* const gml = gmlConverter.to(graph);
|
|
60
|
+
* const roundTripped = gmlConverter.from(gml);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
7
63
|
declare const gmlConverter: GraphFormatConverter<string>;
|
|
8
64
|
//#endregion
|
|
9
65
|
export { fromGML, gmlConverter, toGML };
|