24 |
24 |
25 #include "html.h" |
25 #include "html.h" |
26 |
26 |
27 #include <cstdio> |
27 #include <cstdio> |
28 |
28 |
29 #include <chrono> |
|
30 namespace chrono = std::chrono; |
29 namespace chrono = std::chrono; |
31 |
30 |
32 namespace html { |
31 namespace html { |
|
32 static constexpr const char* weekdays[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}; |
|
33 |
33 static unsigned indentation; |
34 static unsigned indentation; |
34 static const char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; |
35 static const char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; |
35 static void indent(int change = 0) { |
36 static void indent(int change = 0) { |
36 indentation += change; |
37 indentation += change; |
37 fwrite(tabs, 1, indentation, stdout); |
38 fwrite(tabs, 1, indentation, stdout); |
86 width: 1.5em; |
87 width: 1.5em; |
87 height: 1.5em; |
88 height: 1.5em; |
88 } |
89 } |
89 table.heatmap td.out-of-range { |
90 table.heatmap td.out-of-range { |
90 background-color: gray; |
91 background-color: gray; |
|
92 } |
|
93 |
|
94 table.heatmap td.zero-commits { |
|
95 background-color: white; |
|
96 } |
|
97 |
|
98 table.heatmap td.one-commit { |
|
99 background-color: #80E7A0; |
|
100 } |
|
101 |
|
102 table.heatmap td.up-to-5-commits { |
|
103 background-color: #30D350; |
|
104 } |
|
105 |
|
106 table.heatmap td.up-to-10-commits { |
|
107 background-color: #00BF00; |
|
108 } |
|
109 |
|
110 table.heatmap td.up-to-20-commits { |
|
111 background-color: #00A300; |
|
112 } |
|
113 |
|
114 table.heatmap td.commit-spam { |
|
115 background-color: #008000; |
91 } |
116 } |
92 </style> |
117 </style> |
93 </head> |
118 </head> |
94 <body>)"); |
119 <body>)"); |
95 indentation = 2; |
120 indentation = 2; |
166 void html::cell_out_of_range() { |
190 void html::cell_out_of_range() { |
167 indent(); |
191 indent(); |
168 puts("<td class=\"out-of-range\"></td>"); |
192 puts("<td class=\"out-of-range\"></td>"); |
169 } |
193 } |
170 |
194 |
171 void html::cell(unsigned commits) { |
195 void html::cell(std::chrono::year_month_day ymd, unsigned commits) { |
172 indent(); |
196 const char *color_class; |
173 // TODO: use nice coloring and tooltips instead of printing the commits |
197 if (commits == 0) { |
174 printf("<td>%u</td>\n", commits); |
198 color_class = "zero-commits"; |
175 } |
199 } else if (commits == 1) { |
|
200 color_class = "one-commit"; |
|
201 } else if (commits <= 5) { |
|
202 color_class = "up-to-5-commits"; |
|
203 } else if (commits <= 10) { |
|
204 color_class = "up-to-10-commits"; |
|
205 } else if (commits <= 20) { |
|
206 color_class = "up-to-20-commits"; |
|
207 } else { |
|
208 color_class = "commit-spam"; |
|
209 } |
|
210 indent(); |
|
211 printf("<td class=\"%s\" title=\"%s, %d-%u-%u: %u commits\"></td>\n", |
|
212 color_class, |
|
213 weekdays[chrono::weekday(ymd).iso_encoding() - 1], |
|
214 static_cast<int>(ymd.year()), |
|
215 static_cast<unsigned>(ymd.month()), |
|
216 static_cast<unsigned>(ymd.day()), |
|
217 commits); |
|
218 } |