|
1 | 1 | (ns twitterbuzz.showgraph
|
2 | 2 | (:require [twitterbuzz.core :as buzz]
|
| 3 | + [twitterbuzz.anneal :as ann] |
| 4 | + [twitterbuzz.layout :as layout] |
3 | 5 | [goog.dom :as dom]
|
| 6 | + [goog.events :as events] |
| 7 | + [goog.fx.Animation :as anim] |
4 | 8 | [goog.graphics :as graphics]))
|
5 | 9 |
|
6 | 10 | ; Drawing configuration
|
7 |
| -(def avatar-size 0.15) ; used for both x and y dimensions of avatars |
| 11 | +(def avatar-size 0.07) ; used for both x and y dimensions of avatars |
8 | 12 | (def edge-widths [0 0.001 0.005 0.010 0.020]) ; More mentions == thicker edges
|
9 | 13 |
|
| 14 | +; BAD HACK: don't change globals like this -- find a better way: |
| 15 | +(set! anim/TIMEOUT 500) |
| 16 | + |
10 | 17 | (def edge-strokes
|
11 | 18 | (vec (map #(graphics/Stroke. % "#009") edge-widths)))
|
12 | 19 |
|
|
43 | 50 | {"jboner" {:x 0.3 :y 0.8} "sbtourist" {:x 0.3 :y 0.2} "djspiewak" {:x 0.5 :y 0.5}}
|
44 | 51 | {"jboner" {:x 0.2 :y 0.7} "sbtourist" {:x 0.4 :y 0.1} "djspiewak" {:x 0.7 :y 0.4}})))
|
45 | 52 |
|
46 |
| -(defn update-graph [tweets] |
47 |
| - (draw-graph {:locs (peek @test-graph), :mentions test-users}) |
48 |
| - (swap! test-graph pop)) |
| 53 | +(def animation (atom nil)) |
| 54 | + |
| 55 | +;(set! cljs.core/string-print (fn [x] (js* "console.log(~{x})"))) |
| 56 | + |
| 57 | +(set! (.cycle animation) |
| 58 | + (fn [t] |
| 59 | + (draw-graph (:best (first @animation))) |
| 60 | + (swap! animation rest))) |
| 61 | + |
| 62 | +(events/listen |
| 63 | + (dom/getElement "network") |
| 64 | + (array events/EventType.CLICK) |
| 65 | + (fn [_] |
| 66 | + (reset! animation |
| 67 | + (ann/anneal |
| 68 | + layout/score |
| 69 | + (ann/linear-cooling 1000) |
| 70 | + layout/permute-move |
| 71 | + ann/standard-prob |
| 72 | + (layout/init-state test-users))) |
| 73 | + (anim/registerAnimation animation))) |
49 | 74 |
|
50 |
| -(buzz/register update-graph) |
|
0 commit comments