-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet_wall.html
345 lines (271 loc) · 9.07 KB
/
tweet_wall.html
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<style>
html, body {
height: 100%;
overflow:hidden;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
svg {
display: inline-block;
position: relative;
width: 100%;
padding-bottom: 100%; /* aspect ratio */
vertical-align: top;
overflow: hidden;
}
.svg-content-responsive {
display: inline-block;
position: absolute;
top: 0;
left: 0;
}
.free-wall {
margin: 15px;
}
.brick {
width: 200px;
margin: 0px;
padding: 0px;
display: block;
}
.info {
padding: 15px;
color: #333;
}
#staytweet {position:absolute;left:0;width:2500px;top:25px;}
#leavetweet {position:absolute;right:0;width:2500px;top:25px;}
#stayhead {position:absolute;left:2500px;top:0;}
#leavehead {position:absolute;right:2500px;top:0;}
</style>
<meta http-equiv="refresh" content="60000">
<!-- External Resources-->
<script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));
</script>
<!-- Insert this line above script imports -->
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<!-- normal script imports etc -->
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script src="js/freewall.js" type="text/javascript"></script>
<!-- Insert this line after script imports -->
<script>if (window.module) module = window.module;</script>
</head>
<body>
<script>
var margin = {top: 0, right: 0, bottom: 0, left: 0},
width = 6400 - margin.left - margin.right,
height = 900 - margin.top - margin.bottom;
//var y = d3.time.scale()
//.range([height, 0]);
var y = d3.scale.ordinal()
.rangeRoundBands([height, 0]);
var x = d3.scale.linear()
.rangeRound([0, width]);
//var color = d3.scale.ordinal()
// .range(["#000099", "#ffffff", "#CF142B"]);
var color = d3.scale.threshold()
.domain([40, 20, 5, -5, -20, -40])
.range(["#2265f7", "#6995f4", "#bbcef7","#f9f7f7","#f7adad", "#f96b6b", "#f22b2b"]);
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.tickFormat(d3.format(".2s"));
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.attr("viewBox", "0 80 " + width + " " + height )
.attr("preserveAspectRatio", "xMinYMin meet")
.append("g");
//.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
/*
var svg = d3.select("body")
.append("div")
.classed("svg-container", true)
.append("svg")
//.attr("width", width + margin.left + margin.right)
//.attr("height", height + margin.top + margin.bottom)
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 600 400")
//class to make it responsive
.classed("svg-content-responsive", true)
.append("g");
//.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
/*
var svg = d3.select("div#chartId")
.append("div")
.classed("svg-container", true) //container class to make it responsive
.append("svg")
//responsive SVG needs these 2 attributes and no width and height attr
.attr("preserveAspectRatio", "xMinYMin meet")
.attr("viewBox", "0 0 600 400")
//class to make it responsive
.classed("svg-content-responsive", true);
*/
d3.csv("data/state_votes.csv", function(error, s_votes) {
d3.csv("data/pres_polls.csv", function(error, data) {
if (error) throw error;
//data = data.smoothedData;
data.sort(function(a, b) { return a[data.columns[4]] - b[data.columns[5]] ;});
/* data.forEach(function(d) {
d.date = new Date(d.date);
});
*/
//color.domain(d3.keys(data[0]).filter(function(key) { return key !== "date"; }));
//color.domain(["remain", "undecided", "leave"]);
//color.domain(d3.keys(data[0]).filter(function(key) { return ((key !== "date") && (key !== "method") && (key !== "pollOfPolls")); }));
data.forEach(function(d) {
var y0 = 0;
d.votes = color.domain().map(function(name) { return {name: name, y0: y0, y1: y0 += +d[name]}; });
d.total = d.votes[d.votes.length - 1].y1;
});
//data.sort(function(a, b) { return b.total - a.total; });
//var testY = d3.extent(data, function(d) { return d.date; });
//y.domain(d3.extent(data, function(d) { return d.date; }));
y.domain(data.map(function(d) { return d.date; }));
//number of electorits 538
x.domain([0, 538]);
/*svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
*/
var testdate = data[0].date;
var test = y(data[0].date);
var state = svg.selectAll(".state")
.data(data)
.enter().append("g")
.attr("class", "g")
.attr("transform", function(d) { return "translate(0," + y(d.date) + ")"; });
state.selectAll("rect")
.data(function(d) { return d.votes; })
.enter().append("rect")
.attr("height", height/data.length)
.attr("x", function(d) { return x(d.y0); })
.attr("width", function(d) { return x(d.y1) - x(d.y0); })
.style("fill", function(d) { return color(d.name); });
svg.append("svg:line") // attach a line
.style("stroke", "black") // colour the line
.style("stroke-width", "5") // colour the line
.attr("x1", 3200) // x position of the first end of the line
.attr("y1", 0) // y position of the first end of the line
.attr("x2", 3200) // x position of the second end of the line
.attr("y2", 900);
});
});
</script>
<div id="stayhead"><H1><strong>#Stay</strong></H1></div>
<div id="staytweet" class="free-wall">
</div>
<div id="leavehead"><H1><strong>#Leave</strong></H1></div>
<div id="leavetweet" class="free-wall">
</div>
<script>
// This example requires the Visualization library. Include the libraries=visualization
// parameter when you first load the API. For example:
//<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDhm1qNyoXWr4sVC7_hnTD4T4yYdIMBNsM&libraries=visualization">
//var map, heatmapPos, liveTweetsPos;
//var timeseries = [];
//var socket = io.connect('http://localhost:3700');
var socket = io.connect('http://sociamvm-app-001.ecs.soton.ac.uk:3700');
socket.emit("load_data","");
console.log("testing if we load data");
socket.on('stay-tweets', function (tweets) {
console.log("@@@@@@@@@stay-tweets");
console.log("####STAY Meta##", tweets["search_metadata"]);
//staytweet
$("#staytweet").empty();
$( "#staytweet" ).append( "<H2><strong>#Stay</strong></H2>" );
for(var i=0; i<15; i++) {
//var data = JSON.parse(tweets["statuses"][i]);
var data = tweets["statuses"][i];
//$("#tweet"+i).empty();
$( "#staytweet" ).append( '<div class="brick" id="tweet'+i+'"></div>');
twttr.widgets.createTweet(
data.id_str,
document.getElementById('tweet'+i),
{
align: 'left',
width: 80,
height: '400px',
})
.then(function (el) {
console.log("@ev's Stay Tweet has been displayed.");
var wall = new Freewall("#staytweet");
//wall.fitWidth();
wall.reset({
selector: '.brick',
animate: true,
cellW: 200,
cellH: 'auto',
onResize: function() {
wall.fitWidth();
}
});
$(window).trigger("resize");
});
}
twttr.widgets.load(
document.getElementById("staytweet")
);
});///socket stay
socket.on('leave-tweets', function (tweets) {
console.log("########leave-data");
$("#leavetweet").empty();
$( "#leavetweet" ).append( "<H2><strong>#Leave</strong></H2>" );
for(var i=0; i<15; i++) {
var data = tweets["statuses"][i];
//$("#Ltweet"+i).empty();
$( "#leavetweet" ).append( '<div class="brick" id="Ltweet'+i+'"></div>' );
//console.log("leave-data:", data);
twttr.widgets.createTweet(
data.id_str,
document.getElementById('Ltweet'+i),
{
align: 'left',
width: 100,
height: '400px',
})
.then(function (el) {
console.log("@ev's Leave Tweet has been displayed.");
var wall = new Freewall("#leavetweet");
wall.reset({
selector: '.brick',
animate: true,
cellW: 200,
cellH: 'auto',
onResize: function() {
wall.fitWidth();
}
});
$(window).trigger("resize");
});
}
twttr.widgets.load(
document.getElementById("leavetweet")
);
});
</script>
</body>