1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009 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"), npp->label);
38 xrchart_write_xlabel (cr, geom, _("Observed Value"));
39 xrchart_write_ylabel (cr, geom, _("Expected Normal"));
40 xrchart_write_xscale (cr, geom,
41 npp->x_lower - npp->slack,
42 npp->x_upper + npp->slack, 5);
43 xrchart_write_yscale (cr, geom, npp->y_first, npp->y_last, 5);
45 data = casereader_clone (npp->data);
46 for (; (c = casereader_read (data)) != NULL; case_unref (c))
47 xrchart_datum (cr, geom, 0,
48 case_data_idx (c, NP_IDX_Y)->f,
49 case_data_idx (c, NP_IDX_NS)->f);
50 casereader_destroy (data);
52 xrchart_line (cr, geom, npp->slope, npp->intercept,
53 npp->y_first, npp->y_last, XRCHART_DIM_Y);
57 dnp_plot_chart_draw (const struct chart_item *chart_item, cairo_t *cr,
58 struct xrchart_geometry *geom)
60 const struct np_plot_chart *dnpp = to_np_plot_chart (chart_item);
61 struct casereader *data;
64 xrchart_write_title (cr, geom, _("Detrended Normal Q-Q Plot of %s"),
66 xrchart_write_xlabel (cr, geom, _("Observed Value"));
67 xrchart_write_ylabel (cr, geom, _("Dev from Normal"));
68 xrchart_write_xscale (cr, geom, dnpp->y_min, dnpp->y_max, 5);
69 xrchart_write_yscale (cr, geom, dnpp->dns_min, dnpp->dns_max, 5);
71 data = casereader_clone (dnpp->data);
72 for (; (c = casereader_read (data)) != NULL; case_unref (c))
73 xrchart_datum (cr, geom, 0, case_data_idx (c, NP_IDX_Y)->f,
74 case_data_idx (c, NP_IDX_DNS)->f);
75 casereader_destroy (data);
77 xrchart_line (cr, geom, 0, 0, dnpp->y_min, dnpp->y_max, XRCHART_DIM_X);
81 xrchart_draw_np_plot (const struct chart_item *chart_item, cairo_t *cr,
82 struct xrchart_geometry *geom)
84 const struct np_plot_chart *npp = to_np_plot_chart (chart_item);
87 dnp_plot_chart_draw (chart_item, cr, geom);
89 np_plot_chart_draw (chart_item, cr, geom);