[gnumeric] ODF: regression equation import/export



commit 011ca2b47beea9066dce85cf0fbae65053e59723
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Aug 26 14:29:26 2010 -0600

    ODF: regression equation import/export
    
    2010-08-26  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (od_series_reg_equation): new
    	(od_series_regression): store regression line
    	(opendoc_content_dtd): connect od_series_reg_equation
    	* openoffice-write.c (odf_write_plot_style_*): moved
    	(odf_write_standard_series): write regression equation
    
    2010-08-26  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* developer/odf-foreign.txt: update

 doc/ChangeLog                         |    4 +
 doc/developer/odf-foreign.txt         |   38 ++++++-
 plugins/openoffice/ChangeLog          |   10 ++-
 plugins/openoffice/openoffice-read.c  |   63 ++++++++++-
 plugins/openoffice/openoffice-write.c |  216 +++++++++++++++++++--------------
 5 files changed, 237 insertions(+), 94 deletions(-)
---
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 2dfeae0..b295bf2 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2010-08-26  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* developer/odf-foreign.txt: update
+
 2010-08-20  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* developer/odf-foreign.txt: update
diff --git a/doc/developer/odf-foreign.txt b/doc/developer/odf-foreign.txt
index fea4f0f..feeee1c 100644
--- a/doc/developer/odf-foreign.txt
+++ b/doc/developer/odf-foreign.txt
@@ -46,12 +46,42 @@ gnm:default-separation
 This is an attribute for the plot-style chart:circle
 
 gnm:expression
-Attribute used where ODF restricts expressions to be cell references via table:cell-range-address fore xample chart titles.
+Attribute used where ODF restricts expressions to be cell references via table:cell-range-address for example chart titles.
 
 gnm:font-stretch-pango
 gnm:font-gravity-pango
 Attributes to chart:text-properties
 
+gnm:label-cell-expression
+used instead of chart:label-cell-address if that isn't just a range reference
+
+gnm:droplines
+element to add droplines to charts
+
+gnm:regression-curve
+element used instead of chart:regression-curve for any second or later regression curve in a plot
+
+gnm:multi-series
+flag to recognize an XLSurfacePlot export
+
+gnm:vary-style-by-element
+plot property
+
+gnm:show-negatives
+property of bubble plots
+
+gnm:reverse-direction
+gnm:automatic-content
+gnm:display-equation
+gnm:display-r-square
+used instead of the ODF1.2 attribute chart:...
+
+gnm:regression-affine
+whether a given regression is affine or not
+
+gnm:regression-polynomial-dims
+dimension for a polynomial regression
+
 3) Attribute _values_ added by Gnumeric. 
 Since these are not eleemnts or new attributes they are used in all ODF exports.
 
@@ -65,6 +95,12 @@ gnm:step-center-x
 gnm:step-center-y
 various attribute values specifying chart:interpolation types
 
+gnm:polynomial
+gnm:log-fit
+gnm:moving-average
+gnm:exponential-smoothed
+various attributes for chart:regression-type
+
 3a) Plot Styles added by Gnumeric (these are technically also attribute values)
 
 gnm:box
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index d2e3e4a..e0b0def 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,4 +1,12 @@
-2010-08-25  Andreas J. Guelzow <aguelzow pyrshep ca>
+2010-08-26  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (od_series_reg_equation): new
+	(od_series_regression): store regression line
+	(opendoc_content_dtd): connect od_series_reg_equation
+	* openoffice-write.c (odf_write_plot_style_*): moved
+	(odf_write_standard_series): write regression equation
+
+2010-08-26  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-read.c (od_style_prop_chart); new properties
 	(od_series_regression): new
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index dae3542..ea2643c 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -192,6 +192,7 @@ typedef struct {
 
 	GogObject	*axis;
 	xmlChar         *cat_expr;
+	GogObject	*regression;
 
 	GnmExprTop const        *title_expr;
 	gchar                   *title_style;
@@ -4776,11 +4777,65 @@ oo_series_pt (GsfXMLIn *xin, xmlChar const **attrs)
 }
 
 static void
