File tree Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Expand file tree Collapse file tree 2 files changed +17
-19
lines changed Original file line number Diff line number Diff line change 44
44
(defn radial
45
45
[mentions-data]
46
46
(let [mentions #(rad/get-mentions mentions-data %)
47
- weights (rad/branch- weights
47
+ weights (rad/weights
48
48
(into #{} (mapcat mentions (keys mentions-data)))
49
49
mentions)]
50
50
{:mentions mentions-data
Original file line number Diff line number Diff line change 29
29
(into (disj check c) (remove kids (child-fn c))))
30
30
kids))))
31
31
32
- (defn branch-weights
33
- " Return a map of node to its weight (number of descendants),
34
- using child-fn to get the set of children for a node.
35
- Recursive, assumes no cycles."
32
+ (defn weight
33
+ " Weight of noce, given child-fn (mapping of node to set
34
+ of kids)."
35
+ [node child-fn]
36
+ (if-let [kids (seq (child-fn node))]
37
+ (reduce + (map #(weight % child-fn) kids))
38
+ 1 ))
39
+
40
+ (defn weights
41
+ " Return a map of node to its weight,
42
+ using child-fn to get the set of children for a node."
36
43
[nodes child-fn]
37
- (loop [weights {}
38
- known #{}
39
- remaining (set nodes)]
40
- (let [nodes (remove (fn [n] (seq (set/difference (child-fn n) known))) remaining)]
41
- (if (seq nodes)
42
- (recur (into weights (map
43
- (fn [n] [n (+ 1
44
- #_(count (child-fn n))
45
- (reduce + (map weights (child-fn n))))])
46
- nodes))
47
- (into known nodes)
48
- (set/difference remaining nodes))
49
- weights))))
44
+ (reduce
45
+ (fn [m n] (assoc m n (weight n child-fn)))
46
+ {}
47
+ nodes))
50
48
51
49
(defn layout
52
50
" Returns a map of node => :radius, :slice, :angle.
68
66
(recur
69
67
(merge
70
68
m
71
- {node {:radius radius :slice s :angle (math/average c1 c2)}}
69
+ {node {:radius radius :slice s :angle (/ ( + c1 c2) 2 )}}
72
70
(when-let [children (seq (remove seen (child-fn node)))]
73
71
(layout children weight-fn child-fn (inc radius) c1 c2 seen)))
74
72
c2
You can’t perform that action at this time.
0 commit comments