annotate toolboxes/graph_visualisation/graphViz4Matlab/layouts/Gridlayout.m @ 0:cc4b1211e677 tip

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