[goffice] GogAxis: better handling of bounds for log axis.



commit 0653764c8c44828a60012882d6e39b4867a88fae
Author: Morten Welinder <terra gnome org>
Date:   Thu Mar 12 20:43:56 2015 -0400

    GogAxis: better handling of bounds for log axis.

 ChangeLog                |    8 ++++++++
 NEWS                     |    3 +++
 goffice/graph/gog-axis.c |   30 ++++++++++++++++++++++++++++++
 goffice/graph/gog-axis.h |    2 ++
 plugins/plot_xy/gog-xy.c |    6 ++++--
 5 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 79405ae..6be140a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2015-03-12  Morten Welinder  <terra gnome org>
+
+       * goffice/graph/gog-axis.c (gog_axis_data_get_bounds): New
+       function.
+
+       * plugins/plot_xy/gog-xy.c (gog_2d_plot_update): Use
+       gog_axis_data_get_bounds.
+
 2015-03-10  Jean Brefort  <jean brefort normalesup org>
 
        * plugins/plot_surface/gog-matrix.c (gog_matrix_view_render): fix rendering
diff --git a/NEWS b/NEWS
index fe943a5..0f45bc3 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@ goffice 0.10.22:
 Johannes Deutsch:
        * Do not draw the line over the arrow head at start. [#745736]
 
+Morten:
+       * Improve log axis bounds.
+
 --------------------------------------------------------------------------
 goffice 0.10.21:
 
diff --git a/goffice/graph/gog-axis.c b/goffice/graph/gog-axis.c
index fe5f1b5..c24e3dc 100644
--- a/goffice/graph/gog-axis.c
+++ b/goffice/graph/gog-axis.c
@@ -3853,6 +3853,36 @@ gog_axis_bound_changed (GogAxis *axis, GogObject *contrib)
        gog_object_request_update (GOG_OBJECT (axis));
 }
 
+/*
+ * gog_axis_data_get_bounds:
+ * @axis: (allow-none): the axis for which the data applies
+ * @data: the data to get bounds for
+ * @minimum: smallest valid data value.
+ * @maximum: largest valid data value.
+ */
+void
+gog_axis_data_get_bounds (GogAxis *axis, GOData *data,
+                         double *minimum, double *maximum)
+{
+       gboolean (*map_finite) (double value) =
+               axis ? axis->actual_map_desc->map_finite : go_finite;
+
+       if (map_finite != go_finite) {
+               size_t i, n = go_data_get_n_values (data);
+               const double *values = go_data_get_values (data);
+               *minimum = go_pinf;
+               *maximum = go_ninf;
+               for (i = 0; i < n; i++) {
+                       double x = values[i];
+                       if (!map_finite (x))
+                               continue;
+                       *minimum = MIN (*minimum, x);
+                       *maximum = MAX (*maximum, x);
+               }
+       } else
+               go_data_get_bounds (data, minimum, maximum);
+}
+
 /**
  * gog_axis_get_grid_line:
  * @axis: #GogAxis
diff --git a/goffice/graph/gog-axis.h b/goffice/graph/gog-axis.h
index d58e603..20752e2 100644
--- a/goffice/graph/gog-axis.h
+++ b/goffice/graph/gog-axis.h
@@ -106,6 +106,8 @@ GSList const *gog_axis_contributors   (GogAxis *axis);
 void         gog_axis_clear_contributors (GogAxis *axis);
 void         gog_axis_bound_changed      (GogAxis *axis, GogObject *contrib);
 
+void          gog_axis_data_get_bounds    (GogAxis *axis, GOData *data, double *minimum, double *maximum);
+
 GogGridLine  *gog_axis_get_grid_line     (GogAxis *axis, gboolean major);
 
 void                   gog_axis_set_polar_unit         (GogAxis *axis, GogAxisPolarUnit unit);
diff --git a/plugins/plot_xy/gog-xy.c b/plugins/plot_xy/gog-xy.c
index 6d01de1..50dd0a5 100644
--- a/plugins/plot_xy/gog-xy.c
+++ b/plugins/plot_xy/gog-xy.c
@@ -73,6 +73,8 @@ gog_2d_plot_update (GogObject *obj)
        GogXYSeries const *series = NULL;
        double x_min, x_max, y_min, y_max, tmp_min, tmp_max;
        GSList *ptr;
+       GogAxis *x_axis = gog_plot_get_axis (GOG_PLOT (model), GOG_AXIS_X);
+       GogAxis *y_axis = gog_plot_get_axis (GOG_PLOT (model), GOG_AXIS_Y);
 
        x_min = y_min =  DBL_MAX;
        x_max = y_max = -DBL_MAX;
@@ -82,7 +84,7 @@ gog_2d_plot_update (GogObject *obj)
                if (!gog_series_is_valid (GOG_SERIES (series)))
                        continue;
 
-               go_data_get_bounds (series->base.values[1].data, &tmp_min, &tmp_max);
+               gog_axis_data_get_bounds (y_axis, series->base.values[1].data, &tmp_min, &tmp_max);
                if (y_min > tmp_min) y_min = tmp_min;
                if (y_max < tmp_max) y_max = tmp_max;
                if (model->y.fmt == NULL)
@@ -90,7 +92,7 @@ gog_2d_plot_update (GogObject *obj)
                model->y.date_conv = go_data_date_conv (series->base.values[1].data);
 
                if (series->base.values[0].data != NULL) {
-                       go_data_get_bounds (series->base.values[0].data, &tmp_min, &tmp_max);
+                       gog_axis_data_get_bounds (x_axis, series->base.values[0].data, &tmp_min, &tmp_max);
 
                        if (!go_finite (tmp_min) || !go_finite (tmp_max) ||
                            tmp_min > tmp_max) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]