Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / output / charts / roc-chart-cairo.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2009, 2011 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/roc-chart.h"
20
21 #include "data/case.h"
22 #include "data/casereader.h"
23 #include "language/stats/roc.h"
24 #include "output/cairo-chart.h"
25
26 #include "gettext.h"
27 #define _(msgid) gettext (msgid)
28
29 void
30 xrchart_draw_roc (const struct chart_item *chart_item, cairo_t *cr,
31                   struct xrchart_geometry *geom)
32 {
33   const struct roc_chart *rc = to_roc_chart (chart_item);
34   size_t i;
35
36   xrchart_write_title (cr, geom, _("ROC Curve"));
37   xrchart_write_xlabel (cr, geom, _("1 - Specificity"));
38   xrchart_write_ylabel (cr, geom, _("Sensitivity"));
39
40   xrchart_write_xscale (cr, geom, 0, 1, 5);
41   xrchart_write_yscale (cr, geom, 0, 1, 5);
42
43   if ( rc->reference )
44     {
45       xrchart_line (cr, geom, 1.0, 0,
46                     0.0, 1.0,
47                     XRCHART_DIM_X);
48     }
49
50   for (i = 0; i < rc->n_vars; ++i)
51     {
52       const struct roc_var *rv = &rc->vars[i];
53       struct casereader *r = casereader_clone (rv->cutpoint_reader);
54       struct ccase *cc;
55
56       xrchart_vector_start (cr, geom, rv->name);
57       for (; (cc = casereader_read (r)) != NULL; case_unref (cc))
58         {
59           double se = case_data_idx (cc, ROC_TP)->f;
60           double sp = case_data_idx (cc, ROC_TN)->f;
61
62           se /= case_data_idx (cc, ROC_FN)->f + case_data_idx (cc, ROC_TP)->f ;
63           sp /= case_data_idx (cc, ROC_TN)->f + case_data_idx (cc, ROC_FP)->f ;
64
65           xrchart_vector (cr, geom, 1 - sp, se);
66         }
67       xrchart_vector_end (cr, geom);
68       casereader_destroy (r);
69     }
70
71   xrchart_write_legend (cr, geom);
72 }
73