comparison m-toolbox/classes/@history/plot.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % PLOT plots a history object as a tree diagram.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: PLOT plots a history object as a tree diagram.
5 %
6 % NOTE: Some of the code below is taken from Mathworks's treeplot.m
7 %
8 % CALL: plot (history)
9 % plot (history, arg)
10 % plot (history, arg, pl)
11 % plot (axes_handle, ...)
12 %
13 % PARAMETER: 'stop_option' - 'File' ignores the history steps below load-history step
14 % - 'Repo' ignores the history steps below retrieve-history step
15 % - 'File Repo' both steps above
16 % - N maximun depth
17 %
18 % VERSION: $Id: plot.m,v 1.34 2011/02/18 16:48:52 ingo Exp $
19 %
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
22 function varargout = plot(varargin)
23
24 import utils.const.*
25 prefs = getappdata(0, 'LTPDApreferences');
26 utils.helper.msg(msg.OMNAME, 'running %s/%s', mfilename('class'), mfilename);
27
28 %%% Used call: plot (history, arg)
29 if isa(varargin{1}, 'history')
30
31 figure;
32 hists = varargin{1};
33 curr_axes = axes;
34 if nargin >= 2
35 varargin = varargin(2:end);
36 else
37 varargin = {};
38 end
39
40 %%% Used call: plot (curr_axes_handle, history, arg)
41 elseif ishandle(varargin{1})
42
43 curr_axes = varargin{1};
44 axes(curr_axes);
45 hists = varargin{2};
46 if nargin >= 3
47 varargin = varargin(3:end);
48 else
49 varargin = {};
50 end
51
52 else
53 error (['### the first input should be a history object or an axes handle' ...
54 sprintf(' varargin{1} = [%s]',varargin{1})]);
55 end
56
57 %%% collect the parameter and put them into the parameter list
58 plot_args = {};
59 pl = plist();
60 args = varargin;
61
62 while ~isempty(args)
63
64 if isa(args{1}, 'plist')
65 arg = args{1};
66 pl = append(pl, arg);
67 args = args(2:end);
68
69 % Add the key-values to the parameter list
70 elseif length(args) >= 2
71 if ischar(args{1})
72 arg = args{1};
73 val = args{2};
74 pl = append(pl, param(arg, val));
75
76 plot_args{end+1} = arg;
77 plot_args{end+1} = val;
78 args = args(3:end);
79
80 else
81 error('### the key [%s] is not from the type ''char''', char(args{1}));
82 end
83 else
84 help(mfilename('fullpath'))
85 error('### There is no key/value pair left.');
86 end
87
88 end
89
90 %%% Combine input plist and default plist
91 pl = combine(pl, getDefaultPlist);
92
93 %%% Comes the call from the browser or from the command window
94 stop_option = find(pl, 'stop_option');
95
96 %%% Output handles for figures and axes
97 hfig = [];
98 ax = [];
99 at = [];
100
101 nhists = length(hists);
102 for i=1:nhists
103
104 hist = hists(i);
105 % disp(sprintf('--- plotting history %s', hist.name));
106
107 % convert history object to a node list
108 [n,a, nodes] = getNodes(hist, stop_option);
109
110 p = [nodes(:).pn];
111 [x,y,h]=treelayout(p);
112 f = find(p~=0);
113 pp = p(f);
114 X = [x(f); x(pp); repmat(NaN,size(f))];
115 Y = [y(f); y(pp); repmat(NaN,size(f))];
116 X = X(:);
117 Y = Y(:);
118
119 % figure
120 hfig = [hfig gcf];
121
122 % axes objects
123 a = plot (curr_axes, X, Y, 'r--', x, y, 'ro');
124 % plot (X,Y) --> die linien
125 if length(a)>1
126 set(a(2), 'MarkerFaceColor', 'r');
127 set(a(2), 'MarkerSize', 8);
128 end
129 args = plot_args;
130 while ~isempty(args)
131 prop = args{1};
132 val = args{2};
133 args = args(3:end);
134 for ii = 1:length(a)
135 set(a(ii), prop, val);
136 end
137 end
138 ax = [ax a];
139
140 % text objects
141 a = [];
142 for j=1:length(x)
143 % node description
144 fcnname = getFcnName(nodes(j).names);
145 str = ['{\bf\color{blue}' num2str(nodes(j).n) ':}{\bf\color{red}' fcnname '} ' strrep(strrep(char(nodes(j).params), '{', '\{'), '}', '\}')];
146 nlstr = getNodeInputs(nodes(j).invars);
147
148 na = text(x(j), y(j),...
149 [utils.prog.wrapstring(strrep(str,'_', '\_'), double(prefs.getDisplayPrefs.getDisplayWrapStrings)) ...
150 cellstr(['{\color{magenta} ' strrep(nlstr,'_', '\_') '}'])]);
151 set(na, 'HorizontalAlignment', 'center');
152 set(na, 'EdgeColor', 'k', 'Fontsize', 10);
153 set(na, 'BackgroundColor', 'w');
154 set(na, 'Margin', 5);
155 a = [a na];
156 end
157 at = [at a];
158
159 % xlabel(['height = ' int2str(h)]);
160 axis([0 1 0 1]);
161 box off;
162 axis off;
163
164 end
165
166 % Make outputs
167 if nargout > 0
168 varargout{1} = hfig;
169 end
170 if nargout > 1
171 varargout{2} = ax;
172 end
173 if nargout > 2
174 varargout{3} = at;
175 end
176 end
177
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 % Local Functions %
180 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181
182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 %
184 % FUNCTION: getFcnName
185 %
186 % DESCRIPTION: compute strings to display for function name.
187 %
188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189
190 function fcnname = getFcnName(name)
191
192 % switch name
193 % case 'mtimes'
194 % fcnname = 'x';
195 % case 'times'
196 % fcnname = 'x';
197 % case 'plus'
198 % fcnname = '+';
199 % case 'minus'
200 % fcnname = '-';
201 % % case 'sqrt'
202 % % fcnname = '\surd';
203 % case 'mrdivide'
204 % fcnname = '/';
205 % case 'rdivide'
206 % fcnname = '/';
207 % otherwise
208 % fcnname = char(name);
209 % end
210
211 fcnname = char(name);
212 end
213
214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215 %
216 % FUNCTION: getNodeInputs
217 %
218 % DESCRIPTION: compute strings to display for inputs to nodes.
219 %
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221
222 function str = getNodeInputs(invars)
223
224 ni = length(invars);
225 if ni > 0
226 str = char(invars{1});
227 for iv=2:ni
228 s = char(invars{iv});
229 if ~strcmp(s, 'pl')
230 str = [str ' ' s];
231 end
232 end
233 else
234 str = '';
235 end
236 end
237
238 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
239 %
240 % FUNCTION: getDefaultPlist
241 %
242 % DESCRIPTION: Returns the default parameter list.
243 %
244 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245
246 function plo = getDefaultPlist()
247 plo = plist('stop_option', 'full');
248 end
249