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.

97 lines
2.0 KiB

  1. import { HorizontalBar, mixins, Doughnut } from 'vue-chartjs';
  2. import Vue from 'vue';
  3. import HTTP from './http';
  4. const { reactiveProp, reactiveData } = mixins;
  5. Vue.component('line-chart', {
  6. extends: HorizontalBar,
  7. mixins: [reactiveProp],
  8. props: ['chartData'],
  9. data() {
  10. return {
  11. options: {
  12. scales: {
  13. yAxes: [{
  14. barPercentage: 0.3,
  15. }],
  16. xAxes: [{
  17. ticks: {
  18. beginAtZero: true,
  19. min: 0,
  20. },
  21. }],
  22. },
  23. maintainAspectRatio: false,
  24. },
  25. };
  26. },
  27. mounted() {
  28. this.renderChart(this.chartData, this.options);
  29. },
  30. });
  31. Vue.component('doughnut-chart', {
  32. extends: Doughnut,
  33. mixins: [reactiveProp],
  34. props: ['chartData'],
  35. data() {
  36. return {
  37. options: {
  38. maintainAspectRatio: false,
  39. },
  40. };
  41. },
  42. mounted() {
  43. this.renderChart(this.chartData, this.options);
  44. },
  45. });
  46. const vm = new Vue({
  47. el: '#mail-app',
  48. delimiters: ['[[', ']]'],
  49. data: {
  50. labelData: null,
  51. userData: null,
  52. progressData: null,
  53. },
  54. methods: {
  55. makeData(data, labels, label) {
  56. const res = {
  57. labels: labels,
  58. datasets: [{
  59. label: label,
  60. backgroundColor: '#00d1b2',
  61. data: data,
  62. }],
  63. };
  64. return res;
  65. },
  66. },
  67. created() {
  68. HTTP.get('stats').then((response) => {
  69. this.labelData = this.makeData(response.data.label.data, response.data.label.labels, 'Label stats');
  70. this.userData = this.makeData(response.data.user.data, response.data.user.users, 'User stats');
  71. });
  72. HTTP.get('progress').then((response) => {
  73. const complete = response.data.total - response.data.remaining;
  74. const incomplete = response.data.remaining;
  75. this.progressData = {
  76. datasets: [{
  77. data: [complete, incomplete],
  78. backgroundColor: ['#00d1b2', '#ffdd57'],
  79. }],
  80. labels: [
  81. 'Completed',
  82. 'Incomplete',
  83. ],
  84. };
  85. });
  86. },
  87. });