# graph drawing in tikz - uni- .underlying graph, reusing the already established tree-based...

Post on 02-Aug-2018

213 views

Embed Size (px)

TRANSCRIPT

Graph Drawing in TikZTill Tantau

Graph Drawing Conference 2012

The Problem: Integrating Graph Drawings Into Documents

148 M. Chimani et al.

h

f1 f2

f3

f4f5

f6p

1

6

2 3 4

5

(a) The insertion path p cross a hypernode h.

h

f1 f2

f3

f4f5

f6

h

p

1 6 5

42 3

(b) A realization of p.

Fig. 2. Splitting a hypernode by introducing an additional arc can reduce the crossings

small downward pieces of arcs, due to port constraints, are restricted to thedirect neighborhood of the corresponding node.

Note that, after the full upward-planarization approach is completed, we canmerge multiple such dummy nodes that correspond to the same hyperarc, whenthey lie in a common face.

Inserting reversed arcs, i.e., a Rev. To ensure confluency in the hyperarcs, wehave to take special care for the arcs that where reversed in the preprocessingstep to remove cycles. After the drawing is computed, we will have to reset theiroriginal direction. To avoid notational complexity, we will add such arcs onlyafter all other arcs of the hyperarc are already inserted.

Assume the arc a = (x, y) originally connected a source vertex to the hypern-ode of the star-based underlying graph, but got reversed and hence connects thehypernode to a target vertex. Nonetheless we have to ensure that it connects tothe aforementioned subtree Ts, instead of Tt. Let S be the set of original sourcesin Ts before inserting a. Then a confluency-feasible upward insertion path fora can be found by selecting the minimal insertion path from any node in S toy. Thereby it may cross over A \ Tt and next to crossing dummies of A \ Ttat no cost. The analogous holds, if a originally connected a target vertex to thestar-based hypernode.

Putting it together. So overall, after first computing a special feasible upwardsubgraph, our upward-planarization approach inserts one hyperarc after another.Each hyperarc is inserted by incrementally inserting the arcs of the star-basedunderlying graph, reusing the already established tree-based sub-drawing of thehyperarc as far as possible. By specially considering original arc directions, wethereby guarantee that all hyperarcs are drawn as confluent trees. The finalresult of the planarization is an upward-planar representation (planar, upward-feasible sT -graph) R of G, and hence of H , together with an embedding ofR. Within R, hyperarcs of H are represented as confluent trees, and crossingsare represented as dummy nodes.

Crossing Minimization and Layouts of Directed Hypergraphs 149

1 20

6 8 975

3 4

h2

h4

h3

h1

c2

c1

(a)

1 20

6 8 975

3 4

h2

h4

h3

h1

c2

c1c1 c1

c2 c2

(b)

Fig. 3. Steps towards a final layout: (a) the subgraph between consecutive layers ofan UPR R, (b) fine-layering of the subgraph with included dummy nodes to split longarcs

3 Layout

Using the embedding of the upward-planar planarization (UPR) R computedin the previous step, our layout procedure works in three steps:

1. A layering L of R is computed.2. An initial orthogonal drawing of R is computed.3. Optional step: Orthogonal compaction is applied to remove unnecessary bend

points and improve layout quality.

We finally obtain an upward drawing of R, which induces a drawing of H in astraight-forward way. The number of hyperarc crossings in this drawing equalsthe number of crossing dummies in R, thus it is minimal with respect to thecomputed embedding. Our initial method for orthogonal upward drawing mayproduce an unnecessarily high number of bend points, but it reveals that sucha drawing can be computed efficiently. We discuss the individual steps in moredetail.

Layering. We compute a layering of R in two phases using the layering algorithmby Chimani et al. [8], which also induces a node ordering for each layer. In thefirst phase we compute a layering L of the nodes of H , and in the secondphase a layering L of the subgraph between each two consecutive layers of L.Notice that the nodes of L are either crossing dummies or hypernodes. For eachcrossing dummy c of L, we split c by adding new dummy nodes c and c suchthat c is the immediate left and c is the immediate right neighbor of c. Thesetwo nodes will be bend points in the later drawing and ensure the orthogonalityof the arcs incident to c. We redirect the left incoming and the right outgoing arcof c such that c is its new target and c is its new source node, respectively. Wethen merge L and L into a complete layering L of R and create dummy nodesto split long edges that span multiple layers. An example is shown in Fig. 3.

Till Tantau GD 2012 2 / 17

The Problem: Integrating Graph Drawings Into Documents

GraphViz yields

INTEGRAL

exp dx

.

2pi +

x r

TEX yields

exp

2 +

x r

dx

What we actually want:exp

2 +

x r

dx

Till Tantau GD 2012 2 / 17

The Problem: Integrating Graph Drawings Into Documents

