|
@@ -5,6 +5,11 @@ import graphviz
|
|
from yamily import Person, PersonCollection
|
|
from yamily import Person, PersonCollection
|
|
|
|
|
|
|
|
|
|
|
|
+def _add_person_node(graph: graphviz.dot.Digraph, person: Person) -> None:
|
|
|
|
+ label = person.name or person.identifier
|
|
|
|
+ graph.node(person.identifier, label=label, shape="box")
|
|
|
|
+
|
|
|
|
+
|
|
def digraph(collection: PersonCollection) -> graphviz.dot.Digraph:
|
|
def digraph(collection: PersonCollection) -> graphviz.dot.Digraph:
|
|
"""
|
|
"""
|
|
>>> bob = Person('bob')
|
|
>>> bob = Person('bob')
|
|
@@ -31,27 +36,27 @@ def digraph(collection: PersonCollection) -> graphviz.dot.Digraph:
|
|
digraph yamily {
|
|
digraph yamily {
|
|
{
|
|
{
|
|
rank=same
|
|
rank=same
|
|
- grace [shape=box]
|
|
+ grace [label=grace shape=box]
|
|
}
|
|
}
|
|
{
|
|
{
|
|
rank=same
|
|
rank=same
|
|
- carol [shape=box]
|
|
+ carol [label=carol shape=box]
|
|
- bob [shape=box]
|
|
+ bob [label=bob shape=box]
|
|
"relation-bob-carol" [shape=point width=0]
|
|
"relation-bob-carol" [shape=point width=0]
|
|
carol -> "relation-bob-carol" [arrowhead=none constraint=False]
|
|
carol -> "relation-bob-carol" [arrowhead=none constraint=False]
|
|
bob -> "relation-bob-carol" [arrowhead=none constraint=False]
|
|
bob -> "relation-bob-carol" [arrowhead=none constraint=False]
|
|
}
|
|
}
|
|
{
|
|
{
|
|
rank=same
|
|
rank=same
|
|
- frank [shape=box]
|
|
+ frank [label=frank shape=box]
|
|
}
|
|
}
|
|
{
|
|
{
|
|
rank=same
|
|
rank=same
|
|
- alice [shape=box]
|
|
+ alice [label=alice shape=box]
|
|
}
|
|
}
|
|
{
|
|
{
|
|
rank=same
|
|
rank=same
|
|
- david [shape=box]
|
|
+ david [label=david shape=box]
|
|
}
|
|
}
|
|
grace -> carol
|
|
grace -> carol
|
|
frank -> bob
|
|
frank -> bob
|
|
@@ -69,10 +74,10 @@ def digraph(collection: PersonCollection) -> graphviz.dot.Digraph:
|
|
continue
|
|
continue
|
|
with graph.subgraph() as subgraph:
|
|
with graph.subgraph() as subgraph:
|
|
subgraph.attr(rank="same")
|
|
subgraph.attr(rank="same")
|
|
- subgraph.node(person.identifier, shape="box")
|
|
+ _add_person_node(subgraph, person)
|
|
nodes.add(person)
|
|
nodes.add(person)
|
|
for coparent in collection.get_coparents(person):
|
|
for coparent in collection.get_coparents(person):
|
|
- subgraph.node(coparent.identifier, shape="box")
|
|
+ _add_person_node(subgraph, coparent)
|
|
nodes.add(coparent)
|
|
nodes.add(coparent)
|
|
parents = tuple(sorted((person, coparent), key=lambda p: p.identifier))
|
|
parents = tuple(sorted((person, coparent), key=lambda p: p.identifier))
|
|
parent_node_name = "relation-{}-{}".format(
|
|
parent_node_name = "relation-{}-{}".format(
|