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., 51 Franklin Street, Fifth Floor, 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)
59 pl_savestate_r(ch->lp);
61 pl_move_r(ch->lp,ch->data_left, ch->abscissa_top);
62 pl_alabel_r(ch->lp,0,'t',label);
64 pl_restorestate_r(ch->lp);
70 /* Write the ordinate label */
72 chart_write_ylabel(struct chart *ch, const char *label)
77 pl_savestate_r(ch->lp);
79 pl_move_r(ch->lp, ch->data_bottom, ch->ordinate_right);
80 pl_textangle_r(ch->lp, 90);
81 pl_alabel_r(ch->lp, 0, 0, label);
83 pl_restorestate_r(ch->lp);
89 write_legend(struct chart *chart, const char *heading,
98 pl_savestate_r(chart->lp);
100 pl_filltype_r(chart->lp,1);
102 pl_move_r(chart->lp, chart->legend_left,
103 chart->data_bottom + chart->font_size * n * 1.5);
105 pl_alabel_r(chart->lp,0,'b',heading);
107 for (ds = 0 ; ds < n ; ++ds )
109 pl_fmove_r(chart->lp,
111 chart->data_bottom + chart->font_size * ds * 1.5);
113 pl_savestate_r(chart->lp);
114 pl_fillcolorname_r(chart->lp,data_colour[ds]);
115 pl_fboxrel_r (chart->lp,
117 chart->font_size, chart->font_size);
118 pl_restorestate_r(chart->lp);
120 pl_fmove_r(chart->lp,
121 chart->legend_left + chart->font_size * 1.5,
122 chart->data_bottom + chart->font_size * ds * 1.5);
124 pl_alabel_r(chart->lp,'l','b',dataset[ds].label);
128 pl_restorestate_r(chart->lp);
132 /* Plot a data point */
134 chart_datum(struct chart *ch, int dataset UNUSED, double x, double y)
141 (x - ch->x_min) * ch->abscissa_scale + ch->data_left ;
144 (y - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
146 pl_savestate_r(ch->lp);
148 pl_fmarker_r(ch->lp, x_pos, y_pos, 6, 15);
150 pl_restorestate_r(ch->lp);
154 /* Draw a line with slope SLOPE and intercept INTERCEPT.
155 between the points limit1 and limit2.
156 If lim_dim is CHART_DIM_Y then the limit{1,2} are on the
157 y axis otherwise the x axis
160 chart_line(struct chart *ch, double slope, double intercept,
161 double limit1, double limit2, enum CHART_DIM lim_dim)
170 if ( lim_dim == CHART_DIM_Y )
172 x1 = ( limit1 - intercept ) / slope ;
173 x2 = ( limit2 - intercept ) / slope ;
181 y1 = slope * x1 + intercept;
182 y2 = slope * x2 + intercept;
185 y1 = (y1 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
186 y2 = (y2 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
187 x1 = (x1 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
188 x2 = (x2 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
190 pl_savestate_r(ch->lp);
192 pl_fline_r(ch->lp, x1, y1, x2, y2);
194 pl_restorestate_r(ch->lp);