GraphViz yields

INTEGRAL

exp dx

.

2pi +

x r

TEX yields

exp

2 +

x r

dx

What we actually want:exp

2 +

x r

dx

Till Tantau GD 2012 2 / 17

A Solution: Graph Drawing in TikZ

Take an existing document description language (TEX)with an embedded graphics description language (TikZ).

Add options and syntactic extensions for specifying graphs easily.

Run graph drawing algorithms as part of the document processing.

Advantages

+ Styling of nodes and edges matches main document.

+ Graph drawing algorithms know size of nodes and labels precisely.

+ No external programs needed.

+ Algorithm designers can concentrate on algorithmic aspects.

Till Tantau GD 2012 3 / 17

Talk Outline

How Do I Use It?

How Does It Work?

How Do I Implementing An Algorithm?

Till Tantau GD 2012 4 / 17

TikZ in a Nutshell: The Idea

\usepackage{tikz}...A circle like \tikz {\fill[red] (0,0) circle[radius=.5ex];

} is round.

A circle like isround.

TikZ is a package of TEX-macros for specifying graphics.

The macros transform highlevel descriptions of graphics intolowlevel PDF-, PostScript-, or SVG-primitives during a TEX run.

Till Tantau GD 2012 5 / 17

TikZ in a Nutshell: Nodes and Edges

\tikz {\node (a) at (0,2) [rounded rectangle] {Hello};\node (b) at (2,2) [tape] {World};\node (c) at (4,2) [circle, dashed] {$ c^2 $};\node (d) at (4,0) [diamond] {$ \delta $};\draw (a) edge[->] (b) (b) edge[->] (c)

(b) edge[->] (d) (d) edge[->] (a);}

Hello World c2

Till Tantau GD 2012 6 / 17

Using the Graph Drawing System = Adding an Option

\usetikzlibrary{graphdrawing.layered}...\tikz [layered layout] {\node (a) at (0,1) [rounded rectangle] {Hello};\node (b) at (2,1) [tape] {World};\node (c) at (4,1) [circle, dashed] {$ c^2 $};\node (d) at (4,0) [diamond] {$ \delta $};\draw (a) edge[->] (b) (b) edge[->] (c)

(b) edge[->] (d) (d) edge[->] (a);}

Hello

World

c2

Till Tantau GD 2012 7 / 17

Using the Graph Drawing System = Adding an Option

\usetikzlibrary{graphdrawing.force}...\tikz [spring layout, node distance=1.25cm] {\node (a) at (0,1) [rounded rectangle] {Hello};\node (b) at (2,1) [tape] {World};\node (c) at (4,1) [circle, dashed] {$ c^2 $};\node (d) at (4,0) [diamond] {$ \delta $};\draw (a) edge[->] (b) (b) edge[->] (c)

(b) edge[->] (d) (d) edge[->] (a);}

Hello

World

c2

Till Tantau GD 2012 7 / 17

A Concise Syntax for Graphs

A concise syntax for graphs is importantwhen humans specify graphs by hand.

The chosen syntaxmixes the philosophies of DOT and TikZ.

\tikz \graph [layered layout] {Hello -> World -> "$c^2$";World -> "$\delta$" -> Hello;

};

Hello

World

c2

Till Tantau GD 2012 8 / 17

Key Features of TikZs Syntax for Graphs

Node options follow nodes in square brackets.

Edge options follow edges in square brackets.

Additonal edge kinds.

Natural specification of trees.

\tikz \graph [layered layout] {Hello [rounded rectangle]

-> World [tape]-> "$c^2$" [circle, dashed];

World -> "$\delta$"[diamond]-> Hello;

};

Hello

World

c2

Till Tantau GD 2012 9 / 17

Key Features of TikZs Syntax for Graphs

Node options follow nodes in square brackets.

Edge options follow edges in square brackets.

Additonal edge kinds.

Natural specification of trees.

\tikz \graph [layered layout] {Hello [rounded rectangle]

-> World [tape]-> "$c^2$" [circle, dashed];

World->[dashed, blue] "$\delta$"[diamond]->[bend right, "foo"] Hello;

};

foo

Hello

World

c2

Till Tantau GD 2012 9 / 17

Key Features of TikZs Syntax for Graphs

Node options follow nodes in square brackets.

Edge options follow edges in square brackets.

Additonal edge kinds.

Natural specification of trees.

\tikz \graph [tree layout] {a -> b -- c

Key Features of TikZs Syntax for Graphs

Node options follow nodes in square brackets.

Edge options follow edges in square brackets.

Additonal edge kinds.

Natural specification of trees.

\tikz \graph [binary tree layout] {root -> {left -> {1,2

},right -> {3 -> { , 4 }

}}

};

root

left

1 2

right

3

4

Recommended