Skip to content
This repository was archived by the owner on Aug 29, 2021. It is now read-only.

Commit 74e9fce

Browse files
committed
Add get_extrema implementation to GoatDatasetStore
Also add dummy implementations for `get_color` and `get_style`.
1 parent 421ba13 commit 74e9fce

File tree

2 files changed

+74
-16
lines changed

2 files changed

+74
-16
lines changed

src/goat-dataset-store.c

Lines changed: 73 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ GoatDatasetStore *goat_dataset_store_new (GtkTreeModel *tree_model)
2525

2626
static void goat_dataset_store_finalize (GObject *object)
2727
{
28-
GoatDatasetStore *self = (GoatDatasetStore *)object;
28+
/* GoatDatasetStore *self = (GoatDatasetStore *)object; */
2929
/* GoatDatasetStorePrivate *priv = goat_dataset_store_get_instance_private (self); */
3030

3131
G_OBJECT_CLASS (goat_dataset_store_parent_class)->finalize (object);
@@ -86,17 +86,18 @@ static void goat_dataset_store_class_init (GoatDatasetStoreClass *klass)
8686
object_class->set_property = goat_dataset_store_set_property;
8787

8888
obj_properties[PROP_TREE_MODEL] =
89-
g_param_spec_object ("tree-model", "GoatDatasetStore::tree-model", "the backend tree store", GTK_TYPE_TREE_MODEL,
90-
G_PARAM_READWRITE | G_PARAM_STATIC_BLURB);
89+
g_param_spec_object ("tree-model", "GoatDatasetStore::tree-model", "the backend tree store",
90+
GTK_TYPE_TREE_MODEL, G_PARAM_READWRITE | G_PARAM_STATIC_BLURB);
9191

92-
obj_properties[PROP_X_INDEX] = g_param_spec_int ("x-index", "GoatDatasetStore::x-index", "mapping", -1, G_MAXINT, -1,
93-
G_PARAM_READWRITE | G_PARAM_STATIC_BLURB);
92+
obj_properties[PROP_X_INDEX] = g_param_spec_int ("x-index", "GoatDatasetStore::x-index", "mapping", -1, G_MAXINT,
93+
-1, G_PARAM_READWRITE | G_PARAM_STATIC_BLURB);
9494

95-
obj_properties[PROP_Y_INDEX] = g_param_spec_int ("y-index", "GoatDatasetStore::y-index", "mapping", -1, G_MAXINT, -1,
96-
G_PARAM_READWRITE | G_PARAM_STATIC_BLURB);
95+
obj_properties[PROP_Y_INDEX] = g_param_spec_int ("y-index", "GoatDatasetStore::y-index", "mapping", -1, G_MAXINT,
96+
-1, G_PARAM_READWRITE | G_PARAM_STATIC_BLURB);
9797

98-
obj_properties[PROP_YSTDDEV_INDEX] = g_param_spec_int ("ystddev-index", "GoatDatasetStore::ystddev-index",
99-
"mapping", -1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_BLURB);
98+
obj_properties[PROP_YSTDDEV_INDEX] =
99+
g_param_spec_int ("ystddev-index", "GoatDatasetStore::ystddev-index", "mapping", -1, G_MAXINT, -1,
100+
G_PARAM_READWRITE | G_PARAM_STATIC_BLURB);
100101

101102
g_object_class_install_properties (object_class, N_PROPS, obj_properties);
102103
}
@@ -105,9 +106,9 @@ static void goat_dataset_store_init (GoatDatasetStore *self)
105106
{
106107
GoatDatasetStorePrivate *priv = goat_dataset_store_get_instance_private (self);
107108
priv->tree_model = NULL;
108-
priv->x_index = -1; // minus one so gtk_tree_model_get stops parsing
109-
priv->y_index = -1;
110-
priv->ystddev_index = -1;
109+
priv->x_index = -1; // minus one so gtk_tree_model_get stops parsing
110+
priv->y_index = -1;
111+
priv->ystddev_index = -1;
111112
}
112113

