Пример #1
0
def draw_host(g, aHost, aNodes, aLinks):
    clusterName = 'cluster_' + aHost

    gv.graph(g, clusterName)
    g1 = gv.findsubg(g, clusterName)
    gv.setv(g1, "label", aHost)
   # gv.setv(g1, "clusterMode", "local")

    #rank = "same"
   # gv.setv(g1, "rank", rank)

    # draw nodes
    aNodes1 = {}
    for key in aNodes:
        aName = aHost + key
        aType = aNodes[key]
        n = draw_node(g1, key, aName, aType)
        aNodes1[aName] = aName

    # draw edges
    #aLinks1 = {}
    for x in aLinks:
        (x1, x2) = x
        n1 = aHost + x1
        n2 = aHost + x2
        e = draw_edge(g1, n1, n2, aNodes1)
Пример #2
0
def draw_edge(g, x1, x2, aDict):
    if x1 in aDict and x2 in aDict:
        n2 = aDict[x2]
        n1 = aDict[x1]
        e = gv.edge(g, n1, n2)
        gv.setv(e, "dir", "none")
        return e
Пример #3
0
def draw_edge(g, x1, x2, aDict):
    if x1 in aDict and x2 in aDict:
        n2 = aDict[x2]
        n1 = aDict[x1]
        e = gv.edge(g, n1, n2)
        gv.setv(e, "dir", "none")
        return e
Пример #4
0
def draw_host(g, aHost, aNodes, aLinks):
    clusterName = 'cluster_' + aHost

    gv.graph(g, clusterName)
    g1 = gv.findsubg(g, clusterName)
    gv.setv(g1, "label", aHost)
    # gv.setv(g1, "clusterMode", "local")

    #rank = "same"
    # gv.setv(g1, "rank", rank)

    # draw nodes
    aNodes1 = {}
    for key in aNodes:
        aName = aHost + key
        aType = aNodes[key]
        n = draw_node(g1, key, aName, aType)
        aNodes1[aName] = aName

    # draw edges
    #aLinks1 = {}
    for x in aLinks:
        (x1, x2) = x
        n1 = aHost + x1
        n2 = aHost + x2
        e = draw_edge(g1, n1, n2, aNodes1)
 def setEdgeAttrs(self, _edge, _attr_dict, _type):
     import gv
     for _name, _value in _attr_dict[_type].items():
         if type(_value)==types.MethodType:
             gv.setv(_edge, _name, _value())
         else:
             gv.setv(_edge, _name, _value)
 def setNodeAttrs(self, _node, _attrs):
     import gv
     for _name, _value in _attrs.items():
         if type(_value)==types.MethodType:
             gv.setv(_node, _name, _value())
         else:
             gv.setv(_node, _name, _value)
 def setEdgeAttrs(self, _edge, _attr_dict, _type):
     import gv
     for _name, _value in _attr_dict[_type].items():
         if type(_value) == types.MethodType:
             gv.setv(_edge, _name, _value())
         else:
             gv.setv(_edge, _name, _value)
 def setNodeAttrs(self, _node, _attrs):
     import gv
     for _name, _value in _attrs.items():
         if type(_value) == types.MethodType:
             gv.setv(_node, _name, _value())
         else:
             gv.setv(_node, _name, _value)
Пример #9
0
    def add_link(self, link):

        color = link_colors.next()

        for option_uid in link.options:
            option = self.nodes[option_uid]
            gv.setv(option, 'style', 'filled')
            gv.setv(option, 'color', color)
Пример #10
0
    def add_link(self, link):

        color = link_colors.next()

        for option_uid in link.options:
            option = self.nodes[option_uid]
            gv.setv(option, 'style', 'filled')
            gv.setv(option, 'color', color)
Пример #11
0
def subgraphfun(graph,name,label):
    try:
        subgraph = subgraphs[name]
    except:
        subgraph = gv.graph(graph, 'cluster_' + name)
        gv.setv(subgraph, 'label', label)
        subgraphs[name] = subgraph

    return subgraph
Пример #12
0
def render_graph(g, filename, output_dot = None):
    gv.setv(g, 'center', 'true')
    gv.setv(g, 'fontname', 'helvetica')
    gv.layout(g, 'dot')
    
    if (output_dot):
        gv.write(g, output_dot)
    
    gv.render(g, 'png', filename) 
Пример #13
0
    def out_graph(self):
        if self.depth > 1:
            self.generate_graph(1,0)
        else:
            first_node = self.get_node(1,0)
            n = gv.node(self.G, first_node.string())
            gv.setv(n, "label", "%s|%d" % (first_node.string(), first_node.weight))

        gv.layout(self.G, 'dot')
        #gv.render(self.G, 'xlib')
        gv.write(self.G, "tree.dot")
Пример #14
0
def __graphviz_tree(tree, names, graph, curr_node_handle):
    for node in tree.nodes:
        if node.attribute:
            label = names[node.attribute][0]
        else:
            label = names[0][node.node_class]
        edge_label = names[tree.attribute][node.value]
        gv_child = gv.node(graph, label + str(id(node)))
        gv.setv(gv_child, "label", label)
        gv_edge = gv.edge(curr_node_handle, gv_child)
        gv.setv(gv_edge, "label", edge_label)
        __graphviz_tree(node, names, graph, gv_child)
Пример #15
0
    def export(self, graph, path, type):
        """
        Export the graph
        """
        dot = write(graph)
        gvv = gv.readstring(dot)
        gv.setv(gvv,'rankdir','LR')
        gv.layout(gvv,'dot')

        graphname = path + '/' + type + '.svg-' + str(time.time())
        gv.render(gvv, 'svg', graphname)
        return graphname
