d48a3642a805c3190feffad8fbcaf84c8c31b71c
[pspp-builds.git] / src / output / charts / scree-cairo.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18
19 #include <output/charts/scree.h>
20
21 #include <math.h>
22
23 #include <output/cairo-chart.h>
24
25 #include "gettext.h"
26 #define _(msgid) gettext (msgid)
27
28 void
29 xrchart_draw_scree (const struct chart_item *chart_item, cairo_t *cr,
30                     struct xrchart_geometry *geom)
31 {
32   const struct scree *rc = to_scree (chart_item);
33   size_t i;
34   double min, max;
35
36   xrchart_write_title (cr, geom, _("Scree Plot"));
37   xrchart_write_xlabel (cr, geom, rc->xlabel);
38   xrchart_write_ylabel (cr, geom, _("Eigenvalue"));
39
40   gsl_vector_minmax (rc->eval, &min, &max);
41
42   if ( fabs (max) > fabs (min))
43     max = fabs (max);
44   else
45     max = fabs (min);
46
47   xrchart_write_yscale (cr, geom, 0, max, max);
48   xrchart_write_xscale (cr, geom, 0, rc->eval->size + 1, rc->eval->size + 1);
49
50   xrchart_vector_start (cr, geom, "");
51   for (i = 0 ; i < rc->eval->size; ++i)
52     {
53       const double x = 1 + i;
54       const double y = gsl_vector_get (rc->eval, i);
55       xrchart_vector (cr, geom, x, y);
56     }
57   xrchart_vector_end (cr, geom);
58
59   for (i = 0 ; i < rc->eval->size; ++i)
60     {
61       const double x = 1 + i;
62       const double y = gsl_vector_get (rc->eval, i);
63       xrchart_datum (cr, geom, 0, x, y);
64     }
65 }