goffice r2281 - in trunk: . goffice/graph plugins/plot_barcol plugins/plot_xy



Author: jbrefort
Date: Sat Nov 29 08:51:52 2008
New Revision: 2281
URL: http://svn.gnome.org/viewvc/goffice?rev=2281&view=rev

Log:
2008-11-29  Jean Brefort  <jean brefort normalesup org>

	* goffice/graph/goffice-graph.h: make GogAxisBase public, at least a bit.
	* goffice/graph/gog-axis-line-impl.h: ditto.
	* goffice/graph/gog-axis-line.c: ditto.
	* goffice/graph/gog-axis-line.h: ditto.
	* plugins/plot_barcol/gog-line.c: make drop lines go to the axis instead
	of bottom (or left when horizontal).
	* plugins/plot_xy/gog-xy.c: ditto.



Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/goffice/graph/goffice-graph.h
   trunk/goffice/graph/gog-axis-line-impl.h
   trunk/goffice/graph/gog-axis-line.c
   trunk/goffice/graph/gog-axis-line.h
   trunk/plugins/plot_barcol/gog-line.c
   trunk/plugins/plot_xy/gog-xy.c

Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS	(original)
+++ trunk/NEWS	Sat Nov 29 08:51:52 2008
@@ -11,6 +11,7 @@
 	* Drop the libgome dependency. [#558709]
 	* Made spline interpolation really use Bezier cubic splines.
 	* Add closed Bezier and cubic spline interpolation.
+	* Make drop lines go to the axis instead of chart bottom (or left).
 
 Morten:
 	* Plug leaks.

Modified: trunk/goffice/graph/goffice-graph.h
==============================================================================
--- trunk/goffice/graph/goffice-graph.h	(original)
+++ trunk/goffice/graph/goffice-graph.h	Sat Nov 29 08:51:52 2008
@@ -45,6 +45,7 @@
 typedef struct _GogLegend	GogLegend;
 typedef struct _GogLabel	GogLabel;
 typedef struct _GogStyledObject	GogStyledObject;
+typedef struct _GogAxisBase GogAxisBase;
 typedef struct _GogAxis		GogAxis;
 typedef struct _GogAxisLine	GogAxisLine;
 typedef struct _GogGrid		GogGrid;

Modified: trunk/goffice/graph/gog-axis-line-impl.h
==============================================================================
--- trunk/goffice/graph/gog-axis-line-impl.h	(original)
+++ trunk/goffice/graph/gog-axis-line-impl.h	Sat Nov 29 08:51:52 2008
@@ -35,7 +35,7 @@
 		int size_pts;
 } GogAxisTickProperties;
 
-typedef struct {
+struct _GogAxisBase {
 	GogStyledObject	 base;
 
 	GogChart	*chart;
@@ -49,16 +49,10 @@
 
 	GogAxisTickProperties major, minor;
 	gboolean major_tick_labeled;
-} GogAxisBase;
+};
 
 typedef GogStyledObjectClass GogAxisBaseClass;
 
-#define GOG_AXIS_BASE_TYPE	(gog_axis_base_get_type ())
-#define GOG_AXIS_BASE(o)	(G_TYPE_CHECK_INSTANCE_CAST ((o), GOG_AXIS_BASE_TYPE, GogAxisBase))
-#define IS_GOG_AXIS_BASE(o)	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GOG_AXIS_BASE_TYPE))
-
-GType gog_axis_base_get_type (void);
-
 GogAxisPosition 	gog_axis_base_get_position 	   (GogAxisBase *axis_base);
 void		    	gog_axis_base_set_position 	   (GogAxisBase *axis_base, GogAxisPosition position);
 GogAxisPosition 	gog_axis_base_get_clamped_position (GogAxisBase *axis_base);

Modified: trunk/goffice/graph/gog-axis-line.c
==============================================================================
--- trunk/goffice/graph/gog-axis-line.c	(original)
+++ trunk/goffice/graph/gog-axis-line.c	Sat Nov 29 08:51:52 2008
@@ -49,8 +49,6 @@
 #include <glib/gi18n-lib.h>
 #include <string.h>
 
-static double gog_axis_base_get_cross_location (GogAxisBase *axis_base);
-
 static GogViewClass *gab_view_parent_klass;
 static GObjectClass *gab_parent_klass;
 
@@ -294,7 +292,7 @@
 	return crossed_type;
 }
 
-static GogAxis *
+GogAxis *
 gog_axis_base_get_crossed_axis (GogAxisBase *axis_base)
 {
 	GogAxis *crossed_axis = NULL;
@@ -772,7 +770,7 @@
 	gab->minor.size_pts = 2;
 }
 
