1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2015 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/charts/barchart.h"
20 #include "output/charts/piechart.h"
24 #include "output/cairo-chart.h"
26 #include "gl/minmax.h"
29 #define _(msgid) gettext (msgid)
33 draw_bar (cairo_t *cr, const struct xrchart_geometry *geom,
34 const struct barchart *bc, int bar)
37 (geom->axis[SCALE_ABSCISSA].data_max - geom->axis[SCALE_ABSCISSA].data_min)
42 (geom->axis[SCALE_ABSCISSA].data_max - geom->axis[SCALE_ABSCISSA].data_min) *
48 double height = geom->axis[SCALE_ORDINATE].scale * bc->bars[bar].magnitude;
51 geom->axis[SCALE_ABSCISSA].data_min + x_pos + width * 0.1,
52 geom->axis[SCALE_ORDINATE].data_min,
55 cairo_set_source_rgb (cr,
56 geom->fill_colour.red / 255.0,
57 geom->fill_colour.green / 255.0,
58 geom->fill_colour.blue / 255.0);
59 cairo_fill_preserve (cr);
63 draw_tick (cr, geom, SCALE_ABSCISSA, true,
64 x_pos + width / 2.0, "%s", ds_cstr (&bc->bars[bar].label));
69 xrchart_draw_barchart (const struct chart_item *chart_item, cairo_t *cr,
70 struct xrchart_geometry *geom)
72 struct barchart *bc = to_barchart (chart_item);
75 xrchart_write_title (cr, geom, _("BARCHART"));
77 xrchart_write_ylabel (cr, geom, bc->ylabel);
78 xrchart_write_xlabel (cr, geom, chart_item_get_title (chart_item));
80 xrchart_write_yscale (cr, geom, 0, bc->largest);
82 for (i = 0; i < bc->n_bars; i++)
84 draw_bar (cr, geom, bc, i);