2 //= require cal-heatmap/dist/cal-heatmap
4 //= require cal-heatmap/dist/plugins/Tooltip
6 /* global CalHeatmap, Tooltip */
7 document.addEventListener("DOMContentLoaded", () => {
8 const heatmapElement = document.querySelector("#cal-heatmap");
10 if (!heatmapElement) {
14 const heatmapData = heatmapElement.dataset.heatmap ? JSON.parse(heatmapElement.dataset.heatmap) : [];
15 const colorScheme = document.documentElement.getAttribute("data-bs-theme") ?? "auto";
16 const rangeColors = ["#14432a", "#166b34", "#37a446", "#4dd05a"];
17 const startDate = new Date(Date.now() - (365 * 24 * 60 * 60 * 1000));
18 const monthNames = I18n.t("date.abbr_month_names");
20 const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
22 let cal = new CalHeatmap();
23 let currentTheme = getTheme();
25 function renderHeatmap() {
27 cal = new CalHeatmap();
30 itemSelector: "#cal-heatmap",
36 text: (timestamp) => monthNames[new Date(timestamp).getUTCMonth() + 1],
40 dynamicDimension: true
62 range: currentTheme === "dark" ? rangeColors : Array.from(rangeColors).reverse(),
63 domain: [10, 20, 30, 40]
68 text: (date, value) => getTooltipText(date, value)
73 function getTooltipText(date, value) {
74 const localizedDate = I18n.l("date.formats.long", date);
77 return I18n.t("javascripts.heatmap.tooltip.contributions", { count: value, date: localizedDate });
80 return I18n.t("javascripts.heatmap.tooltip.no_contributions", { date: localizedDate });
84 if (colorScheme === "auto") {
85 return mediaQuery.matches ? "dark" : "light";
91 if (colorScheme === "auto") {
92 mediaQuery.addEventListener("change", (e) => {
93 currentTheme = e.matches ? "dark" : "light";