From: AutoAquaria Date: Mon, 10 Feb 2014 17:18:56 +0000 (-0600) Subject: Add --left-axis-format option to control labels on y-axis of graph. X-Git-Tag: v1.5.0-rc1~138 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=795227f2ad228d09d8ffb0799c764bd4c966f75e;p=thirdparty%2Frrdtool-1.x.git Add --left-axis-format option to control labels on y-axis of graph. Conflicts: src/rrd_graph.c --- diff --git a/doc/rrdgraph.pod b/doc/rrdgraph.pod index d4ff48e3..90962e2a 100644 --- a/doc/rrdgraph.pod +++ b/doc/rrdgraph.pod @@ -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] + +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 diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 12033e6d..0bc5dbdb 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -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'; diff --git a/src/rrd_graph.h b/src/rrd_graph.h index fb1feb62..6a153d97 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -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 */ diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 7ad3163f..43be961f 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -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"