Added fancy new 'temperature gradients' feature.
authorBrenden Matthews <brenden@rty.ca>
Sun, 24 May 2009 21:53:32 +0000 (15:53 -0600)
committerBrenden Matthews <brenden@rty.ca>
Sun, 24 May 2009 21:53:32 +0000 (15:53 -0600)
See docs for more details on 'temperature gradients', which can be
turned on with the -t switch on graphs.  Also improved parsing of
options with $execgraph and $execigraph, but may cause some breakage.

ChangeLog
doc/variables.xml
src/colours.c
src/conky.c
src/specials.c
src/specials.h
src/text_object.h

index a963f27..47e2ebc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-05-24
+       * Added fancy new 'temperature gradients' feature for graphs, via the -t
+       switch at the end of graph arguments.
+
 2009-05-19
        * Added inotify support to reload the config when modified automatically
        on systems that support it
index acc7eb9..748c62f 100644 (file)
        <varlistentry>
                <term>
                        <command><option>apcupsd_loadgraph</option></command>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t)</option>
                </term>
                <listitem>
                        History graph of current load.
        <varlistentry>
                <term>
                        <command><option>cpugraph</option></command>
-                       <option>(cpuN) ("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale)</option>
+                       <option>(cpuN) ("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t)</option>
                </term>
                <listitem>
-                       CPU usage graph, with optional colours in hex, minus the #.  See $cpu for more info on SMP. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".
+                       CPU usage graph, with optional colours in hex, minus the #.  See $cpu for more info on SMP. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>diskiograph</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (device)</option>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (device)</option>
                </term>
                <listitem>
-                       Disk IO graph, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".
+                       Disk IO graph, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>diskiograph_read</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (device)</option>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (device)</option>
                </term>
                <listitem>
-                       Disk IO graph for reads, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph.  Device as in diskio. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".
+                       Disk IO graph for reads, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph.  Device as in diskio. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>diskiograph_write</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (device)</option>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (device)</option>
                </term>
                <listitem>
-                       Disk IO graph for writes, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph.  Device as in diskio. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".
+                       Disk IO graph for writes, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph.  Device as in diskio. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>downspeedgraph</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (net)</option>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (net)</option>
                </term>
                <listitem>
-                       Download speed graph, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".
+                       Download speed graph, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>execgraph</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) command</option>
+                       <option>("normal"|"log") (-t) command</option>
                </term>
                <listitem>
-                       Same as execbar, but graphs values. Uses a logaritmic scale when the log option is given (to see small numbers). Values still have to be between 0 and 100.  The size for graphs can be controlled via the default_graph_size config setting.
+                       Same as execbar, but graphs values. Uses a logaritmic scale when the log option is given (to see small numbers). Values still have to be between 0 and 100.  The size for graphs can be controlled via the default_graph_size config setting.  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>execigraph</option></command>
-                       <option>interval command</option>
+                       <option>interval ("normal"|"log") (-t) command</option>
                </term>
                <listitem>
                        Same as execgraph, but takes an interval arg and graphs values.
        <varlistentry>
                <term>
                        <command><option>loadgraph</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale)</option>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t)</option>
                </term>
                <listitem>
-                       Load1 average graph, similar to xload, with optional colours in hex, minus the #. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".
+                       Load1 average graph, similar to xload, with optional colours in hex, minus the #. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>memgraph</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale)</option>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t)</option>
                </term>
                <listitem>
-                       Memory usage graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".
+                       Memory usage graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>lua_graph</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) function_name (function parameters)</option>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) function_name (function parameters)</option>
                </term>
                <listitem>
-                       Executes a Lua function with given parameters and draws a graph. Expects result value to be an integer between 0 and 100.  See also 'lua_load' on how to load scripts.
+                       Executes a Lua function with given parameters and draws a graph. Expects result value to be an integer between 0 and 100.  See also 'lua_load' on how to load scripts.  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
        <varlistentry>
                <term>
                        <command><option>upspeedgraph</option></command>
-                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (net)</option>
+                       <option>("normal"|"log") (height),(width) (gradient colour 1) (gradient colour 2) (scale) (-t) (net)</option>
                </term>
                <listitem>
