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
24 #include <output/chart.h>
26 #include <output/charts/plot-chart.h>
27 #include <output/charts/cartesian.h>
28 #include <libpspp/compiler.h>
41 static const struct dataset dataset[DATASETS] =
51 write_legend(struct chart *chart, const char *heading, int n);
55 /* Write the abscissa label */
57 chart_write_xlabel(struct chart *ch, const char *label)
62 pl_savestate_r(ch->lp);
64 pl_move_r(ch->lp,ch->data_left, ch->abscissa_top);
65 pl_alabel_r(ch->lp,0,'t',label);
67 pl_restorestate_r(ch->lp);
73 /* Write the ordinate label */
75 chart_write_ylabel(struct chart *ch, const char *label)
80 pl_savestate_r(ch->lp);
82 pl_move_r(ch->lp, ch->data_bottom, ch->ordinate_right);
83 pl_textangle_r(ch->lp, 90);
84 pl_alabel_r(ch->lp, 0, 0, label);
86 pl_restorestate_r(ch->lp);
92 write_legend(struct chart *chart, const char *heading,
101 pl_savestate_r(chart->lp);
103 pl_filltype_r(chart->lp,1);
105 pl_move_r(chart->lp, chart->legend_left,
106 chart->data_bottom + chart->font_size * n * 1.5);
108 pl_alabel_r(chart->lp,0,'b',heading);
110 for (ds = 0 ; ds < n ; ++ds )
112 pl_fmove_r(chart->lp,
114 chart->data_bottom + chart->font_size * ds * 1.5);
116 pl_savestate_r(chart->lp);
117 pl_fillcolorname_r(chart->lp,data_colour[ds]);
118 pl_fboxrel_r (chart->lp,
120 chart->font_size, chart->font_size);
121 pl_restorestate_r(chart->lp);
123 pl_fmove_r(chart->lp,
124 chart->legend_left + chart->font_size * 1.5,
125 chart->data_bottom + chart->font_size * ds * 1.5);
127 pl_alabel_r(chart->lp,'l','b',dataset[ds].label);
131 pl_restorestate_r(chart->lp);
135 /* Plot a data point */
137 chart_datum(struct chart *ch, int dataset UNUSED, double x, double y)
144 (x - ch->x_min) * ch->abscissa_scale + ch->data_left ;
147 (y - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
149 pl_savestate_r(ch->lp);
151 pl_fmarker_r(ch->lp, x_pos, y_pos, 6, 15);
153 pl_restorestate_r(ch->lp);
157 /* Draw a line with slope SLOPE and intercept INTERCEPT.
158 between the points limit1 and limit2.
159 If lim_dim is CHART_DIM_Y then the limit{1,2} are on the
160 y axis otherwise the x axis
163 chart_line(struct chart *ch, double slope, double intercept,
164 double limit1, double limit2, enum CHART_DIM lim_dim)
173 if ( lim_dim == CHART_DIM_Y )
175 x1 = ( limit1 - intercept ) / slope ;
176 x2 = ( limit2 - intercept ) / slope ;
184 y1 = slope * x1 + intercept;
185 y2 = slope * x2 + intercept;
188 y1 = (y1 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
189 y2 = (y2 - ch->y_min) * ch->ordinate_scale + ch->data_bottom ;
190 x1 = (x1 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
191 x2 = (x2 - ch->x_min) * ch->abscissa_scale + ch->data_left ;
193 pl_savestate_r(ch->lp);
195 pl_fline_r(ch->lp, x1, y1, x2, y2);
197 pl_restorestate_r(ch->lp);