Daniel@0: function [x, y, h] = draw_graph(adj, labels, node_t, x, y) Daniel@0: % DRAW_LAYOUT Draws a layout for a graph Daniel@0: % Daniel@0: % [] = DRAW_LAYOUT(ADJ, ) Daniel@0: % Daniel@0: % Inputs : Daniel@0: % ADJ : Adjacency matrix (source, sink) Daniel@0: % LABELS : Cell array containing labels Daniel@0: % ISBOX : 1 if node is a box, 0 if oval Daniel@0: % X, Y, : Coordinates of nodes on the unit square Daniel@0: % Daniel@0: % Outputs : Daniel@0: % X, Y : Coordinates of nodes on the unit square Daniel@0: % H : Object handles Daniel@0: % Daniel@0: % Usage Example : [x, y] = draw_layout([0 1;0 0], {'Hidden','Visible'}, [1 0]'); Daniel@0: % Daniel@0: % h(i,1) is the text handle - color Daniel@0: % h(i,2) is the circle handle - facecolor Daniel@0: % Daniel@0: % Note : Daniel@0: % See also MAKE_LAYOUT Daniel@0: Daniel@0: % Uses : Daniel@0: Daniel@0: % Change History : Daniel@0: % Date Time Prog Note Daniel@0: % 13-Apr-2000 9:06 PM ATC Created under MATLAB 5.3.1.29215a (R11.1) Daniel@0: Daniel@0: % ATC = Ali Taylan Cemgil, Daniel@0: % SNN - University of Nijmegen, Department of Medical Physics and Biophysics Daniel@0: % e-mail : cemgil@mbfys.kun.nl Daniel@0: adj = double(adj); Daniel@0: N = size(adj,1); Daniel@0: if nargin<2, Daniel@0: % labels = cellstr(char(zeros(N,1)+double('+'))); Daniel@0: labels = cellstr(int2str((1:N)')); Daniel@0: end; Daniel@0: Daniel@0: if nargin<3, Daniel@0: node_t = zeros(N,1); Daniel@0: % node_t = rand(N,1) > 0.5; Daniel@0: else Daniel@0: node_t = node_t(:); Daniel@0: end; Daniel@0: Daniel@0: axis([0 1 0 1]); Daniel@0: set(gca,'XTick',[],'YTick',[],'box','on'); Daniel@0: % axis('square'); Daniel@0: %colormap(flipud(gray)); Daniel@0: Daniel@0: if nargin<4, Daniel@0: [x y] = make_layout(adj); Daniel@0: end; Daniel@0: Daniel@0: idx1 = find(node_t==0); wd1=[]; Daniel@0: if ~isempty(idx1), Daniel@0: [h1 wd1] = textoval(x(idx1), y(idx1), labels(idx1)); Daniel@0: end; Daniel@0: Daniel@0: idx2 = find(node_t~=0); wd2 = []; Daniel@0: if ~isempty(idx2), Daniel@0: [h2 wd2] = textbox(x(idx2), y(idx2), labels(idx2)); Daniel@0: end; Daniel@0: Daniel@0: wd = zeros(size(wd1,1)+size(wd2,1),2); Daniel@0: if ~isempty(idx1), wd(idx1, :) = wd1; end; Daniel@0: if ~isempty(idx2), wd(idx2, :) = wd2; end; Daniel@0: Daniel@0: for i=1:N, Daniel@0: j = find(adj(i,:)==1); Daniel@0: for k=j, Daniel@0: if x(k)-x(i)==0, Daniel@0: sign = 1; Daniel@0: if y(i)>y(k), alpha = -pi/2; else alpha = pi/2; end; Daniel@0: else Daniel@0: alpha = atan((y(k)-y(i))/(x(k)-x(i))); Daniel@0: if x(i)2, Daniel@0: h = zeros(length(wd),2); Daniel@0: if ~isempty(idx1), Daniel@0: h(idx1,:) = h1; Daniel@0: end; Daniel@0: if ~isempty(idx2), Daniel@0: h(idx2,:) = h2; Daniel@0: end; Daniel@0: end; Daniel@0: Daniel@0: %%%%% Daniel@0: Daniel@0: function [t, wd] = textoval(x, y, str) Daniel@0: % TEXTOVAL Draws an oval around text objects Daniel@0: % Daniel@0: % [T, WIDTH] = TEXTOVAL(X, Y, STR) Daniel@0: % [..] = TEXTOVAL(STR) % Interactive Daniel@0: % Daniel@0: % Inputs : Daniel@0: % X, Y : Coordinates Daniel@0: % TXT : Strings Daniel@0: % Daniel@0: % Outputs : Daniel@0: % T : Object Handles Daniel@0: % WIDTH : x and y Width of ovals Daniel@0: % Daniel@0: % Usage Example : [t] = textoval('Visit to Asia?'); Daniel@0: % Daniel@0: % Daniel@0: % Note : Daniel@0: % See also TEXTBOX Daniel@0: Daniel@0: % Uses : Daniel@0: Daniel@0: % Change History : Daniel@0: % Date Time Prog Note Daniel@0: % 15-Jun-1998 10:36 AM ATC Created under MATLAB 5.1.0.421 Daniel@0: Daniel@0: % ATC = Ali Taylan Cemgil, Daniel@0: % SNN - University of Nijmegen, Department of Medical Physics and Biophysics Daniel@0: % e-mail : cemgil@mbfys.kun.nl Daniel@0: Daniel@0: temp = []; Daniel@0: Daniel@0: switch nargin, Daniel@0: case 1, Daniel@0: str = x; Daniel@0: if ~isa(str,'cell') str=cellstr(str); end; Daniel@0: N = length(str); Daniel@0: wd = zeros(N,2); Daniel@0: for i=1:N, Daniel@0: [x, y] = ginput(1); Daniel@0: tx = text(x,y,str{i},'HorizontalAlignment','center','VerticalAlign','middle'); Daniel@0: [ptc wx wy] = draw_oval(tx, x, y); Daniel@0: wd(i,:) = [wx wy]; Daniel@0: delete(tx); Daniel@0: tx = text(x,y,str{i},'HorizontalAlignment','center','VerticalAlign','middle'); Daniel@0: temp = [temp ; tx ptc]; Daniel@0: end; Daniel@0: case 3, Daniel@0: if ~isa(str,'cell') str=cellstr(str); end; Daniel@0: N = length(str); Daniel@0: wd = zeros(N,2); Daniel@0: for i=1:N, Daniel@0: tx = text(x(i),y(i),str{i},'HorizontalAlignment','center','VerticalAlign','middle'); Daniel@0: [ptc wx wy] = draw_oval(tx, x(i), y(i)); Daniel@0: wd(i,:) = [wx wy]; Daniel@0: delete(tx); Daniel@0: tx = text(x(i),y(i),str{i},'HorizontalAlignment','center','VerticalAlign','middle'); Daniel@0: temp = [temp; tx ptc]; Daniel@0: end; Daniel@0: otherwise, Daniel@0: end; Daniel@0: Daniel@0: if nargout>0, t = temp; end; Daniel@0: Daniel@0: %%%%%%%%% Daniel@0: Daniel@0: Daniel@0: function [ptc, wx, wy] = draw_oval(tx, x, y) Daniel@0: % Draws an oval box around a tex object Daniel@0: sz = get(tx,'Extent'); Daniel@0: wy = sz(4); Daniel@0: wx = max(2/3*sz(3), wy); Daniel@0: wx = 0.5*wx; % KPM Daniel@0: wy = 0.5*wy; Daniel@0: ptc = ellipse(x, y, wx, wy); Daniel@0: set(ptc, 'FaceColor','w'); Daniel@0: Daniel@0: Daniel@0: %%%%%%%%%%%%% Daniel@0: Daniel@0: function [p] = ellipse(x, y, rx, ry, c) Daniel@0: % ELLIPSE Draws Ellipse shaped patch objects Daniel@0: % Daniel@0: % [

] = ELLIPSE(X, Y, Rx, Ry, C) Daniel@0: % Daniel@0: % Inputs : Daniel@0: % X : N x 1 vector of x coordinates Daniel@0: % Y : N x 1 vector of y coordinates Daniel@0: % Rx, Ry : Radii Daniel@0: % C : Color index Daniel@0: % Daniel@0: % Daniel@0: % Outputs : Daniel@0: % P = Handles of Ellipse shaped path objects Daniel@0: % Daniel@0: % Usage Example : [] = ellipse(); Daniel@0: % Daniel@0: % Daniel@0: % Note : Daniel@0: % See also Daniel@0: Daniel@0: % Uses : Daniel@0: Daniel@0: % Change History : Daniel@0: % Date Time Prog Note Daniel@0: % 27-May-1998 9:55 AM ATC Created under MATLAB 5.1.0.421 Daniel@0: Daniel@0: % ATC = Ali Taylan Cemgil, Daniel@0: % SNN - University of Nijmegen, Department of Medical Physics and Biophysics Daniel@0: % e-mail : cemgil@mbfys.kun.nl Daniel@0: Daniel@0: if (nargin < 2) error('Usage Example : e = ellipse([0 1],[0 -1],[1 0.5],[2 0.5]); '); end; Daniel@0: if (nargin < 3) rx = 0.1; end; Daniel@0: if (nargin < 4) ry = rx; end; Daniel@0: if (nargin < 5) c = 1; end; Daniel@0: Daniel@0: if length(c)==1, c = ones(size(x)).*c; end; Daniel@0: if length(rx)==1, rx = ones(size(x)).*rx; end; Daniel@0: if length(ry)==1, ry = ones(size(x)).*ry; end; Daniel@0: Daniel@0: n = length(x); Daniel@0: p = zeros(size(x)); Daniel@0: t = 0:pi/30:2*pi; Daniel@0: for i=1:n, Daniel@0: px = rx(i)*cos(t)+x(i); Daniel@0: py = ry(i)*sin(t)+y(i); Daniel@0: p(i) = patch(px,py,c(i)); Daniel@0: end; Daniel@0: Daniel@0: if nargout>0, pp = p; end; Daniel@0: Daniel@0: %%%%% Daniel@0: Daniel@0: function [t, wd] = textbox(x,y,str) Daniel@0: % TEXTBOX Draws A Box around the text Daniel@0: % Daniel@0: % [T, WIDTH] = TEXTBOX(X, Y, STR) Daniel@0: % [..] = TEXTBOX(STR) Daniel@0: % Daniel@0: % Inputs : Daniel@0: % X, Y : Coordinates Daniel@0: % TXT : Strings Daniel@0: % Daniel@0: % Outputs : Daniel@0: % T : Object Handles Daniel@0: % WIDTH : x and y Width of boxes Daniel@0: %% Daniel@0: % Usage Example : t = textbox({'Ali','Veli','49','50'}); Daniel@0: % Daniel@0: % Daniel@0: % Note : Daniel@0: % See also TEXTOVAL Daniel@0: Daniel@0: % Uses : Daniel@0: Daniel@0: % Change History : Daniel@0: % Date Time Prog Note Daniel@0: % 09-Jun-1998 11:43 AM ATC Created under MATLAB 5.1.0.421 Daniel@0: Daniel@0: % ATC = Ali Taylan Cemgil, Daniel@0: % SNN - University of Nijmegen, Department of Medical Physics and Biophysics Daniel@0: % e-mail : cemgil@mbfys.kun.nl Daniel@0: Daniel@0: % See Daniel@0: temp = []; Daniel@0: Daniel@0: switch nargin, Daniel@0: case 1, Daniel@0: str = x; Daniel@0: if ~isa(str,'cell') str=cellstr(str); end; Daniel@0: N = length(str); Daniel@0: wd = zeros(N,2); Daniel@0: for i=1:N, Daniel@0: [x, y] = ginput(1); Daniel@0: tx = text(x,y,str{i},'HorizontalAlignment','center','VerticalAlign','middle'); Daniel@0: [ptc wx wy] = draw_box(tx, x, y); Daniel@0: wd(i,:) = [wx wy]; Daniel@0: delete(tx); Daniel@0: tx = text(x,y,str{i},'HorizontalAlignment','center','VerticalAlign','middle'); Daniel@0: temp = [temp; tx ptc]; Daniel@0: end; Daniel@0: case 3, Daniel@0: if ~isa(str,'cell') str=cellstr(str); end; Daniel@0: N = length(str); Daniel@0: for i=1:N, Daniel@0: tx = text(x(i),y(i),str{i},'HorizontalAlignment','center','VerticalAlign','middle'); Daniel@0: [ptc wx wy] = draw_box(tx, x(i), y(i)); Daniel@0: wd(i,:) = [wx wy]; Daniel@0: delete(tx); Daniel@0: tx = text(x(i),y(i),str{i},'HorizontalAlignment','center','VerticalAlign','middle'); Daniel@0: temp = [temp; tx ptc]; Daniel@0: end; Daniel@0: Daniel@0: otherwise, Daniel@0: Daniel@0: end; Daniel@0: Daniel@0: if nargout>0, t = temp; end; Daniel@0: Daniel@0: Daniel@0: function [ptc, wx, wy] = draw_box(tx, x, y) Daniel@0: % Draws a box around a tex object Daniel@0: sz = get(tx,'Extent'); Daniel@0: wy = 2/3*sz(4); Daniel@0: wx = max(2/3*sz(3), wy); Daniel@0: ptc = patch([x-wx x+wx x+wx x-wx], [y+wy y+wy y-wy y-wy],'w'); Daniel@0: set(ptc, 'FaceColor','w'); Daniel@0: