def layout(self, prog='dot', factor=8, offset=0):
"""Use GraphViz to auto-layout modules."""
if pgv is not None:
g = pgv.AGraph(self.graph(), directed=True, strict=False)
g.layout(prog=prog)
for node in g.nodes():
x, y = node.attr['pos'].split(',')
x, y = int(float(x)), int(float(y))
idx = int(node)
mod = self.modules[idx]
if isinstance(factor, int):
xfactor, yfactor = factor, factor
else:
xfactor, yfactor = factor
if isinstance(offset, int):
xoffset, yoffset = offset, offset
else:
xoffset, yoffset = offset
mod.x = x * xfactor + xoffset
mod.y = y * yfactor + yoffset
return True
else:
logging.warning('GraphViz not available; could not auto-layout.')
return False
评论列表
文章目录