Пример #16
0
def mark():
    ok = False
    n = gv.firstnode(gr)
    while gv.ok(n):
        if gv.getv(n, 'color') == 'green':
            nh = gv.firsthead(n)
            while gv.ok(nh):
                if gv.getv(nh, 'color') != 'green':
                    gv.setv(nh, 'color', 'green')
                    ok = True
                nh = gv.nexthead(n, nh)
        n = gv.nextnode(gr, n)
    return ok
Пример #17
0
    def _setattrs(self, handle="",
                  edge="", node="", subg="", proto="",
                  **attrs):
        """ Sets attributes for item by handle or by name and type

        Finds the item handle by type, if necessary, and sets given
        attributes.
        """
        head, tail = '', ''
        if edge:
            head, tail = edge

        node, head, tail, subg = map(encode_page, [node, head, tail, subg])

        self.changed = 1

        if proto in ["node", "edge"]:
            # Gets handle when called from Subraphs.set()
            if subg:
                handle = gv.findsubg(self.handle, subg)
            # Called by self.set() and GraphvizSubgraph.set(), handle known
            item = getattr(gv, "proto%s" % proto)(handle)
            # print "item = gv.proto" + proto + "(g)"
        elif head and tail:
            item = gv.findedge(gv.findnode(handle, head),
                               gv.findnode(handle, tail))
            # print "item = gv.findedge(gv.findnode(g, '" + head + "')," + \
            #       "gv.findnode(g, '" + tail + "'))"
        elif node:
            item = gv.findnode(handle, node)
            # print "item = gv.findnode(g, '" + node + "')"
        elif subg:
            item = gv.findsubg(handle, subg)
            # print "item = gv.findsubg(g, '" + subg + "')"
        elif handle:
            item = handle
        else:
            raise ValueError("No graph element or element type specified")

        for key, elem in attrs.iteritems():
            if isinstance(elem, set):
                for e in elem:
                    key, e = map(encode_page, [key, e])
                    gv.setv(item, key, e)
            else:
                key, elem = map(encode_page, [key, elem])
                gv.setv(item, key, elem)
Пример #18
0
    def __draw_related_outside(self, graph, search_files):
        for search_file in search_files:
            if search_file not in self.__drawn_nodes:
                gv.node(graph, self.get_relative_path(search_file))
                self.__drawn_nodes.add(search_file)

            imported_by = self.index.get(search_file)

            if imported_by is None:
                continue

            imported_by = set(imported_by)

            squashed = get_squashed(imported_by, self.index) if len(imported_by) > 8 and self.__squash else []
            squashed = squashed if len(squashed) > 6 else []

            file_rel_path = self.get_relative_path(search_file)

            for imp in imported_by:
                if imp not in self.__drawn_nodes:
                    self.__drawn_nodes.add(imp)
                    if imp not in squashed:
                        gv.node(graph, self.get_relative_path(imp))

                if (imp, file_rel_path) not in self.__drawn_edges:
                    self.__drawn_edges.add((imp, file))
                    if imp not in squashed:
                        gv.edge(graph, self.get_relative_path(imp), file_rel_path)

            if squashed:
                name = '{} files importing {}'.format(len(squashed), file_rel_path)
                if name not in self.__drawn_nodes:
                    self.__drawn_nodes.add(name)
                    n = gv.node(graph, name)
                    gv.setv(n, 'fontsize', '25')
                    gv.setv(n, 'tooltip', '\n'.join(map(self.get_relative_path, squashed)))

                if (name, file_rel_path) not in self.__drawn_edges:
                    self.__drawn_edges.add((name, file_rel_path))
                    gv.edge(graph, name, file_rel_path)

            self.__depth += 1

            if self.__limit is None or self.__depth < self.__limit:
                self.__draw_related_outside(graph, imported_by)
Пример #19
0
def create_graph():
    logger.debug('Creating graph...')

    graph = gv.graph('xsls')
    gv.setv(graph, 'charset', 'utf-8')
    gv.setv(graph, 'rankdir', 'LR')

    item = gv.protoedge(graph)
    gv.setv(item, 'minlen', '10')
    gv.setv(item, 'dir', 'forward')

    return graph
Пример #20
0
 def __init__(self):
     self.root = collections.deque()
     self.root.append([Node(LEAF, 1, 1)])
     self.depth = 1
     #point to the last inserted
     self.last = 0
     #for draw
     self.G = gv.digraph("G")
     gv.setv(self.G, 'nodesep', '0.05')
     gv.setv(self.G, 'rankdir', 'TB')
     N = gv.protonode(self.G)
     gv.setv(N, 'shape', 'record')
     E = gv.protoedge(self.G)
     gv.setv(E, 'side', 'left')
Пример #21
0
def gv_layout(nodes, edges, mode="dot"):
    G = gv.graph("root")
    s = gv.graph(G, "test")
    for i in nodes:
        sg = "%02x %s" % (i, nodes[i][0])
        n = gv.node(s, sg)
        if nodes[i][0] in gv_colors:
            gv.setv(n, "color", gv_colors[nodes[i][0]])
            gv.setv(n, "style", "filled")

    for i in edges:
        if i[0] in nodes and i[1] in nodes:
            e = gv.edge(G, "%02x %s" % (i[0], nodes[i[0]][0]),
                        "%02x %s" % (i[1], nodes[i[1]][0]))
            gv.setv(e, "dir", "none")
    gv.layout(G, mode)
    gv.render(G)
    # for debugging purposes
    gv.render(G, 'svg', 'test.svg')
    devs = {}
    fn = gv.firstnode(G)
    try:
        devs[gv.nameof(fn)] = gv.getv(fn, "pos").split(",")
    except:
        print 'Failed in gv_render'
    for i in range(len(nodes) - 1):
        fn = gv.nextnode(G, fn)
        devs[gv.nameof(fn)] = gv.getv(fn, "pos").split(",")

    return devs
