[goffice] Fix criticals when adding a trend line. [#676641]



commit 3673e3a64a11ef9ad26859f3fb04cb27db6d6a31
Author: Jean Brefort <jean brefort normalesup org>
Date:   Thu May 24 16:21:41 2012 +0200

    Fix criticals when adding a trend line. [#676641]

 ChangeLog                            |   16 ++++++++++++++++
 NEWS                                 |    2 ++
 goffice/graph/gog-reg-curve.c        |   31 ++++++++++++++-----------------
 plugins/reg_linear/gog-lin-reg.c     |    7 ++++++-
 plugins/reg_linear/gog-log-reg.c     |    2 +-
 plugins/reg_linear/gog-polynom-reg.c |    6 +++++-
 6 files changed, 44 insertions(+), 20 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a440636..70456e6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2012-05-24  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/graph/gog-reg-curve.c (gog_reg_curve_populate_editor): fix
+	criticals, with gtk+ < 3.2, [#676641]
+	(gog_reg_curve_view_render): fix limits with a discrete X-axis.
+	* plugins/reg_linear/gog-lin-reg.c
+	(gog_lin_reg_curve_build_values), fix x automatic values,
+	(gog_lin_reg_curve_populate_editor): fix
+	criticals, with gtk+ < 3.2. [#676641]
+	* plugins/reg_linear/gog-log-reg.c
+	(gog_log_reg_curve_build_values): fix x automatic values.
+	* plugins/reg_linear/gog-polynom-reg.c
+	(gog_polynom_reg_curve_build_values), fix x automatic values,
+	(gog_polynom_reg_curve_populate_editor): fix
+	criticals, with gtk+ < 3.2. [#676641]
+
 2012-05-21  Jean Brefort  <jean brefort normalesup org>
 
 	* configure.in: copied code from introspection.m4
diff --git a/NEWS b/NEWS
index d7e2c22..5fced83 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ Andreas:
 Jean:
 	* Fixed logfit equation typo. [#675560]
 	* Fix text item position when clipped. [#676067]
+	* Fix criticals when adding a trend line. [#676641]
+	* Fix trend lines limits for impled X values.
 
 --------------------------------------------------------------------------
 goffice 0.9.3:
diff --git a/goffice/graph/gog-reg-curve.c b/goffice/graph/gog-reg-curve.c
index 990897c..239a1db 100644
--- a/goffice/graph/gog-reg-curve.c
+++ b/goffice/graph/gog-reg-curve.c
@@ -163,6 +163,9 @@ gog_reg_curve_populate_editor (GogObject	*gobj,
 	gtk_combo_box_set_active (GTK_COMBO_BOX (w), db);
 	g_signal_connect (G_OBJECT (w), "changed",
 		G_CALLBACK (limits_changed_cb), cl);
+#if !GTK_CHECK_VERSION(3,2,0)
+	g_object_set_data (G_OBJECT (grid), "last-label", gtk_builder_get_object (gui, "last-lbl"));
+#endif
 	if ((GOG_REG_CURVE_GET_CLASS (gobj))->populate_editor != NULL)
 		(GOG_REG_CURVE_GET_CLASS (gobj))->populate_editor (GOG_REG_CURVE (gobj), grid);
 
@@ -403,7 +406,7 @@ gog_reg_curve_view_render (GogView *view, GogViewAllocation const *bbox)
 	GOPath *path;
 	GSList *ptr;
 	double *x, *y;
-	double delta_x;
+	double min, max, delta_x;
 	int i;
 
 	chart_map = gog_chart_map_new (chart, &view->residual,
@@ -424,6 +427,8 @@ gog_reg_curve_view_render (GogView *view, GogViewAllocation const *bbox)
 	y = g_new (double, rc->ninterp + 1);
 	switch (rc->drawing_bounds) {
 	case GOG_REG_CURVE_DRAWING_BOUNDS_NONE:
+		min = gog_axis_map_from_view (x_map, view->residual.x);
+		max = gog_axis_map_from_view (x_map, view->residual.x + view->residual.w);
 		delta_x = view->residual.w / rc->ninterp;
 		for (i = 0; i <= rc->ninterp; i++) {
 			x[i] = gog_axis_map_from_view (x_map, i * delta_x + view->residual.x);
@@ -431,7 +436,6 @@ gog_reg_curve_view_render (GogView *view, GogViewAllocation const *bbox)
 		}
 		break;
 	case GOG_REG_CURVE_DRAWING_BOUNDS_ABSOLUTE: {
-		double min, max;
 		if (rc->bounds[2].data) {
 			min = go_data_get_scalar_value (rc->bounds[2].data);
 			if (min == go_nan || !go_finite (min))
@@ -446,16 +450,10 @@ gog_reg_curve_view_render (GogView *view, GogViewAllocation const *bbox)
 
 		} else
 			max = gog_axis_map_from_view (x_map, view->residual.x + view->residual.w);
-
-		delta_x = (max - min) / rc->ninterp;
-		for (i = 0; i <= rc->ninterp; i++) {
-			x[i] = min + i * delta_x;
-			y[i] = gog_reg_curve_get_value_at (rc, x[i]);
-		}
 		break;
 	}
 	case GOG_REG_CURVE_DRAWING_BOUNDS_RELATIVE: {
-		double min, max, val;
+		double val;
 		GOData *data = NULL;
 		GogSeries *series = GOG_SERIES (gog_object_get_parent (GOG_OBJECT (rc)));
 		GogSeriesDesc *desc = &GOG_PLOT_GET_CLASS (series->plot)->desc.series;
@@ -469,8 +467,8 @@ gog_reg_curve_view_render (GogView *view, GogViewAllocation const *bbox)
 		if (data)
 			go_data_get_bounds (data, &min, &max);
 		else {
-			min = 0.;
-			max = series->num_elements - 1;
+			min = 1.;
+			max = series->num_elements;
 		}
 		if (rc->bounds[0].data) {
 			val = go_data_get_scalar_value (rc->bounds[0].data);
@@ -494,16 +492,15 @@ gog_reg_curve_view_render (GogView *view, GogViewAllocation const *bbox)
 				max += val;
 
 		}
-
-		delta_x = (max - min) / rc->ninterp;
-		for (i = 0; i <= rc->ninterp; i++) {
-			x[i] = min + i * delta_x;
-			y[i] = gog_reg_curve_get_value_at (rc, x[i]);
-		}
 		break;
 	}
 	}
 
+	delta_x = (max - min) / rc->ninterp;
+	for (i = 0; i <= rc->ninterp; i++) {
+		x[i] = min + i * delta_x;
+		y[i] = gog_reg_curve_get_value_at (rc, x[i]);
+	}
 	path = gog_chart_map_make_path (chart_map, x, y, rc->ninterp + 1, GO_LINE_INTERPOLATION_CUBIC_SPLINE, FALSE, NULL);
 	style = GOG_STYLED_OBJECT (rc)->style;
 	gog_renderer_push_style (view->renderer, style);
diff --git a/plugins/reg_linear/gog-lin-reg.c b/plugins/reg_linear/gog-lin-reg.c
index e49b1d3..b8c53b0 100644
--- a/plugins/reg_linear/gog-lin-reg.c
+++ b/plugins/reg_linear/gog-lin-reg.c
@@ -120,7 +120,7 @@ gog_lin_reg_curve_build_values (GogLinRegCurve *rc, double const *x_vals, double
 	g_free (rc->y_vals);
 	rc->y_vals = g_new (double, n);
 	for (i = 0, used = 0; i < n; i++) {
-		x = (x_vals)? x_vals[i]: i;
+		x = (x_vals)? x_vals[i]: i + 1;
 		y = y_vals[i];
 		if (!go_finite (x) || !go_finite (y)) {
 			if (rc->base.skip_invalid)
@@ -156,7 +156,12 @@ gog_lin_reg_curve_populate_editor (GogRegCurve *reg_curve, gpointer table)
 	w = gtk_check_button_new_with_label (_("Affine"));
 	gtk_widget_set_tooltip_text (w, _("Uncheck to force zero intercept"));
 	gtk_widget_show (w);
+#if GTK_CHECK_VERSION(3,2,0)
 	gtk_grid_attach_next_to (table, w, NULL, GTK_POS_BOTTOM, 1, 3);
+#else
+	gtk_grid_attach_next_to (table, w, GTK_WIDGET (g_object_get_data (table, "last-label")), GTK_POS_BOTTOM, 1, 3);
+	g_object_set_data (G_OBJECT (table), "last-label", w);
+#endif
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), lin->affine);
 	g_signal_connect (G_OBJECT (w), "toggled", G_CALLBACK (affine_toggled_cb), lin);
 }
diff --git a/plugins/reg_linear/gog-log-reg.c b/plugins/reg_linear/gog-log-reg.c
index 610340d..fe1832a 100644
--- a/plugins/reg_linear/gog-log-reg.c
+++ b/plugins/reg_linear/gog-log-reg.c
@@ -41,7 +41,7 @@ gog_log_reg_curve_build_values (GogLinRegCurve *rc, double const *x_vals, double
 	g_free (rc->y_vals);
 	rc->y_vals = g_new (double, n);
 	for (i = 0, used = 0; i < n; i++) {
-		x = (x_vals)? x_vals[i]: i;
+		x = (x_vals)? x_vals[i]: i + 1;
 		y = y_vals[i];
 		if (x <= 0. || !go_finite (x) || !go_finite (y)) {
 			if (rc->base.skip_invalid)
diff --git a/plugins/reg_linear/gog-polynom-reg.c b/plugins/reg_linear/gog-polynom-reg.c
index 615d8fd..896f67e 100644
--- a/plugins/reg_linear/gog-polynom-reg.c
+++ b/plugins/reg_linear/gog-polynom-reg.c
@@ -52,7 +52,7 @@ gog_polynom_reg_curve_build_values (GogLinRegCurve *rc, double const *x_vals,
 	g_free (rc->y_vals);
 	rc->y_vals = g_new (double, n);
 	for (i = 0, used = 0; i < n; i++) {
-		x = (x_vals)? x_vals[i]: i;
+		x = (x_vals)? x_vals[i]: i + 1;
 		y = y_vals[i];
 		if (!go_finite (x) || !go_finite (y)) {
 			if (rc->base.skip_invalid)
@@ -201,7 +201,11 @@ gog_polynom_reg_curve_populate_editor (GogRegCurve *reg_curve, gpointer table)
 	gtk_misc_set_alignment (GTK_MISC (l), 0., 0.5);
 	gtk_label_set_justify (GTK_LABEL (l), GTK_JUSTIFY_LEFT);
 	gtk_widget_show (l);
+#if GTK_CHECK_VERSION(3,2,0)
 	gtk_grid_attach_next_to (table, l, NULL, GTK_POS_BOTTOM, 1, 1);
+#else
+	gtk_grid_attach_next_to (table, l, GTK_WIDGET (g_object_get_data (table, "last-label")), GTK_POS_BOTTOM, 1, 1);
+#endif
 	w = gtk_spin_button_new_with_range (2, 10, 1);
 	gtk_spin_button_set_digits (GTK_SPIN_BUTTON (w), 0);
 	gtk_widget_show (w);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]