Created
March 19, 2013 20:11
-
-
Save stuarthalloway/5199642 to your computer and use it in GitHub Desktop.
Draw a pedestal dataflow with dorothy + Graphviz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; from leiningen, use [dorothy/dorothy "0.0.3"] | |
(require '[dorothy.core :as dot]) | |
;; dataflow copied from chat | |
;; https://github.com/pedestal/samples/blob/master/chat/chat-client/app/src/chat_client/behavior.clj | |
(def dataflow '{:transform | |
{:outbound {:init {} :fn outbound-transform} | |
:inbound {:init {} :fn inbound-transform} | |
:nickname {:init nil :fn nickname-transform}} | |
:effect {:outbound send-message-to-server} | |
:combine {:new-messages {:fn new-messages :input #{:inbound :outbound}} | |
:updated-messages {:fn updated-messages :input #{:outbound :new-messages}} | |
:deleted-messages {:fn deleted-messages :input #{:inbound :outbound}}} | |
:emit {:emit {:fn chat-emit :input #{:new-messages :deleted-messages :updated-messages :nickname}}}}) | |
(defn dfg | |
"Given a Pedestal dataflow, return statements suitable for interpretation | |
by dorothy for Graphviz." | |
[dataflow] | |
(concat | |
(mapcat | |
(fn [[stage attrs]] | |
(let [m (get dataflow stage)] | |
(map | |
(fn [node] [node attrs]) | |
(keys m)))) | |
{:transform {:style :filled :color :green} | |
:combine {:style :filled :color :red} | |
:emit {:style :filled :color :blue}}) | |
(mapcat | |
(fn [stage] | |
(let [m (get dataflow stage)] | |
(mapcat | |
(fn [to] (map (fn [from] [from to]) (-> m to :input))) | |
(keys m)))) | |
[:combine :emit]))) | |
;; render the chat dataflow | |
(-> (dfg dataflow) dot/digraph dot/dot dot/show!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use:
to render a png of a dataflow.
Then go on and open the png-file in Emacs. M-x auto-revert-mode on the buffer.
Work on the dataflow, C-M-x the expression, the png in Emacs gets refreshed with your current dataflow.
http://t.co/XnJiF7BWtY