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
37 const char *data_colour[] = {
56 struct outp_driver *d;
58 chart = xmalloc(sizeof(struct chart) );
60 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
62 assert(d->class->initialise_chart);
63 d->class->initialise_chart(d, chart);
70 if (pl_openpl_r (chart->lp) < 0) /* open Plotter */
73 pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */
74 pl_flinewidth_r (chart->lp, 0.25); /* set line thickness */
75 pl_pencolorname_r (chart->lp, "black");
77 pl_erase_r (chart->lp); /* erase graphics display */
78 pl_filltype_r(chart->lp,0);
82 pl_savestate_r(chart->lp);
84 /* Set default chartetry */
85 chart->data_top = 900;
86 chart->data_right = 800;
87 chart->data_bottom = 120;
88 chart->data_left = 150;
89 chart->abscissa_top = 70;
90 chart->ordinate_right = 120;
91 chart->title_bottom = 920;
92 chart->legend_left = 810;
93 chart->legend_right = 1000;
95 strcpy(chart->fill_colour,"red");
98 /* Get default font size */
99 if ( !chart->font_size)
100 chart->font_size = pl_fontsize_r(chart->lp, -1);
102 /* Draw the data area */
104 chart->data_left, chart->data_bottom,
105 chart->data_right, chart->data_top);
113 /* Draw a tick mark at position
114 If label is non zero, then print it at the tick mark
117 draw_tick(struct chart *chart,
118 enum tick_orientation orientation,
120 const char *label, ...)
122 const int tickSize = 10;
126 pl_savestate_r(chart->lp);
128 pl_move_r(chart->lp, chart->data_left, chart->data_bottom);
130 if ( orientation == TICK_ABSCISSA )
131 pl_flinerel_r(chart->lp, position, 0, position, -tickSize);
132 else if (orientation == TICK_ORDINATE )
133 pl_flinerel_r(chart->lp, 0, position, -tickSize, position);
141 vsnprintf(buf,10,label,ap);
143 if ( orientation == TICK_ABSCISSA )
144 pl_alabel_r(chart->lp, 'c','t', buf);
145 else if (orientation == TICK_ORDINATE )
147 if ( fabs(position) < DBL_EPSILON )
148 pl_moverel_r(chart->lp, 0, 10);
150 pl_alabel_r(chart->lp, 'r','c', buf);
156 pl_restorestate_r(chart->lp);
162 /* Write the title on a chart*/
164 chart_write_title(struct chart *chart, const char *title, ...)
171 pl_savestate_r(chart->lp);
172 pl_ffontsize_r(chart->lp,chart->font_size * 1.5);
173 pl_move_r(chart->lp,chart->data_left, chart->title_bottom);
176 vsnprintf(buf,100,title,ap);
177 pl_alabel_r(chart->lp,0,0,buf);
180 pl_restorestate_r(chart->lp);
184 extern struct som_table_class tab_table_class;
187 chart_submit(struct chart *chart)
194 pl_restorestate_r(chart->lp);
196 s.class = &tab_table_class;
201 if (pl_closepl_r (chart->lp) < 0) /* close Plotter */
203 fprintf (stderr, "Couldn't close Plotter\n");
206 pl_deletepl_r(chart->lp);
208 pl_deleteplparams(chart->pl_params);
215 /* Set the scale for the abscissa */
217 chart_write_xscale(struct chart *ch, double min, double max, int ticks)
221 const double tick_interval =
222 chart_rounded_tick( (max - min) / (double) ticks);
227 ch->x_max = ceil( max / tick_interval ) * tick_interval ;
228 ch->x_min = floor ( min / tick_interval ) * tick_interval ;
231 ch->abscissa_scale = fabs(ch->data_right - ch->data_left) /
232 fabs(ch->x_max - ch->x_min);
234 for(x = ch->x_min ; x <= ch->x_max; x += tick_interval )
236 draw_tick (ch, TICK_ABSCISSA,
237 (x - ch->x_min) * ch->abscissa_scale, "%g", x);
243 /* Set the scale for the ordinate */
245 chart_write_yscale(struct chart *ch, double smin, double smax, int ticks)
249 const double tick_interval =
250 chart_rounded_tick( (smax - smin) / (double) ticks);
256 ch->y_max = ceil ( smax / tick_interval ) * tick_interval ;
257 ch->y_min = floor ( smin / tick_interval ) * tick_interval ;
260 fabs(ch->data_top - ch->data_bottom) / fabs(ch->y_max - ch->y_min) ;
262 for(y = ch->y_min ; y <= ch->y_max; y += tick_interval )
264 draw_tick (ch, TICK_ORDINATE,
265 (y - ch->y_min) * ch->ordinate_scale, "%g", y);