Created
August 25, 2011 18:04
-
-
Save austinbv/1171314 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function() { | |
| var build_chart, build_pie_chart, current, fade_duration, get_total; | |
| window.trends = {}; | |
| current = {}; | |
| fade_duration = 200; | |
| $(function() { | |
| return build_pie_chart("d"); | |
| }); | |
| build_chart = function(chart_type) {}; | |
| build_pie_chart = function(duration) { | |
| var chart, name, options, total, trend, vis; | |
| chart = new google.visualization.DataTable(); | |
| chart.addColumn("string", "Search Term"); | |
| chart.addColumn("number", "Popularity"); | |
| for (name in trends) { | |
| trend = trends[name]; | |
| total = get_total(trend, duration, function(total) { | |
| console.log(total) | |
| chart.addRows([[trend.title, total]]); | |
| }); | |
| } | |
| options = { | |
| "title": "Number of mentions of key religious terms in the past " + duration, | |
| "height": 500, | |
| "width": 300 | |
| }; | |
| vis = new google.visualization.PieChart($("#chart").get(0)); | |
| return vis.draw(chart, options); | |
| }; | |
| function get_total(trend, duration, callback) { | |
| var deferrds = [], total = 0; | |
| for(var i = 0, l = trend.search_terms; i < l; i++) { | |
| deferrds.push($.get("http://otter.topsy.com/search.json?q=" + trend.search_terms[i] + "&window=" + duration, function(data) { | |
| total += data.response.total; | |
| })); | |
| } | |
| $.when.apply($, deferrds).then(function() { | |
| callback(total); | |
| }); | |
| } | |
| }).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment