8000 Commandline option for dot graph direction (rankdir) by mao-liu · Pull Request #3 · davidfraser/pyan · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commandline option for dot graph direction (rankdir) #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions pyan.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ def to_dot(self, **kwargs):
colored = ("colored" in kwargs and kwargs["colored"])
grouped = ("grouped" in kwargs and kwargs["grouped"])
nested_groups = ("nested_groups" in kwargs and kwargs["nested_groups"])
rankdir = kwargs.get("rankdir", "TB")

# Color nodes by top-level namespace. Use HSL: hue = file, lightness = nesting level.
#
Expand Down Expand Up @@ -576,12 +577,17 @@ def get_hue_idx(node):

s = """digraph G {\n"""

graph_opts = {'rankdir': rankdir}
# enable clustering
if grouped:
graph_opts['clusterrank'] = 'local'
# Newer versions of GraphViz (e.g. 2.36.0 (20140111.2315) in Ubuntu 14.04) have a stricter parser.
# http://www.graphviz.org/doc/info/attrs.html#a:clusterrank
# s += """ graph [clusterrank local];\n"""
s += """ graph [clusterrank="local"];\n"""
graph_opts = ', '.join(
[key + '="' + value + '"' for key, value in graph_opts.items()]
)
s += """ graph [""" + graph_opts + """];\n"""

vis_node_list = [] # for sorting; will store nodes to be visualized
def nodecmp(n1, n2):
Expand Down Expand Up @@ -743,6 +749,9 @@ def get_module_name(filename):

if not os.path.exists(init_path):
return mod_name

if not os.path.dirname(filename):
return mod_name

return get_module_name(os.path.dirname(filename)) + '.' + mod_name

Expand Down Expand Up @@ -781,6 +790,13 @@ def main():
parser.add_option("-e", "--nested-groups",
action="store_true", default=False, dest="nested_groups",
help="create nested groups (subgraphs) for nested namespaces (implies -g) [dot only]")
parser.add_option("--dot-rankdir", default="TB", dest="rankdir",
help=(
"specifies the dot graph 'rankdir' property for "
"controlling the direction of the graph. "
"Allowed values: ['TB', 'LR', 'BT', 'RL']. "
"[dot only]"
))

options, args = parser.parse_args()
filenames = [fn2 for fn in args for fn2 in glob(fn)]
Expand Down Expand Up @@ -822,7 +838,8 @@ def main():
draw_uses=options.draw_uses,
colored=options.colored,
grouped=options.grouped,
nested_groups=options.nested_groups)
nested_groups=options.nested_groups,
rankdir=options.rankdir)
if options.tgf:
print v.to_tgf(draw_defines=options.draw_defines,
draw_uses=options.draw_uses)
Expand Down
0