]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Add --left-axis-format option to control labels on y-axis of graph.
authorAutoAquaria <james@autoaquaria.com>
Mon, 10 Feb 2014 17:18:56 +0000 (11:18 -0600)
committerTobias Oetiker <tobi@oetiker.ch>
Mon, 10 Feb 2014 21:37:50 +0000 (22:37 +0100)
Conflicts:

src/rrd_graph.c

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

index d4ff48e328f0abd937387503899fcdad0c1eac05..90962e2ad5881dd4dff99356716b905e7785a2c3 100644 (file)
@@ -213,6 +213,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 12033e6d4ddd1951fbee324ad0b67918f4875c2f..0bc5dbdbe5c0d2a4995cf0dbc83db2f22fc48a1f 100644 (file)
@@ -2087,34 +2087,43 @@ int draw_horizontal_grid(
                 || (nlabels == 1
                     && (YN < im->yorigin - im->ysize || YN > im->yorigin))) {
                 if (im->symbol == ' ') {
-                    if (im->extra_flags & ALTYGRID) {
-                        snprintf(graph_label, sizeof graph_label,
-                                im->ygrid_scale.labfmt,
-                                scaledstep * (double) i);
-                    } else {
-                        if (MaxY < 10) {
-                            snprintf(graph_label, sizeof graph_label, "%4.1f",
+                    if (im->primary_axis_format[0] == '\0'){
+                        if (im->extra_flags & ALTYGRID) {
+                            snprintf(graph_label, sizeof graph_label,
+                                    im->ygrid_scale.labfmt,
                                     scaledstep * (double) i);
                         } else {
-                            snprintf(graph_label, sizeof graph_label, "%4.0f",
-                                    scaledstep * (double) i);
+                            if (MaxY < 10) {
+                                snprintf(graph_label, sizeof graph_label, "%4.1f",
+                                        scaledstep * (double) i);
+                            } else {
+                                snprintf(graph_label, sizeof graph_label,"%4.0f",
+                                        scaledstep * (double) i);
+                            }
                         }
+                    } else {
+                        snprintf(graph_label, sizeof graph_label, im->primary_axis_format,
+                                scaledstep * (double) i);
                     }
                 } else {
-                    char      sisym = (i == 0 ? ' ' : im->symbol);
-
-                    if (im->extra_flags & ALTYGRID) {
-                        snprintf(graph_label, sizeof graph_label,
-                                im->ygrid_scale.labfmt,
-                                scaledstep * (double) i, sisym);
-                    } else {
-                        if (MaxY < 10) {
-                            snprintf(graph_label, sizeof graph_label, "%4.1f %c",
+                    char      sisym = (i == 0 ? ' ' : im->symbol);                   
+                    if (im->primary_axis_format[0] == '\0'){
+                        if (im->extra_flags & ALTYGRID) {
+                            snprintf(graph_label,sizeof graph_label,
+                                    im->ygrid_scale.labfmt,
                                     scaledstep * (double) i, sisym);
                         } else {
-                            snprintf(graph_label, sizeof graph_label, "%4.0f %c",
-                                    scaledstep * (double) i, sisym);
+                            if (MaxY < 10) {
+                                snprintf(graph_label, sizeof graph_label,"%4.1f %c",
+                                        scaledstep * (double) i, sisym);
+                            } else {
+                                snprintf(graph_label, sizeof graph_label, "%4.0f %c",
+                                        scaledstep * (double) i, sisym);
+                            }
                         }
+                    } else {
+                        sprintf(graph_label, im->primary_axis_format,
+                                scaledstep * (double) i, sisym);
                     }
                 }
                 nlabels++;
@@ -4461,6 +4470,7 @@ void rrd_graph_options(
         { "dynamic-labels",     no_argument,       0, 1009},
         { "week-fmt",           required_argument, 0, 1010},
         { "graph-type",         required_argument, 0, 1011},
+        { "left-axis-format",   required_argument, 0, 1012},
         {  0, 0, 0, 0}
 };
 /* *INDENT-ON* */
@@ -4682,6 +4692,14 @@ void rrd_graph_options(
             strncpy(im->second_axis_format,optarg,150);
             im->second_axis_format[150]='\0';
             break;
+        case 1012:
+            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 fb1feb62596806f9876f698fe371f8be8f7b3220..6a153d974c0eb467c8a1f8e873d40ce883319607 100644 (file)
@@ -273,7 +273,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 7ad3163f6595acb0dcf482f52db193e457ab3b6c..43be961f9dd9b9715284c4ba773215ea99ce6f10 100644 (file)
@@ -136,6 +136,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"