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.

RepoActivityTopAuthors.vue 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <script>
  2. import VueBarGraph from 'vue-bar-graph';
  3. import {createApp} from 'vue';
  4. const sfc = {
  5. components: {VueBarGraph},
  6. data: () => ({
  7. colors: {
  8. barColor: 'green',
  9. textColor: 'black',
  10. textAltColor: 'white',
  11. },
  12. // possible keys:
  13. // * avatar_link: (...)
  14. // * commits: (...)
  15. // * home_link: (...)
  16. // * login: (...)
  17. // * name: (...)
  18. activityTopAuthors: window.config.pageData.repoActivityTopAuthors || [],
  19. }),
  20. computed: {
  21. graphPoints() {
  22. return this.activityTopAuthors.map((item) => {
  23. return {
  24. value: item.commits,
  25. label: item.name,
  26. };
  27. });
  28. },
  29. graphAuthors() {
  30. return this.activityTopAuthors.map((item, idx) => {
  31. return {
  32. position: idx + 1,
  33. ...item,
  34. };
  35. });
  36. },
  37. graphWidth() {
  38. return this.activityTopAuthors.length * 40;
  39. },
  40. },
  41. mounted() {
  42. const refStyle = window.getComputedStyle(this.$refs.style);
  43. const refAltStyle = window.getComputedStyle(this.$refs.altStyle);
  44. this.colors.barColor = refStyle.backgroundColor;
  45. this.colors.textColor = refStyle.color;
  46. this.colors.textAltColor = refAltStyle.color;
  47. },
  48. };
  49. export function initRepoActivityTopAuthorsChart() {
  50. const el = document.getElementById('repo-activity-top-authors-chart');
  51. if (el) {
  52. createApp(sfc).mount(el);
  53. }
  54. }
  55. export default sfc; // activate the IDE's Vue plugin
  56. </script>
  57. <template>
  58. <div>
  59. <div class="activity-bar-graph" ref="style" style="width: 0; height: 0;"/>
  60. <div class="activity-bar-graph-alt" ref="altStyle" style="width: 0; height: 0;"/>
  61. <vue-bar-graph
  62. :points="graphPoints"
  63. :show-x-axis="true"
  64. :show-y-axis="false"
  65. :show-values="true"
  66. :width="graphWidth"
  67. :bar-color="colors.barColor"
  68. :text-color="colors.textColor"
  69. :text-alt-color="colors.textAltColor"
  70. :height="100"
  71. :label-height="20"
  72. >
  73. <template #label="opt">
  74. <g v-for="(author, idx) in graphAuthors" :key="author.position">
  75. <a
  76. v-if="opt.bar.index === idx && author.home_link"
  77. :href="author.home_link"
  78. >
  79. <image
  80. :x="`${opt.bar.midPoint - 10}px`"
  81. :y="`${opt.bar.yLabel}px`"
  82. height="20"
  83. width="20"
  84. :href="author.avatar_link"
  85. />
  86. </a>
  87. <image
  88. v-else-if="opt.bar.index === idx"
  89. :x="`${opt.bar.midPoint - 10}px`"
  90. :y="`${opt.bar.yLabel}px`"
  91. height="20"
  92. width="20"
  93. :href="author.avatar_link"
  94. />
  95. </g>
  96. </template>
  97. <template #title="opt">
  98. <tspan v-for="(author, idx) in graphAuthors" :key="author.position">
  99. <tspan v-if="opt.bar.index === idx">
  100. {{ author.name }}
  101. </tspan>
  102. </tspan>
  103. </template>
  104. </vue-bar-graph>
  105. </div>
  106. </template>