gitea源码

RepoActivityTopAuthors.vue 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <script lang="ts" setup>
  2. // @ts-expect-error - module exports no types
  3. import {VueBarGraph} from 'vue-bar-graph';
  4. import {computed, onMounted, shallowRef, useTemplateRef} from 'vue';
  5. const colors = shallowRef({
  6. barColor: 'green',
  7. textColor: 'black',
  8. textAltColor: 'white',
  9. });
  10. type ActivityAuthorData = {
  11. avatar_link: string;
  12. commits: number;
  13. home_link: string;
  14. login: string;
  15. name: string;
  16. }
  17. const activityTopAuthors: Array<ActivityAuthorData> = window.config.pageData.repoActivityTopAuthors || [];
  18. const graphPoints = computed(() => {
  19. return activityTopAuthors.map((item) => {
  20. return {
  21. value: item.commits,
  22. label: item.name,
  23. };
  24. });
  25. });
  26. const graphAuthors = computed(() => {
  27. return activityTopAuthors.map((item, idx: number) => {
  28. return {
  29. position: idx + 1,
  30. ...item,
  31. };
  32. });
  33. });
  34. const graphWidth = computed(() => {
  35. return activityTopAuthors.length * 40;
  36. });
  37. const styleElement = useTemplateRef('styleElement');
  38. const altStyleElement = useTemplateRef('altStyleElement');
  39. onMounted(() => {
  40. const refStyle = window.getComputedStyle(styleElement.value);
  41. const refAltStyle = window.getComputedStyle(altStyleElement.value);
  42. colors.value = {
  43. barColor: refStyle.backgroundColor,
  44. textColor: refStyle.color,
  45. textAltColor: refAltStyle.color,
  46. };
  47. });
  48. </script>
  49. <template>
  50. <div>
  51. <div class="activity-bar-graph tw-w-0 tw-h-0" ref="styleElement"/>
  52. <div class="activity-bar-graph-alt tw-w-0 tw-h-0" ref="altStyleElement"/>
  53. <vue-bar-graph
  54. :points="graphPoints"
  55. :show-x-axis="true"
  56. :show-y-axis="false"
  57. :show-values="true"
  58. :width="graphWidth"
  59. :bar-color="colors.barColor"
  60. :text-color="colors.textColor"
  61. :text-alt-color="colors.textAltColor"
  62. :height="100"
  63. :label-height="20"
  64. >
  65. <template #label="opt">
  66. <g v-for="(author, idx) in graphAuthors" :key="author.position">
  67. <a
  68. v-if="opt.bar.index === idx && author.home_link"
  69. :href="author.home_link"
  70. >
  71. <image
  72. :x="`${opt.bar.midPoint - 10}px`"
  73. :y="`${opt.bar.yLabel}px`"
  74. height="20"
  75. width="20"
  76. :href="author.avatar_link"
  77. />
  78. </a>
  79. <image
  80. v-else-if="opt.bar.index === idx"
  81. :x="`${opt.bar.midPoint - 10}px`"
  82. :y="`${opt.bar.yLabel}px`"
  83. height="20"
  84. width="20"
  85. :href="author.avatar_link"
  86. />
  87. </g>
  88. </template>
  89. <template #title="opt">
  90. <tspan v-for="(author, idx) in graphAuthors" :key="author.position">
  91. <tspan v-if="opt.bar.index === idx">
  92. {{ author.name }}
  93. </tspan>
  94. </tspan>
  95. </template>
  96. </vue-bar-graph>
  97. </div>
  98. </template>