diff --git a/src/wanijo/framework/view.clj b/src/wanijo/framework/view.clj index 3f2f887..dff4721 100644 --- a/src/wanijo/framework/view.clj +++ b/src/wanijo/framework/view.clj @@ -71,7 +71,7 @@ [:section [:h2 [:span.__icon "▤"] "Visualisation"] [:ul - [:li [:a {:href ""} + [:li [:a {:href (path :vis-all-instances)} "All Instances"]]]]))] (into [:main (for [msg (:flash request)] diff --git a/src/wanijo/visualisation/domain.clj b/src/wanijo/visualisation/domain.clj new file mode 100644 index 0000000..a7a4bbd --- /dev/null +++ b/src/wanijo/visualisation/domain.clj @@ -0,0 +1,15 @@ +(ns wanijo.visualisation.domain + (:require [wanijo.framework.neo4j :as neo4j])) + +(neo4j/defquery all-instance-connections + "MATCH + (source:instance)-[:of]->(schema:schema) + OPTIONAL MATCH + (source)<-[:link_from]-(link:link)-[:link_to]->(target:instance), + (target)-[:of]->(target_schema:schema) + WHERE + target IS NULL OR target <> source + RETURN source, link, target, schema, target_schema") + +(defn all-instance-connections! [] + (neo4j/exec-query! all-instance-connections {})) diff --git a/src/wanijo/visualisation/routes.clj b/src/wanijo/visualisation/routes.clj index 7cc7e5b..93233e5 100644 --- a/src/wanijo/visualisation/routes.clj +++ b/src/wanijo/visualisation/routes.clj @@ -3,12 +3,29 @@ GET POST DELETE]] [ring.util.response :as resp] [wanijo.framework.routing :refer [register! path]] + [wanijo.framework.view :as view] [wanijo.instance.domain :as domain-instance] + [wanijo.visualisation.domain :as vis-domain] [wanijo.visualisation.viz :as viz])) +(defn all-instances [req] + (view/layout! + :request req + :content + [[:h1 "All Instances"] + [:img {:src (path :vis-all-instances-img) + :alt "All Instances"}]])) + (defroutes routes (GET (register! :vis-single-instance "/visualisation/instance/:uuid") [uuid] {:body (viz/single-instance (domain-instance/full-instance-by-uuid! uuid)) + :headers {"Content-Type" "image/svg+xml"}}) + (GET (register! :vis-all-instances "/visualisation/all-instances") + [:as req] + (all-instances req)) + (GET (register! :vis-all-instances-img "/visualisation/all-instances.svg") + [] + {:body (viz/all-instances (vis-domain/all-instance-connections!)) :headers {"Content-Type" "image/svg+xml"}})) diff --git a/src/wanijo/visualisation/viz.clj b/src/wanijo/visualisation/viz.clj index ec8ed3d..ebcd135 100644 --- a/src/wanijo/visualisation/viz.clj +++ b/src/wanijo/visualisation/viz.clj @@ -32,3 +32,30 @@ dot/digraph dot/dot (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 %))}) + 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)] + (-> [{:forcelabels "true" + :rankdir "LR"}] + (into sources) + (into targets) + (into links) + dot/digraph + dot/dot + (doro-jvm/render {:format :svg}))))