[gnumeric] xlsx: export multiple plots in one chart.



commit 680c30a2112f4fe5f1ffcc2b126d687929801d51
Author: Morten Welinder <terra gnome org>
Date:   Sat Mar 7 17:13:51 2015 -0500

    xlsx: export multiple plots in one chart.
    
    There still seems to be some problems with axis positioning.

 NEWS                               |    1 +
 plugins/excel/ChangeLog            |    3 +++
 plugins/excel/xlsx-read-drawing.c  |   14 +++++++++++++-
 plugins/excel/xlsx-write-drawing.c |   24 +++++++++---------------
 samples/graph-tests.gnumeric       |  Bin 11083 -> 11246 bytes
 5 files changed, 26 insertions(+), 16 deletions(-)
---
diff --git a/NEWS b/NEWS
index ccdbd05..7179d73 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Gnumeric 1.12.22
 
 Morten:
        * xlsx import/export of log axis.
+       * xlsx export of multiple plots in chart.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.21
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index d1e2267..a15c3c0 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,8 @@
 2015-03-07  Morten Welinder  <terra gnome org>
 
+       * xlsx-write-drawing.c (xlsx_write_plots): Write all plots, not
+       just the first one.
+
        * xlsx-write.c: Use new go_xml_out_add_double.
 
        * xlsx-write-drawing.c: Use new go_xml_out_add_double.
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 8f32a42..af5df55 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -708,7 +708,7 @@ xlsx_axis_start (GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attrs)
        /* Push dummy object for now until we can deduce the role.  */
        xlsx_chart_push_obj (state, NULL);
 #ifdef DEBUG_AXIS
-       g_printerr ("Create dummy object for axis\n");
+       g_printerr ("Create NULL object for axis\n");
 #endif
 }
 
@@ -805,6 +805,18 @@ xlsx_create_axis_object (XLSXReadState *state)
        if (state->cur_obj)
                return;
 
+       if (state->axis.info && state->axis.info->axis) {
+               axis = GOG_OBJECT (state->axis.obj = state->axis.info->axis);
+               /* Replace dummy object.  */
+               xlsx_chart_pop_obj (state);
+               xlsx_chart_push_obj (state, axis);
+#ifdef DEBUG_AXIS
+               g_printerr ("Re-using axis object %s with role %s\n",
+                           gog_object_get_name (axis), role);
+#endif
+               return;
+       }
+
        dummy = (!state->axis.info || !state->axis.info->plots);
        if (dummy) {
                plot = NULL;
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index ea4d5a4..4be1f41 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -66,7 +66,7 @@ xlsx_write_chart_float (GsfXMLOut *xml, char const *name, double val)
 }
 
 static void
-xlsx_write_plot_1_5_type (GsfXMLOut *xml, GogObject const *plot, gboolean is_barcol)
+xlsx_write_plot_1_5_type (GsfXMLOut *xml, GogPlot const *plot, gboolean is_barcol)
 {
        char *type;
        const char *gtype;
@@ -774,7 +774,7 @@ xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogPlot *plot, GogAxis *
 
 
 static void
-xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *chart, GogObject const *plot)
+xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *chart, GogPlot *plot)
 {
        double explosion = 0.;
        gboolean vary_by_element;
@@ -1102,18 +1102,12 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
 static void
 xlsx_write_plots (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *chart)
 {
-       GSList *plots;
-       GogObject const *plot;
-
-       plots = gog_object_get_children
-               (GOG_OBJECT (chart),
-                gog_object_find_role_by_name (GOG_OBJECT (chart), "Plot"));
-       if (plots != NULL && plots->data != NULL) {
-               plot = plots->data;
-               if (plots->next != NULL) {
-                       int n = g_slist_length (plots) - 1;
-                       g_warning ("Dropping %d plots from a chart.", n);
-               }
+       GSList *plots, *l;
+       GogObjectRole const *role = gog_object_find_role_by_name (GOG_OBJECT (chart), "Plot");
+
+       plots = gog_object_get_children (GOG_OBJECT (chart), role);
+       for (l = plots; l; l = l->next) {
+               GogPlot *plot = l->data;
                xlsx_write_one_plot (state, xml, chart, plot);
        }
        g_slist_free (plots);
@@ -1180,7 +1174,7 @@ xlsx_write_chart (XLSXWriteState *state, GsfOutput *chart_part, SheetObject *so)
                        xlsx_write_one_chart (state, xml, chart1);
                        if (charts->next)
                                g_warning ("Dropping %d charts on the floor!",
-                                          g_slist_length (charts));
+                                          g_slist_length (charts->next));
                        g_slist_free (charts);
                }
        }
diff --git a/samples/graph-tests.gnumeric b/samples/graph-tests.gnumeric
index 886ba64..f38d0ab 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]