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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <script>
  2. import {CalendarHeatmap} from 'vue3-calendar-heatmap';
  3. export default {
  4. components: {CalendarHeatmap},
  5. props: {
  6. values: {
  7. type: Array,
  8. default: () => [],
  9. },
  10. locale: {
  11. type: Object,
  12. default: () => {},
  13. },
  14. },
  15. data: () => ({
  16. colorRange: [
  17. 'var(--color-secondary-alpha-60)',
  18. 'var(--color-secondary-alpha-60)',
  19. 'var(--color-primary-light-4)',
  20. 'var(--color-primary-light-2)',
  21. 'var(--color-primary)',
  22. 'var(--color-primary-dark-2)',
  23. 'var(--color-primary-dark-4)',
  24. ],
  25. endDate: new Date(),
  26. }),
  27. mounted() {
  28. // work around issue with first legend color being rendered twice and legend cut off
  29. const legend = document.querySelector('.vch__external-legend-wrapper');
  30. legend.setAttribute('viewBox', '12 0 80 10');
  31. legend.style.marginRight = '-12px';
  32. },
  33. methods: {
  34. handleDayClick(e) {
  35. // Reset filter if same date is clicked
  36. const params = new URLSearchParams(document.location.search);
  37. const queryDate = params.get('date');
  38. // Timezone has to be stripped because toISOString() converts to UTC
  39. const clickedDate = new Date(e.date - (e.date.getTimezoneOffset() * 60000)).toISOString().substring(0, 10);
  40. if (queryDate && queryDate === clickedDate) {
  41. params.delete('date');
  42. } else {
  43. params.set('date', clickedDate);
  44. }
  45. params.delete('page');
  46. const newSearch = params.toString();
  47. window.location.search = newSearch.length ? `?${newSearch}` : '';
  48. },
  49. },
  50. };
  51. </script>
  52. <template>
  53. <div class="total-contributions">
  54. {{ locale.contributions_in_the_last_12_months }}
  55. </div>
  56. <calendar-heatmap
  57. :locale="locale"
  58. :no-data-text="locale.no_contributions"
  59. :tooltip-unit="locale.contributions"
  60. :end-date="endDate"
  61. :values="values"
  62. :range-color="colorRange"
  63. @day-click="handleDayClick($event)"
  64. />
  65. </template>