changeset 18761:868dcab453bd

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.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Sun, 04 May 2014 21:56:23 +0200
parents 5baada25d5a2
children d1750be79dee
files libinterp/corefcn/graphics.cc scripts/plot/draw/colorbar.m
diffstat 2 files changed, 13 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Sun May 04 16:23:47 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)
     {
--- a/scripts/plot/draw/colorbar.m	Sun May 04 16:23:47 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