gtkdatabox  1.0.0
About: GtkDatabox is a Gtk+-widget for live display of large amounts of fluctuating numerical data.
  Fossies Dox: gtkdatabox-1.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

gtkdatabox_bars.c
Go to the documentation of this file.
1 /* $Id: gtkdatabox_bars.c 4 2008-06-22 09:19:11Z rbock $ */
2 /* GtkDatabox - An extension to the gtk+ library
3  * Copyright (C) 1998 - 2008 Dr. Roland Bock
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public License
7  * as published by the Free Software Foundation; either version 2.1
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include <gtkdatabox_bars.h>
21 
23  GtkDatabox* box);
24 /**
25  * GtkDataboxBarsPrivate
26  *
27  * A private data structure used by the #GtkDataboxBars. It shields all internal things
28  * from developers who are just using the object.
29  *
30  **/
32 
34 {
35  gint16 *xpixels;
36  gint16 *ypixels;
37  guint pixelsalloc;
38 };
39 
42 
43 static void
44 bars_finalize (GObject * object)
45 {
46  GtkDataboxBars *bars = GTK_DATABOX_BARS (object);
47  GtkDataboxBarsPrivate *priv=gtk_databox_bars_get_instance_private(bars);
48 
49  g_free (priv->xpixels);
50  g_free (priv->ypixels);
51 
52  /* Chain up to the parent class */
53  G_OBJECT_CLASS (gtk_databox_bars_parent_class)->finalize (object);
54 }
55 
56 static void
58 {
59  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
60  GtkDataboxGraphClass *graph_class = GTK_DATABOX_GRAPH_CLASS (klass);
61 
62  gobject_class->finalize = bars_finalize;
63 
64  graph_class->draw = gtk_databox_bars_real_draw;
65 }
66 
67 static void
69 {
70  GtkDataboxBarsPrivate *priv=gtk_databox_bars_get_instance_private(bars);
71  priv->xpixels = NULL;
72  priv->ypixels = NULL;
73  priv->pixelsalloc = 0;
74 }
75 
76 static void
78 {
79  g_signal_connect (bars, "notify::length",
80  G_CALLBACK (gtk_databox_bars_complete), NULL);
81 }
82 
83 /**
84  * gtk_databox_bars_new:
85  * @len: length of @X and @Y
86  * @X: array of horizontal position values of markers
87  * @Y: array of vertical position values of markers
88  * @color: color of the markers
89  * @size: marker size or line width (depending on the @type)
90  *
91  * Creates a new #GtkDataboxBars object which can be added to a #GtkDatabox widget
92  *
93  * Return value: A new #GtkDataboxBars object
94  **/
96 gtk_databox_bars_new (guint len, gfloat * X, gfloat * Y,
97  GdkRGBA * color, guint size)
98 {
99  GtkDataboxBars *bars;
100  g_return_val_if_fail (X, NULL);
101  g_return_val_if_fail (Y, NULL);
102  g_return_val_if_fail ((len > 0), NULL);
103 
104  bars = g_object_new (GTK_DATABOX_TYPE_BARS,
105  "X-Values", X,
106  "Y-Values", Y,
107  "xstart", 0,
108  "ystart", 0,
109  "xstride", 1,
110  "ystride", 1,
111  "xtype", G_TYPE_FLOAT,
112  "ytype", G_TYPE_FLOAT,
113  "length", len,
114  "maxlen", len,
115  "color", color, "size", size, NULL);
116 
117  return GTK_DATABOX_GRAPH (bars);
118 }
119 
120 /**
121  * gtk_databox_bars_new_full:
122  * @maxlen: maximum length of @X and @Y
123  * @len: actual number of @X and @Y values to plot
124  * @X: array of horizontal position values of markers
125  * @Y: array of vertical position values of markers
126  * @xstart: the first element in the X array to plot (usually 0)
127  * @ystart: the first element in the Y array to plot (usually 0)
128  * @xstride: successive elements in the X array are separated by this much (1 if array, ncols if matrix)
129  * @ystride: successive elements in the Y array are separated by this much (1 if array, ncols if matrix)
130  * @xtype: the GType of the X array elements. G_TYPE_FLOAT, G_TYPE_DOUBLE, etc.
131  * @ytype: the GType of the Y array elements. G_TYPE_FLOAT, G_TYPE_DOUBLE, etc.
132  * @color: color of the markers
133  * @size: marker size or line width (depending on the @type)
134  *
135  * Creates a new #GtkDataboxBars object which can be added to a #GtkDatabox widget
136  *
137  * Return value: A new #GtkDataboxBars object
138  **/
140 gtk_databox_bars_new_full (guint maxlen, guint len,
141  void * X, guint xstart, guint xstride, GType xtype,
142  void * Y, guint ystart, guint ystride, GType ytype,
143  GdkRGBA * color, guint size)
144 {
145  GtkDataboxBars *bars;
146  g_return_val_if_fail (X, NULL);
147  g_return_val_if_fail (Y, NULL);
148  g_return_val_if_fail ((len > 0), NULL);
149 
150  bars = g_object_new (GTK_DATABOX_TYPE_BARS,
151  "X-Values", X,
152  "Y-Values", Y,
153  "xstart", xstart,
154  "ystart", ystart,
155  "xstride", xstride,
156  "ystride", ystride,
157  "xtype", xtype,
158  "ytype", ytype,
159  "length", len,
160  "maxlen", maxlen,
161  "color", color, "size", size, NULL);
162 
163  return GTK_DATABOX_GRAPH (bars);
164 }
165 
166 static void
168  GtkDatabox* box)
169 {
170  GtkDataboxBars *bars = GTK_DATABOX_BARS (graph);
171  GtkDataboxBarsPrivate *priv=gtk_databox_bars_get_instance_private(bars);
172  guint i = 0;
173  void *X;
174  void *Y;
175  guint len, maxlen;
176  gint16 zero = 0;
177  gfloat fzero = 0.0;
178  cairo_t *cr;
179  gint16 *xpixels, *ypixels;
180  guint xstart, xstride, ystart, ystride;
181  GType xtype, ytype;
182 
183  g_return_if_fail (GTK_DATABOX_IS_BARS (bars));
184  g_return_if_fail (GTK_IS_DATABOX (box));
185 
187  g_warning
188  ("gtk_databox_bars do not work well with logarithmic scale in Y axis");
189 
190  cr = gtk_databox_graph_create_gc (graph, box);
191 
194 
195  if (priv->pixelsalloc < len)
196  {
197  priv->pixelsalloc = len;
198  priv->xpixels = (gint16 *)g_realloc(priv->xpixels, len * sizeof(gint16));
199  priv->ypixels = (gint16 *)g_realloc(priv->ypixels, len * sizeof(gint16));
200  }
201 
202  xpixels = priv->xpixels;
203  ypixels = priv->ypixels;
204 
209  gtk_databox_values_to_xpixels(box, xpixels, X, xtype, maxlen, xstart, xstride, len);
210 
215  gtk_databox_values_to_ypixels(box, ypixels, Y, ytype, maxlen, ystart, ystride, len);
216 
217  gtk_databox_values_to_ypixels(box, &zero, &fzero, G_TYPE_FLOAT, 1, 0, 1, 1);
218 
219  for (i = 0; i < len; i++, xpixels++, ypixels++)
220  {
221  cairo_move_to (cr, *xpixels + 0.5, zero + 0.5);
222  cairo_line_to (cr, *xpixels + 0.5, *ypixels + 0.5);
223  }
224  cairo_stroke(cr);
225  cairo_destroy(cr);
226 
227  return;
228 }
229 
GtkDataboxScaleType gtk_databox_get_scale_type_y(GtkDatabox *box)
Definition: gtkdatabox.c:1097
void gtk_databox_values_to_xpixels(GtkDatabox *box, gint16 *pixels, void *values, GType vtype, guint maxlen, guint start, guint stride, guint len)
Definition: gtkdatabox.c:2236
void gtk_databox_values_to_ypixels(GtkDatabox *box, gint16 *pixels, void *values, GType vtype, guint maxlen, guint start, guint stride, guint len)
Definition: gtkdatabox.c:2308
#define GTK_IS_DATABOX(obj)
Definition: gtkdatabox.h:62
static void gtk_databox_bars_class_init(GtkDataboxBarsClass *klass)
static void gtk_databox_bars_complete(GtkDataboxBars *bars)
static void gtk_databox_bars_real_draw(GtkDataboxGraph *bars, GtkDatabox *box)
static void gtk_databox_bars_init(GtkDataboxBars *bars)
GtkDataboxGraph * gtk_databox_bars_new(guint len, gfloat *X, gfloat *Y, GdkRGBA *color, guint size)
G_DEFINE_TYPE_WITH_PRIVATE(GtkDataboxBars, gtk_databox_bars, GTK_DATABOX_TYPE_XYC_GRAPH)
GtkDataboxGraph * gtk_databox_bars_new_full(guint maxlen, guint len, void *X, guint xstart, guint xstride, GType xtype, void *Y, guint ystart, guint ystride, GType ytype, GdkRGBA *color, guint size)
#define GTK_DATABOX_BARS(obj)
#define GTK_DATABOX_TYPE_BARS
#define GTK_DATABOX_IS_BARS(obj)
cairo_t * gtk_databox_graph_create_gc(GtkDataboxGraph *graph, GtkDatabox *box)
#define GTK_DATABOX_GRAPH(obj)
#define GTK_DATABOX_GRAPH_CLASS(klass)
@ GTK_DATABOX_SCALE_LOG
typedefG_BEGIN_DECLS struct _GtkDatabox GtkDatabox
gfloat * gtk_databox_xyc_graph_get_Y(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_xstride(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_ystride(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_xstart(GtkDataboxXYCGraph *xyc_graph)
gfloat * gtk_databox_xyc_graph_get_X(GtkDataboxXYCGraph *xyc_graph)
#define GTK_DATABOX_XYC_GRAPH(obj)
GType gtk_databox_xyc_graph_get_ytype(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_maxlen(GtkDataboxXYCGraph *xyc_graph)
GType gtk_databox_xyc_graph_get_xtype(GtkDataboxXYCGraph *xyc_graph)
#define GTK_DATABOX_TYPE_XYC_GRAPH
guint gtk_databox_xyc_graph_get_length(GtkDataboxXYCGraph *xyc_graph)
guint gtk_databox_xyc_graph_get_ystart(GtkDataboxXYCGraph *xyc_graph)
void(* draw)(GtkDataboxGraph *graph, GtkDatabox *box)