--- rrdtool-1.3.7.orig/src/rrd_graph.c 2009-04-07 09:31:53.000000000 +0200 +++ rrdtool-1.3.7/src/rrd_graph.c 2009-04-09 11:08:37.000000000 +0200 @@ -2546,6 +2546,8 @@ long i; int res = 0; double X0, Y0; /* points for filled graph and more */ + int j = 0; + imgtitle_t myimgtitle_t; struct gfx_color_t water_color; /* draw 3d border */ @@ -2617,13 +2619,17 @@ } /* graph title */ - gfx_text(im, - im->ximg / 2, 6, - im->graph_col[GRC_FONT], - im-> - text_prop[TEXT_PROP_TITLE]. - font_desc, - im->tabwidth, 0.0, GFX_H_CENTER, GFX_V_TOP, im->title); + myimgtitle_t = split_graphtitle(im->title); + while(myimgtitle_t.pieces[j] != NULL) { + gfx_text(im, + im->ximg / 2, (im->text_prop[TEXT_PROP_TITLE].size * 1.3) + (im->text_prop[TEXT_PROP_TITLE].size * 1.6 * j), + im->graph_col[GRC_FONT], + im-> + text_prop[TEXT_PROP_TITLE]. + font_desc, + im->tabwidth, 0.0, GFX_H_CENTER, GFX_V_CENTER, myimgtitle_t.pieces[j]); + j++; + } /* rrdtool 'logo' */ if (!(im->extra_flags & NO_RRDTOOL_TAG)){ water_color = im->graph_col[GRC_FONT]; @@ -2777,6 +2783,8 @@ 0, Xylabel = 0, Xmain = 0, Ymain = 0, Yxlabel = 0, Xspacing = 15, Yspacing = 15, Ywatermark = 4; + imgtitle_t myimgtitle_t; + if (im->extra_flags & ONLY_GRAPH) { im->xorigin = 0; im->ximg = im->xsize; @@ -2816,7 +2824,8 @@ ** spacing is added here, on each side. */ /* if necessary, reduce the font size of the title until it fits the image width */ - Ytitle = im->text_prop[TEXT_PROP_TITLE].size * 2.6 + 10; + myimgtitle_t = split_graphtitle(im->title); + Ytitle = im->text_prop[TEXT_PROP_TITLE].size * (myimgtitle_t.count + 1) * 1.6; } if (elements) { @@ -2928,7 +2937,8 @@ im->text_prop[TEXT_PROP_TITLE].font_desc, im->tabwidth, im->title, 0) + 2*Xspacing; */ - Ytitle = im->text_prop[TEXT_PROP_TITLE].size * 2.6 + 10; + myimgtitle_t = split_graphtitle(im->title); + Ytitle = im->text_prop[TEXT_PROP_TITLE].size * (myimgtitle_t.count + 1) * 1.6; } if (elements) { @@ -4839,3 +4849,26 @@ im->grinfo = im->grinfo_current; } } + +imgtitle_t split_graphtitle( + char *input) +{ + imgtitle_t retval; + char *str; + int count = 0; + char delim = '?'; + + str = strdup(input); + + retval.pieces = malloc((MAX_IMGTITLE_NEWLINES + 1 ) * sizeof(char *)); + + retval.pieces[count] = strtok (str, &delim); + while ( retval.pieces[count] != NULL && count++ < MAX_IMGTITLE_NEWLINES) + { + retval.pieces[count] = strtok( NULL, &delim); + } + retval.pieces[count] = NULL; + retval.count = count; + + return retval; +} --- rrdtool-1.3.7.orig/src/rrd_graph.h 2008-12-26 09:05:03.000000000 +0100 +++ rrdtool-1.3.7/src/rrd_graph.h 2009-04-09 09:23:02.000000000 +0200 @@ -39,6 +39,8 @@ #define FULL_SIZE_MODE 0x200 /* -width and -height indicate the total size of the image */ #define NO_RRDTOOL_TAG 0x400 /* disable the rrdtool tag */ +#define MAX_IMGTITLE_NEWLINES 5 + enum tmt_en { TMT_SECOND = 0, TMT_MINUTE, TMT_HOUR, TMT_DAY, TMT_WEEK, TMT_MONTH, TMT_YEAR }; @@ -265,6 +267,12 @@ rrd_info_t *grinfo_current; /* pointing to current entry */ } image_desc_t; +typedef struct imgtitle_t +{ + char **pieces; + int count; +} imgtitle_t; + /* Prototypes */ int xtr( image_desc_t *, @@ -471,3 +479,5 @@ image_desc_t *im, char *key, rrd_info_type_t type, rrd_infoval_t value); + +imgtitle_t split_graphtitle(char *);