File tree 1 file changed +12
-10
lines changed
Clojure-Websockets/MainApp/src/cljs/birdwatch/charts
1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 30
30
[:polygon {:transform arrowTrans :stroke " none" :fill color :points points}]))
31
31
32
32
(defn bar [text cnt y h w idx]
33
- (let [pos-slope (get @pos-trends text)]
33
+ (let [pos-slope (get @pos-trends text)
34
+ ratio-slope (get @ratio-trends text)]
34
35
[:g
35
36
[:text {:y (+ y 8 ) :x 138 :stroke " none" :fill " black" :dy " .35em" :textAnchor " end" } text]
36
- [arrow 146 y (cond
37
- (pos? pos-slope) :UP
38
- (neg? pos-slope ) :DOWN
39
- :else :RIGHT )]
40
- [arrow 160 y :RIGHT ]
37
+ [arrow 146 y (cond (pos? pos-slope) :UP (neg? pos-slope ) :DOWN :else :RIGHT )]
38
+ [arrow 160 y (cond (pos? ratio-slope) :RIGHT-UP (neg? ratio-slope ) :RIGHT-DOWN :else :RIGHT )]
41
39
[:rect {:y y :x 168 :height 15 :width w :stroke " white" :fill " #428bca" }]
42
40
(if (> w 50 )
43
41
[:text (merge text-defaults {:y (+ y 8 ) :x (+ w 160 )}) cnt]
66
64
" update wordcount chart"
67
65
[words]
68
66
(reset! items (vec (map-indexed vector words)))
69
- (doseq [[idx [text cnt]] @items]
70
- (let [slope (get (reg/linear-regression (take 3 (get @pos-items text))) 1 )]
67
+ (let [items @items
68
+ total-cnt (apply + (map (fn [[_[_ cnt]]] cnt) items))]
69
+ (doseq [[idx [text cnt]] items]
71
70
(swap! pos-items update-in [text] conj idx)
72
- (swap! pos-trends assoc-in [text] slope))))
73
-
71
+ (swap! ratio-items update-in [text] conj (/ total-cnt cnt))
72
+ (swap! pos-trends assoc-in [text]
73
+ (get (reg/linear-regression (take 3 (get @pos-items text))) 1 ))
74
+ (swap! ratio-trends assoc-in [text]
75
+ (get (reg/linear-regression (take 1000 (get @ratio-items text))) 1 )))))
You can’t perform that action at this time.
0 commit comments