[gnumeric] Fix bar and column chart import/export to ODF.



commit 19bbdb2fb4c298ddacd4865b5d9e73e2fefc29c0
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Fri Jul 15 14:28:01 2011 -0600

    Fix bar and column chart import/export to ODF.
    
    2011-07-15  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_style_have_three_dimensional): replace
    	with oo_style_has_property
    	(oo_style_have_multi_series): ditto
    	(oo_style_has_property): new
    	(oo_style_has_plot_property): new
    	(oo_chart_axis): bar charts have differnt axes interpretaion than
    	column charts
    	* openoffice-write.c (odf_write_*_axes_styles): add arguments and
    	change all callers
    	(odf_write_axis_full): new
    	(odf_write_axis): use odf_write_axis_full
    	(odf_write_axis_no_cats): use odf_write_axis_full
    	(odf_write_plot): we need to distinguish column charts from bar charts

 NEWS                                  |    3 +-
 plugins/openoffice/ChangeLog          |   16 +++++
 plugins/openoffice/openoffice-read.c  |   57 +++++++++++-----
 plugins/openoffice/openoffice-write.c |  121 ++++++++++++++++++++++++++-------
 4 files changed, 153 insertions(+), 44 deletions(-)
---
diff --git a/NEWS b/NEWS
index 99f9194..16572ab 100644
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,8 @@ Andreas:
 	* Allow document properties to be edited and added.
 	* Add an interface for conditional styles.
 	* Fix ODF import of styles with inherited conditional styles. [#654214] 
-	* Provide undo for cut between 2 gnumeric processes. [#640922] 
+	* Provide undo for cut between 2 gnumeric processes. [#640922]
+	* Fix bar and column chart import/export to ODF.
 
 Morten:
 	* Fix --with-gnome compilation:  [#652802]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 108908a..3731435 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,19 @@
+2011-07-15  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (oo_style_have_three_dimensional): replace
+	with oo_style_has_property
+	(oo_style_have_multi_series): ditto
+	(oo_style_has_property): new
+	(oo_style_has_plot_property): new
+	(oo_chart_axis): bar charts have differnt axes interpretaion than
+	column charts
+	* openoffice-write.c (odf_write_*_axes_styles): add arguments and
+	change all callers
+	(odf_write_axis_full): new
+	(odf_write_axis): use odf_write_axis_full
+	(odf_write_axis_no_cats): use odf_write_axis_full
+	(odf_write_plot): we need to distinguish column charts from bar charts
+
 2011-07-14  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-write.c (odf_write_axis): do not confuse MS Excel by
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 5d1b949..0e38067 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -5536,29 +5536,27 @@ oo_prop_list_has (GSList *props, gboolean *threed, char const *tag)
 }
 
 static gboolean
-oo_style_have_three_dimensional (OOChartStyle **style)
+oo_style_has_property (OOChartStyle **style, char const *prop, gboolean def)
 {
 	int i;
-	gboolean is_three_dimensional = FALSE;
+	gboolean has_prop = def;
 	for (i = 0; i < OO_CHART_STYLE_INHERITANCE; i++)
 		if (style[i] != NULL)
 			oo_prop_list_has (style[i]->other_props,
-					  &is_three_dimensional,
-					  "three-dimensional");
-	return is_three_dimensional;
+					  &has_prop, prop);
+	return has_prop;
 }
 
 static gboolean
-oo_style_have_multi_series (OOChartStyle **style)
+oo_style_has_plot_property (OOChartStyle **style, char const *prop, gboolean def)
 {
 	int i;
-	gboolean is_multi_series = FALSE;
+	gboolean has_prop = def;
 	for (i = 0; i < OO_CHART_STYLE_INHERITANCE; i++)
 		if (style[i] != NULL)
-			oo_prop_list_has (style[i]->other_props,
-					  &is_multi_series,
-					  "multi-series");
-	return is_multi_series;
+			oo_prop_list_has (style[i]->plot_props,
+					  &has_prop, prop);
+	return has_prop;
 }
 
 static void
@@ -6805,6 +6803,12 @@ oo_chart_axis (GsfXMLIn *xin, xmlChar const **attrs)
 		{ "z",	GOG_AXIS_Z },
 		{ NULL,	0 },
 	};
+	static OOEnum const types_bar[] = {
+		{ "x",	GOG_AXIS_Y },
+		{ "y",	GOG_AXIS_X },
+		{ "z",	GOG_AXIS_Z },
+		{ NULL,	0 },
+	};
 	static OOEnum const types_radar[] = {
 		{ "x",	GOG_AXIS_CIRCULAR },
 		{ "y",	GOG_AXIS_RADIAL },
@@ -6817,15 +6821,30 @@ oo_chart_axis (GsfXMLIn *xin, xmlChar const **attrs)
 	gchar const *style_name = NULL;
 	GogAxisType  axis_type;
 	int tmp;
+	OOEnum const *axes_types;
+
+	switch (state->chart.plot_type) {
+	case OO_PLOT_RADAR:
+	case OO_PLOT_RADARAREA:
+	case OO_PLOT_POLAR:
+		axes_types = types_radar;
+		break;
+	case OO_PLOT_BAR:
+		if (oo_style_has_plot_property (state->chart.i_plot_styles, "horizontal", FALSE))
+			axes_types = types_bar;
+		else
+			axes_types = types;
+		break;
+	default:
+		axes_types = types;
+		break;
+	}
 
 	axis_type = GOG_AXIS_UNKNOWN;
 	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
 		if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_CHART, "style-name"))
 			style_name = CXML2C (attrs[1]);
