Generate SVG images
This commit is contained in:
parent
2286e75f0d
commit
d96250b444
2 changed files with 35 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
||||||
(ns mailhead.routes.home
|
(ns mailhead.routes.home
|
||||||
(:require [mailhead.layout :as layout]
|
(:require [mailhead.layout :as layout]
|
||||||
|
[mailhead.visualize :as v]
|
||||||
[compojure.core :refer [defroutes GET POST]]
|
[compojure.core :refer [defroutes GET POST]]
|
||||||
[ring.util.http-response :refer [ok]]
|
[ring.util.http-response :refer [ok]]
|
||||||
[clojure.java.io :as io]))
|
[clojure.java.io :as io]))
|
||||||
|
@ -11,7 +12,11 @@
|
||||||
(layout/render "about.html"))
|
(layout/render "about.html"))
|
||||||
|
|
||||||
(defn analyze-mailheader [mailheader]
|
(defn analyze-mailheader [mailheader]
|
||||||
(layout/render "result.html" {:mailheader mailheader}))
|
(let [token (v/draw mailheader)]
|
||||||
|
;; TODO: Generate token
|
||||||
|
;; TODO: Generate image
|
||||||
|
;; TODO: Show image and other data on result.html
|
||||||
|
(layout/render "result.html" {:mailheader mailheader})))
|
||||||
|
|
||||||
(defroutes home-routes
|
(defroutes home-routes
|
||||||
(GET "/" [] (home-page))
|
(GET "/" [] (home-page))
|
||||||
|
|
|
@ -9,28 +9,38 @@
|
||||||
(partition 2 (interleave cleaned-chain (rest cleaned-chain)))))
|
(partition 2 (interleave cleaned-chain (rest cleaned-chain)))))
|
||||||
|
|
||||||
(defn edges [path]
|
(defn edges [path]
|
||||||
(let [p (map #(concat % [{:label "ms" :fillcolor "gray" :color "gray"}]) (edge-path path))]
|
(let [p (map
|
||||||
|
#(concat % [{:label "time" :fillcolor "gray" :color "gray"}])
|
||||||
|
(edge-path path))]
|
||||||
(into [] (map #(into [] %)) p)))
|
(into [] (map #(into [] %)) p)))
|
||||||
|
|
||||||
(defn draw-path [receive-path]
|
(defn draw-path [receive-path]
|
||||||
(-> (graph->dot
|
(graph->dot
|
||||||
[]
|
[]
|
||||||
(edges receive-path)
|
(edges receive-path)
|
||||||
{:node {:shape :box
|
{:node {:shape :box
|
||||||
:fontname "Arial"
|
:fontname "Arial"
|
||||||
:fontsize 12
|
:fontsize 12
|
||||||
:style "filled"
|
:style "filled"
|
||||||
:fillcolor "darkgoldenrod1"
|
:fillcolor "darkgoldenrod1"
|
||||||
:color "darkgoldenrod3"}
|
:color "darkgoldenrod3"}
|
||||||
:edge {:fontname "Arial"
|
:edge {:fontname "Arial"
|
||||||
:fontsize 10}
|
:fontsize 10}
|
||||||
:directed? true
|
:directed? true
|
||||||
:graph {:rankdir :LR
|
:graph {:rankdir :LR
|
||||||
:color "transparent"}})
|
:color "transparent"}}))
|
||||||
(dot->image "png")))
|
|
||||||
|
|
||||||
(defn draw [filename]
|
(defn save-image [dot token]
|
||||||
(draw-path (parser/parse-from-file filename)))
|
(let [path (str "generated-images/" token ".svg")]
|
||||||
|
(clojure.java.io/make-parents path)
|
||||||
|
(spit path (dot->svg dot))))
|
||||||
|
|
||||||
(draw "/home/aaron/workbench/clojurecup2015/sample-data/header1.eml")
|
(defn next-token []
|
||||||
|
(str (java.util.UUID/randomUUID)))
|
||||||
|
|
||||||
|
;; TODO: Make it work with strings
|
||||||
|
(defn draw [mailheader]
|
||||||
|
(let [filename "/home/aaron/workbench/clojurecup2015/sample-data/header1.eml"
|
||||||
|
token (next-token)]
|
||||||
|
(save-image (draw-path (parser/parse-from-file filename)) token)
|
||||||
|
token))
|
||||||
|
|
Loading…
Reference in a new issue