cairo-chart.c: new struct xrchart_axis
[pspp] / src / output / cairo-chart.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2011 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef OUTPUT_CAIRO_CHART_H
18 #define OUTPUT_CAIRO_CHART_H 1
19
20 #include <cairo/cairo.h>
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include "libpspp/compiler.h"
24
25 struct chart_item;
26
27 struct xrchart_colour
28   {
29     uint8_t red;
30     uint8_t green;
31     uint8_t blue;
32   };
33
34 struct xrchart_axis
35 {
36   int data_max;
37   int data_min;
38
39   double scale;
40   double min;
41   double max;
42 };
43
44 /* The geometry of a chart. */
45 struct xrchart_geometry
46   {
47     int abscissa_top;
48     int ordinate_right;
49
50     int title_bottom;
51
52     /* Legend. */
53     int legend_left;
54     int legend_right;
55     char **dataset;
56     int n_datasets;
57
58     /* Default font size for the plot. */
59     double font_size;
60
61     struct xrchart_colour fill_colour;
62
63     /* Stuff particular to cartesians and boxplots. */
64     struct xrchart_axis axis[2];
65
66     /* True iff a path is currently being drawn */
67     bool in_path;
68   };
69
70 void xrchart_geometry_init (cairo_t *, struct xrchart_geometry *,
71                             double width, double length);
72 void xrchart_geometry_free (cairo_t *, struct xrchart_geometry *);
73
74 #define XRCHART_N_COLOURS 9
75 extern const struct xrchart_colour data_colour[];
76
77 enum tick_orientation
78   {
79     SCALE_ABSCISSA=0,
80     SCALE_ORDINATE
81   };
82
83 enum xrmarker_type
84   {
85     XRMARKER_CIRCLE,              /* Hollow circle. */
86     XRMARKER_ASTERISK,            /* Asterisk (*). */
87     XRMARKER_SQUARE               /* Hollow square. */
88   };
89
90 void xrchart_draw_marker (cairo_t *, double x, double y, enum xrmarker_type,
91                           double size);
92
93 void xrchart_label (cairo_t *, int horz_justify, int vert_justify,
94                     double font_size, const char *);
95
96 /* Draw a tick mark at position
97    If label is non zero, then print it at the tick mark
98 */
99 void draw_tick (cairo_t *, const struct xrchart_geometry *,
100                 enum tick_orientation orientation, double position,
101                 const char *label, ...)
102   PRINTF_FORMAT (5, 6);
103
104
105 /* Write the title on a chart*/
106 void xrchart_write_title (cairo_t *, const struct xrchart_geometry *,
107                           const char *title, ...)
108   PRINTF_FORMAT (3, 4);
109
110 /* Set the scale for the abscissa */
111 void xrchart_write_xscale (cairo_t *, struct xrchart_geometry *,
112                            double min, double max, int ticks);
113
114
115 /* Set the scale for the ordinate */
116 void xrchart_write_yscale (cairo_t *, struct xrchart_geometry *,
117                            double smin, double smax, int ticks);
118
119 void xrchart_write_xlabel (cairo_t *, const struct xrchart_geometry *,
120                            const char *label) ;
121
122 /* Write the ordinate label */
123 void xrchart_write_ylabel (cairo_t *, const struct xrchart_geometry *,
124                            const char *label);
125
126 void xrchart_write_legend (cairo_t *, const struct xrchart_geometry *);
127
128 enum xrchart_dim
129   {
130     XRCHART_DIM_X,
131     XRCHART_DIM_Y
132   };
133
134 void xrchart_vector_start (cairo_t *, struct xrchart_geometry *,
135                            const char *name);
136 void xrchart_vector_end (cairo_t *, struct xrchart_geometry *);
137 void xrchart_vector (cairo_t *, struct xrchart_geometry *, double x, double y);
138
139 /* Plot a data point */
140 void xrchart_datum (cairo_t *, const struct xrchart_geometry *,
141                     int dataset UNUSED, double x, double y);
142
143 /* Draw a line with slope SLOPE and intercept INTERCEPT.
144    between the points limit1 and limit2.
145    If lim_dim is XRCHART_DIM_Y then the limit{1,2} are on the
146    y axis otherwise the x axis
147 */
148 void xrchart_line (cairo_t *, const struct xrchart_geometry *,
149                    double slope, double intercept,
150                    double limit1, double limit2, enum xrchart_dim lim_dim);
151
152 /* Drawing various kinds of charts. */
153 void xrchart_draw_boxplot (const struct chart_item *, cairo_t *,
154                            struct xrchart_geometry *);
155 void xrchart_draw_roc (const struct chart_item *, cairo_t *,
156                        struct xrchart_geometry *);
157 void xrchart_draw_piechart (const struct chart_item *, cairo_t *,
158                             struct xrchart_geometry *);
159 void xrchart_draw_histogram (const struct chart_item *, cairo_t *,
160                              struct xrchart_geometry *);
161 void xrchart_draw_np_plot (const struct chart_item *, cairo_t *,
162                            struct xrchart_geometry *);
163 void xrchart_draw_scree (const struct chart_item *, cairo_t *,
164                          struct xrchart_geometry *);
165
166 #endif /* output/cairo-chart.h */