]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Add --left-axis-format option to control labels on y-axis of graph. 439/head
authorAutoAquaria <james@autoaquaria.com>
Mon, 10 Feb 2014 17:18:56 +0000 (11:18 -0600)
committerAutoAquaria <james@autoaquaria.com>
Mon, 10 Feb 2014 17:18:56 +0000 (11:18 -0600)
doc/rrdgraph.pod
src/rrd_graph.c
src/rrd_graph.h
src/rrd_tool.c

index b38ecbdb94e77ba553eda1a18da7e7e0ff939f72..6c19c8a32e9aa60748a150bd0fc9f549abd2ea0a 100644 (file)
@@ -208,6 +208,12 @@ If you have set --y-grid to 'none' not only the labels get suppressed, also
 the space reserved for the labels is removed. You can still add space
 manually if you use the --units-length command to explicitly reserve space.
 
+[B<--left-axis-format> I<format-string>]
+
+By default the format of the axis labels gets determined automatically. If
+you want to do this your self, use this option with the same %lf arguments
+you know from the PRINT and GPRINT commands.
+
 [B<-Y>|B<--alt-y-grid>]
 
 Place the Y grid dynamically based on the graph's Y range. The algorithm
index 619550f22d2bcc206c91311dde7e9de56cacb6c5..9771535cb44f5be5dfad428cc0216760c8a8f574 100644 (file)
@@ -2057,34 +2057,44 @@ int draw_horizontal_grid(
                 || (nlabels == 1
                     && (YN < im->yorigin - im->ysize || YN > im->yorigin))) {
                 if (im->symbol == ' ') {
-                    if (im->extra_flags & ALTYGRID) {
-                        sprintf(graph_label,
-                                im->ygrid_scale.labfmt,
-                                scaledstep * (double) i);
-                    } else {
-                        if (MaxY < 10) {
-                            sprintf(graph_label, "%4.1f",
+                    if (im->primary_axis_format[0] == '\0'){
+                        if (im->extra_flags & ALTYGRID) {
+                            sprintf(graph_label,
+                                    im->ygrid_scale.labfmt,
                                     scaledstep * (double) i);
                         } else {
-                            sprintf(graph_label, "%4.0f",
-                                    scaledstep * (double) i);
+                            if (MaxY < 10) {
+                                sprintf(graph_label, "%4.1f",
+                                        scaledstep * (double) i);
+                            } else {
+                                sprintf(graph_label, "%4.0f",
+                                        scaledstep * (double) i);
+                            }
                         }
+                    } else {
+                        sprintf(graph_label, im->primary_axis_format,
+                                scaledstep * (double) i);
                     }
                 } else {
                     char      sisym = (i == 0 ? ' ' : im->symbol);
-
-                    if (im->extra_flags & ALTYGRID) {
-                        sprintf(graph_label,
-                                im->ygrid_scale.labfmt,
-                                scaledstep * (double) i, sisym);
-                    } else {
-                        if (MaxY < 10) {
-                            sprintf(graph_label, "%4.1f %c",
+                    
+                    if (im->primary_axis_format[0] == '\0'){
+                        if (im->extra_flags & ALTYGRID) {
+                            sprintf(graph_label,
+                                    im->ygrid_scale.labfmt,
                                     scaledstep * (double) i, sisym);
                         } else {
-                            sprintf(graph_label, "%4.0f %c",
-                                    scaledstep * (double) i, sisym);
+                            if (MaxY < 10) {
+                                sprintf(graph_label, "%4.1f %c",
+                                        scaledstep * (double) i, sisym);
+                            } else {
+                                sprintf(graph_label, "%4.0f %c",
+                                        scaledstep * (double) i, sisym);
+                            }
                         }
+                    } else {
+                        sprintf(graph_label, im->primary_axis_format,
+                                scaledstep * (double) i, sisym);
                     }
                 }
                 nlabels++;
@@ -4263,6 +4273,7 @@ void rrd_graph_options(
         { "border",             required_argument, 0, 1007},
         { "grid-dash",          required_argument, 0, 1008},
         { "dynamic-labels",     no_argument,       0, 1009},
+        { "left-axis-format",   required_argument, 0, 1010},
         {  0, 0, 0, 0}
 };
 /* *INDENT-ON* */
@@ -4475,6 +4486,14 @@ void rrd_graph_options(
             strncpy(im->second_axis_format,optarg,150);
             im->second_axis_format[150]='\0';
             break;
+        case 1010:
+            if (bad_format(optarg)){
+                rrd_set_error("use either %le or %lf formats");
+                return;
+            }
+            strncpy(im->primary_axis_format,optarg,150);
+            im->primary_axis_format[150]='\0';
+            break;
         case 'v':
             strncpy(im->ylegend, optarg, 150);
             im->ylegend[150] = '\0';
index 18b49a3e8a45f489c3c626dafdabef2130a7ee65..ac7f3987b22d9f2af5473bf18eadbf86757b8e13 100644 (file)
@@ -228,7 +228,7 @@ typedef struct image_desc_t {
     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 */    
-
+    char      primary_axis_format[210]; /* format for the numbers on the primary axis */
     double    ygridstep;    /* user defined step for y grid */
     int       ylabfact; /* every how many y grid shall a label be written ? */
     double    tabwidth; /* tabwdith */
index 3002d383795bee0be8b047f37a1ad3403251fb28..07316a4560eb90f3868d0ef0d5bb928a319c3d53 100644 (file)
@@ -137,6 +137,7 @@ void PrintUsage(
     const char *help_graph1 =
         N_("\t\t[-x|--x-grid x-axis grid and label]\n"
            "\t\t[-Y|--alt-y-grid] [--full-size-mode]\n"
+           "\t\t[--left-axis-format format]\n"
            "\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"