-
Notifications
You must be signed in to change notification settings - Fork 5
Graphviz #25
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 #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -826,3 +826,68 @@ | |
| (p/demolish factory obj) | ||
| (after-demolish! {:key key :object obj}) | ||
| nil)))))) | ||
|
|
||
| (defn inspect [] | ||
| (fn [registry] | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add space |
||
| (fn [key] | ||
| (let [factory (registry key)] | ||
| (reify p/Factory | ||
| (dependencies [_] | ||
| (p/dependencies factory)) | ||
| (build [_ deps] | ||
| (into [{:key key :deps (keys deps)}] | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. {:key key
:deps (keys deps)
:dep-types (p/dependencies this)} |
||
| (comp | ||
| (mapcat val) | ||
| (distinct)) | ||
| deps)) | ||
| (demolish [_ obj])))))) | ||
|
|
||
|
|
||
| (defn- graphviz-id [x] | ||
| (str "\"" x "\"")) | ||
|
|
||
| (defn render-graphviz [root middlewares] | ||
| (let [system (start root middlewares (inspect)) | ||
| components @system] | ||
|
|
||
| (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 deps]} components] | ||
| (print "{") | ||
| (doseq [token (interpose "," (map graphviz-id deps))] | ||
| (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 "}")))) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| (ns darkleaf.di.tutorial.x-inspect-test | ||
| (:require | ||
| [clojure.test :as t] | ||
| [darkleaf.di.core :as di])) | ||
|
|
||
| (defn a [] | ||
| :ok) | ||
|
|
||
| (defn b [{a `a}] | ||
| :ok) | ||
|
|
||
| (defn c [{a `a | ||
| b `b}] | ||
| :ok) | ||
|
|
||
| (t/deftest ok | ||
| (with-open [info (di/start `c (di/inspect))] | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not be a middleware |
||
| (t/is (= [{:key `c :deps [`a `b]} | ||
| {:key `a :deps nil} | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we remove a key with nil value? |
||
| {:key `b :deps [`a]}] | ||
| @info)))) | ||
|
|
||
|
|
||
| (comment | ||
| (di/render-graphviz `c nil) | ||
| ,,,) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should move it into a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#27