function adjustview(this,Data,Event,NormalRefresh)
%ADJUSTVIEW  Adjusts view prior to and after picking the axes limits. 
%
%  ADJUSTVIEW(VIEW,DATA,'prelim') clips unbounded branches of the locus
%  using the XFocus and YFocus info in DATA before invoking the limit
%  picker.
%
%  ADJUSTVIEW(VIEW,DATA,'postlimit') restores the full branch extent once  
%  the axes limits have been finalized (invoked in response, e.g., to a 
%  'LimitChanged' event).

%  Author(s): P. Gahinet
%  Copyright 1986-2004 The MathWorks, Inc.
%  $Revision: 1.1.6.1 $Date: 2004/12/26 21:53:09 $

switch Event
   case 'prelim'
      % Prepare plot for limit picker
      hsv = Data.HSV;
      nsv = length(hsv);
      if strcmp(this.AxesGrid.YScale,'linear')
         factor = 1.5;
         BaseValue = 0;
      else
         factor = 10;
         BaseValue = 1;
      end

      % Replace zero and infinite hsv 
      isf = find(isfinite(hsv) & hsv>0);
      hsvf = hsv(isf);
      if isempty(hsvf)
         hsvmin = 0.1;
         hsvmax = 10;
      else
         hsvmin = min(hsvf)/factor;
         hsvmax = max(BaseValue,max(hsvf))*factor;
      end
      hsv(isinf(hsv)) = hsvmax;
      hsv(hsv==0) = hsvmin;
      
      set(this.FiniteSV,'Xdata',1:nsv,'YData',hsv,'BaseValue',BaseValue)
      refresh(this.FiniteSV)
      set(this.InfiniteSV,'Xdata',NaN,'YData',NaN,'BaseValue',BaseValue)
      refresh(this.InfiniteSV)

   case 'postlim'
      % Restore branches to their full extent
      draw(this,Data)
end