-		else if (oo_attr_enum (xin, attrs, OO_NS_CHART, "dimension",
-				       (state->chart.plot_type == OO_PLOT_RADAR ||
-					state->chart.plot_type == OO_PLOT_RADARAREA ||
-					state->chart.plot_type == OO_PLOT_POLAR)? types_radar :  types, &tmp))
+		else if (oo_attr_enum (xin, attrs, OO_NS_CHART, "dimension", axes_types, &tmp))
 			axis_type = tmp;
 
 	axes = gog_chart_get_axes (state->chart.chart, axis_type);
@@ -7112,10 +7131,11 @@ oo_plot_area (GsfXMLIn *xin, xmlChar const **attrs)
 	case OO_PLOT_SCATTER:	type = "GogXYPlot";	break;
 	case OO_PLOT_STOCK:	type = "GogMinMaxPlot";	break;  /* This is not quite right! */
 	case OO_PLOT_CONTOUR:
-		if (oo_style_have_multi_series (state->chart.i_plot_styles)) {
+		if (oo_style_has_property (state->chart.i_plot_styles, "multi-series", FALSE)) {
 			type = "XLSurfacePlot";
 			state->chart.plot_type = OO_PLOT_XL_SURFACE;
-		} else if (oo_style_have_three_dimensional (state->chart.i_plot_styles)) {
+		} else if (oo_style_has_property (state->chart.i_plot_styles, 
+						   "three-dimensional", FALSE)) {
 			type = "GogSurfacePlot";
 			state->chart.plot_type = OO_PLOT_SURFACE;
 		} else
@@ -7125,7 +7145,8 @@ oo_plot_area (GsfXMLIn *xin, xmlChar const **attrs)
 	case OO_PLOT_GANTT:	type = "GogDropBarPlot"; break;
 	case OO_PLOT_POLAR:	type = "GogPolarPlot"; break;
 	case OO_PLOT_XYZ_SURFACE:
-		if (oo_style_have_three_dimensional (state->chart.i_plot_styles))
+		if (oo_style_has_property (state->chart.i_plot_styles, 
+						   "three-dimensional", FALSE))
 			type = "GogXYZSurfacePlot";
 		else
 			type = "GogXYZContourPlot";
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 4f03a2c..13b5bf9 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -6145,10 +6145,13 @@ odf_write_generic_axis_style (GnmOOExport *state, char const *style_label)
 
 static void
 odf_write_circle_axes_styles (GnmOOExport *state, GogObject const *chart,
-			     G_GNUC_UNUSED GogObject const *plot,
-			       gchar **x_style,
-			       gchar **y_style,
-			       gchar **z_style)
+			      G_GNUC_UNUSED GogObject const *plot,
+			      gchar **x_style,
+			      gchar **y_style,
+			      gchar **z_style,
+			      gchar const *x_role,
+			      gchar const *y_role,
+			      gchar const *z_role)
 {
 	odf_write_generic_axis_style (state, "yaxis");
 	*x_style = g_strdup ("yaxis");
@@ -6160,9 +6163,12 @@ odf_write_circle_axes_styles (GnmOOExport *state, GogObject const *chart,
 static void
 odf_write_radar_axes_styles (GnmOOExport *state, GogObject const *chart,
 			     G_GNUC_UNUSED GogObject const *plot,
-			       gchar **x_style,
-			       gchar **y_style,
-			       gchar **z_style)
+			     gchar **x_style,
+			     gchar **y_style,
+			     gchar **z_style,
+			     gchar const *x_role,
+			     gchar const *y_role,
+			     gchar const *z_role)
 {
 	GogObject const *axis;
 
@@ -6180,15 +6186,18 @@ odf_write_standard_axes_styles (GnmOOExport *state, GogObject const *chart,
 				GogObject const *plot,
 				gchar **x_style,
 				gchar **y_style,
-				gchar **z_style)
+				gchar **z_style,
+				gchar const *x_role,
+				gchar const *y_role,
+				gchar const *z_role)
 {
 	GogObject const *axis;
 
-	axis = gog_object_get_child_by_name (chart, "X-Axis");
+	axis = gog_object_get_child_by_name (chart, x_role);
 	if (axis != NULL)
 		*x_style = odf_get_gog_style_name_from_obj (axis);
 
-	axis = gog_object_get_child_by_name (chart, "Y-Axis");
+	axis = gog_object_get_child_by_name (chart, y_role);
 	if (axis != NULL)
 		*y_style = odf_get_gog_style_name_from_obj (axis);
 }
@@ -6198,13 +6207,17 @@ odf_write_surface_axes_styles (GnmOOExport *state, GogObject const *chart,
 			       GogObject const *plot,
 				gchar **x_style,
 				gchar **y_style,
-				gchar **z_style)
+				gchar **z_style,
+				gchar const *x_role,
+				gchar const *y_role,
+				gchar const *z_role)
 {
 	GogObject const *axis;
 
-	odf_write_standard_axes_styles (state, chart, plot, x_style, y_style, z_style);
+	odf_write_standard_axes_styles (state, chart, plot, x_style, y_style, z_style,
+					x_role, y_role, z_role);
 
-	axis = gog_object_get_child_by_name (chart, "Z-Axis");
+	axis = gog_object_get_child_by_name (chart, z_role);
 	if (axis != NULL)
 		*z_style = odf_get_gog_style_name_from_obj (axis);
 }
