From 5d1f15e7be0bf5bd2962125a7f86119477354db2 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 17 Dec 2021 17:20:36 +0530 Subject: Abstract out serialization of graphviz properties. * ccwl/graphviz.scm (serialize-properties): New function. (graph->dot): Use serialize-properties. --- ccwl/graphviz.scm | 18 ++++++++++++------ 1 file 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 object, or a 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 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)) -- cgit v1.2.3