stats.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. "use strict";
  2. function initStats() {
  3. if (!window.Flotr) {
  4. if (window.console) {
  5. console.log('FreshRSS waiting for Flotr…');
  6. }
  7. window.setTimeout(initStats, 50);
  8. return;
  9. }
  10. var jsonStats = document.getElementById('jsonStats'),
  11. stats = JSON.parse(jsonStats.innerHTML);
  12. jsonStats.outerHTML = '';
  13. // Entry per day
  14. var avg = [];
  15. for (var i = -31; i <= 0; i++) {
  16. avg.push([i, stats.average]);
  17. }
  18. Flotr.draw(document.getElementById('statsEntryPerDay'),
  19. [{
  20. data: stats.dataCount,
  21. bars: {horizontal: false, show: true}
  22. },{
  23. data: avg,
  24. lines: {show: true},
  25. label: stats.average,
  26. }],
  27. {
  28. grid: {verticalLines: false},
  29. xaxis: {noTicks: 6, showLabels: false, tickDecimals: 0, min: -30.75, max: -0.25},
  30. yaxis: {min: 0},
  31. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
  32. });
  33. // Feed per category
  34. Flotr.draw(document.getElementById('statsFeedPerCategory'),
  35. stats.feedByCategory,
  36. {
  37. grid: {verticalLines: false, horizontalLines: false},
  38. pie: {explode: 10, show: true, labelFormatter: function(){return '';}},
  39. xaxis: {showLabels: false},
  40. yaxis: {showLabels: false},
  41. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ numberFormat(obj.y) + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}},
  42. legend: {container: document.getElementById('statsFeedPerCategoryLegend'), noColumns: 3}
  43. });
  44. // Entry per category
  45. Flotr.draw(document.getElementById('statsEntryPerCategory'),
  46. stats.entryByCategory,
  47. {
  48. grid: {verticalLines: false, horizontalLines: false},
  49. pie: {explode: 10, show: true, labelFormatter: function(){return '';}},
  50. xaxis: {showLabels: false},
  51. yaxis: {showLabels: false},
  52. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ numberFormat(obj.y) + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}},
  53. legend: {container: document.getElementById('statsEntryPerCategoryLegend'), noColumns: 3}
  54. });
  55. }
  56. initStats();