Home > classes > @history > plot.m

plot

PURPOSE ^

PLOT plots a history object as a tree diagram.

SYNOPSIS ^

function varargout = plot(varargin)

DESCRIPTION ^

 PLOT plots a history object as a tree diagram.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: PLOT plots a history object as a tree diagram.

 NOTE:        Some of the code below is taken from Mathworks's treeplot.m

 CALL:        plot (history)
              plot (history, arg)
              plot (axes_handle, ...)

 M-FILE INFO: Get information about this methods by calling
              >> history.getInfo('plot')

              Get information about a specified set-plist by calling:
              >> history.getInfo('plot', 'set')

 VERSION:     $Id: plot.m,v 1.27 2008/09/05 14:17:01 hewitson Exp $

 HISTORY:     02-02-07 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % PLOT plots a history object as a tree diagram.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: PLOT plots a history object as a tree diagram.
0005 %
0006 % NOTE:        Some of the code below is taken from Mathworks's treeplot.m
0007 %
0008 % CALL:        plot (history)
0009 %              plot (history, arg)
0010 %              plot (axes_handle, ...)
0011 %
0012 % M-FILE INFO: Get information about this methods by calling
0013 %              >> history.getInfo('plot')
0014 %
0015 %              Get information about a specified set-plist by calling:
0016 %              >> history.getInfo('plot', 'set')
0017 %
0018 % VERSION:     $Id: plot.m,v 1.27 2008/09/05 14:17:01 hewitson Exp $
0019 %
0020 % HISTORY:     02-02-07 M Hewitson
0021 %                 Creation
0022 %
0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 
0025 function varargout = plot(varargin)
0026   
0027 
0028   %%% Check if this is a call for parameters
0029   if utils.helper.isinfocall(varargin{:})
0030     varargout{1} = getInfo(varargin{3});
0031     return
0032   end
0033 
0034   import utils.const.*
0035   utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
0036   
0037   %%% Used call: plot (history, arg)
0038   if isa(varargin{1}, 'history')
0039 
0040     figure;
0041     hists = varargin{1};
0042     curr_axes = axes;
0043     if nargin >= 2
0044       varargin = varargin(2:end);
0045     else
0046       varargin = {};
0047     end
0048 
0049     %%% Used call: plot (curr_axes_handle, history, arg)
0050   elseif ishandle(varargin{1})
0051 
0052     curr_axes = varargin{1};
0053     axes(curr_axes);
0054     hists = varargin{2};
0055     if nargin >= 3
0056       varargin = varargin(3:end);
0057     else
0058       varargin = {};
0059     end
0060 
0061   else
0062     error (['### the first input should be a history object or an axes handle' ...
0063       sprintf(' varargin{1} = [%s]',varargin{1})]);
0064   end
0065 
0066   %%% collect the parameter and put them into the parameter list
0067   plot_args = {};
0068   pl        = plist();
0069   args      = varargin;
0070 
0071   while ~isempty(args)
0072 
0073     if isa(args{1}, 'plist')
0074       arg  = args{1};
0075       pl   = append(pl, arg);
0076       args = args(2:end);
0077 
0078       % Add the key-values to the parameter list
0079     elseif length(args) >= 2
0080       if  ischar(args{1})
0081         arg = args{1};
0082         val = args{2};
0083         pl  = append(pl, param(arg, val));
0084 
0085         plot_args{end+1} = arg;
0086         plot_args{end+1} = val;
0087         args = args(3:end);
0088 
0089       else
0090         error('### the key [%s] is not from the type ''char''', char(args{1}));
0091       end
0092     else
0093       help(mfilename('fullpath'))
0094       error('### There is no key/value pair left.');
0095     end
0096 
0097   end
0098 
0099   %%% Comes the call from the browser or from the command window
0100   max_depth = find(pl, 'max_depth');
0101 
0102   %%% Output handles for figures and axes
0103   hfig = [];
0104   ax   = [];
0105   at   = [];
0106 
0107   nhists = length(hists);
0108   for i=1:nhists
0109 
0110     hist = hists(i);
0111     % disp(sprintf('--- plotting history %s', hist.name));
0112 
0113     % convert history object to a node list
0114     if ~isempty(max_depth)
0115       [n,a, nodes] = getNodes_plot(hist, [], 0, 1, [], 0, max_depth);
0116     else
0117       [n,a, nodes] = getNodes(hist, [], 0, 1, []);
0118     end
0119     p = [nodes(:).pn];
0120     [x,y,h]=treelayout(p);
0121     f = find(p~=0);
0122     pp = p(f);
0123     X = [x(f); x(pp); repmat(NaN,size(f))];
0124     Y = [y(f); y(pp); repmat(NaN,size(f))];
0125     X = X(:);
0126     Y = Y(:);
0127 
0128     % figure
0129     hfig = [hfig gcf];
0130 
0131     % axes objects
0132     a = plot (curr_axes, X, Y, 'r--', x, y, 'ro');
0133     % plot (X,Y) --> die linien
0134     if length(a)>1
0135       set(a(2), 'MarkerFaceColor', 'r');
0136       set(a(2), 'MarkerSize', 8);
0137     end
0138     args  = plot_args;
0139     while ~isempty(args)
0140       prop = args{1};
0141       val  = args{2};
0142       args = args(3:end);
0143       for ii = 1:length(a)
0144         set(a(ii), prop, val);
0145       end
0146     end
0147     ax = [ax a];
0148 
0149     % text objects
0150     a    = [];
0151     for j=1:length(x)
0152       % node description
0153       fcnname = getFcnName(nodes(j).names);
0154       str = ['{\bf\color{blue}' num2str(nodes(j).n) ':}{\bf\color{red}' fcnname '} ' char(nodes(j).params)];
0155       nlstr = getNodeInputs(nodes(j).invars);
0156 
0157       na  = text(x(j), y(j),...
0158         [utils.prog.wrapstring(strrep(str,'_', '\_'),getappdata(0, 'wrapstringat')) ...
0159         cellstr(['{\color{magenta} ' strrep(nlstr,'_', '\_') '}'])]);
0160       set(na, 'HorizontalAlignment', 'center');
0161       set(na, 'EdgeColor', 'k', 'Fontsize', 10);
0162       set(na, 'BackgroundColor', 'w');
0163       set(na, 'Margin', 5);
0164       a   = [a na];
0165     end
0166     at = [at a];
0167 
0168     % xlabel(['height = ' int2str(h)]);
0169     axis([0 1 0 1]);
0170     box off;
0171     axis off;
0172 
0173   end
0174 
0175   % Make outputs
0176   if nargout > 0
0177     varargout{1} = hfig;
0178   end
0179   if nargout > 1
0180     varargout{2} = ax;
0181   end
0182   if nargout > 2
0183     varargout{3} = at;
0184   end
0185 end
0186 
0187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0188 %                               Local Functions                               %
0189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0190 
0191 %--------------------------------------------------------------------------
0192 % compute strings to display for function name
0193 function fcnname = getFcnName(name)
0194 
0195 %   switch name
0196 %     case 'mtimes'
0197 %       fcnname = 'x';
0198 %     case 'times'
0199 %       fcnname = 'x';
0200 %     case 'plus'
0201 %       fcnname = '+';
0202 %     case 'minus'
0203 %       fcnname = '-';
0204 % %     case 'sqrt'
0205 % %       fcnname = '\surd';
0206 %     case 'mrdivide'
0207 %       fcnname = '/';
0208 %     case 'rdivide'
0209 %       fcnname = '/';
0210 %     otherwise
0211 %       fcnname = char(name);
0212 %   end
0213 
0214 fcnname = char(name);
0215 end
0216 
0217 %--------------------------------------------------------------------------
0218 % compute strings to display for inputs to nodes
0219 function    str = getNodeInputs(invars)
0220 
0221   ni = length(invars);
0222   if ni > 0
0223     str = char(invars{1});
0224     for iv=2:ni
0225       s = char(invars{iv});
0226       if ~strcmp(s, 'pl')
0227         str = [str '  ' s];
0228       end
0229     end
0230   else
0231     str = '';
0232   end
0233 end
0234 
0235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0236 %
0237 % FUNCTION:    getInfo
0238 %
0239 % DESCRIPTION: Get Info Object
0240 %
0241 % HISTORY:     11-07-07 M Hewitson
0242 %                Creation.
0243 %
0244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0245 
0246 function ii = getInfo(varargin)
0247   if nargin == 1 && strcmpi(varargin{1}, 'None')
0248     sets = {};
0249     pl   = [];
0250   else
0251     sets = {'Default'};
0252     pl   = getDefaultPlist;
0253   end
0254   % Build info object
0255   ii = minfo(mfilename, 'history', '', utils.const.categories.output, '$Id: plot.m,v 1.27 2008/09/05 14:17:01 hewitson Exp $', sets, pl);
0256 end
0257 
0258 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0259 %
0260 % FUNCTION:    getDefaultPlist
0261 %
0262 % DESCRIPTION: Get Default Plist
0263 %
0264 % HISTORY:     11-07-07 M Hewitson
0265 %                Creation.
0266 %
0267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0268 
0269 function plo = getDefaultPlist()
0270   plo = plist();
0271 end
0272

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003