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
37 const char *data_colour[] = {
55 struct outp_driver *d;
57 d = outp_drivers (NULL);
61 chart = xmalloc(sizeof(struct chart) );
62 d->class->initialise_chart(d, chart);
69 if (pl_openpl_r (chart->lp) < 0) /* open Plotter */
72 pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */
73 pl_flinewidth_r (chart->lp, 0.25); /* set line thickness */
74 pl_pencolorname_r (chart->lp, "black");
76 pl_erase_r (chart->lp); /* erase graphics display */
77 pl_filltype_r(chart->lp,0);
79 pl_savestate_r(chart->lp);
81 /* Set default chartetry */
82 chart->data_top = 900;
83 chart->data_right = 800;
84 chart->data_bottom = 120;
85 chart->data_left = 150;
86 chart->abscissa_top = 70;
87 chart->ordinate_right = 120;
88 chart->title_bottom = 920;
89 chart->legend_left = 810;
90 chart->legend_right = 1000;
92 strcpy(chart->fill_colour,"red");
94 /* Get default font size */
95 if ( !chart->font_size)
96 chart->font_size = pl_fontsize_r(chart->lp, -1);
98 /* Draw the data area */
100 chart->data_left, chart->data_bottom,
101 chart->data_right, chart->data_top);
106 /* Draw a tick mark at position
107 If label is non zero, then print it at the tick mark
110 draw_tick(struct chart *chart,
111 enum tick_orientation orientation,
113 const char *label, ...)
115 const int tickSize = 10;
119 pl_savestate_r(chart->lp);
121 pl_move_r(chart->lp, chart->data_left, chart->data_bottom);
123 if ( orientation == TICK_ABSCISSA )
124 pl_flinerel_r(chart->lp, position, 0, position, -tickSize);
125 else if (orientation == TICK_ORDINATE )
126 pl_flinerel_r(chart->lp, 0, position, -tickSize, position);
134 vsnprintf(buf,10,label,ap);
136 if ( orientation == TICK_ABSCISSA )
137 pl_alabel_r(chart->lp, 'c','t', buf);
138 else if (orientation == TICK_ORDINATE )
140 if ( fabs(position) < DBL_EPSILON )
141 pl_moverel_r(chart->lp, 0, 10);
143 pl_alabel_r(chart->lp, 'r','c', buf);
149 pl_restorestate_r(chart->lp);
155 /* Write the title on a chart*/
157 chart_write_title(struct chart *chart, const char *title, ...)
165 pl_savestate_r(chart->lp);
166 pl_ffontsize_r(chart->lp,chart->font_size * 1.5);
167 pl_move_r(chart->lp,chart->data_left, chart->title_bottom);
170 vsnprintf(buf,100,title,ap);
171 pl_alabel_r(chart->lp,0,0,buf);
174 pl_restorestate_r(chart->lp);
178 extern struct som_table_class tab_table_class;
181 chart_submit(struct chart *chart)
184 struct outp_driver *d;
189 pl_restorestate_r(chart->lp);
191 s.class = &tab_table_class;
196 if (pl_closepl_r (chart->lp) < 0) /* close Plotter */
198 fprintf (stderr, "Couldn't close Plotter\n");
201 pl_deletepl_r(chart->lp);
203 pl_deleteplparams(chart->pl_params);
205 d = outp_drivers (NULL);
206 d->class->finalise_chart(d, chart);
211 /* Set the scale for the abscissa */
213 chart_write_xscale(struct chart *ch, double min, double max, int ticks)
217 const double tick_interval =
218 chart_rounded_tick( (max - min) / (double) ticks);
223 ch->x_max = ceil( max / tick_interval ) * tick_interval ;
224 ch->x_min = floor ( min / tick_interval ) * tick_interval ;
227 ch->abscissa_scale = fabs(ch->data_right - ch->data_left) /
228 fabs(ch->x_max - ch->x_min);
230 for(x = ch->x_min ; x <= ch->x_max; x += tick_interval )
232 draw_tick (ch, TICK_ABSCISSA,
233 (x - ch->x_min) * ch->abscissa_scale, "%g", x);
239 /* Set the scale for the ordinate */
241 chart_write_yscale(struct chart *ch, double smin, double smax, int ticks)
245 const double tick_interval =
246 chart_rounded_tick( (smax - smin) / (double) ticks);
252 ch->y_max = ceil ( smax / tick_interval ) * tick_interval ;
253 ch->y_min = floor ( smin / tick_interval ) * tick_interval ;
256 fabs(ch->data_top - ch->data_bottom) / fabs(ch->y_max - ch->y_min) ;
258 for(y = ch->y_min ; y <= ch->y_max; y += tick_interval )
260 draw_tick (ch, TICK_ORDINATE,
261 (y - ch->y_min) * ch->ordinate_scale, "%g", y);