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.

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