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