all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#30711] [PATCH 1/1] guix: graph: Add Trival Graph Format (TGF) backend.
@ 2018-03-05 11:41 Hartmut Goebel
  2018-03-05 17:17 ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: Hartmut Goebel @ 2018-03-05 11:41 UTC (permalink / raw)
  To: 30711

* guix/graph.scm ((emit-edge, emit-d3js-edge, emit-cypher-edge): New arguments
  label1 , label2.
  (emit-tg-progloug, mit-tgf-epilouge, emit-tgf-node, emit-tgf-edge): New
  variables.
  (%trivial-graph-backend): New variable.
  (%graph-backends): Add %trivial-graph-backend.
  (export-graph): Pass labels to emit-edge.
---
 guix/graph.scm | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/guix/graph.scm b/guix/graph.scm
index d7fd5f3e4..650d577f6 100644
--- a/guix/graph.scm
+++ b/guix/graph.scm
@@ -46,6 +46,7 @@
             %graph-backends
             %d3js-backend
             %graphviz-backend
+            %trival-graph-backend
             graph-backend?
             graph-backend
             graph-backend-name
@@ -173,7 +174,7 @@ typically returned by 'node-edges' or 'node-back-edges'."
 (define (emit-node id label port)
   (format port "  \"~a\" [label = \"~a\", shape = box, fontname = Helvetica];~%"
           id label))
-(define (emit-edge id1 id2 port)
+(define (emit-edge id1 label1 id2 label2 port)
   (format port "  \"~a\" -> \"~a\" [color = ~a];~%"
           id1 id2 (pop-color id1)))
 
@@ -219,7 +220,7 @@ nodes[\"~a\"] = {\"id\": \"~a\", \"label\": \"~a\", \"index\": nodeArray.length}
 nodeArray.push(nodes[\"~a\"]);~%"
           id id label id))
 
-(define (emit-d3js-edge id1 id2 port)
+(define (emit-d3js-edge id1 label1 id2 label2 port)
   (format port "links.push({\"source\": \"~a\", \"target\": \"~a\"});~%"
           id1 id2))
 
@@ -245,7 +246,7 @@ nodeArray.push(nodes[\"~a\"]);~%"
   (format port "MERGE (p:Package { id: ~s }) SET p.name = ~s;~%"
           id label ))
 
-(define (emit-cypher-edge id1 id2 port)
+(define (emit-cypher-edge id1 label1 id2 label2 port)
   (format port "MERGE (a:Package { id: ~s });~%" id1)
   (format port "MERGE (b:Package { id: ~s });~%" id2)
   (format port "MATCH (a:Package { id: ~s }), (b:Package { id: ~s }) CREATE UNIQUE (a)-[:NEEDS]->(b);~%"
@@ -260,13 +261,32 @@ nodeArray.push(nodes[\"~a\"]);~%"
 
 \f
 ;;;
+;;; Trivial graph export.
+;;;
+
+(define (emit-tgf-prologue name port) #t)
+(define (emit-tgf-epilogue port) #t)
+(define (emit-tgf-node id label port) #t)
+(define (emit-tgf-edge id1 label1 id2 label2 port)
+  (format port "~a ~a~%" label1 label2))
+
+(define %trival-graph-backend
+  (graph-backend "tgf"
+                 "Generate graph in Trivial Graph Format."
+                 emit-tgf-prologue emit-tgf-epilogue
+                 emit-tgf-node emit-tgf-edge))
+
+
+\f
+;;;
 ;;; Shared.
 ;;;
 
 (define %graph-backends
   (list %graphviz-backend
         %d3js-backend
-        %cypher-backend))
+        %cypher-backend
+        %trival-graph-backend))
 
 (define* (export-graph sinks port
                        #:key
@@ -299,8 +319,16 @@ true, draw reverse arrows."
                      (emit-node id (node-label head) port)
                      (for-each (lambda (dependency dependency-id)
                                  (if reverse-edges?
-                                     (emit-edge dependency-id id port)
-                                     (emit-edge id dependency-id port)))
+                                     (emit-edge dependency-id
+                                                (node-label dependency)
+                                                id
+                                                (node-label head)
+                                                port)
+                                     (emit-edge id
+                                                (node-label head)
+                                                dependency-id
+                                                (node-label dependency)
+                                                port)))
                                dependencies ids)
                      (loop (append dependencies tail)
                            (set-insert id visited)))))))))))))
-- 
2.13.6

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-03-12 14:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-05 11:41 [bug#30711] [PATCH 1/1] guix: graph: Add Trival Graph Format (TGF) backend Hartmut Goebel
2018-03-05 17:17 ` Ludovic Courtès
2018-03-05 21:12   ` Hartmut Goebel
2018-03-06 10:32     ` Ludovic Courtès
2018-03-06 20:20       ` bug#30711: " Hartmut Goebel
2018-03-06 21:05         ` [bug#30711] " Björn Höfling
2018-03-06 21:23           ` Hartmut Goebel
2018-03-12 14:30             ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.