stats.js 2.1 KB

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