function xfocus = getfocus(this)
%GETFOCUS  Computes optimal X limits for wave plot 
%          by merging Focus of individual waveforms.

%  Author(s):  
%  Copyright 1986-2002 The MathWorks, Inc.
%  $Revision: 1.1.6.1 $ $Date: 2004/12/26 21:40:20 $

% Collect time Focus for all visible MIMO responses
xfocus = [];
for rct = allwaves(this)'
  % For each visible response...
  if rct.isvisible
    thisfocus = {unitconv(get(rct.Data,'Focus'),rct.Data.FreqUnits,...
        this.axesgrid.xunits)};
    xfocus = [xfocus; thisfocus];
  end
end

% Merge into single focus
xfocus = LocalMergeFocus(xfocus);

% Round it up
% REVISIT: should depend on units.
% Return something reasonable if empty.
if isempty(xfocus)
  xfocus = [0 1];
else
  xfocus(2) = tchop(xfocus(2));
end


% ----------------------------------------------------------------------------%
% Purpose: Merge all ranges
% ----------------------------------------------------------------------------%
function focus = LocalMergeFocus(Ranges)
% Take the union of a list of ranges
focus = zeros(0,2);
for ct = 1:length(Ranges)
  focus = [focus ; Ranges{ct}];
  focus = [min(focus(:,1)) , max(focus(:,2))];
end
