[goffice] Fix date axis problem.



commit 0164c78fd1d155275d3f553080a2fc9574aafde6
Author: Morten Welinder <terra gnome org>
Date:   Fri Apr 17 18:29:09 2009 -0400

    Fix date axis problem.
    
    * goffice/graph/gog-axis.c (map_date_auto_bound): Fix problem with
    upper bound when step is in years and maximum in not on January 1.
---
 ChangeLog                |    5 +++++
 goffice/graph/gog-axis.c |   18 +++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4f5534c..d1e03ef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-04-17  Morten Welinder  <terra gnome org>
+
+        * goffice/graph/gog-axis.c (map_date_auto_bound): Fix problem with
+        upper bound when step is in years and maximum in not on January 1.
+
 2009-04-17  Jean Brefort  <jean brefort normalesup org>
 
 	* plugins/plot_radar/Makefile.am: add the glade fil to EXTRA_DIST since
diff --git a/goffice/graph/gog-axis.c b/goffice/graph/gog-axis.c
index 5195804..b9526bc 100644
--- a/goffice/graph/gog-axis.c
+++ b/goffice/graph/gog-axis.c
@@ -565,7 +565,7 @@ map_date_auto_bound (GogAxis *axis, double minimum, double maximum, double *boun
 		step = 30;
 		minor_step = (range <= 180 ? 1 : step);
 	} else {
-		int N = 1, y;
+		int N = 1, y, maxy;
 
 		while (years > 20 * N) {
 			N *= 10;
@@ -577,12 +577,16 @@ map_date_auto_bound (GogAxis *axis, double minimum, double maximum, double *boun
 		if (g_date_valid_dmy (1, 1, y))
 			g_date_set_year (&min_date, y);
 
-		y = (g_date_get_year (&max_date) + N - 1) / N * N;
-		if (g_date_valid_dmy (1, 1, y)) {
-			g_date_set_day (&max_date, 1);
-			g_date_set_month (&max_date, 1);
-			g_date_set_year (&max_date, y);
-		}
+		maxy = g_date_get_year (&max_date);
+		y = (maxy + N - 1) / N * N;
+		/* Make sure we are not going backwards. */
+		if (y == maxy &&
+		    (g_date_get_day (&max_date) != 1 ||
+		     g_date_get_month (&max_date) != 1))
+			y += N;
+
+		if (g_date_valid_dmy (1, 1, y))
+			g_date_set_dmy (&max_date, 1, 1, y);
 
 		minimum = datetime_g_to_serial (&min_date, axis->date_conv);
 		maximum = datetime_g_to_serial (&max_date, axis->date_conv);



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