[goffice] Fixed exponential smoothing related issues.
- From: Jean BrÃfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Fixed exponential smoothing related issues.
- Date: Sat, 19 Nov 2011 20:27:48 +0000 (UTC)
commit abab4199b1c73df4f96152634e85f982d8641694
Author: Jean Brefort <jean brefort normalesup org>
Date: Sat Nov 19 21:26:59 2011 +0100
Fixed exponential smoothing related issues.
ChangeLog | 16 ++++++++++
goffice/graph/gog-smoothed-curve.c | 39 +++++++++++++++++++------
goffice/graph/gog-smoothed-curve.h | 1 +
goffice/graph/gog-trend-line.c | 4 ++-
plugins/smoothing/gog-exp-smooth.c | 56 ++++-------------------------------
plugins/smoothing/gog-exp-smooth.h | 1 -
6 files changed, 57 insertions(+), 60 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index cb2aafc..4df4a40 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2011-11-19 Jean Brefort <jean brefort normalesup org>
+ * goffice/graph/gog-trend-line.c (gog_trend_line_populate_editor): fixed
+ editor build.
+ * goffice/graph/gog-smoothed-curve.c
+ (gog_smoothed_curve_parent_changed),
+ (gog_smoothed_curve_class_init), (gog_smoothed_curve_init),
+ (gog_smoothed_curve_dataset_dims),
+ (gog_smoothed_curve_dataset_get_elem),
+ (gog_smoothed_curve_dataset_dim_changed): fixed data management in
+ exponential smoothing.
+ * goffice/graph/gog-smoothed-curve.h: ditto.
+ * plugins/smoothing/gog-exp-smooth.c (gog_exp_smooth_update),
+ (gog_exp_smooth_class_init), (gog_exp_smooth_init): ditto.
+ * plugins/smoothing/gog-exp-smooth.h: ditto.
+
+2011-11-19 Jean Brefort <jean brefort normalesup org>
+
* goffice/graph/gog-guru.ui: fixed a Gtk warning.
2011-11-16 Jody Goldberg <jody gnome org>
diff --git a/goffice/graph/gog-smoothed-curve.c b/goffice/graph/gog-smoothed-curve.c
index 6986a43..6837e25 100644
--- a/goffice/graph/gog-smoothed-curve.c
+++ b/goffice/graph/gog-smoothed-curve.c
@@ -84,17 +84,31 @@ gog_smoothed_curve_type_name (GogObject const *gobj)
}
static void
+gog_smoothed_curve_parent_changed (GogObject *obj, G_GNUC_UNUSED gboolean was_set)
+{
+ GogSmoothedCurve *sc = GOG_SMOOTHED_CURVE (obj);
+ if (sc->name == NULL) {
+ GogSmoothedCurveClass *klass = (GogSmoothedCurveClass *) G_OBJECT_GET_CLASS (obj);
+ sc->name = g_new0 (GogDatasetElement, klass->max_dim + 2);
+ }
+}
+
+static void
gog_smoothed_curve_class_init (GogObjectClass *gog_klass)
{
GObjectClass *gobject_klass = (GObjectClass *) gog_klass;
GogStyledObjectClass *style_klass = (GogStyledObjectClass *) gog_klass;
+ GogSmoothedCurveClass *curve_klass = (GogSmoothedCurveClass *) gog_klass;
smoothed_curve_parent_klass = g_type_class_peek_parent (gog_klass);
gobject_klass->finalize = gog_smoothed_curve_finalize;
+ curve_klass->max_dim = -1;
style_klass->init_style = gog_smoothed_curve_init_style;
gog_klass->type_name = gog_smoothed_curve_type_name;
+ gog_klass->parent_changed = gog_smoothed_curve_parent_changed;
gog_klass->view_type = gog_smoothed_curve_view_get_type ();
+
#ifdef GOFFICE_WITH_GTK
gog_klass->populate_editor = gog_smoothed_curve_populate_editor;
#endif
@@ -105,34 +119,41 @@ gog_smoothed_curve_init (GogSmoothedCurve *curve)
{
curve->nb = 0;
curve->x = curve->y = NULL;
- curve->name = g_new0 (GogDatasetElement, 1);
}
static void
gog_smoothed_curve_dataset_dims (GogDataset const *set, int *first, int *last)
{
+ GogSmoothedCurveClass *klass = (GogSmoothedCurveClass *) G_OBJECT_GET_CLASS (set);
+
*first = -1;
- *last = -1;
+ *last = klass->max_dim;
}
static GogDatasetElement *
gog_smoothed_curve_dataset_get_elem (GogDataset const *set, int dim_i)
{
GogSmoothedCurve const *sc = GOG_SMOOTHED_CURVE (set);
- g_return_val_if_fail (dim_i == -1, NULL);
- return sc->name;
+ GogSmoothedCurveClass *klass = (GogSmoothedCurveClass *) G_OBJECT_GET_CLASS (set);
+ g_return_val_if_fail (dim_i >= -1 && dim_i <= klass->max_dim, NULL);
+ dim_i++;
+ return sc->name + dim_i;
}
static void
gog_smoothed_curve_dataset_dim_changed (GogDataset *set, int dim_i)
{
- g_return_if_fail (dim_i == -1);
+ GogSmoothedCurveClass *klass = (GogSmoothedCurveClass *) G_OBJECT_GET_CLASS (set);
+ g_return_if_fail (dim_i >= -1 && dim_i <= klass->max_dim);
{
GogSmoothedCurve const *sc = GOG_SMOOTHED_CURVE (set);
- GOData *name_src = sc->name->data;
- char *name = (name_src != NULL)
- ? go_data_get_scalar_string (name_src) : NULL;
- gog_object_set_name (GOG_OBJECT (set), name, NULL);
+ if (dim_i == -1) {
+ GOData *name_src = sc->name->data;
+ char *name = (name_src != NULL)
+ ? go_data_get_scalar_string (name_src) : NULL;
+ gog_object_set_name (GOG_OBJECT (set), name, NULL);
+ } else
+ gog_object_request_update (GOG_OBJECT (set));
}
}
diff --git a/goffice/graph/gog-smoothed-curve.h b/goffice/graph/gog-smoothed-curve.h
index 9c1bc39..ecd0913 100644
--- a/goffice/graph/gog-smoothed-curve.h
+++ b/goffice/graph/gog-smoothed-curve.h
@@ -37,6 +37,7 @@ struct _GogSmoothedCurve {
typedef struct {
GogTrendLineClass base;
+ int max_dim;
} GogSmoothedCurveClass;
diff --git a/goffice/graph/gog-trend-line.c b/goffice/graph/gog-trend-line.c
index 5d6927b..51566e9 100644
--- a/goffice/graph/gog-trend-line.c
+++ b/goffice/graph/gog-trend-line.c
@@ -110,7 +110,9 @@ gog_trend_line_populate_editor (GogObject *gobj,
g_object_get (G_OBJECT (box), "n-rows", &nrows, "n-columns", &ncols, NULL);
gtk_table_resize (table, nrows + 1, ncols);
gtk_table_attach (table, w, 0, ncols, nrows, nrows + 1, GTK_FILL, 0, 0, 0);
- } else
+ } else if (GTK_IS_CONTAINER (box))
+ gtk_container_add (GTK_CONTAINER (box), w);
+ else
g_warning ("Unsupported container");
gtk_widget_show (w);
diff --git a/plugins/smoothing/gog-exp-smooth.c b/plugins/smoothing/gog-exp-smooth.c
index eeaef81..f8d8526 100644
--- a/plugins/smoothing/gog-exp-smooth.c
+++ b/plugins/smoothing/gog-exp-smooth.c
@@ -123,8 +123,8 @@ gog_exp_smooth_update (GogObject *obj)
}
go_range_min (x, n, &xmin);
go_range_max (x, n, &xmax);
- if (es->period->data != NULL)
- period = go_data_get_scalar_value (es->period->data);
+ if (es->base.name[1].data != NULL)
+ period = go_data_get_scalar_value (es->base.name[1].data);
if (period <= 0.)
period = 10. * (xmax - xmin) / (n - 1);
@@ -198,25 +198,12 @@ gog_exp_smooth_set_property (GObject *obj, guint param_id,
}
static void
-gog_exp_smooth_finalize (GObject *obj)
-{
- GogExpSmooth *es = GOG_EXP_SMOOTH (obj);
- if (es->period != NULL) {
- gog_dataset_finalize (GOG_DATASET (obj));
- g_free (es->period);
- es->period = NULL;
- }
- (*exp_smooth_parent_klass->finalize) (obj);
-}
-
-static void
gog_exp_smooth_class_init (GogSmoothedCurveClass *curve_klass)
{
GObjectClass *gobject_klass = (GObjectClass *) curve_klass;
GogObjectClass *gog_object_klass = (GogObjectClass *) curve_klass;
exp_smooth_parent_klass = g_type_class_peek_parent (curve_klass);
- gobject_klass->finalize = gog_exp_smooth_finalize;
gobject_klass->get_property = gog_exp_smooth_get_property;
gobject_klass->set_property = gog_exp_smooth_set_property;
@@ -226,6 +213,8 @@ gog_exp_smooth_class_init (GogSmoothedCurveClass *curve_klass)
gog_object_klass->update = gog_exp_smooth_update;
gog_object_klass->type_name = gog_exp_smooth_type_name;
+ curve_klass->max_dim = 0;
+
g_object_class_install_property (gobject_klass, EXP_SMOOTH_PROP_STEPS,
g_param_spec_int ("steps",
_("Steps"),
@@ -238,39 +227,8 @@ static void
gog_exp_smooth_init (GogExpSmooth *es)
{
es->steps = 100;
- es->period = g_new0 (GogDatasetElement, 1);
-}
-
-static void
-gog_exp_smooth_dataset_dims (GogDataset const *set, int *first, int *last)
-{
- *first = 0;
- *last = 0;
-}
-
-static GogDatasetElement *
-gog_exp_smooth_dataset_get_elem (GogDataset const *set, int dim_i)
-{
- GogExpSmooth const *es = GOG_EXP_SMOOTH (set);
- g_return_val_if_fail (dim_i == 0, NULL);
- return es->period;
-}
-
-static void
-gog_exp_smooth_dataset_dim_changed (GogDataset *set, int dim_i)
-{
- gog_object_request_update (GOG_OBJECT (set));
-}
-
-static void
-gog_exp_smooth_dataset_init (GogDatasetClass *iface)
-{
- iface->get_elem = gog_exp_smooth_dataset_get_elem;
- iface->dims = gog_exp_smooth_dataset_dims;
- iface->dim_changed = gog_exp_smooth_dataset_dim_changed;
}
-GSF_DYNAMIC_CLASS_FULL (GogExpSmooth, gog_exp_smooth,
- NULL, NULL, gog_exp_smooth_class_init, NULL,
- gog_exp_smooth_init, GOG_TYPE_SMOOTHED_CURVE, 0,
- GSF_INTERFACE (gog_exp_smooth_dataset_init, GOG_TYPE_DATASET))
+GSF_DYNAMIC_CLASS (GogExpSmooth, gog_exp_smooth,
+ gog_exp_smooth_class_init, gog_exp_smooth_init,
+ GOG_TYPE_SMOOTHED_CURVE)
diff --git a/plugins/smoothing/gog-exp-smooth.h b/plugins/smoothing/gog-exp-smooth.h
index a7a6b04..6887155 100644
--- a/plugins/smoothing/gog-exp-smooth.h
+++ b/plugins/smoothing/gog-exp-smooth.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
typedef struct {
GogSmoothedCurve base;
- GogDatasetElement *period;
unsigned steps;
} GogExpSmooth;
typedef GogSmoothedCurveClass GogExpSmoothClass;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]