113114
static gboolean iter_init (GoatDataset *dataset, GoatDatasetIter *iter)
@@ -138,12 +139,67 @@ static gboolean get (GoatDataset *dataset, GoatDatasetIter *iter, gdouble *x, gd
138139
GoatDatasetStore *self = GOAT_DATASET_STORE (dataset);
139140
GoatDatasetStorePrivate *priv = goat_dataset_store_get_instance_private (self);
140141

141-
gtk_tree_model_get (priv->tree_model, (GtkTreeIter *)(iter->state), priv->x_index, x, priv->y_index, y, priv->ystddev_index, ystddev, -1);
142+
gtk_tree_model_get (priv->tree_model, (GtkTreeIter *)(iter->state), priv->x_index, x, priv->y_index, y,
143+
priv->ystddev_index, ystddev, -1);
142144
return TRUE;
143145
}
144146

145-
static gboolean get_extrema(GoatDataset *dataset, gdouble *x, gdouble *y, gdouble *ystddev) {
146-
return FALSE; // FIXME
147+
// FIXME make this the interface default implementation?
148+
static gboolean get_extrema (GoatDataset *dataset, gdouble *x_min, gdouble *x_max, gdouble *y_min, gdouble *y_max)
149+
{
150+
g_return_val_if_fail (dataset, FALSE);
151+
g_return_val_if_fail (GOAT_IS_DATASET_STORE (dataset), FALSE);
152+
GoatDatasetStore *self = GOAT_DATASET_STORE (dataset);
153+
154+
GoatDatasetIter iter;
155+
double x, y, ystddev;
156+
157+
x = y = ystddev = 0.;
158+
159+
*x_min = 0.;
160+
*x_max = 0.;
161+
*y_min = 0.;
162+
*y_max = 0.;
163+
164+
if (goat_dataset_get_iter_first (GOAT_DATASET (self), &iter)) {
165+
goat_dataset_get (GOAT_DATASET (self), &iter, &x, &y, &ystddev);
166+
if (goat_dataset_iter_next (GOAT_DATASET (self), &iter)) {
167+
*x_min = *x_max = x;
168+
*y_min = y + ystddev;
169+
*y_max = y - ystddev;
170+
if (goat_dataset_iter_next (GOAT_DATASET (self), &iter)) {
171+
do {
172+
goat_dataset_get (GOAT_DATASET (self), &iter, &x, &y, &ystddev);
173+
174+
if (x < *x_min) {
175+
*x_min = x;
176+
}
177+
if (x > *x_max) {
178+
*x_max = x;
179+
}
180+
if (y - ystddev < *y_min) {
181+
*y_min = y - ystddev;
182+
}
183+
if (y + ystddev > *y_max) {
184+
*y_max = y + ystddev;
185+
}
186+
} while (goat_dataset_iter_next (GOAT_DATASET (self), &iter));
187+
}
188+
return TRUE;
189+
}
190+
}
191+
return FALSE;
192+
}
193+
194+
195+
static GoatMarkerStyle get_marker_style (GoatDataset *dataset)
196+
{
197+
return GOAT_MARKER_STYLE_POINT; // FIXME
198+
}
199+
200+
static void get_color (GoatDataset *dataset, GdkRGBA *color)
201+
{
202+
gdk_rgba_parse (color, "mediumseagreen"); // FIXME
147203
}
148204

149205
static void goat_dataset_store_interface_init (GoatDatasetInterface *iface)
@@ -152,4 +208,6 @@ static void goat_dataset_store_interface_init (GoatDatasetInterface *iface)
152208
iface->iter_next = iter_next;
153209
iface->get = get;
154210
iface->get_extrema = get_extrema;
211+
iface->get_marker_style = get_marker_style;
212+
iface->get_color = get_color;
155213
}

src/goat-dataset-store.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef GOAT_DATASET_STORE_H
22
#define GOAT_DATASET_STORE_H
33

4-
#include <gtk/gtk.h>
54
#include <goat-dataset-interface.h>
5+
#include <gtk/gtk.h>
66

77
G_BEGIN_DECLS
88

0 commit comments

Comments
 (0)