X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcharts%2Fscree.c;h=ffa77568bd975a4c537beef1541d4169cb0cb701;hb=dfd1972f7bcb550a4fc3b05dbe7e71d12334b0a7;hp=44f7c7a60107b86fed41d9209460090f147ec83d;hpb=c9a3c45e44c1c03d13d4eb186e3817bc836f75f8;p=pspp-builds.git diff --git a/src/output/charts/scree.c b/src/output/charts/scree.c index 44f7c7a6..ffa77568 100644 --- a/src/output/charts/scree.c +++ b/src/output/charts/scree.c @@ -18,94 +18,38 @@ #include -#include -#include -#include +#include -#include - -#include "xalloc.h" +#include "gl/xalloc.h" #include "gettext.h" #define _(msgid) gettext (msgid) -struct scree - { - struct chart chart; - const gsl_vector *eval; - const char *xlabel; - }; - -static const struct chart_class scree_class; - struct scree * scree_create (const gsl_vector *eigenvalues, const char *xlabel) { struct scree *rc = xmalloc (sizeof *rc); - chart_init (&rc->chart, &scree_class); - rc->eval = eigenvalues; - rc->xlabel = xlabel; - return rc; -} - - -struct chart * -scree_get_chart (struct scree *rc) -{ - return &rc->chart; -} - -static void -scree_draw (const struct chart *chart, cairo_t *cr, - struct chart_geometry *geom) -{ - const struct scree *rc = UP_CAST (chart, struct scree, chart); - size_t i; - double min, max; - - chart_write_title (cr, geom, _("Scree Plot")); - chart_write_xlabel (cr, geom, rc->xlabel); - chart_write_ylabel (cr, geom, _("Eigenvalue")); + chart_item_init (&rc->chart_item, &scree_class, NULL); - gsl_vector_minmax (rc->eval, &min, &max); + rc->eval = gsl_vector_alloc (eigenvalues->size); + gsl_vector_memcpy (rc->eval, eigenvalues); - if ( fabs (max) > fabs (min)) - max = fabs (max); - else - max = fabs (min); + rc->xlabel = xstrdup (xlabel); - chart_write_yscale (cr, geom, 0, max, max); - chart_write_xscale (cr, geom, 0, rc->eval->size + 1, rc->eval->size + 1); - - chart_vector_start (cr, geom, ""); - for (i = 0 ; i < rc->eval->size; ++i) - { - const double x = 1 + i; - const double y = gsl_vector_get (rc->eval, i); - chart_vector (cr, geom, x, y); - } - chart_vector_end (cr, geom); - - for (i = 0 ; i < rc->eval->size; ++i) - { - const double x = 1 + i; - const double y = gsl_vector_get (rc->eval, i); - chart_datum (cr, geom, 0, x, y); - } + return rc; } static void -scree_destroy (struct chart *chart) +scree_destroy (struct chart_item *chart_item) { - struct scree *rc = UP_CAST (chart, struct scree, chart); + struct scree *rc = to_scree (chart_item); + gsl_vector_free (rc->eval); + free (rc->xlabel); free (rc); } -static const struct chart_class scree_class = +const struct chart_item_class scree_class = { - scree_draw, scree_destroy }; - -