-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathposts.html
More file actions
171 lines (150 loc) · 4.51 KB
/
posts.html
File metadata and controls
171 lines (150 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
---
layout: page
title: Blog posts
menu: main
navigation_weight: 5
color: "#cbd5e8"
---
These blog posts are primarily meant as external memory for members of the lab.
<table>
<tr>
<td colspan="2" valign="top">
<div id="visual"></div>
<script type="text/javascript" src="d3.min.js"></script>
<script type="text/javascript" src="d3.layout.cloud.js"></script>
<!-- <script type="text/javascript" src="underscore-min.js"></script> -->
<script>
{% capture tags %}
[
{% for post in site.categories.main %}
{% unless post.private %}
{% for tag in post.tags %}
"{{tag}}"|
{% endfor %}
{% endunless %}
{% endfor %}
]
{% endcapture %}
var words = {{ tags | strip_newlines | replace: "|", ","}}
var cloudData = {};
words.forEach(function(w) {
if (cloudData.hasOwnProperty(w)) {
cloudData[w] = cloudData[w] + 1
} else {
cloudData[w] = 1
}
})
var data = []
data = Object.keys(cloudData).map(function(w) {
return {text: w, size: cloudData[w]*10}
})
console.log(JSON.stringify(data))
var fill = d3.scale.category20();
d3.layout.cloud().size([800, 500])
.words(data)
.padding(5)
.rotate(function() { return ~~(Math.random() * 2) * 90; })
.font("Impact")
.fontSize(function(d) { return d.size; })
.on("end", draw)
.start();
function draw(words) {
d3.select("#visual").append("svg")
.attr("width", 800)
.attr("height", 500)
.append("g")
.attr("transform", "translate(400,250)")
.selectAll("text")
.data(words)
.enter()
.append("a")
.attr("xlink:href", function(d) { return "#" + d.text }).append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Roboto")
.style("fill", function(d, i) { return fill(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; });
}
function drawUpdate(words){
d3.layout.cloud().size([800, 500])
.words(words)
.padding(5)
.rotate(function() { return ~~(Math.random() * 2) * 90; })
.font("Impact")
.fontSize(function(d) { return d.size; })
.start();
d3.select("svg")
.selectAll("g")
.attr("transform", "translate(400,250)")
.selectAll("text")
.data(words).enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Roboto")
.style("fill", function(d, i) { return fill(i); })
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; });
}
setInterval(function () {
var d_new = data;
d_new.push({word:randomWord(),weight:randomWeight()});
drawUpdate(d_new.map(function(d) {
return {text: d.word, size: d.weight};
}));
}, 1500);
function randomWord() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
function randomWeight(){
var r = Math.round(Math.random() * 100);
return r;
}
</script>
</td></tr>
<tr><td>
<h2 id="bytag">:: By tag ::</h2>
{% capture tags %}
{% for tag in site.tags %}
{% assign publicexists = false %}
{% for post in tag[1] %}
{% unless post.private %}
{% assign publicexists = true %}
{% endunless %}
{% endfor %}
{% if publicexists %}
{{ tag | first }}
{% endif %}
{% endfor %}
{% endcapture %}
{% assign sortedtags = tags | split:' ' | sort %}
{% for tag in sortedtags %}
<h3 id="{{ tag }}">- {{ tag }}</h3>
<ul>
{% for post in site.tags[tag] %}
{% unless post.private %}
<li><time style="color:#666;font-size:11px;" datetime='{{post.date | date: "%Y-%m-%d"}}'>{{post.date | date: "%m/%d/%y"}}</time> <a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a></li>
{% endunless %}
{% endfor %}
</ul>
{% endfor %}
</td>
<td valign="top">
<h2 id="chronological">:: Chronological ::</h2>
<ul>
{% for post in site.categories.main %}
{% unless post.private %}
<li>
<time style="color:#666;font-size:11px;" datetime='{{post.date | date: "%Y-%m-%d"}}'>{{post.date | date: "%m/%d/%y"}}</time> <a href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a>
</li>
{% endunless %}
{% endfor %}
</ul>
</td></tr></table>