blob: 9eb33d7fe121b7e0062cb8e16e5794e728f931f1 [file] [log] [blame]
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +01001#ifndef GRAPH_H
2#define GRAPH_H
3
4struct graph;
5
Stephen M. Cameroncae08722012-03-07 14:47:38 +01006
Jens Axboef3e84402012-03-07 13:14:32 +01007struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +01008/* graph_new() Returns a new graph structure of the given dimensions and font */
Stephen M. Cameron3ea48b82012-03-07 19:40:58 +01009void graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010010/* graph_set_size() Changes the size of a graph to the given dimensions. */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010011void bar_graph_draw(struct graph *g, cairo_t *cr);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010012/* bar_graph_draw() draws the given graph as a bar graph */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010013void line_graph_draw(struct graph *g, cairo_t *cr);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010014/* line_graph_draw draws the given graph as a line graph */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010015void line_graph_set_data_count_limit(struct graph *g, int per_label_limit);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010016/* line_graph_set_data_count_limit() limits the amount of data which can
17 * be added to a line graph. Once the limit is reached, the oldest data
18 * is discarded as new data is added
19 */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010020void graph_title(struct graph *g, const char *title);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010021/* graph_title() sets the main title of the graph to the given string */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010022void graph_x_title(struct graph *g, const char *title);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010023/* graph_x_title() sets the title of the x axis to the given string */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010024void graph_y_title(struct graph *g, const char *title);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010025/* graph_y_title() sets the title of the y axis to the given string */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010026void graph_add_label(struct graph *g, const char *label);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010027/* graph_add_label() adds a new "stream" of data to be graphed.
28 * For line charts, each label is a separate line on the graph.
29 * For bar charts, each label is a grouping of columns on the x-axis
30 * For example:
31 *
32 * | * | **
33 * | * xxxxxxxx | **
34 * | *** x | ** **
35 * | *x **** | ** ** **
36 * | xxxx* ***** | ** xx ** xx **
37 * | x ** | ** xx ** xx ** xx
38 * | x | ** xx ** xx ** xx
39 * ----------------------- -------------------------
40 * A B C
41 *
42 * For a line graph, the 'x's For a bar graph,
43 * would be on one "label", and 'A', 'B', and 'C'
44 * the '*'s would be on another are the labels.
45 * label.
46 */
47
Stephen M. Cameron09ad20f2012-03-11 11:34:38 +010048int graph_add_data(struct graph *g, const char *label, const double value);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010049/* graph_add_data() is used to add data to the labels of a bar graph */
Stephen M. Cameron09ad20f2012-03-11 11:34:38 +010050int graph_add_xy_data(struct graph *g, const char *label,
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010051 const double x, const double y);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010052/* graph_add_xy_data is used to add data to the labels of a line graph */
53
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010054void graph_set_color(struct graph *g, const char *label,
55 double red, double green, double blue);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010056#define INVISIBLE_COLOR (-1.0)
57/* graph_set_color is used to set the color used to plot the data in
58 * a line graph. INVISIBLE_COLOR can be used to plot the data invisibly.
59 * Invisible data will have the same effect on the scaling of the axes
60 * as visible data.
61 */
62
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010063void graph_free(struct graph *bg);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010064/* free a graph allocated by graph_new() */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010065
Stephen M. Cameron7175d912012-03-11 11:35:10 +010066typedef void (*graph_axis_unit_change_callback)(struct graph *g, int power_of_ten);
67void graph_x_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
68void graph_y_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010069/* The labels used on the x and y axes may be shortened. You can register for callbacks
70 * so that you can know how the labels are shorted, typically used to adjust the axis
71 * titles to display the proper units. The power_of_ten parameter indicates what power
72 * of ten the labels have been divided by (9, 6, 3, or 0, corresponding to billions,
73 * millions, thousands and ones.
74 */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010075
76#endif
77