1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/* PSPP - a program for statistical analysis.
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include "output/charts/np-plot.h"
#include "data/case.h"
#include "data/casereader.h"
#include "math/np.h"
#include "output/cairo-chart.h"
#include "gettext.h"
#define _(msgid) gettext (msgid)
static void
np_plot_chart_draw (const struct chart_item *chart_item, cairo_t *cr,
struct xrchart_geometry *geom)
{
const struct np_plot_chart *npp = to_np_plot_chart (chart_item);
struct casereader *data;
struct ccase *c;
xrchart_write_title (cr, geom, _("Normal Q-Q Plot of %s"), chart_item->title);
xrchart_write_xlabel (cr, geom, _("Observed Value"));
xrchart_write_ylabel (cr, geom, _("Expected Normal"));
xrchart_write_xscale (cr, geom,
npp->x_lower - npp->slack,
npp->x_upper + npp->slack);
xrchart_write_yscale (cr, geom, npp->y_first, npp->y_last);
data = casereader_clone (npp->data);
for (; (c = casereader_read (data)) != NULL; case_unref (c))
xrchart_datum (cr, geom, 0,
case_data_idx (c, NP_IDX_Y)->f,
case_data_idx (c, NP_IDX_NS)->f);
casereader_destroy (data);
xrchart_line (cr, geom, npp->slope, npp->intercept,
npp->y_first, npp->y_last, XRCHART_DIM_Y);
}
static void
dnp_plot_chart_draw (const struct chart_item *chart_item, cairo_t *cr,
struct xrchart_geometry *geom)
{
const struct np_plot_chart *dnpp = to_np_plot_chart (chart_item);
struct casereader *data;
struct ccase *c;
xrchart_write_title (cr, geom, _("Detrended Normal Q-Q Plot of %s"), chart_item->title);
xrchart_write_xlabel (cr, geom, _("Observed Value"));
xrchart_write_ylabel (cr, geom, _("Dev from Normal"));
xrchart_write_xscale (cr, geom, dnpp->y_min, dnpp->y_max);
xrchart_write_yscale (cr, geom, dnpp->dns_min, dnpp->dns_max);
data = casereader_clone (dnpp->data);
for (; (c = casereader_read (data)) != NULL; case_unref (c))
xrchart_datum (cr, geom, 0, case_data_idx (c, NP_IDX_Y)->f,
case_data_idx (c, NP_IDX_DNS)->f);
casereader_destroy (data);
xrchart_line (cr, geom, 0, 0, dnpp->y_min, dnpp->y_max, XRCHART_DIM_X);
}
void
xrchart_draw_np_plot (const struct chart_item *chart_item, cairo_t *cr,
struct xrchart_geometry *geom)
{
const struct np_plot_chart *npp = to_np_plot_chart (chart_item);
if (npp->detrended)
dnp_plot_chart_draw (chart_item, cr, geom);
else
np_plot_chart_draw (chart_item, cr, geom);
}
|