/*
PSPP - a program for statistical analysis.
- Copyright (C) 2012, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2012, 2013, 2015 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
ST_XYZ
};
+/* Variable index for histogram case */
+enum
+ {
+ HG_IDX_X,
+ HG_IDX_WT
+ };
+
struct exploratory_stats
{
double missing;
enum chart_type chart_type;
enum scatter_type scatter_type;
const struct variable *byvar;
+ /* A caseproto that contains the plot data */
+ struct caseproto *gr_proto;
};
static void
-show_scatterplot (const struct graph *cmd, const struct casereader *input)
+show_scatterplot (const struct graph *cmd, struct casereader *input)
{
struct string title;
struct scatterplot_chart *scatterplot;
if (cmd->byvar)
{
- ds_put_format (&title, _("%s vs. %s by %s"),
- var_to_string (cmd->dep_vars[0]),
+ ds_put_format (&title, _("%s vs. %s by %s"),
var_to_string (cmd->dep_vars[1]),
- var_to_string (cmd->byvar));
+ var_to_string (cmd->dep_vars[0]),
+ var_to_string (cmd->byvar));
}
else
{
- ds_put_format (&title, _("%s vs. %s"),
- var_to_string (cmd->dep_vars[0]),
- var_to_string (cmd->dep_vars[1]));
+ ds_put_format (&title, _("%s vs. %s"),
+ var_to_string (cmd->dep_vars[1]),
+ var_to_string (cmd->dep_vars[0]));
}
- scatterplot = scatterplot_create(input,
- cmd->dep_vars[0],
- cmd->dep_vars[1],
- cmd->byvar,
- &byvar_overflow,
- ds_cstr (&title),
- cmd->es[0].minimum, cmd->es[0].maximum,
- cmd->es[1].minimum, cmd->es[1].maximum);
- scatterplot_chart_submit(scatterplot);
- ds_destroy(&title);
+ scatterplot = scatterplot_create (input,
+ var_to_string(cmd->dep_vars[0]),
+ var_to_string(cmd->dep_vars[1]),
+ cmd->byvar,
+ &byvar_overflow,
+ ds_cstr (&title),
+ cmd->es[0].minimum, cmd->es[0].maximum,
+ cmd->es[1].minimum, cmd->es[1].maximum);
+ scatterplot_chart_submit (scatterplot);
+ ds_destroy (&title);
if (byvar_overflow)
{
- msg (MW, _("Maximum number of scatterplot categories reached."
+ msg (MW, _("Maximum number of scatterplot categories reached."
"Your BY variable has too many distinct values."
- "The colouring of the plot will not be correct"));
+ "The coloring of the plot will not be correct"));
}
-
-
}
static void
-show_histogr (const struct graph *cmd, const struct casereader *input)
+show_histogr (const struct graph *cmd, struct casereader *input)
{
struct histogram *histogram;
struct ccase *c;
- struct casereader *reader;
{
/* Sturges Rule */
}
- for (reader=casereader_clone(input);(c = casereader_read (reader)) != NULL; case_unref (c))
+ for (;(c = casereader_read (input)) != NULL; case_unref (c))
{
- const struct variable *var = cmd->dep_vars[0];
- const double x = case_data (c, var)->f;
- const double weight = dict_get_case_weight(cmd->dict,c,NULL);
+ const double x = case_data_idx (c, HG_IDX_X)->f;
+ const double weight = case_data_idx (c, HG_IDX_WT)->f;
moments_pass_two (cmd->es[0].mom, x, weight);
histogram_add (histogram, x, weight);
}
- casereader_destroy(reader);
+ casereader_destroy (input);
{
ds_cstr (&label), n, mean,
sqrt (var), false));
- statistic_destroy(&histogram->parent);
+ statistic_destroy (&histogram->parent);
ds_destroy (&label);
}
}
{
struct ccase *c;
struct casereader *reader;
+ struct casewriter *writer;
-
- cmd->es = pool_calloc(cmd->pool,cmd->n_dep_vars,sizeof(struct exploratory_stats));
+ cmd->es = pool_calloc (cmd->pool,cmd->n_dep_vars,sizeof(struct exploratory_stats));
for(int v=0;v<cmd->n_dep_vars;v++)
{
cmd->es[v].mom = moments_create (MOMENT_KURTOSIS);
NULL,
NULL);
- for (reader = casereader_clone (input);
- (c = casereader_read (reader)) != NULL; case_unref (c))
+ writer = autopaging_writer_create (cmd->gr_proto);
+
+ /* The case data is copied to a new writer */
+ /* The setup of the case depends on the Charttype */
+ /* For Scatterplot x is assumed in dep_vars[0] */
+ /* y is assumed in dep_vars[1] */
+ /* For Histogram x is assumed in dep_vars[0] */
+ assert(SP_IDX_X == 0 && SP_IDX_Y == 1 && HG_IDX_X == 0);
+
+ for (;(c = casereader_read (input)) != NULL; case_unref (c))
{
- const double weight = dict_get_case_weight(cmd->dict,c,NULL);
+ struct ccase *outcase = case_create (cmd->gr_proto);
+ const double weight = dict_get_case_weight (cmd->dict,c,NULL);
+ if (cmd->chart_type == CT_HISTOGRAM)
+ case_data_rw_idx (outcase, HG_IDX_WT)->f = weight;
+ if (cmd->chart_type == CT_SCATTERPLOT && cmd->byvar)
+ value_copy (case_data_rw_idx (outcase, SP_IDX_BY),
+ case_data (c, cmd->byvar),
+ var_get_width (cmd->byvar));
for(int v=0;v<cmd->n_dep_vars;v++)
{
const struct variable *var = cmd->dep_vars[v];
cmd->es[v].missing += weight;
continue;
}
+ /* Magically v value fits to SP_IDX_X, SP_IDX_Y, HG_IDX_X */
+ case_data_rw_idx (outcase, v)->f = x;
if (x > cmd->es[v].maximum)
cmd->es[v].maximum = x;
if (cmd->es[v].cmin > weight)
cmd->es[v].cmin = weight;
}
+ casewriter_write (writer,outcase);
}
- casereader_destroy (reader);
+
+ reader = casewriter_make_reader (writer);
switch (cmd->chart_type)
{
case CT_HISTOGRAM:
- reader = casereader_clone(input);
- show_histogr(cmd,reader);
- casereader_destroy(reader);
+ show_histogr (cmd,reader);
break;
case CT_SCATTERPLOT:
- reader = casereader_clone(input);
- show_scatterplot(cmd,reader);
- casereader_destroy(reader);
+ show_scatterplot (cmd,reader);
break;
default:
NOT_REACHED ();
break;
};
- casereader_destroy(input);
-
+ casereader_destroy (input);
cleanup_exploratory_stats (cmd);
}
graph.chart_type = CT_NONE;
graph.scatter_type = ST_BIVARIATE;
graph.byvar = NULL;
+ graph.gr_proto = caseproto_create ();
while (lex_token (lexer) != T_ENDCMD)
{
lex_match (lexer, T_SLASH);
- if (lex_match_id(lexer, "HISTOGRAM"))
+ if (lex_match_id (lexer, "HISTOGRAM"))
{
if (graph.chart_type != CT_NONE)
{
- lex_error(lexer, _("Only one chart type is allowed."));
+ lex_error (lexer, _("Only one chart type is allowed."));
goto error;
}
if (!lex_force_match (lexer, T_EQUALS))
goto error;
if (graph.n_dep_vars > 1)
{
- lex_error(lexer, _("Only one variable is allowed"));
+ lex_error (lexer, _("Only one variable is allowed."));
goto error;
}
}
{
if (graph.chart_type != CT_NONE)
{
- lex_error(lexer, _("Only one chart type is allowed."));
+ lex_error (lexer, _("Only one chart type is allowed."));
goto error;
}
graph.chart_type = CT_SCATTERPLOT;
}
else if (lex_match_id (lexer, "OVERLAY"))
{
- lex_error(lexer, _("%s is not yet implemented."),"OVERLAY");
+ lex_error (lexer, _("%s is not yet implemented."),"OVERLAY");
goto error;
}
else if (lex_match_id (lexer, "MATRIX"))
{
- lex_error(lexer, _("%s is not yet implemented."),"MATRIX");
+ lex_error (lexer, _("%s is not yet implemented."),"MATRIX");
goto error;
}
else if (lex_match_id (lexer, "XYZ"))
}
else
{
- lex_error_expecting(lexer, "BIVARIATE", NULL);
+ lex_error_expecting (lexer, "BIVARIATE", NULL);
goto error;
}
if (!lex_force_match (lexer, T_RPAREN))
if (graph.scatter_type == ST_BIVARIATE && graph.n_dep_vars != 1)
{
- lex_error(lexer, _("Only one variable allowed"));
+ lex_error(lexer, _("Only one variable is allowed."));
goto error;
}
if (graph.scatter_type == ST_BIVARIATE && graph.n_dep_vars != 2)
{
- lex_error(lexer, _("Only one variable allowed"));
+ lex_error (lexer, _("Only one variable is allowed."));
goto error;
}
- if (lex_match(lexer, T_BY))
+ if (lex_match (lexer, T_BY))
{
const struct variable *v = NULL;
if (!lex_match_variable (lexer,graph.dict,&v))
{
- lex_error(lexer, _("Variable expected"));
+ lex_error (lexer, _("Variable expected"));
goto error;
}
graph.byvar = v;
}
}
- if (graph.chart_type == CT_NONE)
+ switch (graph.chart_type)
{
- lex_error_expecting(lexer,"HISTOGRAM","SCATTERPLOT",NULL);
+ case CT_SCATTERPLOT:
+ /* See scatterplot.h for the setup of the case prototype */
+ graph.gr_proto = caseproto_add_width (graph.gr_proto, 0); /* x value - SP_IDX_X*/
+ graph.gr_proto = caseproto_add_width (graph.gr_proto, 0); /* y value - SP_IDX_Y*/
+ /* The byvar contains the plot categories for the different xy plot colors */
+ if (graph.byvar) /* SP_IDX_BY */
+ graph.gr_proto = caseproto_add_width (graph.gr_proto, var_get_width(graph.byvar));
+ break;
+ case CT_HISTOGRAM:
+ graph.gr_proto = caseproto_add_width (graph.gr_proto, 0); /* x value */
+ graph.gr_proto = caseproto_add_width (graph.gr_proto, 0); /* weight value */
+ break;
+ case CT_NONE:
+ lex_error_expecting (lexer,"HISTOGRAM","SCATTERPLOT",NULL);
goto error;
- }
-
+ default:
+ NOT_REACHED ();
+ break;
+ };
{
struct casegrouper *grouper;
free (graph.dep_vars);
pool_destroy (graph.pool);
+ caseproto_unref (graph.gr_proto);
return CMD_SUCCESS;
error:
+ caseproto_unref (graph.gr_proto);
free (graph.dep_vars);
pool_destroy (graph.pool);