A GVPR Program Transforming Org Chart

In Graph Galaxy 13.0, the document can take a GVPR program to transform the graph. I played the feature a little with the use case - count descendent nodes in a tree. The use case is interesting as it can be easily applied to the real world, like counting the members under a manager in org.

Let's take a quick look with a screenshot:

The GVPR program in bottom-left window transforms the above graph into another representation shown in bottom-right window. The program iterates each node and count its descendants, then shows the number in node.

Of course the program can be optimized further like eliminating the duplicated calculations by using a single pass of DFS to count descendants for all nodes. The program also doesn't handle structures like multiple parents and circular reference that are invalid for org chart. It shows the fundamentals - walk through the structure, access the node property, and finally format the result into node label.

With this set-up, the graph becomes dynamic with the transformation you assigned. Whenever you make a change in original graph, the program will run again and transform the new graph for you, reflecting the new number of people someone manages in the org.

This program also shows a limitation of GVPR program. As you may already realized - it doesn't support recursive function call. Seems to be that the context of a function call will be overwritten by next run of the same function without stack support. That's why the function count_descendants is implemented in non-recursive approach.

The GVPR manual lists some known issues. We should read about it and avoid the pitfalls when writing GVPR program.