guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/02: graph: Edges are colored based on their source node.


From: Ludovic Courtès
Subject: 01/02: graph: Edges are colored based on their source node.
Date: Sat, 02 Apr 2016 20:40:23 +0000

civodul pushed a commit to branch master
in repository guix.

commit 8463d1345ef302fd016c73b412bd90fdf8adc818
Author: Ludovic Courtès <address@hidden>
Date:   Sat Apr 2 21:46:26 2016 +0200

    graph: Edges are colored based on their source node.
    
    * guix/graph.scm (%colors): New variable.
    (pop-color): New procedure.
    (emit-edge): Use it.
---
 guix/graph.scm |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/guix/graph.scm b/guix/graph.scm
index a39208e..1a8f2d5 100644
--- a/guix/graph.scm
+++ b/guix/graph.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2015 Ludovic Courtès <address@hidden>
+;;; Copyright © 2015, 2016 Ludovic Courtès <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -131,6 +131,16 @@ typically returned by 'node-edges' or 'node-back-edges'."
   (node     graph-backend-node)
   (edge     graph-backend-edge))
 
+(define %colors
+  ;; See colortbl.h in Graphviz.
+  #("red" "magenta" "blue" "cyan3" "darkseagreen"
+    "peachpuff4" "darkviolet" "dimgrey" "darkgoldenrod"))
+
+(define (pop-color hint)
+  "Return a Graphviz color based on HINT, an arbitrary object."
+  (let ((index (hash hint (vector-length %colors))))
+    (vector-ref %colors index)))
+
 (define (emit-prologue name port)
   (format port "digraph \"Guix ~a\" {\n"
           name))
@@ -140,8 +150,8 @@ typically returned by 'node-edges' or 'node-back-edges'."
   (format port "  \"~a\" [label = \"~a\", shape = box, fontname = 
Helvetica];~%"
           id label))
 (define (emit-edge id1 id2 port)
-  (format port "  \"~a\" -> \"~a\" [color = red];~%"
-          id1 id2))
+  (format port "  \"~a\" -> \"~a\" [color = ~a];~%"
+          id1 id2 (pop-color id1)))
 
 (define %graphviz-backend
   (graph-backend emit-prologue emit-epilogue



reply via email to

[Prev in Thread] Current Thread [Next in Thread]