Source

grrdrr / example-schema.py


from model import WithGraphStyle
from draw import measure, draw_smooth
from algorithm import rank, layer, order, place
from database import build_schema
from graphviz import draw_graphviz
import sys
import re

if len(sys.argv) != 2:
    print "Usage: %s <db>" % sys.argv[0]
    sys.exit(1)
db = sys.argv[1]
basename_match = re.search(r'[0-9a-zA-Z_-]+$', db)
if basename_match is not None:
    basename = basename_match.group()
else:
    basename = db

example = build_schema(db)
example.upgrade(WithGraphStyle)
example.set_style(
        arc_width=1.5,
        border_width=1.5,
        font_size=16.0)
example.freeze()

print "MEASURING..."
measure(example)
print "RANKING..."
rank(example)
print "LAYERING..."
layer(example)
print "ORDERING..."
order(example)
print "PLACING..."
place(example)
print "DONE"

#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)

filename = "%s.sugiyama.png" % basename
stream = open(filename, 'wb')
draw_smooth(example, stream)
stream.close()
print "Sugiyama rendering is written to: %s" % filename

filename = "%s.graphviz.png" % basename
stream = open(filename, 'wb')
draw_graphviz(example, stream)
stream.close()
print "GraphViz rendering is written to: %s" % filename