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.

ActivityTopAuthors.vue 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div>
  3. <div class="activity-bar-graph" ref="style" style="width:0px;height:0px"></div>
  4. <div class="activity-bar-graph-alt" ref="altStyle" style="width:0px;height:0px"></div>
  5. <vue-bar-graph
  6. :points="graphData"
  7. :show-x-axis="true"
  8. :show-y-axis="false"
  9. :show-values="true"
  10. :width="graphWidth"
  11. :bar-color="colors.barColor"
  12. :text-color="colors.textColor"
  13. :text-alt-color="colors.textAltColor"
  14. :height="100"
  15. :label-height="20"
  16. >
  17. <template v-slot:label="opt">
  18. <g v-for="(author, idx) in authors" :key="author.position">
  19. <a
  20. v-if="opt.bar.index === idx && author.home_link !== ''"
  21. :href="author.home_link"
  22. >
  23. <image
  24. :x="`${opt.bar.midPoint - 10}px`"
  25. :y="`${opt.bar.yLabel}px`"
  26. height="20"
  27. width="20"
  28. :href="author.avatar_link"
  29. />
  30. </a>
  31. <image
  32. v-else-if="opt.bar.index === idx"
  33. :x="`${opt.bar.midPoint - 10}px`"
  34. :y="`${opt.bar.yLabel}px`"
  35. height="20"
  36. width="20"
  37. :href="author.avatar_link"
  38. />
  39. </g>
  40. </template>
  41. <template v-slot:title="opt">
  42. <tspan v-for="(author, idx) in authors" :key="author.position"><tspan v-if="opt.bar.index === idx">{{ author.name }}</tspan></tspan>
  43. </template>
  44. </vue-bar-graph>
  45. </div>
  46. </template>
  47. <script>
  48. import VueBarGraph from 'vue-bar-graph';
  49. export default {
  50. components: {
  51. VueBarGraph,
  52. },
  53. props: {
  54. data: { type: Array, default: () => [] },
  55. },
  56. mounted() {
  57. const st = window.getComputedStyle(this.$refs.style);
  58. const stalt = window.getComputedStyle(this.$refs.altStyle);
  59. this.colors.barColor = st.backgroundColor;
  60. this.colors.textColor = st.color;
  61. this.colors.textAltColor = stalt.color;
  62. },
  63. data() {
  64. return {
  65. colors: {
  66. barColor: 'green',
  67. textColor: 'black',
  68. textAltColor: 'white',
  69. },
  70. };
  71. },
  72. computed: {
  73. graphData() {
  74. return this.data.map((item) => {
  75. return {
  76. value: item.commits,
  77. label: item.name,
  78. };
  79. });
  80. },
  81. authors() {
  82. return this.data.map((item, idx) => {
  83. return {
  84. position: idx+1,
  85. ...item,
  86. }
  87. });
  88. },
  89. graphWidth() {
  90. return this.data.length * 40;
  91. },
  92. },
  93. methods: {
  94. hasHomeLink(i) {
  95. return this.graphData[i].homeLink !== '' && this.graphData[i].homeLink !== null;
  96. },
  97. }
  98. }
  99. </script>