links in dot graphs

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

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

Loading…
Cancel
Save