diff -r 04bccad7fe53 -r 886bfa7441d0 tweetcast/nodejs-bis/client/js/script.js --- a/tweetcast/nodejs-bis/client/js/script.js Mon Nov 21 11:46:37 2011 +0100 +++ b/tweetcast/nodejs-bis/client/js/script.js Tue Nov 22 13:25:43 2011 +0100 @@ -27,13 +27,15 @@ tlBuffer = '', relHover = [], wheelDelta = 0, + scrollEnabled = false, + scrollExtent = 8000 - 452, + lastScrollPos = 0, rx_url = /https?:\/\/[0-9a-zA-Z\.%\/-_]+/g, rx_word = /[^ \.&;,'"!\?\d\(\)\+\[\]\\\…\-«»:\/]{3,}/g, stop_list = [ 'and', 'avec', 'aux', 'car', 'comme', 'dans', 'donc', 'des', 'elle', 'est', 'être', 'eux', 'ils', 'les', 'leur', 'leurs', 'mes', 'mon', 'tes', 'ton', 'notre', 'nos', 'nous', 'ont', 'pas', 'que', 'qui', 'sont', 'the', 'une', 'votre', 'vos', 'vous' ]; function getColor(annotation, lum) { -// console.log(annotations[annotation].h, annotations[annotation].s, lum, Raphael.hsl(annotations[annotation].h, annotations[annotation].s, lum)) - return Raphael.hsl(annotations[annotation].colors.h, annotations[annotation].colors.s, lum); + return Raphael.hsl2rgb(annotations[annotation].colors.h, annotations[annotation].colors.s, lum); } function arc(source, target) { @@ -260,7 +262,7 @@ if (tweet.annotations.length) { html += '
'; for (var i in tweet.annotations) { - html += '
'; + html += '
'; } html += '
'; } @@ -436,6 +438,7 @@ } function updateDisplay() { + var p = twCx.position, l = twCx.tweets.length, lines = 0, @@ -444,18 +447,8 @@ tweetsOnDisplay = [], localWords = {}; - if (p == 0) { - $("#downbutton").addClass("inactive"); - } else { - $("#downbutton").removeClass("inactive"); - } - - if (p == l-1) { - $("#upbutton").addClass("inactive"); - } else { - $("#upbutton").removeClass("inactive"); - } - + lastScrollPos = Math.floor( scrollExtent * ( 1 - ( p / twCx.tweets.length ) ) ); + $("#scrollcont").scrollTop(lastScrollPos); function pushTweet(tp, className) { if (tp < l && tp >= 0) { @@ -557,8 +550,13 @@ maxann = tab[j].annotations[k]; } } - var coul = (ann == "default" ? '' : ' background: ' + getColor(ann, 1 - .4 * ( tab[j].annotations[ann] / tab[j].freq ) ) + ';"'), - fontsize = Math.floor( ( 12 + Math.sqrt( tab[j].score - minfreq ) * echfreq ) ); + if (ann == "default") { + var coul = ''; + } else { + var c = getColor(ann, .4), + coul = "background: rgba(" + [ Math.floor(c.r), Math.floor(c.g), Math.floor(c.b), ( tab[j].annotations[ann] / tab[j].freq )].join(',') + ")"; + } + var fontsize = Math.floor( ( 12 + Math.sqrt( tab[j].score - minfreq ) * echfreq ) ); html += '' + tab[j].word + ' '; } $("#motscles").html(html); @@ -630,7 +628,7 @@ var l = twCx.tlOnDisplay[i].displayData[j].length; if (l > 0) { tlPaper.rect( twCx.deltaX + n * twCx.scaleX, posY, l * twCx.scaleX, twCx.scaleY ) - .attr({"stroke" : "none", "fill" : getColor(j, .4) }); + .attr({"stroke" : "none", "fill" : getColor(j, .4).hex }); n += l; } } @@ -770,9 +768,13 @@ twCx.tlMouseClicked = false; twCx.tlMouseMoved = false; }); - $("#scrollcont").scroll(function(evt) { - var p = Math.floor( twCx.tweets.length * ( 1 - $(this).scrollTop() / 9548 ) ); - goToPos(p); - }) + setInterval(function() { + var sc = $("#scrollcont"); + if (sc.scrollTop() != lastScrollPos) { + var p = Math.floor( twCx.tweets.length * ( 1 - sc.scrollTop() / scrollExtent ) ); + goToPos(p); + } + + }, 100) });