diff --git a/src/rrd_graph.c b/src/rrd_graph.c
index aae131708b4cf5c483d53c72c6615180f973f3d7..41024eccc3925932b92aaf0802ceb79f248f712c 100644 (file)
--- a/src/rrd_graph.c
+++ b/src/rrd_graph.c
/****************************************************************************
- * RRDtool 1.2.23 Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.2.28 Copyright by Tobi Oetiker, 1997-2008
****************************************************************************
* rrd__graph.c produce graphs from data in rrdfiles
****************************************************************************/
{10, 0, TMT_MINUTE,5, TMT_MINUTE,20, TMT_MINUTE,20, 0,"%H:%M"},
{30, 0, TMT_MINUTE,10, TMT_HOUR,1, TMT_HOUR,1, 0,"%H:%M"},
{60, 0, TMT_MINUTE,30, TMT_HOUR,2, TMT_HOUR,2, 0,"%H:%M"},
- {60, 24*3600, TMT_MINUTE,30, TMT_HOUR,2, TMT_HOUR,4, 0,"%a %H:%M"},
+ {60, 24*3600, TMT_MINUTE,30, TMT_HOUR,2, TMT_HOUR,6, 0,"%a %H:%M"},
{180, 0, TMT_HOUR,1, TMT_HOUR,6, TMT_HOUR,6, 0,"%H:%M"},
{180, 24*3600, TMT_HOUR,1, TMT_HOUR,6, TMT_HOUR,12, 0,"%a %H:%M"},
/*{300, 0, TMT_HOUR,3, TMT_HOUR,12, TMT_HOUR,12, 12*3600,"%a %p"}, this looks silly*/
im->minval = sensiblevalues[i]*(im->magfact);
if (-sensiblevalues[i-1]<=scaled_min &&
- -sensiblevalues[i]>=scaled_min)
+ -sensiblevalues[i]>=scaled_min)
im->minval = -sensiblevalues[i-1]*(im->magfact);
if (sensiblevalues[i-1] >= scaled_max &&
double new_range = factor * (im->maxval - im->minval);
double gridstep = im->ygrid_scale.gridstep;
double minor_y, minor_y_px, minor_y_px_frac;
+
+
if (im->maxval > 0.0)
im->maxval = im->minval + new_range;
else
im->minval = im->maxval - new_range;
ytr(im,DNAN); /* reset precalc */
+
/* make sure first minor gridline is on integer pixel y coord */
minor_y = gridstep * floor(im->minval / gridstep);
while (minor_y < im->minval)
return 0;
}
+static int AlmostEqual2sComplement (float A, float B, int maxUlps)
+{
+
+ int aInt = *(int*)&A;
+ int bInt = *(int*)&B;
+ int intDiff;
+ /* Make sure maxUlps is non-negative and small enough that the
+ default NAN won't compare as equal to anything. */
+
+ /* assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024); */
+
+ /* Make aInt lexicographically ordered as a twos-complement int */
+
+ if (aInt < 0)
+ aInt = 0x80000000l - aInt;
+
+ /* Make bInt lexicographically ordered as a twos-complement int */
+
+ if (bInt < 0)
+ bInt = 0x80000000l - bInt;
+
+ intDiff = abs(aInt - bInt);
+
+ if (intDiff <= maxUlps)
+ return 1;
+
+ return 0;
+}
+
/* massage data so, that we get one value for each x coordinate in the graph */
int
data_proc( image_desc_t *im ){
im->maxval = maxval;
}
/* make sure min is smaller than max */
- if (im->minval > im->maxval) {
+ if (im->minval > im->maxval ) {
+ if (im->maxval > 0)
im->minval = 0.99 * im->maxval;
+ else
+ im->minval = 1.01 * im->maxval;
}
/* make sure min and max are not equal */
- if (im->minval == im->maxval) {
- im->maxval *= 1.01;
+ if ( AlmostEqual2sComplement(im->minval,im->maxval,4)) {
+ if (im->maxval > 0)
+ im->maxval *= 1.01;
+ else
+ im->maxval *= 0.99;
+
if (! im->logarithmic) {
- im->minval *= 0.99;
+ if (im->minval > 0)
+ im->minval *= 0.99;
+ else
+ im->minval *= 1.01;
}
/* make sure min and max are not both zero */
- if (im->maxval == 0.0) {
+ if (AlmostEqual2sComplement(im->maxval,0,4)) {
im->maxval = 1.0;
}
}
int sgrid = (int)( im->minval / im->ygrid_scale.gridstep - 1);
int egrid = (int)( im->maxval / im->ygrid_scale.gridstep + 1);
double MaxY;
+ double second_axis_magfact = 0;
+ char *second_axis_symb = "";
scaledstep = im->ygrid_scale.gridstep/(double)im->magfact*(double)im->viewfactor;
MaxY = scaledstep*(double)egrid;
for (i = sgrid; i <= egrid; i++){
double Y0=ytr(im,im->ygrid_scale.gridstep*i);
double YN=ytr(im,im->ygrid_scale.gridstep*(i+1));
- if ( round(Y0) >= im->yorigin-im->ysize
- && round(Y0) <= im->yorigin){
+ if ( floor(Y0+0.5) >= im->yorigin-im->ysize
+ && floor(Y0+0.5) <= im->yorigin){
/* Make sure at least 2 grid labels are shown, even if it doesn't agree
with the chosen settings. Add a label if required by settings, or if
there is only one label so far and the next grid line is out of bounds. */
}
}
nlabels++;
+ if (im->second_axis_scale != 0){
+ char graph_label_right[100];
+ double sval = im->ygrid_scale.gridstep*(double)i/im->second_axis_scale+im->second_axis_shift;
+ if (!second_axis_magfact){
+ double dummy = im->ygrid_scale.gridstep*(double)(sgrid+egrid)/2.0/im->second_axis_scale+im->second_axis_shift;
+ auto_scale(im,&dummy,&second_axis_symb,&second_axis_magfact);
+ }
+ sval /= second_axis_magfact;
+
+ if(MaxY < 10) {
+ sprintf(graph_label_right,"%5.1f %s",sval,second_axis_symb);
+ } else {
+ sprintf(graph_label_right,"%5.0f %s",sval,second_axis_symb);
+ }
+ gfx_new_text ( im->canvas,
+ X1+7, Y0,
+ im->graph_col[GRC_FONT],
+ im->text_prop[TEXT_PROP_AXIS].font,
+ im->text_prop[TEXT_PROP_AXIS].size,
+ im->tabwidth,0.0, GFX_H_LEFT, GFX_V_CENTER,
+ graph_label_right );
+ }
gfx_new_text ( im->canvas,
X0-im->text_prop[TEXT_PROP_AXIS].size, Y0,
return mnt;
}
-static int AlmostEqual2sComplement (float A, float B, int maxUlps)
-{
-
- int aInt = *(int*)&A;
- int bInt = *(int*)&B;
- int intDiff;
- /* Make sure maxUlps is non-negative and small enough that the
- default NAN won't compare as equal to anything. */
-
- /* assert(maxUlps > 0 && maxUlps < 4 * 1024 * 1024); */
-
- /* Make aInt lexicographically ordered as a twos-complement int */
-
- if (aInt < 0)
- aInt = 0x80000000l - aInt;
-
- /* Make bInt lexicographically ordered as a twos-complement int */
-
- if (bInt < 0)
- bInt = 0x80000000l - bInt;
-
- intDiff = abs(aInt - bInt);
-
- if (intDiff <= maxUlps)
- return 1;
-
- return 0;
-}
-
/* logaritmic horizontal grid */
int
horizontal_log_grid(image_desc_t *im)
pre_value = value;
Y0 = ytr(im, value);
- if(Y0 <= im->yorigin - im->ysize) break;
+ if(floor(Y0+0.5) <= im->yorigin - im->ysize) break;
/* major grid line */
gfx_new_dashed_line ( im->canvas,
else
symbol = '?';
- sprintf(graph_label,"%3.0f %c", pvalue, symbol);
- } else
+ sprintf(graph_label,"%3.0f %c", pvalue, symbol);
+ } else {
sprintf(graph_label,"%3.0e", value);
+ }
+ if (im->second_axis_scale != 0){
+ char graph_label_right[100];
+ if (im->extra_flags & FORCE_UNITS_SI) {
+ double sval = value/im->second_axis_scale+im->second_axis_shift;
+ double mfac = 1;
+ char *symb = "";
+ auto_scale(im,&sval,&symb,&mfac);
+ sprintf(graph_label_right,"%4.0f %s", sval,symb);
+ }
+ else {
+ sprintf(graph_label_right,"%3.0e", value/im->second_axis_scale+im->second_axis_shift);
+ }
+ gfx_new_text ( im->canvas,
+ X1+7, Y0,
+ im->graph_col[GRC_FONT],
+ im->text_prop[TEXT_PROP_AXIS].font,
+ im->text_prop[TEXT_PROP_AXIS].size,
+ im->tabwidth,0.0, GFX_H_LEFT, GFX_V_CENTER,
+ graph_label_right );
+ }
+
gfx_new_text ( im->canvas,
- X0-im->text_prop[TEXT_PROP_AXIS].size, Y0,
- im->graph_col[GRC_FONT],
- im->text_prop[TEXT_PROP_AXIS].font,
- im->text_prop[TEXT_PROP_AXIS].size,
- im->tabwidth,0.0, GFX_H_RIGHT, GFX_V_CENTER,
- graph_label );
+ X0-im->text_prop[TEXT_PROP_AXIS].size, Y0,
+ im->graph_col[GRC_FONT],
+ im->text_prop[TEXT_PROP_AXIS].font,
+ im->text_prop[TEXT_PROP_AXIS].size,
+ im->tabwidth,0.0, GFX_H_RIGHT, GFX_V_CENTER,
+ graph_label );
/* minor grid */
if(mid < 4 && exfrac == 1) {
if(value < im->minval) continue;
Y0 = ytr(im, value);
- if(Y0 <= im->yorigin - im->ysize) break;
+ if(floor(Y0+0.5) <= im->yorigin - im->ysize) break;
/* draw lines */
gfx_new_dashed_line ( im->canvas,
if(value < im->minval) continue;
Y0 = ytr(im, value);
- if(Y0 <= im->yorigin - im->ysize) break;
+ if(floor(Y0+0.5) <= im->yorigin - im->ysize) break;
/* draw lines */
gfx_new_dashed_line ( im->canvas,
if(value < im->minval) continue;
Y0 = ytr(im, value);
- if(Y0 <= im->yorigin - im->ysize) break;
+ if(floor(Y0+0.5) <= im->yorigin - im->ysize) break;
/* draw lines */
gfx_new_dashed_line ( im->canvas,
if(value < im->minval) continue;
Y0 = ytr(im, value);
- if(Y0 <= im->yorigin - im->ysize) break;
+ if(floor(Y0+0.5) <= im->yorigin - im->ysize) break;
/* draw lines */
gfx_new_dashed_line ( im->canvas,
im->xorigin+0.5, im->yorigin-im->ysize-7, /* LINEOFFSET */
im->graph_col[GRC_ARROW]);
+ if (im->second_axis_scale != 0){
+ gfx_new_line ( im->canvas, im->xorigin+im->xsize,im->yorigin+4,
+ im->xorigin+im->xsize,im->yorigin-im->ysize-4,
+ MGRIDWIDTH, im->graph_col[GRC_AXIS]);
+ gfx_new_area ( im->canvas,
+ im->xorigin+im->xsize-2, im->yorigin-im->ysize-2,
+ im->xorigin+im->xsize+3, im->yorigin-im->ysize-2,
+ im->xorigin+im->xsize+0.5, im->yorigin-im->ysize-7, /* LINEOFFSET */
+ im->graph_col[GRC_ARROW]);
+ }
}
void
}
/* yaxis unit description */
- gfx_new_text( im->canvas,
+ if (im->ylegend[0] != '\0'){
+ gfx_new_text( im->canvas,
10, (im->yorigin - im->ysize/2),
im->graph_col[GRC_FONT],
im->text_prop[TEXT_PROP_UNIT].font,
RRDGRAPH_YLEGEND_ANGLE,
GFX_H_LEFT, GFX_V_CENTER,
im->ylegend);
-
+ }
+ if (im->second_axis_legend[0] != '\0'){
+ double Xylabel=gfx_get_text_width(im->canvas, 0,
+ im->text_prop[TEXT_PROP_AXIS].font,
+ im->text_prop[TEXT_PROP_AXIS].size,
+ im->tabwidth,
+ "0", 0) * im->unitslength
+ + im->text_prop[TEXT_PROP_UNIT].size *2;
+ gfx_new_text( im->canvas,
+ im->xorigin+im->xsize+Xylabel+4, (im->yorigin - im->ysize/2),
+ im->graph_col[GRC_FONT],
+ im->text_prop[TEXT_PROP_UNIT].font,
+ im->text_prop[TEXT_PROP_UNIT].size, im->tabwidth,
+ RRDGRAPH_YLEGEND_ANGLE,
+ GFX_H_LEFT, GFX_V_CENTER,
+ im->second_axis_legend);
+ }
/* graph title */
gfx_new_text( im->canvas,
im->ximg/2, im->text_prop[TEXT_PROP_TITLE].size*1.3+4,
GFX_H_CENTER, GFX_V_CENTER,
im->title);
/* rrdtool 'logo' */
- gfx_new_text( im->canvas,
+ if (!(im->extra_flags & NO_RRDTOOL_TAG)){
+ gfx_new_text( im->canvas,
im->ximg-7, 7,
( im->graph_col[GRC_FONT] & 0xffffff00 ) | 0x00000044,
im->text_prop[TEXT_PROP_AXIS].font,
5.5, im->tabwidth, 270,
GFX_H_RIGHT, GFX_V_TOP,
"RRDTOOL / TOBI OETIKER");
-
+ }
/* graph watermark */
if(im->watermark[0] != '\0') {
gfx_new_text( im->canvas,
*/
im->ximg = Xylabel + Xmain + 2 * Xspacing;
+ if (im->second_axis_scale != 0){
+ im->ximg += Xylabel + Xspacing;
+ }
+ if (im->extra_flags & NO_RRDTOOL_TAG){
+ im->ximg -= Xspacing;
+ }
+
#ifdef WITH_PIECHART
im->ximg += Xpie;
#endif
im->ximg += Xvertical;
im->xorigin += Xvertical;
}
+ if (im->second_axis_legend[0] != '\0' ) {
+ im->ximg += Xvertical;
+ }
+
xtr(im,0);
/* The vertical size is interesting... we need to compare
im->ysize = 100;
im->step = 0;
im->ylegend[0] = '\0';
+ im->second_axis_scale = 0; /* 0 disables it */
+ im->second_axis_shift = 0; /* no shift by default */
+ im->second_axis_legend[0] = '\0';
im->title[0] = '\0';
im->watermark[0] = '\0';
im->minval = DNAN;
{"font-smoothing-threshold", required_argument, 0, 'B'},
{"watermark", required_argument, 0, 'W'},
{"alt-y-mrtg", no_argument, 0, 1000}, /* this has no effect it is just here to save old apps from crashing when they use it */
+ {"disable-rrdtool-tag", no_argument, 0, 1001},
+ {"right-axis", required_argument, 0, 1002},
+ {"right-axis-label", required_argument, 0, 1003},
{0,0,0,0}};
int option_index = 0;
int opt;
case 'F':
im->extra_flags |= FORCE_RULES_LEGEND;
break;
+ case 1001:
+ im->extra_flags |= NO_RRDTOOL_TAG;
+ break;
case LONGOPT_UNITS_SI:
if(im->extra_flags & FORCE_UNITS) {
rrd_set_error("--units can only be used once!");
return;
}
break;
+ case 1002: /* right y axis */
+
+ if(sscanf(optarg,
+ "%lf:%lf",
+ &im->second_axis_scale,
+ &im->second_axis_shift) == 2) {
+ if(im->second_axis_scale==0){
+ rrd_set_error("the second_axis_scale must not be 0");
+ return;
+ }
+ } else {
+ rrd_set_error("invalid right-axis format expected scale:shift");
+ return;
+ }
+ break;
+ case 1003:
+ strncpy(im->second_axis_legend,optarg,150);
+ im->second_axis_legend[150]='\0';
+ break;
case 'v':
strncpy(im->ylegend,optarg,150);
im->ylegend[150]='\0';
case 'n':{
char prop[15];
double size = 1;
- char font[1024] = "";
-
+ int end;
if(sscanf(optarg,
- "%10[A-Z]:%lf:%1000s",
- prop,&size,font) >= 2){
+ "%10[A-Z]:%lf%n",
+ prop,&size,&end) >= 2){
int sindex,propidx;
if((sindex=text_prop_conv(prop)) != -1){
for (propidx=sindex;propidx<TEXT_PROP_LAST;propidx++){
if (size > 0){
im->text_prop[propidx].size=size;
+ }
+ if ((int)strlen(optarg) > end){
+ if (optarg[end] == ':'){
+ strncpy(im->text_prop[propidx].font,optarg+end+1,255);
+ im->text_prop[propidx].font[255] = '\0';
+ } else {
+ rrd_set_error("expected : after font size in '%s'",optarg);
+ return;
+ }
}
- if (strlen(font) > 0){
- strcpy(im->text_prop[propidx].font,font);
- }
+ /* only run the for loop for DEFAULT (0) for
+ all others, we break here. woodo programming */
if (propidx==sindex && sindex != 0) break;
}
} else {
src = &im->gdes[dst->vidx];
data = src->data + src->ds;
steps = (src->end - src->start) / src->step;
-
#if 0
printf("DEBUG: start == %lu, end == %lu, %lu steps\n"
,src->start