Пример #22
0
def gv_layout(nodes,edges,mode="dot"):
	G = gv.graph("root")
	s = gv.graph(G,"test")
	for i in nodes:
		sg = "%02x %s"%(i,nodes[i][0])
		n = gv.node(s,sg)
		if nodes[i][0] in gv_colors:
			gv.setv(n,"color",gv_colors[nodes[i][0]])
			gv.setv(n,"style","filled")

	for i in edges:
		if i[0] in nodes and i[1] in nodes:
			e = gv.edge(G,"%02x %s"%(i[0],nodes[i[0]][0]),"%02x %s"%(i[1],nodes[i[1]][0]))
			gv.setv(e,"dir","none")
	gv.layout(G, mode)
	gv.render(G)
# for debugging purposes
	gv.render(G,'svg','test.svg')
	devs = {}
	fn = gv.firstnode(G)
	try:
		devs[gv.nameof(fn)] = gv.getv(fn,"pos").split(",")
	except:
		print 'Failed in gv_render'
	for i in range(len(nodes)-1):
		fn = gv.nextnode(G,fn)
		devs[gv.nameof(fn)] = gv.getv(fn,"pos").split(",")

	return devs
Пример #23
0
def graph_from_parse_tree(root, same_level = False):
    def visit(node, graph, subgraph):
        if isinstance(node, Rule):
            gnode = gv.node(graph, str(id(node)))
            stylize_rule(gnode, node)
            
            for n in node.childs:
                visit(n, graph, subgraph)
                e = gv.edge(graph, str(id(node)), str(id(n)))
                stylize_edge(e)
        else: # Token
            gnode = gv.node(subgraph, str(id(node)))
            stylize_token(gnode, node)

    g = gv.digraph('graph')
    tg = gv.graph(g, 'token_graph')
    
    if (same_level):
        gv.setv(tg, 'rank', 'same')
        
    visit(root, g, tg)
    return g
Пример #24
0
    def add_node(self, fact):
        node = gv.node(self.graph, fact.uid.encode('utf-8'))
        gv.setv(node, 'shape', 'plaintext')
        gv.setv(node, 'label', self.create_label_for(fact).encode('utf-8'))
        gv.setv(node, 'fontsize', '10')

        self.nodes[fact.uid] = node

        return node
Пример #25
0
    def add_node(self, fact):
        node = gv.node(self.graph, fact.uid.encode('utf-8'))
        gv.setv(node, 'shape', 'plaintext')
        gv.setv(node, 'label', self.create_label_for(fact).encode('utf-8'))
        gv.setv(node, 'fontsize', '10')

        self.nodes[fact.uid] = node

        return node
Пример #26
0
def draw_node(g, key, aName, aType):
    global aColor

    n = gv.node(g, aName)
    # set node show name
    gv.setv(n, "label", key)

    gv.setv(n, "style", "filled")
    gv.setv(n, "shape", "box")

   # if aType == "ovs":
   #    gv.setv(n, "fixedsize", "true")
   #    gv.setv(n, "width", "3")
   # elif aType == "br":
   #    gv.setv(n, "fixedsize", "true")
   #    gv.setv(n, "width", "3")
   # elif aType == "eth":
   #     e = gv.edge(n, "swith")
   #     gv.setv(e, "dir", "none")

    #if aType == "eth":
    #   e = gv.edge(n, "swith")
    #   gv.setv(e, "dir", "none")
    #   gv.setv(e, "style", "dashed")

    if key == "br-int":
       gv.setv(n, "width", "10")

    # set color
    if aType in aColor:
       c = aColor[aType]
    else:
       c = "lightgrey"
    gv.setv(n, "color", c)

    return n
Пример #27
0
def draw_node(g, key, aName, aType):
    global aColor

    n = gv.node(g, aName)
    # set node show name
    gv.setv(n, "label", key)

    gv.setv(n, "style", "filled")
    gv.setv(n, "shape", "box")

    # if aType == "ovs":
    #    gv.setv(n, "fixedsize", "true")
    #    gv.setv(n, "width", "3")
    # elif aType == "br":
    #    gv.setv(n, "fixedsize", "true")
    #    gv.setv(n, "width", "3")
    # elif aType == "eth":
    #     e = gv.edge(n, "swith")
    #     gv.setv(e, "dir", "none")

    #if aType == "eth":
    #   e = gv.edge(n, "swith")
    #   gv.setv(e, "dir", "none")
    #   gv.setv(e, "style", "dashed")

    if key == "br-int":
        gv.setv(n, "width", "10")

    # set color
    if aType in aColor:
        c = aColor[aType]
    else:
        c = "lightgrey"
    gv.setv(n, "color", c)

    return n
Пример #28
0
    def draw(self, graph, nodes, nesting):
        subgraph = gv.graph(graph, self.uid.encode('utf-8'))
        gv.setv(subgraph, 'label', self.uid.encode('utf-8'))
        # gv.setv(subgraph, 'rank', 'same')
        gv.setv(subgraph, 'shape', 'box')
        gv.setv(subgraph, 'bgcolor', self.color % (150+nesting*25) if '%' in self.color else self.color)

        for node_uid in self.members:
            if node_uid in nodes:
                gv.node(subgraph, node_uid.encode('utf-8'))

        for child in self.children:
            child.draw(subgraph, nodes, nesting=nesting+1)
