From: Michael Tremer Date: Sat, 4 Oct 2025 12:01:50 +0000 (+0000) Subject: graphs: Make it configurable if the graph is reversed X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f16f2b0dbb9a15fd365dada415f70ab3ae1a596d;p=collecty.git graphs: Make it configurable if the graph is reversed Signed-off-by: Michael Tremer --- diff --git a/src/daemon/graph.c b/src/daemon/graph.c index 0f1e55e..a5f26fe 100644 --- a/src/daemon/graph.c +++ b/src/daemon/graph.c @@ -60,10 +60,6 @@ const char* DEFAULT_RENDER_ARGS[] = { // Add a watermark "--watermark=" PACKAGE_NAME, - // Invert legend order. This way, we can draw graphs from back to front - // to be able to user overlay and transparency. - "--legend-direction=bottomup", - // Honour upper/lower limit "--rigid", @@ -317,6 +313,15 @@ int collecty_graph_render(collecty_graph* self, const char* object, } } + // Invert the legend? + // This way, we can draw graphs from back to front + // to be able to user overlay and transparency. + if (self->impl->flags & COLLECTY_GRAPH_REVERSE) { + r = collecty_args_push(args, "--legend-direction=bottomup"); + if (r < 0) + goto ERROR; + } + // Write the graph to the output stream r = collecty_args_push(args, "-"); if (r < 0) diff --git a/src/daemon/graph.h b/src/daemon/graph.h index 59a9abc..2f1fc62 100644 --- a/src/daemon/graph.h +++ b/src/daemon/graph.h @@ -32,6 +32,11 @@ typedef struct collecty_graph_impl { // Name const char* name; + // Flags + enum { + COLLECTY_GRAPH_REVERSE = (1 << 0), + } flags; + // Limits long lower_limit; long upper_limit; diff --git a/src/daemon/graphs/conntrack.c b/src/daemon/graphs/conntrack.c index 5e13910..c19762b 100644 --- a/src/daemon/graphs/conntrack.c +++ b/src/daemon/graphs/conntrack.c @@ -42,12 +42,8 @@ static int conntrack_render(collecty_ctx* ctx, if (r < 0) return r; - // Limit - DRAW_LINE1_WITH_LABEL(args, "max", LIMIT, _("Limit"), DASHES SKIPSCALE); - PRINT_LARGE_INTEGER(args, "max_cur"); - PRINT_NOTHING(args); - PRINT_NOTHING(args); - PRINT_NOTHING(args, EOL); + // Header + PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); // Entries DRAW_AREA_WITH_LABEL(args, "count", GREEN, _("Entries")); @@ -56,8 +52,12 @@ static int conntrack_render(collecty_ctx* ctx, PRINT_LARGE_INTEGER(args, "count_min"); PRINT_LARGE_INTEGER(args, "count_max", EOL); - // Header - PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); + // Limit + DRAW_LINE1_WITH_LABEL(args, "max", LIMIT, _("Limit"), DASHES SKIPSCALE); + PRINT_LARGE_INTEGER(args, "max_cur"); + PRINT_NOTHING(args); + PRINT_NOTHING(args); + PRINT_NOTHING(args, EOL); return 0; } diff --git a/src/daemon/graphs/contextswitches.c b/src/daemon/graphs/contextswitches.c index 446318a..45089ef 100644 --- a/src/daemon/graphs/contextswitches.c +++ b/src/daemon/graphs/contextswitches.c @@ -42,6 +42,9 @@ static int contextswitches_render(collecty_ctx* ctx, if (r < 0) return r; + // Header + PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); + // Context Switches DRAW_AREA_WITH_LABEL(args, "ctxt", GREEN, _("Context Switches")); PRINT_LARGE_INTEGER(args, "ctxt_cur"); @@ -49,9 +52,6 @@ static int contextswitches_render(collecty_ctx* ctx, PRINT_LARGE_INTEGER(args, "ctxt_min"); PRINT_LARGE_INTEGER(args, "ctxt_max", EOL); - // Header - PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum")); - return 0; } diff --git a/src/daemon/graphs/loadavg.c b/src/daemon/graphs/loadavg.c index 4ce63d0..ffc691b 100644 --- a/src/daemon/graphs/loadavg.c +++ b/src/daemon/graphs/loadavg.c @@ -75,6 +75,9 @@ const collecty_graph_impl loadavg_graph = { .title = loadavg_title, .vlabel = loadavg_title, + // Flags + .flags = COLLECTY_GRAPH_REVERSE, + // Limits .lower_limit = 0, .upper_limit = LONG_MAX,