[gnumeric] ODF import/export chart axis min and max formulae



commit 33cc4a641593f1401dc2b025e74d01c5e846db71
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Tue Jan 27 00:38:22 2015 -0700

    ODF import/export chart axis min and max formulae
    
    2015-01-27  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        * openoffice-write.c (odf_write_data_attribute): check for extensions
        (+odf_add_expr): new
        (odf_write_axis_style): write minimum- and maximum-expression
        (odf_write_reg_name): use odf_add_expr
        * openoffice-read.c (odf_apply_expression): new
        (oo_prop_list_apply_to_axis): handle minimum_expression and
        maximum_expression
        (od_style_prop_chart): read minimum_expression and
        maximum_expression

 NEWS                                  |    1 +
 plugins/openoffice/ChangeLog          |   12 ++++
 plugins/openoffice/openoffice-read.c  |   97 +++++++++++++++++++++++----------
 plugins/openoffice/openoffice-write.c |   47 +++++++++++-----
 4 files changed, 114 insertions(+), 43 deletions(-)
---
diff --git a/NEWS b/NEWS
index 911d8db..099e4c5 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Andreas:
        * ODF import/export trendline names. [#743448]
        * ODF import/export trendline affinity & dimensions.
        * ODF import/export major & minor chart axis tick marks.
+       * ODF import/export chart axis min and max formulae
 
 Morten:
        * xlsx chart import: fix font family name.
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index 9838203..acfef01 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,15 @@
+2015-01-27  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+       * openoffice-write.c (odf_write_data_attribute): check for extensions
+       (+odf_add_expr): new
+       (odf_write_axis_style): write minimum- and maximum-expression
+       (odf_write_reg_name): use odf_add_expr
+       * openoffice-read.c (odf_apply_expression): new
+       (oo_prop_list_apply_to_axis): handle minimum_expression and
+       maximum_expression
+       (od_style_prop_chart): read minimum_expression and
+       maximum_expression
+
 2015-01-26  Andreas J. Guelzow <aguelzow pyrshep ca>
 
        * openoffice-write.c (odf_write_plot_style): correctly write chart lines
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 78c8322..c544851 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -6726,8 +6726,28 @@ oo_prop_list_apply (GSList *props, GObject *obj)
 }
 
 static void
-oo_prop_list_apply_to_axis (OOParseState *state, GSList *props, GObject *obj)
+odf_apply_expression (GsfXMLIn *xin, gint dim, GObject *obj, gchar const *expression)
 {
+       OOParseState *state = (OOParseState *)xin->user_state;
+       GnmParsePos pp;
+       GOData *data;
+       GnmExprTop const *expr;
+       parse_pos_init (&pp, state->pos.wb, state->pos.sheet, 0, 0);
+       expr = oo_expr_parse_str
+               (xin, expression, &pp,
+                GNM_EXPR_PARSE_FORCE_EXPLICIT_SHEET_REFERENCES,
+                FORMULA_OPENFORMULA);
+       if (expr != NULL) {
+               data = gnm_go_data_scalar_new_expr (state->pos.sheet, expr);
+               gog_dataset_set_dim (GOG_DATASET (obj), dim, data, NULL);
+       } 
+}
+
+static void
+oo_prop_list_apply_to_axis (GsfXMLIn *xin, GSList *props, GObject *obj)
+{
+       OOParseState *state = (OOParseState *)xin->user_state;
+
        GSList *ptr;
        OOProp *prop;
        GOData *data;
@@ -6735,6 +6755,8 @@ oo_prop_list_apply_to_axis (OOParseState *state, GSList *props, GObject *obj)
        double minimum = go_ninf, maximum = go_pinf;
        double interval_major = 0.;
        double interval_minor_divisor = 0.;
+       gchar const *minimum_expression = NULL;
+       gchar const *maximum_expression = NULL;
 
        oo_prop_list_apply (props, obj);
 
@@ -6749,10 +6771,17 @@ oo_prop_list_apply_to_axis (OOParseState *state, GSList *props, GObject *obj)
                else if (0 == strcmp ("interval-minor-divisor", prop->name))
                        interval_minor_divisor
                                = g_value_get_double (&prop->value);
-
+               else if (0 == strcmp ("minimum-expression", prop->name))
+                       minimum_expression = g_value_get_string (&prop->value);
+               else if (0 == strcmp ("maximum-expression", prop->name))
+                       maximum_expression = g_value_get_string (&prop->value);
        }
 
        gog_axis_set_bounds (GOG_AXIS (obj), minimum, maximum);
