repartition.js 2.0 KB

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