1 #ifndef _RRD_GRAPH_H
2 #define _RRD_GRAPH_H
4 #include "rrd_tool.h"
5 #include "rrd_rpncalc.h"
6 #include "rrd_gfx.h"
8 #define MAX_VNAME_LEN 29
9 #define DEF_NAM_FMT "%29[-_A-Za-z0-9]"
11 #define ALTYGRID 0x01 /* use alternative y grid algorithm */
12 #define ALTAUTOSCALE 0x02 /* use alternative algorithm to find lower and upper bounds */
13 #define ALTAUTOSCALE_MAX 0x04 /* use alternative algorithm to find upper bounds */
14 #define NOLEGEND 0x08 /* use no legend */
15 #define NOMINOR 0x10 /* Turn off minor gridlines */
16 #define ONLY_GRAPH 0x20 /* use only graph */
17 #define FORCE_RULES_LEGEND 0x40 /* force printing of HRULE and VRULE legend */
20 enum tmt_en {TMT_SECOND=0,TMT_MINUTE,TMT_HOUR,TMT_DAY,
21 TMT_WEEK,TMT_MONTH,TMT_YEAR};
23 enum grc_en {GRC_CANVAS=0,GRC_BACK,GRC_SHADEA,GRC_SHADEB,
24 GRC_GRID,GRC_MGRID,GRC_FONT,GRC_ARROW,GRC_AXIS,GRC_FRAME,__GRC_END__};
26 #define MGRIDWIDTH 0.6
27 #define GRIDWIDTH 0.4
29 enum gf_en {GF_PRINT=0,GF_GPRINT,GF_COMMENT,GF_HRULE,GF_VRULE,GF_LINE,
30 GF_AREA,GF_STACK,GF_TICK,
31 GF_DEF, GF_CDEF, GF_VDEF, GF_SHIFT,
32 #ifdef WITH_PIECHART
33 GF_PART,
34 #endif
35 GF_XPORT};
37 enum vdef_op_en {
38 VDEF_MAXIMUM=0 /* like the MAX in (G)PRINT */
39 ,VDEF_MINIMUM /* like the MIN in (G)PRINT */
40 ,VDEF_AVERAGE /* like the AVERAGE in (G)PRINT */
41 ,VDEF_PERCENT /* Nth percentile */
42 ,VDEF_TOTAL /* average multiplied by time */
43 ,VDEF_FIRST /* first non-unknown value and time */
44 ,VDEF_LAST /* last non-unknown value and time */
45 };
46 enum text_prop_en { TEXT_PROP_DEFAULT=0, /* default settings */
47 TEXT_PROP_TITLE, /* properties for the title */
48 TEXT_PROP_AXIS, /* for the numbers next to the axis */
49 TEXT_PROP_UNIT, /* for the vertical unit description */
50 TEXT_PROP_LEGEND, /* fot the legend below the graph */
51 TEXT_PROP_LAST };
53 typedef struct text_prop_t {
54 double size;
55 char font[1024];
56 } text_prop_t;
59 typedef struct vdef_t {
60 enum vdef_op_en op;
61 double param; /* parameter for function, if applicable */
62 double val; /* resulting value */
63 time_t when; /* timestamp, if applicable */
64 } vdef_t;
66 typedef struct xlab_t {
67 long minsec; /* minimum sec per pix */
68 enum tmt_en gridtm; /* grid interval in what ?*/
69 long gridst; /* how many whats per grid*/
70 enum tmt_en mgridtm; /* label interval in what ?*/
71 long mgridst; /* how many whats per label*/
72 enum tmt_en labtm; /* label interval in what ?*/
73 long labst; /* how many whats per label*/
74 long precis; /* label precision -> label placement*/
75 char *stst; /* strftime string*/
76 } xlab_t;
78 typedef struct ygrid_scale_t { /* y axis grid scaling info */
79 double gridstep;
80 int labfact;
81 char labfmt[64];
82 } ygrid_scale_t;
84 /* sensible y label intervals ...*/
86 typedef struct ylab_t {
87 double grid; /* grid spacing */
88 int lfac[4]; /* associated label spacing*/
89 } ylab_t;
92 /* this structure describes the elements which can make up a graph.
93 because they are quite diverse, not all elements will use all the
94 possible parts of the structure. */
95 #ifdef HAVE_SNPRINTF
96 #define FMT_LEG_LEN 200
97 #else
98 #define FMT_LEG_LEN 2000
99 #endif
101 typedef struct graph_desc_t {
102 enum gf_en gf; /* graphing function */
103 int stack; /* boolean */
104 int debug; /* boolean */
105 char vname[MAX_VNAME_LEN+1]; /* name of the variable */
106 long vidx; /* gdes reference */
107 char rrd[1024]; /* name of the rrd_file containing data */
108 char ds_nam[DS_NAM_SIZE]; /* data source name */
109 long ds; /* data source number */
110 enum cf_en cf; /* consolidation function */
111 enum cf_en cf_reduce; /* consolidation function for reduce_data() */
112 gfx_color_t col; /* graph color */
113 char format[FMT_LEG_LEN+5]; /* format for PRINT AND GPRINT */
114 char legend[FMT_LEG_LEN+5]; /* legend*/
115 double leg_x,leg_y; /* location of legend */
116 double yrule; /* value for y rule line and for VDEF */
117 time_t xrule; /* time for x rule line and for VDEF */
118 vdef_t vf; /* instruction for VDEF function */
119 rpnp_t *rpnp; /* instructions for CDEF function */
121 /* SHIFT implementation */
122 int shidx; /* gdes reference for offset (-1 --> constant) */
123 time_t shval; /* offset if shidx is -1 */
124 time_t shift; /* current shift applied */
126 /* description of data fetched for the graph element */
127 time_t start,end; /* timestaps for first and last data element */
128 unsigned long step; /* time between samples */
129 unsigned long ds_cnt; /* how many data sources are there in the fetch */
130 long data_first; /* first pointer to this data */
131 char **ds_namv; /* name of datasources in the fetch. */
132 rrd_value_t *data; /* the raw data drawn from the rrd */
133 rrd_value_t *p_data; /* processed data, xsize elments */
134 double linewidth; /* linewideth */
135 } graph_desc_t;
137 typedef struct image_desc_t {
139 /* configuration of graph */
141 char graphfile[MAXPATH]; /* filename for graphic */
142 FILE *graphhandle; /* FILE to use if filename is "-" */
143 long xsize,ysize; /* graph area size in pixels */
144 #ifdef WITH_PIECHART
145 long piesize; /* size of the piechart */
146 #endif
147 gfx_color_t graph_col[__GRC_END__]; /* real colors for the graph */
148 text_prop_t text_prop[TEXT_PROP_LAST]; /* text properties */
149 char ylegend[200]; /* legend along the yaxis */
150 char title[200]; /* title for graph */
151 int draw_x_grid; /* no x-grid at all */
152 int draw_y_grid; /* no x-grid at all */
153 double grid_dash_on, grid_dash_off;
154 xlab_t xlab_user; /* user defined labeling for xaxis */
155 char xlab_form[200]; /* format for the label on the xaxis */
157 double ygridstep; /* user defined step for y grid */
158 int ylabfact; /* every how many y grid shall a label be written ? */
159 double tabwidth; /* tabwdith */
160 time_t start,end; /* what time does the graph cover */
161 unsigned long step; /* any preference for the default step ? */
162 rrd_value_t minval,maxval; /* extreme values in the data */
163 int rigid; /* do not expand range even with
164 values outside */
165 ygrid_scale_t ygrid_scale; /* calculated y axis grid info */
166 int gridfit; /* adjust y-axis range etc so all
167 grindlines falls in integer pixel values */
168 char* imginfo; /* construct an <IMG ... tag and return
169 as first retval */
170 int lazy; /* only update the image if there is
171 reasonable probablility that the
172 existing one is out of date */
173 int slopemode; /* connect the dots of the curve directly, not using a stair */
174 int logarithmic; /* scale the yaxis logarithmic */
176 /* status information */
178 long xorigin,yorigin;/* where is (0,0) of the graph */
179 #ifdef WITH_PIECHART
180 long pie_x,pie_y; /* where is the centerpoint */
181 #endif
182 long ximg,yimg; /* total size of the image */
183 double magfact; /* numerical magnitude*/
184 long base; /* 1000 or 1024 depending on what we graph */
185 char symbol; /* magnitude symbol for y-axis */
186 float viewfactor; /* how should the numbers on the y-axis be scaled for viewing ? */
187 int unitsexponent; /* 10*exponent for units on y-asis */
188 int unitslength; /* width of the yaxis labels */
189 int extra_flags; /* flags for boolean options */
190 /* data elements */
192 long prt_c; /* number of print elements */
193 long gdes_c; /* number of graphics elements */
194 graph_desc_t *gdes; /* points to an array of graph elements */
195 gfx_canvas_t *canvas; /* graphics library */
196 } image_desc_t;
198 /* Prototypes */
199 int xtr(image_desc_t *,time_t);
200 double ytr(image_desc_t *, double);
201 enum gf_en gf_conv(char *);
202 enum gfx_if_en if_conv(char *);
203 enum tmt_en tmt_conv(char *);
204 enum grc_en grc_conv(char *);
205 enum text_prop_en text_prop_conv(char *);
206 int im_free(image_desc_t *);
207 void auto_scale( image_desc_t *, double *, char **, double *);
208 void si_unit( image_desc_t *);
209 void expand_range(image_desc_t *);
210 void apply_gridfit(image_desc_t *);
211 void reduce_data( enum cf_en, unsigned long, time_t *, time_t *, unsigned long *, unsigned long *, rrd_value_t **);
212 int data_fetch( image_desc_t *);
213 long find_var(image_desc_t *, char *);
214 long find_var_wrapper(void *arg1, char *key);
215 long lcd(long *);
216 int data_calc( image_desc_t *);
217 int data_proc( image_desc_t *);
218 time_t find_first_time( time_t, enum tmt_en, long);
219 time_t find_next_time( time_t, enum tmt_en, long);
220 int print_calc(image_desc_t *, char ***);
221 int leg_place(image_desc_t *);
222 int calc_horizontal_grid(image_desc_t *);
223 int draw_horizontal_grid(image_desc_t *);
224 int horizontal_log_grid(image_desc_t *);
225 void vertical_grid(image_desc_t *);
226 void axis_paint(image_desc_t *);
227 void grid_paint(image_desc_t *);
228 int lazy_check(image_desc_t *);
229 int graph_paint(image_desc_t *, char ***);
230 #ifdef WITH_PIECHART
231 void pie_part(image_desc_t *, gfx_color_t, double, double, double, double, double);
232 #endif
233 int gdes_alloc(image_desc_t *);
234 int scan_for_col(char *, int, char *);
235 int rrd_graph(int, char **, char ***, int *, int *, FILE *, double *, double *);
236 void rrd_graph_init(image_desc_t *);
237 void rrd_graph_options(int, char **, image_desc_t *);
238 void rrd_graph_script(int, char **, image_desc_t *, int);
239 int rrd_graph_check_vname(image_desc_t *, char *, char *);
240 int rrd_graph_color(image_desc_t *, char *, char *, int);
241 int bad_format(char *);
242 int vdef_parse(struct graph_desc_t *,char *);
243 int vdef_calc(image_desc_t *, int);
244 int vdef_percent_compar(const void *,const void *);
245 int graph_size_location(image_desc_t *, int
246 #ifdef WITH_PIECHART
247 ,int
248 #endif
249 );
251 #endif