Created
May 14, 2014 19:55
-
-
Save kurogelee/0556e474365563ed0a6e to your computer and use it in GitHub Desktop.
dorothyの魔法でクラス図を描く ref: http://qiita.com/kurogelee/items/aa5bb531ff87de0fe99e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns classzu.core | |
(:require [dorothy.core :refer :all] | |
[clojure.set :as set] | |
[clojure.walk :as walk])) | |
(defn show-diagram [& class-defs] | |
(->> (for [[class extends & implements] class-defs] | |
(concat [class] | |
(when extends [[class extends]]) | |
(map (fn [i] [class i {:style :dashed}]) implements))) | |
(apply concat) | |
(list* (node-attrs {:shape :record}) | |
(edge-attrs {:arrowhead :empty})) | |
digraph dot show!)) | |
(show-diagram [:classA :classB :interface1 :interface2] [:classZ nil :interface9]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> [[:node1 {:style :filled :shape :record}] :node2 | |
[:a :b :c :d :a {:arrowhead :empty}] | |
[:e :f]] | |
digraph dot show!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> [(node-attrs {:color :red}) | |
(edge-attrs {:style :dashed}) | |
[:node1 {:style :filled :shape :record}] :node2 | |
[:a :b :c :d :a {:arrowhead :empty}] | |
[:e :f]] | |
digraph dot show!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> [(node-attrs {:color :red}) | |
(edge-attrs {:style :dashed}) | |
[:node1 {:style :filled :shape :record}] :node2 | |
[:a :b :c :d :a {:arrowhead :empty}] | |
[:e :f]] | |
digraph dot (save! "out.png" {:format :png})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-classdef [^Class c] | |
(->> (list* c (.getSuperclass c) (apply set/difference (supers c) #{(.getSuperclass c)} (map supers (supers c)))) | |
(walk/postwalk #(if (or (nil? %) (sequential? %)) % (keyword (.getSimpleName %)))))) | |
(defn get-all-classdefs [& classes] | |
(distinct (concat (map get-classdef classes) | |
(mapcat #(apply get-all-classdefs (supers %)) classes)))) | |
(import '[java.util ArrayList LinkedList]) | |
(apply show-diagram (get-all-classdefs ArrayList LinkedList)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(apply show-diagram (apply get-all-classdefs (map class [() '(1) (range 1) (seq "a") (cons 1 []) | |
(seq {1 2}) (keys {1 2}) (vals {1 2})]))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns classzu.sample | |
(:require [dorothy.core :refer :all])) | |
(-> [[:node1] :node2 | |
[:node1 :node2]] | |
graph dot show!) | |
(-> [[:node1] :node2 | |
[:a :b :c :d :a]] | |
digraph dot show!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment