1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009, 2011 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/np-plot.h"
21 #include "data/case.h"
22 #include "data/casereader.h"
24 #include "output/cairo-chart.h"
27 #define _(msgid) gettext (msgid)
30 np_plot_chart_draw (const struct chart_item *chart_item, cairo_t *cr,
31 struct xrchart_geometry *geom)
33 const struct np_plot_chart *npp = to_np_plot_chart (chart_item);
34 struct casereader *data;
37 xrchart_write_title (cr, geom, _("Normal Q-Q Plot of %s"), chart_item->title);
38 xrchart_write_xlabel (cr, geom, _("Observed Value"));
39 xrchart_write_ylabel (cr, geom, _("Expected Normal"));
40 if (! xrchart_write_xscale (cr, geom,
41 npp->x_lower - npp->slack,
42 npp->x_upper + npp->slack))
45 if (! xrchart_write_yscale (cr, geom, npp->y_first, npp->y_last))
48 data = casereader_clone (npp->data);
49 for (; (c = casereader_read (data)) != NULL; case_unref (c))
50 xrchart_datum (cr, geom, 0,
51 case_data_idx (c, NP_IDX_Y)->f,
52 case_data_idx (c, NP_IDX_NS)->f);
53 casereader_destroy (data);
55 xrchart_line (cr, geom, npp->slope, npp->intercept,
56 npp->y_first, npp->y_last, XRCHART_DIM_Y);
60 dnp_plot_chart_draw (const struct chart_item *chart_item, cairo_t *cr,
61 struct xrchart_geometry *geom)
63 const struct np_plot_chart *dnpp = to_np_plot_chart (chart_item);
64 struct casereader *data;
67 xrchart_write_title (cr, geom, _("Detrended Normal Q-Q Plot of %s"), chart_item->title);
68 xrchart_write_xlabel (cr, geom, _("Observed Value"));
69 xrchart_write_ylabel (cr, geom, _("Dev from Normal"));
70 if (! xrchart_write_xscale (cr, geom, dnpp->y_min, dnpp->y_max))
72 if (! xrchart_write_yscale (cr, geom, dnpp->dns_min, dnpp->dns_max))
75 data = casereader_clone (dnpp->data);
76 for (; (c = casereader_read (data)) != NULL; case_unref (c))
77 xrchart_datum (cr, geom, 0, case_data_idx (c, NP_IDX_Y)->f,
78 case_data_idx (c, NP_IDX_DNS)->f);
79 casereader_destroy (data);
81 xrchart_line (cr, geom, 0, 0, dnpp->y_min, dnpp->y_max, XRCHART_DIM_X);
85 xrchart_draw_np_plot (const struct chart_item *chart_item, cairo_t *cr,
86 struct xrchart_geometry *geom)
88 const struct np_plot_chart *npp = to_np_plot_chart (chart_item);
91 dnp_plot_chart_draw (chart_item, cr, geom);
93 np_plot_chart_draw (chart_item, cr, geom);