[gnumeric] Cleanup.



commit 9aaa68ed4a6f0fedf2568e0a16354f300ecb84d4
Author: Morten Welinder <terra gnome org>
Date:   Mon Jan 19 14:06:42 2015 -0500

    Cleanup.

 plugins/excel/ChangeLog            |    7 ++++
 plugins/excel/xlsx-read-drawing.c  |   64 +++++++++++++++--------------------
 plugins/excel/xlsx-utils.c         |   28 +++++++++++++++
 plugins/excel/xlsx-utils.h         |   17 +++++++++
 plugins/excel/xlsx-write-drawing.c |   66 ++++++++++++------------------------
 5 files changed, 101 insertions(+), 81 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index 1ba323d..9611baf 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-19  Morten Welinder  <terra gnome org>
+
+       * xlsx-write-drawing.c (xlsx_write_one_plot): Use
+       xlsx_plottype_from_type_name for readability.
+
+       * xlsx-utils.c (xlsx_plottype_from_type_name): New function.
+
 2015-01-17  Morten Welinder  <terra gnome org>
 
        * xlsx-write-drawing.c (xlsx_get_axid): New function allowing us
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 78c5cc6..39d9f0e 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -741,36 +741,38 @@ xlsx_axis_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
                char const *type = G_OBJECT_TYPE_NAME (plot);
                char const *role = NULL;
                GSList *ptr;
-
-               if (0 == strcmp (type, "GogRadarPlot") ||
-                   0 == strcmp (type, "GogRadarAreaPlot")) {
-                       role = (state->axis.type == XLSX_AXIS_CAT
-                               || state->axis.type == XLSX_AXIS_DATE) ? "Circular-Axis" : "Radial-Axis";
-               } else if (0 == strcmp (type, "GogBubblePlot") ||
-                          0 == strcmp (type, "GogXYPlot")) {
-                       /* both are VAL, use the position to decide */
+               gboolean inverted = FALSE;
+               gboolean cat_or_date = (state->axis.type == XLSX_AXIS_CAT ||
+                                       state->axis.type == XLSX_AXIS_DATE);
+
+               switch (xlsx_plottype_from_type_name (type)) {
+               case XLSX_PT_GOGRADARPLOT:
+               case XLSX_PT_GOGRADARAREAPLOT:
+                       role = cat_or_date ? "Circular-Axis" : "Radial-Axis";
+                       break;
+               case XLSX_PT_GOGBUBBLEPLOT:
+               case XLSX_PT_GOGXYPLOT:
                        if (state->axis.info->compass  == GOG_POSITION_N ||
                            state->axis.info->compass  == GOG_POSITION_S)
                                role = "X-Axis";
                        else
                                role = "Y-Axis";
-               } else if (0 == strcmp (type, "GogBarColPlot")) {
-                       gboolean h;
+                       break;
+               case XLSX_PT_GOGBARCOLPLOT:
                        /* swap for bar plots */
-                       g_object_get (G_OBJECT (plot), "horizontal", &h, NULL);
-                       if (h)
-                               role = (state->axis.type == XLSX_AXIS_CAT
-                                       || state->axis.type == XLSX_AXIS_DATE) ? "Y-Axis" : "X-Axis";
+                       g_object_get (G_OBJECT (plot), "horizontal", &inverted, NULL);
+                       break;
+
+               default:
+                       break;
                }
 
                if (NULL == role)
-                       role = (state->axis.type == XLSX_AXIS_CAT
-                               || state->axis.type == XLSX_AXIS_DATE) ? "X-Axis" : "Y-Axis";
+                       role = (inverted ^ cat_or_date) ? "X-Axis" : "Y-Axis";
 
-               /* absorb a ref, and set the id, and atype */
+               /* Set the id, and atype.  Ref to balance.  */
                gog_object_add_by_name (GOG_OBJECT (state->chart),
-                                       role, GOG_OBJECT (state->axis.obj));
-               g_object_ref (state->axis.obj);
+                                       role, GOG_OBJECT (g_object_ref (state->axis.obj)));
                for (ptr = state->axis.info->plots; ptr != NULL ; ptr = ptr->next) {
                        GogPlot *plot = ptr->data;
 #ifdef DEBUG_AXIS
@@ -825,28 +827,16 @@ xlsx_scatter_style (GsfXMLIn *xin, xmlChar const **attrs)
 
 static void
 xlsx_chart_bubble (GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attrs)
-{ xlsx_chart_add_plot (xin, "GogBubblePlot"); }
+{
+       xlsx_chart_add_plot (xin, "GogBubblePlot");
+}
 
 static void
 xlsx_chart_radar (GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attrs)
-{ xlsx_chart_add_plot (xin, "GogRadarPlot"); }
+{
+       xlsx_chart_add_plot (xin, "GogRadarPlot");
+}
 
-#if 0
-       char const *type = "GogRadarPlot";
-       gboolean with_markers = FALSE;
-       /* Irritants.  They put the sub type into a child record ... */
-       for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
-               if (0 == strcmp (attrs[0], "type")) {
-                       if (0 == strcmp (attrs[1], "filled"))
-                               type = "as_percentage";
-                       else if (0 == strcmp (attrs[1], "marker"))
-                               type = "stacked";
-                       g_object_set (G_OBJECT (state->plot), "type", type, NULL);
-               }
-               if (0 == strcmp (xin, attrs, "cx", state->drawing_pos + (COL | TO | OFFSET)))
-                       state->drawing_pos_flags |= (1 << (COL | TO | OFFSET));
-       g_object_set (G_OBJECT (state->plot), "default-style-has-markers", with_markers, NULL);
-#endif
 
 static void
 xlsx_plot_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
diff --git a/plugins/excel/xlsx-utils.c b/plugins/excel/xlsx-utils.c
index 15a543b..a3c51b0 100644
--- a/plugins/excel/xlsx-utils.c
+++ b/plugins/excel/xlsx-utils.c
@@ -749,3 +749,31 @@ xlsx_get_gradient_direction (double ang)
                return GO_GRADIENT_N_TO_S;
        }
 }