Пример #29
0
    def draw(self, graph, nodes, nesting):
        subgraph = gv.graph(graph, self.uid.encode('utf-8'))
        gv.setv(subgraph, 'label', self.uid.encode('utf-8'))
        # gv.setv(subgraph, 'rank', 'same')
        gv.setv(subgraph, 'shape', 'box')
        gv.setv(subgraph, 'bgcolor', self.color % (150+nesting*25) if '%' in self.color else self.color)

        for node_uid in self.members:
            if node_uid in nodes:
                gv.node(subgraph, node_uid.encode('utf-8'))

        for child in self.children:
            child.draw(subgraph, nodes, nesting=nesting+1)
Пример #30
0
	def set_style(self):
		node_style = [('style', 'filled'), ('fillcolor', 'royalblue'), ('penwidth', '0'), 
				('shape', 'box'), ('width', '.6'), ('height', '.05'), ('fontname', 'Ubuntu'),
				('fontsize', '10'), ('fontcolor', 'white')]
		n = gv.protonode(self.gr)
		for (a, v) in node_style:
			gv.setv(n, a, v)
		
		edge_style = [('fontname', 'Ubuntu-bold'), ('fontsize', '8'), ('penwidth', '1'), ('color', 'gray73')]
		e = gv.protoedge(self.gr)
		for (a, v) in edge_style:
			gv.setv(e, a, v)

		graph_style = [('size', '1000,600'), ('ratio', '0.6'), ('epsilon', '0.001'), ('maxiter', '10000')]
		for (a, v) in graph_style:
			gv.setv(self.gr, a, v)

		return
Пример #31
0
    def set_style(self):
        node_style = [('style', 'filled'), ('fillcolor', 'royalblue'),
                      ('penwidth', '0'), ('shape', 'box'), ('width', '.6'),
                      ('height', '.05'), ('fontname', 'Ubuntu'),
                      ('fontsize', '10'), ('fontcolor', 'white')]
        n = gv.protonode(self.gr)
        for (a, v) in node_style:
            gv.setv(n, a, v)

        edge_style = [('fontname', 'Ubuntu-bold'), ('fontsize', '8'),
                      ('penwidth', '1'), ('color', 'gray73')]
        e = gv.protoedge(self.gr)
        for (a, v) in edge_style:
            gv.setv(e, a, v)

        graph_style = [('size', '1000,600'), ('ratio', '0.6'),
                       ('epsilon', '0.001'), ('maxiter', '10000')]
        for (a, v) in graph_style:
            gv.setv(self.gr, a, v)

        return
Пример #32
0
 def add_node(self, node_id, label):
     n = gv.node(self.gr, node_id)
     gv.setv(n, 'label', label)
     return
Пример #33
0
 def add_edge(self, node1, node2, value):
     length = self.minlen + pow((self.maxv - value), 2) * self.dx
     e = gv.edge(self.gr, node1, node2)
     gv.setv(e, 'len', str(length))
     gv.setv(e, 'label', str(value))
     return
Пример #34
0
 def render(self, form='png', filename=None, label=None):
     gv.layout(self.gr, 'neato')
     if label: gv.setv(self.gr, 'label', label)
     gv.render(self.gr, form)
     return
Пример #35
0
# display the kernel module dependencies

# author: Michael Hohn <*****@*****.**>
#  based on: modgraph.tcl by John Ellson <*****@*****.**>

import sys
import gv

modules = open("/proc/modules", 'r').readlines()

G = gv.digraph("G")
N = gv.protonode(G)
E = gv.protoedge(G)

gv.setv(G, 'rankdir', 'LR')
gv.setv(G, 'nodesep', '0.05')
gv.setv(N, 'shape', 'box')
gv.setv(N, 'width', '0')
gv.setv(N, 'height', '0')
gv.setv(N, 'margin', '.03')
gv.setv(N, 'fontsize', '8')
gv.setv(N, 'fontname', 'helvetica')
gv.setv(E, 'arrowsize', '.4')

for rec in modules:
   fields = rec.split(' ')
   n = gv.node(G, fields[0])
   for usedby in fields[3].split(','):
      if (usedby != '-') & (usedby != ''):
         gv.edge(n, gv.node(G, usedby))
Пример #36
0
	def add_edge(self, node1, node2, value):
		length = self.minlen + pow((self.maxv - value), 2) * self.dx
		e = gv.edge(self.gr, node1, node2)
		gv.setv(e, 'len', str(length))
		gv.setv(e, 'label', str(value))
		return
# display the kernel module dependencies

# author: Michael Hohn <*****@*****.**>
#  based on: modgraph.tcl by John Ellson <*****@*****.**>

import sys
import gv

modules = open("/proc/modules", 'r').readlines()

G = gv.digraph("G")
N = gv.protonode(G)
E = gv.protoedge(G)

gv.setv(G, 'rankdir', 'LR')
gv.setv(G, 'nodesep', '0.05')
gv.setv(N, 'shape', 'box')
gv.setv(N, 'width', '0')
gv.setv(N, 'height', '0')
gv.setv(N, 'margin', '.03')
gv.setv(N, 'fontsize', '8')
gv.setv(N, 'fontname', 'helvetica')
gv.setv(E, 'arrowsize', '.4')

