repartition.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 jsonRepartition = document.getElementById('jsonRepartition'),
  13. stats = JSON.parse(jsonRepartition.innerHTML);
  14. jsonRepartition.outerHTML = '';
  15. // Entry per hour
  16. Flotr.draw(document.getElementById('statsEntryPerHour'),
  17. [{
  18. data: stats.repartitionHour,
  19. bars: {horizontal: false, show: true}
  20. }],
  21. {
  22. grid: {verticalLines: false},
  23. xaxis: {noTicks: 23,
  24. tickFormatter: function(x1) {
  25. return 1 + parseInt(x1);
  26. },
  27. min: -0.9,
  28. max: 23.9,
  29. tickDecimals: 0},
  30. yaxis: {min: 0},
  31. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
  32. });
  33. // Entry per day of week
  34. Flotr.draw(document.getElementById('statsEntryPerDayOfWeek'),
  35. [{
  36. data: stats.repartitionDayOfWeek,
  37. bars: {horizontal: false, show: true}
  38. }],
  39. {
  40. grid: {verticalLines: false},
  41. xaxis: {noTicks: 6,
  42. tickFormatter: function(x2) {
  43. return stats.days[parseInt(x2)];
  44. },
  45. min: -0.9,
  46. max: 6.9,
  47. tickDecimals: 0},
  48. yaxis: {min: 0},
  49. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
  50. });
  51. // Entry per month
  52. Flotr.draw(document.getElementById('statsEntryPerMonth'),
  53. [{
  54. data: stats.repartitionMonth,
  55. bars: {horizontal: false, show: true}
  56. }],
  57. {
  58. grid: {verticalLines: false},
  59. xaxis: {noTicks: 12,
  60. tickFormatter: function(x3) {
  61. return stats.months[parseInt(x3) - 1];
  62. },
  63. min: 0.1,
  64. max: 12.9,
  65. tickDecimals: 0},
  66. yaxis: {min: 0},
  67. mouse: {relative: true, track: true, trackDecimals: 0, trackFormatter: function(obj) {return numberFormat(obj.y);}}
  68. });
  69. }
  70. initStats();