measurement_chart.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <script type="module">
  2. // Get raw data
  3. const rawData = [
  4. {% for sample in measurement.samples %}
  5. [{{ sample.commit_num }}, {{ sample.mean.gv_value() }}, {{ sample.start_time }}, '{{sample.commit}}'],
  6. {% endfor %}
  7. ];
  8. const convertToMinute = (time) => {
  9. return time[0]*60 + time[1] + time[2]/60 + time[3]/3600;
  10. }
  11. // Update value format to either minutes or leave as size value
  12. const updateValue = (value) => {
  13. // Assuming the array values are duration in the format [hours, minutes, seconds, milliseconds]
  14. return Array.isArray(value) ? convertToMinute(value) : value
  15. }
  16. // Convert raw data to the format: [time, value]
  17. const data = rawData.map(([commit, value, time]) => {
  18. return [
  19. // The Date object takes values in milliseconds rather than seconds. So to use a Unix timestamp we have to multiply it by 1000.
  20. new Date(time * 1000).getTime(),
  21. // Assuming the array values are duration in the format [hours, minutes, seconds, milliseconds]
  22. updateValue(value)
  23. ]
  24. });
  25. const commitCountList = rawData.map(([commit, value, time]) => {
  26. return commit
  27. });
  28. const commitCountData = rawData.map(([commit, value, time]) => {
  29. return updateValue(value)
  30. });
  31. // Set chart options
  32. const option_start_time = {
  33. tooltip: {
  34. trigger: 'axis',
  35. enterable: true,
  36. position: function (point, params, dom, rect, size) {
  37. return [point[0], '0%'];
  38. },
  39. formatter: function (param) {
  40. const value = param[0].value[1]
  41. const sample = rawData.filter(([commit, dataValue]) => updateValue(dataValue) === value)
  42. const formattedDate = new Date(sample[0][2] * 1000).toString().replace(/GMT[+-]\d{4}/, '').replace(/\(.*\)/, '(CEST)');
  43. // Add commit hash to the tooltip as a link
  44. const commitLink = `https://git.yoctoproject.org/poky/commit/?id=${sample[0][3]}`
  45. if ('{{ measurement.value_type.quantity }}' == 'time') {
  46. const hours = Math.floor(value/60)
  47. const minutes = Math.floor(value % 60)
  48. const seconds = Math.floor((value * 60) % 60)
  49. return `<strong>Duration:</strong> ${hours}:${minutes}:${seconds}, <strong>Commit number:</strong> <a href="${commitLink}" target="_blank" rel="noreferrer noopener">${sample[0][0]}</a>, <br/> <strong>Start time:</strong> ${formattedDate}`
  50. }
  51. return `<strong>Size:</strong> ${value.toFixed(2)} MB, <strong>Commit number:</strong> <a href="${commitLink}" target="_blank" rel="noreferrer noopener">${sample[0][0]}</a>, <br/> <strong>Start time:</strong> ${formattedDate}`
  52. ;}
  53. },
  54. xAxis: {
  55. type: 'time',
  56. },
  57. yAxis: {
  58. name: '{{ measurement.value_type.quantity }}' == 'time' ? 'Duration in minutes' : 'Disk size in MB',
  59. type: 'value',
  60. min: function(value) {
  61. return Math.round(value.min - 0.5);
  62. },
  63. max: function(value) {
  64. return Math.round(value.max + 0.5);
  65. }
  66. },
  67. dataZoom: [
  68. {
  69. type: 'slider',
  70. xAxisIndex: 0,
  71. filterMode: 'none'
  72. },
  73. ],
  74. series: [
  75. {
  76. name: '{{ measurement.value_type.quantity }}',
  77. type: 'line',
  78. symbol: 'none',
  79. data: data
  80. }
  81. ]
  82. };
  83. const option_commit_count = {
  84. tooltip: {
  85. trigger: 'axis',
  86. enterable: true,
  87. position: function (point, params, dom, rect, size) {
  88. return [point[0], '0%'];
  89. },
  90. formatter: function (param) {
  91. const value = param[0].value
  92. const sample = rawData.filter(([commit, dataValue]) => updateValue(dataValue) === value)
  93. const formattedDate = new Date(sample[0][2] * 1000).toString().replace(/GMT[+-]\d{4}/, '').replace(/\(.*\)/, '(CEST)');
  94. // Add commit hash to the tooltip as a link
  95. const commitLink = `https://git.yoctoproject.org/poky/commit/?id=${sample[0][3]}`
  96. if ('{{ measurement.value_type.quantity }}' == 'time') {
  97. const hours = Math.floor(value/60)
  98. const minutes = Math.floor(value % 60)
  99. const seconds = Math.floor((value * 60) % 60)
  100. return `<strong>Duration:</strong> ${hours}:${minutes}:${seconds}, <strong>Commit number:</strong> <a href="${commitLink}" target="_blank" rel="noreferrer noopener">${sample[0][0]}</a>, <br/> <strong>Start time:</strong> ${formattedDate}`
  101. }
  102. return `<strong>Size:</strong> ${value.toFixed(2)} MB, <strong>Commit number:</strong> <a href="${commitLink}" target="_blank" rel="noreferrer noopener">${sample[0][0]}</a>, <br/> <strong>Start time:</strong> ${formattedDate}`
  103. ;}
  104. },
  105. xAxis: {
  106. name: 'Commit count',
  107. type: 'category',
  108. data: commitCountList
  109. },
  110. yAxis: {
  111. name: '{{ measurement.value_type.quantity }}' == 'time' ? 'Duration in minutes' : 'Disk size in MB',
  112. type: 'value',
  113. min: function(value) {
  114. return Math.round(value.min - 0.5);
  115. },
  116. max: function(value) {
  117. return Math.round(value.max + 0.5);
  118. }
  119. },
  120. dataZoom: [
  121. {
  122. type: 'slider',
  123. xAxisIndex: 0,
  124. filterMode: 'none'
  125. },
  126. ],
  127. series: [
  128. {
  129. name: '{{ measurement.value_type.quantity }}',
  130. type: 'line',
  131. symbol: 'none',
  132. data: commitCountData
  133. }
  134. ]
  135. };
  136. // Draw chart
  137. const draw_chart = (chart_id, option) => {
  138. let chart_name
  139. const chart_div = document.getElementById(chart_id);
  140. // Set dark mode
  141. if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
  142. chart_name= echarts.init(chart_div, 'dark', {
  143. height: 320
  144. });
  145. } else {
  146. chart_name= echarts.init(chart_div, null, {
  147. height: 320
  148. });
  149. }
  150. // Change chart size with browser resize
  151. window.addEventListener('resize', function() {
  152. chart_name.resize();
  153. });
  154. return chart_name.setOption(option);
  155. }
  156. draw_chart('{{ chart_elem_start_time_id }}', option_start_time)
  157. draw_chart('{{ chart_elem_commit_count_id }}', option_commit_count)
  158. </script>