grrdrr / example.py

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


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

example.set_style(
        arc_width=1.5,
        border_width=1.5,
        font_size=16.0)

op_organization = example.add_node()
op_project = example.add_node()
op_person = example.add_node()
op_participation = example.add_node()
hr_private_info = example.add_node()
ws_workitem = example.add_node()
ws_worklist = example.add_node()
ws_dependency = example.add_node()
wsx_issue = example.add_node()
wsx_meeting = example.add_node()
wsx_meeting_topic = example.add_node()
wsx_standing_meeting = example.add_node()
tb_invoice = example.add_node()
tb_lineitem = example.add_node()
tb_timeslip = 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")
hr_private_info.set_label("hr.private_info")
ws_workitem.set_label("ws.workitem")
ws_worklist.set_label("ws.worklist")
ws_dependency.set_label("ws.dependency")
wsx_issue.set_label("wsx.issue")
wsx_meeting.set_label("wsx.meeting")
wsx_meeting_topic.set_label("wsx.meeting_topic")
wsx_standing_meeting.set_label("wsx.standing_meeting")
tb_invoice.set_label("tb.invoice")
tb_lineitem.set_label("tb.lineitem")
tb_timeslip.set_label("tb.timeslip")

organization_division_of_fk = example.add_arc(op_organization, op_organization)
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)
private_info_person_fk = example.add_arc(hr_private_info, op_person)
workitem_project_fk = example.add_arc(ws_workitem, op_project)
workitem_worklist_fk = example.add_arc(ws_workitem, ws_worklist)
worklist_workitem_fk = example.add_arc(ws_worklist, ws_workitem)
worklist_person_fk = example.add_arc(ws_worklist, op_person)
dependency_of_workitem_fk = example.add_arc(ws_dependency, ws_workitem)
dependency_on_workitem_fk = example.add_arc(ws_dependency, ws_workitem)
issue_workitem_fk = example.add_arc(wsx_issue, ws_workitem)
issue_person_fk = example.add_arc(wsx_issue, op_person)
meeting_workitem_fk = example.add_arc(wsx_meeting, ws_workitem)
meeting_topic_meeting_fk = example.add_arc(wsx_meeting_topic, wsx_meeting)
standing_meeting_meeting_fk = example.add_arc(wsx_standing_meeting, wsx_meeting)
invoice_organization_fk = example.add_arc(tb_invoice, op_organization)
lineitem_invoice_fk = example.add_arc(tb_lineitem, tb_invoice)
timeslip_participation_fk = example.add_arc(tb_timeslip, op_participation)
timeslip_lineitem_fk = example.add_arc(tb_timeslip, tb_lineitem)
timeslip_workitem_fk = example.add_arc(tb_timeslip, ws_workitem)

organization_division_of_fk.set_label("division_of").set_weight(0.5)
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)
private_info_person_fk.set_label("person").set_weight(1.0)
workitem_project_fk.set_label("project").set_weight(1.0)
workitem_worklist_fk.set_label("worklist").set_weight(0.5)
worklist_workitem_fk.set_label("workitem").set_weight(1.0)
worklist_person_fk.set_label("assigned_to").set_weight(0.5)
dependency_of_workitem_fk.set_label("of").set_weight(1.0)
dependency_on_workitem_fk.set_label("on").set_weight(1.0)
issue_workitem_fk.set_label("workitem").set_weight(1.0)
issue_person_fk.set_label("reported_by").set_weight(0.5)
meeting_workitem_fk.set_label("workitem").set_weight(1.0)
meeting_topic_meeting_fk.set_label("meeting").set_weight(1.0)
standing_meeting_meeting_fk.set_label("meeting").set_weight(1.0)
invoice_organization_fk.set_label("organization").set_weight(0.5)
lineitem_invoice_fk.set_label("invoice").set_weight(1.0)
timeslip_participation_fk.set_label("participation").set_weight(1.0)
timeslip_lineitem_fk.set_label("lineitem").set_weight(0.5)
timeslip_workitem_fk.set_label("workitem").set_weight(0.5)

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

example = example.clone()

print
print repr(example)

print
for node in example.nodes:
    print repr(node)

print
for arc in example.arcs:
    print repr(arc), arc.weight.value


print
for node in example.nodes_by_rank:
    print node, node.rank.value

print
for layer in example.layers:
    print repr(layer)
    for bead in layer.beads:
        print "\t", repr(bead)

print
for layer in example.layers:
    print repr(layer)
    for bead in layer.beads_by_order:
        print "\t", repr(bead)

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.png", "wb")
#draw(example, stream)
draw_smooth(example, stream)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.