-                       Upload speed graph, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".
+                       Upload speed graph, colours defined in hex, minus the #.  If scale is non-zero, it becomes the scale for the graph. Uses a logarithmic scale (to see small numbers) when you use "log" instead of "normal".  Takes the switch '-t' to use a temperature gradient, which makes the gradient values change depending on the amplitude of a particular graph value (try it and see).
                        <para></para></listitem>
        </varlistentry>
 
index a50f840..235e62d 100644 (file)
@@ -88,8 +88,8 @@ unsigned int adjust_colors(unsigned int color)
 }
 
 /* this function returns the next colour between two colours for a gradient */
-unsigned long do_gradient(unsigned long first_colour,
-               unsigned long last_colour)
+unsigned long do_gradient(const unsigned long first_colour,
+               const unsigned long last_colour)
 {
        int tmp_color = 0;
        int red1, green1, blue1;                                // first colour
index e66d730..fda53bd 100644 (file)
@@ -707,22 +707,22 @@ static void free_text_objects(struct text_object *root, int internal)
                                free(data.local_mail.box);
                                break;
                        case OBJ_imap_unseen:
-                               if (!obj->global_mode) {
+                               if (!obj->char_b) {
                                        free(data.mail);
                                }
                                break;
                        case OBJ_imap_messages:
-                               if (!obj->global_mode) {
+                               if (!obj->char_b) {
                                        free(data.mail);
                                }
                                break;
                        case OBJ_pop3_unseen:
-                               if (!obj->global_mode) {
+                               if (!obj->char_b) {
                                        free(data.mail);
                                }
                                break;
                        case OBJ_pop3_used:
-                               if (!obj->global_mode) {
+                               if (!obj->char_b) {
                                        free(data.mail);
                                }
                                break;
@@ -1465,11 +1465,11 @@ static struct text_object *construct_text_object(const char *s,
        END OBJ(cpugraph, INFO_CPU)
                SCAN_CPU(arg, obj->data.cpu_index);
                scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                       &obj->e, &obj->showaslog);
+                       &obj->e, &obj->char_a, &obj->char_b);
                DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
        END OBJ(loadgraph, INFO_LOADAVG)
                char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                               &obj->e, &obj->showaslog);
+                               &obj->e, &obj->char_a, &obj->char_b);
                if (buf) {
                        int a = 1, r = 3;
                        if (arg) {
@@ -1488,21 +1488,21 @@ static struct text_object *construct_text_object(const char *s,
 #ifdef X11
        END OBJ(diskiograph, INFO_DISKIO)
                char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                       &obj->e, &obj->showaslog);
+                               &obj->e, &obj->char_a, &obj->char_b);
 
                obj->data.diskio = prepare_diskio_stat(dev_name(buf));
                if (buf)
                        free(buf);
        END OBJ(diskiograph_read, INFO_DISKIO)
                char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                       &obj->e, &obj->showaslog);
+                               &obj->e, &obj->char_a, &obj->char_b);
 
                obj->data.diskio = prepare_diskio_stat(dev_name(buf));
                if (buf)
                        free(buf);
        END OBJ(diskiograph_write, INFO_DISKIO)
                char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                       &obj->e, &obj->showaslog);
+                               &obj->e, &obj->char_a, &obj->char_b);
 
                obj->data.diskio = prepare_diskio_stat(dev_name(buf));
                if (buf)
@@ -1556,7 +1556,7 @@ static struct text_object *construct_text_object(const char *s,
 #ifdef X11
        END OBJ(downspeedgraph, INFO_NET)
                char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                       &obj->e, &obj->showaslog);
+                               &obj->e, &obj->char_a, &obj->char_b);
 
                // default to DEFAULTNETDEV
                buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
@@ -2220,7 +2220,7 @@ static struct text_object *construct_text_object(const char *s,
                scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
        END OBJ(memgraph, INFO_MEM)
                char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                       &obj->e, &obj->showaslog);
+                               &obj->e, &obj->char_a, &obj->char_b);
 
                if (buf) {
                        free(buf);
@@ -2372,7 +2372,7 @@ static struct text_object *construct_text_object(const char *s,
 #ifdef X11
        END OBJ(upspeedgraph, INFO_NET)
                char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                       &obj->e, &obj->showaslog);
+                               &obj->e, &obj->char_a, &obj->char_b);
 
                // default to DEFAULTNETDEV
                buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
