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.

78 lines
1.9 KiB

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