Added an optional --without-libplot flag to configure
[pspp-builds.git] / src / chart.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2004 Free Software Foundation, Inc.
3    Written by John Darrington <john@darrington.wattle.id.au>
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20
21 #ifndef CHART_H
22 #define CHART_H
23
24 #include <config.h>
25 #include <stdio.h>
26 #include <gsl/gsl_histogram.h>
27 #include "var.h"
28
29 #ifndef NO_CHARTS
30 #include <plot.h>
31 #endif
32
33
34 /* Array of standard colour names */
35 extern const char *data_colour[];
36
37
38 struct chart {
39
40 #ifndef NO_CHARTS
41   plPlotter *lp ;
42   plPlotterParams *pl_params;
43 #endif
44
45   /* The geometry of the chart 
46      See diagram at the foot of this file.
47    */
48   
49   int data_top   ;
50   int data_right ;
51   int data_bottom;
52   int data_left  ;
53
54   int abscissa_top;
55
56   int ordinate_right ;
57
58   int title_bottom ;
59
60   int legend_left ;
61   int legend_right ;
62
63   
64   /* Default font size for the plot (if zero, then use plotter default) */
65   int font_size; 
66
67   char fill_colour[10];
68
69   /* Stuff Particular to Cartesians (and Boxplots ) */
70   double ordinate_scale;
71   double abscissa_scale;
72   double x_min;
73   double x_max;
74   double y_min;
75   double y_max;
76
77 };
78
79
80 int  chart_initialise(struct chart *ch);
81
82 void chart_finalise(struct chart *ch);
83
84
85 double chart_rounded_tick(double tick);
86
87 void chart_write_xlabel(struct chart *ch, const char *label);
88 void chart_write_ylabel(struct chart *ch, const char *label);
89
90 void chart_write_title(struct chart *ch, const char *title, ...);
91
92 enum tick_orientation {
93   TICK_ABSCISSA=0,
94   TICK_ORDINATE
95 };
96
97 void draw_tick(struct chart *ch, enum tick_orientation orientation, 
98                double position, const char *label, ...);
99
100
101
102 enum  bar_opts {
103   BAR_GROUPED =  0,
104   BAR_STACKED,
105   BAR_RANGE
106 };
107
108
109 void draw_barchart(struct chart *ch, const char *title, 
110                    const char *xlabel, const char *ylabel, enum bar_opts opt);
111
112 void draw_box_whisker_chart(struct chart *ch, const char *title);
113
114
115
116 struct normal_curve
117 {
118   double N ;
119   double mean ;
120   double stddev ;
121 };
122
123
124 void histogram_write_legend(struct chart *ch, const struct normal_curve *norm);
125
126
127 /* Plot a gsl_histogram */
128 void histogram_plot(const gsl_histogram *hist, const char *factorname,
129                     const struct normal_curve *norm, short show_normal);
130
131
132 /* Create a gsl_histogram and set it's parameters based upon 
133    x_min, x_max and bins. 
134    The caller is responsible for freeing the histogram.
135 */
136 gsl_histogram * histogram_create(double bins, double x_min, double x_max) ;
137
138
139
140
141
142 struct slice {
143   const char *label;
144   double magnetude;
145 };
146
147
148
149
150 /* Draw a piechart */
151 void piechart_plot(const char *title,
152                    const struct slice *slices, int n_slices);
153
154 void draw_scatterplot(struct chart *ch);
155
156
157 void draw_lineplot(struct chart *ch);
158
159
160 /* Set the scale on chart CH.
161    The scale extends from MIN to MAX .
162    TICK is the approximate number of tick marks.
163 */
164
165 void chart_write_xscale(struct chart *ch, 
166                         double min, double max, int ticks);
167
168 void chart_write_yscale(struct chart *ch, 
169                         double min, double max, int ticks);
170
171
172 void chart_datum(struct chart *ch, int dataset, double x, double y);
173
174 struct metrics;
175
176
177 void  boxplot_draw_boxplot(struct chart *ch,
178                            double box_centre, 
179                            double box_width,
180                            struct metrics *m,
181                            const char *name);
182
183
184 void boxplot_draw_yscale(struct chart *ch , double y_max, double y_min);
185
186
187 enum CHART_DIM
188   {
189     CHART_DIM_X,
190     CHART_DIM_Y
191   };
192
193
194 void chart_line(struct chart *ch, double slope, double intercept, 
195                 double limit1, double limit2, enum CHART_DIM limit_d);
196
197
198 #endif
199
200 #if 0
201 The anatomy of a chart is as follows.
202
203 +-------------------------------------------------------------+
204 |            +----------------------------------+             |
205 |            |                                  |             |
206 |            |          Title                   |             |
207 |            |                                  |             |
208 |            +----------------------------------+             |
209 |+----------++----------------------------------++-----------+|
210 ||          ||                                  ||           ||
211 ||          ||                                  ||           ||
212 ||          ||                                  ||           ||
213 ||          ||                                  ||           ||
214 ||          ||                                  ||           ||
215 ||          ||                                  ||           ||
216 ||          ||                                  ||           ||
217 ||          ||                                  ||           ||
218 ||          ||                                  ||           ||
219 ||          ||                                  ||           ||
220 || Ordinate ||            Data                  ||  Legend   ||
221 ||          ||                                  ||           ||
222 ||          ||                                  ||           ||
223 ||          ||                                  ||           ||
224 ||          ||                                  ||           ||
225 ||          ||                                  ||           ||
226 ||          ||                                  ||           ||
227 ||          ||                                  ||           ||
228 ||          ||                                  ||           ||
229 ||          ||                                  ||           ||
230 ||          ||                                  ||           ||       
231 |+----------++----------------------------------++-----------+|   --  
232 |            +----------------------------------+             | -  ^  data_bottom
233 |            |          Abscissa                |             | ^  |             
234 |            |                                  |             | | abscissa_top
235 |            +----------------------------------+             | v  v  
236 +-------------------------------------------------------------+ ----  
237                                                 
238 ordinate_right                                  ||           |
239 |           |                                   ||           |
240 |<--------->|                                   ||           |
241 |            |                                  ||           |
242 | data_left  |                                  ||           |
243 |<---------->|                                  ||           |
244 |                                               ||           |
245 |               data_right                      ||           |
246 |<--------------------------------------------->||           |
247 |                  legend_left                   |           |
248 |<---------------------------------------------->|           |
249 |                    legend_right                            |
250 |<---------------------------------------------------------->|
251                                                              
252 #endif