# HG changeset patch
# User Pantxo Diribarne <pantxo.diribarne@gmail.com>
# Date 1399233383 -7200
# Node ID e1b6621bd49a934a4edc42969259ba537115c120
# Parent  87fafe6d05d3c14116757a808920477f7bbb3045
Distinguish axes when checking for recursion in axes limits updates (bug #40005)

* graphics.cc: change static variables "updating_aspectratios" and "updating_axis_limits" type to  std::set<double> in order to store all currently updating axes
* graphics.cc (axes::properties::update_aspectratios,  axes::update_axis_limits): update to use the new types and be able to distinguish what axes is being updated 

diff -r 87fafe6d05d3 -r e1b6621bd49a libinterp/corefcn/graphics.cc
--- a/libinterp/corefcn/graphics.cc	Sat May 03 17:28:49 2014 -0700
+++ b/libinterp/corefcn/graphics.cc	Sun May 04 21:56:23 2014 +0200
@@ -5672,12 +5672,13 @@
     s = xmax(s, (limits(1) - limits(0)) / (pbfactor * dafactor));
 }
 
-static bool updating_aspectratios = false;
+static std::set<double> updating_aspectratios;
 
 void
 axes::properties::update_aspectratios (void)
 {
-  if (updating_aspectratios)
+  if (updating_aspectratios.find (get___myhandle__ ().value ()) !=
+      updating_aspectratios.end ())
     return;
 
   Matrix xlimits = get_xlim ().matrix_value ();
@@ -5743,7 +5744,7 @@
           unwind_protect frame;
           frame.protect_var (updating_aspectratios);
 
-          updating_aspectratios = true;
+          updating_aspectratios.insert (get___myhandle__ ().value ());
 
           dx = pba(0) *da(0);
           dy = pba(1) *da(1);
@@ -6691,13 +6692,14 @@
     }
 }
 
-static bool updating_axis_limits = false;
+static std::set<double> updating_axis_limits;
 
 void
 axes::update_axis_limits (const std::string& axis_type,
                           const graphics_handle& h)
 {
-  if (updating_axis_limits)
+  if (updating_axis_limits.find (get_handle ().value ()) != 
+      updating_axis_limits.end ())
     return;
 
   Matrix kids = Matrix (1, 1, h.value ());
@@ -6856,7 +6858,7 @@
   unwind_protect frame;
   frame.protect_var (updating_axis_limits);
 
-  updating_axis_limits = true;
+  updating_axis_limits.insert (get_handle ().value ());
 
   switch (update_type)
     {
@@ -6899,7 +6901,10 @@
 void
 axes::update_axis_limits (const std::string& axis_type)
 {
-  if (updating_axis_limits || updating_aspectratios)
+  if ((updating_axis_limits.find (get_handle ().value ()) != 
+       updating_axis_limits.end ()) ||
+      (updating_aspectratios.find (get_handle ().value ()) !=
+       updating_aspectratios.end ()))
     return;
 
   Matrix kids = xproperties.get_children ();
@@ -7015,7 +7020,7 @@
   unwind_protect frame;
   frame.protect_var (updating_axis_limits);
 
-  updating_axis_limits = true;
+  updating_axis_limits.insert (get_handle ().value ());
 
   switch (update_type)
     {
diff -r 87fafe6d05d3 -r e1b6621bd49a scripts/plot/draw/colorbar.m
--- a/scripts/plot/draw/colorbar.m	Sat May 03 17:28:49 2014 -0700
+++ b/scripts/plot/draw/colorbar.m	Sun May 04 21:56:23 2014 +0200
@@ -310,36 +310,6 @@
       set (hi, "xdata", [cmin, cmax]);
       set (hiax, "xlim", cext);
     endif
-
-    ##########################################################################
-    ## FIXME: Setting xlim or ylim from within a listener callback
-    ##        causes the axis to change size rather than change limits.
-    ##        Workaround it by jiggling the position property which forces
-    ##        a redraw of the axis object.
-    ##
-    ## To see the problem:
-    ## Comment out the 5 lines below the comment box which jiggle position
-    ## 
-    ## Now run the the following code:
-    ##   clear -f
-    ##   clf; contour (peaks ()); colorbar (); 
-    ##   caxis ([0 5]);
-    ## Up to this point everything is fine.
-    ##   caxis ("auto");
-    ## Now colorbar will be badly sized.
-    ##
-    ## The problem line is
-    ##   set (hiax, "ylim", cext) 
-    ##
-    ## The issue seems to be that the axes object is redrawn to the wrong size
-    ## and then is marked as clean so that further internal calls which set the
-    ## correct size do not cause the object to be refreshed.
-    ##########################################################################
-    pos = get (hiax, "position");
-    pos(1) += eps;
-    set (hiax, "position", pos);
-    pos(1) -= eps;
-    set (hiax, "position", pos);
   endif
 endfunction
 
