Instead of making system or portable file readers responsible for
[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 "var.h"
27
28
29 /* Array of standard colour names */
30 extern const char *data_colour[];
31
32
33 struct chart {
34
35   plPlotter *lp ;
36   plPlotterParams *pl_params;
37
38   /* The geometry of the chart 
39      See diagram at the foot of this file.
40    */
41   
42   int data_top   ;
43   int data_right ;
44   int data_bottom;
45   int data_left  ;
46
47   int abscissa_top;
48
49   int ordinate_right ;
50
51   int title_bottom ;
52
53   int legend_left ;
54   int legend_right ;
55
56   
57   /* Default font size for the plot (if zero, then use plotter default) */
58   int font_size; 
59
60   char fill_colour[10];
61
62   /* Stuff Particular to Cartesians */
63   double ordinate_scale;
64   double abscissa_scale;
65   double x_min;
66   double x_max;
67   double y_min;
68   double y_max;
69
70 };
71
72
73 int  chart_initialise(struct chart *ch);
74
75 void chart_finalise(struct chart *ch);
76
77
78
79 void chart_write_xlabel(struct chart *ch, const char *label);
80 void chart_write_ylabel(struct chart *ch, const char *label);
81
82 void chart_write_title(struct chart *ch, const char *title, ...);
83
84 enum tick_orientation {
85   TICK_ABSCISSA=0,
86   TICK_ORDINATE
87 };
88
89 void draw_tick(struct chart *ch, enum tick_orientation orientation, 
90                double position, const char *label, ...);
91
92
93
94 enum  bar_opts {
95   BAR_GROUPED =  0,
96   BAR_STACKED,
97   BAR_RANGE
98 };
99
100
101 void draw_barchart(struct chart *ch, const char *title, 
102                    const char *xlabel, const char *ylabel, enum bar_opts opt);
103
104 void draw_box_whisker_chart(struct chart *ch, const char *title);
105
106
107
108 struct normal_curve
109 {
110   double N ;
111   double mean ;
112   double stddev ;
113 };
114
115
116 void draw_histogram(struct chart *ch, 
117                     const struct variable *v,
118                     const struct freq_tab *frq_tab,
119                     const char *title, 
120                     struct normal_curve *norm,
121                     int show_normal);
122
123
124 double chart_rounded_tick(double tick);
125
126
127 void draw_piechart(struct chart *ch, const struct variable *v,
128                    const struct freq_tab *);
129
130 void draw_scatterplot(struct chart *ch);
131
132
133 void draw_lineplot(struct chart *ch);
134
135
136 void chart_write_xscale(struct chart *ch, 
137                         double min, double max, double tick);
138
139 void chart_write_yscale(struct chart *ch, 
140                         double min, double max, double tick);
141
142
143 void chart_datum(struct chart *ch, int dataset, double x, double y);
144
145
146
147 enum CHART_DIM
148   {
149     CHART_DIM_X,
150     CHART_DIM_Y
151   };
152
153
154 void chart_line(struct chart *ch, double slope, double intercept, 
155                 double limit1, double limit2, enum CHART_DIM limit_d);
156
157
158 #endif
159
160 #if 0
161 The anatomy of a chart is as follows.
162
163 +-------------------------------------------------------------+
164 |            +----------------------------------+             |
165 |            |                                  |             |
166 |            |          Title                   |             |
167 |            |                                  |             |
168 |            +----------------------------------+             |
169 |+----------++----------------------------------++-----------+|
170 ||          ||                                  ||           ||
171 ||          ||                                  ||           ||
172 ||          ||                                  ||           ||
173 ||          ||                                  ||           ||
174 ||          ||                                  ||           ||
175 ||          ||                                  ||           ||
176 ||          ||                                  ||           ||
177 ||          ||                                  ||           ||
178 ||          ||                                  ||           ||
179 ||          ||                                  ||           ||
180 || Ordinate ||            Data                  ||  Legend   ||
181 ||          ||                                  ||           ||
182 ||          ||                                  ||           ||
183 ||          ||                                  ||           ||
184 ||          ||                                  ||           ||
185 ||          ||                                  ||           ||
186 ||          ||                                  ||           ||
187 ||          ||                                  ||           ||
188 ||          ||                                  ||           ||
189 ||          ||                                  ||           ||
190 ||          ||                                  ||           ||       
191 |+----------++----------------------------------++-----------+|   --  
192 |            +----------------------------------+             | -  ^  data_bottom
193 |            |          Abscissa                |             | ^  |             
194 |            |                                  |             | | abscissa_top
195 |            +----------------------------------+             | v  v  
196 +-------------------------------------------------------------+ ----  
197                                                 
198 ordinate_right                                  ||           |
199 |           |                                   ||           |
200 |<--------->|                                   ||           |
201 |            |                                  ||           |
202 | data_left  |                                  ||           |
203 |<---------->|                                  ||           |
204 |                                               ||           |
205 |               data_right                      ||           |
206 |<--------------------------------------------->||           |
207 |                  legend_left                   |           |
208 |<---------------------------------------------->|           |
209 |                    legend_right                            |
210 |<---------------------------------------------------------->|
211                                                              
212 #endif