[gnumeric] xlsx: fix import and export of trend line "affine flag".



commit 7fb0512ffec5af861be1c2f2d58af4647293c6f6
Author: Morten Welinder <terra gnome org>
Date:   Thu Oct 26 19:20:33 2017 -0400

    xlsx: fix import and export of trend line "affine flag".

 NEWS                               |    1 +
 plugins/excel/ChangeLog            |    6 +++++-
 plugins/excel/xlsx-read-drawing.c  |   14 ++++++++++++++
 plugins/excel/xlsx-write-drawing.c |   10 ++++++++--
 samples/graph-tests.gnumeric       |  Bin 14184 -> 14447 bytes
 5 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index 0a206b0..f82e1e5 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ Morten:
        * xlsx import improvements for contour graphs.
        * xlsx export improvements for contour graphs.
        * Fix xlsx export of trend line equation.
+       * Fix xlsx import and export of trend line affine flag.
        * Avoid critical on exporting unnamed xlsx trend line.
 
 --------------------------------------------------------------------------
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index ca52c70..6d990da 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,10 +1,14 @@
 2017-10-26  Morten Welinder  <terra gnome org>
 
+       * xlsx-read-drawing.c (xlsx_ser_trendline_intercept): Read
+       intercept.
+
        * xlsx-write-drawing.c (xlsx_write_axis): Make axis tag for
        contour charts match what XL wants.  Even if it isn't obvious why.
        (xlsx_write_one_chart): Save a view3D for contour charts.
        (xlsx_write_one_plot): Fix writing trendline equation.  Don't
-       write a trendline name if there isn't one.
+       write a trendline name if there isn't one.  Write intercept=0 when
+       not linear.
 
 2017-10-24  Morten Welinder  <terra gnome org>
 
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 5b722ef..a9833b0 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -1409,6 +1409,19 @@ xlsx_get_trend_eq (XLSXReadState *state)
 
 
 static void
+xlsx_ser_trendline_intercept (GsfXMLIn *xin, G_GNUC_UNUSED  xmlChar const **attrs)
+{
+       XLSXReadState *state = (XLSXReadState *)xin->user_state;
+       gnm_float intercept = 1;
+
+       (void)simple_float (xin, attrs, &intercept);
+       // We don't have _writeable_ yet.
+       if (gnm_object_has_readable_prop (state->cur_obj, "affine", G_TYPE_BOOLEAN, NULL)) {
+               g_object_set (state->cur_obj, "affine", intercept != 0, NULL);
+       }
+}
+
+static void
 xlsx_ser_trendline_disprsqr (GsfXMLIn *xin, G_GNUC_UNUSED  xmlChar const **attrs)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
@@ -2671,6 +2684,7 @@ GSF_XML_IN_NODE_FULL (START, CHART_SPACE, XL_NS_CHART, "chartSpace", GSF_XML_NO_
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_NAME, XL_NS_CHART, "name", GSF_XML_CONTENT, 
NULL, &xlsx_ser_trendline_name),
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SHAPE_PR, XL_NS_CHART, "spPr", GSF_XML_2ND, NULL, NULL),
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_TYPE, XL_NS_CHART,     "trendlineType", 
GSF_XML_NO_CONTENT, &xlsx_ser_trendline_type, NULL),
+            GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_INTERCEPT, XL_NS_CHART,        "intercept", 
GSF_XML_NO_CONTENT, &xlsx_ser_trendline_intercept, NULL),
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_RSQR, XL_NS_CHART,     "dispRSqr", 
GSF_XML_NO_CONTENT, &xlsx_ser_trendline_disprsqr, NULL),
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_EQ, XL_NS_CHART,       "dispEq", 
GSF_XML_NO_CONTENT, &xlsx_ser_trendline_dispeq, NULL),
             GSF_XML_IN_NODE (SERIES_TRENDLINE, SERIES_TRENDLINE_LABEL, XL_NS_CHART,    "trendlineLbl", 
GSF_XML_NO_CONTENT, NULL, NULL),
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index 7f901b1..0900514 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -1090,15 +1090,18 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml,
                        GogObject *eq;
                        GOData *dat;
                        char *name;
+                       double intercept = gnm_nan;
 
                        if (!GOG_IS_TREND_LINE (trend))
                                continue;
 
                        if (strcmp (trend_type_name, "GogExpRegCurve") == 0)
                                trend_type = "exp";
-                       else if (strcmp (trend_type_name, "GogLinRegCurve") == 0)
+                       else if (strcmp (trend_type_name, "GogLinRegCurve") == 0) {
                                trend_type = "linear";
-                       else if (strcmp (trend_type_name, "GogLogRegCurve") == 0)
+                               if (!gnm_object_get_bool (trend, "affine"))
+                                       intercept = 0;
+                       } else if (strcmp (trend_type_name, "GogLogRegCurve") == 0)
                                trend_type = "log";
                        else if (strcmp (trend_type_name, "GogMovingAvg") == 0)
                                trend_type = "movingAvg";
@@ -1121,6 +1124,9 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml,
                        xlsx_write_go_style (xml, state, go_styled_object_get_style (GO_STYLED_OBJECT 
(trend)));
                        xlsx_write_chart_cstr_unchecked (xml, "c:trendlineType", trend_type);
 
+                       if (!gnm_isnan (intercept))
+                               xlsx_write_chart_float (xml, "c:intercept", intercept);
+
                        eq = gog_object_get_child_by_name (trend, "Equation");
                        if (eq) {
                                gboolean has_r2, has_eq;
diff --git a/samples/graph-tests.gnumeric b/samples/graph-tests.gnumeric
index 008f287..09c1911 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]