]> git.ipfire.org Git - oddments/collecty.git/commitdiff
graphs: Simplify the LINE macros
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Oct 2025 11:46:22 +0000 (11:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 29 Oct 2025 11:46:22 +0000 (11:46 +0000)
We should pass the strength of the line instead of replicating the same
macro again and again.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/graphs/conntrack.c
src/daemon/graphs/cpufreq.c
src/daemon/graphs/graph.h
src/daemon/graphs/hostapd-station-rate-info.c
src/daemon/graphs/hostapd-station-signal.c
src/daemon/graphs/memory.c

index 48cbd80d56f6c74ca0ea24f2a995bd56b5eb0f05..20d2338deda8fe444b484aaf44f148e9030b4fea 100644 (file)
@@ -51,7 +51,7 @@ static int conntrack_render(td_ctx* ctx,
        PRINT_CAMM(args, "count", NULL, LARGE_INTEGER);
 
        // Limit
-       DRAW_LINE1_WITH_LABEL(args, "max", NULL, LIMIT, _("Limit"), DASHES SKIPSCALE);
+       DRAW_LINE_WITH_LABEL(args, 1, "max", NULL, LIMIT, _("Limit"), DASHES SKIPSCALE);
        PRINT(args, FIELD_CURRENT("max_cur"), NULL, LARGE_INTEGER);
        PRINT_NOTHING(args);
        PRINT_NOTHING(args);
index e3b6a8ef6c7416c20afbd037ef8d26365628dff0..1b883c6a5c99407b5e7e6b2c64b1927b50488eb7 100644 (file)
@@ -58,14 +58,14 @@ static int cpufreq_render(td_ctx* ctx,
                        return r;
 
                // Draw the line
-               DRAW_LINE1_WITH_LABEL(args, "freq_cur", object, COLOR_CPU(i), _("CPU Core %ld"));
+               DRAW_LINE_WITH_LABEL(args, 1, "freq_cur", object, COLOR_CPU(i), _("CPU Core %ld"));
                PRINT_CAMM(args, "freq_cur", object, HZ, _("Hz"));
 
                // Draw the minimum
-               DRAW_LINE2(args, "freq_min", object, MINIMUM);
+               DRAW_LINE(args, 2, "freq_min", object, MINIMUM);
 
                // Draw the maximum
-               DRAW_LINE2(args, "freq_max", object, MAXIMUM);
+               DRAW_LINE(args, 2, "freq_max", object, MAXIMUM);
        }
 
        return 0;
index ab4d9d6289f552ff7998a11d2253fc0eaf8fbc3c..8cab94c19affc39916d13d4ef2319678bbd7cab9 100644 (file)
        SCRIPT(args, what ":" FIELD "%s:" LABEL __VA_ARGS__, FIELD_AND_OBJECT(field, object), color, label)
 
 // Draw lines
-#define DRAW_LINE1(args, field, object, color, ...) \
-       DRAW(args, "LINE1", field, object, color, __VA_ARGS__)
-#define DRAW_LINE1_WITH_LABEL(args, field, object, color, label, ...) \
-       DRAW_WITH_LABEL(args, "LINE1", field, object, color, label, __VA_ARGS__)
-
-#define DRAW_LINE2(args, field, object, color, ...) \
-       DRAW(args, "LINE2", field, object, color, __VA_ARGS__)
-#define DRAW_LINE2_WITH_LABEL(args, field, object, color, label, ...) \
-       DRAW_WITH_LABEL(args, "LINE2", field, object, color, label, __VA_ARGS__)
-
-#define DRAW_LINE3(args, field, object, color, ...) \
-       DRAW(args, "LINE3", field, object, color, __VA_ARGS__)
-#define DRAW_LINE3_WITH_LABEL(args, field, object, color, label, ...) \
-       DRAW_WITH_LABEL(args, "LINE3", field, object, color, label, __VA_ARGS__)
+#define DRAW_LINE(args, strength, field, object, color, ...) \
+       DRAW(args, "LINE" TOSTRING(strength), field, object, color, __VA_ARGS__)
+#define DRAW_LINE_WITH_LABEL(args, strength, field, object, color, label, ...) \
+       DRAW_WITH_LABEL(args, "LINE" TOSTRING(strength), field, object, color, label, __VA_ARGS__)
 
 // Macros to draw the background of an area
 #define DRAW_AREA_BACKGROUND(args, field, object, color, ...) \
        DRAW(args, "AREA", field, object, COLOR_WITH_ALPHA(color, OPACITY_AREA), __VA_ARGS__)
 
 // Macros to draw the area's outline
-#define DRAW_AREA_OUTLINE                              DRAW_LINE1
-#define DRAW_AREA_OUTLINE_WITH_LABEL   DRAW_LINE1_WITH_LABEL
+#define DRAW_AREA_OUTLINE(args, field, object, color) \
+       DRAW_LINE(args, 1, field, object, color)
+#define DRAW_AREA_OUTLINE_WITH_LABEL(args, field, object, color, label, ...) \
+       DRAW_LINE_WITH_LABEL(args, 1, field, object, color, label, __VA_ARGS__)
 
 #define DRAW_AREA(args, field, object, color) \
        do { \
index 5f796aefa5e2d8f3d9da13789b6c25e79ced36a7..d83d6c14e836dd960e1bb361a4d926c5758df35e 100644 (file)
@@ -47,11 +47,11 @@ static int hostapd_station_rate_info_render(td_ctx* ctx,
        PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
 
        // Receive Rate
-       DRAW_LINE2_WITH_LABEL(args, "rx_rate", object, COLOR_RX, _("Receive Rate"));
+       DRAW_LINE_WITH_LABEL(args, 2, "rx_rate", object, COLOR_RX, _("Receive Rate"));
        PRINT_CAMM(args, "rx_rate", object, BPS, _("bps"));
 
        // Transmit Rate
-       DRAW_LINE2_WITH_LABEL(args, "tx_rate", object, COLOR_TX, _("Transmit Rate"));
+       DRAW_LINE_WITH_LABEL(args, 2, "tx_rate", object, COLOR_TX, _("Transmit Rate"));
        PRINT_CAMM(args, "tx_rate", object, BPS, _("bps"));
 
        return 0;
index 7df75c2a0e82ecfeafd587e767e91d76cfe73747..528b5b43f4de9c6c3c6c453f92e1d6999882b5e7 100644 (file)
@@ -59,16 +59,16 @@ static int hostapd_station_signal_render(td_ctx* ctx,
        PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
 
        // Draw signal
-       DRAW_LINE2_WITH_LABEL(args, "signal", object, GREEN, _("Signal"));
+       DRAW_LINE_WITH_LABEL(args, 2, "signal", object, GREEN, _("Signal"));
        PRINT_CAMM(args, "signal", object, FLOAT_WITH_UNIT, _("dBm"));
 
        // Draw the lower signal quality in different colors
-       DRAW_LINE2(args, "signal_good", object, YELLOW);
-       DRAW_LINE2(args, "signal_fair", object, ORANGE);
-       DRAW_LINE2(args, "signal_poor", object, RED);
+       DRAW_LINE(args, 2, "signal_good", object, YELLOW);
+       DRAW_LINE(args, 2, "signal_fair", object, ORANGE);
+       DRAW_LINE(args, 2, "signal_poor", object, RED);
 
        // Draw last ACK signal
-       DRAW_LINE2_WITH_LABEL(args, "last_ack_signal", object, GREY, _("Last ACK Signal"));
+       DRAW_LINE_WITH_LABEL(args, 2, "last_ack_signal", object, GREY, _("Last ACK Signal"));
        PRINT_CAMM(args, "last_ack_signal", object, FLOAT_WITH_UNIT, _("dBm"));
 
        return 0;
index 21aa7273f1486312ba3d7050ee12e349351b87ee..03a84065f7c0b09994086999eb33cc6650b4d54a 100644 (file)
@@ -81,18 +81,18 @@ static int memory_render(td_ctx* ctx,
        PRINT_CAMM(args, "cached", NULL, LARGE_FLOAT);
 
        // Draw the total memory as a line
-       DRAW_LINE1(args, "mem_total", NULL, COLOR_MEM_TOTAL);
+       DRAW_LINE(args, 1, "mem_total", NULL, COLOR_MEM_TOTAL);
 
        // Make some space for swap
        PRINT_EMPTY_LINE(args);
 
-       DRAW_LINE1_WITH_LABEL(args, "swap_used", NULL, COLOR_SWAP_USED, _("Used Swap"), DASHES);
+       DRAW_LINE_WITH_LABEL(args, 1, "swap_used", NULL, COLOR_SWAP_USED, _("Used Swap"), DASHES);
        PRINT_CAMM(args, "swap_used", NULL, LARGE_FLOAT);
 
        PRINT_EMPTY_LABEL(args);
        PRINT_CAMM(args, "swap_used", NULL, PERCENTAGE);
 
-       DRAW_LINE1_WITH_LABEL(args, "swap_total", NULL, COLOR_SWAP_TOTAL, _("Total Swap"), DASHES);
+       DRAW_LINE_WITH_LABEL(args, 1, "swap_total", NULL, COLOR_SWAP_TOTAL, _("Total Swap"), DASHES);
        PRINT(args, FIELD_CURRENT("swap_used"), NULL, LARGE_FLOAT);
        PRINT_NOTHING(args);
        PRINT_NOTHING(args);