Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphviz #30

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -864,3 +864,52 @@
middlewares
(inspect-middleware))]
@components))



(defn- graphviz-id [x]
(str "\"" x "\""))

(defn graphviz [root middlewares]
(let [components (inspect root middlewares)]
(with-out-str
(println "digraph {")
(println "rankdir=LR;")
#_(println "splines=ortho;")
#_(println "concentrate=true;")

(println "node [shape=box color=gray style=rounded];")
(println "edge [color=gray arrowhead=empty];")

#_
(println (graphviz-id (-> components first :key))
(str "[color=magenta];"))

(doseq [{:keys [key dependencies]} components]
(print "{")
(doseq [token (interpose "," (map graphviz-id (keys dependencies)))]
(print token))
(println "}" "->" (graphviz-id key)))

#_
(doseq [[cluster keys] (->> components
(map :key)
(group-by try-namespace))
:when (and (some? cluster)
(not (str/starts-with? cluster "env"))
(not (str/starts-with? cluster "darkleaf.di.core")))]
(println "subgraph" (graphviz-id cluster) "{")
(println " " (str "label=" (graphviz-id cluster) ";"))
(println " " "cluster=true;")
(println " " "labeljust=l;")
(println " " "color=gray;")
(println " " "style=dashed;")

(doseq [key keys]
(println " " (graphviz-id key)
(str "["
"label=" (graphviz-id (name key)) ;; keywords must start with :
"];")))
(println "}"))

(println "}"))))
Loading