for rec in modules:
    fields = rec.split(' ')
    n = gv.node(G, fields[0])
    for usedby in fields[3].split(','):
        if (usedby != '-') & (usedby != ''):
            gv.edge(n, gv.node(G, usedby))
Пример #38
0
    def _add_edge(self, jump):
        node = gv.node(self.graph, jump.uid.encode('utf-8'))

        gv.setv(node, 'shape', 'plaintext')
        gv.setv(node, 'label', self.create_label_for(jump).encode('utf-8'))
        gv.setv(node, 'fontsize', '10')

        self.nodes[jump.uid] = node

        edge_1 = gv.edge(self.nodes[jump.state_from], node)
        edge_2 = gv.edge(node, self.nodes[jump.state_to])

        gv.setv(edge_1, 'dir', 'none')
        gv.setv(edge_1, 'tailport', jump.state_from.encode('utf-8'))
        gv.setv(edge_1, 'headport', jump.uid.encode('utf-8'))
        gv.setv(edge_1, 'weight', '40')
        gv.setv(edge_1, 'minlen', '1')

        gv.setv(edge_2, 'tailport', jump.uid.encode('utf-8'))
        gv.setv(edge_2, 'headport', jump.state_to.encode('utf-8'))
        gv.setv(edge_2, 'weight', '40')
        gv.setv(edge_2, 'minlen', '1')

        if isinstance(jump, facts.Option):
            gv.setv(edge_1, 'style', 'dotted')
            gv.setv(edge_2, 'style', 'dotted')

        if isinstance(jump, facts.Answer):
            pass
Пример #39
0
    s2 = m1.group(3)
    m2 = r2.match(s2)
    s2_name = m2.group(1)
    s2_cont = filter_cont(m2.group(2))
    if not s2_cont in ls:
        ls.append(s2_cont)
        ds[s2_name] = s2_cont

    t = m1.group(2)
    lt.append((s1_cont, s2_cont, t))

G = gv.graph("G")
N = gv.protonode(G)
E = gv.protoedge(G)
gv.setv(N, 'shape', 'box')

dNodes = {}
for node in ls:
    name = node
    dNodes[name] = gv.node(G, name)

for k in lt:
    edge = gv.edge(dNodes[k[0]], dNodes[k[1]])
    gv.setv(edge, 'label', k[2])
    gv.setv(edge, 'dir', "forward")

gv.layout(G, 'dot')
#gv.render(G, 'xlib')
gv.render(G, 'pdf', sys.argv[2])
def GetGVData(names,map,contents=None,type="xdot",node_shape='record',debug=0,output_graphic_filename=None,aliases=None):
	large_mode=False
	if len(names)>800:
		large_mode=True

	if not aliases:
		aliases={}
	if not node_shape:
		node_shape="record"
	if not contents:
		contents={}
	root_name="Root"
	if len(names)>0:
		root_name=str(names[0])
	g=gv.digraph(root_name)
	layout_alrogithm='dot'
	node_color=None
	if large_mode:
		node_shape='point'
		gv.setv(g,"model","subset")
		layout_alrogithm='neato'
		layout_alrogithm='twopi'
		node_color='red'
		debug=1
	gv.setYinvert(g)
	name2node={}
	edges=[]

	method='plain'
	for name in names:
		if aliases.has_key(name):
			display_name=str(aliases[name])
		else:
			display_name=str(name)

		if method=='plain':
			node_str=''
			if contents.has_key(name):
				for i in range(0,len(contents[name]),1):
					[address,op,[op1,op2],comment]=contents[name][i]
					node_str+=str(op)
					if op1:
						node_str+=" "+str(op1)
					if op2:
						node_str+=" "+str(op2)
					node_str+='\r\n'
				display_name="{"+display_name+"|"+node_str+"}"
			node=gv.node(g,display_name)
			name2node[name]=node
			gv.setv(node,"shape",node_shape)
			if node_color:
				gv.setv(node,"color",node_color)
	
		elif method=='layered': #dirty look
			node_str=''
			if contents.has_key(name):
				for i in range(0,len(contents[name]),1):
					[address,op,[op1,op2],comment]=contents[name][i]
					node_str+="|{"+MakeLenStr(str(op),5)
					if op1:
						node_str+="|"+MakeLenStr(str(op1),5)
					if op2:
						node_str+="|"+MakeLenStr(str(op2),5)
					node_str+='}'
			node=gv.node(g,"{"+display_name+node_str+"}")
			name2node[name]=node
			gv.setv(node,"shape","record")

		elif method=='subgraph': #Too big
			subg=gv.graph(g,'cluster'+display_name)
			gv.setv(subg,"label",display_name)
			gv.setv(subg,"color","black")
	
			node=gv.node(subg,display_name)
			name2node[name]=node
			nodes.append(node)
			gv.setv(node,"shape","record")
	
			node_str=''
			if contents.has_key(name):
				src=node
				for i in range(0,len(contents[name]),1):
					[address,op,[op1,op2],comment]=contents[name][i]
					node_str=hex(address)+"|"+str(op)
					if op1:
						node_str+="|"+str(op1)
					if op2:
						node_str+="|"+str(op2)
					node=gv.node(subg,node_str)
					nodes.append(node)
					gv.setv(node,"shape","record")
					#edge=gv.edge(src,node)
					src=node

	for name in names:
		if map.has_key(name):
			for dst_name in map[name]:
				if name2node.has_key(name) and name2node.has_key(dst_name):
					edge=gv.edge(name2node[name],name2node[dst_name])
					gv.setv(edge,"invis","")
					edges.append([name,dst_name,edge])
	if debug:
		print 'Start layout'
		start_time=time.time()
	gv.layout(g,layout_alrogithm)
	if debug:
		end_time=time.time()
		elapsed_time=end_time-start_time
		print 'End layout',end_time-start_time

	prefix=''
	for i in range(0,5,1):
		prefix+=hex(random.randint(0,9999))
	
	gv.render(g,type,".temp.dat")
	if debug:
		img_filename=prefix+".jpg"
		dot_filename=prefix+".dot"
		print 'writing',img_filename
		gv.render(g,"jpg",img_filename) #For debugging
		gv.render(g,"dot",dot_filename) #For debugging
		print 'done writing',img_filename

	if output_graphic_filename:
		gv.render(g,"jpg",output_graphic_filename) #For debugging

	node_attrs_map={}
	edge_attrs_maps={}
	for name in name2node.keys():
		node_attrs=GetAttrs(name2node[name])
		node_attrs_map[name]=node_attrs

	for [src,dst,edge] in edges:
		line_attrs=GetAttrs(edge)
		if not edge_attrs_maps.has_key(src):
			edge_attrs_maps[src]={}
		edge_attrs_maps[src][dst]=line_attrs

	###### Get maxx,maxy
	maxx=0
	maxy=0
	graph_attrs=GetAttrs(g)
	if graph_attrs.has_key('bb'):
		[x1str,y1str,x2str,y2str]=re.compile(",").split(graph_attrs['bb'])
		x1=int(x1str)
		y1=int(y1str)
		x2=int(x2str)
		y2=int(y2str)
		maxx=x1
		if x2>maxx:
			maxx=x2
		maxy=y1
		if y2>maxy:
			maxy=y2
	maxx+=200
	maxy+=200
	
	return [[maxx,maxy],node_attrs_map,edge_attrs_maps]

