Configurable Graph Drawing Algorithms for the Tikz Graphics Description Language
Total Page:16
File Type:pdf, Size:1020Kb
Diplomarbeit Configurable Graph Drawing Algorithms for the TikZ Graphics Description Language Jannis Pohlmann 14. Oktober 2011 Institut für Theoretische Informatik Prof. Dr. Till Tantau Erklärung Hiermit erkläre ich, dass ich die vorliegende Diplomarbeit selbständig und ausschließlich unter Verwendung der angegebenen Quellen und Hilfsmittel verfasst habe. Zudem versichere ich, dass ich weder diese noch inhaltlich verwandte Arbeiten als Prüfungsleis- tung in anderen Fächern eingereicht habe oder einreichen werde. Lübeck, den 14. Oktober 2011 Abstract Graphs are key to illustrating and understanding many complex systems and processes. This thesis provides an introduction to the graph drawing features of TikZ, a versatile language for creating a wide range of vector graphics that includes a framework for automatic graph layout strategies written in the Lua programming language. Algorithms for two families of drawing methods—spring and spring-electrical layouts of general graphs as well as layered drawings of directed graphs—were developed specifically for TikZ. They are presented along with a discus- sion of their underlying concepts, implementation details, and options to select, configure, and extend them. The generated spring and spring-electrical layouts feature a high degree of sym- metry, evenly distributed nodes and almost uniform edge lengths. The techniques developed for layered drawings are successful in highlighting the flow of directed graphs and producing layouts with uniform edge lengths and few crossings. By discussing many graph drawing fea- tures valuable for end-users and researchers alike, this thesis aims at enabling a comparison to related tools and providing the groundwork for future research and algorithm development. Contents 1 Introduction 1 2 An Overview of TikZ and its Graph Drawing Features 9 2.1 TikZ as a Front-End Language for the PGF Graphics Package 10 2.2 A Special Syntax for Specifying Graphs 12 2.3 The Graph Drawing Engine and its Lua Interface 16 2.4 Contributions to TikZ in the Course of this Thesis 22 3 Force-Based Graph Drawing Algorithms for Arbitrary Graphs 27 3.1 Introduction to Force-Based Graph Drawing 28 3.2 Common Structure and Elements of Spring and Spring-Electrical Algorithms 30 3.3 Spring and Spring-Electrical Algorithms Implemented for TikZ 36 3.4 TikZ Syntax and Options for Creating Spring and Spring-Electrical Layouts 43 4 Algorithms for Layered Drawings of Directed Graphs 51 4.1 An Algorithm Framework Based on the Sugiyama Method 52 4.2 Modular Implementation of the Framework in TikZ 70 4.3 TikZ Syntax and Options for Creating Layered Drawings 73 4.4 Extension Interface of the Algorithm Framework 77 5 Evaluation and Benchmarks 83 5.1 Evaluation of the Spring and Spring-Electrical Algorithms 83 5.2 Evaluation of the Layered Drawing Algorithm 102 6 Conclusion and Outlook 109 Bibliography 113 1 Introduction Consider the following three drawings: These drawings show the same graph. Clearly, the two graphics on the right are more appealing than the one on the left and convey more information about the structure of the graph. What causes us to make this distinction between good and bad or informative and non-informative are aesthetic aspects such as symmetry, distribution of nodes, or edge crossings. Graphs are not only a formal structure to model relational data, but are also key to illustrating and under- standing many complex systems and processes in the form of graph drawings. Three possible applications are the visualization and analysis of social networks, the documentation of compo- nent hierarchies in software engineering, and the illustration of the control flow of a machine or production plant. Due to their size and for reasons of convenience, drawings of graphs are 2 Introduction often generated automatically with the help of specialized software. The quality of the auto- matic layout techniques used in these tools and the compliance with common aesthetic criteria are critical for producing graph drawings that are visually appealing and easy to understand. This is the central focus of graph drawing, an area of mathematics and computer science that ad- dresses the problem of visualizing graphs by developing automatic layout strategies and eval- uating these solutions based on aesthetic criteria. It combines elements from geometric graph theory and information visualization and plays an important role in data analysis as well as the production of research papers, books, lecture notes, and presentations where drawings of graphs are needed. Graph drawing is an active field of research with its own annual conference, the International Symposium on Graph Drawing [5], first held in 1995. Since its early days in the 1960s, graph drawing has succeeded in establishing many concepts related to the visualization of graphs. In addition to the identification and evaluation of common aesthetic criteria such as the minimization of edge crossings or the maximization of symmetry, a number of standard strategies and algorithm frameworks for drawing graphs have been developed. They are often classified by their under- lying concepts, the types of graphs they accept as their input, and the drawing conventions they implement. Popular classifications include methods based on the simulation of physical forces, methods for drawing trees or directed graphs, and methods that produce orthogonal, planar or layered drawings. An introduction to the most important drawing conventions, constraints, and aesthetic criteria as well as a detailed overview of popular techniques for drawing graphs is given by Di Battista et al. [12]. Graph drawing algorithms such as the ones discussed in [18, 21, 27, 31, 35 and 50] have gained recognition and are implemented in many well-known applications, including the graph draw- ing tool Graphviz1 and the computational software Mathematica2. These tools typically provide a special language or syntax for describing graphs. They parse these descriptions and apply graph drawing algorithms in order to find good graph layouts. The resulting drawings are then either rendered to the screen or converted into output formats such as PDF, EPS or PNG, allowing them to be imported into other applications and used in documents and other graphics. This thesis focuses on graph drawing with TikZ, a versatile language for creating a wide range of vector graphics. Like other tools, it provides a compact syntax for specifying graphs and tech- niques for turning these graph descriptions into proper drawings. The work presented here was preceded by extensive research of existing graph drawing literature. Algorithms for two families of drawing methods—force-based layouts of general graphs and layered drawings of 1 Graphviz website: http://graphviz.org 2 Mathematica website: http://www.wolfram.com/mathematica/ 3 directed graphs—were investigated and implemented specifically for use in TikZ. Even though the examples used in this thesis mostly stem from various areas of computer science, the de- veloped algorithms can be applied to many fields of science, education, data visualization, and process modeling. The central topic of the subsequent chapters is to give an introduction to the graph drawing features of TikZ and to discuss the implemented algorithms, including their im- plementation, features, configuration options, and performance. The results produced by these algorithms are evaluated with regards to their visual properties and common aesthetic criteria. What sets TikZ apart from other graph drawing tools are three central features. First of all, its scope is not limited to graph drawing. On the contrary, it has many powerful features for creating complex drawings. Drawing graphs and combining these drawings with other graphic elements is only one of them. In contrast to solutions such as Graphviz or the Open Graph Draw- ing Framework3, TikZ is neither a standalone software nor a framework on top of which other graph drawing tools are built. It can be used to produce graphics for importing into other ap- plications. Its main purpose, however, is to allow the creation of drawings that are embedded into the source code of documents built with the TEX typesetting system. This approach has a number of advantages. Not only does it simplify the document production workflow by en- abling users to store, edit, and build drawings together with the rest of their documents. It also allows drawings to inherit font properties and typesetting features from their containing docu- ments and from TEX, which helps in producing content with a consistent and professional look. The third central feature of TikZ is that—thanks to its modular architecture—it can be extended with new language features, graphics elements, and graph drawing algorithms easily. Unlike with other tools, where such extensions are either not possible at all or require fiddling with compiled languages and build tools, adding new graph drawing algorithms to TikZ is as simple as dropping a script into the TEX directory tree that is written in the Lua programming language and implements a simple function. One thing to note here is that the performance of TEX and algorithms written in Lua is not comparable to the often optimized compiled code used in other tools. This can be a problem with many graph drawings or drawings of large graphs. Luckily, some variants of TEX provide workable solutions to address these issues. Contributions Support for algorithmic graph drawing in TikZ is provided by a dedicated subsystem called the graph drawing engine that takes a graph description, passes it over to a Lua framework where it is turned into an object-oriented representation of the graph and processed with the desired 3 Open Graph Drawing Framework website: http://ogdf.net 4 Introduction graph drawing algorithm. The resulting layout is returned to TikZ for rendering and embedding into the output document. The main contributions of this thesis are the implementation of algorithms for two popular drawing methods applicable to many graphs. These algorithms were implemented specifically for the Lua-based graph drawing engine of TikZ and are presented along with TikZ syntax addi- tions for users to select and configure them.