+od_series_reg_equation (GsfXMLIn *xin, xmlChar const **attrs)
+{
+	OOParseState *state = (OOParseState *)xin->user_state;
+	char const *style_name = NULL;
+	GogObject *equation;
+	gboolean automatic_content = TRUE;
+	gboolean dispay_equation = TRUE;
+	gboolean display_r_square = TRUE;
+	
+
+	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_bool (xin, attrs, OO_NS_CHART, "automatic-content", 
+				       &automatic_content));
+		else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT, "automatic-content", 
+				       &automatic_content));
+		else if (oo_attr_bool (xin, attrs, OO_NS_CHART, "display-equation", 
+				       &dispay_equation));
+		else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT, "display-equation", 
+				       &dispay_equation));
+		else if (oo_attr_bool (xin, attrs, OO_NS_CHART, "display-r-square", 
+				       &display_r_square));
+		else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT, "display-r-square", 
+				       &display_r_square));
+	
+	equation = gog_object_add_by_name (GOG_OBJECT (state->chart.regression), 
+						     "Equation", NULL);
+
+	g_object_set (G_OBJECT (equation), 
+		      "show-eq", dispay_equation, 
+		      "show-r2", display_r_square,
+		      NULL);
+
+	if (!automatic_content)
+		oo_warning (xin, _("Gnumeric does not support non-automatic"
+				   " regression equations. Using automatic"
+				   " equation instead."));
+
+	if (style_name != NULL) {
+		OOChartStyle *chart_style = g_hash_table_lookup
+			(state->chart.graph_styles, style_name);
+		GOStyle *style = NULL;
+		g_object_get (G_OBJECT (equation), "style", &style, NULL);
+		if (style != NULL) {
+			odf_apply_style_props (chart_style->style_props, style);
+			g_object_unref (style);			
+		}
+	}	
+}
+
+static void
 od_series_regression (GsfXMLIn *xin, xmlChar const **attrs)
 {
 	OOParseState *state = (OOParseState *)xin->user_state;
 	char const *style_name = NULL;
 
+	state->chart.regression = NULL;
+
 	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]);
@@ -4819,7 +4874,8 @@ od_series_regression (GsfXMLIn *xin, xmlChar const **attrs)
 			}
 		}
 		
-		regression = GOG_OBJECT (gog_trend_line_new_by_name (type_name));
+		state->chart.regression = regression = 
+			GOG_OBJECT (gog_trend_line_new_by_name (type_name));
 		regression = gog_object_add_by_name (GOG_OBJECT (state->chart.series), 
 						     "Regression curve", regression);
 		oo_prop_list_apply (chart_style->other_props, G_OBJECT (regression));
@@ -5414,6 +5470,11 @@ static GsfXMLInNode const opendoc_content_dtd [] =
 		  GSF_XML_IN_NODE (CHART_SERIES, SERIES_DATA_PT, OO_NS_CHART, "data-point", GSF_XML_NO_CONTENT, &oo_series_pt, NULL),
 		  GSF_XML_IN_NODE (CHART_SERIES, SERIES_DATA_ERR, OO_NS_CHART, "error-indicator", GSF_XML_NO_CONTENT, NULL, NULL),
 		  GSF_XML_IN_NODE (CHART_SERIES, SERIES_REGRESSION, OO_NS_CHART, "regression-curve", GSF_XML_NO_CONTENT,  &od_series_regression, NULL),
