X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcharts%2Froc-chart.c;h=0285d6f6a107e8a599e9be7e93e3adf580389548;hb=81579d9e9f994fb2908f50af41c3eb033d216e58;hp=2094ede545c79edb0c264a2c63c0630cfef1339f;hpb=8b71948cd57dbd2787cb4c50525b957e9be8a62b;p=pspp-builds.git diff --git a/src/output/charts/roc-chart.c b/src/output/charts/roc-chart.c index 2094ede5..0285d6f6 100644 --- a/src/output/charts/roc-chart.c +++ b/src/output/charts/roc-chart.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,41 +16,22 @@ #include -#include +#include "output/charts/roc-chart.h" -#include -#include -#include -#include -#include +#include "data/casereader.h" +#include "language/stats/roc.h" +#include "output/chart-item-provider.h" -#include "xalloc.h" +#include "gl/xalloc.h" #include "gettext.h" #define _(msgid) gettext (msgid) -struct roc_var - { - char *name; - struct casereader *cutpoint_reader; - }; - -struct roc_chart - { - struct chart chart; - bool reference; - struct roc_var *vars; - size_t n_vars; - size_t allocated_vars; - }; - -static const struct chart_class roc_chart_class; - struct roc_chart * roc_chart_create (bool reference) { struct roc_chart *rc = xmalloc (sizeof *rc); - chart_init (&rc->chart, &roc_chart_class); + chart_item_init (&rc->chart_item, &roc_chart_class, NULL); rc->reference = reference; rc->vars = NULL; rc->n_vars = 0; @@ -72,61 +53,10 @@ roc_chart_add_var (struct roc_chart *rc, const char *var_name, rv->cutpoint_reader = casereader_clone (cutpoint_reader); } -struct chart * -roc_chart_get_chart (struct roc_chart *rc) -{ - return &rc->chart; -} - static void -roc_chart_draw (const struct chart *chart, cairo_t *cr, - struct chart_geometry *geom) +roc_chart_destroy (struct chart_item *chart_item) { - const struct roc_chart *rc = UP_CAST (chart, struct roc_chart, chart); - size_t i; - - chart_write_title (cr, geom, _("ROC Curve")); - chart_write_xlabel (cr, geom, _("1 - Specificity")); - chart_write_ylabel (cr, geom, _("Sensitivity")); - - chart_write_xscale (cr, geom, 0, 1, 5); - chart_write_yscale (cr, geom, 0, 1, 5); - - if ( rc->reference ) - { - chart_line (cr, geom, 1.0, 0, - 0.0, 1.0, - CHART_DIM_X); - } - - for (i = 0; i < rc->n_vars; ++i) - { - const struct roc_var *rv = &rc->vars[i]; - struct casereader *r = casereader_clone (rv->cutpoint_reader); - struct ccase *cc; - - chart_vector_start (cr, geom, rv->name); - for (; (cc = casereader_read (r)) != NULL; case_unref (cc)) - { - double se = case_data_idx (cc, ROC_TP)->f; - double sp = case_data_idx (cc, ROC_TN)->f; - - se /= case_data_idx (cc, ROC_FN)->f + case_data_idx (cc, ROC_TP)->f ; - sp /= case_data_idx (cc, ROC_TN)->f + case_data_idx (cc, ROC_FP)->f ; - - chart_vector (cr, geom, 1 - sp, se); - } - chart_vector_end (cr, geom); - casereader_destroy (r); - } - - chart_write_legend (cr, geom); -} - -static void -roc_chart_destroy (struct chart *chart) -{ - struct roc_chart *rc = UP_CAST (chart, struct roc_chart, chart); + struct roc_chart *rc = UP_CAST (chart_item, struct roc_chart, chart_item); size_t i; for (i = 0; i < rc->n_vars; i++) @@ -139,10 +69,7 @@ roc_chart_destroy (struct chart *chart) free (rc); } -static const struct chart_class roc_chart_class = +const struct chart_item_class roc_chart_class = { - roc_chart_draw, roc_chart_destroy }; - -