@@ -6690,9 +6703,14 @@ odf_write_axis_categories (GnmOOExport *state, GSList const *series)
 }
 
 static void
-odf_write_axis (GnmOOExport *state, GogObject const *chart, char const *axis_role,
-		char const *style_label,
-		char const *dimension, odf_chart_type_t gtype, GSList const *series)
+odf_write_axis_full (GnmOOExport *state, 
+		     GogObject const *chart, 
+		     char const *axis_role,
+		     char const *style_label,
+		     char const *dimension, 
+		     G_GNUC_UNUSED odf_chart_type_t gtype, 
+		     GSList const *series,
+		     gboolean include_cats)
 {
 	GogObject const *axis;
 
@@ -6706,17 +6724,46 @@ odf_write_axis (GnmOOExport *state, GogObject const *chart, char const *axis_rol
 		gsf_xml_out_add_cstr (state->xml, CHART "style-name", style_label);
 		odf_write_label (state, axis);
 		odf_write_axis_grid (state, axis);
-		if (ODF_BUBBLE != gtype)
+		if (include_cats)
 			odf_write_axis_categories (state, series);
 		gsf_xml_out_end_element (state->xml); /* </chart:axis> */
 	}
+	
+}
+
+static void
+odf_write_axis (GnmOOExport *state, 
+		GogObject const *chart, 
+		char const *axis_role,
+		char const *style_label,
+		char const *dimension, 
+		odf_chart_type_t gtype, 
+		GSList const *series)
+{
+	odf_write_axis_full (state, chart, axis_role, style_label, 
+			     dimension, gtype, series, TRUE);
 }
 
 static void
