1af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron#ifndef GRAPH_H
2af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron#define GRAPH_H
3af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron
4af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameronstruct graph;
58dfd6071e1a4fd3966c0a77dbb7d719c52433b54Jens Axboestruct graph_label;
6af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron
78dfd6071e1a4fd3966c0a77dbb7d719c52433b54Jens Axboetypedef struct graph_label * graph_label_t;
8cae0872709f690086f896f7327e136c7db7ba567Stephen M. Cameron
9a1e7972d96ce1482aa43c2fcafd81d6c7f3c44d2Jens Axboe#define GRAPH_DEFAULT_FONT	"Sans 12"
10a1e7972d96ce1482aa43c2fcafd81d6c7f3c44d2Jens Axboe
11f3e8440f75f98ced28cdd19ba785718e734cf7c5Jens Axboestruct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font);
12ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_new() Returns a new graph structure of the given dimensions and font */
133ea48b883bcac5ad0c119205805b741af45427e3Stephen M. Cameronvoid graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim);
14ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_set_size() Changes the size of a graph to the given dimensions. */
1557f9d28e010b52fea5f41245e8fcb998367d3bcdStephen M. Cameronvoid graph_set_position(struct graph *g, double xoffset, double yoffset);
1657f9d28e010b52fea5f41245e8fcb998367d3bcdStephen M. Cameron/* graph_set_position() sets the x- and y-offset to translate the graph */
17af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameronvoid bar_graph_draw(struct graph *g, cairo_t *cr);
18ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* bar_graph_draw() draws the given graph as a bar graph */
19af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameronvoid line_graph_draw(struct graph *g, cairo_t *cr);
20ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* line_graph_draw draws the given graph as a line graph */
21af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameronvoid line_graph_set_data_count_limit(struct graph *g, int per_label_limit);
22ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* line_graph_set_data_count_limit() limits the amount of data which can
23ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * be added to a line graph.  Once the limit is reached, the oldest data
24ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * is discarded as new data is added
25ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron */
26a1e7972d96ce1482aa43c2fcafd81d6c7f3c44d2Jens Axboevoid graph_set_font(struct graph *g, const char *font);
27af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameronvoid graph_title(struct graph *g, const char *title);
28ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_title() sets the main title of the graph to the given string */
29af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameronvoid graph_x_title(struct graph *g, const char *title);
30ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_x_title() sets the title of the x axis to the given string */
31af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameronvoid graph_y_title(struct graph *g, const char *title);
32ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_y_title() sets the title of the y axis to the given string */
338dfd6071e1a4fd3966c0a77dbb7d719c52433b54Jens Axboegraph_label_t graph_add_label(struct graph *g, const char *label);
34ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_add_label() adds a new "stream" of data to be graphed.
35ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * For line charts, each label is a separate line on the graph.
36ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * For bar charts, each label is a grouping of columns on the x-axis
37ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * For example:
38ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *
39ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *  |  *                          | **
40ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *  |   *      xxxxxxxx           | **
41ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *  |    ***  x                   | **              **
42ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *  |       *x       ****         | **      **      **
43ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *  |    xxxx*  *****             | ** xx   ** xx   **
44ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *  |   x     **                  | ** xx   ** xx   ** xx
45ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *  |  x                          | ** xx   ** xx   ** xx
46ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *  -----------------------       -------------------------
47ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *                                    A       B       C
48ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron *
49ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * For a line graph, the 'x's     For a bar graph,
50ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * would be on one "label", and   'A', 'B', and 'C'
51ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * the '*'s would be on another   are the labels.
52ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * label.
53ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron */
54ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron
558dfd6071e1a4fd3966c0a77dbb7d719c52433b54Jens Axboeint graph_add_data(struct graph *g, graph_label_t label, const double value);
56ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_add_data() is used to add data to the labels of a bar graph */
578dfd6071e1a4fd3966c0a77dbb7d719c52433b54Jens Axboeint graph_add_xy_data(struct graph *g, graph_label_t label,
5893e2db2bdbedbd6954bb0e0632514cae659fc30eJens Axboe		const double x, const double y, const char *tooltip);
59ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_add_xy_data is used to add data to the labels of a line graph */
60ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron
618dfd6071e1a4fd3966c0a77dbb7d719c52433b54Jens Axboevoid graph_set_color(struct graph *g, graph_label_t label,
62af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron		double red, double green, double blue);
63ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron#define INVISIBLE_COLOR (-1.0)
64ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* graph_set_color is used to set the color used to plot the data in
65ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * a line graph.  INVISIBLE_COLOR can be used to plot the data invisibly.
66ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * Invisible data will have the same effect on the scaling of the axes
67ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * as visible data.
68ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron */
69ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron
70af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameronvoid graph_free(struct graph *bg);
71ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* free a graph allocated by graph_new() */
72af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron
737175d91deff20b1408450c231b2b445ea28f7f29Stephen M. Camerontypedef void (*graph_axis_unit_change_callback)(struct graph *g, int power_of_ten);
747175d91deff20b1408450c231b2b445ea28f7f29Stephen M. Cameronvoid graph_x_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
757175d91deff20b1408450c231b2b445ea28f7f29Stephen M. Cameronvoid graph_y_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
76ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron/* The labels used on the x and y axes may be shortened.  You can register for callbacks
77ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * so that you can know how the labels are shorted, typically used to adjust the axis
78ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * titles to display the proper units.  The power_of_ten parameter indicates what power
79ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * of ten the labels have been divided by (9, 6, 3, or 0, corresponding to billions,
80ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron * millions, thousands and ones.
81ba35aa8dbd78cc59e2f29d3d746ad3be912a0541Stephen M. Cameron */
82af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron
83def0ac29a7eb92282cf7f208b229261bb254ca00Stephen M. Cameronvoid graph_add_extra_space(struct graph *g, double left_percent, double right_percent,
84def0ac29a7eb92282cf7f208b229261bb254ca00Stephen M. Cameron				double top_percent, double bottom_percent);
85def0ac29a7eb92282cf7f208b229261bb254ca00Stephen M. Cameron/* graph_add_extra_space() adds extra space to edges of the the graph
86def0ac29a7eb92282cf7f208b229261bb254ca00Stephen M. Cameron * so that the data doesn't go to the very edges.
87def0ac29a7eb92282cf7f208b229261bb254ca00Stephen M. Cameron */
88def0ac29a7eb92282cf7f208b229261bb254ca00Stephen M. Cameron
8993e2db2bdbedbd6954bb0e0632514cae659fc30eJens Axboeextern int graph_has_tooltips(struct graph *g);
9093e2db2bdbedbd6954bb0e0632514cae659fc30eJens Axboeextern const char *graph_find_tooltip(struct graph *g, int x, int y);
9193e2db2bdbedbd6954bb0e0632514cae659fc30eJens Axboeextern int graph_contains_xy(struct graph *p, int x, int y);
9293e2db2bdbedbd6954bb0e0632514cae659fc30eJens Axboe
93d8fbeefb67641e9f63088b329de78a26a69fdbaeJens Axboeextern void graph_set_base_offset(struct graph *g, unsigned int base_offset);
9401a947f067b1a03add33e645ece73ac19d8257ddJens Axboeextern void graph_set_graph_all_zeroes(struct graph *g, unsigned int set);
95d8fbeefb67641e9f63088b329de78a26a69fdbaeJens Axboe
965721d270285a5f7e41b0b076a4a43b825239d964Jens Axboeextern void graph_clear_values(struct graph *g);
975721d270285a5f7e41b0b076a4a43b825239d964Jens Axboe
98af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron#endif
99af58ef32b7398d791168af54aa4aab0b23192f90Stephen M. Cameron
100