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.

106 lines
2.6 KiB

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