[gnumeric] ODF: individual pie points



commit 0042aa894629a94865abd9a60033baca059a67d3
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sat Aug 28 20:02:45 2010 -0600

    ODF: individual pie points
    
    2010-08-28  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (oo_cell_start): no need to duplicate the style name
    	(od_style_prop_chart): new atribute
    	(oo_plot_series): zero the data point count
    	(oo_series_pt): implement
    	* openoffice-write.c (cmp_data_points): new
    	(odf_write_standard_series): write data points
    	(odf_write_pie_point): new
    	(odf_fill_chart_props_hash): connect odf_write_pie_point

 plugins/openoffice/ChangeLog          |   13 +++++-
 plugins/openoffice/openoffice-read.c  |   47 ++++++++++++++---
 plugins/openoffice/openoffice-write.c |   87 +++++++++++++++++++++++++++++----
 3 files changed, 127 insertions(+), 20 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index fe2d021..2e754ad 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,4 +1,15 @@
-2010-08-29  Andreas J. Guelzow <aguelzow pyrshep ca>
+2010-08-28  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (oo_cell_start): no need to duplicate the style name
+	(od_style_prop_chart): new atribute
+	(oo_plot_series): zero the data point count
+	(oo_series_pt): implement
+	* openoffice-write.c (cmp_data_points): new
+	(odf_write_standard_series): write data points
+	(odf_write_pie_point): new
+	(odf_fill_chart_props_hash): connect odf_write_pie_point
+
+2010-08-28  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-write.c (odf_write_plot): write marker info for
 	  polar plots 
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index f9c6897..06dbd7b 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -1384,7 +1384,7 @@ oo_cell_start (GsfXMLIn *xin, xmlChar const **attrs)
 	int array_cols = -1, array_rows = -1;
 	int merge_cols = 1, merge_rows = 1;
 	GnmStyle *style = NULL;
-	char *style_name = NULL;
+	char const *style_name = NULL;
 	char const *expr_string;
 	GnmRange tmp;
 	int max_cols = gnm_sheet_get_max_cols (state->pos.sheet);
@@ -1490,8 +1490,7 @@ oo_cell_start (GsfXMLIn *xin, xmlChar const **attrs)
 		else if (oo_attr_int_range (xin, attrs, OO_NS_TABLE, "number-rows-spanned", &merge_rows, 0, INT_MAX))
 			;
 		else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_TABLE, "style-name")) {
-			g_free (style_name);
-			style_name = g_strdup (attrs[1]);
+			style_name = attrs[1];
 		}
 	}
 
@@ -1500,7 +1499,6 @@ oo_cell_start (GsfXMLIn *xin, xmlChar const **attrs)
 		if (texpr)
 			gnm_expr_top_unref (texpr);
 		value_release (val);
-		g_free (style_name);
 		return;
 	}
 
@@ -1546,8 +1544,6 @@ oo_cell_start (GsfXMLIn *xin, xmlChar const **attrs)
 		}
 		if (style != NULL)
 			gnm_style_ref (style);
