Added Boxplots to the EXAMINE subcommand repertoire
[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 <stdio.h>
25 #include <plot.h>
26 #include <gsl/gsl_histogram.h>
27
28 #include "var.h"
29
30
31 /* Array of standard colour names */
32 extern const char *data_colour[];
33
34
35 struct chart {
36
37   plPlotter *lp ;
38   plPlotterParams *pl_params;
39
40   /* The geometry of the chart 
41      See diagram at the foot of this file.
42    */
43   
44   int data_top   ;
45   int data_right ;
46   int data_bottom;
47   int data_left  ;
48
49   int abscissa_top;
50
51   int ordinate_right ;
52
53   int title_bottom ;
54
55   int legend_left ;
56   int legend_right ;
57
58   
59   /* Default font size for the plot (if zero, then use plotter default) */
60   int font_size; 
61
62   char fill_colour[10];
63
64   /* Stuff Particular to Cartesians (and Boxplots ) */
65   double ordinate_scale;
66   double abscissa_scale;
67   double x_min;
68   double x_max;
69   double y_min;
70   double y_max;
71
72 };
73
74
75 int  chart_initialise(struct chart *ch);
76
77 void chart_finalise(struct chart *ch);
78
79
80 double chart_rounded_tick(double tick);
81
82 void chart_write_xlabel(struct chart *ch, const char *label);
83 void chart_write_ylabel(struct chart *ch, const char *label);
84
85 void chart_write_title(struct chart *ch, const char *title, ...);
86
87 enum tick_orientation {
88   TICK_ABSCISSA=0,
89   TICK_ORDINATE
90 };
91
92 void draw_tick(struct chart *ch, enum tick_orientation orientation, 
93                double position, const char *label, ...);
94
95
96
97 enum  bar_opts {
98   BAR_GROUPED =  0,
99   BAR_STACKED,
100   BAR_RANGE
101 };
102
103
104 void draw_barchart(struct chart *ch, const char *title, 
105                    const char *xlabel, const char *ylabel, enum bar_opts opt);
106
107 void draw_box_whisker_chart(struct chart *ch, const char *title);
108
109
110
111 struct normal_curve
112 {
113   double N ;
114   double mean ;
115   double stddev ;
116 };
117
118
119 void histogram_write_legend(struct chart *ch, const struct normal_curve *norm);
120
121
122 /* Plot a gsl_histogram */
123 void histogram_plot(const gsl_histogram *hist, const char *factorname,
124                     const struct normal_curve *norm, short show_normal);
125
126
127 /* Create a gsl_histogram and set it's parameters based upon 
128    x_min, x_max and bins. 
129    The caller is responsible for freeing the histogram.
130 */
131 gsl_histogram * histogram_create(double bins, double x_min, double x_max) ;
132
133
134
135
136
137 struct slice {
138   const char *label;
139   double magnetude;
140 };
141
142
143
144
145 /* Draw a piechart */
146 void piechart_plot(const char *title,
147                    const struct slice *slices, int n_slices);
148
149 void draw_scatterplot(struct chart *ch);
150
151
152 void draw_lineplot(struct chart *ch);
153
154
155 /* Set the scale on chart CH.
156    The scale extends from MIN to MAX .
157    TICK is the approximate number of tick marks.
158 */
159
160 void chart_write_xscale(struct chart *ch, 
161                         double min, double max, int ticks);
162
163 void chart_write_yscale(struct chart *ch, 
164                         double min, double max, int ticks);
165
166
167 void chart_datum(struct chart *ch, int dataset, double x, double y);
168
169 struct metrics;
170
171
172 void  boxplot_draw_boxplot(struct chart *ch,
173                            double box_centre, 
174                            double box_width,
175                            struct metrics *m,
176                            const char *name);
177
178
179 void boxplot_draw_yscale(struct chart *ch , double y_max, double y_min);
180
181
182 enum CHART_DIM
183   {
184     CHART_DIM_X,
185     CHART_DIM_Y
186   };
187
188
189 void chart_line(struct chart *ch, double slope, double intercept, 
190                 double limit1, double limit2, enum CHART_DIM limit_d);
191
192
193 #endif
194
195 #if 0
196 The anatomy of a chart is as follows.
197
198 +-------------------------------------------------------------+
199 |            +----------------------------------+             |
200 |            |                                  |             |
201 |            |          Title                   |             |
202 |            |                                  |             |
203 |            +----------------------------------+             |
204 |+----------++----------------------------------++-----------+|
205 ||          ||                                  ||           ||
206 ||          ||                                  ||           ||
207 ||          ||                                  ||           ||
208 ||          ||                                  ||           ||
209 ||          ||                                  ||           ||
210 ||          ||                                  ||           ||
211 ||          ||                                  ||           ||
212 ||          ||                                  ||           ||
213 ||          ||                                  ||           ||
214 ||          ||                                  ||           ||
215 || Ordinate ||            Data                  ||  Legend   ||
216 ||          ||                                  ||           ||
217 ||          ||                                  ||           ||
218 ||          ||                                  ||           ||
219 ||          ||                                  ||           ||
220 ||          ||                                  ||           ||
221 ||          ||                                  ||           ||
222 ||          ||                                  ||           ||
223 ||          ||                                  ||           ||
224 ||          ||                                  ||           ||
225 ||          ||                                  ||           ||       
226 |+----------++----------------------------------++-----------+|   --  
227 |            +----------------------------------+             | -  ^  data_bottom
228 |            |          Abscissa                |             | ^  |             
229 |            |                                  |             | | abscissa_top
230 |            +----------------------------------+             | v  v  
231 +-------------------------------------------------------------+ ----  
232                                                 
233 ordinate_right                                  ||           |
234 |           |                                   ||           |
235 |<--------->|                                   ||           |
236 |            |                                  ||           |
237 | data_left  |                                  ||           |
238 |<---------->|                                  ||           |
239 |                                               ||           |
240 |               data_right                      ||           |
241 |<--------------------------------------------->||           |
242 |                  legend_left                   |           |
243 |<---------------------------------------------->|           |
244 |                    legend_right                            |
245 |<---------------------------------------------------------->|
246                                                              
247 #endif