diff --git a/src/mailhead/visualize.clj b/src/mailhead/visualize.clj index 0061bd3..749191a 100644 --- a/src/mailhead/visualize.clj +++ b/src/mailhead/visualize.clj @@ -2,14 +2,19 @@ (:use [tangle.core]) (:require [mailhead.parser :as parser])) -(defn nodes [receive-path] ["home" "servera" "target"]) +(defn edge-path [receive-path] + (let [path (reverse receive-path) + chain (concat (map :sender (butlast path)) [(:receiver (last path))]) + cleaned-chain (map clojure.string/lower-case chain)] + (partition 2 (interleave cleaned-chain (rest cleaned-chain))))) -(defn edges [receive-path] [["home" "servera" {:label "200ms" :fillcolor "gray" :color "gray"}] - ["servera" "target" {:label "50min" :fillcolor "gray" :color "gray"}]]) +(defn edges [path] + (let [p (map #(concat % [{:label "ms" :fillcolor "gray" :color "gray"}]) (edge-path path))] + (into [] (map #(into [] %)) p))) (defn draw-path [receive-path] (-> (graph->dot - (nodes receive-path) + [] (edges receive-path) {:node {:shape :box :fontname "Arial"