-odf_write_generic_axis (GnmOOExport *state, GogObject const *chart,
-			char const *axis_role,
+odf_write_axis_no_cats (GnmOOExport *state, 
+		GogObject const *chart, 
+		char const *axis_role,
+		char const *style_label,
+		char const *dimension, 
+		odf_chart_type_t gtype, 
+		GSList const *series)
+{
+	odf_write_axis_full (state, chart, axis_role, style_label, 
+			     dimension, gtype, series, FALSE);
+}
+
+static void
+odf_write_generic_axis (GnmOOExport *state, 
+			G_GNUC_UNUSED GogObject const *chart,
+			G_GNUC_UNUSED char const *axis_role,
 			char const *style_label,
-			char const *dimension, odf_chart_type_t gtype,
+			char const *dimension, 
+			G_GNUC_UNUSED odf_chart_type_t gtype,
 			GSList const *series)
 {
 	gsf_xml_out_start_element (state->xml, CHART "axis");
@@ -6754,7 +6801,10 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 						GogObject const *plot,
 						gchar **x_style,
 						gchar **y_style,
-						gchar **z_style);
+						gchar **z_style,
+						gchar const *x_role,
+						gchar const *y_role,
+						gchar const *z_role);
 		void (*odf_write_series)       (GnmOOExport *state,
 						GSList const *series);
 		void (*odf_write_x_axis) (GnmOOExport *state,
@@ -6779,10 +6829,14 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 					  odf_chart_type_t gtype,
 					  GSList const *series);
 	} *this_plot, plots[] = {
-		{ "GogBarColPlot", CHART "bar", ODF_BARCOL,
+		{ "GogColPlot", CHART "bar", ODF_BARCOL,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  odf_write_standard_series,
-		  odf_write_axis, odf_write_axis, odf_write_axis},
+		  odf_write_axis, odf_write_axis_no_cats, odf_write_axis},
+		{ "GogBarPlot", CHART "bar", ODF_BARCOL,
+		  20., "Y-Axis", "X-Axis", NULL, odf_write_standard_axes_styles,
+		  odf_write_standard_series,
+		  odf_write_axis, odf_write_axis_no_cats, odf_write_axis},
 		{ "GogLinePlot", CHART "line", ODF_LINE,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  odf_write_standard_series,
@@ -6844,7 +6898,7 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 		{ "GogBubblePlot", CHART "bubble", ODF_BUBBLE,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  odf_write_bubble_series,
-		  odf_write_axis, odf_write_axis, odf_write_axis},
+		  odf_write_axis_no_cats, odf_write_axis_no_cats, odf_write_axis_no_cats},
 		{ "GogXYColorPlot", GNMSTYLE "scatter-color", ODF_SCATTER_COLOUR,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  odf_write_bubble_series,
@@ -6863,6 +6917,21 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 		  odf_write_axis, odf_write_axis, odf_write_axis}
 	};
 
+	if (0 == strcmp ("GogBarColPlot", plot_type)) {
+		GParamSpec *spec;
+		GObjectClass *klass = G_OBJECT_GET_CLASS (plot);
+
+		plot_type = "GogColPlot";
+		if (NULL != (spec = g_object_class_find_property (klass, "horizontal"))
+		    && spec->value_type == G_TYPE_BOOLEAN
+		    && (G_PARAM_READABLE & spec->flags)) {
+			gboolean b;
+			g_object_get (G_OBJECT (plot), "horizontal", &b, NULL);
+			if (b)
+				plot_type = "GogBarPlot";	
+		}
+	}
+
 	for (this_plot = &plots[0]; this_plot->type != NULL; this_plot++)
 		if (0 == strcmp (plot_type, this_plot->type))
 			break;
@@ -6878,7 +6947,9 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 
 	if (this_plot->odf_write_axes_styles != NULL)
 		this_plot->odf_write_axes_styles (state, chart, plot,
-						  &x_style, &y_style, &z_style);
+						  &x_style, &y_style, &z_style,
+						  this_plot->x_axis_name, this_plot->y_axis_name, 
+						  this_plot->z_axis_name);
 
 	odf_start_style (state->xml, "plotstyle", "chart");
 	gsf_xml_out_start_element (state->xml, STYLE "chart-properties");



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