Code

watermartk feature for rrdgraph by Ronan Mullally
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 1 Apr 2006 15:36:05 +0000 (15:36 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 1 Apr 2006 15:36:05 +0000 (15:36 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@782 a5681a0c-68f1-0310-ab6d-d61299d08faa

CONTRIBUTORS
doc/rrdgraph.pod
src/rrd_graph.c
src/rrd_graph.h
src/rrd_tool.c

index 79c79ba5f508181a2fb4e9622fa6c665fc11883c..d7eb4b0523d4461420c16bef128f881e66c00998 100644 (file)
@@ -45,6 +45,7 @@ REIBENSCHUH Alfred <alfred.reibenschuh with it-austria.com> AIX
 Radoslaw Karas <rkaras with tyndall.ie>
 Rainer Bawidamann <Rainer.Bawidamann with informatik.uni-ulm.de>
 Roman Hoogant <rhoogant with ee.ethz.ch>
+Ronan Mullally <ronan in 4L.ie>
 Russ Wright <rwwright with home.com>
 Sean Summers <sean with Fenstermaker.com> (RPM .spec)
 Selena M Brewington <smbrewin with ichips.intel.com> add_ds
index b5e92b8aadfbb7721f4a1e70b39c27eb4d27c322..da2b4e6f29ac5d7e5fb42a76dcdf61bbdb6d82f1 100644 (file)
@@ -338,6 +338,11 @@ If you are graphing memory (and NOT network traffic) this switch
 should be set to 1024 so that one Kb is 1024 byte. For traffic
 measurement, 1 kb/s is 1000 b/s.
 
+[B<-W>|B<--watermark> I<string>]
+
+Adds the given string as a watermark, horizontally centred, at the bottom 
+of the graph.
+
 =item Data and variables
 
 B<DEF:>I<vname>B<=>I<rrdfile>B<:>I<ds-name>B<:>I<CF>[B<:step=>I<step>][B<:start=>I<time>][B<:end=>I<time>]
index 6fc877c1b952211631e9d796a18cb979787b06eb..a71a174a5001cc931a0013fed39a93e6d8302bc4 100644 (file)
@@ -1977,6 +1977,17 @@ grid_paint(image_desc_t   *im)
                  5.5, im->tabwidth, 270,
                  GFX_H_RIGHT, GFX_V_TOP,
                  "RRDTOOL / TOBI OETIKER");
+
+    /* graph watermark */
+    if(im->watermark[0] != '\0') {
+        gfx_new_text( im->canvas,
+                  im->ximg/2, im->yimg-6,
+                 ( im->graph_col[GRC_FONT] & 0xffffff00 ) | 0x00000044,
+                 im->text_prop[TEXT_PROP_AXIS].font,
+                 5.5, im->tabwidth, 0,
+                 GFX_H_CENTER, GFX_V_BOTTOM,
+                 im->watermark);
+    }
     
     /* graph labels */
     if( !(im->extra_flags & NOLEGEND) & !(im->extra_flags & ONLY_GRAPH) ) {
@@ -2140,6 +2151,8 @@ graph_size_location(image_desc_t *im, int elements
     ** |v+--+-------------------------------+--------+
     ** | |..............legends......................|
     ** +-+-------------------------------------------+
+    ** |                 watermark                   |
+    ** +---------------------------------------------+
     */
     int Xvertical=0,   
                        Ytitle   =0,
@@ -2152,7 +2165,9 @@ graph_size_location(image_desc_t *im, int elements
 #if 0
        Xlegend  =0,    Ylegend  =0,
 #endif
-        Xspacing =15,  Yspacing =15;
+        Xspacing =15,  Yspacing =15,
+       
+                      Ywatermark =4;
 
     if (im->extra_flags & ONLY_GRAPH) {
        im->xorigin =0;
@@ -2239,12 +2254,13 @@ graph_size_location(image_desc_t *im, int elements
     xtr(im,0);
 
     /* The vertical size is interesting... we need to compare
-    ** the sum of {Ytitle, Ymain, Yxlabel, Ylegend} with Yvertical
-    ** however we need to know {Ytitle+Ymain+Yxlabel} in order to
-    ** start even thinking about Ylegend.
+    ** the sum of {Ytitle, Ymain, Yxlabel, Ylegend, Ywatermark} with 
+    ** Yvertical however we need to know {Ytitle+Ymain+Yxlabel}
+    ** in order to start even thinking about Ylegend or Ywatermark.
     **
     ** Do it in three portions: First calculate the inner part,
-    ** then do the legend, then adjust the total height of the img.
+    ** then do the legend, then adjust the total height of the img,
+    ** adding space for a watermark if one exists;
     */
 
     /* reserve space for main and/or pie */
@@ -2273,7 +2289,10 @@ graph_size_location(image_desc_t *im, int elements
     */
     if(leg_place(im)==-1)
        return -1;
-
+       
+    if (im->watermark[0] != '\0') {
+        im->yimg += Ywatermark;
+    }
 
 #if 0
     if (Xlegend > im->ximg) {
@@ -2899,6 +2918,7 @@ rrd_graph_init(image_desc_t *im)
     im->step = 0;
     im->ylegend[0] = '\0';
     im->title[0] = '\0';
+    im->watermark[0] = '\0';
     im->minval = DNAN;
     im->maxval = DNAN;    
     im->unitsexponent= 9999;
@@ -3014,6 +3034,7 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im)
             {"tabwidth",   required_argument, 0,    'T'},            
            {"font-render-mode", required_argument, 0, 'R'},
            {"font-smoothing-threshold", required_argument, 0, 'B'},
+           {"watermark",  required_argument, 0,  'W'},
            {"alt-y-mrtg", no_argument,       0,  1000}, /* this has no effect it is just here to save old apps from crashing when they use it */
            {0,0,0,0}};
        int option_index = 0;
@@ -3021,7 +3042,7 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im)
         int col_start,col_end;
 
        opt = getopt_long(argc, argv, 
-                        "s:e:x:y:v:w:h:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMEX:L:S:T:NR:B:",
+                        "s:e:x:y:v:w:h:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMEX:L:S:T:NR:B:W:",
                          long_options, &option_index);
 
        if (opt == EOF)
@@ -3296,6 +3317,11 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im)
            im->canvas->font_aa_threshold = atof(optarg);
                break;
 
+        case 'W':
+            strncpy(im->watermark,optarg,100);
+            im->watermark[99]='\0';
+            break;
+
        case '?':
             if (optopt != 0)
                 rrd_set_error("unknown option '%c'", optopt);
index d0482b592f9b7329f914258bb559fe38cbb6715c..dca277f717c85e4a0e36e9fed52619a6c6d8d218 100644 (file)
@@ -154,6 +154,7 @@ typedef struct image_desc_t {
     text_prop_t    text_prop[TEXT_PROP_LAST]; /* text properties */
     char           ylegend[200];   /* legend along the yaxis */
     char           title[200];     /* title for graph */
+    char           watermark[100];   /* watermark for graph */
     int            draw_x_grid;      /* no x-grid at all */
     int            draw_y_grid;      /* no x-grid at all */
     double         grid_dash_on, grid_dash_off;
index 23344312868e6810c08047b2774f5ecde562c3b9..dd3f0f9197e1b266bfdbfad6a9103c91c39a68bc 100644 (file)
@@ -114,9 +114,10 @@ void PrintUsage(char *cmd)
           "\t\t[-f|--imginfo printfstr]\n"
           "\t\t[-a|--imgformat PNG]\n"
           "\t\t[-c|--color COLORTAG#rrggbb[aa]] [-t|--title string]\n"
-          "\t\t[DEF:vname=rrd:ds-name:CF]\n"
-          "\t\t[CDEF:vname=rpn-expression]\n";
+          "\t\t[-W|--watermark string]\n"
+          "\t\t[DEF:vname=rrd:ds-name:CF]\n";
     char help_graph3[] =
+          "\t\t[CDEF:vname=rpn-expression]\n"
           "\t\t[VDEF:vdefname=rpn-expression]\n"
           "\t\t[PRINT:vdefname:format]\n"
           "\t\t[GPRINT:vdefname:format]\n"