@statelyai/graph 0.3.0 → 0.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 +12 -11
- package/dist/{adjacency-list-A4_Eiwj3.mjs → adjacency-list-Bv4tfiM3.mjs} +33 -0
- package/dist/{algorithms-DBU7nmIV.mjs → algorithms-CnTmuX9t.mjs} +682 -24
- package/dist/algorithms.d.mts +479 -10
- package/dist/algorithms.mjs +1 -1
- package/dist/converter-C5DlzzHs.mjs +67 -0
- package/dist/{edge-list-DuHMz8hf.mjs → edge-list-R1SUbHwe.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 +53 -5
- 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 +5 -5
- package/dist/formats/gml/index.d.mts +58 -2
- package/dist/formats/gml/index.mjs +59 -4
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/graphml/index.mjs +2 -2
- package/dist/formats/jgf/index.d.mts +51 -2
- package/dist/formats/jgf/index.mjs +54 -5
- package/dist/formats/mermaid/index.d.mts +201 -8
- package/dist/formats/mermaid/index.mjs +365 -26
- package/dist/formats/tgf/index.d.mts +47 -2
- package/dist/formats/tgf/index.mjs +46 -2
- package/dist/formats/xyflow/index.d.mts +73 -0
- package/dist/formats/xyflow/index.mjs +133 -0
- package/dist/index.d.mts +320 -14
- package/dist/index.mjs +117 -9
- package/dist/{indexing-BFFVMnjF.mjs → indexing-DitHphT7.mjs} +37 -7
- package/dist/queries.d.mts +353 -8
- package/dist/queries.mjs +359 -15
- package/dist/{types-B6Tpeerk.d.mts → types-Bq_fmLwW.d.mts} +15 -4
- package/package.json +3 -1
- package/dist/converter-DnbeyE_p.mjs +0 -33
package/README.md
CHANGED
|
@@ -4,17 +4,6 @@ A TypeScript graph library built on plain JSON objects. Supports directed/undire
|
|
|
4
4
|
|
|
5
5
|
Made from our experience at [stately.ai](https://stately.ai), where we build visual tools for complex systems.
|
|
6
6
|
|
|
7
|
-
## Why this library?
|
|
8
|
-
|
|
9
|
-
Graph file formats (GEXF, GraphML) define how to _store_ graphs. Visualization libraries (Cytoscape.js, D3) define how to _render_ them. Neither gives you a good way to _work with_ them in between.
|
|
10
|
-
|
|
11
|
-
This library is the computational layer: plain JSON objects in, algorithms and mutations, plain JSON objects out. No classes, no DOM, no rendering engine — just data and functions.
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
GEXF file → fromGEXF() → Graph → run algorithms, mutate → toCytoscapeJSON() → render
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Your `Graph` is a plain object that survives `JSON.stringify`, `structuredClone`, `postMessage`, and `localStorage` without adapters. Format converters are the I/O ports — read from any supported format, do your work, export to whatever your renderer or database expects.
|
|
18
7
|
|
|
19
8
|
## Install
|
|
20
9
|
|
|
@@ -126,6 +115,18 @@ const back = cytoscapeConverter.from(cyto);
|
|
|
126
115
|
const myConverter = createFormatConverter(myToFn, myFromFn);
|
|
127
116
|
```
|
|
128
117
|
|
|
118
|
+
## Why this library?
|
|
119
|
+
|
|
120
|
+
Graph file formats (GEXF, GraphML) define how to _store_ graphs. Visualization libraries (Cytoscape.js, D3) define how to _render_ them. Neither gives you a good way to _work with_ them in between.
|
|
121
|
+
|
|
122
|
+
This library is the computational layer: plain JSON objects in, algorithms and mutations, plain JSON objects out. No classes, no DOM, no rendering engine; just data and functions.
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
GEXF file → fromGEXF() → Graph → run algorithms, mutate → toCytoscapeJSON() → render
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Your `Graph` is a plain object that survives `JSON.stringify`, `structuredClone`, `postMessage`, and `localStorage` without adapters. Format converters are the I/O ports: read from any supported format, do your work, export to whatever your renderer or database expects.
|
|
129
|
+
|
|
129
130
|
## API
|
|
130
131
|
|
|
131
132
|
### Graph Creation
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
//#region src/formats/adjacency-list/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a graph to an adjacency list representation.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { createGraph, toAdjacencyList } from '@statelyai/graph';
|
|
8
|
+
*
|
|
9
|
+
* const graph = createGraph({
|
|
10
|
+
* nodes: { a: {}, b: {}, c: {} },
|
|
11
|
+
* edges: [{ source: 'a', target: 'b' }, { source: 'a', target: 'c' }],
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* toAdjacencyList(graph);
|
|
15
|
+
* // { a: ['b', 'c'], b: [], c: [] }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
2
18
|
function toAdjacencyList(graph) {
|
|
3
19
|
const adj = {};
|
|
4
20
|
for (const node of graph.nodes) adj[node.id] = [];
|
|
@@ -8,6 +24,23 @@ function toAdjacencyList(graph) {
|
|
|
8
24
|
}
|
|
9
25
|
return adj;
|
|
10
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Parses an adjacency list into a graph.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { fromAdjacencyList } from '@statelyai/graph';
|
|
33
|
+
*
|
|
34
|
+
* const graph = fromAdjacencyList({
|
|
35
|
+
* a: ['b', 'c'],
|
|
36
|
+
* b: ['c'],
|
|
37
|
+
* c: [],
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* graph.nodes; // [{id: 'a', ...}, {id: 'b', ...}, {id: 'c', ...}]
|
|
41
|
+
* graph.edges; // [{sourceId: 'a', targetId: 'b', ...}, ...]
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
11
44
|
function fromAdjacencyList(adj, options) {
|
|
12
45
|
const directed = options?.directed ?? true;
|
|
13
46
|
const seen = /* @__PURE__ */ new Set();
|