[gnumeric] Export column charts to ODF.



commit 27a3bee82c35eee5df7fa82c41ca2e52efb7f7c8
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Fri Jul 10 02:13:47 2009 -0600

    Export column charts to ODF.
    
    2009-07-10 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-write.c (odf_write_series): new
    	(odf_write_bar_col_plot): new
    	(odf_write_graph_content): retrieve plot

 NEWS                                  |    1 +
 plugins/openoffice/ChangeLog          |    6 +++
 plugins/openoffice/openoffice-write.c |   61 ++++++++++++++++++++++++++++++--
 3 files changed, 64 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index b49635e..82a8ff6 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Andreas:
 	* Fix std error for intercept in non-affine case of LINEST. [#550933]
 	* Fix loading of charts from MS generated ODF files. [#588107]
 	* Add some sheet object support to ODF export.
+	* Export column charts to ODF.
 
 Morten:
 	* Make SUMIF/COUNTIF and the D* functions understand pattern. [#586215]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index a50b394..fd996ff 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,11 @@
 2009-07-10 Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* openoffice-write.c (odf_write_series): new
+	(odf_write_bar_col_plot): new
+	(odf_write_graph_content): retrieve plot
+
+2009-07-10 Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* openoffice-write.c (odf_write_frame): also include
 	  an image of graphs
 	(odf_write_graph_manifest): add svg image file
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 66a04d7..fd9b593 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -89,6 +89,7 @@
 #define FOSTYLE	 "fo:"
 #define NUMBER   "number:"
 #define DRAW	 "draw:"
+#define CHART	 "chart:"
 #define SVG	 "svg:"
 #define XLINK	 "xlink:"
 #define GNMSTYLE "gnm:"  /* We use this for attributes and elements not supported by ODF */
@@ -3135,9 +3136,53 @@ odf_write_manifest (GnmOOExport *state, GsfOutput *child)
 
 /**********************************************************************************/
 static void
-odf_write_graph_content (GnmOOExport *state, GsfOutput *child, SheetObject *graph)
+odf_write_series (GnmOOExport *state, GSList const *series)
+{
+	GnmParsePos pp;
+	parse_pos_init (&pp, WORKBOOK (state->wb), NULL, 0,0 );
+
+	for ( ; NULL != series ; series = series->next) {
+		GOData const *dat = gog_dataset_get_dim (GOG_DATASET (series->data), GOG_MS_DIM_VALUES);
+		if (NULL != dat) {
+			GnmExprTop const *texpr = gnm_go_data_get_expr (dat);
+			if (NULL != texpr) {
+				char *str = gnm_expr_top_as_string (texpr, &pp, state->conv);
+				gsf_xml_out_start_element (state->xml, CHART "series");
+				gsf_xml_out_add_cstr (state->xml, CHART "values-cell-range-address", 
+						      odf_strip_brackets (str));
+				gsf_xml_out_end_element (state->xml); /* </chart:series> */
+			}
+		}
+	}
+}
+
+static void
+odf_write_bar_col_plot (GnmOOExport *state, GogObject const *chart, GogObject const *plot)
+{
+	gsf_xml_out_add_cstr (state->xml, CHART "class", "chart:bar");
+
+	gsf_xml_out_start_element (state->xml, CHART "plot-area");
+	odf_write_series (state, gog_plot_get_series (GOG_PLOT (plot)));
+	gsf_xml_out_end_element (state->xml); /* </chart:plot_area> */
+}
+
+static void
+odf_write_plot (GnmOOExport *state, GogObject const *chart, GogObject const *plot)
+{
+	char const *plot_type = G_OBJECT_TYPE_NAME (plot);
+	gsf_xml_out_start_element (state->xml, CHART "chart");
+	gsf_xml_out_add_cstr (state->xml, XLINK "href", "..");
+	if (0 == strcmp (plot_type, "GogBarColPlot"))
+		odf_write_bar_col_plot (state, chart, plot);
+	gsf_xml_out_end_element (state->xml); /* </chart:chart> */
+}
+
+
+static void
+odf_write_graph_content (GnmOOExport *state, GsfOutput *child, SheetObject *so)
 {
 	int i;
+	GogGraph const	*graph;
 
 	state->xml = gsf_xml_out_new (child);
 	gsf_xml_out_set_doc_type (state->xml, "\n");
@@ -3149,10 +3194,18 @@ odf_write_graph_content (GnmOOExport *state, GsfOutput *child, SheetObject *grap
 					get_gsf_odf_version_string ());
 
 	gsf_xml_out_start_element (state->xml, OFFICE "body");
-
-
+	graph = sheet_object_graph_get_gog (so);
+	if (graph != NULL) {
+		GogObject const	*chart = gog_object_get_child_by_name (GOG_OBJECT (graph), "Chart");
+		gsf_xml_out_start_element (state->xml, OFFICE "chart");
+		if (chart != NULL) {
+			GogObject const *plot = gog_object_get_child_by_name (GOG_OBJECT (chart), "Plot");
+			if (plot != NULL) 
+				odf_write_plot (state, chart, plot);
+		}
+		gsf_xml_out_end_element (state->xml); /* </office:chart> */
+	}
 	gsf_xml_out_end_element (state->xml); /* </office:body> */
-
 	gsf_xml_out_end_element (state->xml); /* </office:document-content> */
 	g_object_unref (state->xml);
 	state->xml = NULL;



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