Source

grrdrr / demo / example-small.py

Full commit

from grrdrr.model import build, WithGraphStyle, WithNodeLabel, WithArcLabel, WithArcWeight
from grrdrr.draw import measure, draw
from grrdrr.algorithm import rank, layer, order, place


example = build(WithGraphStyle, WithNodeLabel, WithArcLabel, WithArcWeight)

example.set_style(
        background_color=(0.5, 0.5, 0.5),
        node_color=(0.0, 0.0, 0.5),
        arc_color=(0.5, 0.0, 0.0),
        text_color=(1.0, 1.0, 1.0),
        font_size=18.0)

op_organization = example.add_node()
op_project = example.add_node()
op_person = example.add_node()
op_participation = example.add_node()

op_organization.set_label("op.organization")
op_project.set_label("op.project")
op_person.set_label("op.person")
op_participation.set_label("op.participation")

project_organization_fk = example.add_arc(op_project, op_organization)
person_organization_fk = example.add_arc(op_person, op_organization)
participation_project_fk = example.add_arc(op_participation, op_project)
participation_person_fk = example.add_arc(op_participation, op_person)

project_organization_fk.set_label("organization").set_weight(0.5)
person_organization_fk.set_label("organization").set_weight(1.0)
participation_project_fk.set_label("project").set_weight(1.0)
participation_person_fk.set_label("person").set_weight(1.0)

example.freeze()
measure(example)
rank(example)
layer(example)
order(example)
place(example)

example = example.clone()

print
print "(%s, %s)" % (example.size.width, example.size.height)
for node in example.nodes_by_rank:
    print node, "(%s, %s, %s, %s)" % (node.position.x, node.position.y, node.position.w, node.position.h)

stream = open("example-small.png", "wb")
draw(example, stream)