]> git.cworth.org Git - acre/commitdiff
Fix 0.0 value on axis to be 0.0.
authorCarl Worth <cworth@cworth.org>
Thu, 7 Nov 2013 21:19:39 +0000 (13:19 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 7 Nov 2013 21:19:39 +0000 (13:19 -0800)
I recently saw cases where the %g format was cauing a value that
should be 0.0 on the axis to appear as something insane like 5.58e-17.

If the value is within a thousandth of a sub-step, (a sub-step is the
space between two minor ticks on the axis), of 0.0 then force it to be
truly 0.0.

acre.c

diff --git a/acre.c b/acre.c
index f46aebf6441271523aba89dda74d5e8d17e9e5f0..fac0a2053c4796a102c14fc0d91e5129967e60a4 100644 (file)
--- a/acre.c
+++ b/acre.c
@@ -915,10 +915,14 @@ _draw_ticks (acre_t *acre,
        {
            PangoLayout *layout;
            int width, height;
+           double label_value;
 
            cairo_save (cr);
 
-           layout = _create_layout_printf (acre, "%g", t);
+           label_value = t;
+           if (fabs (label_value) < (sub_step / 1000.))
+               label_value = 0.0;
+           layout = _create_layout_printf (acre, "%g", label_value);
 
            if (ticks == ACRE_TICKS_X)
                cairo_move_to (cr, t, acre->y_axis.view_min);