Skip to content

Instantly share code, notes, and snippets.

@stuarthalloway
Created March 19, 2013 20:11
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stuarthalloway/5199642 to your computer and use it in GitHub Desktop.
Save stuarthalloway/5199642 to your computer and use it in GitHub Desktop.
Draw a pedestal dataflow with dorothy + Graphviz
;; 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!)
@abp
Copy link

abp commented Mar 20, 2013

Use:

(-> (dfg chat-client)
    dot/digraph
    dot/dot
    (dot/save! "/path/to/pedestal-samples/chat/client.png" {:format :png}))

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment