links in dot graphs

integration-tests
Josha von Gizycki 6 years ago
parent a2e6bcd4a7
commit 54a47108f6

@ -1,14 +1,25 @@
(ns wanijo.visualisation.viz (ns wanijo.visualisation.viz
(:require [dorothy (:require [dorothy
[core :as dot] [core :as dot]
[jvm :as doro-jvm]])) [jvm :as doro-jvm]]
[wanijo.framework.routing :refer [path]]))
(defn node->label
([node]
(:name node))
([node1 node2]
(str (:name node1)
"\n"
(:name node2))))
(defn single-instance [instance] (defn single-instance [instance]
(let [out-nodes (map #(vector (-> % :target :uuid) (let [out-nodes (map #(vector (-> % :target :uuid)
{:label (-> % :target :name)}) {:label (node->label (:target %))
:href (path :instance-show (:target %))})
(:links-out instance)) (:links-out instance))
in-nodes (map #(vector (-> % :source :uuid) in-nodes (map #(vector (-> % :source :uuid)
{:label (-> % :source :name)}) {:label (node->label (:source %))
:href (path :instance-show (:source %))})
(:links-in instance)) (:links-in instance))
relationships-out (map (fn [{:keys [link target schema]}] relationships-out (map (fn [{:keys [link target schema]}]
[(:uuid instance) :> (:uuid target) [(:uuid instance) :> (:uuid target)
@ -23,7 +34,7 @@
"LR" "LR"
"TD")] "TD")]
(-> [{:rankdir rankdir} (-> [{:rankdir rankdir}
[(:uuid instance) {:label (:name instance) [(:uuid instance) {:label (node->label instance)
:shape "cylinder"}]] :shape "cylinder"}]]
(into out-nodes) (into out-nodes)
(into in-nodes) (into in-nodes)
@ -34,27 +45,20 @@
(doro-jvm/render {:format :svg})))) (doro-jvm/render {:format :svg}))))
(defn all-instances [instances] (defn all-instances [instances]
(let [labelfn #(str (:name %1) (let [sources (map #(vector (-> % :source :uuid)
"\n" {:label (node->label (:source %)
(:name %2)) (:schema %))
sources (map #(vector (-> % :source :uuid) :href (path :instance-show (:source %))})
{:label (labelfn (:source %)
(:schema %))})
instances) instances)
linked (filter :link instances) linked (filter :link instances)
links (map #(vector (-> % :source :uuid) links (map #(vector (-> % :source :uuid)
:> :>
(-> % :target :uuid) (-> % :target :uuid)
{:label (-> % :link :name)}) {:label (-> % :link :name)})
linked) linked)]
targets (map #(vector (-> % :target :uuid)
{:label (labelfn (:target %)
(:target_schema %))})
linked)]
(-> [{:forcelabels "true" (-> [{:forcelabels "true"
:rankdir "LR"}] :rankdir "LR"}]
(into sources) (into sources)
(into targets)
(into links) (into links)
dot/digraph dot/digraph
dot/dot dot/dot

Loading…
Cancel
Save