#################### End of Graphviz processor ###################
##################################################################
Пример #41
0
        gv.setv(subgraph, 'label', label)
        subgraphs[name] = subgraph

    return subgraph


graph = gv.digraph('filegraph')


for dirpath, dirnames, filenames in os.walk('src'):
    
    try:
        subgraph = subgraphs[clean(dirpath)]
    except:
        subgraph = gv.graph(graph, 'cluster_' + clean(dirpath))
        gv.setv(subgraph, 'label', dirpath)
        subgraphs[clean(dirpath)] = subgraph
    
    print clean(dirpath)
    print dirnames
    print filenames

    for filename in filenames:
        node = gv.node(subgraph, clean(filename))
        gv.setv(node, 'label', filename)


    for dirname in dirnames:
        subgraphfun(subgraph, clean(os.path.join(dirpath,dirname)), dirname)

gv.write(graph, 'graph.dot')
Пример #42
0
	def render(self, form='png', filename=None, label=None):
		gv.layout(self.gr, 'neato')
		if label: gv.setv(self.gr, 'label', label)
		gv.render(self.gr, form)
		return
Пример #43
0
    def _add_edge(self, jump):
        node = gv.node(self.graph, jump.uid.encode('utf-8'))

        gv.setv(node, 'shape', 'plaintext')
        gv.setv(node, 'label', self.create_label_for(jump).encode('utf-8'))
        gv.setv(node, 'fontsize', '10')

        self.nodes[jump.uid] = node

        edge_1 = gv.edge(self.nodes[jump.state_from], node)
        edge_2 = gv.edge(node, self.nodes[jump.state_to])

        gv.setv(edge_1, 'dir', 'none')
        gv.setv(edge_1, 'tailport', jump.state_from.encode('utf-8'))
        gv.setv(edge_1, 'headport', jump.uid.encode('utf-8'))
        gv.setv(edge_1, 'weight', '40')
        gv.setv(edge_1, 'minlen', '1')

        gv.setv(edge_2, 'tailport', jump.uid.encode('utf-8'))
        gv.setv(edge_2, 'headport', jump.state_to.encode('utf-8'))
        gv.setv(edge_2, 'weight', '40')
        gv.setv(edge_2, 'minlen', '1')

        if isinstance(jump, facts.Option):
            gv.setv(edge_1, 'style', 'dotted')
            gv.setv(edge_2, 'style', 'dotted')

        if isinstance(jump, facts.Answer):
            pass
Пример #44
0
 def _add_empty_edge(self, jump):
     edge = gv.edge(self.nodes[jump.state_from], self.nodes[jump.state_to])
     gv.setv(edge, 'headport', jump.state_to.encode('utf-8'))
     gv.setv(edge, 'tailport', jump.state_from.encode('utf-8'))
     gv.setv(edge, 'weight', '20')
     gv.setv(edge, 'minlen', '1')
Пример #45
0
 def _add_empty_edge(self, jump):
     edge = gv.edge(self.nodes[jump.state_from], self.nodes[jump.state_to])
     gv.setv(edge, 'headport', jump.state_to.encode('utf-8'))
     gv.setv(edge, 'tailport', jump.state_from.encode('utf-8'))
     gv.setv(edge, 'weight', '20')
     gv.setv(edge, 'minlen', '1')
Пример #46
0
def draw_note(g):
    global aColor
    gv.graph(g, "cluster_0")
    g1 = gv.findsubg(g, "cluster_0")
    gv.setv(g1, "color", "white")

    aNodes = []
    length = 0
    for key in aColor:
        c = aColor[key]
        n = gv.node(g1, key)
        gv.setv(n, "shape", "box")
        gv.setv(n, "style", "filled")
        gv.setv(n, "color", c)
        gv.setv(n, "label", key)
        aNodes.append(key)
        length = length + 1

    for i in range(0, length - 1):
        e = gv.edge(g1, aNodes[i], aNodes[i + 1])
        gv.setv(e, "style", "invis")
