@statelyai/graph 0.12.0 → 1.0.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 +26 -16
- package/dist/{adjacency-list-Ca0VjKIf.mjs → adjacency-list-VsUaH9SJ.mjs} +2 -2
- package/dist/{algorithms-BHHg7lGq.mjs → algorithms-Ba7o7niK.mjs} +35 -31
- package/dist/{algorithms-BlM-qoJb.d.mts → algorithms-fTqmvhzP.d.mts} +1 -1
- package/dist/algorithms.d.mts +1 -1
- package/dist/algorithms.mjs +1 -1
- package/dist/{converter-Dspillnn.mjs → converter-udLITX36.mjs} +2 -2
- package/dist/{edge-list-gKe8-iRa.mjs → edge-list-DP4otyPU.mjs} +1 -1
- package/dist/format-support.d.mts +6 -0
- package/dist/format-support.mjs +68 -33
- package/dist/formats/adjacency-list/index.d.mts +1 -1
- package/dist/formats/adjacency-list/index.mjs +1 -1
- package/dist/formats/converter/index.d.mts +1 -60
- package/dist/formats/converter/index.mjs +1 -1
- package/dist/formats/cytoscape/index.d.mts +1 -1
- package/dist/formats/cytoscape/index.mjs +19 -3
- package/dist/formats/d2/index.d.mts +109 -0
- package/dist/formats/d2/index.mjs +1086 -0
- package/dist/formats/d3/index.d.mts +8 -1
- package/dist/formats/d3/index.mjs +35 -7
- package/dist/formats/dot/index.d.mts +1 -1
- package/dist/formats/dot/index.mjs +3 -3
- package/dist/formats/edge-list/index.d.mts +1 -1
- package/dist/formats/edge-list/index.mjs +1 -1
- package/dist/formats/elk/index.d.mts +1 -1
- package/dist/formats/elk/index.mjs +86 -23
- package/dist/formats/gexf/index.d.mts +1 -1
- package/dist/formats/gexf/index.mjs +102 -4
- package/dist/formats/gml/index.d.mts +1 -1
- package/dist/formats/gml/index.mjs +43 -16
- package/dist/formats/graphml/index.d.mts +1 -1
- package/dist/formats/graphml/index.mjs +11 -4
- package/dist/formats/jgf/index.d.mts +1 -1
- package/dist/formats/jgf/index.mjs +19 -3
- package/dist/formats/mermaid/index.d.mts +2 -1
- package/dist/formats/mermaid/index.mjs +48 -18
- package/dist/formats/tgf/index.d.mts +1 -1
- package/dist/formats/tgf/index.mjs +2 -2
- package/dist/formats/xyflow/index.d.mts +2 -1
- package/dist/formats/xyflow/index.mjs +97 -40
- package/dist/index-CHoriXZD.d.mts +638 -0
- package/dist/index-D9Kj6Fe3.d.mts +61 -0
- package/dist/index.d.mts +6 -631
- package/dist/index.mjs +8 -7
- package/dist/{indexing-CJc-ul8e.mjs → indexing-DR8M1vBy.mjs} +18 -4
- package/dist/mode-D8OnHFBk.mjs +15 -0
- package/dist/queries-BlkA1HAN.d.mts +516 -0
- package/dist/queries.d.mts +1 -514
- package/dist/queries.mjs +17 -15
- package/dist/schemas.d.mts +29 -17
- package/dist/schemas.mjs +139 -6
- package/dist/{types-CnZ01raw.d.mts → types-3-FS9NV2.d.mts} +30 -7
- package/package.json +2 -1
- package/schemas/edge.schema.json +11 -0
- package/schemas/graph.schema.json +25 -3
- package/schemas/node.schema.json +7 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as GraphFormatConverter, u as Graph } from "../../types-
|
|
1
|
+
import { h as GraphFormatConverter, u as Graph } from "../../types-3-FS9NV2.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/d3/index.d.ts
|
|
4
4
|
interface D3Node {
|
|
@@ -11,8 +11,15 @@ interface D3Link {
|
|
|
11
11
|
[key: string]: any;
|
|
12
12
|
}
|
|
13
13
|
interface D3Graph {
|
|
14
|
+
id?: string;
|
|
15
|
+
mode?: Graph['mode'];
|
|
16
|
+
initialNodeId?: string | null;
|
|
17
|
+
data?: any;
|
|
18
|
+
direction?: Graph['direction'];
|
|
19
|
+
style?: Graph['style'];
|
|
14
20
|
nodes: D3Node[];
|
|
15
21
|
links: D3Link[];
|
|
22
|
+
[key: string]: any;
|
|
16
23
|
}
|
|
17
24
|
/**
|
|
18
25
|
* Converts a graph to D3.js force-directed format.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-udLITX36.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/d3/index.ts
|
|
4
4
|
/**
|
|
@@ -20,14 +20,25 @@ import { n as createFormatConverter } from "../../converter-Dspillnn.mjs";
|
|
|
20
20
|
*/
|
|
21
21
|
function toD3Graph(graph) {
|
|
22
22
|
return {
|
|
23
|
+
...graph.id && { id: graph.id },
|
|
24
|
+
mode: graph.mode,
|
|
25
|
+
initialNodeId: graph.initialNodeId,
|
|
26
|
+
...graph.data !== void 0 && { data: graph.data },
|
|
27
|
+
...graph.direction && { direction: graph.direction },
|
|
28
|
+
...graph.style !== void 0 && { style: graph.style },
|
|
23
29
|
nodes: graph.nodes.map((n) => {
|
|
24
30
|
const node = { id: n.id };
|
|
31
|
+
if (n.parentId) node.parentId = n.parentId;
|
|
32
|
+
if (n.initialNodeId) node.initialNodeId = n.initialNodeId;
|
|
25
33
|
if (n.label) node.label = n.label;
|
|
26
34
|
if (n.data !== void 0) node.data = n.data;
|
|
27
35
|
if (n.x !== void 0) node.x = n.x;
|
|
28
36
|
if (n.y !== void 0) node.y = n.y;
|
|
37
|
+
if (n.width !== void 0) node.width = n.width;
|
|
38
|
+
if (n.height !== void 0) node.height = n.height;
|
|
29
39
|
if (n.color) node.color = n.color;
|
|
30
40
|
if (n.shape) node.shape = n.shape;
|
|
41
|
+
if (n.style !== void 0) node.style = n.style;
|
|
31
42
|
if (n.ports !== void 0) node.ports = n.ports;
|
|
32
43
|
return node;
|
|
33
44
|
}),
|
|
@@ -39,7 +50,13 @@ function toD3Graph(graph) {
|
|
|
39
50
|
if (e.id) link.id = e.id;
|
|
40
51
|
if (e.label) link.label = e.label;
|
|
41
52
|
if (e.data !== void 0) link.data = e.data;
|
|
53
|
+
if (e.weight !== void 0) link.weight = e.weight;
|
|
54
|
+
if (e.x !== void 0) link.x = e.x;
|
|
55
|
+
if (e.y !== void 0) link.y = e.y;
|
|
56
|
+
if (e.width !== void 0) link.width = e.width;
|
|
57
|
+
if (e.height !== void 0) link.height = e.height;
|
|
42
58
|
if (e.color) link.color = e.color;
|
|
59
|
+
if (e.style !== void 0) link.style = e.style;
|
|
43
60
|
if (e.sourcePort !== void 0) link.sourcePort = e.sourcePort;
|
|
44
61
|
if (e.targetPort !== void 0) link.targetPort = e.targetPort;
|
|
45
62
|
return link;
|
|
@@ -64,21 +81,26 @@ function fromD3Graph(d3) {
|
|
|
64
81
|
if (!Array.isArray(d3.nodes)) throw new Error("D3: \"nodes\" must be an array");
|
|
65
82
|
if (!Array.isArray(d3.links)) throw new Error("D3: \"links\" must be an array");
|
|
66
83
|
return {
|
|
67
|
-
id: "",
|
|
68
|
-
|
|
69
|
-
initialNodeId: null,
|
|
70
|
-
data:
|
|
84
|
+
id: d3.id ?? "",
|
|
85
|
+
mode: d3.mode ?? "directed",
|
|
86
|
+
initialNodeId: d3.initialNodeId ?? null,
|
|
87
|
+
data: d3.data,
|
|
88
|
+
...d3.direction && { direction: d3.direction },
|
|
89
|
+
...d3.style !== void 0 && { style: d3.style },
|
|
71
90
|
nodes: d3.nodes.map((n) => ({
|
|
72
91
|
type: "node",
|
|
73
92
|
id: n.id,
|
|
74
|
-
parentId: null,
|
|
75
|
-
initialNodeId: null,
|
|
93
|
+
parentId: n.parentId ?? null,
|
|
94
|
+
initialNodeId: n.initialNodeId ?? null,
|
|
76
95
|
label: n.label ?? "",
|
|
77
96
|
data: n.data,
|
|
78
97
|
...n.x !== void 0 && { x: n.x },
|
|
79
98
|
...n.y !== void 0 && { y: n.y },
|
|
99
|
+
...n.width !== void 0 && { width: n.width },
|
|
100
|
+
...n.height !== void 0 && { height: n.height },
|
|
80
101
|
...n.color && { color: n.color },
|
|
81
102
|
...n.shape && { shape: n.shape },
|
|
103
|
+
...n.style !== void 0 && { style: n.style },
|
|
82
104
|
...n.ports !== void 0 && { ports: n.ports }
|
|
83
105
|
})),
|
|
84
106
|
edges: d3.links.map((l, i) => ({
|
|
@@ -88,7 +110,13 @@ function fromD3Graph(d3) {
|
|
|
88
110
|
targetId: typeof l.target === "string" ? l.target : l.target.id,
|
|
89
111
|
label: l.label ?? "",
|
|
90
112
|
data: l.data,
|
|
113
|
+
...l.weight !== void 0 && { weight: l.weight },
|
|
114
|
+
...l.x !== void 0 && { x: l.x },
|
|
115
|
+
...l.y !== void 0 && { y: l.y },
|
|
116
|
+
...l.width !== void 0 && { width: l.width },
|
|
117
|
+
...l.height !== void 0 && { height: l.height },
|
|
91
118
|
...l.color && { color: l.color },
|
|
119
|
+
...l.style !== void 0 && { style: l.style },
|
|
92
120
|
...l.sourcePort !== void 0 && { sourcePort: l.sourcePort },
|
|
93
121
|
...l.targetPort !== void 0 && { targetPort: l.targetPort }
|
|
94
122
|
}))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-udLITX36.mjs";
|
|
2
2
|
import parse from "dotparser";
|
|
3
3
|
|
|
4
4
|
//#region src/formats/dot/index.ts
|
|
@@ -50,7 +50,7 @@ const SHAPE_TO_DOT = {
|
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
function toDOT(graph) {
|
|
53
|
-
const isDirected = graph.
|
|
53
|
+
const isDirected = graph.mode !== "undirected";
|
|
54
54
|
const keyword = isDirected ? "digraph" : "graph";
|
|
55
55
|
const edgeOp = isDirected ? "->" : "--";
|
|
56
56
|
const lines = [];
|
|
@@ -270,7 +270,7 @@ function fromDOT(dot) {
|
|
|
270
270
|
walkChildren(root.children, null, {}, {});
|
|
271
271
|
return {
|
|
272
272
|
id: root.id ?? "",
|
|
273
|
-
|
|
273
|
+
mode: isDirected ? "directed" : "undirected",
|
|
274
274
|
initialNodeId: null,
|
|
275
275
|
nodes: [...nodeMap.values()],
|
|
276
276
|
edges,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as VisualGraphFormatConverter, M as VisualGraph } from "../../types-3-FS9NV2.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,6 +1,23 @@
|
|
|
1
1
|
import { getChildren } from "../../queries.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/elk/index.ts
|
|
4
|
+
const STATELYAI_METADATA_KEY = "statelyai.metadata";
|
|
5
|
+
function addMetadata(target, metadata) {
|
|
6
|
+
target.layoutOptions = {
|
|
7
|
+
...target.layoutOptions ?? {},
|
|
8
|
+
[STATELYAI_METADATA_KEY]: JSON.stringify(metadata)
|
|
9
|
+
};
|
|
10
|
+
return target;
|
|
11
|
+
}
|
|
12
|
+
function readMetadata(value) {
|
|
13
|
+
const raw = value.layoutOptions?.[STATELYAI_METADATA_KEY];
|
|
14
|
+
if (typeof raw !== "string") return void 0;
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
} catch {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
4
21
|
const DIRECTION_TO_ELK = {
|
|
5
22
|
down: "DOWN",
|
|
6
23
|
up: "UP",
|
|
@@ -20,7 +37,21 @@ function convertEdge(edge) {
|
|
|
20
37
|
targets: [edge.targetPort ?? edge.targetId]
|
|
21
38
|
};
|
|
22
39
|
if (edge.label) elkEdge.labels = [{ text: edge.label }];
|
|
23
|
-
return elkEdge
|
|
40
|
+
return addMetadata(elkEdge, { edge: {
|
|
41
|
+
sourceId: edge.sourceId,
|
|
42
|
+
targetId: edge.targetId,
|
|
43
|
+
sourcePort: edge.sourcePort,
|
|
44
|
+
targetPort: edge.targetPort,
|
|
45
|
+
label: edge.label,
|
|
46
|
+
data: edge.data,
|
|
47
|
+
weight: edge.weight,
|
|
48
|
+
color: edge.color,
|
|
49
|
+
style: edge.style,
|
|
50
|
+
x: edge.x,
|
|
51
|
+
y: edge.y,
|
|
52
|
+
width: edge.width,
|
|
53
|
+
height: edge.height
|
|
54
|
+
} });
|
|
24
55
|
}
|
|
25
56
|
function convertPort(port) {
|
|
26
57
|
const elkPort = {
|
|
@@ -32,7 +63,10 @@ function convertPort(port) {
|
|
|
32
63
|
};
|
|
33
64
|
if (port.label) elkPort.labels = [{ text: port.label }];
|
|
34
65
|
if (port.direction !== "inout") elkPort.layoutOptions = { "org.eclipse.elk.port.side": port.direction === "in" ? "WEST" : "EAST" };
|
|
35
|
-
return elkPort
|
|
66
|
+
return addMetadata(elkPort, { port: {
|
|
67
|
+
data: port.data,
|
|
68
|
+
style: port.style
|
|
69
|
+
} });
|
|
36
70
|
}
|
|
37
71
|
function convertNode(graph, node) {
|
|
38
72
|
const elkNode = {
|
|
@@ -44,6 +78,13 @@ function convertNode(graph, node) {
|
|
|
44
78
|
};
|
|
45
79
|
if (node.label) elkNode.labels = [{ text: node.label }];
|
|
46
80
|
if (node.ports && node.ports.length > 0) elkNode.ports = node.ports.map(convertPort);
|
|
81
|
+
addMetadata(elkNode, { node: {
|
|
82
|
+
initialNodeId: node.initialNodeId,
|
|
83
|
+
data: node.data,
|
|
84
|
+
shape: node.shape,
|
|
85
|
+
color: node.color,
|
|
86
|
+
style: node.style
|
|
87
|
+
} });
|
|
47
88
|
const children = getChildren(graph, node.id);
|
|
48
89
|
if (children.length > 0) {
|
|
49
90
|
elkNode.children = children.map((child) => convertNode(graph, child));
|
|
@@ -85,6 +126,14 @@ function toELK(graph) {
|
|
|
85
126
|
const root = { id: graph.id };
|
|
86
127
|
const elkDir = DIRECTION_TO_ELK[graph.direction];
|
|
87
128
|
if (elkDir) root.layoutOptions = { "elk.direction": elkDir };
|
|
129
|
+
addMetadata(root, { graph: {
|
|
130
|
+
id: graph.id,
|
|
131
|
+
mode: graph.mode,
|
|
132
|
+
initialNodeId: graph.initialNodeId,
|
|
133
|
+
data: graph.data,
|
|
134
|
+
direction: graph.direction,
|
|
135
|
+
style: graph.style
|
|
136
|
+
} });
|
|
88
137
|
const roots = getChildren(graph, null);
|
|
89
138
|
if (roots.length > 0) root.children = roots.map((node) => convertNode(graph, node));
|
|
90
139
|
const allInnerEdgeIds = /* @__PURE__ */ new Set();
|
|
@@ -100,20 +149,25 @@ function toELK(graph) {
|
|
|
100
149
|
function flattenElkNodes(elkNode, parentId, nodes, edges, edgeIdx, portOwner) {
|
|
101
150
|
if (elkNode.children) for (const child of elkNode.children) {
|
|
102
151
|
const label = child.labels?.[0]?.text ?? "";
|
|
152
|
+
const metadata = readMetadata(child)?.node;
|
|
103
153
|
const node = {
|
|
104
154
|
type: "node",
|
|
105
155
|
id: child.id,
|
|
106
156
|
parentId,
|
|
107
|
-
initialNodeId: null,
|
|
157
|
+
initialNodeId: metadata && "initialNodeId" in metadata ? metadata.initialNodeId : null,
|
|
108
158
|
label,
|
|
109
|
-
data: void 0,
|
|
159
|
+
data: metadata && "data" in metadata ? metadata.data : void 0,
|
|
110
160
|
x: child.x ?? 0,
|
|
111
161
|
y: child.y ?? 0,
|
|
112
162
|
width: child.width ?? 0,
|
|
113
|
-
height: child.height ?? 0
|
|
163
|
+
height: child.height ?? 0,
|
|
164
|
+
...metadata?.shape !== void 0 && { shape: metadata.shape },
|
|
165
|
+
...metadata?.color !== void 0 && { color: metadata.color },
|
|
166
|
+
...metadata?.style !== void 0 && { style: metadata.style }
|
|
114
167
|
};
|
|
115
168
|
if (child.ports && child.ports.length > 0) node.ports = child.ports.map((elkPort) => {
|
|
116
169
|
portOwner.set(elkPort.id, child.id);
|
|
170
|
+
const metadata$1 = readMetadata(elkPort)?.port;
|
|
117
171
|
const sideOpt = elkPort.layoutOptions?.["org.eclipse.elk.port.side"];
|
|
118
172
|
let direction = "inout";
|
|
119
173
|
if (sideOpt === "WEST") direction = "in";
|
|
@@ -122,33 +176,40 @@ function flattenElkNodes(elkNode, parentId, nodes, edges, edgeIdx, portOwner) {
|
|
|
122
176
|
name: elkPort.id,
|
|
123
177
|
direction,
|
|
124
178
|
label: elkPort.labels?.[0]?.text,
|
|
125
|
-
data: void 0,
|
|
179
|
+
data: metadata$1 && "data" in metadata$1 ? metadata$1.data : void 0,
|
|
126
180
|
x: elkPort.x ?? 0,
|
|
127
181
|
y: elkPort.y ?? 0,
|
|
128
182
|
width: elkPort.width ?? 0,
|
|
129
|
-
height: elkPort.height ?? 0
|
|
183
|
+
height: elkPort.height ?? 0,
|
|
184
|
+
...metadata$1?.style !== void 0 && { style: metadata$1.style }
|
|
130
185
|
};
|
|
131
186
|
});
|
|
132
187
|
nodes.push(node);
|
|
133
188
|
flattenElkNodes(child, child.id, nodes, edges, edgeIdx, portOwner);
|
|
134
189
|
}
|
|
135
190
|
if (elkNode.edges) for (const elkEdge of elkNode.edges) for (const source of elkEdge.sources) for (const target of elkEdge.targets) {
|
|
191
|
+
const metadata = readMetadata(elkEdge)?.edge;
|
|
136
192
|
const sourceNodeId = portOwner.get(source);
|
|
137
193
|
const targetNodeId = portOwner.get(target);
|
|
138
194
|
const edge = {
|
|
139
195
|
type: "edge",
|
|
140
196
|
id: elkEdge.id ?? `e${edgeIdx.value++}`,
|
|
141
|
-
sourceId: sourceNodeId ?? source,
|
|
142
|
-
targetId: targetNodeId ?? target,
|
|
143
|
-
label: elkEdge.labels?.[0]?.text ?? "",
|
|
144
|
-
data: void 0,
|
|
145
|
-
x: 0,
|
|
146
|
-
y: 0,
|
|
147
|
-
width: 0,
|
|
148
|
-
height: 0
|
|
197
|
+
sourceId: metadata?.sourceId ?? sourceNodeId ?? source,
|
|
198
|
+
targetId: metadata?.targetId ?? targetNodeId ?? target,
|
|
199
|
+
label: metadata && "label" in metadata ? metadata.label : elkEdge.labels?.[0]?.text ?? "",
|
|
200
|
+
data: metadata && "data" in metadata ? metadata.data : void 0,
|
|
201
|
+
x: metadata?.x ?? 0,
|
|
202
|
+
y: metadata?.y ?? 0,
|
|
203
|
+
width: metadata?.width ?? 0,
|
|
204
|
+
height: metadata?.height ?? 0,
|
|
205
|
+
...metadata?.weight !== void 0 && { weight: metadata.weight },
|
|
206
|
+
...metadata?.color !== void 0 && { color: metadata.color },
|
|
207
|
+
...metadata?.style !== void 0 && { style: metadata.style }
|
|
149
208
|
};
|
|
150
|
-
if (
|
|
151
|
-
if (
|
|
209
|
+
if (metadata && "sourcePort" in metadata) edge.sourcePort = metadata.sourcePort;
|
|
210
|
+
else if (sourceNodeId) edge.sourcePort = source;
|
|
211
|
+
if (metadata && "targetPort" in metadata) edge.targetPort = metadata.targetPort;
|
|
212
|
+
else if (targetNodeId) edge.targetPort = target;
|
|
152
213
|
edges.push(edge);
|
|
153
214
|
}
|
|
154
215
|
}
|
|
@@ -179,15 +240,17 @@ function fromELK(elkRoot) {
|
|
|
179
240
|
const seenEdges = /* @__PURE__ */ new Map();
|
|
180
241
|
for (const edge of edges) if (!seenEdges.has(edge.id)) seenEdges.set(edge.id, edge);
|
|
181
242
|
const elkDir = elkRoot.layoutOptions?.["elk.direction"];
|
|
182
|
-
const
|
|
243
|
+
const graphMetadata = readMetadata(elkRoot)?.graph;
|
|
244
|
+
const direction = graphMetadata?.direction ?? (elkDir ? ELK_TO_DIRECTION[elkDir] : void 0) ?? "down";
|
|
183
245
|
return {
|
|
184
|
-
id: elkRoot.id,
|
|
185
|
-
|
|
186
|
-
initialNodeId: null,
|
|
246
|
+
id: graphMetadata?.id ?? elkRoot.id,
|
|
247
|
+
mode: graphMetadata?.mode ?? "directed",
|
|
248
|
+
initialNodeId: graphMetadata && "initialNodeId" in graphMetadata ? graphMetadata.initialNodeId : null,
|
|
187
249
|
nodes,
|
|
188
250
|
edges: [...seenEdges.values()],
|
|
189
|
-
data: void 0,
|
|
190
|
-
direction
|
|
251
|
+
data: graphMetadata && "data" in graphMetadata ? graphMetadata.data : void 0,
|
|
252
|
+
direction,
|
|
253
|
+
...graphMetadata?.style !== void 0 && { style: graphMetadata.style }
|
|
191
254
|
};
|
|
192
255
|
}
|
|
193
256
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as getEdgeMode } from "../../mode-D8OnHFBk.mjs";
|
|
2
|
+
import { n as createFormatConverter } from "../../converter-udLITX36.mjs";
|
|
2
3
|
import { XMLBuilder, XMLParser } from "fast-xml-parser";
|
|
3
4
|
|
|
4
5
|
//#region src/formats/gexf/index.ts
|
|
@@ -24,6 +25,21 @@ function toGEXF(graph) {
|
|
|
24
25
|
"@_title": "shape",
|
|
25
26
|
"@_type": "string"
|
|
26
27
|
},
|
|
28
|
+
{
|
|
29
|
+
"@_id": "a_width",
|
|
30
|
+
"@_title": "width",
|
|
31
|
+
"@_type": "double"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"@_id": "a_height",
|
|
35
|
+
"@_title": "height",
|
|
36
|
+
"@_type": "double"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"@_id": "a_style",
|
|
40
|
+
"@_title": "style",
|
|
41
|
+
"@_type": "string"
|
|
42
|
+
},
|
|
27
43
|
{
|
|
28
44
|
"@_id": "a_ports",
|
|
29
45
|
"@_title": "ports",
|
|
@@ -36,6 +52,36 @@ function toGEXF(graph) {
|
|
|
36
52
|
"@_title": "data",
|
|
37
53
|
"@_type": "string"
|
|
38
54
|
},
|
|
55
|
+
{
|
|
56
|
+
"@_id": "a_edgeWeight",
|
|
57
|
+
"@_title": "weight",
|
|
58
|
+
"@_type": "double"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"@_id": "a_edgeX",
|
|
62
|
+
"@_title": "x",
|
|
63
|
+
"@_type": "double"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"@_id": "a_edgeY",
|
|
67
|
+
"@_title": "y",
|
|
68
|
+
"@_type": "double"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"@_id": "a_edgeWidth",
|
|
72
|
+
"@_title": "width",
|
|
73
|
+
"@_type": "double"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"@_id": "a_edgeHeight",
|
|
77
|
+
"@_title": "height",
|
|
78
|
+
"@_type": "double"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"@_id": "a_edgeStyle",
|
|
82
|
+
"@_title": "style",
|
|
83
|
+
"@_type": "string"
|
|
84
|
+
},
|
|
39
85
|
{
|
|
40
86
|
"@_id": "a_sourcePort",
|
|
41
87
|
"@_title": "sourcePort",
|
|
@@ -65,6 +111,18 @@ function toGEXF(graph) {
|
|
|
65
111
|
"@_for": "a_shape",
|
|
66
112
|
"@_value": n.shape
|
|
67
113
|
});
|
|
114
|
+
if (n.width !== void 0) attvalues.push({
|
|
115
|
+
"@_for": "a_width",
|
|
116
|
+
"@_value": n.width
|
|
117
|
+
});
|
|
118
|
+
if (n.height !== void 0) attvalues.push({
|
|
119
|
+
"@_for": "a_height",
|
|
120
|
+
"@_value": n.height
|
|
121
|
+
});
|
|
122
|
+
if (n.style !== void 0) attvalues.push({
|
|
123
|
+
"@_for": "a_style",
|
|
124
|
+
"@_value": JSON.stringify(n.style)
|
|
125
|
+
});
|
|
68
126
|
if (n.ports !== void 0) attvalues.push({
|
|
69
127
|
"@_for": "a_ports",
|
|
70
128
|
"@_value": JSON.stringify(n.ports)
|
|
@@ -90,18 +148,45 @@ function toGEXF(graph) {
|
|
|
90
148
|
if (n.width !== void 0 || n.height !== void 0) node["viz:size"] = { "@_value": n.width ?? n.height ?? 0 };
|
|
91
149
|
return node;
|
|
92
150
|
});
|
|
151
|
+
const graphDirected = graph.mode !== "undirected";
|
|
93
152
|
const edges = graph.edges.map((e) => {
|
|
94
153
|
const edge = {
|
|
95
154
|
"@_id": e.id,
|
|
96
155
|
"@_source": e.sourceId,
|
|
97
156
|
"@_target": e.targetId
|
|
98
157
|
};
|
|
158
|
+
const edgeDirected = getEdgeMode(graph, e) !== "undirected";
|
|
159
|
+
if (edgeDirected !== graphDirected) edge["@_type"] = edgeDirected ? "directed" : "undirected";
|
|
99
160
|
if (e.label) edge["@_label"] = e.label;
|
|
100
161
|
if (e.data !== void 0) edge.attvalues = { attvalue: [{
|
|
101
162
|
"@_for": "a_edgeData",
|
|
102
163
|
"@_value": JSON.stringify(e.data)
|
|
103
164
|
}] };
|
|
104
165
|
const edgeAttvalues = edge.attvalues?.attvalue ?? [];
|
|
166
|
+
if (e.weight !== void 0) edgeAttvalues.push({
|
|
167
|
+
"@_for": "a_edgeWeight",
|
|
168
|
+
"@_value": e.weight
|
|
169
|
+
});
|
|
170
|
+
if (e.x !== void 0) edgeAttvalues.push({
|
|
171
|
+
"@_for": "a_edgeX",
|
|
172
|
+
"@_value": e.x
|
|
173
|
+
});
|
|
174
|
+
if (e.y !== void 0) edgeAttvalues.push({
|
|
175
|
+
"@_for": "a_edgeY",
|
|
176
|
+
"@_value": e.y
|
|
177
|
+
});
|
|
178
|
+
if (e.width !== void 0) edgeAttvalues.push({
|
|
179
|
+
"@_for": "a_edgeWidth",
|
|
180
|
+
"@_value": e.width
|
|
181
|
+
});
|
|
182
|
+
if (e.height !== void 0) edgeAttvalues.push({
|
|
183
|
+
"@_for": "a_edgeHeight",
|
|
184
|
+
"@_value": e.height
|
|
185
|
+
});
|
|
186
|
+
if (e.style !== void 0) edgeAttvalues.push({
|
|
187
|
+
"@_for": "a_edgeStyle",
|
|
188
|
+
"@_value": JSON.stringify(e.style)
|
|
189
|
+
});
|
|
105
190
|
if (e.sourcePort !== void 0) edgeAttvalues.push({
|
|
106
191
|
"@_for": "a_sourcePort",
|
|
107
192
|
"@_value": e.sourcePort
|
|
@@ -131,11 +216,12 @@ function toGEXF(graph) {
|
|
|
131
216
|
"@_xmlns:viz": "http://gexf.net/1.3/viz",
|
|
132
217
|
"@_version": "1.3",
|
|
133
218
|
graph: {
|
|
134
|
-
"@_defaultedgetype": graph.
|
|
219
|
+
"@_defaultedgetype": graph.mode === "undirected" ? "undirected" : "directed",
|
|
135
220
|
...graph.id && { "@_id": graph.id },
|
|
136
221
|
...graph.initialNodeId && { "@_initialNodeId": graph.initialNodeId },
|
|
137
222
|
...graph.direction && { "@_direction": graph.direction },
|
|
138
223
|
...graph.data !== void 0 && { "@_data": JSON.stringify(graph.data) },
|
|
224
|
+
...graph.style !== void 0 && { "@_style": JSON.stringify(graph.style) },
|
|
139
225
|
attributes: [{
|
|
140
226
|
"@_class": "node",
|
|
141
227
|
attribute: nodeAttrs
|
|
@@ -193,6 +279,7 @@ function fromGEXF(xml) {
|
|
|
193
279
|
data: attvals["data"] !== void 0 ? tryParseJSON(attvals["data"]) : void 0
|
|
194
280
|
};
|
|
195
281
|
if (attvals["shape"]) node.shape = attvals["shape"];
|
|
282
|
+
if (attvals["style"] !== void 0) node.style = tryParseJSON(attvals["style"]);
|
|
196
283
|
if (attvals["ports"] !== void 0) node.ports = tryParseJSON(attvals["ports"]);
|
|
197
284
|
const pos = n["viz:position"];
|
|
198
285
|
if (pos) {
|
|
@@ -204,6 +291,8 @@ function fromGEXF(xml) {
|
|
|
204
291
|
node.width = Number(size["@_value"] ?? 0);
|
|
205
292
|
node.height = Number(size["@_value"] ?? 0);
|
|
206
293
|
}
|
|
294
|
+
if (attvals["width"] !== void 0) node.width = Number(attvals["width"]);
|
|
295
|
+
if (attvals["height"] !== void 0) node.height = Number(attvals["height"]);
|
|
207
296
|
const color = n["viz:color"];
|
|
208
297
|
if (color) {
|
|
209
298
|
const r = Number(color["@_r"] ?? 0);
|
|
@@ -226,6 +315,12 @@ function fromGEXF(xml) {
|
|
|
226
315
|
targetId: String(e["@_target"]),
|
|
227
316
|
label: e["@_label"] ?? "",
|
|
228
317
|
data: attvals["data"] !== void 0 ? tryParseJSON(attvals["data"]) : void 0,
|
|
318
|
+
...attvals["weight"] !== void 0 && { weight: Number(attvals["weight"]) },
|
|
319
|
+
...attvals["x"] !== void 0 && { x: Number(attvals["x"]) },
|
|
320
|
+
...attvals["y"] !== void 0 && { y: Number(attvals["y"]) },
|
|
321
|
+
...attvals["width"] !== void 0 && { width: Number(attvals["width"]) },
|
|
322
|
+
...attvals["height"] !== void 0 && { height: Number(attvals["height"]) },
|
|
323
|
+
...attvals["style"] !== void 0 && { style: tryParseJSON(attvals["style"]) },
|
|
229
324
|
...attvals["sourcePort"] !== void 0 && { sourcePort: attvals["sourcePort"] },
|
|
230
325
|
...attvals["targetPort"] !== void 0 && { targetPort: attvals["targetPort"] }
|
|
231
326
|
};
|
|
@@ -236,16 +331,19 @@ function fromGEXF(xml) {
|
|
|
236
331
|
const b = Number(color["@_b"] ?? 0);
|
|
237
332
|
edge.color = `#${hex(r)}${hex(g)}${hex(b)}`;
|
|
238
333
|
}
|
|
334
|
+
const typeAttr = e["@_type"];
|
|
335
|
+
if (typeAttr !== void 0) edge.mode = String(typeAttr) === "undirected" ? "undirected" : "directed";
|
|
239
336
|
return edge;
|
|
240
337
|
});
|
|
241
338
|
return {
|
|
242
339
|
id: String(graphEl["@_id"] ?? ""),
|
|
243
|
-
|
|
340
|
+
mode: graphType,
|
|
244
341
|
initialNodeId: graphEl["@_initialNodeId"] ?? null,
|
|
245
342
|
nodes,
|
|
246
343
|
edges,
|
|
247
344
|
data: graphEl["@_data"] !== void 0 ? tryParseJSON(String(graphEl["@_data"])) : void 0,
|
|
248
|
-
...graphEl["@_direction"] && { direction: graphEl["@_direction"] }
|
|
345
|
+
...graphEl["@_direction"] && { direction: graphEl["@_direction"] },
|
|
346
|
+
...graphEl["@_style"] !== void 0 && { style: tryParseJSON(String(graphEl["@_style"])) }
|
|
249
347
|
};
|
|
250
348
|
}
|
|
251
349
|
function asArray(val) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as createFormatConverter } from "../../converter-
|
|
1
|
+
import { n as createFormatConverter } from "../../converter-udLITX36.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/formats/gml/index.ts
|
|
4
4
|
/**
|
|
@@ -26,8 +26,12 @@ import { n as createFormatConverter } from "../../converter-Dspillnn.mjs";
|
|
|
26
26
|
function toGML(graph) {
|
|
27
27
|
const lines = [];
|
|
28
28
|
lines.push("graph [");
|
|
29
|
-
lines.push(` directed ${graph.
|
|
29
|
+
lines.push(` directed ${graph.mode === "undirected" ? 0 : 1}`);
|
|
30
30
|
if (graph.id) lines.push(` id ${gmlString(graph.id)}`);
|
|
31
|
+
if (graph.initialNodeId) lines.push(` initialNodeId ${gmlString(graph.initialNodeId)}`);
|
|
32
|
+
if (graph.data !== void 0) lines.push(` data ${gmlString(JSON.stringify(graph.data))}`);
|
|
33
|
+
if (graph.direction) lines.push(` direction ${gmlString(graph.direction)}`);
|
|
34
|
+
if (graph.style !== void 0) lines.push(` style ${gmlString(JSON.stringify(graph.style))}`);
|
|
31
35
|
const childrenMap = /* @__PURE__ */ new Map();
|
|
32
36
|
for (const node of graph.nodes) {
|
|
33
37
|
const pid = node.parentId ?? null;
|
|
@@ -43,6 +47,7 @@ function toGML(graph) {
|
|
|
43
47
|
if (node.ports !== void 0) lines.push(`${indent} ports ${gmlString(JSON.stringify(node.ports))}`);
|
|
44
48
|
if (node.shape) lines.push(`${indent} shape ${gmlString(node.shape)}`);
|
|
45
49
|
if (node.color) lines.push(`${indent} color ${gmlString(node.color)}`);
|
|
50
|
+
if (node.style !== void 0) lines.push(`${indent} style ${gmlString(JSON.stringify(node.style))}`);
|
|
46
51
|
if (node.x !== void 0 || node.y !== void 0 || node.width !== void 0 || node.height !== void 0) {
|
|
47
52
|
lines.push(`${indent} graphics [`);
|
|
48
53
|
if (node.x !== void 0) lines.push(`${indent} x ${node.x}`);
|
|
@@ -64,9 +69,19 @@ function toGML(graph) {
|
|
|
64
69
|
lines.push(` target ${gmlString(edge.targetId)}`);
|
|
65
70
|
if (edge.label) lines.push(` label ${gmlString(edge.label)}`);
|
|
66
71
|
if (edge.data !== void 0) lines.push(` data ${gmlString(JSON.stringify(edge.data))}`);
|
|
72
|
+
if (edge.weight !== void 0) lines.push(` weight ${edge.weight}`);
|
|
67
73
|
if (edge.sourcePort !== void 0) lines.push(` sourcePort ${gmlString(edge.sourcePort)}`);
|
|
68
74
|
if (edge.targetPort !== void 0) lines.push(` targetPort ${gmlString(edge.targetPort)}`);
|
|
69
75
|
if (edge.color) lines.push(` color ${gmlString(edge.color)}`);
|
|
76
|
+
if (edge.style !== void 0) lines.push(` style ${gmlString(JSON.stringify(edge.style))}`);
|
|
77
|
+
if (edge.x !== void 0 || edge.y !== void 0 || edge.width !== void 0 || edge.height !== void 0) {
|
|
78
|
+
lines.push(" graphics [");
|
|
79
|
+
if (edge.x !== void 0) lines.push(` x ${edge.x}`);
|
|
80
|
+
if (edge.y !== void 0) lines.push(` y ${edge.y}`);
|
|
81
|
+
if (edge.width !== void 0) lines.push(` w ${edge.width}`);
|
|
82
|
+
if (edge.height !== void 0) lines.push(` h ${edge.height}`);
|
|
83
|
+
lines.push(" ]");
|
|
84
|
+
}
|
|
70
85
|
lines.push(" ]");
|
|
71
86
|
}
|
|
72
87
|
lines.push("]");
|
|
@@ -118,6 +133,7 @@ function fromGML(gml) {
|
|
|
118
133
|
...n["ports"] !== void 0 && { ports: tryParseJSON(n["ports"]) },
|
|
119
134
|
...n["shape"] && { shape: n["shape"] },
|
|
120
135
|
...n["color"] && { color: n["color"] },
|
|
136
|
+
...n["style"] !== void 0 && { style: tryParseJSON(n["style"]) },
|
|
121
137
|
...gfx?.x !== void 0 && { x: gfx.x },
|
|
122
138
|
...gfx?.y !== void 0 && { y: gfx.y },
|
|
123
139
|
...gfx?.w !== void 0 && { width: gfx.w },
|
|
@@ -128,24 +144,35 @@ function fromGML(gml) {
|
|
|
128
144
|
}
|
|
129
145
|
parseNodes(graphBlock, null);
|
|
130
146
|
const edgeEntries = asArray(graphBlock["edge"]);
|
|
131
|
-
for (const e of edgeEntries)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
147
|
+
for (const e of edgeEntries) {
|
|
148
|
+
const gfx = e["graphics"];
|
|
149
|
+
edges.push({
|
|
150
|
+
type: "edge",
|
|
151
|
+
id: String(e["id"] ?? `e${edges.length}`),
|
|
152
|
+
sourceId: String(e["source"] ?? ""),
|
|
153
|
+
targetId: String(e["target"] ?? ""),
|
|
154
|
+
label: e["label"] ?? "",
|
|
155
|
+
data: e["data"] !== void 0 ? tryParseJSON(e["data"]) : void 0,
|
|
156
|
+
...e["weight"] !== void 0 && { weight: Number(e["weight"]) },
|
|
157
|
+
...e["sourcePort"] !== void 0 && { sourcePort: String(e["sourcePort"]) },
|
|
158
|
+
...e["targetPort"] !== void 0 && { targetPort: String(e["targetPort"]) },
|
|
159
|
+
...e["color"] && { color: e["color"] },
|
|
160
|
+
...e["style"] !== void 0 && { style: tryParseJSON(e["style"]) },
|
|
161
|
+
...gfx?.x !== void 0 && { x: gfx.x },
|
|
162
|
+
...gfx?.y !== void 0 && { y: gfx.y },
|
|
163
|
+
...gfx?.w !== void 0 && { width: gfx.w },
|
|
164
|
+
...gfx?.h !== void 0 && { height: gfx.h }
|
|
165
|
+
});
|
|
166
|
+
}
|
|
142
167
|
return {
|
|
143
168
|
id: graphId,
|
|
144
|
-
|
|
145
|
-
initialNodeId: null,
|
|
169
|
+
mode: directed ? "directed" : "undirected",
|
|
170
|
+
initialNodeId: graphBlock["initialNodeId"] ?? null,
|
|
146
171
|
nodes,
|
|
147
172
|
edges,
|
|
148
|
-
data: void 0
|
|
173
|
+
data: graphBlock["data"] !== void 0 ? tryParseJSON(graphBlock["data"]) : void 0,
|
|
174
|
+
...graphBlock["direction"] && { direction: String(graphBlock["direction"]) },
|
|
175
|
+
...graphBlock["style"] !== void 0 && { style: tryParseJSON(graphBlock["style"]) }
|
|
149
176
|
};
|
|
150
177
|
}
|
|
151
178
|
function tokenize(input) {
|