diff options
| author | Scott Ostler <sostler@deathmachine.local> | 2010-02-23 10:00:55 -0500 |
|---|---|---|
| committer | Scott Ostler <sostler@deathmachine.local> | 2010-02-23 10:00:55 -0500 |
| commit | af3d49a9c3092f600e62a66cc78a462ef9a70e7e (patch) | |
| tree | 6f6e2f7576eea87c7d45fa4d8a63a835c253ac22 /static/js/stats.js | |
| parent | 8a981f390c286cb9c5935290e7846df903148278 (diff) | |
| parent | 2b6c2cef9a3398dbafb1f6cfbc0323c0b83e2053 (diff) | |
Merge
Diffstat (limited to 'static/js/stats.js')
| -rwxr-xr-x | static/js/stats.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/static/js/stats.js b/static/js/stats.js new file mode 100755 index 0000000..00e00a0 --- /dev/null +++ b/static/js/stats.js @@ -0,0 +1,79 @@ +var CurrentStats = ['msgs', 'today']; + +function refreshStats() { + $('a.statname, a.timescale').addClass('disabled'); + $('#statschart').empty().append('<img src="/static/spinner.gif">'); + + var onSuccess = function(json) { + var dataString = "Date,Count\n"; + $.each(json, function(i, v) { + dataString += v.created_on + "," + v.count + "\n"; + }); + $('#statschart').empty(); + new Dygraph($('#statschart')[0], + dataString, + { showRoller: false} + ); + + $('a.statname, a.timescale').removeClass('disabled'); + }; + + var onError = function(resp, textStatus, errorThrown) { + $('a.statname, a.timescale').removeClass('disabled'); + }; + + $.ajax({ + type: 'GET', + timeout: 5000, + url: '/stats', + data: { 'stat': CurrentStats[0], 'ts': CurrentStats[1] }, + cache: false, + dataType: 'json', + success: onSuccess, + error: onError + }); +} + +function makeStatsWindow() { + var statBox= $('<div class="stats" align="center">'); + var choices = ['msgs', 'new users']; + $(choices).map(function(i, c) { + return link = $('<a>') + .text(c) + .attr('href', '#') + .addClass('statname') + .addClass(i == 0 ? 'active' : 'inactive') + .click(function() { + if ($(this).hasClass('disabled') || + CurrentStats[0] == c) { return }; + $('.statname').removeClass('active'); + $(this).addClass('active'); + CurrentStats[0] = c; + refreshStats(); + }); + }).appendTo(statBox); + $('<div id="statschart" style="width:375px; height:300px;">').appendTo(statBox); + var timescales = ['today', 'all time']; + $(timescales).map(function(i, c) { + return link = $('<a>') + .text(c) + .attr('href', '#') + .addClass('timescale') + .addClass(i == 0 ? 'active' : 'inactive') + .click(function() { + if ($(this).hasClass('disabled') || + CurrentStats[1] == c) { return }; + $('.timescale').removeClass('active'); + $(this).addClass('active'); + CurrentStats[1] = c; + refreshStats(); + }); + })//.appendTo(statBox); + return statBox; +} + +function initStats() { + makeStatsWindow().appendTo('body'); + refreshStats(); +} + |
