Commits

ajish  committed 77e81e3

tie-ins

  • Participants
  • Parent commits cad7d39

Comments (0)

Files changed (3)

-<!DOCTYPE HTML>
 <html>
 	<head>
 		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 			$(document).ready(function() {
                     jQuery.getJSON("index.py?page=fetch_points", function(data){
                             fetched = data; 
-                            plotPoints( data.points ); 
+                            plotPoints( data ); 
                     });
                                     				
                     jQuery.getJSON("index.py?page=fetch_texts", function(textdata){
                             $("#texts_table").dataTable({
                                 "bProcessing": true,
+                                "bDestroy": true,
                                 "aaData": textdata,
                             });
 
 		</div>	
         <div id="text_content" class="dynacloud" style="visibility:hidden;">
         </div>
-        <div id="texts" style="position: absolute; top:425px; left:625px; width: 600px; height: 400px; margin: 20 auto; overflow-y:scroll">
+        <div id="texts" style="position: absolute; top:425px; left:625px; width: 800px; height: 400px; margin: 20 auto;">
                 <table id="texts_table">
                     <thead>
                         <tr>
         if maxy and y > maxy:
             continue
         points.append( [x,y] )
-        ids.append( r[idcol] )
-        texts.append( r[textcol] )
-    ret = {     "points" : points,
-                "ids"    : ids,
-                "texts"  : texts    }
-    return ret
-
+    return points
+
+def get_min_max( points ):
+    xmin = 50
+    ymin = 50
+    xmax = -50
+    ymax = -50
+    for p in points:
+        if p[0] < xmin:
+            xmin = p[0]
+        if p[0] > xmax:
+            xmax = p[0]
+        if p[1] < ymin:
+            ymin = p[1]
+        if p[1] > ymax:
+            ymax = p[1]
+    return ( xmin, xmax, ymin, ymax )
+
+def normalize_points( points, minx, maxx, miny, maxy ):
+    ''' normalize the points within a grid to be a maximum of 100 X 100
+        and size the points according to the density
+    '''
+    nsteps = 100.0
+    xstep = (maxx-minx)/nsteps
+    ystep = (maxy-miny)/nsteps
+    normed = {}
+    for p in points:
+        xn = (int(p[0]/xstep)) * xstep
+        yn = (int(p[1]/ystep)) * ystep
+        key = (xn,yn)
+        if not normed.has_key( key ):
+            normed[key]=1
+        else:
+            normed[key]+=1
+    out = []
+    for k,v in normed.items():
+        out.append( [k[0], k[1], float(v)*1000/float(len(points))] )
+    return out
+ 
 def fetch_texts( minx=None, maxx=None, miny=None, maxy=None ):
     ''' get the tweets within the specified range
         identified by tweet-id
     maxx = get_optional_var("maxx", form)
     miny = get_optional_var("miny", form)
     maxy = get_optional_var("maxy", form)
-    points = fetch_points( minx, maxx, miny, maxy )
+    points = fetch_points( float(minx), float(maxx), float(miny), float(maxy) )
+    if not minx:
+        ranges = get_min_max( points )
+    else:
+        ranges = (float(minx), float(maxx), float(miny), float(maxy)) 
+    points = normalize_points( points, ranges[0], ranges[1], ranges[2], ranges[3] )
     out = json.dumps(points, encoding='latin1')
     print "Content-type: application/json\n\n"
     print out    
     maxx = get_optional_var("maxx", form)
     miny = get_optional_var("miny", form)
     maxy = get_optional_var("maxy", form)
-    points = fetch_texts( minx, maxx, miny, maxy )
+    points = fetch_texts( float(minx), float(maxx), float(miny), float(maxy) )
     out = json.dumps(points, encoding='latin1')
     print "Content-type: application/json\n\n"
     print out    
     if mode not in allowed_modes:
         raise Exception("Mode must be one of: %s" % (",".join(allowed_modes)))
     if mode == "keyword":
-        counts = fetch_keyword_counts( minx, maxx, miny, maxy )
+        counts = fetch_keyword_counts( float(minx), float(maxx), float(miny), float(maxy) )
     out = json.dumps(counts, encoding='latin1')
     print "Content-type: application/json\n\n"
     print out    

File js/scatter.js

       chart: {
          renderTo: 'container', 
          defaultSeriesType: 'scatter',
-         zoomType: 'xy'
-         //events: {
-         //   selection: function(event){
-         //       updateTweets( event.xAxis, event.yAxis );
-         //   }
-        //}
+         zoomType: 'xy',
+         events: {
+            selection: updateClouds
+        }
       },
       title: {
          text: 'Tweet Sentiment Spectrum'
       plotOptions: {
          scatter: {
             marker: {
-               radius: 5,
                states: {
                   hover: {
                      enabled: false,
       },
       series: [{
          name: 'tweets',
-         color: 'rgba(223, 83, 83, .05)',
+         color: 'rgba(223, 83, 83, .1)',
       }]
 };
 
+
+function updateClouds( evt ){
+    xst = evt.xAxis[0].min;
+    xen = evt.xAxis[0].max;
+    yst = evt.yAxis[0].min;
+    yen = evt.yAxis[0].max;
+    $.ajax({    type: "GET",
+                url: "index.py?page=fetch_points&minx="+xst+"&maxx="+xen+"&miny="+yst+"&maxy="+yen,
+                success: function(data) {
+                     var pts = renderClouds( data );
+                     chart.xAxis[0].setExtremes();
+                     chart.series[0].setData( pts ); 
+                     // fix the reset zoom button
+                     $('.highcharts-toolbar').click(resetZoom);
+                },
+                error: function(req, text, error) {
+                    $("#err").html("Reload error!");
+                }
+            });
+    updateProxies( xst, xen, yst, yen );
+
+}
+
+function resetZoom(){
+    $.ajax({    type: "GET",
+                url: "index.py?page=fetch_points",
+                success: function(data) {
+                     chart.toolbar.remove('zoom');
+                     var pts = renderClouds( data );
+                     chart.xAxis[0].setExtremes();
+                     chart.series[0].setData( pts ); 
+                     // fix the reset zoom button
+                     $('.highcharts-toolbar').click(resetZoom);
+                },
+                error: function(req, text, error) {
+                    $("#err").html("Reload error!");
+                }
+            });
+}
+
+
+function renderClouds(points){
+
+    var markers = new Array();
+    for (var i=0; i < points.length; i++){
+        markers[i] = {  "x": points[i][0],
+                        "y": points[i][1],
+                        "marker": { "radius": points[i][2]*10 }
+                     };
+    }
+    return( markers );
+}
+        
+
 function plotPoints( points ){
-    options.series[0].data = points;
+    pts = renderClouds( points );
+    options.series[0].data = pts;
     chart = new Highcharts.Chart(options);
 }
+
+
+function updateProxies( xmin, xmax, ymin, ymax ){
+
+    var rangeArgs = "&minx="+xmin +"&maxx="+xmax +"&miny="+ymin +"&maxy="+ymax; 
+    alert(rangeArgs);
+    jQuery.getJSON("index.py?page=fetch_texts"+rangeArgs, function(textdata){
+            $("#texts_table").dataTable({
+                "bProcessing": true,
+                "bDestroy": true,
+                "aaData": textdata,
+            });
+
+    });  
+    jQuery.getJSON("index.py?page=fetch_counts&mode=keyword"+rangeArgs, function(countdata){
+    
+        //load up the list-items
+        var max_idx = 20;
+        if (countdata.length < max_idx){
+            max_idx = countdata.length;
+        }
+        var content = "<canvas id=tag_cloud name=tagcloud width=350 height=350 style=\"float: left; margin-bottom: 20px\"><ul>";
+        for( var i=0; i < max_idx; i++){
+            content = content + "<li><a href=# data-weight="+(Math.round(Math.log(countdata[i][1]))+1)+">"+countdata[i][0]+"</a></li>";
+        }
+        content = content + "</ul></canvas>";
+        $('#text_cloud').html( content );
+
+        $('#tag_cloud').tagcanvas({
+             outlineThickness : 1,
+             maxSpeed : 0.01,
+             depth : 0.75,
+             weightFrom: "data-weight",
+             weightMode: "both",
+             weightSize: 5,
+             weight: true
+           });                    
+    });  
+}