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 921B

123456789101112131415161718192021222324252627282930
  1. import Vue from 'vue';
  2. import ActivityHeatmap from '../components/ActivityHeatmap.vue';
  3. export default function initHeatmap() {
  4. const el = document.getElementById('user-heatmap');
  5. if (!el) return;
  6. try {
  7. const heatmap = {};
  8. for (const {contributions, timestamp} of JSON.parse(el.getAttribute('data-heatmap-data'))) {
  9. // Convert to user timezone and sum contributions by date
  10. const dateStr = new Date(timestamp * 1000).toDateString();
  11. heatmap[dateStr] = (heatmap[dateStr] || 0) + contributions;
  12. }
  13. const values = Object.keys(heatmap).map((v) => {
  14. return {date: new Date(v), count: heatmap[v]};
  15. });
  16. const View = Vue.extend({
  17. render: (createElement) => createElement(ActivityHeatmap, {props: {values}}),
  18. });
  19. new View().$mount(el);
  20. } catch (err) {
  21. console.error('Heatmap failed to load', err);
  22. el.textContent = 'Heatmap failed to load';
  23. }
  24. }