aaf7abc850437baf9e24dd283ef48ada7dfa8ffb
[pspp] / 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 char *title, 
119                     struct normal_curve *norm,
120                     int show_normal);
121
122
123 double chart_rounded_tick(double tick);
124
125
126 void draw_piechart(struct chart *ch, const struct variable *v);
127
128 void draw_scatterplot(struct chart *ch);
129
130
131 void draw_lineplot(struct chart *ch);
132
133
134 void chart_write_xscale(struct chart *ch, 
135                         double min, double max, double tick);
136
137 void chart_write_yscale(struct chart *ch, 
138                         double min, double max, double tick);
139
140
141 void chart_datum(struct chart *ch, int dataset, double x, double y);
142
143
144
145 enum CHART_DIM
146   {
147     CHART_DIM_X,
148     CHART_DIM_Y
149   };
150
151
152 void chart_line(struct chart *ch, double slope, double intercept, 
153                 double limit1, double limit2, enum CHART_DIM limit_d);
154
155
156 #endif
157
158 #if 0
159 The anatomy of a chart is as follows.
160
161 +-------------------------------------------------------------+
162 |            +----------------------------------+             |
163 |            |                                  |             |
164 |            |          Title                   |             |
165 |            |                                  |             |
166 |            +----------------------------------+             |
167 |+----------++----------------------------------++-----------+|
168 ||          ||                                  ||           ||
169 ||          ||                                  ||           ||
170 ||          ||                                  ||           ||
171 ||          ||                                  ||           ||
172 ||          ||                                  ||           ||
173 ||          ||                                  ||           ||
174 ||          ||                                  ||           ||
175 ||          ||                                  ||           ||
176 ||          ||                                  ||           ||
177 ||          ||                                  ||           ||
178 || Ordinate ||            Data                  ||  Legend   ||
179 ||          ||                                  ||           ||
180 ||          ||                                  ||           ||
181 ||          ||                                  ||           ||
182 ||          ||                                  ||           ||
183 ||          ||                                  ||           ||
184 ||          ||                                  ||           ||
185 ||          ||                                  ||           ||
186 ||          ||                                  ||           ||
187 ||          ||                                  ||           ||
188 ||          ||                                  ||           ||       
189 |+----------++----------------------------------++-----------+|   --  
190 |            +----------------------------------+             | -  ^  data_bottom
191 |            |          Abscissa                |             | ^  |             
192 |            |                                  |             | | abscissa_top
193 |            +----------------------------------+             | v  v  
194 +-------------------------------------------------------------+ ----  
195                                                 
196 ordinate_right                                  ||           |
197 |           |                                   ||           |
198 |<--------->|                                   ||           |
199 |            |                                  ||           |
200 | data_left  |                                  ||           |
201 |<---------->|                                  ||           |
202 |                                               ||           |
203 |               data_right                      ||           |
204 |<--------------------------------------------->||           |
205 |                  legend_left                   |           |
206 |<---------------------------------------------->|           |
207 |                    legend_right                            |
208 |<---------------------------------------------------------->|
209                                                              
210 #endif