stats.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
  2. "use strict";
  3. /* globals Flotr, numberFormat */
  4. /* jshint esversion:6, strict:global */
  5. function initStats() {
  6. if (!window.Flotr) {
  7. if (window.console) {
  8. console.log('FreshRSS waiting for Flotr…');
  9. }
  10. window.setTimeout(initStats, 50);
  11. return;
  12. }
  13. const jsonStats = document.getElementById('jsonStats'),
  14. stats = JSON.parse(jsonStats.innerHTML);
  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) {
  44. return obj.series.label + ' - ' + numberFormat(obj.y) + ' (' + (obj.fraction * 100).toFixed(1) + '%)';
  45. }},
  46. legend: {container: document.getElementById('statsFeedPerCategoryLegend'), noColumns: 3}
  47. });
  48. // Entry per category
  49. Flotr.draw(document.getElementById('statsEntryPerCategory'),
  50. stats.entryByCategory,
  51. {
  52. grid: {verticalLines: false, horizontalLines: false},
  53. pie: {explode: 10, show: true, labelFormatter: function () { return ''; }},
  54. xaxis: {showLabels: false},
  55. yaxis: {showLabels: false},
  56. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function (obj) {
  57. return obj.series.label + ' - ' + numberFormat(obj.y) + ' (' + (obj.fraction * 100).toFixed(1) + '%)';
  58. }},
  59. legend: {container: document.getElementById('statsEntryPerCategoryLegend'), noColumns: 3}
  60. });
  61. }
  62. initStats();
  63. window.addEventListener('resize', initStats);
  64. // @license-end