XQuery/Call Graphs

Motivation
You have many XQuery functions and modules and you want to understand the call relationship between them by generating a graph that shows what functions call each other.

Sample Single Module Call Graph
The following is a sample of a call graph for a single module.
 * you can quickly see what functions don't call other functions and are never called (orphan function).
 * Some functions call other functions but are not called by other functions within this module.
 * Some function are considered leaf functions since they don't call any functions other than standard XQuery library functions.
 * Some functions are called many times by other functions. These are good candidates for utility modules.
 * Some functions are only called once. If this is the case you know the impact to functions in this module if it is changed.
 * Functions with arrows that point back to themselves are recursive functions

Here is an example of a call graph between modules:



Background
We can extract the call information of a module using the inspect module

Inspect Module on eXist Site

or if you have installed the documents locally on your desktop or laptop: local eXist doc

The inspect function will return a structure like this:

Which we would like to visualize as a graph like the figure above.

Challenges
GraphViz is a very mature node layout system with many complex features and a non-XML input format.
 * There is little feedback information if there are errors in the GraphViz pipeline. We should use try/catch to get more feedback on errors.
 * The Dot language does not accept "dash" (-) or colon characters in IDs.  If they appear the transform simply returns no results without error messages.  These characters must be removed from the IDs and the "label" attribute must be used to display the value on the nodes.
 * It would be ideal to have a single XQuery typeswitch transform that does the conversion to SVG, but accurate placement of nodes in a graph is a complex process.
 * There should be some ways to adjust the transform placement such as hints that similar function names be grouped together.
 * There should be ways to keep this system portable across XML development tools using XQDoc. This depends on the XQDoc tools exporting the right information.