1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009 Free Software Foundation, Inc.
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.
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.
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/>. */
19 #include <output/charts/scree.h>
21 #include <output/chart-provider.h>
22 #include <output/charts/cartesian.h>
23 #include <output/charts/plot-chart.h>
25 #include <gsl/gsl_vector.h>
30 #define _(msgid) gettext (msgid)
35 const gsl_vector *eval;
39 static const struct chart_class scree_class;
42 scree_create (const gsl_vector *eigenvalues, const char *xlabel)
44 struct scree *rc = xmalloc (sizeof *rc);
45 chart_init (&rc->chart, &scree_class);
46 rc->eval = eigenvalues;
53 scree_get_chart (struct scree *rc)
59 scree_draw (const struct chart *chart, cairo_t *cr,
60 struct chart_geometry *geom)
62 const struct scree *rc = UP_CAST (chart, struct scree, chart);
66 chart_write_title (cr, geom, _("Scree Plot"));
67 chart_write_xlabel (cr, geom, rc->xlabel);
68 chart_write_ylabel (cr, geom, _("Eigenvalue"));
70 gsl_vector_minmax (rc->eval, &min, &max);
72 if ( fabs (max) > fabs (min))
77 chart_write_yscale (cr, geom, 0, max, max);
78 chart_write_xscale (cr, geom, 0, rc->eval->size + 1, rc->eval->size + 1);
80 chart_vector_start (cr, geom, "");
81 for (i = 0 ; i < rc->eval->size; ++i)
83 const double x = 1 + i;
84 const double y = gsl_vector_get (rc->eval, i);
85 chart_vector (cr, geom, x, y);
87 chart_vector_end (cr, geom);
89 for (i = 0 ; i < rc->eval->size; ++i)
91 const double x = 1 + i;
92 const double y = gsl_vector_get (rc->eval, i);
93 chart_datum (cr, geom, 0, x, y);
98 scree_destroy (struct chart *chart)
100 struct scree *rc = UP_CAST (chart, struct scree, chart);
105 static const struct chart_class scree_class =