public

simple example of visualizing prismatic graphs with graphviz

  • Download Gist
simple_graph_visualization.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
(require '[plumbing.core :refer [fnk]])
(require '[plumbing.graph :as graph])
 
(defn calculate-deps [f]
(map (fn [parent] [parent (first f)]) (-> f second meta first second first keys)))
 
(defn print-dot [graph]
(println (clojure.string/join "\n"
(map (fn [r] (str "\""(first r) "\" -> \"" (second r) "\";"))
(mapcat (fn [k] (calculate-deps k)) (graph/->graph graph))))))
;; Example graph
(def stats-graph
"A graph specifying the same computation as 'stats'"
{:n (fnk [xs] (count xs))
:m (fnk [xs n] (/ (+ identity xs) n))
:m2 (fnk [xs n] (/ (+ #(* % %) xs) n))
:v (fnk [m m2] (- m2 (* m m)))})
 
(print-dot stats-graph)
 
; Outputs this:
;
; digraph "example" {
; ":xs" -> ":n";
; ":xs" -> ":m";
; ":n" -> ":m";
; ":xs" -> ":m2";
; ":n" -> ":m2";
; ":m2" -> ":v";
; ":m" -> ":v";
; }

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.