function out = shiftlims(Editor,MagLims,MagRange,yTravel)
%function [MagLims,MovePtr] = shiftlims(Editor,MagLims,MagRange,yTravel)
%SHIFTLIMS  Shift mag limits to keep magnitude plot in focus while dragging it.

%   Author(s): P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.10 $  $Date: 2000/06/14 20:19:43 $

%RE: MagRange is in dB

HG = Editor.HG;

% Convert mag. limits to dB
MagLimdB = MagLims;
if strcmp(Editor.MagnitudeUnits,'abs')
    MagLimdB(1) = max(MagLimdB(1),eps*MagLimdB(2));
    MagLimdB = 20*log10(MagLimdB);
    ExtraJump = 0;
else
    ExtraJump = 20;
end

% Determine if mag. plot is slipping out of focus
HalfRange = (MagRange(2)-MagRange(1))/2;
MovePtr = (isfinite(HalfRange) & ...
    (MagRange(1)<MagLimdB(1)-min(20,HalfRange) | MagRange(2)>MagLimdB(2)));

if MovePtr
    % Adjust limits
    if yTravel>0 
        % Up
        MagLimdB(1) = 20*floor(MagRange(1)/20);
        MagLimdB(2) = 20*ceil(MagRange(2)/20) + ExtraJump * ceil(yTravel/20);
    else
        % Down
        MagLimdB(1) = 20*floor(MagRange(1)/20) - ExtraJump * ceil(-yTravel/20);
        MagLimdB(2) = 20*ceil(MagRange(2)/20);
    end
    
    % Update limits
    MagLims = unitconv(MagLimdB,'dB',Editor.MagnitudeUnits);
    set(HG.PlotAxes(1),'Ylim',MagLims)
    set(HG.NyquistLine(1,:),'Ydata',MagLims)
end

% REVISIT
out = {MagLims,MovePtr};

