104 void html::h2(const std::string& heading) { |
107 void html::h2(const std::string& heading) { |
105 indent(); |
108 indent(); |
106 printf("<h2>%s</h2>\n", encode(heading).c_str()); |
109 printf("<h2>%s</h2>\n", encode(heading).c_str()); |
107 } |
110 } |
108 |
111 |
109 void html::table_begin() { |
112 void html::table_begin(int year) { |
|
113 static constexpr const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
|
114 // compute the column spans, first |
|
115 unsigned colspans[12] = {}; |
|
116 { |
|
117 unsigned total_cols = 0; |
|
118 chrono::sys_days day{chrono::year_month_day{chrono::year{year}, chrono::month{1}, chrono::day{1}}}; |
|
119 if (chrono::weekday{day}.iso_encoding() != 1) { |
|
120 colspans[0] = 1; |
|
121 total_cols = 1; |
|
122 } |
|
123 for (unsigned col = 0; col < 12; ++col) { |
|
124 while (total_cols < html::columns && chrono::year_month_day{day}.month() <= chrono::month{col + 1}) { |
|
125 ++total_cols; |
|
126 ++colspans[col]; |
|
127 day += chrono::days{7}; |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 // now render the table heading |
110 indent(); |
133 indent(); |
111 puts("<table class=\"heatmap\">"); |
134 puts("<table class=\"heatmap\">"); |
112 indent(1); |
135 indent(1); |
113 puts("<tr>"); |
136 puts("<tr>"); |
114 indent(1); |
137 indent(1); |
115 puts("<th></th>"); |
138 puts("<th></th>"); |
116 static constexpr const char* months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; |
|
117 static constexpr int colspans[] = {5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 5}; |
|
118 for (unsigned i = 0 ; i < 12 ; i++) { |
139 for (unsigned i = 0 ; i < 12 ; i++) { |
119 indent(); |
140 indent(); |
120 printf("<th scope=\"col\" colspan=\"%d\">%s</th>\n", colspans[i], months[i]); |
141 printf("<th scope=\"col\" colspan=\"%d\">%s</th>\n", colspans[i], months[i]); |
121 } |
142 } |
122 indent(-1); |
143 indent(-1); |