[gnumeric] Import and export boxplots to and from ODF files. [#626653]



commit fb0954442c0d294d223ee96c3c5b80256ff3d779
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Wed Aug 11 23:49:20 2010 -0600

    Import and export boxplots to and from ODF files. [#626653]
    
    2010-08-11  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* developer/odf-foreign.txt: update
    
    2010-08-11  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-write.c (odf_chart_type_t): add ODF_GNM_BOX
    	(odf_write_box_series): new
    	(odf_write_box_plot_style): new
    	(odf_write_plot): add ODF_GNM_BOX
    	* openoffice-read.c (oo_prop_new_float): new
    	(od_style_prop_chart): add new properties
    	(oo_plot_area): handle OO_PLOT_BOX
    	(oo_chart): add gnm:box

 NEWS                                  |    1 +
 doc/ChangeLog                         |    4 +
 doc/developer/odf-foreign.txt         |   10 +++
 plugins/openoffice/ChangeLog          |   11 +++
 plugins/openoffice/openoffice-read.c  |   22 +++++++
 plugins/openoffice/openoffice-write.c |  109 ++++++++++++++++++++++++++-------
 6 files changed, 135 insertions(+), 22 deletions(-)
---
diff --git a/NEWS b/NEWS
index 5df8f98..c8d061c 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Andreas:
 	* Fix crash on certain handcrafted ODF files. [#626632]
 	* Fix import of some ODF 1.0 charts. [#626632]
 	* Fix crash on paste into an empty expression entry. [#626648]
+	* Import and export boxplots to and from ODF files. [#626653]
 
 Jean:
 	* Import Guppi graphs from gnumeric-1.0.x files. [#567953]
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 044aa41..31525d7 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2010-08-11  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* developer/odf-foreign.txt: update
+
 2010-07-30  Morten Welinder <terra gnome org>
 
 	* Release 1.10.8
diff --git a/doc/developer/odf-foreign.txt b/doc/developer/odf-foreign.txt
index f7799a0..6676f5c 100644
--- a/doc/developer/odf-foreign.txt
+++ b/doc/developer/odf-foreign.txt
@@ -38,3 +38,13 @@ gnm:input-title
 gnm:input-msg
 These are attributes of the <style:table-cell-properties> giving the input title and the input message  [These are currently ignored on import.]
 
+gnm:outliers
+gnm:radius-ratio
+These are attributes for the plot-style gnm:boxplot
+
+3) Plot Styles added by Gnumeric:
+
+gnm:box
+gnm:scatter-color
+gnm:xyz-surface
+gnm:polar
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index fe30238..d0ce74b 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,16 @@
 2010-08-11  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* openoffice-write.c (odf_chart_type_t): add ODF_GNM_BOX
+	(odf_write_box_series): new
+	(odf_write_box_plot_style): new
+	(odf_write_plot): add ODF_GNM_BOX
+	* openoffice-read.c (oo_prop_new_float): new
+	(od_style_prop_chart): add new properties
+	(oo_plot_area): handle OO_PLOT_BOX
+	(oo_chart): add gnm:box
+
+2010-08-11  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* openoffice-read.c (oo_plot_area_end): fall back to 
 	  chart:plot-area table:cell-range-address if no series were 
 	  directly specified.
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 89ebb9d..c5a024f 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -129,6 +129,7 @@ typedef enum {
 	OO_PLOT_XYZ_SURFACE,
 	OO_PLOT_SURFACE,
 	OO_PLOT_XL_SURFACE,
+	OO_PLOT_BOX,
 	OO_PLOT_UNKNOWN
 } OOPlotType;
 
@@ -2851,6 +2852,15 @@ oo_style_map (GsfXMLIn *xin, xmlChar const **attrs)
 }
 
 static OOProp *
+oo_prop_new_float (char const *name, gnm_float val)
+{
+	OOProp *res = g_new0 (OOProp, 1);
+	res->name = name;
+	g_value_init (&res->value, G_TYPE_DOUBLE);
+	g_value_set_double (&res->value, val);
+	return res;
+}
+static OOProp *
 oo_prop_new_bool (char const *name, gboolean val)
 {
 	OOProp *res = g_new0 (OOProp, 1);
@@ -2966,6 +2976,7 @@ od_style_prop_chart (GsfXMLIn *xin, xmlChar const **attrs)
 	OOChartStyle *style = state->chart.cur_graph_style;
 	gboolean btmp;
 	int	  tmp;
+	gnm_float ftmp;
 	gboolean default_style_has_lines_set = FALSE;
 	gboolean draw_stroke_set = FALSE;
 	gboolean draw_stroke;
@@ -2983,6 +2994,15 @@ od_style_prop_chart (GsfXMLIn *xin, xmlChar const **attrs)
 			/* This is backwards from my intuition */
 			style->plot_props = g_slist_prepend (style->plot_props,
 				oo_prop_new_bool ("horizontal", btmp));
+			/* This is for BoxPlots */
+			style->plot_props = g_slist_prepend (style->plot_props,
+				oo_prop_new_bool ("vertical", btmp));
+		} else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT, "outliers", &btmp)) {
+			style->plot_props = g_slist_prepend (style->plot_props,
+				oo_prop_new_bool ("outliers", btmp));
+		} else if (oo_attr_float (xin, attrs, OO_GNUM_NS_EXT, "radius-ratio", &ftmp)) {
+			style->plot_props = g_slist_prepend (style->plot_props,
+				oo_prop_new_float ("radius-ratio", ftmp));
 		} else if (oo_attr_bool (xin, attrs, OO_NS_CHART, "reverse-direction", &btmp)) {
 			style->axis_props = g_slist_prepend (style->axis_props,
 				oo_prop_new_bool ("invert-axis", btmp));
@@ -3750,6 +3770,7 @@ oo_plot_area (GsfXMLIn *xin, xmlChar const **attrs)
 	case OO_PLOT_SURFACE: type = "GogSurfacePlot"; break;
 	case OO_PLOT_SCATTER_COLOUR: type = "GogXYColorPlot";	break;
 	case OO_PLOT_XL_SURFACE: type = "XLSurfacePlot";	break;
+	case OO_PLOT_BOX: type = "GogBoxPlot";	break;
 	default: return;
 	}
 
@@ -3963,6 +3984,7 @@ oo_chart (GsfXMLIn *xin, xmlChar const **attrs)
 		{ "gnm:polar",  	OO_PLOT_POLAR },
 		{ "gnm:xyz-surface", 	OO_PLOT_XYZ_SURFACE },
 		{ "gnm:scatter-color", 	OO_PLOT_SCATTER_COLOUR },
+		{ "gnm:box", 	        OO_PLOT_BOX },
 		{ NULL,	0 },
 	};
 	OOParseState *state = (OOParseState *)xin->user_state;
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index a821b38..dc9ad05 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3303,7 +3303,8 @@ typedef enum {
 	ODF_XYZ_GNM_SURF,
 	ODF_BUBBLE,
 	ODF_SCATTER_COLOUR,
-	ODF_POLAR
+	ODF_POLAR,
+	ODF_GNM_BOX
 } odf_chart_type_t;
 
 static void
@@ -3355,6 +3356,44 @@ odf_write_standard_series (GnmOOExport *state, GSList const *series)
 }
 
 static void
+odf_write_box_series (GnmOOExport *state, GSList const *series)
+{
+	GnmParsePos pp;
+	int i;
+	parse_pos_init (&pp, WORKBOOK (state->wb), NULL, 0,0 );
+
+	for (i = 1; NULL != series ; series = series->next, i++) {
+		GOData const *dat = gog_dataset_get_dim (GOG_DATASET (series->data), 0);
+
+		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));
+				g_free (str);
+				str = g_strdup_printf ("series%i", i);
+				gsf_xml_out_add_cstr (state->xml, CHART "style-name", str);
+				g_free (str);
+				dat = gog_series_get_name (GOG_SERIES (series->data));
+				if (NULL != dat) {
+					texpr = gnm_go_data_get_expr (dat);
+					if (NULL != texpr) {
+						str = gnm_expr_top_as_string (texpr, &pp, state->conv);
+						gsf_xml_out_add_cstr (state->xml, CHART "label-cell-address",
+								      odf_strip_brackets (str));
+						g_free (str);
+					}
+				}
+				gsf_xml_out_end_element (state->xml); /* </chart:series> */
+			}
+		}
+	}
+}
+
+static void
 odf_write_gantt_series (GnmOOExport *state, GSList const *series)
 {
 	GnmParsePos pp;
@@ -3491,6 +3530,28 @@ odf_write_bar_col_plot_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const
 }
 
 static void
