X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcharts%2Froc-chart.c;h=5af8f27ff35ee93eeb8ede9086ce738e71d24944;hb=dfd1972f7bcb550a4fc3b05dbe7e71d12334b0a7;hp=2094ede545c79edb0c264a2c63c0630cfef1339f;hpb=c9a3c45e44c1c03d13d4eb186e3817bc836f75f8;p=pspp-builds.git diff --git a/src/output/charts/roc-chart.c b/src/output/charts/roc-chart.c index 2094ede5..5af8f27f 100644 --- a/src/output/charts/roc-chart.c +++ b/src/output/charts/roc-chart.c @@ -18,9 +18,7 @@ #include -#include -#include -#include +#include #include #include @@ -29,28 +27,11 @@ #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 }; - -