Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 12th, 2012  |  syntax: None  |  size: 1.36 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (function() {
  2.   var build_chart, build_pie_chart, current, fade_duration, get_total;
  3.   window.trends = {};
  4.   current = {};
  5.   fade_duration = 200;
  6.   $(function() {
  7.     return build_pie_chart("d");
  8.   });
  9.   build_chart = function(chart_type) {};
  10.   build_pie_chart = function(duration) {
  11.     var chart, name, options, total, trend, vis;
  12.     chart = new google.visualization.DataTable();
  13.     chart.addColumn("string", "Search Term");
  14.     chart.addColumn("number", "Popularity");
  15.     for (name in trends) {
  16.       trend = trends[name];
  17.       total = get_total(trend, duration, function(total) {
  18.         console.log(total)
  19.         chart.addRows([[trend.title, total]]);
  20.       });
  21.     }
  22.     options = {
  23.       "title": "Number of mentions of key religious terms in the past " + duration,
  24.       "height": 500,
  25.       "width": 300
  26.     };
  27.     vis = new google.visualization.PieChart($("#chart").get(0));
  28.     return vis.draw(chart, options);
  29.   };
  30.   function get_total(trend, duration, callback) {
  31.       var deferrds = [], total = 0;
  32.  
  33.       for(var i = 0, l = trend.search_terms; i < l; i++) {
  34.           deferrds.push($.get("http://otter.topsy.com/search.json?q=" + trend.search_terms[i] + "&window=" + duration, function(data) {
  35.               total += data.response.total;
  36.           }));
  37.       }
  38.  
  39.       $.when.apply($, deferrds).then(function() {
  40.           callback(total);
  41.       });
  42.   }
  43. }).call(this);