1 /* PSPP - computes sample statistics.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by John Darrington <john@darrington.wattle.id.au>
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.
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.
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
28 #define SUB_CATAGORIES 3
32 static const double x_min = 0;
33 static const double x_max = 15.0;
35 static const char *cat_labels[] =
54 static const double data1[] =
68 static const double data2[] =
80 static const double data3[] =
83 0, 45,23, 9, 40, 24,4, 8
87 static const char subcat_name[]="Gender";
95 static const struct subcat sub_catagory[SUB_CATAGORIES] =
104 static const double y_min = 0;
105 static const double y_max = 120.0;
106 static const double y_tick = 20.0;
110 static void write_legend(struct chart *chart) ;
114 draw_barchart(struct chart *ch, const char *title,
115 const char *xlabel, const char *ylabel, enum bar_opts opt)
121 double interval_size = fabs(ch->data_right - ch->data_left) / ( CATAGORIES );
123 double bar_width = interval_size / 1.1 ;
125 if ( opt != BAR_STACKED )
126 bar_width /= SUB_CATAGORIES;
128 double ordinate_scale = fabs(ch->data_top - ch->data_bottom) / fabs(y_max - y_min) ;
130 /* Move to data bottom-left */
131 pl_move_r(ch->lp, ch->data_left, ch->data_bottom);
133 pl_savestate_r(ch->lp);
134 pl_filltype_r(ch->lp,1);
137 for (i = 0 ; i < CATAGORIES ; ++i )
141 double x = i * interval_size;
143 pl_savestate_r(ch->lp);
145 draw_tick (ch, TICK_ABSCISSA, x + (interval_size/2 ),
148 for(sc = 0 ; sc < SUB_CATAGORIES ; ++sc )
151 pl_savestate_r(ch->lp);
152 pl_fillcolorname_r(ch->lp,data_colour[sc]);
158 x + (sc * bar_width ), 0,
159 x + (sc + 1) * bar_width,
160 sub_catagory[sc].data[i] * ordinate_scale );
169 ystart + sub_catagory[sc].data[i] * ordinate_scale );
171 ystart += sub_catagory[sc].data[i] * ordinate_scale ;
178 pl_restorestate_r(ch->lp);
181 pl_restorestate_r(ch->lp);
183 pl_restorestate_r(ch->lp);
185 for ( d = y_min; d <= y_max ; d += y_tick )
188 draw_tick (ch, TICK_ORDINATE,
189 (d - y_min ) * ordinate_scale, "%g", d);
193 /* Write the abscissa label */
194 pl_move_r(ch->lp,ch->data_left, ch->abscissa_top);
195 pl_alabel_r(ch->lp,0,'t',xlabel);
198 /* Write the ordinate label */
199 pl_savestate_r(ch->lp);
200 pl_move_r(ch->lp,ch->data_bottom, ch->ordinate_right);
201 pl_textangle_r(ch->lp,90);
202 pl_alabel_r(ch->lp,0,0,ylabel);
203 pl_restorestate_r(ch->lp);
206 chart_write_title(ch, title);
218 write_legend(struct chart *chart)
222 pl_savestate_r(chart->lp);
224 pl_filltype_r(chart->lp,1);
226 pl_move_r(chart->lp, chart->legend_left,
227 chart->data_bottom + chart->font_size * SUB_CATAGORIES * 1.5);
229 pl_alabel_r(chart->lp,0,'b',subcat_name);
231 for (sc = 0 ; sc < SUB_CATAGORIES ; ++sc )
233 pl_fmove_r(chart->lp,
235 chart->data_bottom + chart->font_size * sc * 1.5);
237 pl_savestate_r(chart->lp);
238 pl_fillcolorname_r(chart->lp,data_colour[sc]);
239 pl_fboxrel_r (chart->lp,
241 chart->font_size, chart->font_size);
242 pl_restorestate_r(chart->lp);
244 pl_fmove_r(chart->lp,
245 chart->legend_left + chart->font_size * 1.5,
246 chart->data_bottom + chart->font_size * sc * 1.5);
248 pl_alabel_r(chart->lp,'l','b',sub_catagory[sc].label);
252 pl_restorestate_r(chart->lp);