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
38 static const struct dataset dataset[DATASETS] =
48 write_legend(struct chart *chart, const char *heading, int n);
52 /* Write the abscissa label */
54 chart_write_xlabel(struct chart *ch, const char *label)
57 pl_savestate_r(ch->lp);
59 pl_move_r(ch->lp,ch->data_left, ch->abscissa_top);
60 pl_alabel_r(ch->lp,0,'t',label);
62 pl_restorestate_r(ch->lp);
66 /* Set the scale for the abscissa */
68 chart_write_xscale(struct chart *ch, double min, double max, double tick)
72 ch->x_max = ceil( max / tick ) * tick ;
73 ch->x_min = floor ( min / tick ) * tick ;
75 ch->abscissa_scale = fabs(ch->data_right - ch->data_left) /
76 fabs(ch->x_max - ch->x_min);
78 for(x = ch->x_min ; x <= ch->x_max; x += tick )
79 draw_tick (ch, TICK_ABSCISSA, (x - ch->x_min) * ch->abscissa_scale, "%g", x);
84 /* Set the scale for the ordinate */
86 chart_write_yscale(struct chart *ch, double min, double max, double tick)
90 ch->y_max = ceil( max / tick ) * tick ;
91 ch->y_min = floor ( min / tick ) * tick ;
94 fabs(ch->data_top - ch->data_bottom) / fabs(ch->y_max - ch->y_min) ;
96 for(y = ch->y_min ; y <= ch->y_max; y += tick )
98 draw_tick (ch, TICK_ORDINATE,
99 (y - ch->y_min) * ch->ordinate_scale, "%g", y);
106 /* Write the ordinate label */
108 chart_write_ylabel(struct chart *ch, const char *label)
110 pl_savestate_r(ch->lp);
112 pl_move_r(ch->lp, ch->data_bottom, ch->ordinate_right);
113 pl_textangle_r(ch->lp, 90);
114 pl_alabel_r(ch->lp, 0, 0, label);
116 pl_restorestate_r(ch->lp);
122 write_legend(struct chart *chart, const char *heading,
127 pl_savestate_r(chart->lp);
129 pl_filltype_r(chart->lp,1);
131 pl_move_r(chart->lp, chart->legend_left,
132 chart->data_bottom + chart->font_size * n * 1.5);
134 pl_alabel_r(chart->lp,0,'b',heading);
136 for (ds = 0 ; ds < n ; ++ds )
138 pl_fmove_r(chart->lp,
140 chart->data_bottom + chart->font_size * ds * 1.5);
142 pl_savestate_r(chart->lp);
143 pl_fillcolorname_r(chart->lp,data_colour[ds]);
144 pl_fboxrel_r (chart->lp,
146 chart->font_size, chart->font_size);
147 pl_restorestate_r(chart->lp);
149 pl_fmove_r(chart->lp,
150 chart->legend_left + chart->font_size * 1.5,
151 chart->data_bottom + chart->font_size * ds * 1.5);
153 pl_alabel_r(chart->lp,'l','b',dataset[ds].label);
157 pl_restorestate_r(chart->lp);
161 /* Plot a data point */
163 chart_datum(struct chart *ch, int dataset UNUSED, double x, double y)
166 (x - ch->x_min) * ch->abscissa_scale + ch->data_left ;
169 (y - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
172 pl_savestate_r(ch->lp);
174 pl_fmarker_r(ch->lp, x_pos, y_pos, 6, 15);
176 pl_restorestate_r(ch->lp);
180 /* Draw a line with slope SLOPE and intercept INTERCEPT.
181 between the points limit1 and limit2.
182 If lim_dim is CHART_DIM_Y then the limit{1,2} are on the
183 y axis otherwise the x axis
186 chart_line(struct chart *ch, double slope, double intercept,
187 double limit1, double limit2, enum CHART_DIM lim_dim)
192 if ( lim_dim == CHART_DIM_Y )
194 x1 = ( limit1 - intercept ) / slope ;
195 x2 = ( limit2 - intercept ) / slope ;
203 y1 = slope * x1 + intercept;
204 y2 = slope * x2 + intercept;
207 y1 = (y1 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
208 y2 = (y2 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
209 x1 = (x1 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
210 x2 = (x2 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
212 pl_savestate_r(ch->lp);
214 pl_fline_r(ch->lp, x1, y1, x2, y2);
216 pl_restorestate_r(ch->lp);