The BIG graph update
[rrdtool.git] / src / rrd_gfx.h
1 /****************************************************************************
2  * RRDtool 1.1.x  Copyright Tobias Oetiker, 1997 - 2001
3  ****************************************************************************
4  * rrd_gfx.h generic graphics adapter library
5  ****************************************************************************/
6
7 #ifndef  RRD_GFX_H
8 #define RRD_GFX_H
9 #define LIBART_COMPILATION
10 #include <libart.h>
11
12 enum gfx_en { GFX_LINE=0,GFX_AREA,GFX_TEXT };
13 enum gfx_h_align_en { GFX_H_NULL=0, GFX_H_LEFT, GFX_H_RIGHT, GFX_H_CENTER };
14 enum gfx_v_align_en { GFX_V_NULL=0, GFX_V_TOP,  GFX_V_BOTTOM, GFX_V_CENTER };
15 typedef unsigned long gfx_color_t;
16
17 typedef struct  gfx_node_t {
18   enum gfx_en   type;         /* type of graph element */
19   gfx_color_t   color;        /* color of element  0xRRGGBBAA  alpha 0xff is solid*/
20   double        size;         /* font size, line width */
21   ArtVpath      *path;        /* path */
22   int           points;
23   int           points_max;
24   ArtSVP        *svp;         /* svp */
25   char *filename;             /* font or image filename */
26   char *text;
27   double        x,y;          /* position */
28   enum gfx_h_align_en halign; /* text alignement */
29   enum gfx_v_align_en valign; /* text alignement */
30   double        tabwidth; 
31   struct gfx_node_t  *next; 
32 } gfx_node_t;
33
34
35 typedef struct gfx_canvas_t 
36 {
37     struct gfx_node_t *firstnode;
38     struct gfx_node_t *lastnode;
39 } gfx_canvas_t;
40
41
42 gfx_canvas_t *gfx_new_canvas (void);
43
44 /* create a new line */
45 gfx_node_t   *gfx_new_line   (gfx_canvas_t *canvas, 
46                               double x0, double y0, 
47                               double x1, double y1,
48                               double width, gfx_color_t color);
49
50 /* create a new area */
51 gfx_node_t   *gfx_new_area   (gfx_canvas_t *canvas, 
52                               double x0, double y0,
53                               double x1, double y1,
54                               double x2, double y2,
55                               gfx_color_t  color);
56
57 /* add a point to a line or to an area */
58 int           gfx_add_point  (gfx_node_t *node, double x, double y);
59
60
61 /* create a text node */
62 gfx_node_t   *gfx_new_text   (gfx_canvas_t *canvas,  
63                               double x, double y, gfx_color_t color,
64                               char* font, double size,                        
65                               double tabwidth, double angle,
66                               enum gfx_h_align_en h_align,
67                               enum gfx_v_align_en v_align,
68                               char* text);
69
70 /* measure width of a text string */
71 double gfx_get_text_width ( double start, char* font, double size,                            
72                             double tabwidth, char* text);
73
74
75
76 /* turn graph into a png image */
77 int       gfx_render_png (gfx_canvas_t *canvas,
78                               art_u32 width, art_u32 height,
79                               double zoom,
80                               gfx_color_t background, FILE *fo);
81                                                                                           
82                                                                                          
83 /* free memory used by nodes this will also remove memory required for
84    node chain and associated material */
85 int           gfx_destroy    (gfx_canvas_t *canvas); 
86
87 #endif
88
89
90