+	            GSF_XML_IN_NODE (SERIES_REGRESSION, SERIES_REG_EQ, OO_NS_CHART, "equation", GSF_XML_NO_CONTENT,  &od_series_reg_equation, NULL),
+	            GSF_XML_IN_NODE (SERIES_REGRESSION, SERIES_REG_EQ_GNM, OO_GNUM_NS_EXT, "equation", GSF_XML_NO_CONTENT,  &od_series_reg_equation, NULL),
+		  GSF_XML_IN_NODE (CHART_SERIES, SERIES_REGRESSION_MULTIPLE, OO_GNUM_NS_EXT, "regression-curve", GSF_XML_NO_CONTENT,  &od_series_regression, NULL),
+	            GSF_XML_IN_NODE (SERIES_REGRESSION_MULTIPLE, SERIES_REG_EQ, OO_NS_CHART, "equation", GSF_XML_NO_CONTENT,  NULL, NULL),/* 2nd Def */
+	            GSF_XML_IN_NODE (SERIES_REGRESSION_MULTIPLE, SERIES_REG_EQ_GNM, OO_GNUM_NS_EXT, "equation", GSF_XML_NO_CONTENT,  NULL, NULL), /* 2nd Def */
 		  GSF_XML_IN_NODE (CHART_SERIES, SERIES_DROPLINES, OO_GNUM_NS_EXT, "droplines", GSF_XML_NO_CONTENT, &oo_series_droplines, NULL),
 		GSF_XML_IN_NODE (CHART_PLOT_AREA, CHART_WALL, OO_NS_CHART, "wall", GSF_XML_NO_CONTENT, &oo_chart_wall, NULL),
 		GSF_XML_IN_NODE (CHART_PLOT_AREA, CHART_FLOOR, OO_NS_CHART, "floor", GSF_XML_NO_CONTENT, NULL, NULL),
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 2ce7b4e..4585a9c 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -455,6 +455,97 @@ gnm_xml_out_add_hex_color (GsfXMLOut *o, char const *id, GnmColor const *c, int
 }
 
 static void
