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.

101 lines
3.1 KiB

  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>