1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
class GraphViz
class FamilyTree
class Couple
def initialize( graph, node, persons ) #:nodoc:
@graph = graph
@node = node
@kids = []
@persons = persons
end
def node #:nodoc:
@node
end
# Add kids to a couple
def kids( *z )
@kids = GraphViz::FamilyTree::Sibling.new( z, @persons )
return
if z.size == 1
@graph.add_edges( @node, z[0].node, "dir" => "none" )
else
cluster = @graph.add_graph( "#{@node.id}Kids" )
cluster["rank"] = "same"
last = nil
count = 0
add = (z.size-1)%2 * z.size/2 + (z.size-1)%2
link = (z.size/2)+1
z.each do |person|
count = count + 1
if count == add
middle = cluster.add_nodes( "#{@node.id}Kids", "shape" => "point" )
@graph.add_edges( @node, middle, "dir" => "none" )
unless last.nil?
cluster.add_edges( last, middle, "dir" => "none" )
end
last = middle
end
kid = cluster.add_nodes( "#{person.node.id}Kid", "shape" => "point" )
@graph.add_edges( kid, person.node, "dir" => "none" )
if add == 0 and count == link
@graph.add_edges( @node, kid, "dir" => "none" )
end
unless last.nil?
cluster.add_edges( last, kid, "dir" => "none" )
end
last = kid
end
end
end
def getKids
@kids
end
end
end
end
|