@@ -2403,33 +2403,33 @@ static struct text_object *construct_text_object(const char *s,
                if (arg) {
                        // proccss
                        obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
-                       obj->global_mode = 0;
+                       obj->char_b = 0;
                } else {
-                       obj->global_mode = 1;
+                       obj->char_b = 1;
                }
        END OBJ_THREAD(imap_messages, 0)
                if (arg) {
                        // proccss
                        obj->data.mail = parse_mail_args(IMAP_TYPE, arg);
-                       obj->global_mode = 0;
+                       obj->char_b = 0;
                } else {
-                       obj->global_mode = 1;
+                       obj->char_b = 1;
                }
        END OBJ_THREAD(pop3_unseen, 0)
                if (arg) {
                        // proccss
                        obj->data.mail = parse_mail_args(POP3_TYPE, arg);
-                       obj->global_mode = 0;
+                       obj->char_b = 0;
                } else {
-                       obj->global_mode = 1;
+                       obj->char_b = 1;
                }
        END OBJ_THREAD(pop3_used, 0)
                if (arg) {
                        // proccss
                        obj->data.mail = parse_mail_args(POP3_TYPE, arg);
-                       obj->global_mode = 0;
+                       obj->char_b = 0;
                } else {
-                       obj->global_mode = 1;
+                       obj->char_b = 1;
                }
 #ifdef IBM
        END OBJ(smapi, 0)
@@ -2668,7 +2668,7 @@ static struct text_object *construct_text_object(const char *s,
        END OBJ(lua_graph, 0)
                if (arg) {
                        arg = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
-                                       &obj->e, &obj->showaslog);
+                                       &obj->e, &obj->char_a, &obj->char_b);
                        if (arg) {
                                obj->data.s = strndup(arg, text_buffer_size);
                        } else {
@@ -2803,7 +2803,8 @@ static struct text_object *construct_text_object(const char *s,
                        END OBJ(apcupsd_loadbar, INFO_APCUPSD)
                                scan_bar(arg, &obj->a, &obj->b);
                        END OBJ(apcupsd_loadgraph, INFO_APCUPSD)
-                               char* buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e, &obj->showaslog);
+                               char* buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
+                                               &obj->e, &obj->char_a, &obj->char_b);
                                if (buf) free(buf);
                        END OBJ(apcupsd_loadgauge, INFO_APCUPSD)
                                scan_gauge(arg, &obj->a, &obj->b);
@@ -3236,7 +3237,7 @@ int parse_conky_vars(struct text_object *root, char *txt, char *p, struct inform
 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
                void *thread(void *), const char *text)
 {
-       if (obj->global_mode && info.mail) {
+       if (obj->char_b && info.mail) {
                // this means we use info
                if (!info.mail->p_timed_thread) {
                        info.mail->p_timed_thread =
@@ -3563,11 +3564,11 @@ static void generate_text_internal(char *p, int p_max_size,
                        OBJ(cpugraph) {
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
                                                round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
-                                               100, 1, obj->showaslog);
+                                               100, 1, obj->char_a, obj->char_b);
                        }
                        OBJ(loadgraph) {
                                new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
-                                               obj->e, 1, obj->showaslog);
+                                               obj->e, 1, obj->char_a, obj->char_b);
                        }
                        OBJ(color) {
                                new_fg(p, obj->data.l);
@@ -3779,15 +3780,15 @@ static void generate_text_internal(char *p, int p_max_size,
 #ifdef X11
                        OBJ(diskiograph) {
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
-                                         obj->data.diskio->current, obj->e, 1, obj->showaslog);
+                                         obj->data.diskio->current, obj->e, 1, obj->char_a, obj->char_b);
                        }
                        OBJ(diskiograph_read) {
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
-                                         obj->data.diskio->current_read, obj->e, 1, obj->showaslog);
+                                         obj->data.diskio->current_read, obj->e, 1, obj->char_a, obj->char_b);
                        }
                        OBJ(diskiograph_write) {
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
-                                         obj->data.diskio->current_write, obj->e, 1, obj->showaslog);
+                                         obj->data.diskio->current_write, obj->e, 1, obj->char_a, obj->char_b);
                        }
 #endif
                        OBJ(downspeed) {
@@ -3800,7 +3801,7 @@ static void generate_text_internal(char *p, int p_max_size,
 #ifdef X11
                        OBJ(downspeedgraph) {
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
-                                       obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->showaslog);
+                                       obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
                        }
 #endif
                        OBJ(else) {
@@ -3928,21 +3929,26 @@ static void generate_text_internal(char *p, int p_max_size,
 #ifdef X11
                        OBJ(execgraph) {
                                char showaslog = FALSE;
+                               char tempgrad = FALSE;
                                double barnum;
+                               char *cmd = obj->data.s;
 
-                               if(strncasecmp(obj->data.s, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
+                               if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
                                        showaslog = TRUE;
-                                       read_exec(obj->data.s + strlen(LOGGRAPH" ") * sizeof(char), p, text_buffer_size);
+                                       cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
                                } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
-                                       read_exec(obj->data.s + strlen(NORMGRAPH" ") * sizeof(char), p, text_buffer_size);
-                               } else {
-                                       read_exec(obj->data.s, p, text_buffer_size);
+                                       cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
+                               }
+                               if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
+                                       tempgrad = TRUE;
+                                       cmd += strlen(" "TEMPGRAD);
                                }
+                               read_exec(cmd, p, text_buffer_size);
                                barnum = get_barnum(p);
 
                                if (barnum >= 0.0) {
                                        new_graph(p, obj->a, obj->b, obj->c, obj->d, round_to_int(barnum),
-                                               100, 1, showaslog);
+                                                       100, 1, showaslog, tempgrad);
                                }
                        }
                        OBJ(execibar) {
@@ -3964,8 +3970,23 @@ static void generate_text_internal(char *p, int p_max_size,
                                if (current_update_time - obj->data.execi.last_update
                                                >= obj->data.execi.interval) {
                                        double barnum;
-
-                                       read_exec(obj->data.execi.cmd, p, text_buffer_size);
+                                       char showaslog = FALSE;
+                                       char tempgrad = FALSE;
+                                       char *cmd = obj->data.execi.cmd;
+
+                                       if (strncasecmp(obj->data.execi.cmd, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
+                                               showaslog = TRUE;
+                                               cmd = cmd + strlen(LOGGRAPH" ") * sizeof(char);
+                                       } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
+                                               cmd = cmd + strlen(NORMGRAPH" ") * sizeof(char);
+                                       }
+                                       if (strstr(cmd, " "TEMPGRAD) && strlen(cmd) > strlen(" "TEMPGRAD)) {
+                                               tempgrad = TRUE;
+                                               cmd += strlen(" "TEMPGRAD);
+                                       }
+                                       obj->char_a = showaslog;
+                                       obj->char_b = tempgrad;
+                                       read_exec(cmd, p, text_buffer_size);
                                        barnum = get_barnum(p);
 
                                        if (barnum >= 0.0) {
@@ -3973,7 +3994,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                        }
                                        obj->data.execi.last_update = current_update_time;
                                }
-                               new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, FALSE);
+                               new_graph(p, obj->a, obj->b, obj->c, obj->d, (int) (obj->f), 100, 1, obj->char_a, obj->char_b);
                        }
                        OBJ(execigauge) {
                                if (current_update_time - obj->data.execi.last_update
@@ -4331,7 +4352,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                int per;
                                if (llua_getinteger(obj->data.s, &per)) {
                                        new_graph(p, obj->a, obj->b, obj->c, obj->d,
-                                                       (per/100.0 * 255), 100, 1, obj->showaslog);
+                                                       (per/100.0 * 255), 100, 1, obj->char_a, obj->char_b);
                                }
                        }
                        OBJ(lua_gauge) {
@@ -4527,7 +4548,7 @@ static void generate_text_internal(char *p, int p_max_size,
                        OBJ(memgraph) {
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
                                        cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
-                                       100, 1, obj->showaslog);
+                                       100, 1, obj->char_a, obj->char_b);
                        }
 #endif
                        /* mixer stuff */
@@ -4738,7 +4759,7 @@ static void generate_text_internal(char *p, int p_max_size,
 #ifdef X11
                        OBJ(upspeedgraph) {
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
-                                       obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->showaslog);
+                                       obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->char_a, obj->char_b);
                        }
 #endif
                        OBJ(uptime_short) {
@@ -5428,7 +5449,7 @@ static void generate_text_internal(char *p, int p_max_size,
                                double progress;
                                progress =      atof(cur->apcupsd.items[APCUPSD_LOAD]);
                                new_graph(p, obj->a, obj->b, obj->c, obj->d,
-                                                 (int)progress, 100, 1, obj->showaslog);
+                                                 (int)progress, 100, 1, obj->char_a, obj->char_b);
                        }
                        OBJ(apcupsd_loadgauge) {
                                double progress;
@@ -6041,11 +6062,9 @@ static void draw_line(char *s)
                                case GRAPH:
                                {
                                        int h, by, i, j = 0;
-                                       int gradient_size = 0;
-                                       float gradient_factor = 0;
-                                       float gradient_update = 0;
+                                       int colour_idx = 0;
                                        unsigned long last_colour = current_color;
-                                       unsigned long tmpcolour = current_color;
+                                       unsigned long *tmpcolour = 0;
                                        if (cur_x - text_start_x > maximum_width
                                                        && maximum_width > 0) {
                                                break;
@@ -6074,21 +6093,34 @@ static void draw_line(char *s)
 
                                        if (specials[special_index].last_colour != 0
                                                        || specials[special_index].first_colour != 0) {
-                                               tmpcolour = specials[special_index].last_colour;
-                                               gradient_size =
+                                               float gradient_factor, gradient_update = 0;
+                                               int gradient_size =
                                                        gradient_max(specials[special_index].last_colour,
-                                                       specials[special_index].first_colour);
-                                               gradient_factor = (float) gradient_size / (w - 2);
+                                                                       specials[special_index].first_colour);
+                                               gradient_factor = (float) gradient_size / (w - 1);
+                                               tmpcolour = malloc((w - 1) * sizeof(unsigned long));
+                                               tmpcolour[0] = specials[special_index].last_colour;
+                                               gradient_update += gradient_factor;
+                                               for (colour_idx = 1; colour_idx < w - 1; colour_idx++) {
+                                                       tmpcolour[colour_idx] = tmpcolour[colour_idx - 1];
+                                                       gradient_update += gradient_factor;
+                                                       while (gradient_update > 0) {
+                                                               tmpcolour[colour_idx] = do_gradient(tmpcolour[colour_idx],
+                                                                               specials[special_index].first_colour);
+                                                               gradient_update--;
+                                                       }
+                                               }
                                        }
+                                       colour_idx = 0;
                                        for (i = w - 2; i > -1; i--) {
                                                if (specials[special_index].last_colour != 0
                                                                || specials[special_index].first_colour != 0) {
-                                                       XSetForeground(display, window.gc, tmpcolour);
-                                                       gradient_update += gradient_factor;
-                                                       while (gradient_update > 0) {
-                                                               tmpcolour = do_gradient(tmpcolour,
-                                                                       specials[special_index].first_colour);
-                                                               gradient_update--;
+                                                       if (specials[special_index].tempgrad) {
+                                                               XSetForeground(display, window.gc, tmpcolour[
+                                                                               (int)((float)(w - 1) - specials[special_index].graph[j] *
+                                                                                (w - 2) / (float)specials[special_index].graph_scale) - 1]);
+                                                       } else {
+                                                               XSetForeground(display, window.gc, tmpcolour[colour_idx++]);
                                                        }
                                                }
                                                if ((w - i) / ((float) (w - 2) /
@@ -6102,6 +6134,7 @@ static void draw_line(char *s)
                                                        by + h - specials[special_index].graph[j] *
                                                        (h - 1) / specials[special_index].graph_scale);
                                        }
+                                       if (tmpcolour) free(tmpcolour);
                                        if (h > cur_y_add
                                                        && h > font_h) {
                                                cur_y_add = h;
index 5c45f1c..26b87dc 100644 (file)
@@ -103,7 +103,7 @@ char *scan_font(const char *args)
 
 char *scan_graph(const char *args, int *w, int *h,
                  unsigned int *first_colour, unsigned int *last_colour,
-                 unsigned int *scale, char *showaslog)
+                 unsigned int *scale, char *showaslog, char *tempgrad)
 {
        const char *nographtype;
        char buf[64];
@@ -115,24 +115,28 @@ char *scan_graph(const char *args, int *w, int *h,
        *first_colour = 0;
        *last_colour = 0;
        *scale = 0;
+       *tempgrad = FALSE;
        if (args) {
-               //set showaslog and place the rest of the args in nographtype
-               if(strcasecmp(args, LOGGRAPH) == EQUAL) {
+               // set showaslog and place the rest of the args in nographtype
+               if (strcasecmp(args, LOGGRAPH) == EQUAL) {
                        *showaslog = TRUE;
                        return NULL;
-               }else if(strcasecmp(args, NORMGRAPH) == EQUAL) {
+               } else if (strcasecmp(args, NORMGRAPH) == EQUAL) {
                        *showaslog = FALSE;
                        return NULL;
-               }else if(strncasecmp(args, LOGGRAPH" ", strlen(LOGGRAPH) + 1 ) == EQUAL) {
+               } else if (strncasecmp(args, LOGGRAPH" ", strlen(LOGGRAPH) + 1 ) == EQUAL) {
                        *showaslog = TRUE;
                        nographtype = &args[strlen(LOGGRAPH) + 1];
-               }else if(strncasecmp(args, NORMGRAPH" ", strlen(NORMGRAPH) + 1 ) == EQUAL) {
+               } else if (strncasecmp(args, NORMGRAPH" ", strlen(NORMGRAPH) + 1 ) == EQUAL) {
                        *showaslog = FALSE;
                        nographtype = &args[strlen(NORMGRAPH) + 1];
-               }else{
+               } else {
                        *showaslog = FALSE;
                        nographtype = args;
                }
+               if (strstr(args, " "TEMPGRAD)) {
+                       *tempgrad = TRUE;
+               }
                DBGP("printing graph as %s, other args are: %s", (*showaslog ? "log" : "normal"), nographtype);
                //check the rest of the args
                if (sscanf(nographtype, "%d,%d %x %x %u", h, w, first_colour, last_colour, scale) == 5) {
@@ -292,7 +296,7 @@ static void graph_append(struct special_t *graph, double f, char showaslog)
 }
 
 void new_graph(char *buf, int w, int h, unsigned int first_colour,
-               unsigned int second_colour, double i, int scale, int append, char showaslog)
+               unsigned int second_colour, double i, int scale, int append, char showaslog, char tempgrad)
 {
        struct special_t *s = 0;
 
@@ -325,6 +329,7 @@ void new_graph(char *buf, int w, int h, unsigned int first_colour,
                s->graph_scale = 1;
                s->show_scale = 1;
        }
+       s->tempgrad = tempgrad;
        /* if (s->width) {
                s->graph_width = s->width - 2;  // subtract 2 for rectangle around
        } */
index 2f8d0bf..901e6eb 100644 (file)
  * and who needs that kind of precision anyway? */
 #define MAX_GRAPH_DEPTH 256
 
-//don't use spaces in LOGGRAPH or NORMGRAPH if you change them
+// don't use spaces in LOGGRAPH or NORMGRAPH if you change them
 #define LOGGRAPH "log"
 #define NORMGRAPH "normal"
+#define TEMPGRAD "-t"
 
 enum special_types {
        HORIZONTAL_LINE,
@@ -70,6 +71,7 @@ struct special_t {
        unsigned long first_colour;     // for graph gradient
        unsigned long last_colour;
        short font_added;
+       char tempgrad;
 };
 
 /* direct access to the registered specials (FIXME: bad encapsulation) */
@@ -94,14 +96,14 @@ const char *scan_gauge(const char *, int *, int *);
 const char *scan_bar(const char *, int *, int *);
 char *scan_font(const char *);
 char *scan_graph(const char *, int *, int *, unsigned int *,
-                 unsigned int *, unsigned int *, char *);
+                 unsigned int *, unsigned int *, char *, char *);
 
 /* printing specials */
 void new_gauge(char *, int, int, int);
 void new_bar(char *, int, int, int);
 void new_font(char *, char *);
 void new_graph(char *, int, int, unsigned int,
-               unsigned int, double, int, int, char);
+               unsigned int, double, int, int, char, char);
 void new_hr(char *, int);
 void new_stippled_hr(char *, int, int);
 #endif
index 07467e9..ea6422c 100644 (file)
@@ -570,8 +570,7 @@ struct text_object {
        long line;
        unsigned int c, d, e;
        float f;
-       char showaslog;
-       char global_mode;
+       char char_a, char_b;
 };
 
 /* text object list helpers */