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.

heatmap.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {createApp} from 'vue';
  2. import ActivityHeatmap from '../components/ActivityHeatmap.vue';
  3. import {translateMonth, translateDay} from '../utils.js';
  4. export function initHeatmap() {
  5. const el = document.getElementById('user-heatmap');
  6. if (!el) return;
  7. try {
  8. const heatmap = {};
  9. for (const {contributions, timestamp} of JSON.parse(el.getAttribute('data-heatmap-data'))) {
  10. // Convert to user timezone and sum contributions by date
  11. const dateStr = new Date(timestamp * 1000).toDateString();
  12. heatmap[dateStr] = (heatmap[dateStr] || 0) + contributions;
  13. }
  14. const values = Object.keys(heatmap).map((v) => {
  15. return {date: new Date(v), count: heatmap[v]};
  16. });
  17. // last heatmap tooltip localization attempt https://github.com/go-gitea/gitea/pull/24131/commits/a83761cbbae3c2e3b4bced71e680f44432073ac8
  18. const locale = {
  19. months: new Array(12).fill().map((_, idx) => translateMonth(idx)),
  20. days: new Array(7).fill().map((_, idx) => translateDay(idx)),
  21. contributions: 'contributions',
  22. contributions_in_the_last_12_months: el.getAttribute('data-locale-total-contributions'),
  23. no_contributions: el.getAttribute('data-locale-no-contributions'),
  24. more: el.getAttribute('data-locale-more'),
  25. less: el.getAttribute('data-locale-less'),
  26. };
  27. const View = createApp(ActivityHeatmap, {values, locale});
  28. View.mount(el);
  29. el.classList.remove('is-loading');
  30. } catch (err) {
  31. console.error('Heatmap failed to load', err);
  32. el.textContent = 'Heatmap failed to load';
  33. }
  34. }