]> Dogcows Code - chaz/homebank/blob - src/gtk-chart.h
import homebank-4.6.3
[chaz/homebank] / src / gtk-chart.h
1 /* HomeBank -- Free, easy, personal accounting for everyone.
2 * Copyright (C) 1995-2014 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 <glib.h>
24 #include <gdk/gdk.h>
25 #include <gtk/gtk.h>
26 #include <cairo.h>
27 #include <math.h>
28
29 G_BEGIN_DECLS
30 #define GTK_TYPE_CHART (gtk_chart_get_type ())
31 #define GTK_CHART(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CHART, GtkChart))
32 #define GTK_CHART_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CHART, GtkChartClass)
33 #define GTK_IS_CHART(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CHART))
34 #define GTK_IS_CHART_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CHART))
35 #define GTK_CHART_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CHART, GtkChartClass))
36
37 typedef struct _GtkChart GtkChart;
38 typedef struct _GtkChartClass GtkChartClass;
39 //typedef struct _GtkChartPrivate GtkChartPrivate;
40
41 typedef struct _ChartItem ChartItem;
42 typedef gchar (* GtkChartPrintIntFunc) (gint value, gboolean minor);
43 typedef gchar (* GtkChartPrintDoubleFunc) (gdouble value, gboolean minor);
44
45 /* = = = = = = = = = = */
46 /* = = = = = = = = = = = = = = = = = = = = */
47 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
48 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
49
50 /* phi value */
51 #define PHI 1.61803399
52
53
54 /* default zoomx for charts */
55 #define GTK_CHART_BARW 24
56 #define GTK_CHART_MINBARW 8
57 #define GTK_CHART_MAXBARW 64
58 #define GTK_CHART_MINRADIUS 64
59
60
61 #define CHART_BUFFER_LENGTH 128
62
63 // for cairo pie
64 #define PIE_LINE_SLICE 0
65 #define SOFT_LIGHT 0
66 #define GRADIENT 0
67 #define CHART_PIE_DONUT 1
68
69
70 /* new stuff */
71 #define CHART_MARGIN 18 //standard a4 margin
72 #define CHART_SPACING 6
73
74 //#define PROP_SHOW_MINOR 6
75 //#define PROP_SHOW_LEGEND 7
76
77 enum
78 {
79 CHART_TYPE_COL,
80 CHART_TYPE_PIE,
81 CHART_TYPE_LINE,
82 CHART_TYPE_MAX
83 };
84
85
86 enum
87 {
88 LST_LEGEND_FAKE,
89 LST_LEGEND_COLOR,
90 LST_LEGEND_TITLE,
91 LST_LEGEND_AMOUNT,
92 LST_LEGEND_RATE,
93 NUM_LST_LEGEND
94 };
95
96
97 struct _ChartItem
98 {
99 /* data part */
100 gchar *label;
101 gdouble serie1;
102 gdouble serie2;
103 gdouble rate;
104
105 /* cairo part */
106 gchar *legend;
107 double angle2; /* rate for pie */
108 double height; /* for column */
109 };
110
111
112 struct _GtkChart
113 {
114 //own widget here
115
116 /*< private >*/
117 //GtkChartPrivate *priv;
118
119
120 /* all below should be in priv normally */
121 GtkHBox hbox;
122
123 GtkWidget *drawarea;
124 GtkAdjustment *adjustment;
125 GtkWidget *scrollbar;
126
127 GtkWidget *scrollwin;
128 GtkWidget *treeview;
129 GtkTreeModel *legend;
130
131 /* data storage */
132 gint nb_items;
133 GArray *items;
134
135 gchar *title;
136 gchar *subtitle;
137
138 /* chart properties */
139 gint type;
140 gboolean dual;
141 gboolean abs;
142 gboolean show_over;
143 gboolean show_xval;
144 gint every_xval;
145 //guint32 kcur;
146 gboolean minor;
147 gdouble minor_rate;
148 gchar *minor_symbol;
149
150 /* color datas */
151 struct rgbcol *colors;
152 gint nb_cols;
153 gint cs_red, cs_green, cs_blue, cs_yellow;
154
155 /* buffer surface */
156 cairo_surface_t *surface;
157
158 /* draw area coordinates */
159 double l, t, b, r, w, h;
160 /* our drawing rectangle with margin */
161 double legend_w;
162
163 /* zones height */
164 double title_zh;
165 double subtitle_zh, subtitle_y;
166
167
168 double ox, oy;
169 gint lastx, lasty, lastactive;
170 gint lastpress_x, lastpress_y;
171 gint active;
172 guint timer_tag;
173
174 /* pie specifics */
175 gdouble total;
176 gint rayon, left, top;
177
178 /* bar specifics */
179 double rawmin, rawmax, range, min, max, unit, minimum;
180 gint div;
181 gint visible;
182
183 double font_h;
184
185 double scale_x, scale_y, scale_w, scale_h;
186 double graph_x, graph_y, graph_width, graph_height; //graph dimension
187 double barw, blkw, posbarh, negbarh;
188
189 gchar buffer1[CHART_BUFFER_LENGTH];
190 gchar buffer2[CHART_BUFFER_LENGTH];
191 };
192
193 struct _GtkChartClass
194 {
195 GtkHBoxClass parent_class;
196
197 /* Padding for future expansion */
198 void (*_gtk_reserved1) (void);
199 void (*_gtk_reserved2) (void);
200 void (*_gtk_reserved3) (void);
201 void (*_gtk_reserved4) (void);
202 };
203
204 GType gtk_chart_get_type (void) G_GNUC_CONST;
205
206 /* public function */
207 GtkWidget *gtk_chart_new(gint type);
208
209 void gtk_chart_set_type(GtkChart *chart, gint type);
210 void gtk_chart_set_color_scheme(GtkChart * chart, gint colorscheme);
211
212 void gtk_chart_queue_redraw(GtkChart *chart);
213
214 void gtk_chart_set_datas(GtkChart *chart, GtkTreeModel *model, guint column, gchar *title);
215 void gtk_chart_set_dualdatas(GtkChart *chart, GtkTreeModel *model, guint column1, guint column2, gchar *title);
216
217 void gtk_chart_set_minor_prefs(GtkChart * chart, gdouble rate, gchar *symbol);
218 //void gtk_chart_set_currency(GtkChart * chart, guint32 kcur);
219
220 void gtk_chart_set_overdrawn(GtkChart * chart, gdouble minimum);
221 void gtk_chart_set_every_xval(GtkChart * chart, gint decay);
222 void gtk_chart_set_barw(GtkChart * chart, gdouble barw);
223
224 void gtk_chart_show_legend(GtkChart * chart, gboolean visible, gboolean showextracol);
225 void gtk_chart_show_overdrawn(GtkChart * chart, gboolean visible);
226 void gtk_chart_show_xval(GtkChart * chart, gboolean visible);
227 void gtk_chart_show_minor(GtkChart * chart, gboolean minor);
228 void gtk_chart_set_absolute(GtkChart * chart, gboolean abs);
229
230 G_END_DECLS
231 #endif /* __GTK_CHART_H__ */
This page took 0.041498 seconds and 5 git commands to generate.