[gnumeric] xlsx: write chart title and axis labels.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] xlsx: write chart title and axis labels.
- Date: Sat, 17 Jan 2015 20:26:32 +0000 (UTC)
commit 47f8227b54a58d4f74d8891fccdce83b609d5327
Author: Morten Welinder <terra gnome org>
Date: Sat Jan 17 15:26:14 2015 -0500
xlsx: write chart title and axis labels.
NEWS | 3 +-
plugins/excel/ChangeLog | 4 +
plugins/excel/xlsx-write-drawing.c | 179 ++++++++++++++++++++++++------------
3 files changed, 126 insertions(+), 60 deletions(-)
---
diff --git a/NEWS b/NEWS
index 760d252..d6c7ffb 100644
--- a/NEWS
+++ b/NEWS
@@ -26,7 +26,8 @@ Morten:
* Fix sheet-filter problem with errors. [#742601]
* Improve error handling for .gnumeric a bit.
* Improve xlsx graph import: line colour; marker size; marker color.
- * Improve xlsx graph export: line style; bar/col direction; marker shape; marker size; marker color.
+ * Improve xlsx graph export: line style; bar/col direction; marker shape;
+ marker size; marker color; axis label; chart title.
* Improve xlsx export: default col widths.
Thomas Kluyver:
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index e2fa92e..0b36c12 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,5 +1,9 @@
2015-01-17 Morten Welinder <terra gnome org>
+ * xlsx-write-drawing.c (xlsx_write_axis): Factor this out from
+ xlsx_write_one_plot. Write axis label.
+ (xlsx_write_one_chart): Write chart title.
+
* xlsx-read-drawing.c (xlsx_plot_area): Keep the backplane in
default style.
diff --git a/plugins/excel/xlsx-write-drawing.c b/plugins/excel/xlsx-write-drawing.c
index 21af776..bb04661 100644
--- a/plugins/excel/xlsx-write-drawing.c
+++ b/plugins/excel/xlsx-write-drawing.c
@@ -275,6 +275,111 @@ xlsx_write_go_style (GsfXMLOut *xml, GOStyle *style)
}
static void
+xlsx_write_chart_text (XLSXWriteState *state, GsfXMLOut *xml,
+ GOData *data, GOStyledObject *so)
+{
+ /* I don't really know what I am doing here. */
+ char *text = go_data_get_scalar_string (data);
+
+ gsf_xml_out_start_element (xml, "c:tx");
+ gsf_xml_out_start_element (xml, "c:rich");
+
+ gsf_xml_out_start_element (xml, "a:bodyPr");
+ gsf_xml_out_end_element (xml);
+
+ gsf_xml_out_start_element (xml, "a:p");
+ gsf_xml_out_start_element (xml, "a:r");
+ gsf_xml_out_start_element (xml, "a:t");
+ gsf_xml_out_add_cstr (xml, NULL, text);
+ gsf_xml_out_end_element (xml);
+ gsf_xml_out_end_element (xml);
+ gsf_xml_out_end_element (xml);
+
+ gsf_xml_out_end_element (xml);
+ gsf_xml_out_end_element (xml);
+
+ g_free (text);
+}
+
+
+static void
+xlsx_write_axis (XLSXWriteState *state, GsfXMLOut *xml, GogAxis *axis, GogAxisType at)
+{
+ GogAxis *crossed = gog_axis_base_get_crossed_axis (GOG_AXIS_BASE (axis));
+ GogAxisPosition pos;
+ GogGridLine *grid;
+ GogObject *label;
+ GOFormat *format;
+
+ if (gog_axis_is_discrete (axis))
+ gsf_xml_out_start_element (xml, "c:catAx");
+ else
+ gsf_xml_out_start_element (xml, "c:valAx");
+ xlsx_write_chart_int (xml, "c:axId", 0, GPOINTER_TO_UINT (axis));
+ gsf_xml_out_start_element (xml, "c:scaling");
+ xlsx_write_chart_cstr_unchecked (xml, "c:orientation", gog_axis_is_inverted (axis)? "maxMin":
"minMax");
+ // TODO: export min, max, an others
+ gsf_xml_out_end_element (xml);
+ xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (axis)));
+ /* 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");
+ xlsx_write_chart_int (xml, "c:crossAx", 0, GPOINTER_TO_UINT (crossed));
+ g_object_get (G_OBJECT (axis), "pos", &pos, NULL);
+ switch (pos) {
+ default:
+ case GOG_AXIS_AT_LOW:
+ /* FIXME: might be wrong if the axis is inverted */
+ xlsx_write_chart_cstr_unchecked (xml, "c:crosses", "min");
+ break;
+ case GOG_AXIS_CROSS: {
+ double cross = gog_axis_base_get_cross_location (GOG_AXIS_BASE (axis));
+ if (cross == 0.)
+ xlsx_write_chart_cstr_unchecked (xml, "c:crosses", "autoZero");
+ else
+ xlsx_write_chart_float (xml, "c:crossesAt", 0., cross);
+ break;
+ }
+ case GOG_AXIS_AT_HIGH:
+ xlsx_write_chart_cstr_unchecked (xml, "c:crosses", "max");
+ break;
+ }
+ /* grids */
+ grid = gog_axis_get_grid_line (axis, TRUE);
+ if (grid) {
+ gsf_xml_out_start_element (xml, "c:majorGridlines");
+ xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (grid)));
+ gsf_xml_out_end_element (xml);
+ }
+ grid = gog_axis_get_grid_line (axis, FALSE);
+ if (grid) {
+ gsf_xml_out_start_element (xml, "c:minorGridlines");
+ xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (grid)));
+ gsf_xml_out_end_element (xml);
+ }
+
+ label = gog_object_get_child_by_name (GOG_OBJECT (axis), "Label");
+ if (label) {
+ GOData *text = gog_dataset_get_dim (GOG_DATASET (label), 0);
+ if (text != NULL) {
+ gsf_xml_out_start_element (xml, "c:title");
+ xlsx_write_chart_text (state, xml, text, GO_STYLED_OBJECT (label));
+ gsf_xml_out_end_element (xml);
+ }
+ }
+
+ gsf_xml_out_start_element (xml, "c:numFmt");
+ format = gog_axis_get_format (axis);
+ gsf_xml_out_add_bool (xml, "sourceLinked", format == NULL || go_format_is_general (format));
+ format = gog_axis_get_effective_format (axis);
+ gsf_xml_out_add_cstr (xml, "formatCode", (format)? go_format_as_XL (format): "General");
+ gsf_xml_out_end_element (xml);
+
+ /* finished with axis */
+ gsf_xml_out_end_element (xml);
+}
+
+
+static void
xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *chart, GogObject const *plot)
{
char const *plot_type;
@@ -431,70 +536,15 @@ xlsx_write_one_plot (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *cha
/* Write axes */
/* first category axis */
/* FIXME: might be a date axis? */
- for (i = 0; i < 3; i++)
+ for (i = 0; i < 3; i++) {
if (axis_type[i] != GOG_AXIS_UNKNOWN) {
GSList *axes = gog_chart_get_axes (GOG_CHART (chart), axis_type[i]), *ptr;
for (ptr = axes; ptr; ptr = ptr->next) {
- GogAxis *crossed = gog_axis_base_get_crossed_axis (GOG_AXIS_BASE (ptr->data));
- GogAxisPosition pos;
- GogGridLine *grid;
- GOFormat *format;
- if (gog_axis_is_discrete (ptr->data))
- gsf_xml_out_start_element (xml, "c:catAx");
- else
- gsf_xml_out_start_element (xml, "c:valAx");
- xlsx_write_chart_int (xml, "c:axId", 0, GPOINTER_TO_UINT (ptr->data));
- gsf_xml_out_start_element (xml, "c:scaling");
- xlsx_write_chart_cstr_unchecked (xml, "c:orientation", gog_axis_is_inverted
(GOG_AXIS (ptr->data))? "maxMin": "minMax");
- // TODO: export min, max, an others
- gsf_xml_out_end_element (xml);
- xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT
(ptr->data)));
- /* FIXME position might be "t" or "r" */
- xlsx_write_chart_cstr_unchecked (xml, "c:axPos", (axis_type[i] == GOG_AXIS_X
|| axis_type[i] == GOG_AXIS_CIRCULAR)? "b": "l");
- xlsx_write_chart_int (xml, "c:crossAx", 0, GPOINTER_TO_UINT (crossed));
- g_object_get (G_OBJECT (ptr->data), "pos", &pos, NULL);
- switch (pos) {
- default:
- case GOG_AXIS_AT_LOW:
- /* FIXME: might be wrong if the axis is inverted */
- xlsx_write_chart_cstr_unchecked (xml, "c:crosses", "min");
- break;
- case GOG_AXIS_CROSS: {
- double cross = gog_axis_base_get_cross_location (GOG_AXIS_BASE
(ptr->data));
- if (cross == 0.)
- xlsx_write_chart_cstr_unchecked (xml, "c:crosses",
"autoZero");
- else
- xlsx_write_chart_float (xml, "c:crossesAt", 0., cross);
- break;
- }
- case GOG_AXIS_AT_HIGH:
- xlsx_write_chart_cstr_unchecked (xml, "c:crosses", "max");
- break;
- }
- /* grids */
- grid = gog_axis_get_grid_line (GOG_AXIS (ptr->data), TRUE);
- if (grid) {
- gsf_xml_out_start_element (xml, "c:majorGridlines");
- xlsx_write_go_style (xml, go_styled_object_get_style
(GO_STYLED_OBJECT (grid)));
- gsf_xml_out_end_element (xml);
- }
- grid = gog_axis_get_grid_line (GOG_AXIS (ptr->data), FALSE);
- if (grid) {
- gsf_xml_out_start_element (xml, "c:minorGridlines");
- xlsx_write_go_style (xml, go_styled_object_get_style
(GO_STYLED_OBJECT (grid)));
- gsf_xml_out_end_element (xml);
- }
- gsf_xml_out_start_element (xml, "c:numFmt");
- format = gog_axis_get_format (GOG_AXIS (ptr->data));
- gsf_xml_out_add_bool (xml, "sourceLinked", format == NULL ||
go_format_is_general (format));
- format = gog_axis_get_effective_format (GOG_AXIS (ptr->data));
- gsf_xml_out_add_cstr (xml, "formatCode", (format)? go_format_as_XL (format):
"General");
- gsf_xml_out_end_element (xml);
-
- /* finished with axis */
- gsf_xml_out_end_element (xml);
+ GogAxis *axis = ptr->data;
+ xlsx_write_axis (state, xml, axis, axis_type[i]);
}
}
+ }
}
static void
@@ -525,6 +575,17 @@ xlsx_write_one_chart (XLSXWriteState *state, GsfXMLOut *xml, GogObject const *ch
xlsx_write_go_style (xml, go_styled_object_get_style (GO_STYLED_OBJECT (chart)));
gsf_xml_out_start_element (xml, "c:chart");
+
+ obj = gog_object_get_child_by_name (chart, "Title");
+ if (obj) {
+ GOData *text = gog_dataset_get_dim (GOG_DATASET (obj), 0);
+ if (text != NULL) {
+ gsf_xml_out_start_element (xml, "c:title");
+ xlsx_write_chart_text (state, xml, text, GO_STYLED_OBJECT (obj));
+ gsf_xml_out_end_element (xml);
+ }
+ }
+
gsf_xml_out_start_element (xml, "c:plotArea");
/* save grid style here */
obj = gog_object_get_child_by_name (GOG_OBJECT (chart), "Backplane");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]