visualisation of all instances

integration-tests
Josha von Gizycki 6 years ago
parent eaeca7f8c3
commit 58edd77428

@ -71,7 +71,7 @@
[:section [:section
[:h2 [:span.__icon "▤"] "Visualisation"] [:h2 [:span.__icon "▤"] "Visualisation"]
[:ul [:ul
[:li [:a {:href ""} [:li [:a {:href (path :vis-all-instances)}
"All Instances"]]]]))] "All Instances"]]]]))]
(into [:main (into [:main
(for [msg (:flash request)] (for [msg (:flash request)]

@ -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 {}))

@ -3,12 +3,29 @@
GET POST DELETE]] GET POST DELETE]]
[ring.util.response :as resp] [ring.util.response :as resp]
[wanijo.framework.routing :refer [register! path]] [wanijo.framework.routing :refer [register! path]]
[wanijo.framework.view :as view]
[wanijo.instance.domain :as domain-instance] [wanijo.instance.domain :as domain-instance]
[wanijo.visualisation.domain :as vis-domain]
[wanijo.visualisation.viz :as viz])) [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 (defroutes routes
(GET (register! :vis-single-instance "/visualisation/instance/:uuid") (GET (register! :vis-single-instance "/visualisation/instance/:uuid")
[uuid] [uuid]
{:body (viz/single-instance {:body (viz/single-instance
(domain-instance/full-instance-by-uuid! uuid)) (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"}})) :headers {"Content-Type" "image/svg+xml"}}))

@ -32,3 +32,30 @@
dot/digraph dot/digraph
dot/dot dot/dot
(doro-jvm/render {:format :svg})))) (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}))))

Loading…
Cancel
Save