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 _del(self, handle="", node="", edge="", subg=""): """ Deletes items. Finds the item handle by type, if necessary, and removes the item from graph """ head, tail = '', '' if edge: head, tail = edge node, head, tail, subg = map(encode_page, [node, head, tail, subg]) self.changed = 1 if head and tail: item = gv.findedge(gv.findnode(handle, head), gv.findnode(handle, tail)) elif node: item = gv.findnode(handle, node) elif subg: item = gv.findsubg(handle, subg) elif handle: item = handle else: raise ValueError("No graph element or element type specified") if item: gv.rm(item)
def _get(self, handle, node="", edge="", subg=""): """ Gets Graphviz.<Type> items from parent graph (given by handle). """ # Default return value if item is not found head, tail = '', '' if edge: head, tail = edge node, head, tail, subg = map(encode_page, [node, head, tail, subg]) graphvizitem = None if head and tail: item = gv.findedge(gv.findnode(handle, head), gv.findnode(handle, tail)) if item: graphvizitem = GraphvizEdge(self, item) elif node: item = gv.findnode(handle, node) if item: graphvizitem = GraphvizNode(self, item) elif subg: item = gv.findsubg(handle, subg) if item: graphvizitem = GraphvizSubgraph(self, item) else: raise ValueError("No graph element type specified") return graphvizitem
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)
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")
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")