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.

ActivityHeatmap.vue 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div id="user-heatmap">
  3. <div class="total-contributions">
  4. {{ sum }} contributions in the last 12 months
  5. </div>
  6. <calendar-heatmap
  7. :locale="locale"
  8. :no-data-text="locale.no_contributions"
  9. :tooltip-unit="locale.contributions"
  10. :end-date="endDate"
  11. :values="values"
  12. :range-color="colorRange"
  13. @day-click="handleDayClick($event)"
  14. />
  15. </div>
  16. </template>
  17. <script>
  18. import {CalendarHeatmap} from 'vue-calendar-heatmap';
  19. export default {
  20. name: 'ActivityHeatmap',
  21. components: {CalendarHeatmap},
  22. props: {
  23. values: {
  24. type: Array,
  25. default: () => [],
  26. },
  27. },
  28. data: () => ({
  29. colorRange: [
  30. 'var(--color-secondary-alpha-70)',
  31. 'var(--color-primary-light-4)',
  32. 'var(--color-primary-light-2)',
  33. 'var(--color-primary)',
  34. 'var(--color-primary-dark-2)',
  35. 'var(--color-primary-dark-4)',
  36. ],
  37. endDate: new Date(),
  38. locale: {
  39. contributions: 'contributions',
  40. no_contributions: 'No contributions',
  41. },
  42. }),
  43. computed: {
  44. sum() {
  45. let s = 0;
  46. for (let i = 0; i < this.values.length; i++) {
  47. s += this.values[i].count;
  48. }
  49. return s;
  50. }
  51. },
  52. methods: {
  53. handleDayClick(e) {
  54. // Reset filter if same date is clicked
  55. const params = new URLSearchParams(document.location.search);
  56. const queryDate = params.get('date');
  57. // Timezone has to be stripped because toISOString() converts to UTC
  58. const clickedDate = new Date(e.date - (e.date.getTimezoneOffset() * 60000)).toISOString().substring(0, 10);
  59. if (queryDate && queryDate === clickedDate) {
  60. params.delete('date');
  61. } else {
  62. params.set('date', clickedDate);
  63. }
  64. const newSearch = params.toString();
  65. window.location.search = newSearch.length ? `?${newSearch}` : '';
  66. }
  67. },
  68. };
  69. </script>
  70. <style scoped/>