-
-		g_free (style_name);
 	}
 
 	if (style != NULL) {
@@ -3538,6 +3534,9 @@ od_style_prop_chart (GsfXMLIn *xin, xmlChar const **attrs)
 			style->plot_props = g_slist_prepend (style->plot_props,
 				oo_prop_new_float ("default-separation", 
 						   tmp/100.));
+			style->plot_props = g_slist_prepend (style->plot_props,
+				oo_prop_new_float ("separation", 
+						   tmp/100.));
 		} else if (oo_attr_percent (xin, attrs, OO_NS_CHART, 
 					    "hole-size", &ftmp)) {
 			style->plot_props = g_slist_prepend (style->plot_props,
@@ -4705,6 +4704,7 @@ oo_plot_series (GsfXMLIn *xin, xmlChar const **attrs)
 
 	state->chart.series_count++;
 	state->chart.domain_count = 0;
+	state->chart.data_pt_count = 0;
 
 
 	/* Create the series */
@@ -4839,10 +4839,39 @@ oo_series_domain (GsfXMLIn *xin, xmlChar const **attrs)
 static void
 oo_series_pt (GsfXMLIn *xin, xmlChar const **attrs)
 {
-#if 0
 	OOParseState *state = (OOParseState *)xin->user_state;
-	/* <chart:data-point chart:repeated="3"/> */
-#endif
+	char const *style_name = NULL;
+	guint repeat_count = 1;
+	OOChartStyle *style = NULL;
+
+	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
+		if (oo_attr_int_range (xin, attrs, OO_NS_CHART, "repeated", &repeat_count, 0, INT_MAX))
+			;
+		else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_NS_CHART, "style-name")) {
+			style_name = attrs[1];
+		}
+	if (repeat_count == 0)
+		return; /* Why does ODF allow repeat counts of 0 ??*/
+
+	if (style_name != NULL &&
+	    NULL != (style = g_hash_table_lookup (state->chart.graph_styles, style_name))) {
+		guint index = state->chart.data_pt_count;
+		state->chart.data_pt_count += repeat_count;
+		for (; index < state->chart.data_pt_count; index++) {
+			GogObject *element = gog_object_add_by_name (GOG_OBJECT (state->chart.series), "Point", NULL);
+			if (element != NULL) {
+				GOStyle *gostyle;
+				g_object_set (G_OBJECT (element), "index", index, NULL);
+				oo_prop_list_apply (style->plot_props, G_OBJECT (element));
+				g_object_get (G_OBJECT (element), "style", &gostyle, NULL);
+				if (gostyle != NULL) {
+					odf_apply_style_props (style->style_props, gostyle);
+					g_object_unref (gostyle);
+				}
+			}
+		}
+	} else
+		state->chart.data_pt_count += repeat_count;
 }
 
 static void
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 54b3800..77b03d2 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3715,6 +3715,20 @@ odf_write_data_attribute (GnmOOExport *state, GOData const *data, GnmParsePos *p
 	}
 }
 
+static gint
+cmp_data_points (GObject *a, GObject *b)
+{
+	int ind_a = 0, ind_b = 0;
+	
+	g_object_get (a, "index", &ind_a, NULL); 
+	g_object_get (b, "index", &ind_b, NULL);
+	
+	if (ind_a < ind_b)
+		return -1;
+	else if (ind_a > ind_b)
+		return 1;
+	else return 0;
+}
 
 static void
 odf_write_standard_series (GnmOOExport *state, GSList const *series)
@@ -3730,7 +3744,7 @@ odf_write_standard_series (GnmOOExport *state, GSList const *series)
 			GogObjectRole const *role = 
 				gog_object_find_role_by_name 
 				(GOG_OBJECT (series->data), "Regression curve");
-			
+			GSList *points;
 			GOData const *cat = gog_dataset_get_dim (GOG_DATASET (series->data), 
 								 GOG_MS_DIM_LABELS);
 			char *str = g_strdup_printf ("series%i", i);
@@ -3803,6 +3817,38 @@ odf_write_standard_series (GnmOOExport *state, GSList const *series)
 					g_free (str);
 				}
 			}
