Source

grrdrr / demo / example-schema-grid.py

Full commit

from grrdrr.model import WithGraphStyle
from grrdrr.draw import measure_uniform, draw_smooth, draw_smooth_cut
from grrdrr.algorithm import array, place_grid
from grrdrr.database import build_schema
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_uniform(example)
print "ARRAYING..."
array(example)
print "PLACING..."
place_grid(example)
print "DONE"

filename = "%s.grid.png" % basename
stream = open(filename, 'wb')
draw_smooth_cut(example, stream)
stream.close()
print "Grid rendering is written to: %s" % filename