Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit592266cf623513b932dc002fde8fbbc0f81b0f28 (patch)
Author
 Syndamia <kamen@syndamia.com>
2026-09-27 22:04:58 +0300
Committer
 Syndamia <kamen@syndamia.com>
2026-09-27 22:18:05 +0300
Files27ef91230caba2d1b9ecd7ec737dfc2851de507f
cgit-592266cf623513b932dc002fde8fbbc0f81b0f28.tar
cgit-592266cf623513b932dc002fde8fbbc0f81b0f28.tar.gz
cgit-592266cf623513b932dc002fde8fbbc0f81b0f28.zip
Parent6494c4defa9e6dc24e13af9d17d25aea793359fc (diff)
ui-stats: (THEME) Rework and reorder stats
Increase period count to 12, insert a class at the year start of every period, add a paragraph outlining the total period, order periods from largest to smallest, use largest as default.
1 files changed, 32 insertions, 9 deletions
-rw-r--r--ui-stats.c41
diff --git a/ui-stats.c b/ui-stats.c
index 02c60ef..236c28a 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -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();
}