creates a visual.conf file (as a string)
    for the given document graph.

def create_visual_conf(docgraph, pointing_chains):
    """
    creates a visual.conf file (as a string)
    for the given document graph.
    """
    num_of_entities = len(pointing_chains)
    mapsize = max(3, min(12, num_of_entities)) # 3 <= mapsize <= 12
    colormap = brewer2mpl.get_map(name='Paired', map_type='Qualitative', number=mapsize)
    colors = range(mapsize) * int(math.ceil(num_of_entities / float(mapsize)))
    # recycle colors if we need more than 12
    endless_color_cycle = itertools.cycle(colors)

    ret_str = u'[drawing]\n\n'
    for chain in pointing_chains:
        background_color = colormap.hex_colors[endless_color_cycle.next()]
        for markable in chain:
            span_tokens = spanstring2tokens(docgraph, docgraph.node[markable][docgraph.ns+':span'])
            span_text = dg.tokens2text(docgraph, span_tokens)
            ascii_markable = unidecode(span_text)
            ret_str += u'{0}\tbgColor:{1}\n'.format(ascii_markable,
                                                  background_color)
    ret_str += '\n[labels]'
    return ret_str