Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# checking filename and converting appropriately
if filename == None:
filename = 'computational_graph.png'
if method != 'dot' and method != 'circo':
method = 'dot'
name, extension = filename.split('.')
if extension != 'png' and extension != 'svg':
print 'Only *.png or *.svg are supported formats!'
print 'Using *.png now'
extension = 'png'
print 'name=',name, 'extension=', extension
# setting the style for the nodes
A = pygraphviz.agraph.AGraph(directed=True, strict = False)
A.node_attr['fillcolor']="#000000"
A.node_attr['shape']='rect'
A.node_attr['width']='0.5'
A.node_attr['height']='0.5'
A.node_attr['fontcolor']='#ffffff'
A.node_attr['style']='filled'
A.node_attr['fixedsize']='true'
# build graph
for f in self.functionList:
if f.type == 'var':
A.add_node(f.id)
continue
for a in numpy.ravel(f.args):
A.add_edge(a.id, f.id)
#e = A.get_edge(a.source.id, f.id)
if orientation != 'LR' and orientation != 'TD' :
orientation = 'TD'
if method != 'dot' and method != 'circo':
method = 'dot'
name, extension = filename.split('.')
if extension != 'png' and extension != 'svg':
print 'Only *.png or *.svg are supported formats!'
print 'Using *.png now'
extension = 'png'
print 'name=',name, 'extension=', extension
# setting the style for the nodes
A = pygraphviz.agraph.AGraph(directed=True, strict = False, rankdir = orientation)
A.node_attr['fillcolor']= '#ffffff'
A.node_attr['shape']='rect'
A.node_attr['width']='0.5'
A.node_attr['height']='0.5'
A.node_attr['fontcolor']="#000000"
A.node_attr['style']='filled'
A.node_attr['fixedsize']='true'
# build graph
for f in self.functionList:
if f.type == 'var' or f.type == 'const':
A.add_node(f.id)
continue
for a in numpy.ravel(f.args):
A.add_edge(a.id, f.id)
def intermediary_to_schema(tables, relationships, output):
""" Transforms and save the intermediary representation to the file chosen. """
from pygraphviz.agraph import AGraph
dot_file = _intermediary_to_dot(tables, relationships)
graph = AGraph()
graph = graph.from_string(dot_file)
extension = output.split('.')[-1]
graph.draw(path=output, prog='dot', format=extension)
def intermediary_to_schema(tables, relationships, output):
""" Transforms and save the intermediary representation to the file chosen. """
dot_file = _intermediary_to_dot(tables, relationships)
graph = AGraph()
graph = graph.from_string(dot_file)
extension = output.split('.')[-1]
graph.draw(path=output, prog='dot', format=extension)
# checking filename and converting appropriately
if filename is None:
filename = 'computational_graph.png'
if method != 'dot' and method != 'circo':
method = 'dot'
name, extension = filename.split('.')
if extension != 'png' and extension != 'svg':
print('Only *.png or *.svg are supported formats!')
print('Using *.png now')
extension = 'png'
print('name=',name, 'extension=', extension)
# setting the style for the nodes
A = pygraphviz.agraph.AGraph(directed=True, strict = False)
A.node_attr['fillcolor']="#000000"
A.node_attr['shape']='rect'
A.node_attr['width']='0.5'
A.node_attr['height']='0.5'
A.node_attr['fontcolor']='#ffffff'
A.node_attr['style']='filled'
A.node_attr['fixedsize']='true'
# build graph
for f in self.functionList:
if f.type == 'var' or f.type=='const' or f.type=='id':
A.add_node(f.id)
continue
for a in numpy.ravel(f.args):
A.add_edge(a.id, f.id)
#e = A.get_edge(a.source.id, f.id)
if orientation != 'LR' and orientation != 'TD' :
orientation = 'TD'
if method != 'dot' and method != 'circo':
method = 'dot'
name, extension = filename.split('.')
if extension != 'png' and extension != 'svg':
print 'Only *.png or *.svg are supported formats!'
print 'Using *.png now'
extension = 'png'
print 'name=',name, 'extension=', extension
# setting the style for the nodes
A = pygraphviz.agraph.AGraph(directed=True, strict = False, rankdir = orientation)
A.node_attr['fillcolor']= '#ffffff'
A.node_attr['shape']='rect'
A.node_attr['width']='0.5'
A.node_attr['height']='0.5'
A.node_attr['fontcolor']="#000000"
A.node_attr['style']='filled'
A.node_attr['fixedsize']='true'
# build graph
for f in self.functionList:
if f.type == 'var' or f.type == 'const':
A.add_node(f.id)
continue
for a in numpy.ravel(f.args):
A.add_edge(a.id, f.id)
"""
Plots a graph in graphviz dot notation.
:param graph: the dot notation graph
:type graph: str
:param filename: the (optional) file to save the generated plot to. The extension determines the file format.
:type filename: str
"""
if not plot.pygraphviz_available:
logger.error("Pygraphviz is not installed, cannot generate graph plot!")
return
if not plot.PIL_available:
logger.error("PIL is not installed, cannot display graph plot!")
return
agraph = AGraph(graph)
agraph.layout(prog='dot')
if filename is None:
filename = tempfile.mktemp(suffix=".png")
agraph.draw(filename)
image = Image.open(filename)
image.show()
def to_directed(self, **kwds):
"""Return directed copy of graph.
Each undirected edge u-v is represented as two directed
edges u->v and v->u.
"""
if not self.directed:
D = AGraph(strict=self.strict, directed=True)
D.graph_attr.update(self.graph_attr)
D.node_attr.update(self.node_attr)
D.edge_attr.update(self.edge_attr)
for n in self.nodes():
D.add_node(n)
new_n = Node(D, n)
new_n.attr.update(n.attr)
for e in self.edges():
(u, v) = e
D.add_edge(u, v)
D.add_edge(v, u)
uv = D.get_edge(u, v)
vu = D.get_edge(v, u)
uv.attr.update(e.attr)
uv.attr.update(e.attr)
vu.attr.update(e.attr)