You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ActivityHeatmap.vue 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div>
  3. <div v-show="isLoading">
  4. <slot name="loading"/>
  5. </div>
  6. <h4 v-if="!isLoading" class="total-contributions">
  7. {{ values.length }} total contributions in the last 12 months
  8. </h4>
  9. <calendar-heatmap
  10. v-show="!isLoading"
  11. :locale="locale"
  12. :no-data-text="locale.no_contributions"
  13. :tooltip-unit="locale.contributions"
  14. :end-date="endDate"
  15. :values="values"
  16. :range-color="colorRange"
  17. />
  18. </div>
  19. </template>
  20. <script>
  21. import {CalendarHeatmap} from 'vue-calendar-heatmap';
  22. const {AppSubUrl, heatmapUser} = window.config;
  23. export default {
  24. name: 'ActivityHeatmap',
  25. components: {CalendarHeatmap},
  26. data: () => ({
  27. isLoading: true,
  28. colorRange: [],
  29. endDate: null,
  30. values: [],
  31. suburl: AppSubUrl,
  32. user: heatmapUser,
  33. locale: {
  34. contributions: 'contributions',
  35. no_contributions: 'No contributions',
  36. },
  37. }),
  38. mounted() {
  39. this.colorRange = [
  40. this.getColor(0),
  41. this.getColor(1),
  42. this.getColor(2),
  43. this.getColor(3),
  44. this.getColor(4),
  45. this.getColor(5)
  46. ];
  47. this.endDate = new Date();
  48. this.loadHeatmap(this.user);
  49. },
  50. methods: {
  51. async loadHeatmap(userName) {
  52. const res = await fetch(`${this.suburl}/api/v1/users/${userName}/heatmap`);
  53. const data = await res.json();
  54. this.values = data.map(({contributions, timestamp}) => {
  55. return {date: new Date(timestamp * 1000), count: contributions};
  56. });
  57. this.isLoading = false;
  58. },
  59. getColor(idx) {
  60. const el = document.createElement('div');
  61. el.className = `heatmap-color-${idx}`;
  62. document.body.appendChild(el);
  63. const color = getComputedStyle(el).backgroundColor;
  64. document.body.removeChild(el);
  65. return color;
  66. }
  67. },
  68. };
  69. </script>
  70. <style scoped/>