"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "gtk/gtkdatabox_xyc_graph.c" between
gtkdatabox-0.9.3.1.tar.gz and gtkdatabox-1.0.0.tar.gz

About: GtkDatabox is a Gtk+-widget for live display of large amounts of fluctuating numerical data.

gtkdatabox_xyc_graph.c  (gtkdatabox-0.9.3.1):gtkdatabox_xyc_graph.c  (gtkdatabox-1.0.0)
skipping to change at line 17 skipping to change at line 17
* as published by the Free Software Foundation; either version 2.1 * as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <gtkdatabox_xyc_graph.h> #include <gtkdatabox_xyc_graph.h>
G_DEFINE_TYPE(GtkDataboxXYCGraph, gtk_databox_xyc_graph,
GTK_DATABOX_TYPE_GRAPH)
static gint gtk_databox_xyc_graph_real_calculate_extrema (GtkDataboxGraph * static gint gtk_databox_xyc_graph_real_calculate_extrema (GtkDataboxGraph *
xyc_graph, xyc_graph,
gfloat * min_x, gfloat * min_x,
gfloat * max_x, gfloat * max_x,
gfloat * min_y, gfloat * min_y,
gfloat * max_y); gfloat * max_y);
/* IDs of properties */ /* IDs of properties */
enum enum
{ {
PROP_X = 1, PROP_X = 1,
PROP_Y, PROP_Y,
PROP_LEN PROP_LEN,
PROP_MAXLEN,
PROP_XSTART,
PROP_YSTART,
PROP_XSTRIDE,
PROP_YSTRIDE,
PROP_XTYPE,
PROP_YTYPE
}; };
/** /**
* GtkDataboxXYCGraphPrivate * GtkDataboxXYCGraphPrivate
* *
* A private data structure used by the #GtkDataboxXYCGraph. It shields all inte rnal things * A private data structure used by the #GtkDataboxXYCGraph. It shields all inte rnal things
* from developers who are just using the object. * from developers who are just using the object.
* *
**/ **/
typedef struct _GtkDataboxXYCGraphPrivate GtkDataboxXYCGraphPrivate; typedef struct _GtkDataboxXYCGraphPrivate GtkDataboxXYCGraphPrivate;
struct _GtkDataboxXYCGraphPrivate struct _GtkDataboxXYCGraphPrivate
{ {
guint len;
gfloat *X; gfloat *X;
gfloat *Y; gfloat *Y;
guint len;
guint maxlen;
guint xstart;
guint ystart;
guint xstride;
guint ystride;
GType xtype;
GType ytype;
}; };
G_DEFINE_TYPE_WITH_PRIVATE(GtkDataboxXYCGraph, gtk_databox_xyc_graph,
GTK_DATABOX_TYPE_GRAPH)
//static gpointer parent_class = NULL;
void
gtk_databox_xyc_graph_set_X_Y_length(GtkDataboxXYCGraph * xyc_graph, gfloat * X,
gfloat * Y, guint len)
{
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
priv->X = X;
priv->Y = Y;
priv->len = len;
}
static void static void
gtk_databox_xyc_graph_set_X (GtkDataboxXYCGraph * xyc_graph, gfloat * X) gtk_databox_xyc_graph_set_X (GtkDataboxXYCGraph * xyc_graph, gfloat * X)
{ {
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph)); g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
g_return_if_fail (X); g_return_if_fail (X);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
GTK_DATABOX_XYC_GRAPH_GET_PRIVATE(xyc_graph)->X = X; (xyc_graph);
priv->X = X;
g_object_notify (G_OBJECT (xyc_graph), "X-Values"); g_object_notify (G_OBJECT (xyc_graph), "X-Values");
} }
static void static void
gtk_databox_xyc_graph_set_Y (GtkDataboxXYCGraph * xyc_graph, gfloat * Y) gtk_databox_xyc_graph_set_Y (GtkDataboxXYCGraph * xyc_graph, gfloat * Y)
{ {
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph)); g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
g_return_if_fail (Y); g_return_if_fail (Y);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
GTK_DATABOX_XYC_GRAPH_GET_PRIVATE(xyc_graph)->Y = Y; (xyc_graph);
priv->Y = Y;
g_object_notify (G_OBJECT (xyc_graph), "Y-Values"); g_object_notify (G_OBJECT (xyc_graph), "Y-Values");
} }
static void static void
gtk_databox_xyc_graph_set_length (GtkDataboxXYCGraph * xyc_graph, guint len) gtk_databox_xyc_graph_set_length (GtkDataboxXYCGraph * xyc_graph, guint len)
{ {
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph)); g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
g_return_if_fail (len > 0); g_return_if_fail (len > 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
GTK_DATABOX_XYC_GRAPH_GET_PRIVATE(xyc_graph)->len = len; (xyc_graph);
priv->len = len;
g_object_notify (G_OBJECT (xyc_graph), "length"); g_object_notify (G_OBJECT (xyc_graph), "length");
} }
static void static void
gtk_databox_xyc_graph_set_maxlen (GtkDataboxXYCGraph * xyc_graph, guint maxlen)
{
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
g_return_if_fail (maxlen > 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
priv->maxlen = maxlen;
g_object_notify (G_OBJECT (xyc_graph), "maxlen");
}
static void
gtk_databox_xyc_graph_set_xstart (GtkDataboxXYCGraph * xyc_graph, guint xstart)
{
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
priv->xstart = xstart;
g_object_notify (G_OBJECT (xyc_graph), "X-Values");
}
static void
gtk_databox_xyc_graph_set_ystart (GtkDataboxXYCGraph * xyc_graph, guint ystart)
{
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
priv->ystart = ystart;
g_object_notify (G_OBJECT (xyc_graph), "Y-Values");
}
static void
gtk_databox_xyc_graph_set_xstride (GtkDataboxXYCGraph * xyc_graph, guint xstride
)
{
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
priv->xstride = xstride;
g_object_notify (G_OBJECT (xyc_graph), "X-Values");
}
static void
gtk_databox_xyc_graph_set_ystride (GtkDataboxXYCGraph * xyc_graph, guint ystride
)
{
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
priv->ystride = ystride;
g_object_notify (G_OBJECT (xyc_graph), "Y-Values");
}
static void
gtk_databox_xyc_graph_set_xtype (GtkDataboxXYCGraph * xyc_graph, GType xtype)
{
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
priv->xtype = xtype;
g_object_notify (G_OBJECT (xyc_graph), "X-Values");
}
static void
gtk_databox_xyc_graph_set_ytype (GtkDataboxXYCGraph * xyc_graph, GType ytype)
{
g_return_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph));
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
priv->ytype = ytype;
g_object_notify (G_OBJECT (xyc_graph), "Y-Values");
}
static void
gtk_databox_xyc_graph_set_property (GObject * object, gtk_databox_xyc_graph_set_property (GObject * object,
guint property_id, guint property_id,
const GValue * value, GParamSpec * pspec) const GValue * value, GParamSpec * pspec)
{ {
GtkDataboxXYCGraph *xyc_graph = GTK_DATABOX_XYC_GRAPH (object); GtkDataboxXYCGraph *xyc_graph = GTK_DATABOX_XYC_GRAPH (object);
switch (property_id) switch (property_id)
{ {
case PROP_X: case PROP_X:
{ gtk_databox_xyc_graph_set_X (xyc_graph, (gfloat *) g_value_get_pointer (va
gtk_databox_xyc_graph_set_X (xyc_graph, lue));
(gfloat *) g_value_get_pointer (value));
}
break; break;
case PROP_Y: case PROP_Y:
{ gtk_databox_xyc_graph_set_Y (xyc_graph, (gfloat *) g_value_get_pointer (va
gtk_databox_xyc_graph_set_Y (xyc_graph, lue));
(gfloat *) g_value_get_pointer (value));
}
break; break;
case PROP_LEN: case PROP_LEN:
{ gtk_databox_xyc_graph_set_length (xyc_graph, g_value_get_int (value));
gtk_databox_xyc_graph_set_length (xyc_graph, break;
g_value_get_int (value)); case PROP_MAXLEN:
} gtk_databox_xyc_graph_set_maxlen (xyc_graph, g_value_get_int (value));
break;
case PROP_XSTART:
gtk_databox_xyc_graph_set_xstart (xyc_graph, g_value_get_int (value));
break;
case PROP_YSTART:
gtk_databox_xyc_graph_set_ystart (xyc_graph, g_value_get_int (value));
break;
case PROP_XSTRIDE:
gtk_databox_xyc_graph_set_xstride (xyc_graph, g_value_get_int (value));
break;
case PROP_YSTRIDE:
gtk_databox_xyc_graph_set_ystride (xyc_graph, g_value_get_int (value));
break;
case PROP_XTYPE:
gtk_databox_xyc_graph_set_xtype (xyc_graph, g_value_get_gtype (value));
break;
case PROP_YTYPE:
gtk_databox_xyc_graph_set_ytype (xyc_graph, g_value_get_gtype (value));
break; break;
default: default:
/* We don't have any other property... */ /* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
} }
} }
/** /**
* gtk_databox_xyc_graph_get_X: * gtk_databox_xyc_graph_get_X:
* @xyc_graph: A #GtkDataboxXYCGraph object * @xyc_graph: A #GtkDataboxXYCGraph object
* *
* Gets the X values of the @xzc_graph. * Gets the X values of the @xzc_graph.
* *
* Return value: Pointer to X values * Return value: Pointer to X values
*/ */
gfloat * gfloat *
gtk_databox_xyc_graph_get_X (GtkDataboxXYCGraph * xyc_graph) gtk_databox_xyc_graph_get_X (GtkDataboxXYCGraph * xyc_graph)
{ {
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), NULL); g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), NULL);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
return GTK_DATABOX_XYC_GRAPH_GET_PRIVATE(xyc_graph)->X; (xyc_graph);
return priv->X;
} }
/** /**
* gtk_databox_xyc_graph_get_Y: * gtk_databox_xyc_graph_get_Y:
* @xyc_graph: A #GtkDataboxXYCGraph object * @xyc_graph: A #GtkDataboxXYCGraph object
* *
* Gets the Y values of the @xzc_graph. * Gets the Y values of the @xzc_graph.
* *
* Return value: Pointer to Y values * Return value: Pointer to Y values
*/ */
gfloat * gfloat *
gtk_databox_xyc_graph_get_Y (GtkDataboxXYCGraph * xyc_graph) gtk_databox_xyc_graph_get_Y (GtkDataboxXYCGraph * xyc_graph)
{ {
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), NULL); g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), NULL);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
return GTK_DATABOX_XYC_GRAPH_GET_PRIVATE(xyc_graph)->Y; (xyc_graph);
return priv->Y;
} }
/** /**
* gtk_databox_xyc_graph_get_length: * gtk_databox_xyc_graph_get_length:
* @xyc_graph: A #GtkDataboxXYCGraph object * @xyc_graph: A #GtkDataboxXYCGraph object
* *
* Gets the the length of the X and Y values arrays. * Gets the the length of the X and Y values arrays.
* *
* Return value: Length of X/Y arrays. * Return value: Length of X/Y arrays.
*/ */
guint guint
gtk_databox_xyc_graph_get_length (GtkDataboxXYCGraph * xyc_graph) gtk_databox_xyc_graph_get_length (GtkDataboxXYCGraph * xyc_graph)
{ {
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0); g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
return priv->len;
}
/**
* gtk_databox_xyc_graph_get_maxlen:
* @xyc_graph: A #GtkDataboxXYCGraph object
*
* Gets the the maxlen of the X and Y values arrays.
*
* Return value: Size of X/Y arrays.
*/
guint
gtk_databox_xyc_graph_get_maxlen (GtkDataboxXYCGraph * xyc_graph)
{
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
return priv->maxlen;
}
/**
* gtk_databox_xyc_graph_get_xstart:
* @xyc_graph: A #GtkDataboxXYCGraph object
*
* Gets the the start offset of the X values array. This is the element in the
array pointed to by X that will be the first element plotted.
* If X is a pointer to a gfloat array, and xstart is 5, then x[5] will be the f
irst data element. If Xstride is 1, then x[6] will be the
* second element. x[5 + len - 1] will be last element.
* Usually, xstart will be 0. It can be nonzero to allow for interleaved X/Y sa
mples, or if the data is stored as a matrix, then X can point
* to the start of the matrix, xstart can be the column number, and xstride the
number of columns.
*
* Return value: The xstart value.
*/
guint
gtk_databox_xyc_graph_get_xstart (GtkDataboxXYCGraph * xyc_graph)
{
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
return priv->xstart;
}
return GTK_DATABOX_XYC_GRAPH_GET_PRIVATE(xyc_graph)->len; /**
* gtk_databox_xyc_graph_get_ystart:
* @xyc_graph: A #GtkDataboxXYCGraph object
*
* Gets the the start offset of the Y values array. This is the element in the
array pointed to by Y that will be the first element plotted.
* If Y is a pointer to a gfloat array, and ystart is 5, then y[5] will be the f
irst data element. If Ystride is 1, then y[6] will be the
* second element. y[5 + len - 1] will be last element.
* Usually, ystart will be 0. It can be nonzero to allow for interleaved X/Y sa
mples, or if the data is stored as a matrix, then Y can point
* to the start of the matrix, ystart can be the column number, and ystride the
number of columns.
*
* Return value: The ystart value.
*/
guint
gtk_databox_xyc_graph_get_ystart (GtkDataboxXYCGraph * xyc_graph)
{
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
return priv->ystart;
}
/**
* gtk_databox_xyc_graph_get_xstride:
* @xyc_graph: A #GtkDataboxXYCGraph object
*
* Gets the the stride offset of the X values array. This is the element in the
array pointed to by X that will be the first element plotted.
* If X is a pointer to a gfloat array, and xstart is 5, then x[5] will be the f
irst data element. If Xstride is 1, then x[6] will be the
* second element. x[5 + len - 1] will be last element.
* Usually, xstride will be 1. It can be nonzero to allow for interleaved X/Y s
amples, or if the data is stored as a matrix, then X can point
* to the start of the matrix, xstart can be the column number, and xstride the
number of columns.
*
* Return value: The xstride value.
*/
guint
gtk_databox_xyc_graph_get_xstride (GtkDataboxXYCGraph * xyc_graph)
{
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
return priv->xstride;
}
/**
* gtk_databox_xyc_graph_get_ystride:
* @xyc_graph: A #GtkDataboxXYCGraph object
*
* Gets the the stride offset of the Y values array. This is the element in the
array pointed to by Y that will be the first element plotted.
* If Y is a pointer to a gfloat array, and ystart is 5, then y[5] will be the f
irst data element. If Ystride is 1, then y[6] will be the
* second element. y[5 + len - 1] will be last element.
* Usually, ystride will be 1. It can be nonzero to allow for interleaved X/Y s
amples, or if the data is stored as a matrix, then Y can point
* to the start of the matrix, ystart can be the column number, and ystride the
number of columns.
*
* Return value: The ystride value.
*/
guint
gtk_databox_xyc_graph_get_ystride (GtkDataboxXYCGraph * xyc_graph)
{
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
return priv->ystride;
}
/**
* gtk_databox_xyc_graph_get_xtype:
* @xyc_graph: A #GtkDataboxXYCGraph object
*
* Gets the the GType of the X array elements. This may be G_TYPE_FLOAT, G_TYPE
_DOUBLE, or similar.
*
* Return value: A GType, usually this is G_TYPE_FLOAT.
*/
GType
gtk_databox_xyc_graph_get_xtype (GtkDataboxXYCGraph * xyc_graph)
{
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
return priv->xtype;
}
/**
* gtk_databox_xyc_graph_get_ytype:
* @xyc_graph: A #GtkDataboxXYCGraph object
*
* Gets the the GType of the Y array elements. This may be G_TYPE_FLOAT, G_TYPE
_DOUBLE, or similar.
*
* Return value: A GType, usually this is G_TYPE_FLOAT.
*/
GType
gtk_databox_xyc_graph_get_ytype (GtkDataboxXYCGraph * xyc_graph)
{
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (xyc_graph), 0);
GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
(xyc_graph);
return priv->ytype;
} }
static void static void
gtk_databox_xyc_graph_get_property (GObject * object, gtk_databox_xyc_graph_get_property (GObject * object,
guint property_id, guint property_id,
GValue * value, GParamSpec * pspec) GValue * value, GParamSpec * pspec)
{ {
GtkDataboxXYCGraph *xyc_graph = GTK_DATABOX_XYC_GRAPH (object); GtkDataboxXYCGraph *xyc_graph = GTK_DATABOX_XYC_GRAPH (object);
switch (property_id) switch (property_id)
{ {
case PROP_X: case PROP_X:
{ g_value_set_pointer (value, gtk_databox_xyc_graph_get_X (xyc_graph));
g_value_set_pointer (value, gtk_databox_xyc_graph_get_X (xyc_graph));
}
break; break;
case PROP_Y: case PROP_Y:
{ g_value_set_pointer (value, gtk_databox_xyc_graph_get_Y (xyc_graph));
g_value_set_pointer (value, gtk_databox_xyc_graph_get_Y (xyc_graph));
}
break; break;
case PROP_LEN: case PROP_LEN:
{ g_value_set_int (value, gtk_databox_xyc_graph_get_length (xyc_graph));
g_value_set_int (value, break;
gtk_databox_xyc_graph_get_length (xyc_graph)); case PROP_MAXLEN:
} g_value_set_int (value, gtk_databox_xyc_graph_get_maxlen (xyc_graph));
break;
case PROP_XSTART:
g_value_set_int (value, gtk_databox_xyc_graph_get_xstart (xyc_graph));
break;
case PROP_YSTART:
g_value_set_int (value, gtk_databox_xyc_graph_get_ystart (xyc_graph));
break;
case PROP_XSTRIDE:
g_value_set_int (value, gtk_databox_xyc_graph_get_xstride (xyc_graph));
break;
case PROP_YSTRIDE:
g_value_set_int (value, gtk_databox_xyc_graph_get_ystride (xyc_graph));
break;
case PROP_XTYPE:
g_value_set_gtype (value, gtk_databox_xyc_graph_get_xtype (xyc_graph));
break;
case PROP_YTYPE:
g_value_set_gtype (value, gtk_databox_xyc_graph_get_ytype (xyc_graph));
break; break;
default: default:
/* We don't have any other property... */ /* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
} }
} }
static void static void
gtk_databox_xyc_graph_class_init (GtkDataboxXYCGraphClass *klass) gtk_databox_xyc_graph_class_init (GtkDataboxXYCGraphClass *klass)
skipping to change at line 238 skipping to change at line 490
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_Y, xyc_graph_param_spec); PROP_Y, xyc_graph_param_spec);
xyc_graph_param_spec = g_param_spec_int ("length", "length of X and Y", "numb er of data points", G_MININT, G_MAXINT, 0, /* default value */ xyc_graph_param_spec = g_param_spec_int ("length", "length of X and Y", "numb er of data points", G_MININT, G_MAXINT, 0, /* default value */
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE); G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_LEN, xyc_graph_param_spec); PROP_LEN, xyc_graph_param_spec);
xyc_graph_param_spec = g_param_spec_int ("maxlen", "maxlen of X and Y", "maxi
mal number of data points", G_MININT, G_MAXINT, 0, /* default value */
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_MAXLEN, xyc_graph_param_spec);
xyc_graph_param_spec = g_param_spec_int ("xstart", "array index of first X",
"array index of first X", G_MININT, G_MAXINT, 0, /* default value */
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_XSTART, xyc_graph_param_spec);
xyc_graph_param_spec = g_param_spec_int ("ystart", "array index of first Y",
"array index of first Y", G_MININT, G_MAXINT, 0, /* default value */
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_YSTART, xyc_graph_param_spec);
xyc_graph_param_spec = g_param_spec_int ("xstride", "stride of X values", "st
ride of X values", G_MININT, G_MAXINT, 1, /* default value */
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_XSTRIDE, xyc_graph_param_spec);
xyc_graph_param_spec = g_param_spec_int ("ystride", "stride of Y values", "st
ride of Y values", G_MININT, G_MAXINT, 1, /* default value */
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_YSTRIDE, xyc_graph_param_spec);
xyc_graph_param_spec = g_param_spec_gtype ("xtype", "GType of X elements", "G
Type of X elements", G_TYPE_NONE,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_XTYPE, xyc_graph_param_spec);
xyc_graph_param_spec = g_param_spec_gtype ("ytype", "GType of Y elements", "G
Type of Y elements", G_TYPE_NONE,
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_YTYPE, xyc_graph_param_spec);
graph_class->calculate_extrema = graph_class->calculate_extrema =
gtk_databox_xyc_graph_real_calculate_extrema; gtk_databox_xyc_graph_real_calculate_extrema;
g_type_class_add_private (klass, sizeof (GtkDataboxXYCGraphPrivate));
} }
static void static void
gtk_databox_xyc_graph_init (GtkDataboxXYCGraph *xyc_graph __attribute__((unused) )) gtk_databox_xyc_graph_init (GtkDataboxXYCGraph *xyc_graph)
{ {
if (xyc_graph == NULL) g_warning ("xyc_graph_init with NULL");
} }
static gint static gint
gtk_databox_xyc_graph_real_calculate_extrema (GtkDataboxGraph * graph, gtk_databox_xyc_graph_real_calculate_extrema (GtkDataboxGraph * graph,
gfloat * min_x, gfloat * max_x, gfloat * min_x, gfloat * max_x,
gfloat * min_y, gfloat * max_y) gfloat * min_y, gfloat * max_y)
{ {
GtkDataboxXYCGraph *xyc_graph = GTK_DATABOX_XYC_GRAPH (graph); GtkDataboxXYCGraph *xyc_graph = GTK_DATABOX_XYC_GRAPH (graph);
GtkDataboxXYCGraphPrivate *priv = GTK_DATABOX_XYC_GRAPH_GET_PRIVATE(xyc_graph GtkDataboxXYCGraphPrivate *priv = gtk_databox_xyc_graph_get_instance_private
); (xyc_graph);
guint i, indx, len, maxlen, start, stride;
guint i; void *values;
GType vtype;
gfloat fval = 0.0, minval = 0.0, maxval = 0.0;
g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (graph), -1); g_return_val_if_fail (GTK_DATABOX_IS_XYC_GRAPH (graph), -1);
g_return_val_if_fail (min_x, -1); g_return_val_if_fail (min_x, -1);
g_return_val_if_fail (max_x, -1); g_return_val_if_fail (max_x, -1);
g_return_val_if_fail (min_y, -1); g_return_val_if_fail (min_y, -1);
g_return_val_if_fail (max_y, -1); g_return_val_if_fail (max_y, -1);
g_return_val_if_fail (priv->len, -1); g_return_val_if_fail (priv->len, -1);
*min_x = *max_x = priv->X[0]; len = priv->len;
*min_y = *max_y = priv->Y[0]; maxlen = priv->maxlen;
values = priv->X;
vtype = priv->xtype;
start = priv->xstart;
stride = priv->xstride;
indx = start * stride;
i = 0;
do {
if (vtype == G_TYPE_FLOAT)
fval = ((gfloat *)values)[indx];
else if (vtype == G_TYPE_DOUBLE)
fval = ((gdouble *)values)[indx];
else if (vtype == G_TYPE_INT)
fval = ((gint *)values)[indx];
else if (vtype == G_TYPE_UINT)
fval = ((guint *)values)[indx];
else if (vtype == G_TYPE_LONG)
fval = ((glong *)values)[indx];
else if (vtype == G_TYPE_ULONG)
fval = ((gulong *)values)[indx];
else if (vtype == G_TYPE_INT64)
fval = ((gint64 *)values)[indx];
else if (vtype == G_TYPE_UINT64)
fval = ((guint64 *)values)[indx];
else if (vtype == G_TYPE_CHAR)
fval = ((gchar *)values)[indx];
else if (vtype == G_TYPE_UCHAR)
fval = ((guchar *)values)[indx];
if (i==0)
{
minval = maxval = fval;
}
else
{
if (fval < minval) minval = fval;
if (fval > maxval) maxval = fval;
}
/* handle the wrap-around (ring buffer) issue using modulus. for
efficiency, don't do this for non-wraparound cases. */
/* note this allows multiple wrap-arounds. One could hold a sing
le cycle of a sine wave, and plot a continuous wave */
/* This can be optimized using pointers later */
if (i + start > maxlen)
indx = ((i + start) % maxlen) * stride;
else
indx += stride;
} while (++i < len);
*min_x = minval;
*max_x = maxval;
values = priv->Y;
vtype = priv->ytype;
start = priv->ystart;
stride = priv->ystride;
indx = start * stride;
i = 0;
do {
if (vtype == G_TYPE_FLOAT)
fval = ((gfloat *)values)[indx];
else if (vtype == G_TYPE_DOUBLE)
fval = ((gdouble *)values)[indx];
else if (vtype == G_TYPE_INT)
fval = ((gint *)values)[indx];
else if (vtype == G_TYPE_UINT)
fval = ((guint *)values)[indx];
else if (vtype == G_TYPE_LONG)
fval = ((glong *)values)[indx];
else if (vtype == G_TYPE_ULONG)
fval = ((gulong *)values)[indx];
else if (vtype == G_TYPE_INT64)
fval = ((gint64 *)values)[indx];
else if (vtype == G_TYPE_UINT64)
fval = ((guint64 *)values)[indx];
else if (vtype == G_TYPE_CHAR)
fval = ((gchar *)values)[indx];
else if (vtype == G_TYPE_UCHAR)
fval = ((guchar *)values)[indx];
if (i==0) /* yes putting this check inside the loop is inefficien
t, but it makes the code simpler */
{
minval = maxval = fval;
}
else
{
if (fval < minval) minval = fval;
if (fval > maxval) maxval = fval;
}
/* handle the wrap-around (ring buffer) issue using modulus. for
efficiency, don't do this for non-wraparound cases. */
/* note this allows multiple wrap-arounds. One could hold a sing
le cycle of a sine wave, and plot a continuous wave */
/* This can be optimized using pointers later */
if (i + start > maxlen)
indx = ((i + start) % maxlen) * stride;
else
indx += stride;
} while (++i < len);
for (i = 1; i < priv->len; ++i) *min_y = minval;
{ *max_y = maxval;
if (priv->X[i] < *min_x)
*min_x = priv->X[i];
else if (priv->X[i] > *max_x)
*max_x = priv->X[i];
if (priv->Y[i] < *min_y)
*min_y = priv->Y[i];
else if (priv->Y[i] > *max_y)
*max_y = priv->Y[i];
}
return 0; return 0;
} }
 End of changes. 27 change blocks. 
59 lines changed or deleted 499 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)