コード例 #1
0
def gravio(ctx, dotfile):
    '''
    Make a dot file using gravio of the connectivity.
    '''
    try:
        from gravio import gen, dotify
    except ImportError:
        click.echo('You need to install the "gravio" package')
        click.echo('See https://github.com/brettviren/gravio')
        sys.exit(1)
    from wirecell.util.wires import apa, graph
    desc = apa.Description()
    G, P = apa.graph(desc)

    # ['wire', 'wib', 'conductor', 'point', 'chip', 'face', 'plane', 'board', 'detector', 'apa', 'channel']
    node_colors = dict(wib='orange',
                       chip='red',
                       face='blue',
                       plane='purple',
                       board='green',
                       channel='pink')

    def skip_node(n):
        skip_types = ['point', 'wire', 'conductor']
        nt = G.nodes[n]['type']
        return nt in skip_types

    gr = gen.Graph("dune", "graph")
    gr.node(shape='point')

    for name, params in G.nodes.items():
        if skip_node(name):
            continue
        nt = G.nodes[name]['type']
        gr.node(name, shape='point', color=node_colors.get(nt, 'black'))

    #link_types = ['slot', 'submodule', 'pt', 'trace', 'wip', 'spot', 'side',
    #              'plane', 'place', 'address', 'segment', 'cable', 'channel']
    link_colors = dict(trace='pink',
                       spot='red',
                       side='blue',
                       plane='purple',
                       address='yellow',
                       cable='brown',
                       chanel='orange')
    seen_edges = set()
    for (n1, n2), params in G.edges.items():
        if skip_node(n1) or skip_node(n2):
            continue
        if (n1, n2) in seen_edges or (n2, n1) in seen_edges:
            continue
        seen_edges.add((n1, n2))
        link = params['link']
        gr.edge(n1, n2, color=link_colors.get(link, 'black'))

    d = dotify.Dotify(gr)
    dottext = str(d)
    open(dotfile, 'w').write(dottext)
コード例 #2
0
def main():
    from gravio import gen
    g = gen.Graph("sshgw", "digraph", label="")

    gravio.examples.sshgw.main(g)
    d = gravio.dotify.Dotify(g)
    filename = "test_examples_sshgw.dot"
    open(filename, "w").write(str(d))
    print("wrote:", filename)
コード例 #3
0
def main(which="felix"):
    from gravio import gen
    g = gen.Graph("dune",
                  "digraph",
                  label="DUNE",
                  nodesep='.1',
                  ranksep='2',
                  rankdir='LR',
                  style="filled,rounded",
                  color='white')

    meth = eval("main_" + which)
    meth(g)
    return g
コード例 #4
0
ファイル: test_simple.py プロジェクト: AG4GitHub/gravio
#!/usr/bin/env python

from gravio import gen, dotify

g = gen.Graph("simple", "digraph", label="my graph", style="filled")
assert g.typename == 'digraph'
n = g('node', 'a', color='red')
assert n.name == 'a'
g.node(None, shape='box')

n = g.node('b', color='blue', special=True)
assert n.attr['color'] == 'blue'
e = g('edge', 'a', 'b', style='dashed', weight=0.1)
assert e.tail == 'a'
assert e.head == 'b'
g.edge(style='dotted')
g.edge('a','c', color='green')
sg = g.subgraph('cluster_sg', style='solid', label="my subgraph")
assert sg.typename == 'subgraph'
sg.node('d')
g.edge('a','d')
print (g.name, g.typename, len(g.subgraphs))
print (g.nodes(color='red'))

g2 = gen.Graph("cluster_external","subgraph",label="external")
g2.edge("aa","bb")
g2.append(gen.Node("cc"))
g2.append(gen.Edge("aa","cc"))

g.append(g2)
e = g.edge("a","aa", constraint=False)