-static double
+double
 gog_axis_base_get_cross_location (GogAxisBase *axis_base)
 {
 	GOData *data;

Modified: trunk/goffice/graph/gog-axis-line.h
==============================================================================
--- trunk/goffice/graph/gog-axis-line.h	(original)
+++ trunk/goffice/graph/gog-axis-line.h	Sat Nov 29 08:51:52 2008
@@ -22,10 +22,20 @@
 #ifndef GOG_AXIS_BASE_H
 #define GOG_AXIS_BASE_H
 
+#include <goffice/graph/goffice-graph.h>
 #include <glib-object.h>
 
 G_BEGIN_DECLS
 
+#define GOG_AXIS_BASE_TYPE	(gog_axis_base_get_type ())
+#define GOG_AXIS_BASE(o)	(G_TYPE_CHECK_INSTANCE_CAST ((o), GOG_AXIS_BASE_TYPE, GogAxisBase))
+#define IS_GOG_AXIS_BASE(o)	(G_TYPE_CHECK_INSTANCE_TYPE ((o), GOG_AXIS_BASE_TYPE))
+
+GType gog_axis_base_get_type (void);
+
+GogAxis *gog_axis_base_get_crossed_axis (GogAxisBase *axis_base);
+double gog_axis_base_get_cross_location (GogAxisBase *axis_base);
+
 typedef enum {
 	GOG_AXIS_AT_LOW,
 	GOG_AXIS_CROSS,
@@ -33,6 +43,8 @@
 	GOG_AXIS_AUTO
 } GogAxisPosition;
 
+GogAxisPosition gog_axis_base_get_clamped_position (GogAxisBase *axis_base);
+
 typedef enum {
 	GOG_AXIS_TICK_NONE,
 	GOG_AXIS_TICK_MAJOR,

Modified: trunk/plugins/plot_barcol/gog-line.c
==============================================================================
--- trunk/plugins/plot_barcol/gog-line.c	(original)
+++ trunk/plugins/plot_barcol/gog-line.c	Sat Nov 29 08:51:52 2008
@@ -427,7 +427,7 @@
 	GogObjectRole const *role = NULL;
 	GogSeriesLines **lines;
 
-	double y_zero, drop_lines_y_zero;
+	double y_zero, y_top, drop_lines_y_min, drop_lines_y_max;
 	double abs_sum, sum, value, x, y = 0.;
 	gboolean is_null, is_area_plot;
 
@@ -457,9 +457,13 @@
 	/* Draw drop lines from point to axis start. See comment in
 	 * GogXYPlotView::render */
 
-	gog_axis_map_get_extents (y_map, &drop_lines_y_zero, NULL); 
-	drop_lines_y_zero = gog_axis_map_to_view (y_map, drop_lines_y_zero);
-	y_zero = gog_axis_map_get_baseline (y_map); 
+	gog_axis_map_get_extents (y_map, &drop_lines_y_min, &drop_lines_y_max); 
+	drop_lines_y_min = gog_axis_map_to_view (y_map, drop_lines_y_min);
+	drop_lines_y_max = gog_axis_map_to_view (y_map, drop_lines_y_max);
+	gog_axis_map_get_extents (y_map, &y_zero, &y_top);
+	y_zero = gog_axis_map_to_view (y_map, y_zero);
+	y_top = gog_axis_map_to_view (y_map, y_top);
+//	y_zero = gog_axis_map_get_baseline (y_map); 
 
 	vals    = g_alloca (num_series * sizeof (double *));
 	error_data = g_alloca (num_series * sizeof (ErrorBarData *));
@@ -599,8 +603,34 @@
 				points[i][j].y = y;
 			}
 			if (lines[i]) {
+				double y_target;
+				GogAxis *axis = GOG_PLOT (model)->axis[GOG_AXIS_X];
+				GogAxisPosition pos = gog_axis_base_get_clamped_position (GOG_AXIS_BASE (axis));
+				switch (pos) {
+				case GOG_AXIS_AT_LOW:
+					y_target = gog_axis_map_is_inverted (y_map)? y_top: y_zero;
+					break;
+				case GOG_AXIS_CROSS: {
+					GogChartMap *c_map;
+					GogAxisMap *a_map;
+					c_map = gog_chart_map_new (chart, area, axis,
+							gog_axis_base_get_crossed_axis (GOG_AXIS_BASE (axis)),
+							NULL, FALSE);
+					a_map = gog_chart_map_get_axis_map (c_map, 1);
+					y_target = gog_axis_map_to_view (a_map, gog_axis_base_get_cross_location (GOG_AXIS_BASE (axis)));
+					gog_chart_map_free (c_map);
+					break;
+				}
+				case GOG_AXIS_AT_HIGH:
+					y_target = gog_axis_map_is_inverted (y_map)? y_zero: y_top;
+					break;
+				default:
+					/* this should not occur */
+					y_target = gog_axis_map_to_view (y_map, 0);
+					break;
+				}
 				go_path_move_to (drop_paths[i], x, y);
-				go_path_line_to (drop_paths[i], x, drop_lines_y_zero);
+				go_path_line_to (drop_paths[i], x, y_target);
 			}
 
 		}

Modified: trunk/plugins/plot_xy/gog-xy.c
==============================================================================
--- trunk/plugins/plot_xy/gog-xy.c	(original)
+++ trunk/plugins/plot_xy/gog-xy.c	Sat Nov 29 08:51:52 2008
@@ -909,12 +909,10 @@
 		hide_outliers = GOG_XY_COLOR_PLOT (model)->hide_outliers;
 	}
 
