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