+
+
+XLSXPlotType
+xlsx_plottype_from_type_name (const char *type_name)
+{
+       static const char * const plot_types[] = {
+               NULL,
+               "GogAreaPlot",
+               "GogBarColPlot",
+               "GogLinePlot",
+               "GogPiePlot",
+               "GogRingPlot",
+               "GogRadarPlot",
+               "GogRadarAreaPlot",
+               "GogBubblePlot",
+               "GogXYPlot",
+               "GogContourPlot",
+               "XLContourPlot"
+       };
+       unsigned plot_type;
+
+       for (plot_type = 1; plot_type < G_N_ELEMENTS (plot_types); plot_type++) {
+               if (strcmp (type_name, plot_types[plot_type]) == 0)
+                       return (XLSXPlotType)plot_type;
+       }
+
+       return XLSX_PT_UNKNOWN;
+}
diff --git a/plugins/excel/xlsx-utils.h b/plugins/excel/xlsx-utils.h
index 093cff0..d4fd09c 100644
--- a/plugins/excel/xlsx-utils.h
+++ b/plugins/excel/xlsx-utils.h
@@ -59,4 +59,21 @@ GOFormat        *xlsx_pivot_date_fmt   (void);
 
 GOGradientDirection xlsx_get_gradient_direction (double ang);
 
+typedef enum {
+       XLSX_PT_UNKNOWN,
+       XLSX_PT_GOGAREAPLOT,
+       XLSX_PT_GOGBARCOLPLOT,
+       XLSX_PT_GOGLINEPLOT,
+       XLSX_PT_GOGPIEPLOT,
+       XLSX_PT_GOGRINGPLOT,
+       XLSX_PT_GOGRADARPLOT,
+       XLSX_PT_GOGRADARAREAPLOT,
+       XLSX_PT_GOGBUBBLEPLOT,
+       XLSX_PT_GOGXYPLOT,
+       XLSX_PT_GOGCONTOURPLOT,
+       XLSX_PT_XLCONTOURPLOT
+} XLSXPlotType;
+XLSXPlotType xlsx_plottype_from_type_name (const char *type_name);
+
+
 #endif /* GNM_XLSX_UTILS_H */
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index aa2e47c..882638b 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -404,26 +404,12 @@ xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogAxis *axis, GogAxisTy
 static void
 xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *chart, GogObject const *plot)
 {
-       gboolean failed = TRUE;
        gboolean use_xy = FALSE;
        double explosion = 0.;
        gboolean vary_by_element;
        GogAxisType axis_type[3] = {GOG_AXIS_X, GOG_AXIS_Y, GOG_AXIS_UNKNOWN};
        unsigned i;
-       static const char * const plot_types[] = {
-               /*  0 */ "GogAreaPlot",
-               /*  1 */ "GogBarColPlot",
-               /*  2 */ "GogLinePlot",
-               /*  3 */ "GogPiePlot",
-               /*  4 */ "GogRingPlot",
-               /*  5 */ "GogRadarPlot",
-               /*  6 */ "GogRadarAreaPlot",
-               /*  7 */ "GogBubblePlot",
-               /*  8 */ "GogXYPlot",
-               /*  9 */ "GogContourPlot",
-               /* 10 */ "XLContourPlot"
-       };
-       unsigned plot_type;
+       XLSXPlotType plot_type;
        const char *plot_type_name;
        GSList const *series;
        unsigned count;
@@ -432,24 +418,20 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                      "vary-style-by-element", &vary_by_element,
                      NULL);
        plot_type_name = G_OBJECT_TYPE_NAME (plot);
