gitea源码

ActivityHeatmap.vue 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <script lang="ts" setup>
  2. // TODO: Switch to upstream after https://github.com/razorness/vue3-calendar-heatmap/pull/34 is merged
  3. import {CalendarHeatmap} from '@silverwind/vue3-calendar-heatmap';
  4. import {onMounted, shallowRef} from 'vue';
  5. import type {Value as HeatmapValue, Locale as HeatmapLocale} from '@silverwind/vue3-calendar-heatmap';
  6. defineProps<{
  7. values?: HeatmapValue[];
  8. locale: {
  9. textTotalContributions: string;
  10. heatMapLocale: Partial<HeatmapLocale>;
  11. noDataText: string;
  12. tooltipUnit: string;
  13. };
  14. }>();
  15. const colorRange = [
  16. 'var(--color-secondary-alpha-60)',
  17. 'var(--color-secondary-alpha-60)',
  18. 'var(--color-primary-light-4)',
  19. 'var(--color-primary-light-2)',
  20. 'var(--color-primary)',
  21. 'var(--color-primary-dark-2)',
  22. 'var(--color-primary-dark-4)',
  23. ];
  24. const endDate = shallowRef(new Date());
  25. onMounted(() => {
  26. // work around issue with first legend color being rendered twice and legend cut off
  27. const legend = document.querySelector<HTMLElement>('.vch__external-legend-wrapper');
  28. legend.setAttribute('viewBox', '12 0 80 10');
  29. legend.style.marginRight = '-12px';
  30. });
  31. function handleDayClick(e: Event & {date: Date}) {
  32. // Reset filter if same date is clicked
  33. const params = new URLSearchParams(document.location.search);
  34. const queryDate = params.get('date');
  35. // Timezone has to be stripped because toISOString() converts to UTC
  36. const clickedDate = new Date(e.date.getTime() - (e.date.getTimezoneOffset() * 60000)).toISOString().substring(0, 10);
  37. if (queryDate && queryDate === clickedDate) {
  38. params.delete('date');
  39. } else {
  40. params.set('date', clickedDate);
  41. }
  42. params.delete('page');
  43. const newSearch = params.toString();
  44. window.location.search = newSearch.length ? `?${newSearch}` : '';
  45. }
  46. </script>
  47. <template>
  48. <div class="total-contributions">
  49. {{ locale.textTotalContributions }}
  50. </div>
  51. <calendar-heatmap
  52. :locale="locale.heatMapLocale"
  53. :no-data-text="locale.noDataText"
  54. :tooltip-unit="locale.tooltipUnit"
  55. :end-date="endDate"
  56. :values="values"
  57. :range-color="colorRange"
  58. @day-click="handleDayClick($event)"
  59. :tippy-props="{theme: 'tooltip'}"
  60. />
  61. </template>