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
30 #include "chart-geometry.h"
31 #include "plot-chart.h"
36 #include "plot-chart.h"
38 const char *data_colour[] = {
52 /* Draw a tick mark at position
53 If label is non zero, then print it at the tick mark
56 draw_tick(struct chart *chart,
57 enum tick_orientation orientation,
59 const char *label, ...)
61 const int tickSize = 10;
65 pl_savestate_r(chart->lp);
67 pl_move_r(chart->lp, chart->data_left, chart->data_bottom);
69 if ( orientation == TICK_ABSCISSA )
70 pl_flinerel_r(chart->lp, position, 0, position, -tickSize);
71 else if (orientation == TICK_ORDINATE )
72 pl_flinerel_r(chart->lp, 0, position, -tickSize, position);
80 vsnprintf(buf,10,label,ap);
82 if ( orientation == TICK_ABSCISSA )
83 pl_alabel_r(chart->lp, 'c','t', buf);
84 else if (orientation == TICK_ORDINATE )
86 if ( fabs(position) < DBL_EPSILON )
87 pl_moverel_r(chart->lp, 0, 10);
89 pl_alabel_r(chart->lp, 'r','c', buf);
95 pl_restorestate_r(chart->lp);
99 /* Write the title on a chart*/
101 chart_write_title(struct chart *chart, const char *title, ...)
109 pl_savestate_r(chart->lp);
110 pl_ffontsize_r(chart->lp,chart->font_size * 1.5);
111 pl_move_r(chart->lp,chart->data_left, chart->title_bottom);
114 vsnprintf(buf,100,title,ap);
115 pl_alabel_r(chart->lp,0,0,buf);
118 pl_restorestate_r(chart->lp);
122 /* Set the scale for the abscissa */
124 chart_write_xscale(struct chart *ch, double min, double max, int ticks)
128 const double tick_interval =
129 chart_rounded_tick( (max - min) / (double) ticks);
134 ch->x_max = ceil( max / tick_interval ) * tick_interval ;
135 ch->x_min = floor ( min / tick_interval ) * tick_interval ;
138 ch->abscissa_scale = fabs(ch->data_right - ch->data_left) /
139 fabs(ch->x_max - ch->x_min);
141 for(x = ch->x_min ; x <= ch->x_max; x += tick_interval )
143 draw_tick (ch, TICK_ABSCISSA,
144 (x - ch->x_min) * ch->abscissa_scale, "%g", x);
150 /* Set the scale for the ordinate */
152 chart_write_yscale(struct chart *ch, double smin, double smax, int ticks)
156 const double tick_interval =
157 chart_rounded_tick( (smax - smin) / (double) ticks);
162 ch->y_max = ceil ( smax / tick_interval ) * tick_interval ;
163 ch->y_min = floor ( smin / tick_interval ) * tick_interval ;
166 fabs(ch->data_top - ch->data_bottom) / fabs(ch->y_max - ch->y_min) ;
168 for(y = ch->y_min ; y <= ch->y_max; y += tick_interval )
170 draw_tick (ch, TICK_ORDINATE,
171 (y - ch->y_min) * ch->ordinate_scale, "%g", y);