stats.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. jsonStats.outerHTML = '';
  16. // Entry per day
  17. const avg = [];
  18. for (let i = -31; i <= 0; i++) {
  19. avg.push([i, stats.average]);
  20. }
  21. Flotr.draw(document.getElementById('statsEntryPerDay'),
  22. [{
  23. data: stats.dataCount,
  24. bars: {horizontal: false, show: true}
  25. },{
  26. data: avg,
  27. lines: {show: true},
  28. label: stats.average,
  29. }],
  30. {
  31. grid: {verticalLines: false},
  32. xaxis: {noTicks: 6, showLabels: false, tickDecimals: 0, min: -30.75, max: -0.25},
  33. yaxis: {min: 0},
  34. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
  35. });
  36. // Feed per category
  37. Flotr.draw(document.getElementById('statsFeedPerCategory'),
  38. stats.feedByCategory,
  39. {
  40. grid: {verticalLines: false, horizontalLines: false},
  41. pie: {explode: 10, show: true, labelFormatter: function(){return '';}},
  42. xaxis: {showLabels: false},
  43. yaxis: {showLabels: false},
  44. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ numberFormat(obj.y) + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}},
  45. legend: {container: document.getElementById('statsFeedPerCategoryLegend'), noColumns: 3}
  46. });
  47. // Entry per category
  48. Flotr.draw(document.getElementById('statsEntryPerCategory'),
  49. stats.entryByCategory,
  50. {
  51. grid: {verticalLines: false, horizontalLines: false},
  52. pie: {explode: 10, show: true, labelFormatter: function(){return '';}},
  53. xaxis: {showLabels: false},
  54. yaxis: {showLabels: false},
  55. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return obj.series.label + ' - '+ numberFormat(obj.y) + ' ('+ (obj.fraction * 100).toFixed(1) + '%)';}},
  56. legend: {container: document.getElementById('statsEntryPerCategoryLegend'), noColumns: 3}
  57. });
  58. }
  59. initStats();
  60. // @license-end