This document describes the package CallGraph.m for making call graphs between the functions that belong to specified contexts.
The main function is CallGraph that gives a graph with vertices that are functions names and edges that show which functions call which other functions. With the default option values the graph vertices are labeled and have tooltips with function usage messages.
The call graphs produced by the main package function CallGraph are assumed to be used for studying or refactoring
of large code bases written with Mathematica / Wolfram Language.
The argument of CallGraph is a context string or a list of context strings.
With the default values of its options CallGraph produces a graph with labeled nodes and the labels have tooltips
that show the usage messages of the functions from the specified contexts.
It is assumed that this would be the most useful call graph type for studying the codes of different sets of packages.
We can make simple, non-label, non-tooltip call graph using CallGraph[ ... , "UsageTooltips" -> False ].
CallGraph[ ... , "UsageTooltips" -> False ]
The simple call graph can be modified with the functions:
CallGraphAddUsageMessages, CallGraphAddPrintDefinitionsButtons, CallGraphBiColorCircularEmbedding
Each of those functions is decorating the simple graph in a particular way.
This loads the package CallGraph.m :
The following packages are used in the examples below.
CallGraph["IGraphM`", GraphLayout -> "SpringElectricalEmbedding", ImageSize -> Large]
gr = CallGraph["IGraphM`", Exclusions -> Map[ToExpression, Names["IG*Q"]], ImageSize -> 900]
gr0 = CallGraph["IGraphM`", "UsageTooltips" -> False];
gr1 = CallGraphAddPrintDefinitionsButtons[gr0, GraphLayout -> "StarEmbedding", ImageSize -> 900]
cols = RandomSample[ ColorData["Rainbow"] /@ Rescale[Range[VertexCount[gr1]]]];
CallGraphBiColorCircularEmbedding[ gr1, "VertexColors" -> cols, ImageSize -> 900 ]
(The core functions used for the implementation of CallGraphBiColorCircularEmbedding were taken from kglr's Mathematica Stack Exchange answer: https://mathematica.stackexchange.com/a/188390/34008 . Those functions were modified to take additional arguments.)
The package functions "CallGraph*" take all of the options of the function Graph.
Below are described the additional options of CallGraph.
"PrivateContexts"Should the functions of the private contexts be included in the call graph.
"SelfReferencing"Should the self referencing edges be excluded or not.
"AtomicSymbols"Should atomic symbols be included in the call graph.
ExclusionsSymbols to be excluded from the call graph.
"UsageTooltips"Should vertex labels with the usage tooltips be added.
"UsageTooltipsStyle"The style of the usage tooltips.
With large context (e.g. "System`") the call graph generation might take long time. (See the TODOs below.)
With "PrivateContexts"->False the call graph will be empty if the public functions do not depend on each other.
For certain packages the scanning of the down values would produce (multiple) error messages or warnings.
The following is my TODO list for this project.
Special handling for the "System`" context.
Use the symbols up-values to make the call graph.
Consider/implement call graph making with specified patterns and list of symbols.
Provide special functions for "call sequence" tracing for a specified symbol.
I was just about to try it on IGraph/M. Then I saw that you already did :-)
Very cool package. You might want to post an answer here: https://mathematica.stackexchange.com/questions/4343/automatically-generating-a-dependency-graph-of-an-arbitrary-mathematica-function
I was planning to see are there other implementations of the CallGraph.m functionality. (Also, I was looking for your email in order to send you the link to this post because I used IGraphM.m ...)
- Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming, and consider contributing your work to the The Notebook Archive!