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);
68 /* Write the ordinate label */
70 chart_write_ylabel(struct chart *ch, const char *label)
72 pl_savestate_r(ch->lp);
74 pl_move_r(ch->lp, ch->data_bottom, ch->ordinate_right);
75 pl_textangle_r(ch->lp, 90);
76 pl_alabel_r(ch->lp, 0, 0, label);
78 pl_restorestate_r(ch->lp);
84 write_legend(struct chart *chart, const char *heading,
89 pl_savestate_r(chart->lp);
91 pl_filltype_r(chart->lp,1);
93 pl_move_r(chart->lp, chart->legend_left,
94 chart->data_bottom + chart->font_size * n * 1.5);
96 pl_alabel_r(chart->lp,0,'b',heading);
98 for (ds = 0 ; ds < n ; ++ds )
100 pl_fmove_r(chart->lp,
102 chart->data_bottom + chart->font_size * ds * 1.5);
104 pl_savestate_r(chart->lp);
105 pl_fillcolorname_r(chart->lp,data_colour[ds]);
106 pl_fboxrel_r (chart->lp,
108 chart->font_size, chart->font_size);
109 pl_restorestate_r(chart->lp);
111 pl_fmove_r(chart->lp,
112 chart->legend_left + chart->font_size * 1.5,
113 chart->data_bottom + chart->font_size * ds * 1.5);
115 pl_alabel_r(chart->lp,'l','b',dataset[ds].label);
119 pl_restorestate_r(chart->lp);
123 /* Plot a data point */
125 chart_datum(struct chart *ch, int dataset UNUSED, double x, double y)
128 (x - ch->x_min) * ch->abscissa_scale + ch->data_left ;
131 (y - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
134 pl_savestate_r(ch->lp);
136 pl_fmarker_r(ch->lp, x_pos, y_pos, 6, 15);
138 pl_restorestate_r(ch->lp);
142 /* Draw a line with slope SLOPE and intercept INTERCEPT.
143 between the points limit1 and limit2.
144 If lim_dim is CHART_DIM_Y then the limit{1,2} are on the
145 y axis otherwise the x axis
148 chart_line(struct chart *ch, double slope, double intercept,
149 double limit1, double limit2, enum CHART_DIM lim_dim)
154 if ( lim_dim == CHART_DIM_Y )
156 x1 = ( limit1 - intercept ) / slope ;
157 x2 = ( limit2 - intercept ) / slope ;
165 y1 = slope * x1 + intercept;
166 y2 = slope * x2 + intercept;
169 y1 = (y1 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
170 y2 = (y2 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
171 x1 = (x1 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
172 x2 = (x2 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
174 pl_savestate_r(ch->lp);
176 pl_fline_r(ch->lp, x1, y1, x2, y2);
178 pl_restorestate_r(ch->lp);