Skip to content

Commit

Permalink
graphviz
Browse files Browse the repository at this point in the history
  • Loading branch information
darkleaf committed Oct 30, 2024
1 parent 9b15044 commit 51ea073
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/darkleaf/di/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -870,3 +870,52 @@
middlewares
(inspect-middleware))]
@components))



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

(defn render-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 "}"))))

0 comments on commit 51ea073

Please sign in to comment.