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