Skip to content

Commit 6d80dec

Browse files
RiccardoMPescelupino3
authored andcommitted
Implementing a visual representation of a node size (#30)
Fixes #29. * Add MacOS .DS_Store file to ignore * Add minimum width and height proportional to the number of lines in each node. See https://www.graphviz.org/doc/info/shapes.html * - Add MAX_NODE_WIDTH as a limit - UpdateSize() is the new method that will update both the width and the height (width / 2). If width exceeds MAX_NODE_WIDTH, the latter will become the new value and thus height will be half of it * The following changes are made: - MAX_NODE is set to 5 times NODE_WIDTH_FACTOR. - Dimensions are rounded up to one decimal digit so as to get more regular ellipses. * Add flag "--represent-node-size" to enable the relative feature Remove int cast because we need a rounded number to one decimal digit * Distribute node size between their min and max values Add flag "--min-node-size" and "--max-node-size" to select min and max sizes from the command line * Change math.inf to float(inf) for better legacy support * Add command line arguements to choose size of nodes * Add node size check so it is never less than 0 * Change formula so as to make it follow the distribution of node sizes more evenly * Add scaling factor (FONT_SCALE_FACTOR) to resize font according to node width * Fix a typo in core.py line 55 that failed unit tests * Move constants to callgraph.py and adds logic to handle None values * Remove min_node_loc and node_loc_std as they are not used * Change to font_scale_factor as constant is defined in callgraph.py * Make min_node_size, max_node_size, font_scale_factor optional by setting their defaults to None but actually calling them with the provided values Set default values in function definition to default numbers to make checks work
1 parent 24e3623 commit 6d80dec

File tree

4 files changed

+443
-389
lines changed

4 files changed

+443
-389
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# MacOS Files
2+
.DS_Store
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]
@@ -109,4 +112,4 @@ venv.bak/
109112
*.un~
110113

111114
# Visual Studio Code
112-
.vscode
115+
.vscode

callgraph/callgraph.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
from . import core
1111
from . import render
1212

13+
DEFAULT_MIN_NODE_SIZE = 3
14+
DEFAULT_MAX_NODE_SIZE = 7
15+
DEFAULT_FONT_SCALE_FACTOR = 7
1316

1417
def main():
1518
parser = argparse.ArgumentParser()
@@ -29,6 +32,13 @@ def main():
2932
type=str)
3033
parser.add_argument("-l", "--log-file", help="Log file. If it's not set, stderr is used.",
3134
type=str, dest="logfile")
35+
parser.add_argument("--represent-node-size",
36+
help="Nodes' size will be proportional to the number of lines they contain.",
37+
action="store_true", dest="nodesize")
38+
parser.add_argument("--min-node-size", help="Set minimum rendered node size.",
39+
dest="min_node_size", action="store", type=int, default=None)
40+
parser.add_argument("--max-node-size", help="Set maximum rendered node size.",
41+
dest="max_node_size", action="store", type=int, default=None)
3242

3343
args = parser.parse_args()
3444

@@ -63,10 +73,22 @@ def main():
6373
print(u"Error opening {}: {}".format(args.output, e), file=sys.stderr)
6474
sys.exit(1)
6575

76+
if args.min_node_size == None:
77+
args.min_node_size = DEFAULT_MIN_NODE_SIZE
78+
79+
if args.max_node_size == None:
80+
args.max_node_size = DEFAULT_MAX_NODE_SIZE
81+
82+
if args.min_node_size > args.max_node_size:
83+
print("Minimum node size should be less than maximum node size")
84+
sys.exit(1)
85+
6686
try:
6787
call_graph = core.CallGraph.Build(input_file, log_file=log_file)
68-
render.PrintDot(call_graph, output_file, log_file=log_file, show_all_calls=args.allcalls,
69-
show_node_stats=args.nodestats, nodes_to_hide=nodes_to_hide)
88+
render.PrintDot(call_graph, out_file=output_file, log_file=log_file, show_all_calls=args.allcalls,
89+
show_node_stats=args.nodestats, nodes_to_hide=nodes_to_hide, represent_node_size=args.nodesize,
90+
min_node_size=args.min_node_size, max_node_size=args.max_node_size,
91+
font_scale_factor=DEFAULT_FONT_SCALE_FACTOR)
7092
except Exception as e:
7193
print(u"Error processing the call graph: {}".format(e))
7294

0 commit comments

Comments
 (0)