File size: 13,284 Bytes
dcdc07a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | {
"id": "contribution-heatmap",
"name": "Contribution Heatmap",
"description": "Reusable GitHub-style contribution heatmap",
"author": "ysharma",
"tags": [
"Business"
],
"category": "Display",
"html_template": "\n<div class=\"heatmap-container\">\n <div class=\"heatmap-header\">\n <h2>${(() => {\n const total = Object.values(value || {}).reduce((a, b) => a + b, 0);\n return '\ud83d\udcca ' + total.toLocaleString() + ' contributions in ' + year;\n })()}</h2>\n <div class=\"legend\">\n <span>Less</span>\n <div class=\"legend-box\" style=\"background:${c0}\"></div>\n <div class=\"legend-box\" style=\"background:${c1}\"></div>\n <div class=\"legend-box\" style=\"background:${c2}\"></div>\n <div class=\"legend-box\" style=\"background:${c3}\"></div>\n <div class=\"legend-box\" style=\"background:${c4}\"></div>\n <span>More</span>\n </div>\n </div>\n <div class=\"month-labels\">\n ${(() => {\n const months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\n return months.map((m, i) =>\n '<span style=\"grid-column:' + (Math.floor(i * 4.33) + 2) + '\">' + m + '</span>'\n ).join('');\n })()}\n </div>\n <div class=\"heatmap-grid\">\n <div class=\"day-labels\">\n <span></span><span>Mon</span><span></span><span>Wed</span><span></span><span>Fri</span><span></span>\n </div>\n <div class=\"cells\">\n ${(() => {\n const v = value || {};\n const sd = new Date(year, 0, 1);\n const pad = sd.getDay();\n const cells = [];\n for (let i = 0; i < pad; i++) cells.push('<div class=\"cell empty\"></div>');\n const totalDays = Math.floor((new Date(year, 11, 31) - sd) / 86400000) + 1;\n for (let d = 0; d < totalDays; d++) {\n const dt = new Date(year, 0, 1 + d);\n const key = dt.getFullYear() + '-' + String(dt.getMonth()+1).padStart(2,'0') + '-' + String(dt.getDate()).padStart(2,'0');\n const count = v[key] || 0;\n let lv = 0;\n if (count > 0) lv = 1;\n if (count >= 3) lv = 2;\n if (count >= 6) lv = 3;\n if (count >= 10) lv = 4;\n const mn = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];\n const tip = count + ' contributions on ' + mn[dt.getMonth()] + ' ' + dt.getDate() + ', ' + year;\n cells.push('<div class=\"cell level-' + lv + '\" data-date=\"' + key + '\" data-count=\"' + count + '\" title=\"' + tip + '\"></div>');\n }\n return cells.join('');\n })()}\n </div>\n </div>\n <div class=\"stats-bar\">\n ${(() => {\n const v = value || {};\n const totalDays = Math.floor((new Date(year, 11, 31) - new Date(year, 0, 1)) / 86400000) + 1;\n let streak = 0, maxStreak = 0, total = 0, active = 0, best = 0;\n const vals = [];\n for (let d = 0; d < totalDays; d++) {\n const dt = new Date(year, 0, 1 + d);\n const key = dt.getFullYear() + '-' + String(dt.getMonth()+1).padStart(2,'0') + '-' + String(dt.getDate()).padStart(2,'0');\n const c = v[key] || 0;\n total += c;\n if (c > 0) { streak++; maxStreak = Math.max(maxStreak, streak); active++; best = Math.max(best, c); vals.push(c); }\n else { streak = 0; }\n }\n const avg = vals.length ? (total / vals.length).toFixed(1) : '0';\n const stats = [\n ['\ud83d\udd25', maxStreak, 'Longest Streak'],\n ['\ud83d\udcc5', active, 'Active Days'],\n ['\u26a1', best, 'Best Day'],\n ['\ud83d\udcc8', avg, 'Avg / Active Day'],\n ['\ud83c\udfc6', total.toLocaleString(), 'Total'],\n ];\n return stats.map(s =>\n '<div class=\"stat\"><span class=\"stat-value\">' + s[1] + '</span><span class=\"stat-label\">' + s[0] + ' ' + s[2] + '</span></div>'\n ).join('');\n })()}\n </div>\n</div>\n",
"css_template": "\n .heatmap-container {\n background: #0d1117;\n border-radius: 12px;\n padding: 24px;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;\n color: #c9d1d9;\n overflow-x: auto;\n }\n .heatmap-header {\n display: flex; justify-content: space-between; align-items: center;\n margin-bottom: 12px; flex-wrap: wrap; gap: 10px;\n }\n .heatmap-header h2 { margin: 0; font-size: 16px; font-weight: 500; color: #f0f6fc; }\n .legend { display: flex; align-items: center; gap: 4px; font-size: 11px; color: #8b949e; }\n .legend-box { width: 12px; height: 12px; border-radius: 2px; }\n .month-labels {\n display: grid; grid-template-columns: 30px repeat(53, 1fr);\n font-size: 11px; color: #8b949e; margin-bottom: 4px; padding-left: 2px;\n }\n .heatmap-grid { display: flex; gap: 4px; }\n .day-labels {\n display: grid; grid-template-rows: repeat(7, 1fr);\n font-size: 11px; color: #8b949e; width: 30px; gap: 2px;\n }\n .day-labels span { height: 13px; display: flex; align-items: center; }\n .cells {\n display: grid; grid-template-rows: repeat(7, 1fr);\n grid-auto-flow: column; gap: 2px; flex: 1;\n }\n .cell {\n width: 13px; height: 13px; border-radius: 2px; cursor: pointer;\n transition: all 0.15s ease; outline: 1px solid rgba(27,31,35,0.06);\n }\n .cell:hover {\n outline: 2px solid #58a6ff; outline-offset: -1px;\n transform: scale(1.3); z-index: 1;\n }\n .cell.empty { visibility: hidden; }\n .level-0 { background: ${c0}; }\n .level-1 { background: ${c1}; }\n .level-2 { background: ${c2}; }\n .level-3 { background: ${c3}; }\n .level-4 { background: ${c4}; }\n .stats-bar {\n display: flex; justify-content: space-around; margin-top: 20px;\n padding-top: 16px; border-top: 1px solid #21262d;\n flex-wrap: wrap; gap: 12px;\n }\n .stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }\n .stat-value { font-size: 22px; font-weight: 700; color: ${c4}; }\n .stat-label { font-size: 12px; color: #8b949e; }\n",
"js_on_load": "\n element.addEventListener('click', (e) => {\n if (e.target && e.target.classList.contains('cell') && !e.target.classList.contains('empty')) {\n const date = e.target.dataset.date;\n const cur = parseInt(e.target.dataset.count) || 0;\n const next = cur >= 12 ? 0 : cur + 1;\n const nv = {...(props.value || {})};\n if (next === 0) delete nv[date]; else nv[date] = next;\n props.value = nv;\n trigger('change');\n }\n });\n",
"default_props": {
"value": {
"2025-01-01": 15,
"2025-01-02": 10,
"2025-01-05": 2,
"2025-01-06": 2,
"2025-01-07": 3,
"2025-01-08": 7,
"2025-01-13": 1,
"2025-01-14": 3,
"2025-01-15": 1,
"2025-01-17": 1,
"2025-01-19": 5,
"2025-01-20": 4,
"2025-01-22": 1,
"2025-01-26": 2,
"2025-01-27": 11,
"2025-01-28": 1,
"2025-01-29": 2,
"2025-02-02": 2,
"2025-02-04": 8,
"2025-02-05": 2,
"2025-02-07": 2,
"2025-02-09": 7,
"2025-02-10": 2,
"2025-02-11": 6,
"2025-02-12": 15,
"2025-02-13": 1,
"2025-02-15": 1,
"2025-02-19": 1,
"2025-02-21": 9,
"2025-02-22": 9,
"2025-02-26": 1,
"2025-02-27": 1,
"2025-02-28": 8,
"2025-03-01": 8,
"2025-03-02": 7,
"2025-03-05": 1,
"2025-03-07": 13,
"2025-03-08": 5,
"2025-03-09": 2,
"2025-03-11": 2,
"2025-03-12": 4,
"2025-03-14": 3,
"2025-03-15": 3,
"2025-03-16": 3,
"2025-03-18": 3,
"2025-03-20": 5,
"2025-03-21": 5,
"2025-03-22": 15,
"2025-03-25": 2,
"2025-03-27": 1,
"2025-03-28": 3,
"2025-04-03": 2,
"2025-04-04": 1,
"2025-04-07": 1,
"2025-04-11": 1,
"2025-04-13": 7,
"2025-04-14": 2,
"2025-04-17": 1,
"2025-04-19": 1,
"2025-04-21": 4,
"2025-04-22": 2,
"2025-04-23": 3,
"2025-04-24": 1,
"2025-04-27": 1,
"2025-04-29": 6,
"2025-04-30": 1,
"2025-05-01": 8,
"2025-05-05": 4,
"2025-05-07": 2,
"2025-05-09": 1,
"2025-05-11": 3,
"2025-05-12": 1,
"2025-05-13": 5,
"2025-05-16": 13,
"2025-05-17": 8,
"2025-05-18": 2,
"2025-05-19": 11,
"2025-05-21": 1,
"2025-05-24": 4,
"2025-05-27": 8,
"2025-05-28": 2,
"2025-05-29": 1,
"2025-05-30": 1,
"2025-06-01": 5,
"2025-06-02": 3,
"2025-06-04": 3,
"2025-06-05": 2,
"2025-06-07": 5,
"2025-06-14": 11,
"2025-06-15": 5,
"2025-06-19": 6,
"2025-06-20": 5,
"2025-06-22": 8,
"2025-06-24": 5,
"2025-06-25": 9,
"2025-06-27": 5,
"2025-06-28": 5,
"2025-06-29": 6,
"2025-06-30": 3,
"2025-07-01": 1,
"2025-07-02": 5,
"2025-07-05": 2,
"2025-07-08": 1,
"2025-07-10": 2,
"2025-07-12": 3,
"2025-07-13": 2,
"2025-07-14": 5,
"2025-07-15": 5,
"2025-07-16": 1,
"2025-07-18": 9,
"2025-07-19": 9,
"2025-07-20": 2,
"2025-07-22": 3,
"2025-07-24": 5,
"2025-07-25": 1,
"2025-07-27": 5,
"2025-07-30": 2,
"2025-08-01": 13,
"2025-08-02": 3,
"2025-08-03": 2,
"2025-08-04": 9,
"2025-08-05": 4,
"2025-08-07": 1,
"2025-08-09": 5,
"2025-08-12": 2,
"2025-08-13": 5,
"2025-08-14": 4,
"2025-08-15": 4,
"2025-08-18": 6,
"2025-08-19": 6,
"2025-08-20": 2,
"2025-08-24": 6,
"2025-08-25": 3,
"2025-08-26": 12,
"2025-08-27": 14,
"2025-08-29": 1,
"2025-08-31": 5,
"2025-09-01": 1,
"2025-09-02": 3,
"2025-09-03": 2,
"2025-09-04": 14,
"2025-09-05": 6,
"2025-09-06": 9,
"2025-09-07": 4,
"2025-09-08": 1,
"2025-09-10": 1,
"2025-09-16": 4,
"2025-09-18": 4,
"2025-09-19": 2,
"2025-09-20": 3,
"2025-09-23": 2,
"2025-09-24": 6,
"2025-09-25": 3,
"2025-09-27": 1,
"2025-09-28": 5,
"2025-09-29": 5,
"2025-10-02": 2,
"2025-10-03": 2,
"2025-10-06": 8,
"2025-10-07": 8,
"2025-10-08": 8,
"2025-10-09": 3,
"2025-10-10": 15,
"2025-10-13": 2,
"2025-10-14": 9,
"2025-10-15": 1,
"2025-10-16": 2,
"2025-10-17": 1,
"2025-10-20": 6,
"2025-10-23": 9,
"2025-10-26": 1,
"2025-10-28": 2,
"2025-10-31": 1,
"2025-11-01": 2,
"2025-11-02": 1,
"2025-11-03": 1,
"2025-11-05": 1,
"2025-11-06": 5,
"2025-11-07": 2,
"2025-11-09": 3,
"2025-11-10": 2,
"2025-11-11": 1,
"2025-11-13": 2,
"2025-11-14": 1,
"2025-11-15": 1,
"2025-11-17": 4,
"2025-11-19": 2,
"2025-11-20": 11,
"2025-11-21": 9,
"2025-11-23": 1,
"2025-11-24": 3,
"2025-11-27": 7,
"2025-11-28": 1,
"2025-11-29": 5,
"2025-12-01": 2,
"2025-12-03": 1,
"2025-12-05": 1,
"2025-12-07": 6,
"2025-12-08": 1,
"2025-12-09": 3,
"2025-12-10": 4,
"2025-12-15": 2,
"2025-12-19": 3,
"2025-12-20": 15,
"2025-12-23": 5,
"2025-12-25": 2,
"2025-12-26": 1,
"2025-12-28": 4,
"2025-12-29": 2
},
"year": 2025,
"c0": "#161b22",
"c1": "#0e4429",
"c2": "#006d32",
"c3": "#26a641",
"c4": "#39d353"
},
"python_code": "class ContributionHeatmap(gr.HTML):\n \"\"\"Reusable GitHub-style contribution heatmap built on gr.HTML.\"\"\"\n\n def __init__(self, value=None, year=2025, theme=\"green\",\n c0=None, c1=None, c2=None, c3=None, c4=None, **kwargs):\n if value is None:\n value = {}\n # Use explicit c0-c4 if provided (from gr.HTML updates), else derive from theme\n colors = COLOR_SCHEMES.get(theme, COLOR_SCHEMES[\"green\"])\n super().__init__(\n value=value,\n year=year,\n c0=c0 or colors[0],\n c1=c1 or colors[1],\n c2=c2 or colors[2],\n c3=c3 or colors[3],\n c4=c4 or colors[4],\n html_template=HEATMAP_HTML,\n css_template=HEATMAP_CSS,\n js_on_load=HEATMAP_JS,\n **kwargs,\n )\n\n def api_info(self):\n return {\"type\": \"object\", \"description\": \"Dict mapping YYYY-MM-DD to int counts\"}\n",
"head": "",
"repo_url": "https://huggingface.co/spaces/ysharma/github-contribution-heatmap"
} |