grrdrr / demo / example-regress.py

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


example = build(WithGraphStyle, WithNodeLabel, WithArcWeight)

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

ad_school = example.add_node()
ad_department = example.add_node()
ad_program = example.add_node()
ad_course = example.add_node()

id_instructor = example.add_node()
id_confidential = example.add_node()
id_appointment = example.add_node()

cd_semester = example.add_node()
cd_class = example.add_node()

ed_student = example.add_node()
ed_enrollment = example.add_node()

rd_prerequisite = example.add_node()
rd_classification = example.add_node()
rd_course_classification = example.add_node()
rd_program_requirement = example.add_node()

ad_school.set_label("school")
ad_department.set_label("department")
ad_program.set_label("program")
ad_course.set_label("course")

id_instructor.set_label("instructor")
id_confidential.set_label("confidential")
id_appointment.set_label("appointment")

cd_semester.set_label("semester")
cd_class.set_label("class")

ed_student.set_label("student")
ed_enrollment.set_label("enrollment")

rd_prerequisite.set_label("prerequisite")
rd_classification.set_label("classification")
rd_course_classification.set_label("course_classification")
rd_program_requirement.set_label("program_requirement")

example.add_arc(ad_department, ad_school).set_weight(0.5)
example.add_arc(ad_program, ad_school).set_weight(1.0)
example.add_arc(ad_program, ad_program).set_weight(0.5)
example.add_arc(ad_course, ad_department).set_weight(1.0)
example.add_arc(id_confidential, id_instructor).set_weight(1.0)
example.add_arc(id_appointment, ad_department).set_weight(1.0)
example.add_arc(id_appointment, id_instructor).set_weight(1.0)
example.add_arc(cd_class, ad_course).set_weight(1.0)
example.add_arc(cd_class, cd_semester).set_weight(1.0)
example.add_arc(cd_class, id_instructor).set_weight(0.5)
example.add_arc(ed_student, ad_program).set_weight(0.5)
example.add_arc(ed_enrollment, ed_student).set_weight(1.0)
example.add_arc(ed_enrollment, cd_class).set_weight(1.0)
example.add_arc(rd_prerequisite, ad_course).set_weight(1.0)
example.add_arc(rd_prerequisite, ad_course).set_weight(1.0)
example.add_arc(rd_classification, rd_classification).set_weight(0.5)
example.add_arc(rd_course_classification, ad_course).set_weight(1.0)
example.add_arc(rd_course_classification, rd_classification).set_weight(1.0)
example.add_arc(rd_program_requirement, ad_program).set_weight(1.0)
example.add_arc(rd_program_requirement, rd_classification).set_weight(1.0)

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("htsql_regress.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.