Skip to content

Commit f9055b7

Browse files
committed
Hook up annealing to showgraph. Click blank network to start! clojure#48
1 parent 18cdadd commit f9055b7

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

samples/twitterbuzz/src/twitterbuzz/showgraph.cljs

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
(ns twitterbuzz.showgraph
22
(:require [twitterbuzz.core :as buzz]
3+
[twitterbuzz.anneal :as ann]
4+
[twitterbuzz.layout :as layout]
35
[goog.dom :as dom]
6+
[goog.events :as events]
7+
[goog.fx.Animation :as anim]
48
[goog.graphics :as graphics]))
59

610
; 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
812
(def edge-widths [0 0.001 0.005 0.010 0.020]) ; More mentions == thicker edges
913

14+
; BAD HACK: don't change globals like this -- find a better way:
15+
(set! anim/TIMEOUT 500)
16+
1017
(def edge-strokes
1118
(vec (map #(graphics/Stroke. % "#009") edge-widths)))
1219

@@ -43,8 +50,25 @@
4350
{"jboner" {:x 0.3 :y 0.8} "sbtourist" {:x 0.3 :y 0.2} "djspiewak" {:x 0.5 :y 0.5}}
4451
{"jboner" {:x 0.2 :y 0.7} "sbtourist" {:x 0.4 :y 0.1} "djspiewak" {:x 0.7 :y 0.4}})))
4552

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)))
4974

50-
(buzz/register update-graph)

0 commit comments

Comments
 (0)