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.

143 lines
3.0 KiB

  1. <template lang="pug">
  2. div(v-cloak="")
  3. div.columns
  4. div.column.is-12
  5. div.card
  6. header.card-header
  7. p.card-header-title Label stats
  8. a.card-header-icon(href="#", aria-label="more options")
  9. span.icon
  10. i.fas.fa-angle-down(aria-hidden="true")
  11. div.card-content.columns
  12. div.column.is-8
  13. line-chart(v-bind:chart-data="labelData")
  14. div.column.is-4
  15. h2.subtitle Annotation Progress
  16. doughnut-chart(v-bind:chart-data="progressData")
  17. div.columns
  18. div.column.is-8
  19. div.card
  20. header.card-header
  21. p.card-header-title User stats
  22. a.card-header-icon(href="#", aria-label="more options")
  23. span.icon
  24. i.fas.fa-angle-down(aria-hidden="true")
  25. div.card-content
  26. line-chart(v-bind:chart-data="userData")
  27. </template>
  28. <script>
  29. import HorizontalBar from 'vue-chartjs/es/BaseCharts/HorizontalBar';
  30. import Doughnut from 'vue-chartjs/es/BaseCharts/Doughnut';
  31. import reactiveProp from 'vue-chartjs/es/mixins/reactiveProp';
  32. import HTTP from './http';
  33. const LineChart = {
  34. extends: HorizontalBar,
  35. mixins: [reactiveProp],
  36. props: {
  37. chartData: {
  38. type: Object,
  39. default: () => {},
  40. },
  41. },
  42. data: () => ({
  43. options: {
  44. scales: {
  45. yAxes: [{
  46. barPercentage: 0.3,
  47. }],
  48. xAxes: [{
  49. ticks: {
  50. beginAtZero: true,
  51. min: 0,
  52. },
  53. }],
  54. },
  55. maintainAspectRatio: false,
  56. },
  57. }),
  58. mounted() {
  59. this.renderChart(this.chartData, this.options);
  60. },
  61. };
  62. const DoughnutChart = {
  63. extends: Doughnut,
  64. mixins: [reactiveProp],
  65. props: {
  66. chartData: {
  67. type: Object,
  68. default: () => {},
  69. },
  70. },
  71. data: () => ({
  72. options: {
  73. maintainAspectRatio: false,
  74. },
  75. }),
  76. mounted() {
  77. this.renderChart(this.chartData, this.options);
  78. },
  79. };
  80. export default {
  81. components: { LineChart, DoughnutChart },
  82. data: () => ({
  83. labelData: null,
  84. userData: null,
  85. progressData: null,
  86. }),
  87. created() {
  88. HTTP.get('statistics').then((response) => {
  89. this.labelData = this.makeData(response.data.label, 'Label stats');
  90. this.userData = this.makeData(response.data.user, 'User stats');
  91. const complete = response.data.total - response.data.remaining;
  92. const incomplete = response.data.remaining;
  93. this.progressData = {
  94. datasets: [{
  95. data: [complete, incomplete],
  96. backgroundColor: ['#00d1b2', '#ffdd57'],
  97. }],
  98. labels: [
  99. 'Completed',
  100. 'Incomplete',
  101. ],
  102. };
  103. });
  104. },
  105. methods: {
  106. makeData(object, label) {
  107. const labels = Object.keys(object);
  108. const counts = Object.values(object);
  109. const res = {
  110. labels: labels,
  111. datasets: [{
  112. label: label,
  113. backgroundColor: '#00d1b2',
  114. data: counts,
  115. }],
  116. };
  117. return res;
  118. },
  119. },
  120. };
  121. </script>