Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
from twyg.cairowrapper import context as ctx

config1 = r"""
[layout]
    style                   layout

[node]
    style                   line
    fontName                $FONTNAME
    fontSize                $FONTSIZE
    textBaselineCorrection  $BASELINE_CORR
    strokeWidth             4

[connection]
    style                   curve

[color]
    style                   cycle
    colorscheme             "mint-examples2"
"""

data1 = {'daffadowndilly': []}

init_surface(160, 50, scale=0.9)

ctx.translate(3, 3)
tree = create_tree(config1, data1)
tree.draw()

ctx.writesurface()
Exemplo n.º 5
0
    cornerStyle             square
    junctionStyle           none
    junctionRadius          10
    junctionXFactor         0.55

[color]
    style                   cycle
    colorscheme             "mint-examples3"
"""

data1 = { 'barrel': ['flank', 'stem', 'grot']}
data2 = { 'barrel': ['flank', 'stem', 'grot']}
data3 = { '7381': ['331', '102', '445', '983']}

init_surface(865, 165, scale=0.75)

tree1 = create_tree(config1, data1)
tree2 = create_tree(config2, data2)
tree3 = create_tree(config3, data3)

ctx.translate(3, 3)
tree1.draw()

ctx.translate(310, 0)
tree2.draw()

ctx.translate(310, 0)
tree3.draw()

ctx.writesurface()