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 2.4 kB

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