]> Dogcows Code - chaz/homebank/blob - src/gtk-chart.h
import homebank-5.1.7
[chaz/homebank] / src / gtk-chart.h
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2018 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_xval;
154 gboolean show_mono;
155 gint every_xval;
156 guint32 kcur;
157 gboolean minor;
158 gdouble minor_rate;
159 gchar *minor_symbol;
160
161 /* color datas */
162 GtkColorScheme color_scheme;
163
164 /* cairo default value */
165 PangoFontDescription *pfd;
166 gint pfd_size;
167
168 /* buffer surface */
169 cairo_surface_t *surface;
170
171 /* drawing datas */
172 double font_h;
173 int l, t, b, r, w, h;
174 cairo_rectangle_t graph;
175 cairo_rectangle_t legend;
176
177 /* legend dimension */
178 double label_w;
179 double legend_font_h;
180 double legend_label_w;
181 double legend_value_w;
182 double legend_rate_w;
183
184 /* zones height */
185 double title_zh;
186 double subtitle_zh, subtitle_y;
187 double header_zh, header_y;
188 double item_zh;
189
190
191
192 double ox, oy;
193 gint lastx, lasty, lastactive;
194 gint lastpress_x, lastpress_y;
195 gint active;
196 guint timer_tag;
197
198 /* pie specifics */
199 gdouble total;
200 gint rayon, mark, left, top;
201 gint leg_nb_l, leg_width_l, leg_vspace_l;
202 gint leg_nb_r, leg_width_r, leg_vspace_r;
203
204 /* bar specifics */
205 double rawmin, rawmax, range, min, max, unit, minimum;
206 gint div;
207 gint visible;
208
209
210
211 double scale_x, scale_y, scale_w, scale_h;
212 double item_x, item_y, item_w;
213 double barw, blkw, posbarh, negbarh;
214 double usrbarw;
215
216 gchar buffer1[CHART_BUFFER_LENGTH];
217 gchar buffer2[CHART_BUFFER_LENGTH];
218 };
219
220
221 struct _GtkChartClass
222 {
223 GtkBoxClass parent_class;
224
225 /* Padding for future expansion */
226 void (*_gtk_reserved1) (void);
227 void (*_gtk_reserved2) (void);
228 void (*_gtk_reserved3) (void);
229 void (*_gtk_reserved4) (void);
230 };
231
232 GType gtk_chart_get_type (void) G_GNUC_CONST;
233
234 /* public function */
235 GtkWidget *gtk_chart_new(gint type);
236
237 void gtk_chart_set_type(GtkChart *chart, gint type);
238 void gtk_chart_set_color_scheme(GtkChart * chart, gint colorscheme);
239
240 void gtk_chart_queue_redraw(GtkChart *chart);
241
242 void gtk_chart_set_datas(GtkChart *chart, GtkTreeModel *model, guint column, gchar *title, gchar *subtitle);
243 void gtk_chart_set_dualdatas(GtkChart *chart, GtkTreeModel *model, guint column1, guint column2, gchar *title, gchar *subtitle);
244
245 void gtk_chart_set_minor_prefs(GtkChart * chart, gdouble rate, gchar *symbol);
246 void gtk_chart_set_currency(GtkChart * chart, guint32 kcur);
247
248 void gtk_chart_set_overdrawn(GtkChart * chart, gdouble minimum);
249 //void gtk_chart_set_every_xval(GtkChart * chart, gint decay);
250 void gtk_chart_set_barw(GtkChart * chart, gdouble barw);
251 void gtk_chart_set_showmono(GtkChart * chart, gboolean mono);
252
253 void gtk_chart_show_legend(GtkChart * chart, gboolean visible, gboolean showextracol);
254 void gtk_chart_show_overdrawn(GtkChart * chart, gboolean visible);
255 void gtk_chart_show_xval(GtkChart * chart, gboolean visible);
256 void gtk_chart_show_minor(GtkChart * chart, gboolean minor);
257 void gtk_chart_set_absolute(GtkChart * chart, gboolean abs);
258
259 G_END_DECLS
260 #endif /* __GTK_CHART_H__ */
This page took 0.043146 seconds and 4 git commands to generate.