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>
31 #include <libpspp/str.h>
32 #include <output/manager.h>
33 #include <output/output.h>
39 #define _(msgid) gettext (msgid)
41 extern struct som_table_class tab_table_class;
44 chart_init (struct chart *chart, const struct chart_class *class)
51 chart_geometry_init (plPlotter *lp, struct chart_geometry *geom,
52 double width, double length)
54 /* Start output page. */
57 /* Set coordinate system. */
58 pl_fspace_r (lp, 0.0, 0.0, width, length);
60 /* Set line thickness. */
61 pl_flinewidth_r (lp, 0.25);
62 pl_pencolor_r (lp, 0, 0, 0);
64 /* Erase graphics display. */
67 pl_filltype_r (lp, 0);
70 /* Set default chartetry. */
71 geom->data_top = 0.900 * length;
72 geom->data_right = 0.800 * width;
73 geom->data_bottom = 0.120 * length;
74 geom->data_left = 0.150 * width;
75 geom->abscissa_top = 0.070 * length;
76 geom->ordinate_right = 0.120 * width;
77 geom->title_bottom = 0.920 * length;
78 geom->legend_left = 0.810 * width;
79 geom->legend_right = width;
82 geom->fill_colour.red = 255;
83 geom->fill_colour.green = 0;
84 geom->fill_colour.blue = 0;
86 /* Get default font size */
88 geom->font_size = pl_fontsize_r (lp, -1);
90 /* Draw the data area */
92 geom->data_left, geom->data_bottom,
93 geom->data_right, geom->data_top);
97 chart_geometry_free (plPlotter *lp)
99 if (pl_closepl_r (lp) < 0)
100 fprintf (stderr, "Couldn't close Plotter\n");
104 chart_draw (const struct chart *chart, plPlotter *lp,
105 struct chart_geometry *geom)
107 chart->class->draw (chart, lp, geom);
111 chart_ref (const struct chart *chart_)
113 struct chart *chart = (struct chart *) chart_;
119 chart_unref (struct chart *chart)
123 assert (chart->ref_cnt > 0);
124 if (--chart->ref_cnt == 0)
125 chart->class->destroy (chart);
130 chart_submit (struct chart *chart)
133 struct outp_driver *d;
135 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
136 if (d->class->output_chart != NULL)
137 d->class->output_chart (d, chart);
144 chart_create_file (const char *type, const char *file_name_tmpl, int number,
145 plPlotterParams *params, char **file_namep, plPlotter **lpp)
147 char *file_name = NULL;
152 number_pos = strchr (file_name_tmpl, '#') - file_name_tmpl;
153 file_name = xasprintf ("%.*s%d%s", number_pos, file_name_tmpl,
154 number, file_name_tmpl + number_pos + 1);
156 fp = fopen (file_name, "wb");
159 error (0, errno, _("creating \"%s\""), file_name);
164 lp = pl_newpl_r (type, 0, fp, stderr, params);
167 params = pl_newplparams ();
168 lp = pl_newpl_r (type, 0, fp, stderr, params);
169 pl_deleteplparams (params);
174 *file_namep = file_name;
182 if (file_name != NULL)