summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosselin Poiret <dev@jpoiret.xyz>2023-08-25 14:24:43 +0200
committerJosselin Poiret <dev@jpoiret.xyz>2023-08-25 14:24:43 +0200
commit106ad23ae44c34f275b8857cfdac2356d5962e6a (patch)
tree37a4a039c2edeedb01825cd66360f467e6c503c1
parentca8acad38264dd29a808904d3ce8e7249194d95f (diff)
graph: Add GraphML backend.
* guix/graph.scm (emit-graphml-prologue, emit-graphml-epilogue, emit-graphml-node, emit-graphml-edge): New procedures. (%graphml-backend): New variable. (%graph-backends): Add %graphml-backend.
-rw-r--r--guix/graph.scm36
1 files changed, 35 insertions, 1 deletions
diff --git a/guix/graph.scm b/guix/graph.scm
index aee0021d6c..9f1111a0ae 100644
--- a/guix/graph.scm
+++ b/guix/graph.scm
@@ -29,6 +29,7 @@
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (ice-9 match)
+ #:use-module (ice-9 string-fun)
#:use-module (ice-9 vlist)
#:export (node-type
node-type?
@@ -49,6 +50,7 @@
%graph-backends
%d3js-backend
%graphviz-backend
+ %graphml-backend
lookup-backend
graph-backend?
@@ -328,6 +330,37 @@ nodeArray.push(nodes[\"~a\"]);~%"
emit-cypher-prologue emit-cypher-epilogue
emit-cypher-node emit-cypher-edge))
+
+;;;
+;;; GraphML export.
+;;;
+
+(define (emit-graphml-prologue name port)
+ (format port "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
+<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"
+ xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
+ xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns
+ http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">
+ <graph id=\"G\" edgedefault=\"directed\">~%"))
+
+(define (emit-graphml-epilogue port)
+ (format port " </graph>
+</graphml>"))
+
+(define (emit-graphml-node id label port)
+ (format port " <node id=\"~a\"/>~%"
+ (string-replace-substring (object->string id) "\"" "\\\"")))
+
+(define (emit-graphml-edge id1 id2 port)
+ (format port " <edge source=\"~a\" target=\"~a\"/>~%"
+ (string-replace-substring (object->string id1) "\"" "\\\"")
+ (string-replace-substring (object->string id2) "\"" "\\\"")))
+
+(define %graphml-backend
+ (graph-backend "graphml"
+ "Generate GraphML."
+ emit-graphml-prologue emit-graphml-epilogue
+ emit-graphml-node emit-graphml-edge))
;;;
@@ -337,7 +370,8 @@ nodeArray.push(nodes[\"~a\"]);~%"
(define %graph-backends
(list %graphviz-backend
%d3js-backend
- %cypher-backend))
+ %cypher-backend
+ %graphml-backend))
(define (lookup-backend name)
"Return the graph backend called NAME. Raise an error if it is not found."