# Ticket #11908: trac_11908-rev.patch

File trac_11908-rev.patch, 3.3 KB (added by ncohen, 8 years ago)
• ## sage/graphs/generic_graph.py

```# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1368014561 -7200
# Node ID b853b21bf7e0a97ea829513c1a21d8f714c28bbb
# Parent  c2f49f4b695494d8f6ffd1174fb3e52e585746a5
Fix tree plotting again -- reviewer's patch

diff --git a/sage/graphs/generic_graph.py b/sage/graphs/generic_graph.py```
 a else: root = tree_root pos = {} # The children and parent of each vertex children = {root:self.neighbors(root)} # always make a copy of the children because they get eaten stack = [[u for u in children[root]]] parent = {u:root for u in children[root]} # stack[i] is the list of children of stick[i] which have not been given # a position yet. stack = [list(children[root])] stick = [root] parent = dict([(u,root) for u in children[root]]) pos = {} # obstruction[y] is the smallest value of x to which a vertex at height # y can be assigned. All vertices at height y which have already been # assigned are on the left of (x-1,y). obstruction = [0.0]*self.num_verts() if tree_orientation in ['down', 'left']: while stack: C = stack[-1] # If all the children of stick[-1] have been given a position if len(C) == 0: p = stick.pop() stack.pop() cp = children[p] y = o*len(stack) if len(cp) == 0: # If p has no children, we draw it at the leftmost position # which has not been forbidden x = obstruction[y] pos[p] = x, y else: # If p has children, we put v on a vertical line going # through the barycenter of its children x = sum([pos[c][0] for c in cp])/len(cp) pos[p] = x, y ox = obstruction[y] if x < ox: slide(p, ox-x) x = ox # If the vertex to the right of p has not children, we want it # at distance 1 from p obstruction[y] = x+1 continue t = C.pop() pt = parent[t] ct = [u for u in self.neighbors(t) if u != pt] for c in ct: parent[c] = t children[t] = ct stack.append([c for c in ct]) stick.append(t) # Otherwise, we take one of the children and add it to the # stack. Note that this vertex is removed from the list C. else: t = C.pop() pt = parent[t] ct = [u for u in self.neighbors(t) if u != pt] children[t] = ct for c in ct: parent[c] = t stack.append([c for c in ct]) stick.append(t) if tree_orientation in ['right', 'left']: return dict([[point,[pos[point][1],pos[point][0]]] for point in pos]) return {p:(py,px) for p,(px,py) in pos.iteritems()} return pos