tweetcast/nodejs/client/js/script.js
author Raphael Velt <raph.velt@gmail.com>
Thu, 27 Oct 2011 17:57:53 +0200
changeset 339 6a073c4a8578
parent 336 d60efd677b50
child 340 a99a04556e3b
permissions -rw-r--r--
Minor changes and bug fixes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     1
var socket,
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     2
    tlPaper,
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     3
    twPaper,
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     4
    tweetData = {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     5
        "tweetcount" : 0,
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     6
        "position" : 0,
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
     7
        "feedMode" : true,
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     8
        "followLast" : true,
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     9
        "zoomLevel" : 3,
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    10
        "timeLevel" : 2,
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    11
        "tweets" : [],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    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
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    19
    },
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    20
    displaySplitting = [
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    21
        {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    22
            positions : [ 10, 20, 22, 24, 25, 26, 27, 28, 29, 31, 33, 43, 53 ],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    23
            classNames : [ 'icons fade', 'icons', 'quarter fade', 'quarter', 'half fade', 'half', 'full', 'half', 'half fade', 'quarter', 'quarter fade', 'icons', 'icons fade' ]
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    24
        },
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    25
        {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    26
            positions : [ 1, 3, 5, 7, 13, 33, 53 ],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    27
            classNames : [ 'full', 'half', 'half fade', 'quarter', 'quarter fade', 'icons', 'icons fade' ]
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    28
        }
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    29
    ];
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    30
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    31
function placeHolder(className) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    32
    return '<li class="placeholder ' + className + '"></li>';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    33
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    34
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    35
function clicTweet(tweetPos) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    36
    if (tweetPos != tweetData.position) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    37
        tweetData.position = tweetPos;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    38
        tweetData.followLast = (tweetData.position == tweetData.tweetcount);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    39
        return false;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    40
    } else {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    41
        console.log("getting linkedTweets");
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    42
        socket.emit('linkedTweets',{"tweetpos":tweetPos});
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    43
    }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    44
}
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    45
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    46
function tweetToHtml(tweet, className) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    47
    if (!tweet) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    48
        return placeHolder(className);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    49
    }
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
    50
	html = '<li class="tweet ' + className + '" id="tweet_' + tweet.pos + '" onclick="return clicTweet(' + tweet.pos + ')"';
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    51
	if (tweetData.followLast && tweet.pos == tweetData.position) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    52
	    html += ' style="display: none"';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    53
	}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    54
	html += '>';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    55
	if (tweet.annotations.length) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    56
	    html += '<div class="annotations">';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    57
	    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
    58
    		html += '<div class="annotation" style="width:' + (100/tweet.annotations.length) + '%; background:' + annotations[tweet.annotations[i]].colors.tweet + '"></div>';
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    59
    	}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    60
    	html += '</div>';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    61
	}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    62
	html += '<div class="twmain">';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    63
	a_user = '<a href="http://twitter.com/' + tweet.user.screen_name + '" target="_blank" title="' + tweet.user.name + '">';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    64
	if (tweet.user.profile_image_url) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    65
		html += a_user + '<img class="profile_image" src="' + tweet.user.profile_image_url + '" /></a>';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    66
	}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    67
	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">';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    68
	lastend = 0;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    69
	txt = '';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    70
	entities = [];
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    71
	for (var i in tweet.entities.hashtags) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    72
	    entities.push({
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    73
	        "start" : tweet.entities.hashtags[i].indices[0],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    74
	        "end" : tweet.entities.hashtags[i].indices[1],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    75
	        "html" : '<a href="http://twitter.com/search?q=%23' + tweet.entities.hashtags[i].text + '" target="_blank">#' + tweet.entities.hashtags[i].text + '</a>'
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    76
	    });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    77
	}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    78
	for (var i in tweet.entities.urls) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    79
	    entities.push({
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    80
	        "start" : tweet.entities.urls[i].indices[0],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    81
	        "end" : tweet.entities.urls[i].indices[1],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    82
	        "html" : '<a href="' + tweet.entities.urls[i].expanded_url + '" target="_blank">' + tweet.entities.urls[i].display_url + '</a>'
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    83
	    });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    84
	}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    85
	for (var i in tweet.entities.user_mentions) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    86
	    entities.push({
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    87
	        "start" : tweet.entities.user_mentions[i].indices[0],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    88
	        "end" : tweet.entities.user_mentions[i].indices[1],
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    89
	        "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>'
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    90
	    });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    91
	}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    92
 	entities.sort(function(a, b) { return a.start - b.start });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    93
    for (var i in entities) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    94
 		txt += tweet.text.substring(lastend, entities[i].start) + entities[i].html;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    95
        lastend = entities[i].end;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    96
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    97
	txt += tweet.text.substring(lastend);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    98
	html += txt + '</p></li></div>';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    99
	return html;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   100
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   101
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   102
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   103
function getUpdate() {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   104
    tweetData.posToDisplay = [];
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   105
    if (tweetData.followLast) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   106
        for (var i = tweetData.tweetcount; i >= tweetData.tweetcount - 52; i--) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   107
            tweetData.posToDisplay.push( i > 0 ? i : -1 );
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   108
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   109
        tweetData.end = tweetData.tweetcount;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   110
        tweetData.start = Math.max(1, tweetData.end - 52);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   111
    } else {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   112
        for (var i = tweetData.position + 26; i >= tweetData.position - 26; i--) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   113
            tweetData.posToDisplay.push( i > 0 && i <= tweetData.tweetcount ? i : -1 );
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   114
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   115
        tweetData.end = Math.min(tweetData.tweetcount, tweetData.position + 26 );
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   116
        tweetData.start = Math.max(1, tweetData.position - 26);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   117
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   118
    var tweetsToGet = [];
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   119
    for (var i = tweetData.start; i <= tweetData.end; i++) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   120
        if (!tweetByPos(i)) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   121
            tweetsToGet.push(i);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   122
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   123
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   124
    if (tweetsToGet.length) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   125
        socket.emit('updateTweets', {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   126
            "tweets" : tweetsToGet
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   127
        });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   128
    } else {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   129
        drawTweetList();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   130
        //drawDisplay();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   131
    }
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   132
    if (tweetData.tlChanged || tweetData.tlLevelChanged) {
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   133
        socket.emit('updateTimeline', {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   134
            "level" : tweetData.timeLevel,
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   135
            "full" : tweetData.tlLevelChanged
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   136
        });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   137
    } else {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   138
        drawTimeLine();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   139
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   140
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   141
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   142
function tweetByPos(pos) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   143
    var index = tweetData.posIndex.indexOf(pos);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   144
    return (index == -1 ? false : tweetData.tweets[index]);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   145
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   146
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   147
function delayedUpdate() {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   148
    tweetData.blockUpdate = false;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   149
    if (tweetData.waitUpdate) {
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   150
        updateDisplay();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   151
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   152
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   153
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   154
function updateDisplay() {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   155
    if (tweetData.blockUpdate) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   156
        tweetData.waitUpdate = true;
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   157
    } else {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   158
        tweetData.waitUpdate = false;
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   159
        getUpdate();
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   160
        tweetData.blockUpdate = true;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   161
        setTimeout(delayedUpdate, 300);
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   162
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   163
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   164
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   165
function setTimeZoom(level) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   166
    if (level >= 0 && level <= 4) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   167
        tweetData.timeLevel = level;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   168
        tweetData.tlChanged = true;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   169
        updateDisplay();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   170
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   171
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   172
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   173
function drawTweetList() {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   174
    html = '';
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   175
    var i = 0;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   176
    while (i < tweetData.posIndex.length) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   177
        if (tweetData.posToDisplay.indexOf(tweetData.posIndex[i]) == -1) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   178
            tweetData.posIndex.splice(i,1);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   179
            tweetData.tweets.splice(i,1);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   180
        } else {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   181
            i++;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   182
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   183
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   184
    for (var i in tweetData.posToDisplay) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   185
        var ds = displaySplitting[tweetData.followLast ? 1 : 0];
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   186
        for (var j in ds.positions) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   187
            if (ds.positions[j] > i) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   188
                var className = ds.classNames[j];
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   189
                break;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   190
            }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   191
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   192
        html += ( tweetData.posToDisplay[i] != -1 ? tweetToHtml(tweetByPos(tweetData.posToDisplay[i]), className) : placeHolder(className) );
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   193
    }
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   194
    if (tweetData.htmlBuffer != html) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   195
        $("#tweetlist").html(html);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   196
        tweetData.htmlBuffer = html;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   197
    }
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   198
    if (tweetData.followLast) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   199
        $("#tweet_" + tweetData.position).fadeIn(500);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   200
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   201
    drawTimeWindow();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   202
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   203
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   204
function drawTimeWindow() {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   205
    twPaper.clear();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   206
    if (!tweetData.timeline || !tweetData.timeline.length) return;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   207
    
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   208
    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
   209
        dtdebtl = tweetData.timeline[0].start,
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   210
        dtfintw = new Date( tweetByPos( tweetData.end ).created_at ),
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   211
        dtdebtw = new Date( tweetByPos( tweetData.start ).created_at ),
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   212
        scY = 600 / ( dtfintl - dtdebtl );
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   213
    twPaper.rect( 0, scY * ( dtfintl - dtfintw ), 300, scY * ( dtfintw - dtdebtw )).attr({"stroke":"none","fill":"#8080ff","fill-opacity":.2});
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   214
    var dtcour = new Date( tweetByPos( tweetData.position ).created_at ),
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   215
        posY = scY * ( dtfintl - dtcour ); 
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   216
    twPaper.path("M0 "+posY+"L300 "+posY).attr({"stroke":"#ff0"});
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   217
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   218
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   219
function drawTimeLine() {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   220
    tlPaper.clear();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   221
    if (!tweetData.timeline || !tweetData.timeline.length) return;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   222
    tweetData.tlTweetRects = [];
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   223
    var scaleY = 600 / tweetData.timeline.length,
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   224
        max = 0;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   225
    for (var i = 0; i < tweetData.timeline.length; i++) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   226
        max = Math.max(max, tweetData.timeline[i].tweets);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   227
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   228
    var scaleX = 160 / max;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   229
    
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   230
    // dessin de l'axe vertical
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   231
    
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   232
    tlPaper.path("M160 0L160 600").attr({"stroke":"#ccc"});
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   233
    
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   234
    // dessin de la date de début
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   235
    
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   236
    tlPaper.text(165, 592, new Date(tweetData.timeline[0].start).toLocaleTimeString()).attr({ "text-anchor" : "start", "font-size": "12px" });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   237
    
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   238
    // dessin de la date de fin
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   239
    
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   240
    tlPaper.text(165, 7, new Date(tweetData.timeline[tweetData.timeline.length - 1].end).toLocaleTimeString()).attr({ "text-anchor" : "start", "font-size": "12px" });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   241
    for (var i = 0; i < tweetData.timeline.length; i++) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   242
        var posY = 600 - (i * scaleY);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   243
        
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   244
        // Si on est à une demi-heure, on trace un axe secondaire + heure
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   245
        
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   246
        if (i && !(new Date(tweetData.timeline[i].start).valueOf() % 1800000)) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   247
            tlPaper.path("M0 "+posY+"L165 "+posY).attr({"stroke":"#ccc"});
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   248
            tlPaper.text(165, posY, new Date(tweetData.timeline[i].start).toLocaleTimeString()).attr({ "text-anchor" : "start", "font-size": "12px" });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   249
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   250
        var anz = {
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   251
            "default" :tweetData.timeline[i].tweets
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   252
        };
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   253
        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
   254
            anz.default -= tweetData.timeline[i].annotations[j];
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   255
            anz[j] = tweetData.timeline[i].annotations[j];
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   256
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   257
        var posX = 0;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   258
        for (var j in anz) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   259
            var largX = scaleX * anz[j];
335
5f83c21dee69 Created conf.js file, shared between server & client
Raphael Velt <raph.velt@gmail.com>
parents: 334
diff changeset
   260
            tlPaper.rect(posX, 600 - scaleY * (i+1), largX, scaleY).attr({"stroke": "none", "fill": annotations[j].colors.timeline});
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   261
            posX += largX;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   262
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   263
    }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   264
    
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   265
    drawTimeWindow();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   266
/*    for (var i = 0; i < tweetData.arcs.length; i++) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   267
        var x1 = scaleX * (tmptw[tweetData.arcs[i].from].x + .5),
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   268
            x2 = scaleX * (tmptw[tweetData.arcs[i].to].x + .5),
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   269
            y1 = 600 - scaleY * (tmptw[tweetData.arcs[i].from].y + .5),
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   270
            y2 = 600 - scaleY * (tmptw[tweetData.arcs[i].to].y + .5),
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   271
            d = "M"+x1+" "+y1+"C";
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   272
        if (y1 == y2) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   273
            d += x1+" "+(y1 - 30)+" "+x2+" "+(y2 - 30);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   274
        } else {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   275
            d += (x1 + 60)+" "+y1+" "+(x2 + 60)+" "+y2;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   276
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   277
        paper.path(d+" "+x2+" "+y2);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   278
    } */
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   279
}
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   280
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   281
$(document).ready(function() {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   282
    tlPaper = Raphael("timeline", 220, 600);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   283
    twPaper = Raphael("timewindow", 220, 600);
334
b7f05d66b620 Minor changes
Raphael Velt <raph.velt@gmail.com>
parents: 333
diff changeset
   284
    socket = io.connect('http://' + document.location.hostname );
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   285
    socket.on('tweetSummary', function (data) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   286
        if (tweetData.tweetcount != data.tweetcount) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   287
            tweetData.tweetcount = data.tweetcount;
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   288
            tweetData.tlLevelChanged = true;
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   289
            if (tweetData.followLast) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   290
                tweetData.position = data.tweetcount;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   291
            }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   292
            updateDisplay();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   293
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   294
    });
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   295
    socket.on('tweetPosByDate', function (data) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   296
        tweetData.position = data.tweetpos;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   297
        tweetData.followLast = (tweetData.position == tweetData.tweetcount);
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   298
        updateDisplay();
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   299
    });
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   300
    socket.on('tweets', function (data) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   301
        for (var i in data) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   302
            if (tweetData.posIndex.indexOf(data[i].pos) == -1) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   303
                tweetData.tweets.push(data[i]);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   304
                tweetData.posIndex.push(data[i].pos);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   305
            }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   306
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   307
        drawTweetList();
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   308
    });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   309
    socket.on('timeline', function (data) {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   310
        tweetData.tlChanged = false;
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   311
        if (data.full) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   312
            tweetData.timeline = data.data;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   313
        } else {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   314
            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
   315
                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
   316
            } else {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   317
                tweetData.timeline.push(data.data[0]);
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   318
            }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   319
        }
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   320
        while (tweetData.length > 50) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   321
            tweetData.splice(0,1);
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   322
        }
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   323
        drawTimeLine();
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   324
    });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   325
    socket.on('linkedTweets', function(data) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   326
        console.log(data);
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   327
    });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   328
    $("#tweetlist").mousewheel(function(e, d) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   329
        tweetData.wheelDelta += d;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   330
        if (Math.abs(tweetData.wheelDelta) >= 1) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   331
            tweetData.position = Math.min( tweetData.tweetcount, Math.max(1, parseInt(tweetData.wheelDelta) + tweetData.position ) );
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   332
            tweetData.followLast = (tweetData.position == tweetData.tweetcount);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   333
            updateDisplay();
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   334
            tweetData.wheelDelta = 0;
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   335
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   336
        return false;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   337
    });
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   338
    $("#timewindow").mousewheel(function(e, d) {
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   339
        tweetData.wheelDelta += d;
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   340
        if (Math.abs(tweetData.wheelDelta) >= 1) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   341
            if (tweetData.wheelDelta > 0) {
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   342
                setTimeZoom(tweetData.timeLevel + 1);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   343
            } else {
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   344
                setTimeZoom(tweetData.timeLevel - 1);
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   345
            }
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   346
            tweetData.wheelDelta = 0;
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   347
        }
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   348
        return false;
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   349
    });
339
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   350
    $("#timewindow").click(function(evt) {
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   351
        var offsetY = evt.pageY - $(this).offset().top,
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   352
            dtfintl = tweetData.timeline[ tweetData.timeline.length - 1 ].end,
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   353
            dtdebtl = tweetData.timeline[0].start,
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   354
            clicTime = dtdebtl + (1 - ( offsetY / 600 ) ) * ( dtfintl - dtdebtl );
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   355
        socket.emit('tweetPosByDate',{ date: clicTime });
6a073c4a8578 Minor changes and bug fixes
Raphael Velt <raph.velt@gmail.com>
parents: 336
diff changeset
   356
    });
333
4389fd4ae58f Reorganisation branche node
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
   357
});