| author | Raphael Velt <raph.velt@gmail.com> |
| Wed, 02 Nov 2011 17:13:23 +0100 | |
| changeset 342 | 60b8281442b8 |
| parent 341 | cab5c9e10f90 |
| permissions | -rw-r--r-- |
| 333 | 1 |
var socket, |
2 |
tlPaper, |
|
3 |
twPaper, |
|
4 |
tweetData = { |
|
5 |
"tweetcount" : 0, |
|
6 |
"position" : 0, |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
7 |
"feedMode" : true, |
| 333 | 8 |
"followLast" : true, |
9 |
"zoomLevel" : 3, |
|
10 |
"timeLevel" : 2, |
|
11 |
"tweets" : [], |
|
12 |
"posIndex" : [], |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
13 |
"tlChanged" : true, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
14 |
"tlLevelChanged" : true, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
15 |
"blockUpdate" : false, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
16 |
"waitUpdate" : true, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
17 |
"htmlBuffer" : '', |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
18 |
"wheelDelta" : 0 |
| 333 | 19 |
}, |
20 |
displaySplitting = [ |
|
21 |
{ |
|
22 |
positions : [ 10, 20, 22, 24, 25, 26, 27, 28, 29, 31, 33, 43, 53 ], |
|
23 |
classNames : [ 'icons fade', 'icons', 'quarter fade', 'quarter', 'half fade', 'half', 'full', 'half', 'half fade', 'quarter', 'quarter fade', 'icons', 'icons fade' ] |
|
24 |
}, |
|
25 |
{ |
|
26 |
positions : [ 1, 3, 5, 7, 13, 33, 53 ], |
|
27 |
classNames : [ 'full', 'half', 'half fade', 'quarter', 'quarter fade', 'icons', 'icons fade' ] |
|
28 |
} |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
29 |
]; |
| 333 | 30 |
|
31 |
function placeHolder(className) { |
|
32 |
return '<li class="placeholder ' + className + '"></li>'; |
|
33 |
} |
|
34 |
||
| 340 | 35 |
function getLinkedTweets() { |
36 |
socket.emit('linkedTweets',{"tweetpos":tweetData.position}); |
|
37 |
} |
|
38 |
||
39 |
function changeMode() { |
|
40 |
if (tweetData.feedMode) { |
|
41 |
getLinkedTweets(); |
|
42 |
} else { |
|
43 |
tweetData.feedMode = true; |
|
44 |
updateDisplay(); |
|
45 |
} |
|
46 |
} |
|
47 |
||
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
48 |
function clicTweet(tweetPos) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
49 |
if (tweetPos != tweetData.position) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
50 |
tweetData.position = tweetPos; |
| 340 | 51 |
if (tweetData.feedMode) { |
52 |
tweetData.followLast = (tweetData.position == tweetData.tweetcount); |
|
53 |
} else { |
|
54 |
getLinkedTweets(); |
|
55 |
} |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
56 |
return false; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
57 |
} else { |
| 340 | 58 |
changeMode(); |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
59 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
60 |
} |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
61 |
|
| 333 | 62 |
function tweetToHtml(tweet, className) { |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
63 |
if (!tweet) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
64 |
return placeHolder(className); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
65 |
} |
| 342 | 66 |
var html = '<li class="tweet ' + className + '" id="tweet_' + tweet.pos + '" onclick="return clicTweet(' + tweet.pos + ')"'; |
| 333 | 67 |
if (tweetData.followLast && tweet.pos == tweetData.position) { |
68 |
html += ' style="display: none"'; |
|
69 |
} |
|
70 |
html += '>'; |
|
71 |
if (tweet.annotations.length) { |
|
72 |
html += '<div class="annotations">'; |
|
73 |
for (var i in tweet.annotations) { |
|
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
74 |
html += '<div class="annotation" style="width:' + (100/tweet.annotations.length) + '%; background:' + annotations[tweet.annotations[i]].colors.tweet + '"></div>'; |
| 333 | 75 |
} |
76 |
html += '</div>'; |
|
77 |
} |
|
78 |
html += '<div class="twmain">'; |
|
| 342 | 79 |
a_user = '<a href="http://twitter.com/' + tweet.user.screen_name + '" var target="_blank" title="' + tweet.user.name + '">'; |
| 333 | 80 |
if (tweet.user.profile_image_url) { |
81 |
html += a_user + '<img class="profile_image" src="' + tweet.user.profile_image_url + '" /></a>'; |
|
82 |
} |
|
83 |
html += '<h4>' + a_user + '@' + tweet.user.screen_name + '</a></h4><p class="created_at">' + new Date(tweet.created_at).toLocaleTimeString() + '</p><p class="tweet_text">'; |
|
84 |
lastend = 0; |
|
| 342 | 85 |
var tab = tweet.text.split(/\&\#|\;/); |
86 |
var txta = ''; |
|
87 |
for (i = 0; i < tab.length; i++) { |
|
88 |
txta += (i % 2 && parseInt(tab[i]) != NaN) ? String.fromCharCode(tab[i]) : tab[i]; |
|
89 |
} |
|
90 |
var txt = '', |
|
91 |
entities = []; |
|
| 333 | 92 |
for (var i in tweet.entities.hashtags) { |
93 |
entities.push({ |
|
94 |
"start" : tweet.entities.hashtags[i].indices[0], |
|
95 |
"end" : tweet.entities.hashtags[i].indices[1], |
|
96 |
"html" : '<a href="http://twitter.com/search?q=%23' + tweet.entities.hashtags[i].text + '" target="_blank">#' + tweet.entities.hashtags[i].text + '</a>' |
|
97 |
}); |
|
98 |
} |
|
99 |
for (var i in tweet.entities.urls) { |
|
100 |
entities.push({ |
|
101 |
"start" : tweet.entities.urls[i].indices[0], |
|
102 |
"end" : tweet.entities.urls[i].indices[1], |
|
| 342 | 103 |
"html" : '<a href="' + tweet.entities.urls[i].expanded_url + '" target="_blank">' + tweet.entities.urls[i].expanded_url + '</a>' |
| 333 | 104 |
}); |
105 |
} |
|
106 |
for (var i in tweet.entities.user_mentions) { |
|
107 |
entities.push({ |
|
108 |
"start" : tweet.entities.user_mentions[i].indices[0], |
|
109 |
"end" : tweet.entities.user_mentions[i].indices[1], |
|
110 |
"html" : '<a href="http://twitter.com/' + tweet.entities.user_mentions[i].screen_name + '" target="_blank" title="' + tweet.entities.user_mentions[i].name + '">@' + tweet.entities.user_mentions[i].screen_name + '</a>' |
|
111 |
}); |
|
112 |
} |
|
113 |
entities.sort(function(a, b) { return a.start - b.start }); |
|
114 |
for (var i in entities) { |
|
| 342 | 115 |
txt += txta.substring(lastend, entities[i].start) + entities[i].html; |
| 333 | 116 |
lastend = entities[i].end; |
117 |
} |
|
| 342 | 118 |
txt += txta.substring(lastend); |
| 333 | 119 |
html += txt + '</p></li></div>'; |
120 |
return html; |
|
121 |
} |
|
122 |
||
123 |
||
124 |
function getUpdate() { |
|
125 |
tweetData.posToDisplay = []; |
|
| 340 | 126 |
if (tweetData.feedMode) { |
127 |
if (tweetData.followLast) { |
|
128 |
tweetData.position = tweetData.tweetcount; |
|
129 |
for (var i = tweetData.tweetcount; i >= tweetData.tweetcount - 52; i--) { |
|
130 |
tweetData.posToDisplay.push( i > 0 ? i : -1 ); |
|
131 |
} |
|
132 |
tweetData.end = tweetData.tweetcount; |
|
133 |
tweetData.start = Math.max(1, tweetData.end - 52); |
|
134 |
} else { |
|
135 |
for (var i = tweetData.position + 26; i >= tweetData.position - 26; i--) { |
|
136 |
tweetData.posToDisplay.push( i > 0 && i <= tweetData.tweetcount ? i : -1 ); |
|
137 |
} |
|
138 |
tweetData.end = Math.min(tweetData.tweetcount, tweetData.position + 26 ); |
|
139 |
tweetData.start = Math.max(1, tweetData.position - 26); |
|
| 333 | 140 |
} |
| 340 | 141 |
if ($("#modeselector").text() != "Mode flux") { |
142 |
$("#modeselector").html("Mode Flux").css({"color":"#000000","background":"#ffffff"}); |
|
143 |
$("#tweetlist").css({"background":"#ffffff"}); |
|
144 |
} |
|
| 333 | 145 |
} else { |
| 340 | 146 |
tweetData.linkedTweets.referenced_by.sort(function(a,b) { return b.pos - a.pos }); |
147 |
tweetData.linkedTweets.referencing.sort(function(a,b) { return b.pos - a.pos }); |
|
148 |
for (var i in tweetData.linkedTweets.referenced_by) { |
|
149 |
tweetData.posToDisplay.push(tweetData.linkedTweets.referenced_by[i].pos); |
|
| 333 | 150 |
} |
| 340 | 151 |
tweetData.posToDisplay.push(tweetData.position); |
152 |
for (var i in tweetData.linkedTweets.referencing) { |
|
153 |
tweetData.posToDisplay.push(tweetData.linkedTweets.referencing[i].pos); |
|
154 |
} |
|
155 |
if ($("#modeselector").text() != "Conversation") { |
|
156 |
$("#modeselector").html("Conversation").css({"color":"#ffffff","background":"#000080"}); |
|
157 |
$("#tweetlist").css({"background":"#000080"}); |
|
158 |
} |
|
| 333 | 159 |
} |
160 |
var tweetsToGet = []; |
|
| 340 | 161 |
for (var i in tweetData.posToDisplay) { |
162 |
if (tweetData.posToDisplay[i] != -1 && !tweetByPos(tweetData.posToDisplay[i])) { |
|
163 |
tweetsToGet.push(tweetData.posToDisplay[i]); |
|
| 333 | 164 |
} |
165 |
} |
|
166 |
if (tweetsToGet.length) { |
|
| 340 | 167 |
// console.log('We need to get '+tweetsToGet.join(',')); |
| 333 | 168 |
socket.emit('updateTweets', { |
169 |
"tweets" : tweetsToGet |
|
170 |
}); |
|
171 |
} else { |
|
172 |
drawTweetList(); |
|
173 |
} |
|
| 340 | 174 |
/* html = ''; |
175 |
for (var i in tweetData.linkedTweets.referenced_by) { |
|
176 |
console.log(tweetData.linkedTweets.referenced_by[i]); |
|
177 |
html += tweetToHtml(tweetData.linkedTweets.referenced_by[i].tweet,'half'); |
|
178 |
} |
|
179 |
html += tweetToHtml(tweetByPos(tweetData.position),'full'); |
|
180 |
for (var i in tweetData.linkedTweets.referencing) { |
|
181 |
console.log(tweetData.linkedTweets.referencing[i]); |
|
182 |
html += tweetToHtml(tweetData.linkedTweets.referencing[i].tweet,'half'); |
|
183 |
} |
|
184 |
if (tweetData.htmlBuffer != html) { |
|
185 |
$("#tweetlist").html(html); |
|
186 |
tweetData.htmlBuffer = html; |
|
187 |
} */ |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
188 |
if (tweetData.tlChanged || tweetData.tlLevelChanged) { |
| 333 | 189 |
socket.emit('updateTimeline', { |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
190 |
"level" : tweetData.timeLevel, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
191 |
"full" : tweetData.tlLevelChanged |
| 333 | 192 |
}); |
193 |
} else { |
|
194 |
drawTimeLine(); |
|
195 |
} |
|
196 |
} |
|
197 |
||
| 340 | 198 |
function addTweet(tweet) { |
199 |
if (tweetData.posIndex.indexOf(tweet.pos) == -1) { |
|
200 |
tweetData.tweets.push(tweet); |
|
201 |
tweetData.posIndex.push(tweet.pos); |
|
202 |
} |
|
203 |
} |
|
204 |
||
| 333 | 205 |
function tweetByPos(pos) { |
206 |
var index = tweetData.posIndex.indexOf(pos); |
|
207 |
return (index == -1 ? false : tweetData.tweets[index]); |
|
208 |
} |
|
209 |
||
210 |
function delayedUpdate() { |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
211 |
tweetData.blockUpdate = false; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
212 |
if (tweetData.waitUpdate) { |
| 333 | 213 |
updateDisplay(); |
214 |
} |
|
215 |
} |
|
216 |
||
217 |
function updateDisplay() { |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
218 |
if (tweetData.blockUpdate) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
219 |
tweetData.waitUpdate = true; |
| 333 | 220 |
} else { |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
221 |
tweetData.waitUpdate = false; |
| 333 | 222 |
getUpdate(); |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
223 |
tweetData.blockUpdate = true; |
| 341 | 224 |
setTimeout(delayedUpdate, 100); |
| 333 | 225 |
} |
226 |
} |
|
227 |
||
228 |
function setTimeZoom(level) { |
|
229 |
if (level >= 0 && level <= 4) { |
|
230 |
tweetData.timeLevel = level; |
|
231 |
tweetData.tlChanged = true; |
|
232 |
updateDisplay(); |
|
233 |
} |
|
234 |
} |
|
235 |
||
236 |
function drawTweetList() { |
|
237 |
html = ''; |
|
238 |
var i = 0; |
|
239 |
while (i < tweetData.posIndex.length) { |
|
240 |
if (tweetData.posToDisplay.indexOf(tweetData.posIndex[i]) == -1) { |
|
241 |
tweetData.posIndex.splice(i,1); |
|
242 |
tweetData.tweets.splice(i,1); |
|
243 |
} else { |
|
244 |
i++; |
|
245 |
} |
|
246 |
} |
|
| 340 | 247 |
if (tweetData.feedMode) { |
248 |
for (var i in tweetData.posToDisplay) { |
|
249 |
var ds = displaySplitting[tweetData.followLast ? 1 : 0]; |
|
250 |
for (var j in ds.positions) { |
|
251 |
if (ds.positions[j] > i) { |
|
252 |
var className = ds.classNames[j]; |
|
253 |
break; |
|
254 |
} |
|
| 333 | 255 |
} |
| 340 | 256 |
html += ( tweetData.posToDisplay[i] != -1 ? tweetToHtml(tweetByPos(tweetData.posToDisplay[i]), className) : placeHolder(className) ); |
| 333 | 257 |
} |
| 340 | 258 |
} else { |
259 |
for (var i in tweetData.posToDisplay) { |
|
260 |
html += tweetToHtml(tweetByPos(tweetData.posToDisplay[i]), (tweetData.posToDisplay[i] == tweetData.position ? 'full' : 'half' )); |
|
261 |
} |
|
| 333 | 262 |
} |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
263 |
if (tweetData.htmlBuffer != html) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
264 |
$("#tweetlist").html(html); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
265 |
tweetData.htmlBuffer = html; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
266 |
} |
| 333 | 267 |
if (tweetData.followLast) { |
268 |
$("#tweet_" + tweetData.position).fadeIn(500); |
|
269 |
} |
|
270 |
drawTimeWindow(); |
|
271 |
} |
|
272 |
||
273 |
function drawTimeWindow() { |
|
274 |
twPaper.clear(); |
|
275 |
if (!tweetData.timeline || !tweetData.timeline.length) return; |
|
276 |
|
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
277 |
var dtfintl = tweetData.timeline[ tweetData.timeline.length - 1 ].end, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
278 |
dtdebtl = tweetData.timeline[0].start, |
| 333 | 279 |
scY = 600 / ( dtfintl - dtdebtl ); |
| 340 | 280 |
if (tweetData.feedMode) { |
281 |
var dtfintw = new Date( tweetByPos( tweetData.end ).created_at ), |
|
282 |
dtdebtw = new Date( tweetByPos( tweetData.start ).created_at ), |
|
283 |
rTop = scY * ( dtfintl - dtfintw ), |
|
284 |
rHeight = scY * ( dtfintw - dtdebtw ); |
|
285 |
if (rHeight > 0) { |
|
286 |
twPaper.rect( 0, rTop, 300, rHeight).attr({"stroke":"none","fill":"#8080ff","fill-opacity":.2}); |
|
287 |
} |
|
288 |
} else { |
|
289 |
for (var i in tweetData.posToDisplay) { |
|
290 |
if (tweetData.posToDisplay[i] != -1) { |
|
291 |
var tw = tweetByPos(tweetData.posToDisplay[i]); |
|
292 |
if (tw) { |
|
293 |
var dtcour = new Date( tw.created_at ), |
|
294 |
posY = scY * ( dtfintl - dtcour ); |
|
295 |
twPaper.path("M0 "+posY+"L300 "+posY).attr({"stroke":"#88f"}); |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
| 333 | 300 |
var dtcour = new Date( tweetByPos( tweetData.position ).created_at ), |
301 |
posY = scY * ( dtfintl - dtcour ); |
|
302 |
twPaper.path("M0 "+posY+"L300 "+posY).attr({"stroke":"#ff0"}); |
|
303 |
} |
|
304 |
||
305 |
function drawTimeLine() { |
|
306 |
tlPaper.clear(); |
|
307 |
if (!tweetData.timeline || !tweetData.timeline.length) return; |
|
308 |
tweetData.tlTweetRects = []; |
|
309 |
var scaleY = 600 / tweetData.timeline.length, |
|
310 |
max = 0; |
|
311 |
for (var i = 0; i < tweetData.timeline.length; i++) { |
|
312 |
max = Math.max(max, tweetData.timeline[i].tweets); |
|
313 |
} |
|
314 |
var scaleX = 160 / max; |
|
315 |
|
|
316 |
// dessin de l'axe vertical |
|
317 |
|
|
318 |
tlPaper.path("M160 0L160 600").attr({"stroke":"#ccc"}); |
|
319 |
|
|
320 |
// dessin de la date de début |
|
321 |
|
|
322 |
tlPaper.text(165, 592, new Date(tweetData.timeline[0].start).toLocaleTimeString()).attr({ "text-anchor" : "start", "font-size": "12px" }); |
|
323 |
|
|
324 |
// dessin de la date de fin |
|
325 |
|
|
326 |
tlPaper.text(165, 7, new Date(tweetData.timeline[tweetData.timeline.length - 1].end).toLocaleTimeString()).attr({ "text-anchor" : "start", "font-size": "12px" }); |
|
327 |
for (var i = 0; i < tweetData.timeline.length; i++) { |
|
328 |
var posY = 600 - (i * scaleY); |
|
329 |
|
|
330 |
// Si on est à une demi-heure, on trace un axe secondaire + heure |
|
331 |
|
|
332 |
if (i && !(new Date(tweetData.timeline[i].start).valueOf() % 1800000)) { |
|
333 |
tlPaper.path("M0 "+posY+"L165 "+posY).attr({"stroke":"#ccc"}); |
|
334 |
tlPaper.text(165, posY, new Date(tweetData.timeline[i].start).toLocaleTimeString()).attr({ "text-anchor" : "start", "font-size": "12px" }); |
|
335 |
} |
|
336 |
var anz = { |
|
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
337 |
"default" :tweetData.timeline[i].tweets |
| 333 | 338 |
}; |
339 |
for (var j in tweetData.timeline[i].annotations) { |
|
|
335
5f83c21dee69
Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents:
334
diff
changeset
|
340 |
anz.default -= tweetData.timeline[i].annotations[j]; |
| 333 | 341 |
anz[j] = tweetData.timeline[i].annotations[j]; |
342 |
} |
|
343 |
var posX = 0; |
|
344 |
for (var j in anz) { |
|
345 |
var largX = scaleX * anz[j]; |
|
| 340 | 346 |
if (largX > 0) { |
347 |
tlPaper.rect(posX, 600 - scaleY * (i+1), largX, scaleY).attr({"stroke": "none", "fill": annotations[j].colors.timeline}); |
|
348 |
posX += largX; |
|
349 |
} |
|
| 333 | 350 |
} |
351 |
} |
|
352 |
|
|
353 |
drawTimeWindow(); |
|
354 |
} |
|
355 |
||
356 |
$(document).ready(function() { |
|
357 |
tlPaper = Raphael("timeline", 220, 600); |
|
358 |
twPaper = Raphael("timewindow", 220, 600); |
|
| 334 | 359 |
socket = io.connect('http://' + document.location.hostname ); |
| 333 | 360 |
socket.on('tweetSummary', function (data) { |
361 |
if (tweetData.tweetcount != data.tweetcount) { |
|
362 |
tweetData.tweetcount = data.tweetcount; |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
363 |
tweetData.tlLevelChanged = true; |
| 333 | 364 |
updateDisplay(); |
365 |
} |
|
366 |
}); |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
367 |
socket.on('tweetPosByDate', function (data) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
368 |
tweetData.position = data.tweetpos; |
| 340 | 369 |
tweetData.feedMode = true; |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
370 |
tweetData.followLast = (tweetData.position == tweetData.tweetcount); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
371 |
updateDisplay(); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
372 |
}); |
| 333 | 373 |
socket.on('tweets', function (data) { |
374 |
for (var i in data) { |
|
| 340 | 375 |
addTweet(data[i]); |
| 333 | 376 |
} |
377 |
drawTweetList(); |
|
378 |
}); |
|
379 |
socket.on('timeline', function (data) { |
|
380 |
tweetData.tlChanged = false; |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
381 |
if (data.full) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
382 |
tweetData.timeline = data.data; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
383 |
} else { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
384 |
if (tweetData.timeline[tweetData.timeline.length - 1].start == data.data[0].start) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
385 |
tweetData.timeline[tweetData.timeline.length - 1] = data.data[0]; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
386 |
} else { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
387 |
tweetData.timeline.push(data.data[0]); |
| 333 | 388 |
} |
389 |
} |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
390 |
while (tweetData.length > 50) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
391 |
tweetData.splice(0,1); |
| 333 | 392 |
} |
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
393 |
drawTimeLine(); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
394 |
}); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
395 |
socket.on('linkedTweets', function(data) { |
| 340 | 396 |
tweetData.followLast = false; |
397 |
tweetData.feedMode = false; |
|
398 |
tweetData.position = data.tweetpos; |
|
399 |
tweetData.linkedTweets = data; |
|
400 |
updateDisplay(); |
|
| 333 | 401 |
}); |
402 |
$("#tweetlist").mousewheel(function(e, d) { |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
403 |
tweetData.wheelDelta += d; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
404 |
if (Math.abs(tweetData.wheelDelta) >= 1) { |
| 340 | 405 |
if (tweetData.feedMode) { |
406 |
tweetData.position = Math.min( tweetData.tweetcount, Math.max(1, parseInt(tweetData.wheelDelta) + tweetData.position ) ); |
|
407 |
tweetData.followLast = (tweetData.position == tweetData.tweetcount); |
|
408 |
updateDisplay(); |
|
409 |
} else { |
|
410 |
if (tweetData.wheelDelta > 0) { |
|
411 |
if (tweetData.linkedTweets.referenced_by.length) { |
|
412 |
tweetData.position = tweetData.linkedTweets.referenced_by[tweetData.linkedTweets.referenced_by.length - 1].pos; |
|
413 |
getLinkedTweets(); |
|
414 |
} |
|
415 |
} else { |
|
416 |
if (tweetData.linkedTweets.referencing.length) { |
|
417 |
tweetData.position = tweetData.linkedTweets.referencing[0].pos; |
|
418 |
getLinkedTweets(); |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
422 |
tweetData.wheelDelta = 0; |
| 333 | 423 |
} |
424 |
return false; |
|
425 |
}); |
|
426 |
$("#timewindow").mousewheel(function(e, d) { |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
427 |
tweetData.wheelDelta += d; |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
428 |
if (Math.abs(tweetData.wheelDelta) >= 1) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
429 |
if (tweetData.wheelDelta > 0) { |
| 333 | 430 |
setTimeZoom(tweetData.timeLevel + 1); |
431 |
} else { |
|
432 |
setTimeZoom(tweetData.timeLevel - 1); |
|
433 |
} |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
434 |
tweetData.wheelDelta = 0; |
| 333 | 435 |
} |
436 |
return false; |
|
437 |
}); |
|
|
339
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
438 |
$("#timewindow").click(function(evt) { |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
439 |
var offsetY = evt.pageY - $(this).offset().top, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
440 |
dtfintl = tweetData.timeline[ tweetData.timeline.length - 1 ].end, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
441 |
dtdebtl = tweetData.timeline[0].start, |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
442 |
clicTime = dtdebtl + (1 - ( offsetY / 600 ) ) * ( dtfintl - dtdebtl ); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
443 |
socket.emit('tweetPosByDate',{ date: clicTime }); |
|
6a073c4a8578
Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents:
336
diff
changeset
|
444 |
}); |
| 340 | 445 |
$("#modeselector").click(changeMode); |
| 333 | 446 |
}); |