comparison toolboxes/graph_visualisation/graphViz4Matlab/layouts/Gridlayout.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 classdef Gridlayout < Abstractlayout
2 % Provides a simple, (naive) grid layout for Graphlayout.
3 % An uninitialized instance can be created to pass to the GraphLayout
4 % constructor by just calling Gridlayout without any parameters, e.g.
5 % Graphlayout('-adjMat',[0 1; 0 0], '-layout',Gridlayout);
6 %
7 % Matthew Dunham
8 % University of British Columbia
9 % http://www.cs.ubc.ca/~mdunham/
10
11 properties
12 xmin; % The left most point on the graph axis in data units
13 xmax; % The right most point on the graph axis in data units
14 ymin; % The bottom most point on the graph axis in data units
15 ymax; % The top most point on the graph axis in data units
16 adjMatrix; % The adjacency matrix
17 maxNodeSize; % The maximum diameter of a node in data units
18 image; % An image for the button that will lanuch this layout
19 name; % A unique name for instances of this class
20 shortDescription; % A description for use in the tooltips
21 nodeSize; % The calculated node size, call dolayout() before accessing
22 centers; % The calculated node centers in an n-by-2 matrix
23 end
24
25 methods
26 function obj = Gridlayout(name)
27
28 % constructor
29 if(nargin < 1)
30 obj.name = 'Gridlayout';
31 else
32 obj.name = name;
33 end
34 load glicons;
35 obj.image = icons.grid;
36 obj.shortDescription = 'Grid Layout';
37 end
38
39 end
40
41
42 methods(Access = 'protected')
43
44 function calcLayout(obj)
45
46 nnodes = size(obj.adjMatrix,1);
47 obj.centers = zeros(nnodes,2);
48 xspacePerNode = (obj.xmax - obj.xmin)/ceil(sqrt(nnodes));
49 yspacePerNode = (obj.ymax - obj.ymin)/ceil(sqrt(nnodes));
50 obj.nodeSize = min(min([xspacePerNode,yspacePerNode]./2),obj.maxNodeSize);
51 xstart = obj.xmin + (xspacePerNode)/2;
52 ystart = obj.ymin + (yspacePerNode)/2;
53 counter = 1;
54 for ypos=1:ceil(sqrt(nnodes))
55 if(counter > nnodes),break,end
56 for xpos=1:ceil(sqrt(nnodes))
57 obj.centers(counter,1) = xstart + (xpos-1)*xspacePerNode;
58 obj.centers(counter,2) = ystart + (ypos-1)*yspacePerNode;
59 positions(ypos,xpos) = counter; %#ok
60 counter = counter + 1;
61 end
62 end
63
64 %swap out the center node for the node with the most edges,
65 %(total of in and out).
66 edgeCounts = sum(obj.adjMatrix,1)' + sum(obj.adjMatrix,2);
67 [vals ndx] = sort(edgeCounts,'descend');
68 c = positions(ceil(size(positions,1)/2),ceil(size(positions,2)/2));
69 if(c ~= 0)
70 store = obj.centers(c,:);
71 obj.centers(c,:) = obj.centers(ndx(1),:);
72 obj.centers(ndx(1),:) = store;
73 end
74
75 end
76
77
78 end
79
80 end