diff options
1 files changed, 32 insertions, 9 deletions
| -rw-r--r-- | ui-stats.c | 41 |
@@ -130,10 +130,10 @@ static char *pretty_year(struct tm *tm) } static const struct cgit_period periods[] = { - {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, - {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, - {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, - {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year}, + {'w', "week", 12, 12, trunc_week, dec_week, inc_week, pretty_week}, + {'m', "month", 12, 12, trunc_month, dec_month, inc_month, pretty_month}, + {'q', "quarter", 12, 12, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, + {'y', "year", 12, 12, trunc_year, dec_year, inc_year, pretty_year}, }; /* Given a period code or name, return a period index (1, 2, 3 or 4) @@ -284,6 +284,10 @@ static void print_combined_authorrow(struct string_list *authors, int from, fmt(name, to - from + 1)); for (j = 0; j < period->count; j++) { tmp = period->pretty(&tm); + if (tm.tm_mon == 0) + htmlf("<td class='%s year-start'>", centerclass); + else + htmlf("<td class='%s'>", centerclass); period->inc(&tm); subtotal = 0; for (i = from; i <= to; i++) { @@ -294,7 +298,7 @@ static void print_combined_authorrow(struct string_list *authors, int from, if (date) subtotal += (uintptr_t)date->util; } - htmlf("<td class='%s'>%ld</td>", centerclass, subtotal); + htmlf("%ld</td>", subtotal); total += subtotal; } htmlf("<td class='%s'>%ld</td></tr>", rightclass, total); @@ -321,7 +325,11 @@ static void print_authors(struct string_list *authors, int top, html("<table class='stats'><tr><th>Author</th>"); for (j = 0; j < period->count; j++) { tmp = period->pretty(&tm); - htmlf("<th>%s</th>", tmp); + if (tm.tm_mon == 0) + html("<th class='year-start'>"); + else + html("<th>"); + htmlf("%s</th>", tmp); period->inc(&tm); } html("<th>Total</th></tr>\n"); @@ -341,12 +349,16 @@ static void print_authors(struct string_list *authors, int top, period->dec(&tm); for (j = 0; j < period->count; j++) { tmp = period->pretty(&tm); + if (tm.tm_mon == 0) + html("<td class='year-start'>"); + else + html("<td>"); period->inc(&tm); date = string_list_lookup(items, tmp); if (!date) - html("<td>0</td>"); + html("0</td>"); else { - htmlf("<td>%lu</td>", (uintptr_t)date->util); + htmlf("%lu</td>", (uintptr_t)date->util); total += (uintptr_t)date->util; } } @@ -373,6 +385,9 @@ void cgit_show_stats(void) int top, i; const char *code = "w"; + if (ctx.repo->max_stats) + code = fmt("%c", periods[ctx.repo->max_stats - 1].code); + if (ctx.qry.period) code = ctx.qry.period; @@ -404,7 +419,7 @@ void cgit_show_stats(void) if (ctx.repo->max_stats > 1) { html("<tr><td class='label'>Period:</td>"); html("<td class='ctrl'><select name='period' onchange='this.form.submit();'>"); - for (i = 0; i < ctx.repo->max_stats; i++) + for (i = ctx.repo->max_stats - 1; i >= 0; i--) html_option(fmt("%c", periods[i].code), periods[i].name, fmt("%c", period->code)); html("</select></td></tr>"); @@ -429,6 +444,14 @@ void cgit_show_stats(void) html("')"); } html("</h2>"); + html("<p>Last "); + switch (period->code) { + case 'w': htmlf("%d months (%d weeks)", period->count / 4, period->count); break; + case 'm': htmlf("%d years (%d months)", period->count / 12, period->count); break; + case 'q': htmlf("%d years (%d quarters)", period->count / 4, period->count); break; + case 'y': htmlf("%d years", period->count); break; + } + html("</p>"); print_authors(&authors, top, period); cgit_print_layout_end(); } |
