2024-10-29 04:15:05 +08:00
|
|
|
<script lang="ts" setup>
|
2024-05-02 21:22:55 +08:00
|
|
|
// TODO: Switch to upstream after https://github.com/razorness/vue3-calendar-heatmap/pull/34 is merged
|
|
|
|
import {CalendarHeatmap} from '@silverwind/vue3-calendar-heatmap';
|
2024-10-29 04:15:05 +08:00
|
|
|
import {onMounted, ref} from 'vue';
|
|
|
|
import type {Value as HeatmapValue, Locale as HeatmapLocale} from '@silverwind/vue3-calendar-heatmap';
|
2020-04-06 09:31:11 +08:00
|
|
|
|
2024-10-29 04:15:05 +08:00
|
|
|
defineProps<{
|
|
|
|
values?: HeatmapValue[];
|
|
|
|
locale: {
|
|
|
|
textTotalContributions: string;
|
|
|
|
heatMapLocale: Partial<HeatmapLocale>;
|
|
|
|
noDataText: string;
|
|
|
|
tooltipUnit: string;
|
|
|
|
};
|
|
|
|
}>();
|
2021-02-21 06:08:58 +08:00
|
|
|
|
2024-10-29 04:15:05 +08:00
|
|
|
const colorRange = [
|
|
|
|
'var(--color-secondary-alpha-60)',
|
|
|
|
'var(--color-secondary-alpha-60)',
|
|
|
|
'var(--color-primary-light-4)',
|
|
|
|
'var(--color-primary-light-2)',
|
|
|
|
'var(--color-primary)',
|
|
|
|
'var(--color-primary-dark-2)',
|
|
|
|
'var(--color-primary-dark-4)',
|
|
|
|
];
|
2021-02-21 06:08:58 +08:00
|
|
|
|
2024-10-29 04:15:05 +08:00
|
|
|
const endDate = ref(new Date());
|
2023-02-25 05:15:10 +08:00
|
|
|
|
2024-10-29 04:15:05 +08:00
|
|
|
onMounted(() => {
|
|
|
|
// work around issue with first legend color being rendered twice and legend cut off
|
|
|
|
const legend = document.querySelector<HTMLElement>('.vch__external-legend-wrapper');
|
|
|
|
legend.setAttribute('viewBox', '12 0 80 10');
|
|
|
|
legend.style.marginRight = '-12px';
|
|
|
|
});
|
|
|
|
|
|
|
|
function handleDayClick(e: Event & {date: Date}) {
|
|
|
|
// Reset filter if same date is clicked
|
|
|
|
const params = new URLSearchParams(document.location.search);
|
|
|
|
const queryDate = params.get('date');
|
|
|
|
// Timezone has to be stripped because toISOString() converts to UTC
|
|
|
|
const clickedDate = new Date(e.date.getTime() - (e.date.getTimezoneOffset() * 60000)).toISOString().substring(0, 10);
|
|
|
|
|
|
|
|
if (queryDate && queryDate === clickedDate) {
|
|
|
|
params.delete('date');
|
|
|
|
} else {
|
|
|
|
params.set('date', clickedDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
params.delete('page');
|
|
|
|
|
|
|
|
const newSearch = params.toString();
|
|
|
|
window.location.search = newSearch.length ? `?${newSearch}` : '';
|
|
|
|
}
|
2020-04-06 09:31:11 +08:00
|
|
|
</script>
|
2023-09-02 22:59:07 +08:00
|
|
|
<template>
|
|
|
|
<div class="total-contributions">
|
2024-05-02 21:22:55 +08:00
|
|
|
{{ locale.textTotalContributions }}
|
2023-09-02 22:59:07 +08:00
|
|
|
</div>
|
|
|
|
<calendar-heatmap
|
2024-05-02 21:22:55 +08:00
|
|
|
:locale="locale.heatMapLocale"
|
|
|
|
:no-data-text="locale.noDataText"
|
|
|
|
:tooltip-unit="locale.tooltipUnit"
|
2023-09-02 22:59:07 +08:00
|
|
|
:end-date="endDate"
|
|
|
|
:values="values"
|
|
|
|
:range-color="colorRange"
|
|
|
|
@day-click="handleDayClick($event)"
|
2024-05-02 21:22:55 +08:00
|
|
|
:tippy-props="{theme: 'tooltip'}"
|
2023-09-02 22:59:07 +08:00
|
|
|
/>
|
|
|
|
</template>
|