Skip to content

Commit 0226e55

Browse files
committed
Merge branch 'master' of [email protected]:relevance/clojurescript
2 parents dffb31d + 223aacd commit 0226e55

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

samples/twitterbuzz/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ <h2>Timeline</h2>
7272
<script type="text/javascript">
7373
goog.require('twitterbuzz.core');
7474
goog.require('twitterbuzz.timeline');
75+
goog.require('twitterbuzz.showgraph');
7576
</script>
7677

7778
</body>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(ns twitterbuzz.showgraph
2+
(:require [twitterbuzz.core :as buzz]
3+
[goog.dom :as dom]
4+
[goog.graphics :as graphics]))
5+
6+
; Drawing configuration
7+
(def avatar-size 0.15) ; used for both x and y dimensions of avatars
8+
(def edge-widths [0 0.001 0.005 0.010 0.020]) ; More mentions == thicker edges
9+
10+
(def edge-strokes
11+
(vec (map #(graphics/Stroke. % "#009") edge-widths)))
12+
13+
(def max-stroke (peek edge-strokes))
14+
15+
(def g
16+
(doto (graphics/createGraphics "100%" "100%" 1.0 1.0)
17+
(.render (dom/getElement "network"))))
18+
19+
(defn draw-graph [users nodes]
20+
; 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))))
29+
30+
; Draw avatar nodes
31+
(let [offset (/ avatar-size 2)]
32+
(doseq [[username {:keys [x y]}] nodes]
33+
(.drawImage g (- x offset) (- y offset) avatar-size avatar-size
34+
(-> users (get username) :image-url)))))
35+
36+
; This is temporary. The graph data should flow somehow from the
37+
; tweets. For now, just hardcode some:
38+
(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}}))
49+
50+
(buzz/register update-graph)

samples/twitterbuzz/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ section#status-bar a.reset-search {
5050

5151
#network {
5252
width: 500px;
53-
height: 680px;
53+
height: 500px;
5454
padding: 10px 10px 0 0;
5555
float: left;
5656
}

0 commit comments

Comments
 (0)