function draw(this, Data, NormalRefresh)
%DRAW  Draws Bode response curves.
%
%  DRAW(VIEW,DATA) maps the response data in DATA to the curves in VIEW.

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

AxGrid = this.AxesGrid;

%% Input and output sizes
[Ny, Nu] = size(this.Curves);
Freq = unitconv(Data.Frequency,Data.FreqUnits,AxGrid.XUnits);
Spec = Data.Response;

%% Eliminate zero frequencies in log scale
if strcmp(AxGrid.Xscale{1},'log')
  idxf = find(Freq>0);
  Freq = Freq(idxf);
  if ~isempty(Spec)
     Spec = Spec(idxf,:);
  end
end

%% Spec curves
for ct = 1:Ny*Nu
   % REVISIT: remove conversion to double (UDD bug where XOR mode ignored)
   set(double(this.Curves(ct)), 'XData', Freq, ...
       'YData', Spec(:,ct));
end

%% Get the parent axes (note all curves must lie in the same axes)
ax = get(this.Curves(1),'Parent');

%% Draw time selection rectangles. Each SelectionPatch need only be
%% drawn once in each axes since they all occur at the same times. Need to
%% detect this and avoid drawing overlapping rectangles. Also avoids xor
%% mode toggling the visibility of overlapping patches
ax = cell2mat(get(this.SelectionPatch,{'Parent'}));
[junk,I] = unique(ax);
for k=1:length(I)
    if length(this.SelectedInterval)>0
        ylim = get(get(this.SelectionPatch(I(k)),'Parent'),'yLim');
        xdata = [this.SelectedInterval this.SelectedInterval(:,end:-1:1)]';
        ydata = [ylim(1); ylim(1);ylim(2);ylim(2)]*ones(1,length(this.SelectedInterval));
        zdata = [-10;-10;-10;-10]*ones(1,length(this.SelectedInterval));
        set(this.SelectionPatch(I(k)),...
          'Zdata',zdata,...
          'Xdata',xdata,...
          'Ydata',ydata,...
          'LineStyle','none',...
          'HandleVisibility','off','HitTest','on');
    else
         set(this.SelectionPatch(I(k)),...
          'Zdata',[NaN;NaN;NaN;NaN],...
          'Xdata',[NaN;NaN;NaN;NaN],...
          'Ydata',[NaN;NaN;NaN;NaN],...
          'LineStyle','none',...
          'HandleVisibility','off','HitTest','on');
    end
end
nullind = setdiff(1:length(ax),I);
for k=1:length(nullind)
          set(this.SelectionPatch(nullind(k)),...
          'Zdata',[NaN;NaN;NaN;NaN],...
          'Xdata',[NaN;NaN;NaN;NaN],...
          'Ydata',[NaN;NaN;NaN;NaN],...
          'LineStyle','none',...
          'HandleVisibility','on','HitTest','on');
end
