src/html.cpp

changeset 7
d0f77dd2da42
parent 6
1040ba37d4c9
child 11
127fb6a8f706
--- a/src/html.cpp	Fri Jan 31 22:27:28 2025 +0100
+++ b/src/html.cpp	Fri Jan 31 22:48:43 2025 +0100
@@ -26,10 +26,11 @@
 
 #include <cstdio>
 
-#include <chrono>
 namespace chrono = std::chrono;
 
 namespace html {
+    static constexpr const char* weekdays[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
+
     static unsigned indentation;
     static const char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
     static void indent(int change = 0) {
@@ -89,6 +90,30 @@
             table.heatmap td.out-of-range {
                 background-color: gray;
             }
+
+            table.heatmap td.zero-commits {
+                background-color: white;
+            }
+
+            table.heatmap td.one-commit {
+                background-color: #80E7A0;
+            }
+
+            table.heatmap td.up-to-5-commits {
+                background-color: #30D350;
+            }
+
+            table.heatmap td.up-to-10-commits {
+                background-color: #00BF00;
+            }
+
+            table.heatmap td.up-to-20-commits {
+                background-color: #00A300;
+            }
+
+            table.heatmap td.commit-spam {
+                background-color: #008000;
+            }
         </style>
     </head>
     <body>)");
@@ -151,7 +176,6 @@
 }
 
 void html::row_begin(unsigned int row) {
-    static constexpr const char* weekdays[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
     indent();
     puts("<tr>");
     indent(1);
@@ -168,8 +192,27 @@
     puts("<td class=\"out-of-range\"></td>");
 }
 
-void html::cell(unsigned commits) {
+void html::cell(std::chrono::year_month_day ymd, unsigned commits) {
+    const char *color_class;
+    if (commits == 0) {
+        color_class = "zero-commits";
+    } else if (commits == 1) {
+        color_class = "one-commit";
+    } else if (commits <= 5) {
+        color_class = "up-to-5-commits";
+    } else if (commits <= 10) {
+        color_class = "up-to-10-commits";
+    } else if (commits <= 20) {
+        color_class = "up-to-20-commits";
+    } else {
+        color_class = "commit-spam";
+    }
     indent();
-    // TODO: use nice coloring and tooltips instead of printing the commits
-    printf("<td>%u</td>\n", commits);
+    printf("<td class=\"%s\" title=\"%s, %d-%u-%u: %u commits\"></td>\n",
+        color_class,
+        weekdays[chrono::weekday(ymd).iso_encoding() - 1],
+        static_cast<int>(ymd.year()),
+        static_cast<unsigned>(ymd.month()),
+        static_cast<unsigned>(ymd.day()),
+        commits);
 }

mercurial