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.4.9~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac47eb3e0b46d052859ebab9286f4dc12558ab83;p=thirdparty%2Frrdtool-1.x.git Add --left-axis-format option to control labels on y-axis of graph. --- diff --git a/doc/rrdgraph.pod b/doc/rrdgraph.pod index b38ecbdb..6c19c8a3 100644 --- a/doc/rrdgraph.pod +++ b/doc/rrdgraph.pod @@ -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] + +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 619550f2..9771535c 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -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'; diff --git a/src/rrd_graph.h b/src/rrd_graph.h index 18b49a3e..ac7f3987 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -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 */ diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 3002d383..07316a45 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -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"