From: Sebastien GODARD Date: Sun, 20 Jan 2019 09:05:04 +0000 (+0100) Subject: sadf: SVG: Allow user to customize color palette X-Git-Tag: v12.1.3~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88b2b10f080ffac3225e363f0c50045a448f962e;p=sysstat sadf: SVG: Allow user to customize color palette 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 --- diff --git a/sa.h b/sa.h index a656fbf..1cd0c3d 100644 --- a/sa.h +++ b/sa.h @@ -227,6 +227,9 @@ #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 10e5286..927838d 100644 --- 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. diff --git a/sadf_misc.c b/sadf_misc.c index 7510af0..e40f03e 100644 --- a/sadf_misc.c +++ b/sadf_misc.c @@ -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; + } + } +}