aboutsummaryrefslogtreecommitdiff
path: root/ccwl
diff options
context:
space:
mode:
authorArun Isaac2021-12-17 17:20:36 +0530
committerArun Isaac2021-12-17 17:20:36 +0530
commit5d1f15e7be0bf5bd2962125a7f86119477354db2 (patch)
treec89ed1a76af35874da66d7eaadad3a40b89ea9cc /ccwl
parent1e36c8bdc8c22dee68a3aa292c1d318bd8e0b982 (diff)
downloadccwl-5d1f15e7be0bf5bd2962125a7f86119477354db2.tar.gz
ccwl-5d1f15e7be0bf5bd2962125a7f86119477354db2.tar.lz
ccwl-5d1f15e7be0bf5bd2962125a7f86119477354db2.zip
Abstract out serialization of graphviz properties.
* ccwl/graphviz.scm (serialize-properties): New function. (graph->dot): Use serialize-properties.
Diffstat (limited to 'ccwl')
-rw-r--r--ccwl/graphviz.scm18
1 files changed, 12 insertions, 6 deletions
diff --git a/ccwl/graphviz.scm b/ccwl/graphviz.scm
index 3aa3f2a..fec3908 100644
--- a/ccwl/graphviz.scm
+++ b/ccwl/graphviz.scm
@@ -149,6 +149,16 @@ symbol, a string, a <graph-port> object, or a <html-string> object."
(format "\"~a\"" (string-replace-substring object "\"" "\\\"")))
(else (error "Unknown object type to serialize to graphviz dot:" object))))
+(define (serialize-properties properties)
+ (string-append
+ "["
+ (string-join (map (match-lambda
+ ((key . value)
+ (format "~a=~a" key (serialize value))))
+ properties)
+ ", ")
+ "]"))
+
(define* (graph->dot graph #:optional (port (current-output-port)) (level 0))
"Render GRAPH, a <graph> object, in the graphviz dot syntax to
PORT."
@@ -166,12 +176,8 @@ PORT."
(indent-level port (1+ level))
(display (serialize (graph-node-name node)) port)
(unless (null? (graph-node-properties node))
- (display (format " [~a]"
- (string-join (map (match-lambda
- ((key . value)
- (format "~a=~a" key (serialize value))))
- (graph-node-properties node))
- ", "))
+ (display " " port)
+ (display (serialize-properties (graph-node-properties node))
port))
(display (format ";~%") port))
(graph-nodes graph))