From 592266cf623513b932dc002fde8fbbc0f81b0f28 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 27 Sep 2026 22:04:58 +0300 Subject: 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. --- ui-stats.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) 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("", centerclass); + else + htmlf("", 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("%ld", centerclass, subtotal); + htmlf("%ld", subtotal); total += subtotal; } htmlf("%ld", rightclass, total); @@ -321,7 +325,11 @@ static void print_authors(struct string_list *authors, int top, html(""); for (j = 0; j < period->count; j++) { tmp = period->pretty(&tm); - htmlf("", tmp); + if (tm.tm_mon == 0) + html("", tmp); period->inc(&tm); } html("\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(""); + html("0"); else { - htmlf("", (uintptr_t)date->util); + htmlf("%lu", (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(""); html(""); @@ -429,6 +444,14 @@ void cgit_show_stats(void) html("')"); } html(""); + html("

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("

"); print_authors(&authors, top, period); cgit_print_layout_end(); } -- cgit v1.3.1-23-gd82d
Author%s"); + else + html(""); + htmlf("%sTotal
"); + else + html(""); period->inc(&tm); date = string_list_lookup(items, tmp); if (!date) - html("0%lu
Period: