7 typedef struct graph_label * graph_label_t;
9 struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font);
10 /* graph_new() Returns a new graph structure of the given dimensions and font */
11 void graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim);
12 /* graph_set_size() Changes the size of a graph to the given dimensions. */
13 void graph_set_position(struct graph *g, double xoffset, double yoffset);
14 /* graph_set_position() sets the x- and y-offset to translate the graph */
15 void bar_graph_draw(struct graph *g, cairo_t *cr);
16 /* bar_graph_draw() draws the given graph as a bar graph */
17 void line_graph_draw(struct graph *g, cairo_t *cr);
18 /* line_graph_draw draws the given graph as a line graph */
19 void line_graph_set_data_count_limit(struct graph *g, int per_label_limit);
20 /* line_graph_set_data_count_limit() limits the amount of data which can
21 * be added to a line graph. Once the limit is reached, the oldest data
22 * is discarded as new data is added
24 void graph_title(struct graph *g, const char *title);
25 /* graph_title() sets the main title of the graph to the given string */
26 void graph_x_title(struct graph *g, const char *title);
27 /* graph_x_title() sets the title of the x axis to the given string */
28 void graph_y_title(struct graph *g, const char *title);
29 /* graph_y_title() sets the title of the y axis to the given string */
30 graph_label_t graph_add_label(struct graph *g, const char *label);
31 /* graph_add_label() adds a new "stream" of data to be graphed.
32 * For line charts, each label is a separate line on the graph.
33 * For bar charts, each label is a grouping of columns on the x-axis
39 * | *x **** | ** ** **
40 * | xxxx* ***** | ** xx ** xx **
41 * | x ** | ** xx ** xx ** xx
42 * | x | ** xx ** xx ** xx
43 * ----------------------- -------------------------
46 * For a line graph, the 'x's For a bar graph,
47 * would be on one "label", and 'A', 'B', and 'C'
48 * the '*'s would be on another are the labels.
52 int graph_add_data(struct graph *g, graph_label_t label, const double value);
53 /* graph_add_data() is used to add data to the labels of a bar graph */
54 int graph_add_xy_data(struct graph *g, graph_label_t label,
55 const double x, const double y, const char *tooltip);
56 /* graph_add_xy_data is used to add data to the labels of a line graph */
58 void graph_set_color(struct graph *g, graph_label_t label,
59 double red, double green, double blue);
60 #define INVISIBLE_COLOR (-1.0)
61 /* graph_set_color is used to set the color used to plot the data in
62 * a line graph. INVISIBLE_COLOR can be used to plot the data invisibly.
63 * Invisible data will have the same effect on the scaling of the axes
67 void graph_free(struct graph *bg);
68 /* free a graph allocated by graph_new() */
70 typedef void (*graph_axis_unit_change_callback)(struct graph *g, int power_of_ten);
71 void graph_x_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
72 void graph_y_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
73 /* The labels used on the x and y axes may be shortened. You can register for callbacks
74 * so that you can know how the labels are shorted, typically used to adjust the axis
75 * titles to display the proper units. The power_of_ten parameter indicates what power
76 * of ten the labels have been divided by (9, 6, 3, or 0, corresponding to billions,
77 * millions, thousands and ones.
80 void graph_add_extra_space(struct graph *g, double left_percent, double right_percent,
81 double top_percent, double bottom_percent);
82 /* graph_add_extra_space() adds extra space to edges of the the graph
83 * so that the data doesn't go to the very edges.
86 extern int graph_has_tooltips(struct graph *g);
87 extern const char *graph_find_tooltip(struct graph *g, int x, int y);
88 extern int graph_contains_xy(struct graph *p, int x, int y);
90 extern void graph_set_base_offset(struct graph *g, unsigned int base_offset);
91 extern void graph_set_graph_all_zeroes(struct graph *g, unsigned int set);