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.

77 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 Vue, { PropType } from 'vue'
  19. import BarChart from '@/components/metrics/ChartBar.vue'
  20. import { Distribution } from '~/domain/models/metrics/metrics'
  21. import { LabelDTO } from '~/services/application/label/labelData'
  22. export default Vue.extend({
  23. components: {
  24. BarChart
  25. },
  26. props: {
  27. title: {
  28. type: String,
  29. required: true,
  30. default: 'Distribution'
  31. },
  32. distribution: {
  33. type: Object as PropType<Distribution>,
  34. required: true
  35. },
  36. labelTypes: {
  37. type: Array as PropType<LabelDTO[]>,
  38. default: () => [],
  39. required: true
  40. }
  41. },
  42. computed: {
  43. colorMapping(): { [text: string]: string } {
  44. return Object.fromEntries(
  45. this.labelTypes.map((labelType) => [labelType.text, labelType.backgroundColor])
  46. )
  47. },
  48. chartJSFormat(): any {
  49. const data: { [user: string]: { labels: string[]; datasets: any[] } } = {}
  50. for (const user in this.distribution) {
  51. const labels = Object.keys(this.distribution[user])
  52. labels.sort()
  53. const counts = labels.map((label) => this.distribution[user][label])
  54. const colors = labels.map((label) =>
  55. label in this.colorMapping ? this.colorMapping[label] : '#00d1b2'
  56. )
  57. data[user] = {
  58. labels,
  59. datasets: [
  60. {
  61. title: this.title,
  62. backgroundColor: colors,
  63. data: counts
  64. }
  65. ]
  66. }
  67. }
  68. return data
  69. }
  70. }
  71. })
  72. </script>