def generate_output(data_fname, config_fname, out_fname, outformat, colorscheme=None, scale=1.0, margins=['10%', '5%']): """ TODO """ tree = _buildtree(data_fname, config_fname, colorscheme) # Temporary context for layout calculations (need an actual graphics # context to be able to work with fonts & text extents). Note that # 'None' is given for the output filename, so a failed run won't # overwrite an already existing file with an empty one. The actual # output file will be created later. _ctx.initsurface(1, 1, outformat, None, scale) width, height = tree.calclayout() # Margins can be given as percentages of the total graph size, # that's why we have to wait with the margin calculations until the # layout is complete padtop, padleft, padbottom, padright = calculate_margins(width, height, margins) width += padleft + padright height += padtop + padbottom # Center tree tree.shiftnodes(padleft, padtop) # Create output file _ctx.initsurface(width, height, outformat, out_fname, scale) _ctx.background(tree.background_color()) tree.draw() _ctx.writesurface()
def init_surface(w, h, suffix='', scale=1.0): ctx.initsurface(w, h, OUTFORMAT, _imgname(OUTFORMAT, suffix), scale=scale)
twyg.common.TWYG_HOME = os.path.join('.') IMG_DIR = 'img' OUTFORMAT = 'png' PAD_X = 3 PAD_Y = 3 TEMPLATE_VARS = { '$FONTNAME': '"Open Sans"', '$FONTSIZE': 17, '$BASELINE_CORR': -0.15 } # Init drawing context ctx.initsurface(1, 1, OUTFORMAT) def write_tree(tree, w, h, suffix='', scale=1.0): w += PAD_X * 2 h += PAD_Y * 2 if suffix: suffix = '-' + suffix init_surface(w, h, suffix=suffix, scale=scale) ctx.translate(PAD_X, PAD_Y) tree.draw() ctx.writesurface() def init_surface(w, h, suffix='', scale=1.0): ctx.initsurface(w, h, OUTFORMAT, _imgname(OUTFORMAT, suffix), scale=scale)