]> Dogcows Code - chaz/homebank/blob - src/gtk-chart.h
import homebank-5.2.4
[chaz/homebank] / src / gtk-chart.h
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2019 Maxime DOYEN
3 *
4 * This file is part of HomeBank.
5 *
6 * HomeBank is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * HomeBank is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __GTK_CHART_H__
21 #define __GTK_CHART_H__
22
23 #include "gtk-chart-colors.h"
24
25 G_BEGIN_DECLS
26 #define GTK_TYPE_CHART (gtk_chart_get_type ())
27 #define GTK_CHART(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CHART, GtkChart))
28 #define GTK_CHART_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CHART, GtkChartClass)
29 #define GTK_IS_CHART(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CHART))
30 #define GTK_IS_CHART_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CHART))
31 #define GTK_CHART_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CHART, GtkChartClass))
32
33 typedef struct _GtkChart GtkChart;
34 typedef struct _GtkChartClass GtkChartClass;
35 //typedef struct _GtkChartPrivate GtkChartPrivate;
36
37 typedef struct _ChartItem ChartItem;
38 typedef gchar (* GtkChartPrintIntFunc) (gint value, gboolean minor);
39 typedef gchar (* GtkChartPrintDoubleFunc) (gdouble value, gboolean minor);
40
41 /* = = = = = = = = = = */
42 /* = = = = = = = = = = = = = = = = = = = = */
43 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
44 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
45
46 /* phi value */
47 #define PHI 1.61803399
48
49
50 /* default zoomx for charts */
51 #define GTK_CHART_BARW 41 //24
52
53 #define GTK_CHART_MINBARW 8 //4
54 #define GTK_CHART_MAXBARW 41 //128
55 #define GTK_CHART_SPANBARW GTK_CHART_MAXBARW+1
56
57 #define GTK_CHART_MINRADIUS 64
58
59 #define CHART_BUFFER_LENGTH 128
60
61
62 // char draw options
63 #define CHART_PARAM_PIE_DONUT TRUE
64 #define CHART_PARAM_PIE_LINE FALSE
65 #define CHART_PARAM_PIE_MARK FALSE
66 #define CHART_PARAM_PIE_HOLEVALUE 0.5
67
68
69
70
71 /* new stuff */
72 #define CHART_MARGIN 12 //standard a4 margin is 18
73 #define CHART_SPACING 6
74
75 #define CHART_LINE_SPACING 1.25
76
77 //#define PROP_SHOW_MINOR 6
78 //#define PROP_SHOW_LEGEND 7
79
80 #define ROUNDHALF(x) floor(x *2) / 2
81
82
83
84 enum
85 {
86 CHART_TYPE_NONE,
87 CHART_TYPE_COL,
88
89 CHART_TYPE_PIE,
90 CHART_TYPE_LINE,
91 CHART_TYPE_MAX
92 };
93
94
95 enum
96 {
97 LST_LEGEND_FAKE,
98 LST_LEGEND_COLOR,
99 LST_LEGEND_TITLE,
100 LST_LEGEND_AMOUNT,
101 LST_LEGEND_RATE,
102 NUM_LST_LEGEND
103 };
104
105
106 struct _ChartItem
107 {
108 /* data part */
109 gchar *label;
110 gdouble serie1;
111 gdouble serie2;
112 gdouble rate;
113
114 /* draw stuffs */
115 gchar *legend;
116 double angle2; /* rate for pie */
117 double height; /* for column */
118 };
119
120
121 struct _GtkChart
122 {
123 //own widget here
124
125 /*< private >*/
126 //GtkChartPrivate *priv;
127
128
129 /* all below should be in priv normally */
130 GtkBox hbox;
131
132 GtkWidget *drawarea;
133 GtkAdjustment *adjustment;
134 GtkWidget *scrollbar;
135
136 GtkTreeModel *model;
137
138 /* data storage */
139 gint nb_items;
140 GArray *items;
141
142 gchar *title;
143 gchar *subtitle;
144
145 /* chart properties */
146 gint type; // column/pie/line
147
148 gboolean dual;
149 gboolean abs;
150 gboolean show_legend;
151 gboolean show_legend_wide;
152 gboolean show_over;
153 gboolean show_average;
154 gboolean show_xval;
155 gboolean show_mono;
156 gint every_xval;
157 guint32 kcur;
158 gboolean minor;
159 gdouble minor_rate;
160 gchar *minor_symbol;
161
162 /* color datas */
163 GtkColorScheme color_scheme;
164
165 /* cairo default value */
166 PangoFontDescription *pfd;
167 gint pfd_size;
168
169 /* buffer surface */
170 cairo_surface_t *surface;
171
172 /* drawing datas */
173 double font_h;
174 int l, t, b, r, w, h;
175 cairo_rectangle_t graph;
176 cairo_rectangle_t legend;
177
178 /* legend dimension */
179 double label_w;
180 double legend_font_h;
181 double legend_label_w;
182 double legend_value_w;
183 double legend_rate_w;
184
185 /* zones height */
186 double title_zh;
187 double subtitle_zh, subtitle_y;
188 double header_zh, header_y;
189 double item_zh;
190
191
192
193 double ox, oy;
194 gint lastx, lasty, lastactive;
195 gint lastpress_x, lastpress_y;
196 gint active;
197 guint timer_tag;
198
199 /* pie specifics */
200 gdouble total;
201 gint rayon, mark, left, top;
202 gint leg_nb_l, leg_width_l, leg_vspace_l;
203 gint leg_nb_r, leg_width_r, leg_vspace_r;
204
205 /* bar specifics */
206 double rawmin, rawmax, range, min, max, unit, minimum, average;
207 gint div;
208 gint visible;
209
210
211
212 double scale_x, scale_y, scale_w, scale_h;
213 double item_x, item_y, item_w;
214 double barw, blkw, posbarh, negbarh;
215 double usrbarw;
216
217 gchar buffer1[CHART_BUFFER_LENGTH];
218 gchar buffer2[CHART_BUFFER_LENGTH];
219 };
220
221
222 struct _GtkChartClass
223 {
224 GtkBoxClass parent_class;
225
226 /* Padding for future expansion */
227 void (*_gtk_reserved1) (void);
228 void (*_gtk_reserved2) (void);
229 void (*_gtk_reserved3) (void);
230 void (*_gtk_reserved4) (void);
231 };
232
233 GType gtk_chart_get_type (void) G_GNUC_CONST;
234
235 /* public function */
236 GtkWidget *gtk_chart_new(gint type);
237
238 void gtk_chart_set_type(GtkChart *chart, gint type);
239 void gtk_chart_set_color_scheme(GtkChart * chart, gint colorscheme);
240
241 void gtk_chart_queue_redraw(GtkChart *chart);
242
243 void gtk_chart_set_datas(GtkChart *chart, GtkTreeModel *model, guint column, gchar *title, gchar *subtitle);
244 void gtk_chart_set_dualdatas(GtkChart *chart, GtkTreeModel *model, guint column1, guint column2, gchar *title, gchar *subtitle);
245
246 void gtk_chart_set_minor_prefs(GtkChart * chart, gdouble rate, gchar *symbol);
247 void gtk_chart_set_currency(GtkChart * chart, guint32 kcur);
248
249 void gtk_chart_show_average(GtkChart * chart, gdouble value, gboolean visible);
250 void gtk_chart_set_overdrawn(GtkChart * chart, gdouble minimum);
251 //void gtk_chart_set_every_xval(GtkChart * chart, gint decay);
252 void gtk_chart_set_barw(GtkChart * chart, gdouble barw);
253 void gtk_chart_set_showmono(GtkChart * chart, gboolean mono);
254
255 void gtk_chart_show_legend(GtkChart * chart, gboolean visible, gboolean showextracol);
256 void gtk_chart_show_overdrawn(GtkChart * chart, gboolean visible);
257 void gtk_chart_show_xval(GtkChart * chart, gboolean visible);
258 void gtk_chart_show_minor(GtkChart * chart, gboolean minor);
259 void gtk_chart_set_absolute(GtkChart * chart, gboolean abs);
260
261 G_END_DECLS
262 #endif /* __GTK_CHART_H__ */
This page took 0.043975 seconds and 4 git commands to generate.