Пример #47
0
"""
display the kernel module dependencies

author: Michael Hohn <*****@*****.**>
 based on: modgraph.tcl by John Ellson <*****@*****.**>
"""

import gv  # pylint: disable=import-error

modules = open("/proc/modules", "r").readlines()

G = gv.digraph("G")
N = gv.protonode(G)
E = gv.protoedge(G)

gv.setv(G, "rankdir", "LR")
gv.setv(G, "nodesep", "0.05")
gv.setv(N, "shape", "box")
gv.setv(N, "width", "0")
gv.setv(N, "height", "0")
gv.setv(N, "margin", ".03")
gv.setv(N, "fontsize", "8")
gv.setv(N, "fontname", "helvetica")
gv.setv(E, "arrowsize", ".4")

for rec in modules:
    fields = rec.split(" ")
    n = gv.node(G, fields[0])
    for usedby in fields[3].split(","):
        if usedby not in ("-", ""):
            gv.edge(n, gv.node(G, usedby))
Пример #48
0
	def add_node(self, node_id, label):
		n = gv.node(self.gr, node_id)
		gv.setv(n, 'label', label)
		return
Пример #49
0
def graph_draw(g,
               pos=None,
               size=(15, 15),
               pin=False,
               layout="neato",
               maxiter=None,
               ratio="fill",
               overlap=False,
               splines=False,
               mode="major",
               vsize=0.1,
               penwidth=1.0,
               eweight=None,
               ewidth=None,
               gprops={},
               vprops={},
               eprops={},
               vcolor=None,
               ecolor=None,
               vcmap=matplotlib.cm.jet,
               vnorm=True,
               ecmap=matplotlib.cm.jet,
               enorm=True,
               output="",
               output_format="auto",
               returngv=False,
               fork=False,
               seed=0):
    """Draw a graph using graphviz."""

    if output != "":
        output = os.path.expanduser(output)
        # check opening file for writing, since graphview will bork if it is not
        # possible to open file
        if os.path.dirname(output) != "" and \
               not os.access(os.path.dirname(output), os.W_OK):
            raise IOError("cannot write to " + os.path.dirname(output))

    if g.is_directed():
        gvg = gv.digraph("G")
    else:
        gvg = gv.graph("G")

    # main graph properties
    gv.setv(gvg, "outputorder", "edgesfirst")
    gv.setv(gvg, "mode", mode)
    if overlap == False:
        if layout == "neato" and mode == "ipsep":
            overlap = "ipsep"
        else:
            overlap = "false"
    else:
        overlap = "true"
    if isinstance(overlap, str):
        gv.setv(gvg, "overlap", overlap)
    if splines:
        gv.setv(gvg, "splines", "true")
    gv.setv(gvg, "ratio", str(ratio))
    gv.setv(gvg, "size",
            "%f,%f" % (size[0] / 2.54, size[1] / 2.54))  # centimeters
    if maxiter != None:
        gv.setv(gvg, "maxiter", str(maxiter))
    if seed != 0:
        if type(seed) == int:
            gv.setv(gvg, "start", "%d" % seed)
        else:
            gv.setv(gvg, "start", seed)

    # apply all user supplied properties
    for k, val in gprops.iteritems():
        if isinstance(val, PropertyMap):
            gv.setv(gvg, k, str(val[g]))
        else:
            gv.setv(gvg, k, str(val))

    # normalize color properties
    if vcolor != None and not isinstance(vcolor, str):
        minmax = [float("inf"), -float("inf")]
        for v in g.vertices():
            c = vcolor[v]
            minmax[0] = min(c, minmax[0])
            minmax[1] = max(c, minmax[1])
        if minmax[0] == minmax[1]:
            minmax[1] += 1
        if vnorm:
            vnorm = matplotlib.colors.normalize(vmin=minmax[0], vmax=minmax[1])

    if ecolor != None and not isinstance(ecolor, str):
        minmax = [float("inf"), -float("inf")]
        for e in g.edges():
            c = ecolor[e]
            minmax[0] = min(c, minmax[0])
            minmax[1] = max(c, minmax[1])
        if minmax[0] == minmax[1]:
            minmax[1] += 1
        if enorm:
            enorm = matplotlib.colors.normalize(vmin=minmax[0], vmax=minmax[1])

    nodes = []
    edges = []

    # add nodes
    for v in g.vertices():
        n = gv.node(gvg, str(g.vertex_index[v]))
        if type(vsize) != tuple:
            vw = vh = vsize
        else:
            vw, vh = vsize
        if type(vw) == PropertyMap:
            vw = vw[v]
        if type(vh) == PropertyMap:
            vh = vh[v]

        if type(vw) == str and vw == "in":
            vw = v.in_degree()
        if type(vw) == str and vw == "out":
            vw = v.out_degree()
        if type(vw) == str and vw == "total":
            vw = v.in_degree() + v.out_degree()

        if type(vh) == str and vh == "in":
            vh = v.in_degree()
        if type(vh) == str and vh == "out":
            vh = v.out_degree()
        if type(vh) == str and vh == "total":
            vh = v.in_degree() + v.out_degree()

        gv.setv(n, "width", "%g" % vw)
        gv.setv(n, "height", "%g" % vh)
        gv.setv(n, "style", "filled")
        gv.setv(n, "color", "black")
        # apply color
        if vcolor != None:
            if isinstance(vcolor, str):
                gv.setv(n, "fillcolor", vcolor)
            else:
                color = tuple(
                    [int(c * 255.0) for c in vcmap(vnorm(vcolor[v]))])
                gv.setv(n, "fillcolor", "#%.2x%.2x%.2x%.2x" % color)
        else:
            gv.setv(n, "fillcolor", "red")
        gv.setv(n, "label", "")

        # user supplied position
        if pos != None:
            gv.setv(n, "pos", "%f,%f" % (pos[0][v], pos[1][v]))
            gv.setv(n, "pin", str(pin))

        # apply all user supplied properties
        for k, val in vprops.iteritems():
            if isinstance(val, PropertyMap):
                gv.setv(n, k, str(val[v]))
            else:
                gv.setv(n, k, str(val))
        nodes.append(n)
    for e in g.edges():
        ge = gv.edge(nodes[g.vertex_index[e.source()]],
                     nodes[g.vertex_index[e.target()]])
        gv.setv(ge, "arrowsize", "0.3")
        if g.is_directed():
            gv.setv(ge, "arrowhead", "vee")
        # apply color
        if ecolor != None:
            if isinstance(ecolor, str):
                gv.setv(ge, "color", ecolor)
            else:
                color = tuple(
                    [int(c * 255.0) for c in ecmap(enorm(ecolor[e]))])
                gv.setv(ge, "color", "#%.2x%.2x%.2x%.2x" % color)

        # apply weight
        if eweight != None:
            if isinstance(eweight, PropertyMap):
                gv.setv(ge, "weight", str(eweight[e]))
            else:
                gv.setv(ge, "weight", str(eweight))

        # apply width
        if ewidth != None:
            if isinstance(ewidth, PropertyMap):
                gv.setv(ge, "penwidth", str(ewidth[e]))
            else:
                gv.setv(ge, "penwidth", str(ewidth))

        # apply all user supplied properties
        for k, v in eprops.iteritems():
            if isinstance(v, PropertyMap):
                gv.setv(ge, k, str(v[e]))
            else:
                gv.setv(ge, k, str(v))
        edges.append(ge)

    gv.layout(gvg, layout)
    gv.render(gvg, "dot", "/dev/null")  # retrieve postitions

    if pos == None:
        pos = (g.new_vertex_property("double"),
               g.new_vertex_property("double"))
    for n in xrange(0, len(nodes)):
        p = gv.getv(nodes[n], "pos")
        p = p.split(",")
        pos[0][g.vertex(n)] = float(p[0])
        pos[1][g.vertex(n)] = float(p[1])

    if output_format == "auto":
        if output == "":
            output_format = "xlib"
        else:
            output_format = output.split(".")[-1]

    # if using xlib we need to fork the process, otherwise good ol' graphviz
    # will call exit() when the window is closed
    if output_format == "xlib" or fork:
        pid = os.fork()
        if pid == 0:
            gv.render(gvg, output_format, output)
            os._exit(0)  # since we forked, it's good to be sure
        if output_format != "xlib":
            os.wait()
    else:
        gv.render(gvg, output_format, output)

    if returngv:
        return pos, gv
    else:
        gv.rm(gvg)
        del gvg
        return pos
