[gnumeric] Fix use of cell formats in graphs data labels. [#777338]
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Fix use of cell formats in graphs data labels. [#777338]
- Date: Sun, 22 Jan 2017 18:59:02 +0000 (UTC)
commit edc48af80a97a7a957cbf1af7738646ca47390eb
Author: Jean Brefort <jean brefort normalesup org>
Date: Sun Jan 22 19:58:38 2017 +0100
Fix use of cell formats in graphs data labels. [#777338]
ChangeLog | 5 ++
NEWS | 3 +
src/graph.c | 119 +++++++++++++++++++++++++++++++++-------------------------
3 files changed, 76 insertions(+), 51 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 86f3998..4da96e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-01-22 Jean Brefort <jean brefort normalesup org>
+
+ * src/graph.c (cb_assign_string), (gnm_go_data_vector_get_str): use cell
+ format when generating the string. [#777338]
+
2017-01-19 Morten Welinder <terra gnome org>
* src/mstyle.c (ELEM_IS_EQ): Don't compare conditions by pointer.
diff --git a/NEWS b/NEWS
index 1230c63..2b7c44b 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,9 @@ Andreas:
* Fix Wilcoxon Signed Rank Test handling of ties. [#772718]
* Fix xlsx export of scale to page information. [#776196]
+Jean:
+ * Fix use of cell formats in graphs data labels. [#777338]
+
Morten:
* Speed up sstest part of test suite.
* Bring documentation build into the 21 century.
diff --git a/src/graph.c b/src/graph.c
index 20436fd..d736fa5 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -1,5 +1,4 @@
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-
/*
* graph.c: The gnumeric specific data wrappers for GOffice
*
@@ -867,16 +866,24 @@ gnm_go_data_vector_get_value (GODataVector *dat, unsigned i)
}
+struct string_closure {
+ GPtrArray *strs;
+ GODateConventions const *date_conv;
+};
+
static gpointer
-cb_assign_string (GnmCellIter const *iter, GPtrArray *strs)
+cb_assign_string (GnmCellIter const *iter, struct string_closure *closure)
{
GnmValue *v = NULL;
+ char *str = NULL;
if (iter->cell != NULL) {
gnm_cell_eval (iter->cell);
v = iter->cell->value;
}
- g_ptr_array_add (strs, v);
+ if (v != NULL)
+ str = format_value (gnm_cell_get_format (iter->cell), v, -1, closure->date_conv);
+ g_ptr_array_add (closure->strs, str);
return NULL;
}
@@ -898,63 +905,73 @@ gnm_go_data_vector_get_str (GODataVector *dat, unsigned i)
eval_pos_init_dep (&ep, &vec->dep);
if (VALUE_IS_ARRAY (vec->val)) {
/* we need to cache the strings if needed */
- int len = vec->val->v_array.y * vec->val->v_array.x;
- int x = 0, y = vec->val->v_array.y;
- while (len-- > 0) {
- if (x == 0) {
- x = vec->val->v_array.x;
- y--;
- }
- x--;
- v = vec->val->v_array.vals [x][y];
+ if (vec->strs == NULL) {
+ int len = vec->val->v_array.y * vec->val->v_array.x;
+ int x = 0, y = vec->val->v_array.y;
+ struct string_closure closure;
+ closure.strs = vec->strs = g_ptr_array_new_with_free_func (g_free);
+ closure.date_conv = ep.sheet ? workbook_date_conv (ep.sheet->workbook) : NULL;
+ while (len-- > 0) {
+ if (x == 0) {
+ x = vec->val->v_array.x;
+ y--;
+ }
+ x--;
+ v = vec->val->v_array.vals [x][y];
- if (VALUE_IS_CELLRANGE (v)) {
- /* actually we only need to cache in that case */
- Sheet *start_sheet, *end_sheet;
- GnmRange r;
- if (vec->strs == NULL)
- vec->strs = g_ptr_array_new ();
- gnm_rangeref_normalize (&v->v_range.cell,
- eval_pos_init_dep (&ep, &vec->dep),
- &start_sheet, &end_sheet, &r);
+ if (VALUE_IS_CELLRANGE (v)) {
+ /* actually we only need to cache in that case */
+ Sheet *start_sheet, *end_sheet;
+ GnmRange r;
+ gnm_rangeref_normalize (&v->v_range.cell,
+ eval_pos_init_dep (&ep, &vec->dep),
+ &start_sheet, &end_sheet, &r);
- /* clip here rather than relying on sheet_foreach
- * because that only clips if we ignore blanks */
- if (r.end.row > start_sheet->rows.max_used)
- r.end.row = start_sheet->rows.max_used;
- if (r.end.col > start_sheet->cols.max_used)
- r.end.col = start_sheet->cols.max_used;
+ /* clip here rather than relying on sheet_foreach
+ * because that only clips if we ignore blanks */
+ if (r.end.row > start_sheet->rows.max_used)
+ r.end.row = start_sheet->rows.max_used;
+ if (r.end.col > start_sheet->cols.max_used)
+ r.end.col = start_sheet->cols.max_used;
- if (r.start.col <= r.end.col && r.start.row <= r.end.row)
- sheet_foreach_cell_in_range (start_sheet, CELL_ITER_IGNORE_FILTERED,
- r.start.col, r.start.row, r.end.col, r.end.row,
- (CellIterFunc)cb_assign_string, vec->strs);
+ if (r.start.col <= r.end.col && r.start.row <= r.end.row)
+ sheet_foreach_cell_in_range (start_sheet,
CELL_ITER_IGNORE_FILTERED,
+ r.start.col, r.start.row, r.end.col, r.end.row,
+ (CellIterFunc)cb_assign_string, &closure);
+ }
}
}
if (vec->strs && vec->strs->len > i)
- v = g_ptr_array_index (vec->strs, i);
+ ret = g_ptr_array_index (vec->strs, i);
+ if (ret != NULL)
+ return g_strdup (ret);
} else if (VALUE_IS_CELLRANGE (vec->val)) {
Sheet *start_sheet, *end_sheet;
GnmRange r;
- if (vec->strs == NULL)
- vec->strs = g_ptr_array_new ();
- gnm_rangeref_normalize (&vec->val->v_range.cell,
- eval_pos_init_dep (&ep, &vec->dep),
- &start_sheet, &end_sheet, &r);
+ if (vec->strs == NULL) {
+ struct string_closure closure;
+ closure.strs = vec->strs = g_ptr_array_new_with_free_func (g_free);
+ closure.date_conv = ep.sheet ? workbook_date_conv (ep.sheet->workbook) : NULL;
+ gnm_rangeref_normalize (&vec->val->v_range.cell,
+ eval_pos_init_dep (&ep, &vec->dep),
+ &start_sheet, &end_sheet, &r);
- /* clip here rather than relying on sheet_foreach
- * because that only clips if we ignore blanks */
- if (r.end.row > start_sheet->rows.max_used)
- r.end.row = start_sheet->rows.max_used;
- if (r.end.col > start_sheet->cols.max_used)
- r.end.col = start_sheet->cols.max_used;
+ /* clip here rather than relying on sheet_foreach
+ * because that only clips if we ignore blanks */
+ if (r.end.row > start_sheet->rows.max_used)
+ r.end.row = start_sheet->rows.max_used;
+ if (r.end.col > start_sheet->cols.max_used)
+ r.end.col = start_sheet->cols.max_used;
- if (r.start.col <= r.end.col && r.start.row <= r.end.row)
- sheet_foreach_cell_in_range (start_sheet, CELL_ITER_IGNORE_FILTERED,
- r.start.col, r.start.row, r.end.col, r.end.row,
- (CellIterFunc)cb_assign_string, vec->strs);
+ if (r.start.col <= r.end.col && r.start.row <= r.end.row)
+ sheet_foreach_cell_in_range (start_sheet, CELL_ITER_IGNORE_FILTERED,
+ r.start.col, r.start.row, r.end.col, r.end.row,
+ (CellIterFunc)cb_assign_string, &closure);
+ }
if (vec->strs && vec->strs->len > i)
- v = g_ptr_array_index (vec->strs, i);
+ ret = g_ptr_array_index (vec->strs, i);
+ if (ret != NULL)
+ return g_strdup (ret);
}
if (vec->as_col)
j = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]