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): Bora Eryilmaz
%  Copyright 1986-2004 The MathWorks, Inc.
%  $Revision: 1.1.6.3 $ $Date: 2004/12/26 21:53:20 $

AxGrid = this.AxesGrid;

% Sizes and unit conversions
[Ny, Nu] = size(this.Curves);
Mag   = unitconv(Data.Magnitude, Data.MagUnits,   'dB');
Phase = unitconv(Data.Phase,     Data.PhaseUnits, AxGrid.XUnits);

if strcmp(this.UnwrapPhase, 'off')
  Pi = unitconv(pi, 'rad', AxGrid.XUnits);
  Phase = mod(Phase+Pi,2*Pi) - Pi;
end

% Phase Matching
doComparePhase = strcmp(this.ComparePhase.Enable, 'on');
if doComparePhase
    ax = AxGrid.getaxes; % Revisit
    h = gcr(ax(1));
    Freq = unitconv(Data.Frequency,Data.FreqUnits,h.FrequencyUnits);
    idx = min(find(Freq>this.ComparePhase.Freq));
    if isempty(idx)
        idx = 1;
    end
    Pi = unitconv(pi,'rad',AxGrid.XUnits);
end


% Redraw curves
for ct = 1:Ny*Nu
    % REVISIT: remove conversion to double (UDD bug where XOR mode ignored)
    if ~isempty(Mag)
        % Phase Matching
        if doComparePhase
            n = round(abs(Phase(idx,ct)-this.ComparePhase.Phase)/(2*Pi));
            Phase(:,ct) = Phase(:,ct)-sign(Phase(idx,ct)-this.ComparePhase.Phase)*n*2*Pi;
        end
        set(double(this.Curves(ct)), 'XData', Phase(:,ct), 'YData', Mag(:,ct));
    else
        set(double(this.Curves(ct)), 'XData', [], 'YData', []);
    end
end
