Source

grrdrr / example-loop.py


from model import build, WithGraphStyle, WithNodeLabel, WithArcLabel, WithArcWeight
from draw import measure, draw
from 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)

alpha = example.add_node()
beta = example.add_node()
gamma = example.add_node()

alpha.set_label("alpha")
beta.set_label("beta")
gamma.set_label("gamma")

alpha_beta = example.add_arc(alpha, beta)
beta_gamma = example.add_arc(beta, gamma)
gamma_alpha = example.add_arc(gamma, alpha)

alpha_beta.set_label("alpha-beta").set_weight(1.0)
beta_gamma.set_label("beta-gamma").set_weight(1.0)
gamma_alpha.set_label("gamma-alpha").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-loop.png", "wb")
draw(example, stream)