+odf_write_plot_style_int (GsfXMLOut *xml, GogObject const *plot, 
+			  GObjectClass *klass, char const *property,
+			  char const *id)
+{
+	GParamSpec *spec;
+	if (NULL != (spec = g_object_class_find_property (klass, property)) 
+	    && spec->value_type == G_TYPE_INT 
+	    && (G_PARAM_READABLE & spec->flags)) {
+		int i;
+		g_object_get (G_OBJECT (plot), property, &i, NULL);
+		gsf_xml_out_add_int (xml, id, i);
+	}	
+}
+
+static void
+odf_write_plot_style_uint (GsfXMLOut *xml, GogObject const *plot, 
+			  GObjectClass *klass, char const *property,
+			  char const *id)
+{
+	GParamSpec *spec;
+	if (NULL != (spec = g_object_class_find_property (klass, property)) 
+	    && spec->value_type == G_TYPE_UINT 
+	    && (G_PARAM_READABLE & spec->flags)) {
+		unsigned int i;
+		g_object_get (G_OBJECT (plot), property, &i, NULL);
+		gsf_xml_out_add_uint (xml, id, i);
+	}	
+}
+
+static void
+odf_write_plot_style_double (GsfXMLOut *xml, GogObject const *plot, 
+			     GObjectClass *klass, char const *property,
+			     char const *id)
+{
+	GParamSpec *spec;
+	if (NULL != (spec = g_object_class_find_property (klass, property)) 
+	    && spec->value_type == G_TYPE_DOUBLE 
+	    && (G_PARAM_READABLE & spec->flags)) {
+		double d;
+		g_object_get (G_OBJECT (plot), property, &d, NULL);
+		gsf_xml_out_add_float (xml, id, d, -1);
+	}	
+}
+
+static void
+odf_write_plot_style_double_percent (GsfXMLOut *xml, GogObject const *plot, 
+				     GObjectClass *klass, char const *property,
+				     char const *id)
+{
+	GParamSpec *spec;
+	if (NULL != (spec = g_object_class_find_property (klass, property)) 
+	    && spec->value_type == G_TYPE_DOUBLE 
+	    && (G_PARAM_READABLE & spec->flags)) {
+		double d;
+		g_object_get (G_OBJECT (plot), property, &d, NULL);
+		odf_add_percent (xml, id, d);
+	}	
+}
+
+static void
+odf_write_plot_style_bool (GsfXMLOut *xml, GogObject const *plot, 
+			  GObjectClass *klass, char const *property,
+			  char const *id)
+{
+	GParamSpec *spec;
+	if (NULL != (spec = g_object_class_find_property (klass, property)) 
+	    && spec->value_type == G_TYPE_BOOLEAN 
+	    && (G_PARAM_READABLE & spec->flags)) {
+		gboolean b;
+		g_object_get (G_OBJECT (plot), property, &b, NULL);
+		odf_add_bool (xml, id, b);
+	}	
+}
+
+static void
+odf_write_plot_style_from_bool (GsfXMLOut *xml, GogObject const *plot, 
+				GObjectClass *klass, char const *property,
+				char const *id,
+				char const *t_val, char const *f_val)
+{
+	GParamSpec *spec;
+	if (NULL != (spec = g_object_class_find_property (klass, property)) 
+	    && spec->value_type == G_TYPE_BOOLEAN 
+	    && (G_PARAM_READABLE & spec->flags)) {
+		gboolean b;
+		g_object_get (G_OBJECT (plot), property, &b, NULL);
+		gsf_xml_out_add_cstr (xml, id, b ? t_val : f_val);
+	}	
+}
+
+static void
 odf_start_style (GsfXMLOut *xml, char const *name, char const *family)
 {
 	gsf_xml_out_start_element (xml, STYLE "style");
@@ -3595,10 +3686,43 @@ odf_write_standard_series (GnmOOExport *state, GSList const *series)
 						(GOG_OBJECT (series->data), role);
 					for (l = regressions; l != NULL && l->data != NULL; l = l->next) {
 						GogObject const *regression = l->data;
+						GogObject const *equation 
+							= gog_object_get_child_by_name (regression, "Equation");
 						str = odf_get_gog_style_name_from_obj 
 							(GOG_OBJECT (regression));
-						gsf_xml_out_start_element (state->xml, CHART "regression-curve");
+						gsf_xml_out_start_element 
+							(state->xml, 
+							 (l == regressions) ? CHART "regression-curve" 
+							 : GNMSTYLE "regression-curve");
 						gsf_xml_out_add_cstr (state->xml, CHART "style-name", str);
+						
+						if (equation != NULL) {
+							GObjectClass *klass = G_OBJECT_GET_CLASS (equation);
+							char const *eq_element, *eq_automatic, *eq_display, *eq_r;
+							if (get_gsf_odf_version () > 101) {
+								eq_element = CHART "equation";
+								eq_automatic = CHART "automatic-content";
+								eq_display = CHART "display-equation";
+								eq_r = CHART "display-r-square";
+							} else {
+								eq_element = GNMSTYLE "equation";
+								eq_automatic = GNMSTYLE "automatic-content";
+								eq_display = GNMSTYLE "display-equation";
+								eq_r = GNMSTYLE "display-r-square";
+							}
+							gsf_xml_out_start_element 
+								(state->xml, eq_element);
+							odf_add_bool (state->xml, eq_automatic, TRUE);
+							odf_write_plot_style_bool (state->xml, equation, klass,
+										   "show-eq", eq_display);
+							odf_write_plot_style_bool (state->xml, equation, klass,
+										   "show-r2", eq_r);
+							str = odf_get_gog_style_name_from_obj 
+								(GOG_OBJECT (equation));
+							gsf_xml_out_add_cstr (state->xml, CHART "style-name", str);
+							gsf_xml_out_end_element (state->xml); /* </chart:equation> */
+						}
+
 						gsf_xml_out_end_element (state->xml); /* </chart:regression-curve> */
 						g_free (str);
 					}
@@ -3774,96 +3898,6 @@ odf_write_min_max_series (GnmOOExport *state, GSList const *orig_series)
 	}
 }
 