-	/* Draw drop lines from point to axis start. To change this behaviour
-	 * and draw drop lines from point to zero, we can use gog_axis_map_get_baseline:
-	 * x_bottom = gog_axis_map_get_baseline (x_map); 
-	 * What we really want is to draw drop lines from point to
+	/* What we really want is to draw drop lines from point to
 	 * a selected axis. But for this purpose, we need a GogAxisBase selector in
-	 * GogSeriesLine, which doesn't really know what it's supposed to do with it. */
+	 * GogSeriesLines (we might actually need GogDropLines. For now just let
+	 * the drop lines go the the axis. */
 
 	gog_axis_map_get_extents (x_map, &x_left, &x_right);
 	x_left = gog_axis_map_to_view (x_map, x_left);
@@ -1007,8 +1005,32 @@
 
 		if (series->hdroplines) {
 			GOPath *drop_path;
-			double y_drop;
-
+			double y_drop, x_target;
+			GogAxis *axis = GOG_PLOT (model)->axis[GOG_AXIS_Y];
+			GogAxisPosition pos = gog_axis_base_get_clamped_position (GOG_AXIS_BASE (axis));
+			switch (pos) {
+			case GOG_AXIS_AT_LOW:
+				x_target = gog_axis_map_is_inverted (x_map)? x_right: x_left;
+				break;
+			case GOG_AXIS_CROSS: {
+				GogChartMap *c_map;
+				GogAxisMap *a_map;
+				c_map = gog_chart_map_new (chart, area, axis,
+						gog_axis_base_get_crossed_axis (GOG_AXIS_BASE (axis)),
+						NULL, FALSE);
+				a_map = gog_chart_map_get_axis_map (c_map, 1);
+				x_target = gog_axis_map_to_view (a_map, gog_axis_base_get_cross_location (GOG_AXIS_BASE (axis)));
+				gog_chart_map_free (c_map);
+				break;
+			}
+			case GOG_AXIS_AT_HIGH:
+				x_target = gog_axis_map_is_inverted (x_map)? x_left: x_right;
+				break;
+			default:
+				/* this should not occur */
+				x_target = gog_axis_map_to_view (x_map, 0);
+				break;
+			}
 			gog_renderer_push_style (view->renderer,
 				gog_styled_object_get_style (GOG_STYLED_OBJECT (series->hdroplines)));
 			drop_path = go_path_new ();
@@ -1020,7 +1042,7 @@
 				if (!gog_axis_map_finite (x_map, x))
 					continue;
 				y_drop = gog_axis_map_to_view (y_map, y_vals[i]);
-				go_path_move_to (drop_path, x_left, y_drop);
+				go_path_move_to (drop_path, x_target, y_drop);
 				go_path_line_to (drop_path, gog_axis_map_to_view (x_map, x), y_drop);
 			}
 			gog_renderer_stroke_serie (view->renderer, drop_path);
@@ -1030,8 +1052,32 @@
 
 		if (series->vdroplines) {
 			GOPath *drop_path;
-			double x_drop;
-
+			double x_drop, y_target;
+			GogAxis *axis = GOG_PLOT (model)->axis[GOG_AXIS_X];
+			GogAxisPosition pos = gog_axis_base_get_clamped_position (GOG_AXIS_BASE (axis));
+			switch (pos) {
+			case GOG_AXIS_AT_LOW:
+				y_target = gog_axis_map_is_inverted (y_map)? y_top: y_bottom;
+				break;
+			case GOG_AXIS_CROSS: {
+				GogChartMap *c_map;
+				GogAxisMap *a_map;
+				c_map = gog_chart_map_new (chart, area, axis,
+						gog_axis_base_get_crossed_axis (GOG_AXIS_BASE (axis)),
+						NULL, FALSE);
+				a_map = gog_chart_map_get_axis_map (c_map, 1);
+				y_target = gog_axis_map_to_view (a_map, gog_axis_base_get_cross_location (GOG_AXIS_BASE (axis)));
+				gog_chart_map_free (c_map);
+				break;
+			}
+			case GOG_AXIS_AT_HIGH:
+				y_target = gog_axis_map_is_inverted (y_map)? y_bottom: y_top;
+				break;
+			default:
+				/* this should not occur */
+				y_target = gog_axis_map_to_view (y_map, 0);
+				break;
+			}
 			gog_renderer_push_style (view->renderer,
 				gog_styled_object_get_style (GOG_STYLED_OBJECT (series->vdroplines)));
 			drop_path = go_path_new ();
@@ -1043,7 +1089,7 @@
 				if (!gog_axis_map_finite (x_map, x))
 					continue;
 				x_drop = gog_axis_map_to_view (x_map, x);
-				go_path_move_to (drop_path, x_drop, y_bottom);
+				go_path_move_to (drop_path, x_drop, y_target);
 				go_path_line_to (drop_path, x_drop, gog_axis_map_to_view (y_map, y_vals[i]));
 			}
 			gog_renderer_stroke_serie (view->renderer, drop_path);



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