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.

74 lines
1.7 KiB

  1. <template>
  2. <v-card>
  3. <v-card-title v-text="title" />
  4. <v-divider />
  5. <v-tabs show-arrows>
  6. <v-tab
  7. v-for="(value, user) in chartJSFormat"
  8. :key="user"
  9. class="text-capitalize"
  10. >
  11. {{ user }}
  12. </v-tab>
  13. <v-tab-item
  14. v-for="(value, user) in chartJSFormat"
  15. :key="user"
  16. >
  17. <v-card-text>
  18. <bar-chart
  19. :chart-data="value"
  20. />
  21. </v-card-text>
  22. </v-tab-item>
  23. </v-tabs>
  24. </v-card>
  25. </template>
  26. <script lang="ts">
  27. import Vue, { PropType } from 'vue'
  28. import BarChart from '@/components/metrics/ChartBar.vue'
  29. import { Distribution } from '~/domain/models/metrics/metrics'
  30. export default Vue.extend({
  31. components: {
  32. BarChart
  33. },
  34. props: {
  35. title: {
  36. type: String,
  37. required: true,
  38. default: 'Distribution'
  39. },
  40. distribution: {
  41. type: Object as PropType<Distribution>,
  42. required: true
  43. },
  44. colorMapping: {
  45. type: Object,
  46. default: () => {},
  47. }
  48. },
  49. computed: {
  50. chartJSFormat(): any {
  51. const data: {[user: string]: {labels: string[], datasets: any[]}} = {}
  52. for (const user in this.distribution) {
  53. const labels = Object.keys(this.distribution[user])
  54. labels.sort()
  55. const counts = labels.map((label) => this.distribution[user][label])
  56. const colors = labels.map((label) => label in this.colorMapping ? this.colorMapping[label] : '#00d1b2')
  57. data[user] = {
  58. labels,
  59. datasets: [{
  60. title: this.title,
  61. backgroundColor: colors,
  62. data: counts
  63. }]
  64. }
  65. }
  66. return data
  67. }
  68. }
  69. })
  70. </script>