[goffice] Axis: avoid excess precision.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Axis: avoid excess precision.
- Date: Sun, 6 May 2018 17:06:41 +0000 (UTC)
commit 76224633ef4cf6e9e64d68161fecba3645280c66
Author: Morten Welinder <terra gnome org>
Date: Sun May 6 13:05:35 2018 -0400
Axis: avoid excess precision.
See 789076 for a sample file. Bug is not otherwise related.
ChangeLog | 7 ++++++
NEWS | 3 ++
goffice/graph/gog-axis.c | 50 +++++++++++++++++++--------------------------
3 files changed, 31 insertions(+), 29 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 14bfe40..453173d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-06 Morten Welinder <terra gnome org>
+
+ * goffice/graph/gog-axis.c (axis_format_value): When using General
+ format, limit precision to 9-10 digits. If you need more, use a
+ specific format, but you are probably doing something wrong
+ anyway. This avoids graph ticks of the form "1.10000000000002".
+
2018-04-29 Morten Welinder <terra gnome org>
* configure.ac: Post-release bump.
diff --git a/NEWS b/NEWS
index fd0f902..531bce8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
goffice 0.10.41:
+Morten:
+ * Avoid excess precision of graph ticks.
+
--------------------------------------------------------------------------
goffice 0.10.40:
diff --git a/goffice/graph/gog-axis.c b/goffice/graph/gog-axis.c
index 2439a52..88ab897 100644
--- a/goffice/graph/gog-axis.c
+++ b/goffice/graph/gog-axis.c
@@ -270,6 +270,7 @@ axis_format_value (GogAxis *axis, double val, GOString **str,
const GODateConventions *date_conv = axis->date_conv;
GOFormatNumberError err;
PangoLayout *layout = gog_get_layout ();
+ int chars;
g_return_if_fail (layout != NULL);
@@ -283,13 +284,18 @@ axis_format_value (GogAxis *axis, double val, GOString **str,
val = 0 - val;
}
+ // If no format is explicitly set, avoid using excess precision
+ chars = !fmt || go_format_is_general (fmt)
+ ? 10 + (val < 0)
+ : -1;
+
err = go_format_value_gstring
(layout, NULL,
go_format_measure_strlen,
go_font_metrics_unit,
fmt,
val, 'F', NULL, NULL,
- -1, date_conv, TRUE);
+ chars, date_conv, TRUE);
if (err)
*str = go_string_new ("#####");
else {
@@ -1867,14 +1873,12 @@ gog_axis_map_get_baseline (GogAxisMap *map)
/**
* gog_axis_map_get_extents:
* @map: a #GogAxisMap
- * @start: location to store start for this axis
- * @stop: location to store stop for this axis
+ * @start: (out) (optional): location to store start for this axis
+ * @stop: (out) (optional): location to store stop for this axis
*
* Gets start and stop for the whole chart relative to the given axis map
* in data coordinates. If axis is not inverted, start = minimum and
* stop = maximum. If axis is invalid, it'll return arbitrary bounds.
- *
- * Any of @start and @stop may be NULL.
**/
void
@@ -1910,14 +1914,12 @@ gog_axis_map_get_extents (GogAxisMap *map, double *start, double *stop)
/**
* gog_axis_map_get_real_extents:
* @map: a #GogAxisMap
- * @start: location to store start for this axis
- * @stop: location to store stop for this axis
+ * @start: (out) (optional): location to store start for this axis
+ * @stop: (out) (optional): location to store stop for this axis
*
* Gets start and stop for the given axis map in data coordinates. If
- * axis is not inverted, start = minimum and stop = maximum. If axis is invalid,
- * it'll return arbitrary bounds.
- *
- * Any of @start and @stop may be NULL.
+ * axis is not inverted, start = minimum and stop = maximum. If axis is
+ * invalid, it'll return arbitrary bounds.
**/
void
@@ -1939,15 +1941,12 @@ gog_axis_map_get_real_extents (GogAxisMap *map, double *start, double *stop)
/**
* gog_axis_map_get_bounds:
* @map: a #GogAxisMap
- * @minimum: location to store minimum for this axis
- * @maximum: location to store maximum for this axis
+ * @minimum: (out) (optional): location to store minimum for this axis
+ * @maximum: (out) (optional): location to store maximum for this axis
*
* Gets bounds for the whole chart relative to the given axis map in data
* coordinates. If axis is invalid, it'll return arbitrary bounds.
- *
- * Any of @minimum and @maximum may be NULL.
**/
-
void
gog_axis_map_get_bounds (GogAxisMap *map, double *minimum, double *maximum)
{
@@ -1981,15 +1980,12 @@ gog_axis_map_get_bounds (GogAxisMap *map, double *minimum, double *maximum)
/**
* gog_axis_map_get_real_bounds:
* @map: a #GogAxisMap
- * @minimum: location to store minimum for this axis
- * @maximum: location to store maximum for this axis
+ * @minimum: (out) (optional): location to store minimum for this axis
+ * @maximum: (out) (optional): location to store maximum for this axis
*
* Gets bounds for the given axis map in data coordinates. If axis is invalid,
* it'll return arbitrary bounds.
- *
- * Any of @minimum and @maximum may be NULL.
**/
-
void
gog_axis_map_get_real_bounds (GogAxisMap *map, double *minimum, double *maximum)
{
@@ -2036,11 +2032,10 @@ gog_axis_map_is_discrete (GogAxisMap *map)
/**
* gog_axis_map_free:
- * @map: a #GogAxisMap
+ * @map: (transfer full): a #GogAxisMap
*
* Frees #GogAxisMap object.
**/
-
void
gog_axis_map_free (GogAxisMap *map)
{
@@ -2201,11 +2196,9 @@ role_axis_line_post_add (GogObject *parent, GogObject *child)
/**
* gog_axis_set_format:
* @axis: #GogAxis
- * @fmt: (transfer full): #GOFormat
- *
- * Absorbs a reference to @fmt, and accepts NULL.
+ * @fmt: (transfer full) (nullable): #GOFormat
*
- * Returns: TRUE if things changed
+ * Returns: %TRUE if things changed
**/
gboolean
gog_axis_set_format (GogAxis *axis, GOFormat *fmt)
@@ -2230,8 +2223,7 @@ gog_axis_set_format (GogAxis *axis, GOFormat *fmt)
* gog_axis_get_format:
* @axis: #GogAxis
*
- * Returns: (transfer none): the format assigned to @axis but does not add
- * a reference.
+ * Returns: (transfer none): the format assigned to @axis.
**/
GOFormat *
gog_axis_get_format (GogAxis const *axis)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]