1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004 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>
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;
48 struct outp_driver *d;
50 d = outp_drivers (NULL);
54 chart = xmalloc (sizeof *chart);
56 d->class->initialise_chart(d, chart);
63 if (pl_openpl_r (chart->lp) < 0) /* open Plotter */
66 pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */
67 pl_flinewidth_r (chart->lp, 0.25); /* set line thickness */
68 pl_pencolorname_r (chart->lp, "black");
70 pl_erase_r (chart->lp); /* erase graphics display */
71 pl_filltype_r(chart->lp,0);
73 pl_savestate_r(chart->lp);
75 /* Set default chartetry */
76 chart->data_top = 900;
77 chart->data_right = 800;
78 chart->data_bottom = 120;
79 chart->data_left = 150;
80 chart->abscissa_top = 70;
81 chart->ordinate_right = 120;
82 chart->title_bottom = 920;
83 chart->legend_left = 810;
84 chart->legend_right = 1000;
86 chart->in_path = false;
87 chart->dataset = NULL;
88 chart->n_datasets = 0;
89 strcpy(chart->fill_colour,"red");
91 /* Get default font size */
92 if ( !chart->font_size)
93 chart->font_size = pl_fontsize_r(chart->lp, -1);
95 /* Draw the data area */
97 chart->data_left, chart->data_bottom,
98 chart->data_right, chart->data_top);
104 chart_submit(struct chart *chart)
108 struct outp_driver *d;
113 pl_restorestate_r(chart->lp);
115 s.class = &tab_table_class;
120 if (pl_closepl_r (chart->lp) < 0) /* close Plotter */
122 fprintf (stderr, "Couldn't close Plotter\n");
125 pl_deletepl_r(chart->lp);
127 pl_deleteplparams(chart->pl_params);
129 d = outp_drivers (NULL);
130 d->class->finalise_chart(d, chart);
132 for (i = 0 ; i < chart->n_datasets; ++i)
133 free (chart->dataset[i]);
134 free (chart->dataset);
140 chart_init_separate (struct chart *ch, const char *type,
141 const char *file_name_tmpl, int number)
146 number_pos = strchr (file_name_tmpl, '#') - file_name_tmpl;
147 ch->file_name = xasprintf ("%.*s%d%s",
148 number_pos, file_name_tmpl,
150 file_name_tmpl + number_pos + 1);
151 fp = fopen (ch->file_name, "wb");
154 error (0, errno, _("creating \"%s\""), ch->file_name);
155 free (ch->file_name);
156 ch->file_name = NULL;
160 ch->pl_params = pl_newplparams ();
161 ch->lp = pl_newpl_r (type, 0, fp, stderr, ch->pl_params);
165 chart_finalise_separate (struct chart *ch)
167 free (ch->file_name);