[goffice] Axis: use problem date_conv and unicode minuses.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [goffice] Axis: use problem date_conv and unicode minuses.
- Date: Sun, 18 Oct 2009 19:54:29 +0000 (UTC)
commit 510c3386861ce4a976b0130de8bb21c3541aeda8
Author: Morten Welinder <terra gnome org>
Date: Sun Oct 18 15:54:10 2009 -0400
Axis: use problem date_conv and unicode minuses.
ChangeLog | 4 ++++
goffice/canvas/goc-graph.c | 8 ++++----
goffice/graph/gog-axis.c | 39 ++++++++++++++++++++++++++++++++-------
goffice/graph/gog-axis.h | 2 ++
4 files changed, 42 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5135bf4..7ff4652 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2009-10-18 Morten Welinder <terra gnome org>
+ * goffice/graph/gog-axis.c (gog_axis_get_effective_format): Rename
+ from get_axis_format and make public.
+ (axis_format_value): Use unicode minuses and proper date_conv.
+
* goffice/canvas/goc-graph.c (goc_graph_do_tooltip): Extract from
goc_graph_motion for clarity. Free the right string! Use
format_coordinate, not g_strdup_printf.
diff --git a/goffice/canvas/goc-graph.c b/goffice/canvas/goc-graph.c
index 0151fcc..41372db 100644
--- a/goffice/canvas/goc-graph.c
+++ b/goffice/canvas/goc-graph.c
@@ -222,8 +222,8 @@ static char *
format_coordinate (GogAxis *axis, GOFormat *fmt, double x)
{
GString *res = g_string_sized_new (20);
- int width = fmt ? -1 : 8; /* FIXME? */
- const GODateConventions *date_conv = NULL; /* FIXME: get from axis */
+ int width = (fmt && !go_format_is_general (fmt)) ? -1 : 8; /* FIXME? */
+ const GODateConventions *date_conv = gog_axis_get_date_conv (axis);
GOFormatNumberError err = go_format_value_gstring
(NULL, res,
go_format_measure_strlen,
@@ -314,7 +314,7 @@ goc_graph_do_tooltip (GocGraph *graph, double x, double y)
s1 = format_coordinate (x_axis, NULL, x);
}
} else {
- format = gog_axis_get_format (x_axis);
+ format = gog_axis_get_effective_format (x_axis);
s1 = format_coordinate (x_axis, format, x);
}
if (gog_axis_is_discrete (y_axis)) {
@@ -326,7 +326,7 @@ goc_graph_do_tooltip (GocGraph *graph, double x, double y)
s2 = format_coordinate (y_axis, NULL, y);
}
} else {
- format = gog_axis_get_format (y_axis);
+ format = gog_axis_get_effective_format (y_axis);
s2 = format_coordinate (y_axis, format, y);
}
buf = g_strdup_printf ("(%s,%s)", s1, s2);
diff --git a/goffice/graph/gog-axis.c b/goffice/graph/gog-axis.c
index e96207a..2245554 100644
--- a/goffice/graph/gog-axis.c
+++ b/goffice/graph/gog-axis.c
@@ -110,9 +110,19 @@ create_invalid_axis_ticks (double min, double max)
return ticks;
}
-static GOFormat *
-get_axis_format (GogAxis const *axis)
+const GODateConventions *
+gog_axis_get_date_conv (GogAxis const *axis)
{
+ g_return_val_if_fail (GOG_IS_AXIS (axis), NULL);
+
+ return axis->date_conv;
+}
+
+GOFormat *
+gog_axis_get_effective_format (GogAxis const *axis)
+{
+ g_return_val_if_fail (GOG_IS_AXIS (axis), NULL);
+
if (axis->assigned_format &&
!go_format_is_general (axis->assigned_format))
return axis->assigned_format;
@@ -122,8 +132,23 @@ get_axis_format (GogAxis const *axis)
static char *
axis_format_value (GogAxis *axis, double val)
{
- /* FIXME: Date convention. */
- return go_format_value (get_axis_format (axis), val);
+ GOFormat *fmt = gog_axis_get_effective_format (axis);
+ GString *res = g_string_sized_new (20);
+ const GODateConventions *date_conv = axis->date_conv;
+ GOFormatNumberError err = go_format_value_gstring
+ (NULL, res,
+ go_format_measure_strlen,
+ go_font_metrics_unit,
+ fmt,
+ val, 'F', NULL,
+ NULL,
+ -1, date_conv, TRUE);
+ if (err) {
+ /* Invalid number for format. */
+ g_string_assign (res, "#####");
+ }
+
+ return g_string_free (res, FALSE);
}
static gboolean
@@ -429,7 +454,7 @@ map_time_auto_bound (GogAxis *axis, double minimum, double maximum, double *boun
{
enum { U_Second, U_Minute, U_Hour, U_Day } u;
static const double invunits[4] = { 24* 60 * 60, 24 * 60, 24, 1 };
- GOFormat *fmt = get_axis_format (axis);
+ GOFormat *fmt = gog_axis_get_effective_format (axis);
int is_time = go_format_is_time (fmt);
double range = fabs (maximum - minimum);
double iu, step;
@@ -934,7 +959,7 @@ map_linear_subclass (GogAxis *axis, const GogAxisMapDesc *desc)
return &map_desc_polar;
}
- fmt = get_axis_format (axis);
+ fmt = gog_axis_get_effective_format (axis);
if (fmt && go_format_is_time (fmt) > 0) {
static GogAxisMapDesc map_desc_time;
@@ -2368,7 +2393,7 @@ gog_axis_populate_editor (GogObject *gobj,
/* Format page */
if (!axis->is_discrete) {
- GOFormat *fmt = get_axis_format (axis);
+ GOFormat *fmt = gog_axis_get_effective_format (axis);
w = go_format_sel_new_full (TRUE);
state->format_selector = w;
diff --git a/goffice/graph/gog-axis.h b/goffice/graph/gog-axis.h
index 2cf91b3..75c5b6e 100644
--- a/goffice/graph/gog-axis.h
+++ b/goffice/graph/gog-axis.h
@@ -82,7 +82,9 @@ void gog_axis_set_bounds (GogAxis *axis,
double minimum, double maximum);
void gog_axis_set_extents (GogAxis *axis, double start, double stop);
GOFormat *gog_axis_get_format (GogAxis const *axis);
+GOFormat *gog_axis_get_effective_format (GogAxis const *axis);
gboolean gog_axis_set_format (GogAxis *axis, GOFormat *fmt);
+const GODateConventions *gog_axis_get_date_conv (GogAxis const *axis);
unsigned gog_axis_get_ticks (GogAxis *axis, GogAxisTick **ticks);
GOData *gog_axis_get_labels (GogAxis const *axis,
GogPlot **plot_that_labeled_axis);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]