| | "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", |
| | "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", |