1 #include "rrd_tool.h"
2 #include "rrd_rpncalc.h"
3 #include "rrd_gfx.h"
5 #define MAX_VNAME_LEN 29
6 #define DEF_NAM_FMT "%29[_A-Za-z0-9]"
8 #define ALTYGRID 0x01 /* use alternative y grid algorithm */
9 #define ALTAUTOSCALE 0x02 /* use alternative algorithm to find lower and upper bounds */
10 #define ALTAUTOSCALE_MAX 0x04 /* use alternative algorithm to find upper bounds */
11 #define NOLEGEND 0x08 /* use no legend */
14 enum tmt_en {TMT_SECOND=0,TMT_MINUTE,TMT_HOUR,TMT_DAY,
15 TMT_WEEK,TMT_MONTH,TMT_YEAR};
17 enum grc_en {GRC_CANVAS=0,GRC_BACK,GRC_SHADEA,GRC_SHADEB,
18 GRC_GRID,GRC_MGRID,GRC_FONT,GRC_FRAME,GRC_ARROW,__GRC_END__};
20 #define MGRIDWIDTH 0.6
21 #define GRIDWIDTH 0.4
23 enum gf_en {GF_PRINT=0,GF_GPRINT,GF_COMMENT,GF_HRULE,GF_VRULE,GF_LINE,
24 GF_AREA,GF_STACK,GF_TICK,
25 GF_DEF, GF_CDEF, GF_VDEF,
26 GF_PART};
28 enum if_en {IF_PNG=0};
30 enum vdef_op_en {
31 VDEF_MAXIMUM /* like the MAX in (G)PRINT */
32 ,VDEF_MINIMUM /* like the MIN in (G)PRINT */
33 ,VDEF_AVERAGE /* like the AVERAGE in (G)PRINT */
34 ,VDEF_PERCENT /* Nth percentile */
35 ,VDEF_TOTAL /* average multiplied by time */
36 ,VDEF_FIRST /* first non-unknown value and time */
37 ,VDEF_LAST /* last non-unknown value and time */
38 };
39 enum text_prop_en { TEXT_PROP_DEFAULT=0, /* default settings */
40 TEXT_PROP_TITLE, /* properties for the title */
41 TEXT_PROP_AXIS, /* for the numbers next to the axis */
42 TEXT_PROP_UNIT, /* for the vertical unit description */
43 TEXT_PROP_LEGEND, /* fot the legend below the graph */
44 TEXT_PROP_LAST };
46 typedef struct text_prop_t {
47 double size;
48 char * font;
49 } text_prop_t;
52 typedef struct vdef_t {
53 enum vdef_op_en op;
54 double param; /* parameter for function, if applicable */
55 double val; /* resulting value */
56 time_t when; /* timestamp, if applicable */
57 } vdef_t;
59 typedef struct xlab_t {
60 long minsec; /* minimum sec per pix */
61 enum tmt_en gridtm; /* grid interval in what ?*/
62 long gridst; /* how many whats per grid*/
63 enum tmt_en mgridtm; /* label interval in what ?*/
64 long mgridst; /* how many whats per label*/
65 enum tmt_en labtm; /* label interval in what ?*/
66 long labst; /* how many whats per label*/
67 long precis; /* label precision -> label placement*/
68 char *stst; /* strftime string*/
69 } xlab_t;
71 /* sensible y label intervals ...*/
73 typedef struct ylab_t {
74 double grid; /* grid spacing */
75 int lfac[4]; /* associated label spacing*/
76 } ylab_t;
79 /* this structure describes the elements which can make up a graph.
80 because they are quite diverse, not all elements will use all the
81 possible parts of the structure. */
82 #ifdef HAVE_SNPRINTF
83 #define FMT_LEG_LEN 200
84 #else
85 #define FMT_LEG_LEN 2000
86 #endif
88 typedef struct graph_desc_t {
89 enum gf_en gf; /* graphing function */
90 char vname[MAX_VNAME_LEN+1]; /* name of the variable */
91 long vidx; /* gdes reference */
92 char rrd[255]; /* name of the rrd_file containing data */
93 char ds_nam[DS_NAM_SIZE]; /* data source name */
94 long ds; /* data source number */
95 enum cf_en cf; /* consolidation function */
96 gfx_color_t col; /* graph color */
97 char format[FMT_LEG_LEN+5]; /* format for PRINT AND GPRINT */
98 char legend[FMT_LEG_LEN+5]; /* legend*/
99 double leg_x,leg_y; /* location of legend */
100 double yrule; /* value for y rule line and for VDEF */
101 time_t xrule; /* time for x rule line and for VDEF */
102 vdef_t vf; /* instruction for VDEF function */
103 rpnp_t *rpnp; /* instructions for CDEF function */
105 /* description of data fetched for the graph element */
106 time_t start,end; /* timestaps for first and last data element */
107 unsigned long step; /* time between samples */
108 unsigned long ds_cnt; /* how many data sources are there in the fetch */
109 long data_first; /* first pointer to this data */
110 char **ds_namv; /* name of datasources in the fetch. */
111 rrd_value_t *data; /* the raw data drawn from the rrd */
112 rrd_value_t *p_data; /* processed data, xsize elments */
113 double linewidth; /* linewideth */
114 } graph_desc_t;
116 typedef struct image_desc_t {
118 /* configuration of graph */
120 char graphfile[MAXPATH]; /* filename for graphic */
121 long xsize,ysize; /* graph area size in pixels */
122 double zoom; /* zoom for graph */
123 gfx_color_t graph_col[__GRC_END__]; /* real colors for the graph */
124 text_prop_t text_prop[TEXT_PROP_LAST]; /* text properties */
125 char ylegend[200]; /* legend along the yaxis */
126 char title[200]; /* title for graph */
127 int draw_x_grid; /* no x-grid at all */
128 int draw_y_grid; /* no x-grid at all */
129 xlab_t xlab_user; /* user defined labeling for xaxis */
130 char xlab_form[200]; /* format for the label on the xaxis */
132 double ygridstep; /* user defined step for y grid */
133 int ylabfact; /* every how many y grid shall a label be written ? */
134 double tabwidth; /* tabwdith */
135 time_t start,end; /* what time does the graph cover */
136 unsigned long step; /* any preference for the default step ? */
137 rrd_value_t minval,maxval; /* extreme values in the data */
138 int rigid; /* do not expand range even with
139 values outside */
140 char* imginfo; /* construct an <IMG ... tag and return
141 as first retval */
142 int lazy; /* only update the gif if there is reasonable
143 probablility that the existing one is out of date */
144 int logarithmic; /* scale the yaxis logarithmic */
145 enum if_en imgformat; /* image format */
147 /* status information */
149 long xorigin,yorigin;/* where is (0,0) of the graph */
150 long xgif,ygif; /* total size of the gif */
151 int interlaced; /* will the graph be interlaced? */
152 double magfact; /* numerical magnitude*/
153 long base; /* 1000 or 1024 depending on what we graph */
154 char symbol; /* magnitude symbol for y-axis */
155 int unitsexponent; /* 10*exponent for units on y-asis */
156 int extra_flags; /* flags for boolean options */
157 /* data elements */
159 long prt_c; /* number of print elements */
160 long gdes_c; /* number of graphics elements */
161 graph_desc_t *gdes; /* points to an array of graph elements */
163 } image_desc_t;
165 /* Prototypes */
166 int xtr(image_desc_t *,time_t);
167 int ytr(image_desc_t *, double);
168 enum gf_en gf_conv(char *);
169 enum if_en if_conv(char *);
170 enum tmt_en tmt_conv(char *);
171 enum grc_en grc_conv(char *);
172 enum grc_en text_prop_conv(char *);
173 int im_free(image_desc_t *);
174 void auto_scale( image_desc_t *, double *, char **, double *);
175 void si_unit( image_desc_t *);
176 void expand_range(image_desc_t *);
177 void reduce_data( enum cf_en, unsigned long, time_t *, time_t *, unsigned long *, unsigned long *, rrd_value_t **);
178 int data_fetch( image_desc_t *);
179 long find_var(image_desc_t *, char *);
180 long find_var_wrapper(void *arg1, char *key);
181 long lcd(long *);
182 int data_calc( image_desc_t *);
183 int data_proc( image_desc_t *);
184 time_t find_first_time( time_t, enum tmt_en, long);
185 time_t find_next_time( time_t, enum tmt_en, long);
186 int print_calc(image_desc_t *, char ***);
187 int leg_place(image_desc_t *);
188 int horizontal_grid(gfx_canvas_t *,image_desc_t *);
189 int horizontal_log_grid(gfx_canvas_t *, image_desc_t *);
190 void vertical_grid(gfx_canvas_t *, image_desc_t *);
191 void axis_paint( image_desc_t *, gfx_canvas_t *);
192 void grid_paint( image_desc_t *, gfx_canvas_t *);
193 int lazy_check(image_desc_t *);
194 int graph_paint(image_desc_t *, char ***);
195 void pie_part(gfx_canvas_t *, gfx_color_t, double, double, double, double, double);
196 int gdes_alloc(image_desc_t *);
197 int scan_for_col(char *, int, char *);
198 int rrd_graph(int, char **, char ***, int *, int *);
199 void rrd_graph_init(image_desc_t *);
200 void rrd_graph_options(int, char **, image_desc_t *);
201 void rrd_graph_script(int, char **, image_desc_t *);
202 int rrd_graph_check_vname(image_desc_t *, char *, char *);
203 int rrd_graph_check_CF(image_desc_t *, char *, char *);
204 int rrd_graph_color(image_desc_t *, char *, char *, int);
205 int rrd_graph_legend(graph_desc_t *, char *);
206 int bad_format(char *);
207 int vdef_parse(struct graph_desc_t *,char *);
208 int vdef_calc(image_desc_t *, int);
209 int vdef_percent_compar(const void *,const void *);