Code

added --right-axis-format option to control how the numbers get printed there
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Fri, 24 Oct 2008 09:25:49 +0000 (09:25 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Fri, 24 Oct 2008 09:25:49 +0000 (09:25 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@1630 a5681a0c-68f1-0310-ab6d-d61299d08faa

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

index 02b9a82f44e107e13ee75fb86265b2ab3f361a19..807ef4fc641551ce65dbcb27ad83bc9b75d5ae99 100644 (file)
@@ -67,16 +67,14 @@ this case, no other output is generated.
 [B<-S>|B<--step> I<seconds>]
 
 The start and end of the time series you would like to display, and which
-B<RRA> the data should come from.  Defaults are: 1 day ago until
-now, with the best possible resolution. B<Start> and B<end> can
-be specified in several formats, see
-L<rrdfetch> and L<rrdgraph_examples>.
-By default, B<rrdtool graph> calculates the width of one pixel in
-the time domain and tries to get data from an B<RRA> with that
-resolution.  With the B<step> option you can alter this behaviour.
-If you want B<rrdtool graph> to get data at a one-hour resolution
-from the B<RRD>, set B<step> to 3'600. Note: a step smaller than
-one pixel will silently be ignored.
+B<RRA> the data should come from.  Defaults are: 1 day ago until now, with
+the best possible resolution. B<Start> and B<end> can be specified in
+several formats, see L<rrdfetch> and L<rrdgraph_examples>. By default,
+B<rrdtool graph> calculates the width of one pixel in the time domain and
+tries to get data from an B<RRA> with that resolution.  With the B<step>
+option you can alter this behaviour. If you want B<rrdtool graph> to get
+data at a one-hour resolution from the B<RRD>, set B<step> to 3'600. Note: a
+step smaller than one pixel will silently be ignored.
 
 =item Labels
 
@@ -92,7 +90,14 @@ placed string at the left hand side of the graph.
 [B<--right-axis-label> I<label>]
 
 A second axis will be drawn to the right of the graph. It is tied to the
-left axis via the scale and shift parameters. You can also define a label for the right axis.
+left axis via the scale and shift parameters. You can also define a label
+for the right axis.
+
+[B<--right-axis-format> I<format-string>]
+
+By default the format of the axis lables gets determined automatically. If
+you want todo this your self, use this option with the same %lf arguments
+you know from the PRING and GPRINT commands.
 
 =item Size
 
index 41024eccc3925932b92aaf0802ceb79f248f712c..139b44558211002a476ca85ef69210bf195932e8 100644 (file)
@@ -1748,18 +1748,23 @@ int draw_horizontal_grid(image_desc_t *im)
                 nlabels++;
                 if (im->second_axis_scale != 0){
                         char graph_label_right[100];
-                        double sval = im->ygrid_scale.gridstep*(double)i/im->second_axis_scale+im->second_axis_shift;
-                        if (!second_axis_magfact){
-                                double dummy = im->ygrid_scale.gridstep*(double)(sgrid+egrid)/2.0/im->second_axis_scale+im->second_axis_shift;
+                        double sval = im->ygrid_scale.gridstep*(double)i*im->second_axis_scale+im->second_axis_shift;
+                        if (im->second_axis_format[0] == '\0'){
+                            if (!second_axis_magfact){
+                                double dummy = im->ygrid_scale.gridstep*(double)(sgrid+egrid)/2.0*im->second_axis_scale+im->second_axis_shift;
                                 auto_scale(im,&dummy,&second_axis_symb,&second_axis_magfact);
-                        }
-                        sval /= second_axis_magfact;
+                            }
+                            sval /= second_axis_magfact;
  
-                       if(MaxY < 10) { 
-                           sprintf(graph_label_right,"%5.1f %s",sval,second_axis_symb);
-                          } else {
-                           sprintf(graph_label_right,"%5.0f %s",sval,second_axis_symb);
+                            if(MaxY < 10) { 
+                                sprintf(graph_label_right,"%5.1f %s",sval,second_axis_symb);
+                            } else {
+                                sprintf(graph_label_right,"%5.0f %s",sval,second_axis_symb);
+                            }
                         }
+                        else {
+                           sprintf(graph_label_right,im->second_axis_format,sval);
+                        }        
                         gfx_new_text ( im->canvas,
                                X1+7, Y0,
                                im->graph_col[GRC_FONT],
@@ -1906,16 +1911,22 @@ horizontal_log_grid(image_desc_t   *im)
         }
         if (im->second_axis_scale != 0){
                 char graph_label_right[100];
-                if (im->extra_flags & FORCE_UNITS_SI) {
-                        double sval = value/im->second_axis_scale+im->second_axis_shift;
-                        double mfac = 1;
-                        char   *symb = "";
-                        auto_scale(im,&sval,&symb,&mfac);
-                        sprintf(graph_label_right,"%4.0f %s", sval,symb);
-                }
-                else {        
-                        sprintf(graph_label_right,"%3.0e", value/im->second_axis_scale+im->second_axis_shift);
+                double sval = value*im->second_axis_scale+im->second_axis_shift;
+                if (im->second_axis_format[0] == '\0'){
+                        if (im->extra_flags & FORCE_UNITS_SI) {
+                                double mfac = 1;
+                                char   *symb = "";
+                                auto_scale(im,&sval,&symb,&mfac);
+                                sprintf(graph_label_right,"%4.0f %s", sval,symb);
+                        }
+                        else {        
+                                sprintf(graph_label_right,"%3.0e", sval);
+                        }
                 }
+                else {
+                      sprintf(graph_label_right,im->second_axis_format,sval);
+                }    
+    
                 gfx_new_text ( im->canvas,
                                X1+7, Y0,
                                im->graph_col[GRC_FONT],
@@ -3220,6 +3231,7 @@ rrd_graph_init(image_desc_t *im)
     im->second_axis_scale = 0; /* 0 disables it */
     im->second_axis_shift = 0; /* no shift by default */
     im->second_axis_legend[0] = '\0';
+    im->second_axis_format[0] = '\0';
     im->title[0] = '\0';
     im->watermark[0] = '\0';
     im->minval = DNAN;
@@ -3349,6 +3361,7 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im)
             {"disable-rrdtool-tag", no_argument,  0,  1001},
             {"right-axis", required_argument,  0,  1002},
             {"right-axis-label", required_argument,  0,  1003},
+            {"right-axis-format", required_argument,  0,  1004},
             {0,0,0,0}};
         int option_index = 0;
         int opt;
@@ -3506,6 +3519,14 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im)
             strncpy(im->second_axis_legend,optarg,150);
             im->second_axis_legend[150]='\0';
             break;
+        case 1004:
+            if (bad_format(optarg)){
+                rrd_set_error("use either %le or %lf formats");
+                return;
+            }
+            strncpy(im->second_axis_format,optarg,150);
+            im->second_axis_format[150]='\0';
+            break;
         case 'v':
             strncpy(im->ylegend,optarg,150);
             im->ylegend[150]='\0';
index b39552a7ab8b951b67b35d023103b0fcefa145a8..56308bb8c293685f3e69303d98a7f26489d5de57 100644 (file)
@@ -169,6 +169,7 @@ typedef struct image_desc_t {
     double         second_axis_scale; /* relative to the first axis (0 to disable) */
     double         second_axis_shift; /* how much is it shifted vs the first axis */
     char           second_axis_legend[210]; /* label to put on the seond axis */
+    char           second_axis_format[210]; /* format for the numbers on the scond axis */
 
     double         ygridstep;      /* user defined step for y grid */
     int            ylabfact;       /* every how many y grid shall a label be written ? */
index bcb1d07cb8751700d4db7b7a3ccb35cee60a3ca2..45f9f93baa9a3abb2402f337efc762ba9d9f4a47 100644 (file)
@@ -100,6 +100,7 @@ void PrintUsage(char *cmd)
           "\t\t[-y|--y-grid y-axis grid and label]\n"
           "\t\t[-v|--vertical-label string] [-w|--width pixels]\n"
           "\t\t[--right-axis scale:shift] [--right-axis-label label]\n"
+          "\t\t[--right-axis-format format]\n"
           "\t\t[-h|--height pixels] [-o|--logarithmic]\n"
           "\t\t[-u|--upper-limit value] [-z|--lazy]\n"
           "\t\t[-l|--lower-limit value] [-r|--rigid]\n"