summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5aad9ed)
raw | patch | inline | side by side (parent: 5aad9ed)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Thu, 27 Apr 2006 06:37:03 +0000 (06:37 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Thu, 27 Apr 2006 06:37:03 +0000 (06:37 +0000) |
program/CONTRIBUTORS | patch | blob | history | |
program/doc/rrdgraph.pod | patch | blob | history | |
program/src/rrd_graph.c | patch | blob | history | |
program/src/rrd_graph.h | patch | blob | history |
diff --git a/program/CONTRIBUTORS b/program/CONTRIBUTORS
index edfde57998b923aafe93a3c4ed77dc2ddda12743..8a47341e218ccc01819f7702f545d914e96eea74 100644 (file)
--- a/program/CONTRIBUTORS
+++ b/program/CONTRIBUTORS
Travis Brown <tebrown with csh.rit.edu>
Tuc <ttsg with ttsg.com>
Ulrich Schilling <schilling with netz.uni-essen.de> AIX
+Wim Heirman <wim.heirman elis.ugent.be> --units=si option
Wolfgang Schrimm <wschrimm with uni-hd.de> xport function
Wrolf Courtney <wrolf with wrolf.net> (HP-UX)
hendrik visage <hvisage with is.co.za>
index da2b4e6f29ac5d7e5fb42a76dcdf61bbdb6d82f1..63f5307f9d5844d11d1ebbc089520f60f42a3d5c 100644 (file)
--- a/program/doc/rrdgraph.pod
+++ b/program/doc/rrdgraph.pod
may have to use this option to make enough space once you start
fideling with the y-axis labeling.
+[B<--units=si>]
+
+With this option y-axis values on logarithmic graphs will be scaled to
+the appropriate units (k, M, etc.) instead of using exponential notation.
+Note that for linear graphs, SI notation is used by default.
+
=back
=item Miscellaneous
index e922814ee5e3ea146ef8d208716678cb97c07cce..77a401aa56cc6f782c3d29b802a5c3b89cfc5b86 100644 (file)
--- a/program/src/rrd_graph.c
+++ b/program/src/rrd_graph.c
}
-/* find SI magnitude symbol for the numbers on the y-axis*/
-void
-si_unit(
- image_desc_t *im /* image description */
-)
-{
-
- char symbol[] = {'a', /* 10e-18 Atto */
+static char si_symbol[] = {
+ 'a', /* 10e-18 Atto */
'f', /* 10e-15 Femto */
'p', /* 10e-12 Pico */
'n', /* 10e-9 Nano */
'G', /* 10e9 Giga */
'T', /* 10e12 Tera */
'P', /* 10e15 Peta */
- 'E'};/* 10e18 Exa */
+ 'E', /* 10e18 Exa */
+};
+const static int si_symbcenter = 6;
+
+/* find SI magnitude symbol for the numbers on the y-axis*/
+void
+si_unit(
+ image_desc_t *im /* image description */
+)
+{
- int symbcenter = 6;
double digits,viewdigits=0;
digits = floor( log( max( fabs(im->minval),fabs(im->maxval)))/log((double)im->base));
im->viewfactor = im->magfact / pow((double)im->base , viewdigits);
- if ( ((viewdigits+symbcenter) < sizeof(symbol)) &&
- ((viewdigits+symbcenter) >= 0) )
- im->symbol = symbol[(int)viewdigits+symbcenter];
+ if ( ((viewdigits+si_symbcenter) < sizeof(si_symbol)) &&
+ ((viewdigits+si_symbcenter) >= 0) )
+ im->symbol = si_symbol[(int)viewdigits+si_symbcenter];
else
im->symbol = '?';
}
X1+2,Y0,
MGRIDWIDTH, im->graph_col[GRC_MGRID],
im->grid_dash_on, im->grid_dash_off);
-
- sprintf(graph_label,"%3.0e",value * yloglab[majoridx][i]);
+
+ if (im->extra_flags & FORCE_UNITS_SI) {
+ double pvalue = value * yloglab[majoridx][i];
+ double scale = floor( log10( fabs(pvalue)) / 3);
+ pvalue /= pow(10, 3*scale);
+
+ char symbol;
+ if ( ((scale+si_symbcenter) < sizeof(si_symbol)) &&
+ ((scale+si_symbcenter) >= 0) )
+ symbol = si_symbol[(int)scale+si_symbcenter];
+ else
+ symbol = '?';
+
+ sprintf(graph_label,"%3.0f %c", pvalue, symbol);
+ } else
+ sprintf(graph_label,"%3.0e",value * yloglab[majoridx][i]);
+
gfx_new_text ( im->canvas,
X0-im->text_prop[TEXT_PROP_AXIS].size, Y0,
im->graph_col[GRC_FONT],
parsetime("end-24h", &start_tv);
parsetime("now", &end_tv);
+ /* defines for long options without a short equivalent. should be bytes,
+ and may not collide with (the ASCII value of) short options */
+ #define LONGOPT_UNITS_SI 255
+
while (1){
static struct option long_options[] =
{
{"no-gridfit", no_argument, 0, 'N'},
{"units-exponent",required_argument, 0, 'X'},
{"units-length",required_argument, 0, 'L'},
+ {"units", required_argument, 0, LONGOPT_UNITS_SI },
{"step", required_argument, 0, 'S'},
{"tabwidth", required_argument, 0, 'T'},
{"font-render-mode", required_argument, 0, 'R'},
case 'F':
im->extra_flags |= FORCE_RULES_LEGEND;
break;
+ case LONGOPT_UNITS_SI:
+ if(im->extra_flags & FORCE_UNITS) {
+ rrd_set_error("--units can only be used once!");
+ return;
+ }
+ if(strcmp(optarg,"si")==0)
+ im->extra_flags |= FORCE_UNITS_SI;
+ else {
+ rrd_set_error("invalid argument for --units: %s", optarg );
+ return;
+ }
+ break;
case 'X':
im->unitsexponent = atoi(optarg);
break;
index dca277f717c85e4a0e36e9fed52619a6c6d8d218..e143b7b76db57b9fe086c69232034eed741126a0 100644 (file)
--- a/program/src/rrd_graph.h
+++ b/program/src/rrd_graph.h
#define ONLY_GRAPH 0x20 /* use only graph */
#define FORCE_RULES_LEGEND 0x40 /* force printing of HRULE and VRULE legend */
+#define FORCE_UNITS 0x80 /* mask for all FORCE_UNITS_* flags */
+#define FORCE_UNITS_SI 0x80 /* force use of SI units in Y axis (no effect in linear graph, SI instead of E in log graph) */
enum tmt_en {TMT_SECOND=0,TMT_MINUTE,TMT_HOUR,TMT_DAY,
TMT_WEEK,TMT_MONTH,TMT_YEAR};