-       for (plot_type = 0; plot_type < G_N_ELEMENTS (plot_types); plot_type++) {
-               if (strcmp (plot_type_name, plot_types[plot_type]) == 0) {
-                       failed = FALSE;
-                       break;
-               }
-       }
-       if (failed) {
+       plot_type = xlsx_plottype_from_type_name (plot_type_name);
+
+       switch (plot_type) {
+       default:
+       case XLSX_PT_UNKNOWN:
                g_warning ("unexpected plot type %s", plot_type_name);
                return;
-       }
 
-       switch (plot_type) {
-       case 0:   // "GogAreaPlot"
+       case XLSX_PT_GOGAREAPLOT:
                gsf_xml_out_start_element (xml, "c:areaChart");
                xlsx_write_plot_1_5_type (xml, plot, FALSE);
                break;
 
-       case 1: { // "GogBarColPlot"
+       case XLSX_PT_GOGBARCOLPLOT: {
                gboolean horizontal;
 
                g_object_get (G_OBJECT (plot), "horizontal", &horizontal, NULL);
@@ -467,15 +449,15 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                break;
        }
 
-       case 2:   // "GogLinePlot"
+       case XLSX_PT_GOGLINEPLOT:
                gsf_xml_out_start_element (xml, "c:lineChart");
                xlsx_write_plot_1_5_type (xml, plot, FALSE);
                break;
 
-       case 3:   // "GogPiePlot"
-       case 4: { // "GogRingPlot"
+       case XLSX_PT_GOGPIEPLOT:
+       case XLSX_PT_GOGRINGPLOT: {
                gint16 center = 0;
-               if (plot_type == 4) {
+               if (plot_type == XLSX_PT_GOGRINGPLOT) {
                        double center_size;
                        gsf_xml_out_start_element (xml, "c:doughnutChart");
                        g_object_get (G_OBJECT (plot), "center-size", &center_size, NULL);
@@ -497,8 +479,8 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                break;
        }
 
-       case 5:   // "GogRadarPlot"
-       case 6:   // "GogRadarAreaPlot"
+       case XLSX_PT_GOGRADARPLOT:
+       case XLSX_PT_GOGRADARAREAPLOT:
                gsf_xml_out_start_element (xml, "c:radarChart");
                gsf_xml_out_start_element (xml, "c:radarStyle");
                gsf_xml_out_add_cstr_unchecked (xml, "val", "standard");
@@ -507,13 +489,13 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                axis_type[1] = GOG_AXIS_RADIAL;
                break;
 
-       case 7:  // "GogBubblePlot"
+       case XLSX_PT_GOGBUBBLEPLOT:
                gsf_xml_out_start_element (xml, "c:bubbleChart");
                xlsx_write_chart_bool (xml, "c:varyColors", vary_by_element);
                use_xy = TRUE;
                break;
 
-       case 8: { // "GogXYPlot"
+       case XLSX_PT_GOGXYPLOT: {
                gboolean has_lines, has_markers, use_splines;
                char const *style;
                g_object_get (G_OBJECT (plot),
@@ -532,14 +514,10 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                break;
        }
 
-       case 9:    // "GogContourPlot"
-       case 10:   // "XLContourPlot"
+       case XLSX_PT_GOGCONTOURPLOT:
+       case XLSX_PT_XLCONTOURPLOT:
                gsf_xml_out_start_element (xml, "c:surfaceChart");
                break;
-
-       default:
-               g_assert_not_reached ();
-               break;
        }
 
        count = 0;
@@ -573,7 +551,7 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
        }
 
        switch (plot_type) {
-       case 1: {
+       case XLSX_PT_GOGBARCOLPLOT: {
                char *s;
                int overlap_percentage, gap_percentage;
 
@@ -596,8 +574,8 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                break;
        }
 
-       case 3:
-       case 4: {
+       case XLSX_PT_GOGPIEPLOT:
+       case XLSX_PT_GOGRINGPLOT: {
                double initial_angle = 0;
                g_object_get (G_OBJECT (plot),
                              "initial-angle", &initial_angle,
@@ -606,7 +584,7 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
                break;
        }
 
-       case 7: {
+       case XLSX_PT_GOGBUBBLEPLOT: {
                gboolean show_neg = FALSE, in_3d = FALSE, as_area = TRUE;
                g_object_get (G_OBJECT (plot),
                              "show-negatives", &show_neg,


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