+
+			/* Write data points if any */
+
+			role = gog_object_find_role_by_name 
+				(GOG_OBJECT (series->data), "Point");
+			if (role != NULL && NULL != (points = gog_object_get_children 
+						     (GOG_OBJECT (series->data), role))) {
+				int index = 0, next_index = 0;
+				GSList *l;
+				points = g_slist_sort (points, (GCompareFunc) cmp_data_points);
+				
+				for (l = points; l != NULL; l = l->next) {
+					char *style = odf_get_gog_style_name_from_obj 
+						(GOG_OBJECT (l->data));
+					g_object_get (G_OBJECT (l->data), "index", &index, NULL);
+					if (index > next_index) {
+						gsf_xml_out_start_element (state->xml, 
+									   CHART "data-point");
+						gsf_xml_out_add_int (state->xml, CHART "repeated", 
+								     index - next_index);
+						gsf_xml_out_end_element (state->xml); 
+						/* CHART "data-point" */
+					}
+					gsf_xml_out_start_element (state->xml, 
+								   CHART "data-point");
+					gsf_xml_out_add_cstr (state->xml, CHART "style-name", style);
+					gsf_xml_out_end_element (state->xml); 
+					/* CHART "data-point" */
+					g_free (style);
+				}
+				g_slist_free (points);
+			}
 			
 			if (state->with_extension) {
 				odf_write_drop_line (state, GOG_OBJECT (series->data), 
@@ -5064,7 +5110,7 @@ odf_write_images (SheetObjectImage *image, char const *name, GnmOOExport *state)
 }
 
 static void
-odf_write_drop(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_drop (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	GogObjectRole const *h_role = gog_object_find_role_by_name 
 		(obj->parent, "Horizontal drop lines");
@@ -5074,7 +5120,7 @@ odf_write_drop(GnmOOExport *state, GOStyle const *style, GogObject const *obj)
 }
 
 static void
-odf_write_lin_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_lin_reg (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	gsf_xml_out_add_cstr (state->xml, CHART "regression-type",  "linear");
 	if (state->with_extension) {
@@ -5087,7 +5133,7 @@ odf_write_lin_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj
 }
 
 static void
-odf_write_polynom_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_polynom_reg (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	if (state->with_extension) {
 		GObjectClass *klass = G_OBJECT_GET_CLASS (G_OBJECT (obj));
@@ -5102,25 +5148,25 @@ odf_write_polynom_reg(GnmOOExport *state, GOStyle const *style, GogObject const
 }
 
 static void
-odf_write_exp_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_exp_reg (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	gsf_xml_out_add_cstr (state->xml, CHART "regression-type",  "exponential");
 }
 
 static void
-odf_write_power_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_power_reg (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	gsf_xml_out_add_cstr (state->xml, CHART "regression-type",  "power");
 }
 
 static void
-odf_write_log_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_log_reg (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	gsf_xml_out_add_cstr (state->xml, CHART "regression-type",  "logarithmic");
 }
 
 static void
-odf_write_log_fit_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_log_fit_reg (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	if (state->with_extension)
 		gsf_xml_out_add_cstr (state->xml, CHART "regression-type", 
@@ -5128,7 +5174,7 @@ odf_write_log_fit_reg(GnmOOExport *state, GOStyle const *style, GogObject const
 }
 
 static void
-odf_write_movig_avg_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_movig_avg_reg (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	if (state->with_extension)
 		gsf_xml_out_add_cstr (state->xml, CHART "regression-type", 
@@ -5136,7 +5182,7 @@ odf_write_movig_avg_reg(GnmOOExport *state, GOStyle const *style, GogObject cons
 }
 
 static void
-odf_write_exp_smooth_reg(GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+odf_write_exp_smooth_reg (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
 {
 	if (state->with_extension)
 		gsf_xml_out_add_cstr (state->xml, CHART "regression-type", 
@@ -5144,6 +5190,26 @@ odf_write_exp_smooth_reg(GnmOOExport *state, GOStyle const *style, GogObject con
 }
 
 static void
+odf_write_pie_point (GnmOOExport *state, GOStyle const *style, GogObject const *obj) 
+{
+	GObjectClass *klass = G_OBJECT_GET_CLASS (obj);
+	GParamSpec *spec;
+
+	if (NULL != (spec = g_object_class_find_property (klass, "separation"))   
+	    && spec->value_type == G_TYPE_DOUBLE
+	    && (G_PARAM_READABLE & spec->flags)) {
+		double separation = 0.;
+		g_object_get (G_OBJECT (obj), 
+			      "separation", &separation, 
+			      NULL);
+		gsf_xml_out_add_int (state->xml, 
+				     CHART "pie-offset", 
+				     (separation * 100. + 0.5));
+	}
+
+}
+
+static void
 odf_fill_chart_props_hash (GnmOOExport *state)
 {
 	int i;
@@ -5163,6 +5229,7 @@ odf_fill_chart_props_hash (GnmOOExport *state)
 		{"GogLogFitCurve", odf_write_log_fit_reg},
 		{"GogMovingAvg", odf_write_movig_avg_reg},
 		{"GogExpSmooth", odf_write_exp_smooth_reg},
+		{"GogPieSeriesElement", odf_write_pie_point},
 	};
 		
 	for (i = 0 ; i < (int)G_N_ELEMENTS (props) ; i++)



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