+       if (minimum_expression)
+               odf_apply_expression (xin, 0, obj, minimum_expression);
+       if (maximum_expression)
+               odf_apply_expression (xin, 1, obj, maximum_expression);
 
        if (interval_major > 0) {
                data = gnm_go_data_scalar_new_expr
@@ -6914,52 +6943,64 @@ od_style_prop_chart (GsfXMLIn *xin, xmlChar const **attrs)
                        /* 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)) {
+               } 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_bool (xin, attrs, OO_GNUM_NS_EXT, "reverse-direction", &btmp)) {
+               else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT, "reverse-direction", &btmp))
                        style->axis_props = g_slist_prepend (style->axis_props,
                                oo_prop_new_bool ("invert-axis", btmp));
-               } else if (oo_attr_bool (xin, attrs, OO_NS_CHART,
-                                        "reverse-direction", &btmp)) {
+               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));
-               } else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT,
-                                        "vary-style-by-element", &btmp)) {
+               else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT,
+                                        "vary-style-by-element", &btmp))
                        style->plot_props = g_slist_prepend (style->plot_props,
                                oo_prop_new_bool ("vary-style-by-element",
                                                  btmp));
-               } else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT,
-                                        "show-negatives", &btmp)) {
+               else if (oo_attr_bool (xin, attrs, OO_GNUM_NS_EXT,
+                                        "show-negatives", &btmp))
                        style->plot_props = g_slist_prepend (style->plot_props,
                                oo_prop_new_bool ("show-negatives", btmp));
-               } else if (oo_attr_float (xin, attrs, OO_NS_CHART,
-                                         "minimum", &ftmp)) {
+               else if (oo_attr_float (xin, attrs, OO_NS_CHART,
+                                         "minimum", &ftmp))
                        style->axis_props = g_slist_prepend (style->axis_props,
                                oo_prop_new_double ("minimum", ftmp));
-               } else if (oo_attr_float (xin, attrs, OO_NS_CHART,
-                                         "maximum", &ftmp)) {
+               else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_GNUM_NS_EXT,
+                                            "chart-minimum-expression"))
+                       style->axis_props = g_slist_prepend
+                               (style->axis_props,
+                                oo_prop_new_string ("minimum-expression",
+                                                    CXML2C(attrs[1])));
+               else if (oo_attr_float (xin, attrs, OO_NS_CHART,
+                                         "maximum", &ftmp))
                        style->axis_props = g_slist_prepend (style->axis_props,
                                oo_prop_new_double ("maximum", ftmp));
-               } else if (oo_attr_float (xin, attrs, OO_NS_CHART,
-                                         "interval-major", &ftmp)) {
+               else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), OO_GNUM_NS_EXT,
+                                            "chart-maximum-expression"))
+                       style->axis_props = g_slist_prepend
+                               (style->axis_props,
+                                oo_prop_new_string ("maximum-expression",
+                                                    CXML2C(attrs[1])));
+               else if (oo_attr_float (xin, attrs, OO_NS_CHART,
+                                         "interval-major", &ftmp))
                        style->axis_props = g_slist_prepend (style->axis_props,
                                oo_prop_new_double ("interval-major", ftmp));
-               } else if (oo_attr_float (xin, attrs, OO_NS_CHART,
-                                         "interval-minor-divisor", &ftmp)) {
+               else if (oo_attr_float (xin, attrs, OO_NS_CHART,
+                                         "interval-minor-divisor", &ftmp))
                        style->axis_props = g_slist_prepend
                                (style->axis_props,
                                 oo_prop_new_double ("interval-minor-divisor",
                                                     ftmp));
-               } else if (oo_attr_float (xin, attrs, OO_GNUM_NS_EXT,
-                                         "radius-ratio", &ftmp)) {
+               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_double ("radius-ratio", ftmp));
-               } else if (oo_attr_percent (xin, attrs, OO_GNUM_NS_EXT,
-                                           "default-separation", &ftmp)) {
+               else if (oo_attr_percent (xin, attrs, OO_GNUM_NS_EXT,
+                                           "default-separation", &ftmp))
                        style->plot_props = g_slist_prepend (style->plot_props,
                                oo_prop_new_double ("default-separation", ftmp));
-               } else if (oo_attr_int_range (xin, attrs, OO_NS_CHART,
+               else if (oo_attr_int_range (xin, attrs, OO_NS_CHART,
                                              "pie-offset", &tmp, 0, 500)) {
                        style->plot_props = g_slist_prepend (style->plot_props,
                                oo_prop_new_double ("default-separation",
@@ -6968,14 +7009,14 @@ od_style_prop_chart (GsfXMLIn *xin, xmlChar const **attrs)
                                oo_prop_new_double ("separation",
                                                   tmp/100.));
                } else if (oo_attr_percent (xin, attrs, OO_NS_CHART,
-                                           "hole-size", &ftmp)) {
+                                           "hole-size", &ftmp))
                        style->plot_props = g_slist_prepend (style->plot_props,
                                oo_prop_new_double ("center-size", ftmp));
-               } else if (oo_attr_bool (xin, attrs, OO_NS_CHART,
-                                        "reverse-direction", &btmp)) {
+               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));
-               } else if (oo_attr_bool (xin, attrs, OO_NS_CHART, "stacked",
+               else if (oo_attr_bool (xin, attrs, OO_NS_CHART, "stacked",
                                         &btmp)) {
                        if (btmp) {
                                style->plot_props = g_slist_prepend
@@ -8445,7 +8486,7 @@ oo_chart_axis (GsfXMLIn *xin, xmlChar const **attrs)
                        GOStyle *gostyle;
                        g_object_get (G_OBJECT (state->chart.axis), "style", &gostyle, NULL);
 
-                       oo_prop_list_apply_to_axis (state, style->axis_props,
+                       oo_prop_list_apply_to_axis (xin, style->axis_props,
                                                    G_OBJECT (state->chart.axis));
                        odf_apply_style_props (xin, style->style_props, gostyle);
                        g_object_unref (gostyle);
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 9a5045a..7754bf8 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -6269,10 +6269,13 @@ odf_write_data_attribute (GnmOOExport *state, GOData const *data, GnmParsePos *p
        GnmExprTop const *texpr = gnm_go_data_get_expr (data);
 
        if (NULL != texpr) {
-               char *str = gnm_expr_top_as_string (texpr, pp, state->conv);
-               gsf_xml_out_add_cstr (state->xml, attribute,
-                                     odf_strip_brackets (str));
-               g_free (str);
+               if (state->with_extension) {
+                       char *str = gnm_expr_top_as_string (texpr, pp,
+                                                           state->conv);
+                       gsf_xml_out_add_cstr (state->xml, attribute,
+                                             odf_strip_brackets (str));
+                       g_free (str);
+               }
                if (NULL != c_attribute) {
                        GnmValue const *v = gnm_expr_top_get_constant (texpr);
                        if (NULL != v && VALUE_IS_STRING (v))
@@ -6780,6 +6783,19 @@ odf_get_marker (GOMarkerShape m)
 }
 
 static void
+odf_add_expr (GnmOOExport *state, GogObject const *obj, gint dim,
+             char const *attribute, char const *c_attribute)
+{
+               GnmParsePos pp;
+               GOData const *bd;
+               parse_pos_init (&pp, WORKBOOK (state->wb), NULL, 0,0 );
+               bd = gog_dataset_get_dim (GOG_DATASET (obj), dim);
+               if (bd != NULL)
+                       odf_write_data_attribute
+                               (state, bd, &pp, attribute, c_attribute);
+} 
+
+static void
 odf_write_axis_style (GnmOOExport *state, G_GNUC_UNUSED GOStyle const *style,
                      GogObject const *axis)
 {
@@ -6800,12 +6816,20 @@ odf_write_axis_style (GnmOOExport *state, G_GNUC_UNUSED GOStyle const *style,
 
        tmp = gog_axis_get_entry
                (GOG_AXIS (axis), GOG_AXIS_ELEM_MIN, &user_defined);
-       if (user_defined)
+       if (user_defined) {
                gsf_xml_out_add_float (state->xml, CHART "minimum", tmp, -1);
+               if (state->with_extension)
+                       odf_add_expr (state, GOG_OBJECT (axis), 0, 
+                                     GNMSTYLE "chart-minimum-expression", NULL);
+       }
        tmp = gog_axis_get_entry
                (GOG_AXIS (axis), GOG_AXIS_ELEM_MAX, &user_defined);
-       if (user_defined)
+       if (user_defined) {
                gsf_xml_out_add_float (state->xml, CHART "maximum", tmp, -1);
+               if (state->with_extension)
+                       odf_add_expr (state, GOG_OBJECT (axis), 1, 
+                                     GNMSTYLE "chart-maximum-expression", NULL);               
+       }
 
        interval = gog_dataset_get_dim (GOG_DATASET(axis),2);
        if (interval != NULL) {
@@ -8116,16 +8140,9 @@ odf_write_drop (GnmOOExport *state, G_GNUC_UNUSED GOStyle const *style,
 static void
 odf_write_reg_name (GnmOOExport *state, GogObject const *obj)
 {
-       if (state->with_extension) {
-               GnmParsePos pp;
-               GOData const *bd;
-               parse_pos_init (&pp, WORKBOOK (state->wb), NULL, 0,0 );
-               bd = gog_dataset_get_dim (GOG_DATASET (obj), -1);
-               if (bd != NULL)
-                       odf_write_data_attribute
-                               (state, bd, &pp, GNMSTYLE "regression-name",
+       if (state->with_extension)
+               odf_add_expr (state, obj, -1, GNMSTYLE "regression-name",
                                 LOEXT "regression-name");
-       }
 }
 
 static void


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