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
2.9 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, mixins, Doughnut } from 'vue-chartjs';
  30. import HTTP from './http';
  31. const { reactiveProp } = mixins;
  32. const LineChart = {
  33. extends: HorizontalBar,
  34. mixins: [reactiveProp],
  35. props: {
  36. chartData: {
  37. type: Object,
  38. default: () => {},
  39. },
  40. },
  41. data: () => ({
  42. options: {
  43. scales: {
  44. yAxes: [{
  45. barPercentage: 0.3,
  46. }],
  47. xAxes: [{
  48. ticks: {
  49. beginAtZero: true,
  50. min: 0,
  51. },
  52. }],
  53. },
  54. maintainAspectRatio: false,
  55. },
  56. }),
  57. mounted() {
  58. this.renderChart(this.chartData, this.options);
  59. },
  60. };
  61. const DoughnutChart = {
  62. extends: Doughnut,
  63. mixins: [reactiveProp],
  64. props: {
  65. chartData: {
  66. type: Object,
  67. default: () => {},
  68. },
  69. },
  70. data: () => ({
  71. options: {
  72. maintainAspectRatio: false,
  73. },
  74. }),
  75. mounted() {
  76. this.renderChart(this.chartData, this.options);
  77. },
  78. };
  79. export default {
  80. components: { LineChart, DoughnutChart },
  81. data: () => ({
  82. labelData: null,
  83. userData: null,
  84. progressData: null,
  85. }),
  86. created() {
  87. HTTP.get('statistics').then((response) => {
  88. this.labelData = this.makeData(response.data.label, 'Label stats');
  89. this.userData = this.makeData(response.data.user, 'User stats');
  90. const complete = response.data.total - response.data.remaining;
  91. const incomplete = response.data.remaining;
  92. this.progressData = {
  93. datasets: [{
  94. data: [complete, incomplete],
  95. backgroundColor: ['#00d1b2', '#ffdd57'],
  96. }],
  97. labels: [
  98. 'Completed',
  99. 'Incomplete',
  100. ],
  101. };
  102. });
  103. },
  104. methods: {
  105. makeData(object, label) {
  106. const labels = Object.keys(object);
  107. const counts = Object.values(object);
  108. const res = {
  109. labels: labels,
  110. datasets: [{
  111. label: label,
  112. backgroundColor: '#00d1b2',
  113. data: counts,
  114. }],
  115. };
  116. return res;
  117. },
  118. },
  119. };
  120. </script>