[gnumeric] xlsx: handle log axis.



commit b33ef0129025df055296a1952ab688206bc377a9
Author: Morten Welinder <terra gnome org>
Date:   Wed Mar 4 21:26:00 2015 -0500

    xlsx: handle log axis.

 NEWS                               |    3 +++
 plugins/excel/ChangeLog            |    5 +++++
 plugins/excel/xlsx-read-drawing.c  |   15 +++++++++++----
 plugins/excel/xlsx-read.c          |    1 +
 plugins/excel/xlsx-write-drawing.c |   12 +++++++++++-
 samples/graph-tests.gnumeric       |  Bin 10531 -> 10677 bytes
 6 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/NEWS b/NEWS
index b68369a..ccdbd05 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 Gnumeric 1.12.22
 
+Morten:
+       * xlsx import/export of log axis.
+
 --------------------------------------------------------------------------
 Gnumeric 1.12.21
 
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index ebc243c..0d56f30 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-04  Morten Welinder  <terra gnome org>
+
+       * xlsx-read-drawing.c (xlsx_create_axis_object): Handle log axis.
+       * xlsx-write-drawing.c (xlsx_write_axis): Ditto.
+
 2015-03-04  Morten Welinder <terra gnome org>
 
        * Release 1.12.21
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 18c40bb..9749eb8 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -684,6 +684,7 @@ xlsx_plot_axis_id (GsfXMLIn *xin, xmlChar const **attrs)
                                res->cross      = GOG_AXIS_CROSS;
                                res->cross_value = go_nan;
                                res->invert_axis = FALSE;
+                               res->logbase = 0;
                                g_hash_table_replace (state->axis.by_id, res->id, res);
 #ifdef DEBUG_AXIS
                                g_printerr ("create info for %s = %p\n", attrs[1], res);
@@ -783,10 +784,9 @@ static void
 xlsx_chart_logbase (GsfXMLIn *xin, xmlChar const **attrs)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
-       int base;
-       if (state->axis.info && simple_int (xin, attrs, &base))
-               g_object_set (G_OBJECT (state->axis.obj),
-                       "map-name", "Log", NULL);
+       gnm_float base;
+       if (state->axis.info && simple_float (xin, attrs, &base) && base >= 2 && base <= 1000)
+               state->axis.info->logbase = base;
 }
 
 /* See bug 743347 for discussion.  */
@@ -862,6 +862,13 @@ xlsx_create_axis_object (XLSXReadState *state)
                g_object_set (G_OBJECT (state->axis.obj),
                              "invisible", state->axis.info->deleted,
                              "invert-axis", state->axis.info->invert_axis, NULL);
+
+               if (state->axis.info->logbase > 0) {
+                       g_object_set (G_OBJECT (state->axis.obj),
+                                     "map-name", "Log",
+                                     NULL);
+                       /* Base?  */
+               }
        }
 }
 
diff --git a/plugins/excel/xlsx-read.c b/plugins/excel/xlsx-read.c
index de2854b..43e78d0 100644
--- a/plugins/excel/xlsx-read.c
+++ b/plugins/excel/xlsx-read.c
@@ -121,6 +121,7 @@ typedef struct {
        char    *cross_id;
        gnm_float cross_value;
        gboolean invert_axis;
+       double logbase;
 
        double axis_elements[GOG_AXIS_ELEM_MAX_ENTRY];
        guint8 axis_element_set[GOG_AXIS_ELEM_MAX_ENTRY];
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index 469b22f..96f5856 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -661,6 +661,7 @@ xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogPlot *plot, GogAxis *
        GOFormat *format;
        double d;
        gboolean user_defined;
+       char *map_name;
 
 #ifdef DEBUG_AXIS
        g_printerr ("Writing axis %s [id=%d].  (discrete = %d)\n",
@@ -674,13 +675,22 @@ xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogPlot *plot, GogAxis *
        else
                gsf_xml_out_start_element (xml, "c:valAx");
        xlsx_write_chart_uint (xml, "c:axId", 0, xlsx_get_axid (state, axis));
+
        gsf_xml_out_start_element (xml, "c:scaling");
-       xlsx_write_chart_cstr_unchecked (xml, "c:orientation", gog_axis_is_inverted (axis)? "maxMin": 
"minMax");
+       g_object_get (axis, "map-name", &map_name, NULL);
+       if (g_strcmp0 (map_name, "Log") == 0) {
+               double base = 10;
+               xlsx_write_chart_float (xml, "c:logBase", go_nan, base);
+       }
+       g_free (map_name);
+       xlsx_write_chart_cstr_unchecked (xml, "c:orientation",
+                                        gog_axis_is_inverted (axis)? "maxMin": "minMax");
        d = gog_axis_get_entry (axis, GOG_AXIS_ELEM_MAX, &user_defined);
        if (user_defined) xlsx_write_chart_float (xml, "c:max", go_nan, d);
        d = gog_axis_get_entry (axis, GOG_AXIS_ELEM_MIN, &user_defined);
        if (user_defined) xlsx_write_chart_float (xml, "c:min", go_nan, d);
        gsf_xml_out_end_element (xml);
+
        xlsx_write_chart_uint (xml, "c:delete", 1, 0);
        /* FIXME position might be "t" or "r" */
        xlsx_write_chart_cstr_unchecked (xml, "c:axPos", (at == GOG_AXIS_X || at == GOG_AXIS_CIRCULAR)? "b": 
"l");
diff --git a/samples/graph-tests.gnumeric b/samples/graph-tests.gnumeric
index 0e5af1c..7218f54 100644
Binary files a/samples/graph-tests.gnumeric and b/samples/graph-tests.gnumeric differ


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