-static void
-odf_write_plot_style_int (GsfXMLOut *xml, GogObject const *plot, 
-			  GObjectClass *klass, char const *property,
-			  char const *id)
-{
-	GParamSpec *spec;
-	if (NULL != (spec = g_object_class_find_property (klass, property)) 
-	    && spec->value_type == G_TYPE_INT 
-	    && (G_PARAM_READABLE & spec->flags)) {
-		int i;
-		g_object_get (G_OBJECT (plot), property, &i, NULL);
-		gsf_xml_out_add_int (xml, id, i);
-	}	
-}
-
-static void
-odf_write_plot_style_uint (GsfXMLOut *xml, GogObject const *plot, 
-			  GObjectClass *klass, char const *property,
-			  char const *id)
-{
-	GParamSpec *spec;
-	if (NULL != (spec = g_object_class_find_property (klass, property)) 
-	    && spec->value_type == G_TYPE_UINT 
-	    && (G_PARAM_READABLE & spec->flags)) {
-		unsigned int i;
-		g_object_get (G_OBJECT (plot), property, &i, NULL);
-		gsf_xml_out_add_uint (xml, id, i);
-	}	
-}
-
-static void
-odf_write_plot_style_double (GsfXMLOut *xml, GogObject const *plot, 
-			     GObjectClass *klass, char const *property,
-			     char const *id)
-{
-	GParamSpec *spec;
-	if (NULL != (spec = g_object_class_find_property (klass, property)) 
-	    && spec->value_type == G_TYPE_DOUBLE 
-	    && (G_PARAM_READABLE & spec->flags)) {
-		double d;
-		g_object_get (G_OBJECT (plot), property, &d, NULL);
-		gsf_xml_out_add_float (xml, id, d, -1);
-	}	
-}
-
-static void
-odf_write_plot_style_double_percent (GsfXMLOut *xml, GogObject const *plot, 
-				     GObjectClass *klass, char const *property,
-				     char const *id)
-{
-	GParamSpec *spec;
-	if (NULL != (spec = g_object_class_find_property (klass, property)) 
-	    && spec->value_type == G_TYPE_DOUBLE 
-	    && (G_PARAM_READABLE & spec->flags)) {
-		double d;
-		g_object_get (G_OBJECT (plot), property, &d, NULL);
-		odf_add_percent (xml, id, d);
-	}	
-}
-
-static void
-odf_write_plot_style_bool (GsfXMLOut *xml, GogObject const *plot, 
-			  GObjectClass *klass, char const *property,
-			  char const *id)
-{
-	GParamSpec *spec;
-	if (NULL != (spec = g_object_class_find_property (klass, property)) 
-	    && spec->value_type == G_TYPE_BOOLEAN 
-	    && (G_PARAM_READABLE & spec->flags)) {
-		gboolean b;
-		g_object_get (G_OBJECT (plot), property, &b, NULL);
-		odf_add_bool (xml, id, b);
-	}	
-}
-
-static void
-odf_write_plot_style_from_bool (GsfXMLOut *xml, GogObject const *plot, 
-				GObjectClass *klass, char const *property,
-				char const *id,
-				char const *t_val, char const *f_val)
-{
-	GParamSpec *spec;
-	if (NULL != (spec = g_object_class_find_property (klass, property)) 
-	    && spec->value_type == G_TYPE_BOOLEAN 
-	    && (G_PARAM_READABLE & spec->flags)) {
-		gboolean b;
-		g_object_get (G_OBJECT (plot), property, &b, NULL);
-		gsf_xml_out_add_cstr (xml, id, b ? t_val : f_val);
-	}	
-}
 
 static void
 odf_write_interpolation_attribute (GnmOOExport *state, GogObject const *series) 



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