From 6bbc3f6cf507536df5be8b28fd5e7b52d2556755 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sun, 6 Jan 2002 20:48:52 +0000 Subject: [PATCH] Graph layout routines svn: r681 --- gramps/src/GraphLayout.py | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 gramps/src/GraphLayout.py diff --git a/gramps/src/GraphLayout.py b/gramps/src/GraphLayout.py new file mode 100644 index 000000000..d95984a7b --- /dev/null +++ b/gramps/src/GraphLayout.py @@ -0,0 +1,69 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000 Donald N. Allingham +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +class GraphLayout: + + def __init__(self,plist,person): + self.plist = plist + self.person = person + self.v = [] + self.e = [] + self.maxx = 0 + self.maxy = 0 + + def max_size(self): + return (self.maxx,self.maxy) + + def layout(self): + return ([],[]) + +class DescendLine(GraphLayout): + + def layout(self): + self.elist = [(0,0)] + self.space_for(self.person) + return (self.v,self.e[1:]) + + def space_for(self,person,level=1.0,pos=1.0): + last = self.elist[-1] + self.elist.append(level,pos) + self.e.append(last[0],last[1],level,pos) + self.v.append(person,level,pos) + if level > self.maxx: + self.maxx = level + if pos > self.maxy: + self.maxy = pos + + for family in person.getFamilyList(): + for child in family.getChildList(): + self.space_for(child,level+1.0,pos) + pos = pos + max(self.depth(child),1) + if pos > self.maxy: + self.maxy = pos + self.elist.pop() + + def depth(self,person,val=1.0): + for family in person.getFamilyList(): + clist = family.getChildList() + val = val + len(clist) + for child in clist: + val = self.depth(child,val) + val = val - 1.0 + return val