diff options
Diffstat (limited to 'src/union.py')
-rw-r--r-- | src/union.py | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/src/union.py b/src/union.py index 96016c9..fdfff51 100644 --- a/src/union.py +++ b/src/union.py @@ -37,17 +37,17 @@ class Union: return str - def size_to_draw(self): + def size_desc(self): "Compute size to draw the union an its subtree" totlen = 0 if self.childs == []: - return 3 + return 2 for c in self.childs: - totlen = totlen + c.size_to_draw() - return max(3,totlen) + totlen = totlen + c.size_desc() + return max(2,totlen) - - def compute_draw(self, x, y): + + def compute_desc_pos(self, x, y): "Compute union subtree position" # Reinit size @@ -57,56 +57,63 @@ class Union: # Compute childs size size = 0 for c in self.childs: - size = size + c.size_to_draw() + size = size + c.size_desc() # Compute origin - wmargin = const._person_width/const._person_wmargin_ratio if len(self.childs) == 1: x = x - (const._person_width)/2 else: - x = x - (size*const._person_width+(size-1)*wmargin)/2 + x = x - (size*const._person_width+(size-1)*self.dad.width_margin())/2 # Compute draw for childs for c in self.childs: - c.compute_draw(x, y) - size = c.size_to_draw() - x = x + (size*const._person_width+size*wmargin) + c.set_pos(x, y) + c.compute_desc_pos(x, y) + size = c.size_desc() + x = x + (size*const._person_width+size*c.width_margin()) + + + def conjoint(self, p): + "Return conjoint" + if p == self.dad: + return self.mum + else: + return self.dad - def draw(self, gc, pc, unionnumber): + def draw(self, gc, pc): "Draw person and its subtree in the graphical context" + # Do not draw person without coordinate + if self.dad.x0 is None or self.mum.x0 is None: + return + # Draw link between parents if self.dad.x0 < self.mum.x0: (left, right) = (self.dad, self.mum) - if (unionnumber != 0): - left = left.unions[unionnumber-1].mum else: (left, right) = (self.mum, self.dad) - if (unionnumber != 0): - left = left.unions[unionnumber-1].dad + if len(left.unions) > 1 and self != left.unions[0]: + i = 1 + while left.unions[i].conjoint(left) != right: + i = i + 1 + left = left.unions[i-1].conjoint(left) width = left.x1 - left.x0 height = left.y1 - left.y0 - wmargin = width / const._person_wmargin_ratio - hmargin = height / const._person_hmargin_ratio gc.move_to(left.x0+width, left.y0+(height/2)) gc.line_to(right.x0, right.y0+(height/2)) gc.set_source_rgb(*const._union_color) gc.stroke() - # Draw each child + # Draw link to child size = len(self.childs) for c in self.childs: - # Draw the child - c.draw(gc, pc) - # Draw link to child - gc.move_to(right.x0-(wmargin/2), right.y0+(height/2)) - gc.line_to(right.x0-(wmargin/2), right.y0+height+(hmargin/2)) - if size == 1: - gc.line_to(right.x0-(wmargin/2), c.y0) - else: - gc.line_to(c.x0+(width/2), right.y0+height+(hmargin/2)) - gc.line_to(c.x0+(width/2), c.y0) + if c.x0 is None: + continue + gc.move_to(right.x0-(c.width_margin()/2), right.y0+(height/2)) + gc.line_to(right.x0-(c.width_margin()/2), right.y0+height+(c.height_margin()/2)) + gc.line_to(c.x0+(width/2), right.y0+height+(c.height_margin()/2)) + gc.line_to(c.x0+(width/2), c.y0) gc.set_source_rgb(*const._union_color) gc.stroke()
\ No newline at end of file |