|
16 | 16 | (doto (graphics/createGraphics "100%" "100%" 1.0 1.0)
|
17 | 17 | (.render (dom/getElement "network"))))
|
18 | 18 |
|
19 |
| -(defn draw-graph [users nodes] |
| 19 | +(defn draw-graph [{:keys [locs mentions]}] |
| 20 | + (. g (clear)) |
| 21 | + |
20 | 22 | ; Draw mention edges
|
21 |
| - (doseq [[username {:keys [mentions]}] users |
22 |
| - :when (get nodes username) |
23 |
| - [mention-name mention-count] mentions] |
24 |
| - (when-let [{x2 :x, y2 :y} (get nodes mention-name)] |
25 |
| - (let [{x1 :x, y1 :y} (get nodes username)] |
26 |
| - (.drawPath g |
27 |
| - (-> (. g (createPath)) (.moveTo x1 y1) (.lineTo x2 y2)) |
28 |
| - (get edge-strokes mention-count max-stroke) nil)))) |
| 23 | + (doseq [[username {x1 :x, y1 :y}] locs |
| 24 | + [mention-name mention-count] (:mentions (get mentions username))] |
| 25 | + (when-let [{x2 :x, y2 :y} (get locs mention-name)] |
| 26 | + (.drawPath g |
| 27 | + (-> (. g (createPath)) (.moveTo x1 y1) (.lineTo x2 y2)) |
| 28 | + (get edge-strokes mention-count max-stroke) nil))) |
29 | 29 |
|
30 | 30 | ; Draw avatar nodes
|
31 | 31 | (let [offset (/ avatar-size 2)]
|
32 |
| - (doseq [[username {:keys [x y]}] nodes] |
| 32 | + (doseq [[username {:keys [x y]}] locs] |
33 | 33 | (.drawImage g (- x offset) (- y offset) avatar-size avatar-size
|
34 |
| - (-> users (get username) :image-url))))) |
| 34 | + (:image-url (get mentions username)))))) |
35 | 35 |
|
36 | 36 | ; This is temporary. The graph data should flow somehow from the
|
37 | 37 | ; tweets. For now, just hardcode some:
|
| 38 | +(def test-users {"djspiewak" {:image-url "http://a0.twimg.com/profile_images/746976711/angular-final_normal.jpg", :last-tweet "Does Clojure have a Sinatra clone?", :mentions {}}, "tobsn" {:image-url "http://a2.twimg.com/profile_images/1364411587/yr40_normal.png", :last-tweet "Creating a Query DSL using Clojure and MongoDB http://tob.sn/qgCxkm #mongodb", :mentions {}}, "CzarneckiD" {:image-url "http://a3.twimg.com/profile_images/1156755747/head_trees_normal.jpg", :last-tweet "@greymouser I need to start writing some Clojure I guess :)", :mentions {"greymouser" 2}}, "sbtourist" {:image-url "http://a0.twimg.com/profile_images/72494229/Cryer_Black_normal.jpg", :last-tweet "Clooj, a lightweight Clojure IDE: http://t.co/OSCjr9X", :mentions {"djspiewak" 2}}, "jboner" {:image-url "http://a2.twimg.com/profile_images/1395654712/jonas_bw_small_normal.JPG", :last-tweet "RT @sbtourist: Clooj, a lightweight Clojure IDE: http://t.co/OSCjr9X", :mentions {"sbtourist" 2, "djspiewak" 2, "romanroe" 2}}}) |
| 39 | + |
| 40 | +(def test-graph (atom (list |
| 41 | + {"jboner" {:x 0.2 :y 0.8} "djspiewak" {:x 0.3 :y 0.2}} |
| 42 | + {"jboner" {:x 0.4 :y 0.7} "djspiewak" {:x 0.4 :y 0.3}} |
| 43 | + {"jboner" {:x 0.3 :y 0.8} "sbtourist" {:x 0.3 :y 0.2} "djspiewak" {:x 0.5 :y 0.5}} |
| 44 | + {"jboner" {:x 0.2 :y 0.7} "sbtourist" {:x 0.4 :y 0.1} "djspiewak" {:x 0.7 :y 0.4}}))) |
| 45 | + |
38 | 46 | (defn update-graph [tweets]
|
39 |
| - (draw-graph |
40 |
| - {"bob" |
41 |
| - {:image-url "http://a1.twimg.com/profile_images/1324487726/dr_bunsen_honeydew_normal.jpg" |
42 |
| - :mentions {"susan" 3 "joe" 2} |
43 |
| - :last-tweet "Clojure on JavaScript. Wow!"} |
44 |
| - "susan" |
45 |
| - {:image-url "http://a1.twimg.com/profile_images/1324487726/dr_bunsen_honeydew_normal.jpg" |
46 |
| - :mentions {"joe" 5} |
47 |
| - :last-tweet "ClojureScript doesn't have TCO! I'll never use it."}} |
48 |
| - {"bob" {:x 0.2 :y 0.7} "susan" {:x 0.4 :y 0.1}})) |
| 47 | + (draw-graph {:locs (peek @test-graph), :mentions test-users}) |
| 48 | + (swap! test-graph pop)) |
49 | 49 |
|
50 | 50 | (buzz/register update-graph)
|
0 commit comments