code.gitea.io/gitea@v1.21.7/web_src/js/features/heatmap.js (about)

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