Пример #50
0
#!/usr/bin/python

import gv

g = gv.digraph("G")
print gv.setv(g, "aaa", "xxx")
print gv.getv(g, "aaa")
n = gv.node(g, "hello")
print gv.getv(n, "label")
print gv.setv(n, "aaa", "xxx")
print gv.getv(n, "aaa")
m = gv.node(g, "world")
print gv.getv(m, "aaa")
e = gv.edge(n, m)
print gv.setv(e, "aaa", "xxx")
print gv.getv(e, "aaa")
gv.rm(e)
gv.rm(m)
gv.rm(n)
gv.rm(g)

g = gv.readstring("digraph G {a->b}")
gv.rm(g)

g = gv.read("hello.gv")
gv.layout(g, "dot")
gv.render(g, "png", "hello.png")
gv.rm(g)
Пример #51
0
def draw_note(g):
    global aColor
    gv.graph(g, "cluster_0")
    g1 = gv.findsubg(g, "cluster_0")
    gv.setv(g1, "color", "white")

    aNodes = []
    length = 0
    for key in aColor:
        c = aColor[key]
        n = gv.node(g1, key)
        gv.setv(n, "shape", "box")
        gv.setv(n, "style", "filled")
        gv.setv(n, "color", c)
        gv.setv(n, "label", key)
        aNodes.append(key)
        length =  length +1

    for i in range(0, length-1):
        e = gv.edge(g1, aNodes[i], aNodes[i+1])
        gv.setv(e, "style", "invis")
Пример #52
0
#!/usr/bin/env python3

import gv  # pylint: disable=import-error

g = gv.digraph("G")
print(gv.setv(g, "aaa", "xxx"))
print(gv.getv(g, "aaa"))
n = gv.node(g, "hello")
print(gv.getv(n, "label"))
print(gv.setv(n, "aaa", "xxx"))
print(gv.getv(n, "aaa"))
m = gv.node(g, "world")
print(gv.getv(m, "aaa"))
e = gv.edge(n, m)
print(gv.setv(e, "aaa", "xxx"))
print(gv.getv(e, "aaa"))
gv.rm(e)
gv.rm(m)
gv.rm(n)
gv.rm(g)

g = gv.readstring("digraph G {a->b}")
gv.rm(g)

g = gv.read("hello.gv")
gv.layout(g, "dot")
gv.render(g, "png", "hello.png")
gv.rm(g)