47c6c7d83198983823cac28cf2e60083b602b68a
[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 };
63
64
65 int  chart_initialise(struct chart *ch);
66
67 void chart_finalise(struct chart *ch);
68
69
70
71 void chart_write_title(struct chart *ch, 
72                       const char *title);
73
74 enum tick_orientation {
75   TICK_ABSCISSA=0,
76   TICK_ORDINATE
77 };
78
79 void draw_tick(struct chart *ch, enum tick_orientation orientation, 
80                double position, const char *label, ...);
81
82
83
84 enum  bar_opts {
85   BAR_GROUPED =  0,
86   BAR_STACKED,
87   BAR_RANGE
88 };
89
90
91 void draw_barchart(struct chart *ch, const char *title, 
92                    const char *xlabel, const char *ylabel, enum bar_opts opt);
93
94 void draw_box_whisker_chart(struct chart *ch, const char *title);
95
96
97
98 struct normal_curve
99 {
100   double N ;
101   double mean ;
102   double stddev ;
103 };
104
105
106 void draw_histogram(struct chart *ch, 
107                     const struct variable *v,
108                     const char *title, 
109                     struct normal_curve *norm,
110                     int show_normal);
111
112
113
114 void draw_piechart(struct chart *ch, const struct variable *v);
115
116 void draw_scatterplot(struct chart *ch, const char *title, 
117                       const char *xlabel, const char *ylabel);
118
119
120 void draw_lineplot(struct chart *ch, const char *title, 
121                       const char *xlabel, const char *ylabel);
122
123
124
125 #endif
126
127 #if 0
128 The anatomy of a chart is as follows.
129
130 +-------------------------------------------------------------+
131 |            +----------------------------------+             |
132 |            |                                  |             |
133 |            |          Title                   |             |
134 |            |                                  |             |
135 |            +----------------------------------+             |
136 |+----------++----------------------------------++-----------+|
137 ||          ||                                  ||           ||
138 ||          ||                                  ||           ||
139 ||          ||                                  ||           ||
140 ||          ||                                  ||           ||
141 ||          ||                                  ||           ||
142 ||          ||                                  ||           ||
143 ||          ||                                  ||           ||
144 ||          ||                                  ||           ||
145 ||          ||                                  ||           ||
146 ||          ||                                  ||           ||
147 || Ordinate ||            Data                  ||  Legend   ||
148 ||          ||                                  ||           ||
149 ||          ||                                  ||           ||
150 ||          ||                                  ||           ||
151 ||          ||                                  ||           ||
152 ||          ||                                  ||           ||
153 ||          ||                                  ||           ||
154 ||          ||                                  ||           ||
155 ||          ||                                  ||           ||
156 ||          ||                                  ||           ||
157 ||          ||                                  ||           ||       
158 |+----------++----------------------------------++-----------+|   --  
159 |            +----------------------------------+             | -  ^  data_bottom
160 |            |          Abscissa                |             | ^  |             
161 |            |                                  |             | | abscissa_top
162 |            +----------------------------------+             | v  v  
163 +-------------------------------------------------------------+ ----  
164                                                 
165 ordinate_right                                  ||           |
166 |           |                                   ||           |
167 |<--------->|                                   ||           |
168 |            |                                  ||           |
169 | data_left  |                                  ||           |
170 |<---------->|                                  ||           |
171 |                                               ||           |
172 |               data_right                      ||           |
173 |<--------------------------------------------->||           |
174 |                  legend_left                   |           |
175 |<---------------------------------------------->|           |
176 |                    legend_right                            |
177 |<---------------------------------------------------------->|
178                                                              
179 #endif