]> granicus.if.org Git - sysstat/commitdiff
sadf: SVG: Allow user to customize color palette
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 20 Jan 2019 09:05:04 +0000 (10:05 +0100)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 20 Jan 2019 09:05:04 +0000 (10:05 +0100)
Add a new environment variable (S_COLORS_PALETTE) that can be used to
customize the color palette used by sadf to draw its graphs.
This variable is taken into account when the custom color palette has
been selected ("sadf -g -O customcol (...)").
The contents of this variable is a colon-separated list of six-digit,
three-byte hexadecimal numbers (hex triplets) that represent colors.
Detailed explanations will be given in sadf manual page.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sa.h
sadf.c
sadf_misc.c

diff --git a/sa.h b/sa.h
index a656fbfd0e70563d8fcc910e879355d73d72cb4d..1cd0c3d9e5eefc90eac03d46d082f68b3848569a 100644 (file)
--- a/sa.h
+++ b/sa.h
 #define K_CUSTOMCOL    "customcol"
 #define K_BWCOL                "bwcol"
 
+/* Environment variables */
+#define ENV_COLORS_PALETTE     "S_COLORS_PALETTE"
+
 /* Groups of activities */
 #define G_DEFAULT      0x00
 #define G_INT          0x01
@@ -1345,6 +1348,8 @@ void get_global_soft_statistics
        (struct activity *, int, int, unsigned int, unsigned char []);
 void get_itv_value
        (struct record_header *, struct record_header *, unsigned long long *);
+void init_custom_color_palette
+       (void);
 int next_slice
        (unsigned long long, unsigned long long, int, long);
 void parse_sa_devices
diff --git a/sadf.c b/sadf.c
index 10e5286dc389538c0baa58c2f6534862524e6ea9..927838d49a04eeb9f024748ede83c598866fcd31 100644 (file)
--- a/sadf.c
+++ b/sadf.c
@@ -1295,6 +1295,9 @@ void logic3_display_loop(int ifd, struct file_activity *file_actlst,
        /* Use a decimal point to make SVG code locale independent */
        setlocale(LC_NUMERIC, "C");
 
+       /* Init custom colors palette */
+       init_custom_color_palette();
+
        /*
         * Calculate the number of rows and the max number of views per row to display.
         * Result may be 0. In this case, "No data" will be displayed instead of the graphs.
index 7510af09fe320798912f3235b4d4005f035d3d09..e40f03eb444eec445b7927973944881996ea8c80 100644 (file)
@@ -1151,3 +1151,68 @@ __nr_t count_new_disk(struct activity *a, int curr)
 
        return nr;
 }
+
+/*
+ ***************************************************************************
+ * Init custom color palette used to draw graphs (sadf -g).
+ ***************************************************************************
+ */
+void init_custom_color_palette()
+{
+       char *e, *p;
+       int len;
+       unsigned int val;
+
+       /* Read S_COLORS_PALETTE environment variable */
+       if ((e = getenv(ENV_COLORS_PALETTE)) == NULL)
+               /* Environment variable not set */
+               return;
+
+       for (p = strtok(e, ":"); p; p =strtok(NULL, ":")) {
+
+               len = strlen(p);
+               if ((len > 8) || (len < 3) || (*(p + 1) != '=') ||
+                   (strspn(p + 2, "0123456789ABCDEFabcdef") != (len - 2)))
+                       /* Ignore malformed codes */
+                       continue;
+
+               sscanf(p + 2, "%x", &val);
+
+               if ((*p >= '0') && (*p <= '9')) {
+                       svg_colors[SVG_CUSTOM_COL_PALETTE][*p & 0xf] = val;
+                       continue;
+               }
+               else if (((*p >= 'A') && (*p <= 'F')) ||
+                        ((*p >= 'a') && (*p <= 'f'))) {
+                       svg_colors[SVG_CUSTOM_COL_PALETTE][9 + (*p & 0xf)] = val;
+                       continue;
+               }
+
+               switch (*p) {
+                       case 'G':
+                               svg_colors[SVG_CUSTOM_COL_PALETTE][SVG_COL_GRID_IDX] = val;
+                               break;
+                       case 'H':
+                               svg_colors[SVG_CUSTOM_COL_PALETTE][SVG_COL_HEADER_IDX] = val;
+                               break;
+                       case 'I':
+                               svg_colors[SVG_CUSTOM_COL_PALETTE][SVG_COL_INFO_IDX] = val;
+                               break;
+                       case 'K':
+                               svg_colors[SVG_CUSTOM_COL_PALETTE][SVG_COL_BCKGRD_IDX] = val;
+                               break;
+                       case 'L':
+                               svg_colors[SVG_CUSTOM_COL_PALETTE][SVG_COL_DEFAULT_IDX] = val;
+                               break;
+                       case 'T':
+                               svg_colors[SVG_CUSTOM_COL_PALETTE][SVG_COL_TITLE_IDX] = val;
+                               break;
+                       case 'W':
+                               svg_colors[SVG_CUSTOM_COL_PALETTE][SVG_COL_ERROR_IDX] = val;
+                               break;
+                       case 'X':
+                               svg_colors[SVG_CUSTOM_COL_PALETTE][SVG_COL_AXIS_IDX] = val;
+                               break;
+               }
+       }
+}