Diff options
Diffstat (limited to 'source/ui-stats.c')
-rw-r--r--source/ui-stats.c48
1 file changed, 16 insertions, 32 deletions
diff --git a/source/ui-stats.c b/source/ui-stats.c
index 6b05c80..6da24ad 100644
--- a/source/ui-stats.c
+++ b/source/ui-stats.c
@@ -263,9 +263,9 @@ static struct string_list build_period_labels(const struct cgit_period *period)
* The run of authors to sum is given as a start and a count rather than as
* two indices, so that an empty author list cannot describe a run that wraps.
*/
-static void print_summary_row(struct string_list *authors, size_t from, size_t count,
- const char *label_format, const char *leftclass, const char *centerclass,
- const char *rightclass, const struct string_list *labels)
+static void print_row(struct string_list *authors, size_t from, size_t count,
+ const char *name, const char *nameclass, const char *cellclass,
+ const struct string_list *labels)
{
struct authorstat *stats;
struct string_list_item *bucket;
@@ -273,7 +273,9 @@ static void print_summary_row(struct string_list *authors, size_t from, size_t c
long total, subtotal;
total = 0;
- htmlf("<tr><td class='%s'>%s</td>", leftclass, cgit_fmt(label_format, (long)count));
+ htmlf("<tr><td class='%s'>", nameclass);
+ html_txt(name);
+ html("</td>");
for (column = 0; column < labels->nr; column++) {
const char *label = labels->items[column].string;
@@ -284,18 +286,18 @@ static void print_summary_row(struct string_list *authors, size_t from, size_t c
if (bucket)
subtotal += (uintptr_t)bucket->util;
}
- htmlf("<td class='%s'>%ld</td>", centerclass, subtotal);
+ if (cellclass)
+ htmlf("<td class='%s'>%ld</td>", cellclass, subtotal);
+ else
+ htmlf("<td>%ld</td>", subtotal);
total += subtotal;
}
- htmlf("<td class='%s'>%ld</td></tr>\n", rightclass, total);
+ htmlf("<td class='sum'>%ld</td></tr>\n", total);
}
static void print_authors(struct string_list *authors, int max_rows, const struct string_list *labels)
{
- struct string_list_item *author, *bucket;
- struct authorstat *stats;
size_t i, column, rows;
- long total;
html("<table class='stats'>\n<tr><th scope='col'>Author</th>");
for (column = 0; column < labels->nr; column++)
@@ -305,32 +307,14 @@ static void print_authors(struct string_list *authors, int max_rows, const struc
// The row count arrives through ofs, which carries -1 for "all".
rows = (max_rows <= 0 || (size_t)max_rows > authors->nr) ? authors->nr : (size_t)max_rows;
- for (i = 0; i < rows; i++) {
- author = &authors->items[i];
- html("<tr><td class='left'>");
- html_txt(author->string);
- html("</td>");
- stats = author->util;
- total = 0;
- for (column = 0; column < labels->nr; column++) {
- const char *label = labels->items[column].string;
-
- bucket = string_list_lookup(&stats->periods, label);
- if (!bucket)
- html("<td>0</td>");
- else {
- htmlf("<td>%ju</td>", (uintmax_t)(uintptr_t)bucket->util);
- total += (uintptr_t)bucket->util;
- }
- }
- htmlf("<td class='sum'>%ld</td></tr>\n", total);
- }
+ for (i = 0; i < rows; i++)
+ print_row(authors, i, 1, authors->items[i].string, "left", NULL, labels);
if (rows < authors->nr)
- print_summary_row(authors, rows, authors->nr - rows, "Others (%ld)", "left", "", "sum",
- labels);
+ print_row(authors, rows, authors->nr - rows,
+ cgit_fmt("Others (%ld)", (long)(authors->nr - rows)), "left", NULL, labels);
- print_summary_row(authors, 0, authors->nr, "Total", "total", "sum", "sum", labels);
+ print_row(authors, 0, authors->nr, "Total", "total", "sum", labels);
html("</table>\n");
}