You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.3 KiB

2 years ago
  1. 'use strict';
  2. window.chartColors = {
  3. red: 'rgb(210, 30, 43)',
  4. black: 'rgb(17, 17, 17)',
  5. orange: 'rgb(255, 159, 64)',
  6. yellow: 'rgb(255, 205, 86)',
  7. green: 'rgb(75, 192, 192)',
  8. blue: 'rgb(54, 162, 235)',
  9. purple: 'rgb(153, 102, 255)',
  10. grey: 'rgb(201, 203, 207)'
  11. };
  12. (function(global) {
  13. var Months = [
  14. 'January',
  15. 'February',
  16. 'March',
  17. 'April',
  18. 'May',
  19. 'June',
  20. 'July',
  21. 'August',
  22. 'September',
  23. 'October',
  24. 'November',
  25. 'December'
  26. ];
  27. var COLORS = [
  28. '#4dc9f6',
  29. '#f67019',
  30. '#f53794',
  31. '#537bc4',
  32. '#acc236',
  33. '#166a8f',
  34. '#00a950',
  35. '#58595b',
  36. '#8549ba'
  37. ];
  38. var Samples = global.Samples || (global.Samples = {});
  39. var Color = global.Color;
  40. Samples.utils = {
  41. // Adapted from http://indiegamr.com/generate-repeatable-random-numbers-in-js/
  42. srand: function(seed) {
  43. this._seed = seed;
  44. },
  45. rand: function(min, max) {
  46. var seed = this._seed;
  47. min = min === undefined ? 0 : min;
  48. max = max === undefined ? 1 : max;
  49. this._seed = (seed * 9301 + 49297) % 233280;
  50. return min + (this._seed / 233280) * (max - min);
  51. },
  52. numbers: function(config) {
  53. var cfg = config || {};
  54. var min = cfg.min || 0;
  55. var max = cfg.max || 1;
  56. var from = cfg.from || [];
  57. var count = cfg.count || 8;
  58. var decimals = cfg.decimals || 8;
  59. var continuity = cfg.continuity || 1;
  60. var dfactor = Math.pow(10, decimals) || 0;
  61. var data = [];
  62. var i, value;
  63. for (i = 0; i < count; ++i) {
  64. value = (from[i] || 0) + this.rand(min, max);
  65. if (this.rand() <= continuity) {
  66. data.push(Math.round(dfactor * value) / dfactor);
  67. } else {
  68. data.push(null);
  69. }
  70. }
  71. return data;
  72. },
  73. labels: function(config) {
  74. var cfg = config || {};
  75. var min = cfg.min || 0;
  76. var max = cfg.max || 100;
  77. var count = cfg.count || 8;
  78. var step = (max - min) / count;
  79. var decimals = cfg.decimals || 8;
  80. var dfactor = Math.pow(10, decimals) || 0;
  81. var prefix = cfg.prefix || '';
  82. var values = [];
  83. var i;
  84. for (i = min; i < max; i += step) {
  85. values.push(prefix + Math.round(dfactor * i) / dfactor);
  86. }
  87. return values;
  88. },
  89. months: function(config) {
  90. var cfg = config || {};
  91. var count = cfg.count || 12;
  92. var section = cfg.section;
  93. var values = [];
  94. var i, value;
  95. for (i = 0; i < count; ++i) {
  96. value = Months[Math.ceil(i) % 12];
  97. values.push(value.substring(0, section));
  98. }
  99. return values;
  100. },
  101. color: function(index) {
  102. return COLORS[index % COLORS.length];
  103. },
  104. transparentize: function(color, opacity) {
  105. var alpha = opacity === undefined ? 0.5 : 1 - opacity;
  106. return Color(color).alpha(alpha).rgbString();
  107. }
  108. };
  109. // DEPRECATED
  110. window.randomScalingFactor = function() {
  111. return Math.round(Samples.utils.rand(-100, 100));
  112. };
  113. // INITIALIZATION
  114. Samples.utils.srand(Date.now());
  115. // Google Analytics
  116. /* eslint-disable */
  117. if (document.location.hostname.match(/^(www\.)?chartjs\.org$/)) {
  118. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  119. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  120. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  121. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  122. ga('create', 'UA-28909194-3', 'auto');
  123. ga('send', 'pageview');
  124. }
  125. /* eslint-enable */
  126. }(this));