+odf_write_box_plot_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *chart, GogObject const *plot)
+{
+	gboolean vertical = FALSE;
+	int gap = 0;
+
+	g_object_get (G_OBJECT (plot), 
+		      "vertical", &vertical,  
+		      "gap-percentage", &gap, NULL);
+	odf_add_bool (state->xml, CHART "vertical", vertical);
+	gsf_xml_out_add_int (state->xml, CHART "gap-width", gap);
+	if (state->with_extension) {
+		gboolean outliers = FALSE;
+		double radius = 0.;
+
+		g_object_get (G_OBJECT (plot), "outliers", &outliers, 
+			      "radius-ratio", &radius, NULL);
+		odf_add_bool (state->xml, GNMSTYLE "outliers", outliers);
+		gsf_xml_out_add_float (state->xml, GNMSTYLE "radius-ratio", radius, -1);
+	}
+}
+
+static void
 odf_write_ring_plot_style (GnmOOExport *state, G_GNUC_UNUSED GogObject const *chart, G_GNUC_UNUSED GogObject const *plot)
 {
 	odf_add_percent (state->xml, CHART "hole-size", 0.5);
@@ -3663,60 +3724,64 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 		void (*odf_write_series) (GnmOOExport *state, GSList const *series);
 		void (*odf_write_series_style) (GnmOOExport *state, GogObject const *series);
 	} *this_plot, plots[] = {
-		{ "GogBarColPlot", "chart:bar", ODF_BARCOL,
+		{ "GogBarColPlot", CHART "bar", ODF_BARCOL,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  NULL, odf_write_bar_col_plot_style, odf_write_standard_series, NULL},
-		{ "GogLinePlot", "chart:line", ODF_LINE,
+		{ "GogLinePlot", CHART "line", ODF_LINE,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  odf_write_line_chart_style, NULL, odf_write_standard_series, NULL},
-		{ "GogPolarPlot", "gnm:polar", ODF_POLAR,
+		{ "GogPolarPlot", GNMSTYLE "polar", ODF_POLAR,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  NULL, NULL, odf_write_standard_series, NULL},
-		{ "GogAreaPlot", "chart:area", ODF_AREA,
+		{ "GogAreaPlot", CHART "area", ODF_AREA,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  NULL, NULL, odf_write_standard_series, NULL},
-		{ "GogDropBarPlot", "chart:gantt", ODF_DROPBAR,
+		{ "GogDropBarPlot", CHART "gantt", ODF_DROPBAR,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_dropbar_axes_styles,
 		  NULL, odf_write_bar_col_plot_style, odf_write_gantt_series, NULL},
-		{ "GogMinMaxPlot", "chart:stock", ODF_MINMAX,
+		{ "GogMinMaxPlot", CHART "stock", ODF_MINMAX,
 		  10., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  NULL, NULL, odf_write_min_max_series, NULL},
-		{ "GogPiePlot", "chart:circle", ODF_CIRCLE,
+		{ "GogPiePlot", CHART "circle", ODF_CIRCLE,
 		  5., "X-Axis", "Y-Axis", NULL, odf_write_circle_axes_styles,
 		  NULL, NULL, odf_write_standard_series, NULL},
-		{ "GogRadarPlot", "chart:radar", ODF_RADAR,
+		{ "GogRadarPlot", CHART "radar", ODF_RADAR,
 		  10., "Circular-Axis", "Radial-Axis", NULL, odf_write_radar_axes_styles,
 		  NULL, NULL, odf_write_standard_series, NULL},
-		{ "GogRadarAreaPlot", "chart:filled-radar", ODF_RADARAREA,
+		{ "GogRadarAreaPlot", CHART "filled-radar", ODF_RADARAREA,
 		  10., "X-Axis", "Y-Axis", NULL, odf_write_radar_axes_styles,
 		  NULL, NULL, odf_write_standard_series, NULL},
-		{ "GogRingPlot", "chart:ring", ODF_RING,
+		{ "GogRingPlot", CHART "ring", ODF_RING,
 		  10., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  NULL, odf_write_ring_plot_style, odf_write_standard_series, NULL},
-		{ "GogXYPlot", "chart:scatter", ODF_SCATTER,
+		{ "GogXYPlot", CHART "scatter", ODF_SCATTER,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
-		  odf_write_scatter_chart_style, NULL, odf_write_standard_series, odf_write_scatter_series_style},
-		{ "GogContourPlot", "chart:surface", ODF_SURF,
+		  odf_write_scatter_chart_style, NULL, odf_write_standard_series, 
+		  odf_write_scatter_series_style},
+		{ "GogContourPlot", CHART "surface", ODF_SURF,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  odf_write_contour_chart_style, NULL, odf_write_bubble_series, NULL},
-		{ "GogXYZContourPlot", "gnm:xyz-surface", ODF_XYZ_SURF,
+		{ "GogXYZContourPlot", GNMSTYLE "xyz-surface", ODF_XYZ_SURF,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  odf_write_contour_chart_style, NULL, odf_write_bubble_series, NULL},
-		{ "GogXYZSurfacePlot", "gnm:xyz-surface", ODF_XYZ_GNM_SURF,
+		{ "GogXYZSurfacePlot", GNMSTYLE "xyz-surface", ODF_XYZ_GNM_SURF,
 		  20., "X-Axis", "Y-Axis", "Z-Axis", odf_write_surface_axes_styles,
 		  odf_write_surface_chart_style, NULL, odf_write_bubble_series, NULL},
-		{ "GogSurfacePlot", "chart:surface", ODF_GNM_SURF,
+		{ "GogSurfacePlot", CHART "surface", ODF_GNM_SURF,
 		  20., "X-Axis", "Y-Axis", "Z-Axis", odf_write_surface_axes_styles,
 		  odf_write_surface_chart_style, NULL, odf_write_bubble_series, NULL},
-		{ "GogBubblePlot", "chart:bubble", ODF_BUBBLE,
+		{ "GogBubblePlot", CHART "bubble", ODF_BUBBLE,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  NULL, NULL, odf_write_bubble_series, NULL},
-		{ "GogXYColorPlot", "gnm:scatter-color", ODF_SCATTER_COLOUR,
+		{ "GogXYColorPlot", GNMSTYLE "scatter-color", ODF_SCATTER_COLOUR,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  NULL, NULL, odf_write_bubble_series, NULL},
-		{ "XLSurfacePlot", "chart:surface", ODF_GNM_SURF,
+		{ "XLSurfacePlot", CHART "surface", ODF_GNM_SURF,
 		  20., "X-Axis", "Y-Axis", "Z-Axis", odf_write_surface_axes_styles,
 		  odf_write_xl_surface_chart_style, NULL, odf_write_standard_series, NULL},
+		{ "GogBoxPlot", GNMSTYLE "box", ODF_GNM_BOX,
+		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
+		  NULL, odf_write_box_plot_style, odf_write_box_series, NULL},
 		{ NULL, NULL, 0,
 		  20., "X-Axis", "Y-Axis", NULL, odf_write_standard_axes_styles,
 		  NULL, NULL, odf_write_standard_series, NULL}
@@ -3797,9 +3862,9 @@ odf_write_plot (GnmOOExport *state, SheetObject *so, GogObject const *chart, Gog
 	gsf_xml_out_start_element (state->xml, CHART "plot-area");
 	gsf_xml_out_add_cstr (state->xml, CHART "style-name", "plotarea");
 	if (get_gsf_odf_version () <= 101) {
-		for ( ; NULL != series ; series = series->next) {
+		for ( l = series; NULL != l ; l = l->next) {
 			GOData const *dat = gog_dataset_get_dim
-				(GOG_DATASET (series->data), GOG_MS_DIM_VALUES);
+				(GOG_DATASET (l->data), GOG_MS_DIM_VALUES);
 			if (NULL != dat) {
 				GnmExprTop const *texpr = gnm_go_data_get_expr (dat);
 				if (NULL != texpr) {



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