5.3 Techniques
5.3.3 Graphs
Graphs are one of the most common representations in software visualiza- tion. Usually, nodes represent block and instructions and edges indicate the flow. Different types of graphs where proposed along the years in order to show different perspectives of a program, depending of the goal of the analysis being done:
• Abstract Syntax Tree (see Definition 1) • Control Flow Graph (see Definition 2) • System Dependence Graph (see Definition 9) • Call Graph (see Definition 10)
• Value Dependence Graph (see Definition 11) • Module Dependence Graph (see Definition 12) • Trace Flow Graph (see Definition 14)
All these kind of graphs face a problem with respect to visualization: where to place each node in order to obtain the maximum readability and effectiveness. Several aesthetic criteria concerning graph layout have been investigated in this context [PCJ96]:
• Crossing minimization: a graph should be drawn with as few crossings as possible.
• Bends minimization: edges should have as few bends as possible.
• Area minimization: the area of the drawing should be small and there should be a homogeneous density or an even distribution of the nodes. • Length minimization: shorter edges are more easy to follow. It should be minimized the total edge length and the length of the longest edge. • Angle maximization: small angles between outgoing edges and in
bends make it difficult to discriminate the edges.
• Symmetries: symmetries in the underlying graph should be reflected in the diagram.
• Clustering: for large graphs, parts of the graph which are strongly interconnected — called clusters — should be drawn separate from other parts. Edges drawn in a cluster should be shorter than those connecting different clusters.
Graph drawing techniques differ in the kinds of graphs they are suitable for and in the basic principles underlying the drawing algorithm.
Following are briefly described some of the most important graph layout algorithms used in the most popular software visualization systems. The images shown to illustrate each one of the layouts are either produced by yFiles1 or by Nevron2 tools.
• Orthogonal layout : the edges run either horizontally or vertically and edge inclination must have an angle of 90 degrees. The goal with this kind of layout is to minimize the number of edges crossings and deviations (see Figure 5.12).
• Force-directed Layout (also called Force-based Layout ): the nodes are placed in a way so that all the edges are of more or less equal length and there are as few crossing edges as possible. They are usually se- lected for undirected graphs and are specially target for simulating physical and chemical models. The force-directed algorithms assign forces amongst the set of edges and the set of nodes. The most com- mon is to assign forces as if the edges were springs and the nodes are electrically charged particles. The entire graph is then simulated as if it was a physical system. The electrical force repels the vertices which are close to each other. This is repeated iteratively until the
1
Available at http://www.yworks.com 2
5.3. TECHNIQUES 165
system comes to an equilibrium state; i.e., their relative positions do not change anymore from one iteration to the next (see Figure 5.13). Another common forces are magnetic (edges are interpreted as mag- netic needles that align themselves according to a magnetic field) and gravitational (all nodes are attracted to the bary center of all the other nodes).
• Hierarchical Layout : the nodes are placed in hierarchically arranged layers such that the (majority of) edges of the graph show the same overall orientation, for example, top-to-bottom. Additionally, the or- dering of the nodes within each layer is chosen in such a way that the number of edge crossings is small (see Figure 5.14).
• Tree Layout : used for directed graphs that have a unique root element (trees). Starting with the root node the nodes are arranged either from top to bottom, left to right, right to left, or bottom to top. The edges of a graph can either be routed as straight lines or in an orthogonal fashion (see Figure 5.15).
• Radial Layout : organizes the graph in concentric circles of nodes. The vertices are placed in the center and their descendants are placed on the next circle and so on. It produces a straight line graph drawing (see Figure 5.16).
Other graph layouts (as well as variations of the ones presented) can be used depending of the purpose of the analysis: hyperbolic layout, symmetric layout, circular layout and so on.
But the problem of displaying a graph becomes more complex when a visualization system evolves from static visualizations to dynamic ones (graph animation systems).
Usually, during an animation process using graphs, it is necessary to add and delete edges and nodes. The naif approach, to display a sequence of graphs, is to re-calculate the whole layout in each update. This results in an additional aesthetic criterion known as preserving the mental map. Mental map refers to the abstract structural information that a user forms when looking at the layout of a graph [DG02]. Is this mental map that facilitates the navigation in the graph and its comparison with other graphs. So, an obvious challenge is how to display each one of these graphs in order to preserve the basic layout.
In [DGK00], Dieh et al proposed a solution: given a sequence of n graphs they compute a global layout suitable for each one of the n graphs. In the simplest case, this global layout can match with the super-graph of all graphs in the sequence. This approach is called Foresighted Layout.
A general problem associated with most of the current graph layout techniques is that they do not scale. In general, it is almost impossible to
create a graph with thousands of nodes and keep its consistence or try to minimize edge crossings.
Thus, often the most common and practical solution is to layout a span- ning tree for the graph. A spanning tree is a technique that segments a large graph in smaller ones. A list of algorithms to compute spanning trees for graphs can be found in [Jun07].