[goffice] GogAxisBase: new function for finding crossing axis.



commit a8dc51ed30a8c827429ed7aea73028b33d7d5bc6
Author: Morten Welinder <terra gnome org>
Date:   Tue Feb 24 14:08:34 2015 -0500

    GogAxisBase: new function for finding crossing axis.

 ChangeLog                     |    7 +++++++
 goffice/graph/gog-axis-line.c |   33 ++++++++++++++++++++++++++-------
 goffice/graph/gog-axis-line.h |    2 ++
 3 files changed, 35 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2149586..f11ecd2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-02-24  Morten Welinder  <terra gnome org>
+
+       * goffice/graph/gog-axis-line.c
+       (gog_axis_base_get_crossed_axis_type): Make this public.
+       (gog_axis_base_get_crossed_axis_for_plot): New function -- when we
+       know the plot we can pick the desired axis.
+
 2015-02-20  Morten Welinder  <terra gnome org>
 
        * goffice/gtk/go-pattern-selector.c (go_pattern_tooltip_func): New
diff --git a/goffice/graph/gog-axis-line.c b/goffice/graph/gog-axis-line.c
index d770dfa..405d996 100644
--- a/goffice/graph/gog-axis-line.c
+++ b/goffice/graph/gog-axis-line.c
@@ -259,7 +259,7 @@ gog_axis_base_finalize (GObject *obj)
        (gab_parent_klass->finalize) (obj);
 }
 
-static GogAxisType
+GogAxisType
 gog_axis_base_get_crossed_axis_type (GogAxisBase *axis_base)
 {
        GogAxisType axis_type, crossed_type;
@@ -299,6 +299,26 @@ gog_axis_base_get_crossed_axis_type (GogAxisBase *axis_base)
 }
 
 /**
+ * gog_axis_base_get_crossed_axis_for_plot:
+ * @axis_base: #GogAxisBase
+ * @plot: #GogPlot
+ *
+ * Returns: (transfer none): returns the crossing axis in a 2D plot if set.
+ **/
+GogAxis *
+gog_axis_base_get_crossed_axis_for_plot (GogAxisBase *axis_base, GogPlot *plot)
+{
+       GogAxisType cross_axis_type;
+
+       g_return_val_if_fail (GOG_IS_AXIS_BASE (axis_base), NULL);
+       g_return_val_if_fail (GOG_IS_PLOT (plot), NULL);
+
+       cross_axis_type = gog_axis_base_get_crossed_axis_type (axis_base);
+       return gog_plot_get_axis (plot, cross_axis_type);
+}
+
+
+/**
  * gog_axis_base_get_crossed_axis:
  * @axis_base: #GogAxisBase
  *
@@ -310,17 +330,16 @@ gog_axis_base_get_crossed_axis (GogAxisBase *axis_base)
        GogAxis *crossed_axis = NULL;
        GSList *axes, *ptr;
        gboolean found = FALSE;
-       GogAxisType axis_type = gog_axis_base_get_crossed_axis_type (axis_base);
+       GogAxisType cross_axis_type = gog_axis_base_get_crossed_axis_type (axis_base);
 
-       if (axis_type == GOG_AXIS_UNKNOWN)
+       if (cross_axis_type == GOG_AXIS_UNKNOWN)
                return NULL;
-       axes = gog_chart_get_axes (axis_base->chart, axis_type);
+       axes = gog_chart_get_axes (axis_base->chart, cross_axis_type);
        g_return_val_if_fail (axes != NULL, NULL);
 
-       for (ptr = axes; ptr != NULL && !found; ptr = ptr->next) {
+       for (ptr = axes; !found && ptr; ptr = ptr->next) {
                crossed_axis = GOG_AXIS (ptr->data);
-               if (gog_object_get_id (GOG_OBJECT (crossed_axis)) == axis_base->crossed_axis_id)
-                       found = TRUE;
+               found = (gog_object_get_id (GOG_OBJECT (crossed_axis)) == axis_base->crossed_axis_id);
        }
 
        if (!found)
diff --git a/goffice/graph/gog-axis-line.h b/goffice/graph/gog-axis-line.h
index d9faf2b..d0fe544 100644
--- a/goffice/graph/gog-axis-line.h
+++ b/goffice/graph/gog-axis-line.h
@@ -32,7 +32,9 @@ G_BEGIN_DECLS
 
 GType gog_axis_base_get_type (void);
 
+GogAxisType gog_axis_base_get_crossed_axis_type (GogAxisBase *axis_base);
 GogAxis *gog_axis_base_get_crossed_axis (GogAxisBase *axis_base);
+GogAxis *gog_axis_base_get_crossed_axis_for_plot (GogAxisBase *axis_base, GogPlot *plot);
 double gog_axis_base_get_cross_location (GogAxisBase *axis_base);
 
 typedef enum {


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