1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 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/chart.h>
20 #include <output/chart-provider.h>
32 #include <libpspp/str.h>
33 #include <output/manager.h>
34 #include <output/output.h>
40 #define _(msgid) gettext (msgid)
42 extern struct som_table_class tab_table_class;
45 chart_init (struct chart *chart, const struct chart_class *class)
52 chart_geometry_init (plPlotter *lp, struct chart_geometry *geom)
54 /* Start output page. */
57 /* Set coordinate system. */
58 pl_fspace_r (lp, 0.0, 0.0, 1000.0, 1000.0);
60 /* Set line thickness. */
61 pl_flinewidth_r (lp, 0.25);
62 pl_pencolorname_r (lp, "black");
64 /* Erase graphics display. */
67 pl_filltype_r (lp, 0);
70 /* Set default chartetry. */
72 geom->data_right = 800;
73 geom->data_bottom = 120;
74 geom->data_left = 150;
75 geom->abscissa_top = 70;
76 geom->ordinate_right = 120;
77 geom->title_bottom = 920;
78 geom->legend_left = 810;
79 geom->legend_right = 1000;
81 strcpy (geom->fill_colour, "red");
83 /* Get default font size */
85 geom->font_size = pl_fontsize_r (lp, -1);
87 /* Draw the data area */
89 geom->data_left, geom->data_bottom,
90 geom->data_right, geom->data_top);
94 chart_geometry_free (plPlotter *lp)
96 if (pl_closepl_r (lp) < 0)
97 fprintf (stderr, "Couldn't close Plotter\n");
101 chart_draw (const struct chart *chart, plPlotter *lp)
103 chart->class->draw (chart, lp);
107 chart_ref (const struct chart *chart_)
109 struct chart *chart = (struct chart *) chart_;
115 chart_unref (struct chart *chart)
117 assert (chart->ref_cnt > 0);
118 if (--chart->ref_cnt == 0)
119 chart->class->destroy (chart);
123 chart_submit (struct chart *chart)
125 struct outp_driver *d;
127 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
128 if (d->class->output_chart != NULL)
129 d->class->output_chart (d, chart);
135 chart_create_file (const char *type, const char *file_name_tmpl, int number,
136 plPlotterParams *params, char **file_namep, plPlotter **lpp)
138 char *file_name = NULL;
143 number_pos = strchr (file_name_tmpl, '#') - file_name_tmpl;
144 file_name = xasprintf ("%.*s%d%s", number_pos, file_name_tmpl,
145 number, file_name_tmpl + number_pos + 1);
147 fp = fopen (file_name, "wb");
150 error (0, errno, _("creating \"%s\""), file_name);
155 lp = pl_newpl_r (type, 0, fp, stderr, params);
158 params = pl_newplparams ();
159 lp = pl_newpl_r (type, 0, fp, stderr, params);
160 pl_deleteplparams (params);
165 *file_namep = file_name;
173 if (file_name != NULL)