This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

10.7155/jgaa.00587 \Issue2611711982022 \HeadingAuthorKlawitter and Mchedlidze \HeadingTitleUpward planar drawings with two slopes \authorOrcid[first]Jonathan [email protected] first]University of Würzburg, Germany \authorOrcid[second]Tamara [email protected] second]Utrecht University, The Netherlands \submittedNovember 2021\reviewedMarch 2021\finalMay 2021\publishedJune 2021\typeRegular paper\editorG. Liotta

Upward planar drawings with two slopes

(April 2021; May 2021)
Abstract

In an upward planar 2-slope drawing of a digraph, edges are drawn as straight-line segments in the upward direction without crossings using only two different slopes. We investigate whether a given upward planar digraph admits such a drawing and, if so, how to construct it. For the fixed embedding scenario, we give a simple characterisation and a linear-time construction by adopting algorithms from orthogonal drawings. For the variable embedding scenario, we describe a linear-time algorithm for single-source digraphs, a quartic-time algorithm for series-parallel digraphs, and a fixed-parameter tractable algorithm for general digraphs. For the latter two classes, we make use of SPQR-trees and the notion of upward spirality. As an application of this drawing style, we show how to draw an upward planar phylogenetic network with two slopes such that all leaves lie on a horizontal line.

1 Introduction

When we visualize directed graphs (digraphs for short) that model hierarchical relations with node-link diagrams, we traditionally turn edge directions into geometric directions by letting each edge point upward. Aiming for visual clarity, we would like such an upward drawing to be planar, that is, no two edges should cross [14]. If this is possible, the resulting drawing is called upward planar drawing; see Figure 1 (a). Interestingly, as Di Battista and Tamassia [15] have shown, every upward planar drawing can be turned into one where each edge is drawn with a single line segment; such a straight-line drawing may however require an exponentially large drawing area [17].

Refer to caption
Figure 1: (a) An upward planar drawing; (b) an orthogonal drawing; (c) an upward planar 2-slope drawing.

Another important class of drawings are (planar) orthogonal drawings, where edges are drawn as sequences of horizontal and vertical line segments [14]; see Figure 1 (b). This drawing style is commonly used for schematic drawings such as VLSI circuit design and UML diagrams. Schematic drawings that allow more than two slopes for edge segments include hexalinear and octilinear drawings, which find application in metro maps [41]. In general, the use of only few geometric primitives (such as different slopes) in a graph drawing facilitates a low visual complexity; a common quality measure for drawings [47].

In recent years, the interest in upward planar drawings that use only few different slopes has grown. For example, among other results, Bekos et al. [4] showed that every so-called bitonic stst-graph with maximum degree Δ\Delta admits an upward planar drawing where every edge has at most one bend and the edges segments use only Δ\Delta distinct slopes. Di Giacomo et al. [19] provided complementary results by proving that also every series-parallel digraph admits a 1-bend upward planar drawing on Δ\Delta distinct slopes; their drawings also have optimal angular resolution. Brückner et al. [8] considered level-planar drawings, that is, upward planar drawings where each vertex is drawn on a predefined integer y-coordinate (its level), with a fixed slope set. In this paper, we continue this recent trend. In particular, we study bendless upward planar drawings that use only two different slopes. An example of such a drawing is shown in Figure 1 (c). Some of our results can be extended to 1-bend upward planar drawings. We now define these drawing concepts more precisely and list related work.

Upward planarity.

An upward planar drawing of a directed graph GG is a planar drawing of GG where every edge (u,v)(u,v) (i.e., an edge directed from uu to vv) is drawn as a monotonic upward curve from uu to vv. A digraph is called upward planar if it admits an upward planar drawing. Two upward planar drawings of the same digraph are topologically equivalent if the left-to-right orderings of the incoming and outgoing edges around each vertex coincide in the two drawings. An upward planar embedding is an equivalence class of upward planar drawings. An upward planar digraph is called upward plane if it is equipped with an upward planar embedding.

A necessary though not sufficient condition for upward planarity is acyclicity [5]. Moreover, Garg and Tamassia [24] showed that testing upward planarity is NP-complete for general digraphs. While the digraphs used in their reduction contain vertices with in- and outdegree higher than two, such vertices can be split into mulitple vertices of maximum in- and outdegree at most two without losing any of the properties required in their proofs. It is thus also NP-complete to test upward planarity for digraphs with in- and outdegree at most two. On the positive side, there exist several fixed-parameter tractable algorithms for general digraphs [10, 26, 20] and polynomial time algorithms for single source digraphs [6], series-parallel digraphs [20], outerplanar digraphs [43], and triconnected digraphs [5]. Moreover, upward planarity can be decided in polynomial time if the embedding is specified [5].

\ell-bend kk-slope drawings.

In an \ell-bend drawing of a graph GG each edge is drawn with at most +1\ell+1 line segments; equivalently, each edge has at most \ell bends. An \ell-bend kk-slope drawing of GG is an \ell-bend drawing of GG where every edge segment has one of at most kk distinct slopes. From now on and if not further specified, we refer to bendless (or 0-bend) kk-slope drawings simply as kk-slope drawings.

Note that orthogonal drawings are 22-slope drawings without a bound on the number of bends. Tamassia [49] showed that a planar orthogonal drawing with minimum total number of bends of a plane graph on nn vertices can be computed in 𝒪(n2logn)\mathcal{O}(n^{2}\log n) time. Rhaman et al. [45] gave necessary and sufficient conditions for a subcubic plane graph to admit a bendless orthogonal drawing. For drawings of cubic graphs in 3D, Eppstein [23] considered bendless orthogonal graph drawings where two vertices are adjacent if and only if two of their coordinates are equal.

Given a graph GG, the minimum number kk of slopes needed for GG to admit a kk-slope drawing is called the slope number of GG [53]. In the planar setting, this is the planar slope number of GG. Both these numbers have been studied extensively. For example, Pach and Pálvölgyi [42] showed that the slope number of graphs with maximum degree 5 can be arbitrarily large. Further results, include bounds on slope numbers of graph classes such as trees, 2-trees, planar 3-trees, outerplanar graphs [21, 39, 33, 38], cubic graphs [40], and subcubic graphs [18, 34]. Determining the planar slope number is hard in the existential theory of the reals [28].

Upward planar 2-slope drawings.

The focus of this paper lies on (bendless) upward planar 22-slope drawings. We consider only the slope set {π/4,π/4}\{-\pi/4,\pi/4\} and denote it by {,}\{\nwarrow,\nearrow\}, since an upward planar 2-slope drawing on any two slopes can be morphed into an upward planar 2-slope drawing with the slopes \nwarrow and \nearrow – imagine this as (un)skewing a partial grid; see Figure 2. Note that a natural lower bound on the upward planar slope number of a graph is given by its maximum in- and outdegree. Hence, we assume that the graphs considered in this paper have maximum in- and outdegree at most two.

Refer to caption
Figure 2: Two upward planar 2-slope drawings of the same graph on different slope sets – edge directions are given implicitly. Using an affine transformation one can transform a drawing on any size-two slope set into one on {,}\{\nwarrow,\nearrow\}.

Bachmaier et al. [1], Brunner and Matzeder [9], and Bachmaier and Matzeder [3] studied straight-line drawings of ordered and unordered rooted trees on orthogonal grids with kk directions for k{4,6,8}k\in\{4,6,8\}. Some of their drawing styles are also upward planar. A classical result of Crescenzi et al. [11] shows that any binary tree with nn vertices admits an upward planar 2-slope drawing in 𝒪(nlogn)\mathcal{O}(n\log n) area. Concerning more complex graphs, upward planar drawings with few slopes for lattices have been studied by Czyzowicz et al. [13] and Czyzowicz [12]. As mentioned above, Bekos et al. [4] and Di Giacomo et al. [19] considered such drawings for stst-graph and series-parallel graphs but also allowed bends. In a companion paper to the current one, Klawitter and Zink [36] study upward planar kk-slope drawings for k3k\geq 3 and among other results show that it is NP-hard to decide whether an outerplanar digraph admits an upward planar 3-slope drawing.

Phylogenetic networks.

Our interest in upward planar 2-slope drawings also stems from the problem of visualizing phylogenetic networks. Phylogenetic trees and networks are used to model the evolutionary history of a set of taxa like species, genes, or languages [31, 22, 48]. The precise definition of phylogenetic networks and their drawing conventions may vary widely depending on the particular use case. For instance, vertices may have timestamps that should be represented in the drawings or leaves may be required to be placed on the same height. In combinatorial phylogenetics the following definition is commonly used [31]: A phylogenetic network is a rooted digraph where the leaves are labelled bijectively with a set of taxa. Inner vertices are either tree vertices that have indegree one and outdegree two or reticulations that have indegree two and outdegree one; see Figure 3 (a). A network without reticulations is a phylogenetic tree; see Figure 3 (b,c).

Refer to caption
Figure 3: (a) A phylogenetic network with two reticulations; (b) a phylogenetic tree drawn as rectangular cladogram and (c) upward planar with two slopes.

There exist different drawing styles for phylogenetic trees such as rectangular or circular cladograms [2, 29]. If the focus is on the topology of the tree (and thus the taxonomy), a common drawing style is upward planar with 2-slope and all leaves aligned on a line. Theoretical work to adapt classical drawing styles from phylogenetic trees to phylogenetic networks has been carried out by Huson et al. [37, 29, 31]. A different approach has been taken by Tollis and Kakoulis [51], who propose a drawing style similar to treemaps for a special class of phylogenetic networks. There also exist several software tools to draw phylogenetic networks [30, 32, 7, 52, 46]. Here we are interested in drawing upward planar phylogenetic networks with two slopes and the additional constraint that all leaves lie on a horizontal line; see Figure 3 (c).

Contribution.

In this paper we investigate the following decision problem. Given a digraph GG of in- and outdegree at most two, decide whether it admits an upward planar 22-slope drawing. We distinguish the fixed and variable embedding scenario, that is, whether GG is already equipped with an upward planar embedding or not. In the former case, we give a simple characterisation of when a drawing exists; see Section 3. By making use of orthogonal drawing algorithms, we also show how to construct a drawing (if it exists) in linear time. In addition, if no upward planar 2-slope drawing exists, we describe how to obtain an upward planar 1-bend 2-slope drawing of GG with minimum number of bends.

For the variable embedding scenario, we check whether graphs of different graph classes admit an upward planar 2-slope drawing, based on the results of Section 3. In Section 4.1, we show that for a single-source digraph GG, checking whether an upward planar 2-slope drawing of GG exists can be done starting from any single upward planar embedding of GG. In the affirmative, a suitable upward planar embedding can be derived and a drawing constructed in linear time. For series-parallel digraphs (Section 4.3) and general digraphs (Sections 4.4 and 4.5), we derive a quartic-time and a fixed-parameter tractable algorithm, respectively. These algorithms are based on Didimo et al.’s algorithms for upward planarity testing [20].

Lastly, we show how to compute 2-slope drawings of upward planar phylogenetic networks, where all leaves lie on a horizontal line in linear time; see Section 5. We conclude with a short discussion and open problems.

2 Preliminaries

Let GG be an upward plane digraph with maximum in- and outdegree two. We assume, without loss of generality, that GG is connected and let nn denote the number of vertices of GG or the graph currently under consideration. We use (u,v)(u,v) to denote an edge of GG that is directed from uu to vv. For two vertices u,vV(G)u,v\in V(G), we say that uu precedes vv if there is a directed path from uu to vv.

If a vertex vv of GG has two incoming edges, then based on the left-to-right ordering of the edges around vv, it is natural to talk about the left and the right incoming edge of vv. If an edge ee is the only incoming edge at vv, we call ee the sole incoming edge of vv. The same holds for outgoing edges; see Figure 4 (a). We say that a vertex vv has face ff to the left (right) if ff is the face left (resp. right) of vv’s leftmost (resp. rightmost) incoming and leftmost (resp. rightmost) outgoing edge (if they exist).

A 2-slope assignment ϕ\phi is a mapping from the edges of GG to the slopes \nearrow and \nwarrow, that is, ϕ:E(G){,}\phi:E(G)\rightarrow\{\nwarrow,\nearrow\}. We say ϕ\phi is a consistent 2-slope assignment if

  • every left (right) incoming edge of a vertex is assigned the slope \nearrow (resp. \nwarrow), and

  • every left (right) outgoing edge of a vertex is assigned the slope \nwarrow (resp. \nearrow).

An edge (u,v)(u,v) that is the sole outgoing edge of uu and the sole incoming edge of vv may have either slope. A digraph GG together with a consistent 2-slope assignment ϕ\phi forms an upward planar 2-slope representation UG=(G,ϕ)U_{G}=(G,\phi). To avoid cumbersome notation, we simply write 2-slope representation.

Suppose GG contains an edge e=(u,v)e=(u,v) that is the left outgoing edge of uu and left incoming edge of vv. Let ff be the face to the right of ee; see Figure 4 (b). We then call ee a bad edge with respect to ff since ee obstructs a consistent 22-slope assignment. Note, however, that ee is not a bad edge with respect to the face ff^{\prime} left of ee; see again Figure 4 (b). The same holds with “left” and “right” in reversed roles.

Refer to caption
Figure 4: (a) The edge (u,v)(u,v) is the right outgoing edge of uu and left incoming edge of vv, the edge (v,w)(v,w) is the sole outgoing edge of vv; (b) the edge (u,v)(u,v) is a bad edge with respect to ff; (c) uu is a left-switch spanning a small angle, vv spans a flat angle and is thus not a switch, and ww is a sink-switch spanning a large angle.

Let UGU_{G} be a 22-slope representation of GG. Let a=(e1,v,e2)a=(e_{1},v,e_{2}) be a triplet such that vv is a vertex of the boundary of a face ff and e1e_{1}, e2e_{2} are incident edges of vv that are consecutive on the boundary of ff in counterclockwise direction. The following definitions follow Bertolazzi et al. [6] and Didimo et al. [20] though are adjusted to also encapsulate geometric properties induced by UGU_{G}. The triplet aa is called an angle of ff. We can categorise angles into three groups, namely, aa is

  • a large angle if e1e_{1} and e2e_{2} span a 270 angle in ff,

  • a small angle if e1e_{1} and e2e_{2} span a 90 angle in ff, or

  • a flat angle if e1e_{1} and e2e_{2} span a 180 angle in ff

with respect to the slopes assigned to e1e_{1} and e2e_{2}. A vertex vv of GG is called a local source with respect to a face ff if vv has two outgoing edges on the boundary of ff. A local sink is defined analogously. Furthermore, we call vv a switch with respect to ff if the slopes of e1e_{1} and e2e_{2} differ; for example, every local source is a switch. We further categorise switches by the angle they span and where they lie on the boundary of ff; see Figure 4 (c). A switch vv is a large switch if e1e_{1} and e2e_{2} span a large angle at ff and a small switch otherwise; note that there can be no “flat” switches. We call vv a source-switch or sink-switch if vv is a local sink or local source, respectively. Otherwise, if e1e_{1} and e2e_{2} have ff to the right (left), then vv is a left-switch (resp. right-switch). Note that an inner face ff of GG contains exactly four small switches more than large switches and that the outer face contains four large switches more than small switches. An inner (the outer) face ff is rectangular if it contains exactly four small (resp. large) switches.

Assume for now that GG is biconnected. The following definitions are illustrated in Figure 5. A split pair {u,v}\{u,v\} of GG is either a separation pair or a pair of adjacent vertices. A split component of GG with respect to the split pair {u,v}\{u,v\} is either an edge (u,v)(u,v) (or (v,u)(v,u)) or a maximal subgraph GG^{\prime} of GG such that GG^{\prime} contains uu and vv and {u,v}\{u,v\} is not a split pair of GG^{\prime}. Let GG^{\prime} be such a split component with respect to the split pair {u,v}\{u,v\}. If GG^{\prime} is equipped with an upward planar embedding, then we define the flip of GG^{\prime} as the change of the embedding of GG^{\prime} by reversing the edge ordering of every vertex of GG^{\prime}.

Refer to caption
Figure 5: (a) A biconnected digraph with split pair {u,v}\{u,v\}, (b) which induces three split components; (c) flip of the third split component.

3 Fixed embedding

In this section we consider the problem of whether an upward plane digraph admits an upward planar 2-slope drawing under the given fixed embedding. As noted above, a bad edge obstructs the existence of a consistent 2-slope assignment and thus of a 2-slope representation for GG. We show that the absence of any bad edges is not only necessary but also sufficient.

Since upward planar 2-slope drawings are related to orthogonal drawings, we can make use of techniques used to construct them. The classical algorithm by Tamassia [49], which constructs an orthogonal drawing of a plane graph with minimum number of bends, works in three steps; refer also to Di Battista et al. [14, Chapter 5]. It starts with a plane graph and constructs a so-called orthogonal representation, a description of the shapes of the faces. The second step, called refinement, subdivides each face into rectangles. Finally, the third step performs a so-called compaction – it assigns coordinates to the vertices with the goal to minimize the area of the drawing. The technique for constructing an orthogonal representation cannot be directly applied for the construction of an upward planar 2-slope drawing, as it does not preserve the upwardness of edges. However, assuming a 2-slope representation is already given, we can adopt the refinement algorithm by Tamassia [49] and the compaction algorithm by Di Battista et al. [14] for our purposes. In the following lemma we describe a modified version of Tamassia’s algorithm that refines the faces of a 2-slope representation; we explain how to obtain a 2-slope representation in Theorem 3.3. For this, recall that a switch is a triplet (e1,v,e2)(e_{1},v,e_{2}) consisting of a vertex and its two incident edges along a face in counterclockwise order where e1e_{1} and e2e_{2} have different slopes.

Lemma 3.1.

Let GG be an upward plane digraph on nn vertices with a 2-slope representation UG=(G,ϕ)U_{G}=(G,\phi). Then, in 𝒪(n)\mathcal{O}(n) time, GG can be refined into a digraph G¯\bar{G} that contains only rectangular faces and such that GG is a topological minor of G¯\bar{G} respecting ϕ\phi.

Proof 3.2.

If every face of GG is already rectangular, then we are done and G¯=G\bar{G}=G. Assume that this is not the case and let ff be a non-rectangular inner face of GG. We describe how to refine ff into rectangular faces.

First, traverse the boundary of ff counterclockwise and store in each switch pointers to its preceding and subsequent switch. Next, starting at any switch, traverse the circular sequence of switches in counterclockwise order. Let uu be the first encountered large switch that is preceding a small switch vv. Note that such uu exists since ff is not rectangular but contains at least four small switches. Without loss of generality, assume that uu is a sink-switch. (The cases when uu is a source-, left-, or right-switch work analogously.) Let ww be the subsequent switch of vv. If ww is a large switch, then add a vertex xx and the edges (u,x)(u,x) and (w,x)(w,x) with slopes \nearrow and \nwarrow, respectively; see Figure 6 (a). Otherwise, if ww is a small switch (and thus a right-switch), then subdivide the outgoing edge of ww with a new vertex xx, and add the edge (u,x)(u,x) with slope \nearrow. Assign the slope \nwarrow to the two edges resulting from the subdivision. This ensures that ϕ\phi is respected by GG as topological minor of G¯\bar{G}; see Figure 6 (b). In either of the two cases, the result is a rectangular face f1f_{1} and a face f2f_{2} with one less small and one less large switch than ff. Let f2f_{2} now take the role of ff and store the preceding switch of uu and the subsequent switch of ww as preceding and subsequent switches of xx, respectively. If xx is a small switch, continue the traversal with the switch preceding xx instead of with xx. Therefore, if a large switch precedes uu in ff, the process directly continues with a refinement step without having to potentially traverse the whole circular sequence first. Stop when only four switches are left and when ff is thus rectangular. Note that this process runs in linear time in terms of the size of ff and that it only adds as many new vertices as the number of large switches that ff contains.

Refer to caption
Figure 6: How to refine non-rectangular faces of GG to obtain G¯\bar{G} when a large switch is followed (a) by a small and a large switch or (b) by two small switches. On the right, the large switch u4u_{4} precedes the large switch u3u_{3} and is thus processed after u3u_{3}.

Repeat this procedure for every non-rectangular inner face of GG. If the outer face f0f_{0} of GG is non-rectangular, apply the analogous procedure with the difference that the goal is to remove all small switches such that f0f_{0} only contains four large switches. Further note that here a large switch uu preceding a small switch vv exists since f0f_{0} being non-rectangular implies that there is at least one small switch.

Let G¯\bar{G} be the resulting digraph where all faces are rectangular. By construction, G¯\bar{G} has GG as topological minor and size in 𝒪(n)\mathcal{O}(n). Furthermore, since the boundary of every face of GG was traversed only twice, this refinement algorithm runs in 𝒪(n)\mathcal{O}(n) time.

We can now prove the main theorem of this section.

Theorem 3.3.

Let GG be an upward plane digraph with nn vertices. Then the following statements are equivalent.

  1. (F1)

    GG admits an upward planar 22-slope drawing.

  2. (F2)

    GG admits a 22-slope representation UGU_{G}.

  3. (F3)

    GG contains no bad edge.

Moreover, there exists an 𝒪(n)\mathcal{O}(n)-time algorithm that tests if GG satisfies (F3) and constructs an upward planar 2-slope drawing of GG in the affirmative case.

Proof 3.4.

Note that (F1) implies (F2) and (F2) implies (F3). We first show that (F3) implies (F2) and then how to construct a drawing (F1) from (F2).

Whether GG contains a bad edge can easily be checked in 𝒪(n)\mathcal{O}(n) time. Suppose it does not and thus satisfies (F3). Construct a consistent 2-slope assignment for GG as follows. Go through all edges of GG (in any order). For an edge ee, if it is a left (right) incoming edge, assign to it slope \nearrow (resp. \nwarrow). Otherwise, if it is a left (right) outgoing edge, assign to it slope \nwarrow (resp. \nearrow). We claim that since ee is not a bad edge, there is no conflict. Assume otherwise, namely, that e=(u,v)e=(u,v) gets, say, slope \nwarrow from uu and slope \nearrow from vv. However, then uu must be the left outgoing edge at uu and the left incoming edge at vv, which makes ee a bad edge thus contradiction our assumption. If ee is both a sole incoming and a sole outgoing edge, assign it an arbitrary slope, say \nwarrow. Together with the already given upward planar embedding of GG, this slope assignment yields a 2-slope representation UGU_{G} of GG.

Next, we construct an upward planar 2-slope drawing of GG. Use Lemma 3.1 to obtain a 22-slope representation UG¯U_{\bar{G}} of an upward planar digraph G¯\bar{G} in which every face is rectangular in 𝒪(n)\mathcal{O}(n) time. Note that rotating G¯\bar{G} clockwise by 45, makes the slope \nwarrow vertical and the slope \nearrow horizontal and we get an orthogonal representation of a graph where every face is rectangular. Therefore we can apply the linear-time compaction algorithm by Di Battista et al. [14, Theorem 5.3]. This algorithm assigns edge lengths and computes coordinates while handling the vertical and orthogonal direction of a orthogonal representation independently. Hence, applying the algorithm to UG¯U_{\bar{G}}, the edges with slopes \nearrow and \nwarrow are handled independently and keep their slopes. (Note that a, say, vertical edge (u,v)(u,v) with length cc in the orthogonal drawing corresponds to vv being cc units above and to the left of uu in an upward planar 2-slope drawing.) As a result, we get an upward planar 2-slope drawing of G¯\bar{G}, which we can reduce to a drawing of GG. Since the three steps run in 𝒪(n)\mathcal{O}(n) time each, the claim on the running time follows.

Suppose we have an upward plane digraph GG with kk bad edges. Since GG admits no upward planar 2-slope drawing, it is natural to ask whether GG admits an upward planar 1-bend 2-slope drawing. In particular, if such a drawing exist, is it enough to bend only the kk bad edges? Using Theorem 3.3 we can answer this question affirmatively.

Corollary 3.5.

Let GG be an upward plane digraph with nn vertices, maximum in- and outdegree at most two, and with kk bad edges. Then GG admits an upward planar 1-bend 2-slope drawing with kk bends. Moreover, without changing the embedding, this is the minimum number of bends that can be achieved.

Proof 3.6.

Subdivide every bad edge once to obtain a graph GG^{\prime}. Then apply Theorem 3.3 to obtain an upward planar 2-slope drawing of GG^{\prime}. Since a bad edge ee of GG is neither a sole incoming nor a sole outgoing edge, the two edges obtained from ee in GG^{\prime} have different slopes. Hence, by turning every subdivision vertex into a bend we get an upward planar 1-bend 2-slope drawing of GG.

Since even a single bad edge obstructs a 2-slope representation and since bending a non-bad edge clearly does not eliminate any other bad edges either, it follows that kk bends are also necessary.

Note that GG may admit an upward planar 1-bend 2-slope drawing with less or no bends if the embedding is changed.

4 Variable embedding

In this section we consider the problem of whether a given upward planar digraph GG of a particular graph class admits an upward planar 22-slope drawing under any upward planar embedding. We start with two general observations, before we consider the class of single-source digraphs, where upward planarity can be tested in linear time, and then continue with the more complex classes of series-parallel digraphs and general digraphs.

Let GG be an upward planar digraph with maximum in- and outdegree at most two. Suppose GG contains a leaf \ell. Note that removing \ell from GG does not change whether GG admits an upward planar 2-slope drawing. Moreover, we may reduce GG to a digraph without leaves, obtain a drawing of the reduced digraph (if possible), and then add the leaves to obtain a 22-slope drawing of GG. Removing and later restoring leaves takes only linear time.

While leaves are no obstruction, transitive edges are. However, note that not all bad edges have to be transitive edges; see Figure 8.

Observation 4.1

A transitive edge of an upward planar digraph GG is a bad edge in any upward planar embedding of GG.

Proof 4.2.

Let e=(u,v)e=(u,v) be a transitive edge of GG. By definition, there is a directed path PP from uu to vv different from ee. Since PP may not cross ee, it enters vv from the same side (left or right) as it leaves uu in any upward planar embedding of GG and hence ee is always a bad edge.

4.1 Single-source digraphs

For a single-source digraph GG, our idea is to first compute an arbitrary upward planar embedding of GG with the linear-time algorithm of Bertolazzi et al. [6]. We then check whether there are any bad edges and, if so, whether they can be fixed with small changes to the embedding. To this end, we need the following lemmata.

Lemma 4.3.

An upward planar single-source digraph GG contains no bad edge with respect to the outer face.

Proof 4.4.

Consider an upward planar embedding of GG and suppose e=(u,v)e=(u,v) is a bad edge with respect to the outer face f0f_{0}; see Figure 7 (a). Let ee^{\prime} be the second incoming edge of vv. Then vv is a local sink of f0f_{0} such that if ee and ee^{\prime} would be drawn with slopes \nearrow and \nwarrow accordingly, then f0f_{0} would have a small angle at vv. However, this implies that there are two local sources (w1w_{1} and w2w_{2} in Figure 7 (a)) of f0f_{0} that are also sources of GG. This is a contradiction to GG being a single-source digraph.

Lemma 4.5.

Let GG be an upward planar single-source digraph with maximum in- and outdegree at most two. Then in any upward planar embedding of GG, there are at most two bad edges with respect to the same face.

Proof 4.6.

Let GG be an upward plane single-source digraph and let ff be a face of GG. Note that a bad edge ee with respect to ff is incident to a local sink vv of a face ff where vv lies between its two incoming edges in a counterclockwise traverse of the boundary of ff. In other words, in an upward planar drawing of GG, ff would have a (small) angle of less than 180 at vv. If there are three or more bad edges with respect to ff, then ff contains at least two such local sinks (like v1v_{1} and v2v_{2} in Figure 7 (b)). There is then at least one local source uu for ff that would span a large angle in ff, i.e., more than 180. However, uu is also a source of GG and since it is not the source for the outer face, it is not the only source of GG. This is a contradiction to GG being a single-source digraph. Figure 7 (c) gives an example of a face with two bad edges.

Refer to caption
Figure 7: (a) A bad edge with respect to the outer face f0f_{0} implies the existence of at least two sources w1w_{1} and w2w_{2}; (b) a face ff that has four bad edges of which two are adjacent to the local sink v1v_{1} of ff and two are adjacent to the local sink v2v_{2} of ff. However, ff also contains a source uu; (c) a face ff with two bad edges (u1,v1)(u_{1},v_{1}) and (u2,v1)(u_{2},v_{1}) that can be a face of a single source digraph.
Lemma 4.7.

Let GG be an upward plane single-source digraph with maximum in- and outdegree at most two and with bad edges {e1,e2,,ek}\{e_{1},e_{2},\ldots,e_{k}\}. Let e1e_{1} be a bad edge with respect to face ff. Deciding whether GG admits an upward planar embedding with bad edges {e2,,ek}\{e_{2},\ldots,e_{k}\} can be done in 𝒪(|f|)\mathcal{O}(\lvert f\rvert) time.

Proof 4.8.

Let e1=e=(u,v)e_{1}=e=(u,v), let eue_{u} be the second outgoing edge of uu, and let eve_{v} be the second incoming edge of vv. Note that eve_{v} and eue_{u} are also on the boundary of ff and that by Lemma 4.3ff is not the outer face. We claim that ee cannot be a bridge. Assume otherwise and let GuG_{u} and GvG_{v} be the components of G{e}G\setminus\{e\} that contain uu and vv, respectively. Note that both GuG_{u} and GvG_{v} have a source each and vv cannot be the source of GvG_{v}. This implies that GG has two sources, which is a contradiction to GG being a single-source digraph. Let ff^{\prime} be the second face with ee on its boundary, which exists since ee is not a bridge. Without loss of generality, assume that ff^{\prime} is to the left and ff to the right of ee.

For GG to admit an upward planar embedding where ee is not a bad edge, it must be possible to change, without loss of generality, the order of eue_{u} and ee at uu, that is, eue_{u} and ee need to become the left and right outgoing edges of uu, respectively. If eue_{u} is a bridge (and thus has ff as left and right face), then we can swap ee and eue_{u} at uu and flip the component that does not contain uu of G{eu}G\setminus\{e_{u}\}; see Figure 8 (a). We can find out whether eue_{u} is a bridge with a single traverse of ff. Furthermore, clearly, this flip does not introduce a new bad edge.

Refer to caption
Figure 8: Two scenarios where a bad edge ee with respect to ff in a single-source digraph can be repaired: (a) eue_{u} is a bridge and can be flipped from ff to ff^{\prime}; (b) the digraph GG^{\prime} between ff and ff^{\prime} and between the split pair {w,u}\{w,u\} can be flipped.

Otherwise, if eue_{u} is not a bridge, observe that we need to flip a subgraph GG^{\prime} of GG that contains eue_{u} and that is enclosed by ff^{\prime} and ff; see Figure 8 (b). For such GG^{\prime} to exist, there must be a vertex ww that forms a split pair with uu, and that has ff to the right and ff^{\prime} to the left. It can be seen as a split pair {u,w}\{u,w^{\prime}\} without this property does not yield a flippable digraph GG^{\prime} (as in Figure 9 (a)) and if no such a split pair exists at all, then the triconnectedness implies that eve_{v}ee, and eue_{u} always lie on the boundary of the same face (as in Figure 9 (b)). Assuming now that such ww exists, we can define GG^{\prime} as the digraph consisting of all split components of GG with respect to {w,u}\{w,u\} that do not contain vv. To repair ee, we flip GG^{\prime} as shown in Figure 8 (b), that is, we reverse the order of incoming and outgoing edges for each vertex in GG^{\prime} except for ww, where we only reverse the order of the outgoing edges. Note that the flip cannot introduce a new bad edge since ww is not a local sink or local source of ff or ff^{\prime}. Furthermore, note that such ww precedes uu, since otherwise both GG^{\prime} and GGG\setminus G^{\prime} would contain a source (that is not ww) each, which contradicts GG being a single-source digraph; see Figure 9 (c). Hence, we may find ww with a traverse of ff.

Refer to caption
Figure 9: Scenarios where a bad edge ee with respect to ff in a single-source digraph cannot be repaired (a) since GG^{\prime} cannot be flipped or (b) since there is no split pair {w,u}\{w,u\}; (c) here GG^{\prime} can be flipped, but the digraph is not a a single-source digraph.

Lastly, we show that changing the order of ee and eve_{v} at vv is possible only when the case above applies where the order of ee and eue_{u} at uu can be changed. To begin with, note that eve_{v} cannot be a bridge, since GG is a single-source digraph. Hence, we would need to flip again a digraph GG^{\prime} that contains eve_{v} and that is enclosed by ff and ff^{\prime}. Such GG^{\prime} would imply a split pair {w,v}\{w^{\prime},v\}, where, however, ww^{\prime} would also serve as split pair {w,u}\{w^{\prime},u\} as in Figure 8 (b).

Since we can check whether eue_{u} is a bridge or find a suitable ww with a single traverse of ff, the claim on the running time holds.

From Lemma 4.7, we get that an upward plane single-source digraph admits an upward planar 2-slope drawing (possibly for a different upward planar embedding) if every bad edge can be fixed. We may thus check every bad edge and perform the necessary flips. Since digraphs to flip may be nested, executing simply one flip after the other could be costly. We now show how to keep the running time linear.

Theorem 4.9.

Let GG be an upward planar single-source digraph with nn vertices. An upward planar 2-slope drawing of GG can be computed in 𝒪(n)\mathcal{O}(n) time, if one exists.

Proof 4.10.

As noted above, we may assume that GG does not contain a leaf. A linear-time algorithm to compute an upward planar 2-slope drawing of GG then works as follows. First, compute an upward planar embedding of GG with the algorithm of Bertolazzi et al. [6] in 𝒪(n)\mathcal{O}(n) time. Second, to identify all bad edges in 𝒪(n)\mathcal{O}(n) time it suffices to traverse the boundary of each face since every bad edge is bad with respect to exactly one face. Third, for each bad edge e=(u,v)e=(u,v) with respect to a face ff, check whether it can be repaired with Lemma 4.7. To keep track of where we have to flip the edge order at vertices, we use two types of markers. A green marker at a vertex xx indicates that the outgoing edges of xx should be swapped and that both incoming and outgoing edges of the vertices “above” xx should be reversed. We thus mark uu green if ee can be repaired because the respective edge eue_{u} is a bridge and we mark ww green if ee can be repaired because of a respective split pair {w,u}\{w,u\}. Furthermore, we mark ee red to tells us to stop reversing edge orders. Both the check and the marking can be done in 𝒪(|f|)\mathcal{O}(\lvert f\rvert) time. Since by Lemma 4.5 any face contains at most two bad edges, this step takes overall also only 𝒪(n)\mathcal{O}(n) time.

Suppose every bad edge can be fixed. Then run a BFS on GG that starts at the source. During the traversal, remember along each path the number of green marked vertices minus the number of encountered red edges. Then for each vertex vv, use the parity of this number to decide whether its edge orders have to be reversed; if odd, then reverse, and if even, then do not. Vertices marked green need to be handled appropriately. This takes again only linear time and as a result we get an upward planar embedding of GG that admits a 2-slope representation UGU_{G}. Finally, apply the algorithm from Theorem 3.3 on UGU_{G} to compute an upward planar 2-slope drawing of GG.

Note that in Lemma 4.7, whether a bad edge is bad in any upward planar embedding of GG is independent from whether another edge is bad in any upward planar embedding of GG. Hence, we can also use Theorem 4.9 and Corollary 3.5 to minimise the number of bends in a 1-bend 2-slope drawing of GG.

Corollary 4.11.

Let GG be an upward planar single-source digraph with nn vertices and maximum in- and outdegree two. An upward planar 1-bend 2-slope drawing of GG with the minimum number of bends can be computed in 𝒪(n)\mathcal{O}(n) time.

4.2 SPQR-trees and upward spirality

Didimo et al. [20] described algorithms to compute upward planar embeddings of biconnected series-parallel and general digraphs. They then use a result from Healy and Lynch [27] about combining biconnected blocks of upward planar digraphs to get rid of the biconnectivity condition. We follow their approach closely. In particular, we also use the notions of SPQR-trees and upward spirality (with the latter tailored to our needs) on which Didimo et al.’s approach heavily relies on and tailor them to our needs. We refer to Didimo et al. [20] for the precise definition of SPQR-trees (for undirected graphs and then derived for digraphs), though recall the main concepts in this section.

Let GG be a biconnected digraph and let e=(s,t)e=(s,t) be any edge of GG called reference edge. An SPRQ-tree TT of GG with respect to ee represents a decomposition of GG with respect to its triconnected components [16, 25]. As such, it also represents all planar embeddings of GG with ee on the outer face. Starting with the split pair {s,t}\{s,t\}, the decomposition is constructed recursively on the split pairs of GG. More precisely, TT is a rooted tree where every node is of type S, P, Q, or R: Q-nodes represent single edges, S-nodes and P-nodes represent series components and parallel components, and R-nodes represent triconnected (rigid) components; see Figure 10 for an example. Each node μ\mu in TT has associated a biconnected multigraph 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu), called the skeleton of μ\mu, in which the children of μ\mu and its reference edge are represented by a virtual edge. The root of TT is a Q-node representing (s,t)(s,t). The child of μ\mu is now defined recursively as follows:

Trivial case.

If GG consists of exactly two parallel edges between ss and tt, then μ\mu is a Q-node representing the edge (s,t)(s,t) parallel to the reference edge and the skeleton 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu) is GG.

Parallel case.

If the split pair {s,t}\{s,t\} has three or four split components G1,G2,,GkG_{1},G_{2},\ldots,G_{k} (more are not possible with our degree restrictions), then μ\mu is a P-node. The skeleton 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu) consists of kk parallel edges between ss and tt that represent the reference edge G1G_{1} and the components GiG_{i}, 2ik2\leq i\leq k.

Series case.

If {s,t}\{s,t\} induces two split components e=(s,t)e=(s,t) and G¯\bar{G}, then μ\mu is an S-node. If G¯\bar{G} is a chain of biconnected components G1,,GkG_{1},\ldots,G_{k} with cut vertices c1,,ck1c_{1},\ldots,c_{k-1} (k2k\geq 2), then 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu) is the cycle tt, ee, ss, e1e_{1}, c1c_{1}, \ldots, ck1c_{k-1}, eke_{k}, tt where eie_{i} represents GiG_{i}.

Rigid case.

Otherwise μ\mu is an R-node. Let {s1,t1}\{s_{1},t_{1}\}, …, {sk,tk}\{s_{k},t_{k}\} be the maximal split pairs of GG with respect to {s,t}\{s,t\}. Let GiG_{i} be the union of split components of {si,ti}\{s_{i},t_{i}\} except the one containing ee. Then 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu) is obtained from GG by replacing each subgraph GiG_{i} with eie_{i}.

The skeleton of the root consists of two parallel edges, ee and a virtual edge representing the rest of the graph. Each node μ\mu of TT that is not a Q-node has children μ1,,μk\mu_{1},\ldots,\mu_{k}, in this order such that μi\mu_{i} is a child of μ\mu based on GieiG_{i}\cup e_{i} with respect to eie_{i}. The pertinent graph GμG_{\mu} for a node μ\mu of TT represents the full subgraph of GG in the SPQR-tree rooted at μ\mu. The end vertices of ei=(si,ti)e_{i}=(s_{i},t_{i}) are called the poles of μ\mu, of 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu), and of GμG_{\mu}. Refer to Figure 10 for an example and note that every edge is represented by a Q-node. We assume that TT is in its canonical form, that is, every S-node of TT has exactly two children. The canonical form can be derived from a non-canonical form in linear time [20].

Refer to caption
Figure 10: A digraph GG and its (non-canonical) SPQR-tree with respect to the reference edge {s,t}\{s,t\}. The skeletons of some nodes are depicted with the virtual edge drawn dashed. The pertinent graph GμG_{\mu} of the R-node μ\mu is highlighted in GG.

Assume that GG is equipped with an st-numbering (based on its underlying undirected graph and with respect to the reference edge {s,t}\{s,t\}). Let μ\mu be a node of TT with poles uu and vv such that uu precedes vv in the st-numbering. Then uu is the first pole and vv is the second pole of μ\mu.

Assume that a pertinent graph GμG_{\mu} of a node μ\mu of TT admits an upward planar 2-slope drawing and let UGμU_{G_{\mu}} be a 22-slope representation of GμG_{\mu}. Let uu and vv be the poles of μ\mu and let w{u,v}w\in\{u,v\}. The pole category twt_{w} of the pole ww is the way the edges that lie in the outer face of Gμ{G_{\mu}} are incident to ww and which slopes they got assigned under UGμU_{G_{\mu}}. Note that edges incident to ww that lie in the interior of Gμ{G_{\mu}} do not affect the pole category of ww. The sixteen possible pole categories of split components are shown in Figure 11. Two poles ww and ww^{\prime} with pole category twt_{w} and twt_{w}^{\prime}, respectively, are compatible if twt_{w} and twt_{w}^{\prime} can be combined into a pole category of higher degree. For example, combining iR and iL gives iRiL.

Refer to caption
Figure 11: Pole categories in a 2-slope representation; gray areas indicate where the interior of the graph lies.

Next we define upward spirality, which measures how much a split component is “rolled up”. The pertinent graph GμG_{\mu} of a node μ\mu of TT may have 2-slope representations with different spirality. Let UGμU_{G_{\mu}} be a 2-slope representation of GμG_{\mu} with first pole uu and second pole vv. Let PP be an undirected path in UGμU_{G_{\mu}}. Two subsequent edges {x,y}\{x,y\} and {y,z}\{y,z\} of PP define a right (left) turn if PP makes a 90 clockwise (resp. counterclockwise) turn at yy according to UGμU_{G_{\mu}}. Define the turn number n(P)\operatorname{\mathrm{n}}(P) of PP as the number of right turns minus the number of left turns of PP. Let PlP_{l} and PrP_{r} be the clockwise and counterclockwise paths from uu to vv along the outer face, respectively. We define the upward 22-slope spirality σ\sigma of UGμU_{G_{\mu}} as σ(UGμ)=n(Pl)+n(Pr)2.\sigma(U_{G_{\mu}})=\frac{\operatorname{\mathrm{n}}(P_{l})+\operatorname{\mathrm{n}}(P_{r})}{2}\text{.} See Figure 12 for examples. Note that the turn number of a path is bounded by its length. Therefore, the number of possible values for the upward 22-slope spirality of UGμU_{G_{\mu}} is in 𝒪(n)\mathcal{O}(n) (and in 𝒪(d)\mathcal{O}(d) where dd is the diameter of UGμU_{G_{\mu}}). For technical reasons that become apparent later, when we store the upward 2-slope spirality of a 2-slope representation, we also store the values n(Pl)\operatorname{\mathrm{n}}(P_{l}) and n(Pr)\operatorname{\mathrm{n}}(P_{r}).

Refer to caption
Figure 12: Two different 22-slope representations of the same digraph for different upward planar embeddings: (a) The paths PlP_{l} and PrP_{r} have turn number 11 and 0, and so the upward 22-slope spirality is 0.50.5; (b) the paths PlP_{l} and PrP_{r} have turn number 3-3 and 4-4, and so the upward 22-slope spirality is 3.5-3.5

Let μ\mu be a node of TT with first pole uu and second pole vv. A feasible tuple of μ\mu is a tuple τμ=UGμ,σ,tu,tv\tau_{\mu}=\langle U_{G_{\mu}},\sigma,t_{u},t_{v}\rangle where UGμU_{G_{\mu}} is an upward 2-slope representation of GμG_{\mu} with pole categories tut_{u} and tvt_{v} and upward 2-slope spirality σ\sigma. Two feasible tuples of μ\mu are spirality equivalent if they have the same upward 22-slope spirality and pole categories. A feasible set μ{\mathcal{F}}_{\mu} of μ\mu is a set of all feasible tuples of μ\mu such that there is exactly one representative tuple for each class of spirality equivalent tuples of μ\mu.

4.3 Series-parallel digraphs

Let GG be a biconnected series-parallel digraph, that is, an SPQR-tree (or rather SPQ-tree) of GG contains no R nodes. Our goal is to test the existence of an upward planar embedding that does not contain a bad edge and thus the existence of a 2-slope representation of GG. The idea of the algorithm is as follows. Pick a reference edge ee and construct the respective SPQR-tree TT of GG. In a post-order traversal of TT, compute the feasible set of each node. This is straightforward for Q-nodes. For an S- or P-node μ\mu, try to combine feasible tuples of the children of μ\mu to feasible tuples of μ\mu. The pole categories and upward 22-slope spirality values make it easier to check whether a composition admits an upward planar 22-slope representation. If this leads to a non-empty feasible set for the root of TT, we can construct a drawing. Otherwise, we try again with another reference edge.

Let μ\mu be a Q-node of TT with first pole uu and second pole vv and suppose GμG_{\mu} is the edge (u,v)(u,v); the case where GμG_{\mu} is (v,u)(v,u) is handled analogously. Then there are only two upward 22-slope representation of GμG_{\mu}, namely when (u,v)(u,v) is assigned the slope \nwarrow or the slope \nearrow. Therefore, μ{\mathcal{F}}_{\mu} has size two. The following two lemmata show how to compute the feasible set of an S-node and a P-node of TT.

Lemma 4.12.

Let GG be a biconnected digraph with nn vertices and TT be an SPQR-tree of GG. Let μ\mu be an S-node of TT with children μ1\mu_{1} and μ2\mu_{2}. Given the feasible sets μ1{\mathcal{F}}_{\mu_{1}} and μ2{\mathcal{F}}_{\mu_{2}}, the feasible set μ{\mathcal{F}}_{\mu} can be computed in 𝒪(n2)\mathcal{O}(n^{2}) time.

Proof 4.13.

To compute a feasible tuple τ\tau of μ{\mathcal{F}}_{\mu} we check for all pairs τ1μ1\tau_{1}\in{\mathcal{F}}_{\mu_{1}} and τ2μ2\tau_{2}\in{\mathcal{F}}_{\mu_{2}} whether they can be combined. More precisely, let uu be the first and vv the second pole of μ\mu; refer to Figure 13. Let uiu_{i} be the first and viv_{i} be the second pole of μi\mu_{i}, i{1,2}i\in\{1,2\}. Without loss of generality, assume that u=u1u=u_{1}, v1=u2v_{1}=u_{2}, and v2=vv_{2}=v. For each pair of feasible tuples τ1=UGμ1,σ1,tu1,tv1μ1\tau_{1}=\langle U_{G_{\mu_{1}}},\sigma_{1},t_{u_{1}},t_{v_{1}}\rangle\in{\mathcal{F}}_{\mu_{1}} and τ2=UGμ2,σ2,tu2,tv2μ2\tau_{2}=\langle U_{G_{\mu_{2}}},\sigma_{2},t_{u_{2}},t_{v_{2}}\rangle\in{\mathcal{F}}_{\mu_{2}} check whether tv1t_{v_{1}} and tu2t_{u_{2}} are compatible. In other words, check whether Gμ1G_{\mu_{1}} and Gμ2G_{\mu_{2}} can be plugged together at v1=u2v_{1}=u_{2} under the slope assignments of UGμ1U_{G_{\mu_{1}}} and UGμ2U_{G_{\mu_{2}}} and with the reference edge on the outer face.

If the pole categories are compatible, the feasible tuple τ=UGμ,σ,tu,tv\tau=\langle U_{G_{\mu}},\sigma,t_{u},t_{v}\rangle is given by tu=tu1t_{u}=t_{u_{1}}, tv=tv2t_{v}=t_{v_{2}}, UGμU_{G_{\mu}} as the series composition of UGμ1U_{G_{\mu_{1}}} and UGμ2U_{G_{\mu_{2}}} at the common vertex u2=v1u_{2}=v_{1}, and where σ\sigma can be computed as follows. For i{1,2}i\in\{1,2\}, let elie_{l}^{i} and erie_{r}^{i} be the edges of UGμiU_{G_{\mu_{i}}} that are incident to u2=v1u_{2}=v_{1} and lie on the clockwise and counterclockwise path from uu to vv along the outer face, respectively; see Figure 13 (b). Note that elie_{l}^{i} may coincide with erie_{r}^{i}. For j{l,r}j\in\{l,r\}, let αj\alpha_{j} be 1-1, 11, or 0 depending on whether ej1e_{j}^{1} and ej2e_{j}^{2} make a left, right, or no turn, respectively. The upward 22-slope spirality of UGμU_{G_{\mu}} is σ=σ1+σ2+αl+αr2\sigma=\sigma_{1}+\sigma_{2}+\frac{\alpha_{l}+\alpha_{r}}{2} (compare to Lemma 6.4 by Didimo et al. [20]). Store τ\tau in μ{\mathcal{F}}_{\mu} if μ{\mathcal{F}}_{\mu} contains no feasible tuple with spirality equivalent to τ\tau. Since μ1{\mathcal{F}}_{\mu_{1}} and μ2{\mathcal{F}}_{\mu_{2}} have 𝒪(n)\mathcal{O}(n) tuples, μ{\mathcal{F}}_{\mu} can be computed in 𝒪(n2)\mathcal{O}(n^{2}) time.

Refer to caption
Figure 13: Illustration of a series composition of split components G1G_{1} and G2G_{2}: (b) UG1U_{G_{1}} and UG2U_{G_{2}} are compatible and the upward 22-slope spirality can be computed based on σ(UG1)\sigma(U_{G_{1}}), σ(UG2)\sigma(U_{G_{2}}), and the turns at el1e_{l}^{1} and el2e_{l}^{2} and at er1e_{r}^{1} and er2e_{r}^{2}; (c) UG1U_{G_{1}} and UG2U_{G_{2}}^{\prime} are not compatible.
Lemma 4.14.

Let GG be a biconnected digraph with nn vertices and TT be an SPQR-tree of GG. Let μ\mu be a P-node of TT with children μ1,,μk\mu_{1},\ldots,\mu_{k} with k4k\leq 4. Given the feasible sets μ1,,μk{\mathcal{F}}_{\mu_{1}},\ldots,{\mathcal{F}}_{\mu_{k}}, the feasible set μ{\mathcal{F}}_{\mu} can be computed in 𝒪(n)\mathcal{O}(n) time.

Proof 4.15.

Let uu be the first and vv the second pole of μ\mu (and its children). Since uu and vv have at most degree four in GG, μ\mu has at most four children (but at least two). We first consider the case where μ\mu has three children. The cases where μ\mu has two or four children are discussed at the end of this proof.

For i{1,2,3}i\in\{1,2,3\}, let GiG_{i} be the pertinent digraph of μi\mu_{i}. Note that uu and vv have degree one in GiG_{i}. We can thus define eie_{i} and eie_{i}^{\prime} as the edges of GiG_{i} incident to uu and vv, respectively. (If μi\mu_{i} is a Q-node, then ei=eie_{i}=e_{i}^{\prime}.) Let eue_{u} and eve_{v} be the edges of GG incident to uu and vv, respectively, that lie outside of GμG_{\mu}. (Note that eu=eve_{u}=e_{v} is only possible in the final composition, where eue_{u} is then also the reference edge.) We want to construct a 22-slope representation of GμG_{\mu} such that the order of e1,e2,e3,eue_{1},e_{2},e_{3},e_{u} at uu is the reverse order of e1,e2,e3,eve_{1}^{\prime},e_{2}^{\prime},e_{3}^{\prime},e_{v} at vv; see Figure 14 (a). Furthermore, the half edges representing eue_{u} and eve_{v} have to be on the outer face.

Suppose we pick a feasible tuple τ1=UG1,σ1,tu1,tv1μ1\tau_{1}=\langle U_{G_{1}},\sigma_{1},t_{u_{1}},t_{v_{1}}\rangle\in{\mathcal{F}}_{\mu_{1}}. Then tu1t_{u_{1}} and tu2t_{u_{2}} restrict the choices of pole categories of compatible upward 22-slope representations of G2G_{2} and G3G_{3}. Likewise, σ1\sigma_{1} restricts these choices further; see Figure 14 (b) and (c). More precisely, we observe that the upward 22-slope spirality σ2\sigma_{2} and σ3\sigma_{3} of compatible UG2U_{G_{2}} and UG3U_{G_{3}} differ from σ1\sigma_{1} by at least two and at most six (compare to Lemma 6.6 by Didimo et al. [20]). Therefore, when trying all possible permutations of G1G_{1}, G2G_{2}, and G3G_{3}, we only have to consider 𝒪(1)\mathcal{O}(1) feasible tuples in μ2{\mathcal{F}}_{\mu_{2}} and μ3{\mathcal{F}}_{\mu_{3}} instead of iterating over complete sets. Storing the feasible tuples in a hash table based on the spirality and pole categories we can find compatible τ2\tau_{2} and τ3\tau_{3} in constant time. Similar to the series-composition, we can compute the upward 22-slope spirality of the resulting upward 22-slope representation UGμU_{G_{\mu}} based on its categories and σi\sigma_{i}, i{1,2,3}i\in\{1,2,3\}. More precisely, for this purpose we not only stored each σi\sigma_{i} but also the respective values n(Pl)\operatorname{\mathrm{n}}(P_{l}) and n(Pr)\operatorname{\mathrm{n}}(P_{r}) to compute them. Therefore, we can take the appropriate values from the two 2-slope representations of UGiU_{G_{i}}, i{1,2,3}i\in\{1,2,3\}, that are on the outer face. Overall, we get that by iterating once over μ1{\mathcal{F}}_{\mu_{1}} we can construct all feasible tuples of μ{\mathcal{F}}_{\mu} in 𝒪(n)\mathcal{O}(n) time.

The case where μ\mu has four children is only possible in the final composition with the reference edge ee. Here the algorithms works along the same line with the difference that the half edges eue_{u} and eve_{v} are replaced with ee. The case where μ\mu has two children, works analogously with the difference that for some feasible tuples of UG1U_{G_{1}} there can now be more compatible upward spirality values for UG2U_{G_{2}} than above. However, these are still 𝒪(1)\mathcal{O}(1) many and the running time is thus not affected.

Refer to caption
Figure 14: Illustration of a parallel compositions with three children and how picking an upward 22-slope representation of G1G_{1} enforces the spirality of representation of G2G_{2} and G3G_{3}.

Lastly, for the root composition we check in 𝒪(n)\mathcal{O}(n) time whether the root of TT, which is a Q-node representing ee, can be combined with a feasible tuple of its child. In the affirmative case, we obtain an upward 22-slope representation of GG. With all compositions described, we can now prove the main theorem of this section.

Theorem 4.16.

Let GG be a biconnected series-parallel digraph with nn vertices. There exists an 𝒪(n4)\mathcal{O}(n^{4})-time algorithm that tests if GG admits an upward planar 2-slope drawing and, if so, that constructs such a drawing.

Proof 4.17.

Let ee be an edge of GG. Compute the (canonical) SPQR-tree TT with respect to ee of GG, which can be done in 𝒪(n)\mathcal{O}(n) time [25, 20]. In a post-order traversal of TT, the algorithm computes the feasible set for every node of TT. If the algorithm arrives at a node with an empty feasible set, its starts with another reference of GG. Otherwise, the algorithm stops when it has constructed a feasible tuple for GG. We can then use Theorem 3.3 to construct an upward planar 2-slope drawing. For one reference edge, this takes at most 𝒪(n2)\mathcal{O}(n^{2}) time per node by Lemmas 4.12 and 4.14. and since the size of TT is linear in nn, at most 𝒪(n3)\mathcal{O}(n^{3}) time in total. The total running time is thus in 𝒪(n4)\mathcal{O}(n^{4}).

In Section 4.5 we explain how to handle non-biconnected series-parallel digraphs.

4.4 Biconnected digraphs

We extend the algorithm for biconnected series-parallel digraphs to general biconnected digraphs following again Didimo et al. [20]. The upward planarity check is again combined with finding a 2-slope representation. Let GG be a biconnected digraph. Let TT be the SPQR-tree of GG with respect to a reference edge ee. The algorithm computes again the feasible sets of the nodes of TT in a post-order traversal. For Q-, S-, or P-nodes this works as before. Recall that to compute a feasible tuple of an S-node or P-node it suffices to look at the pole categories and upward spirality of its children. For R-node this connection is not as clear and we rely thus on a brute-force approach. More precisely, we compute the feasible set by considering all possible combinations of tuples for each virtual edge of 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu) to construct UGμU_{G_{\mu}}. If substitutions are successful, we have to check upward planarity and the existence of bad edges.

Lemma 4.18.

Let GG be a biconnected digraph with nn vertices and TT be an SPQR-tree of GG. Let μ\mu be an R-node of TT with children μ1,,μk\mu_{1},\ldots,\mu_{k}. Let dd be the diameter of GμG_{\mu}. Given the feasible sets μ1,,μk{\mathcal{F}}_{\mu_{1}},\ldots,{\mathcal{F}}_{\mu_{k}}, the feasible set μ{\mathcal{F}}_{\mu} can be computed in 𝒪(dkn2)\mathcal{O}(d^{k}n^{2}) time.

Proof 4.19.

Note that since 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu) is triconnected, it has a unique planar embedding (up to mirroring), which we can compute in 𝒪(n)\mathcal{O}(n) time. Note that, by Theorem 3.3, if 𝑠𝑘𝑒𝑙(μ)\mathit{skel}(\mu) contains a bad edge with respect to three non-virtual edges, then μ{\mathcal{F}}_{\mu} is empty. Moreover, then GG admits no upward planar 2-slope drawing and the main algorithm can stop. So suppose no such bad edge exists.

Construct a 2-slope representation of GμG_{\mu} by substituting virtual edges with the respective 2-slope representations. More precisely, for all i{1,,k}i\in\{1,\ldots,k\}, substitute eie_{i} with the 22-slope representation UGμiU_{G_{\mu_{i}}} of a feasible tuple in μi{\mathcal{F}}_{\mu_{i}}. Let UGμU_{G_{\mu}}^{\prime} denote the partial upward 22-slope representation of GμG_{\mu} during this process, that is, UGμU_{G_{\mu}}^{\prime} consists of an embedding of GμG_{\mu} and the 2-slope assignment for all edges of the UGμiU_{G_{\mu_{i}}}, for i{1,,k}i\in\{1,\ldots,k\}. At each pole of a child μi\mu_{i} in UGμU_{G_{\mu}}^{\prime} check whether the 22-slope representations of the substituted parts are conflicting. If this check fails, backtrack and try another feasible tuple. Suppose that it is successful for all poles of all μi\mu_{i}. Then test the upward planarity of UGμU_{G_{\mu}}^{\prime} with the flow-based upward planarity algorithm for triconnected digraphs by Bertolazzi et al. [5] where the assignment of switches to faces is given for the substituted parts (derived from UGμU_{G_{\mu}}^{\prime}). This flow-based algorithm runs in 𝒪(n2)\mathcal{O}(n^{2}) time.

If UGμU_{G_{\mu}}^{\prime} is upward planar, check whether UGμU_{G_{\mu}}^{\prime} contains any bad edge and, if not, extend UGμU_{G_{\mu}}^{\prime} to a 22-slope representation UGμU_{G_{\mu}} of GμG_{\mu} (compare to Lemma 8.2 by Didimo et al. [20]). Suppose there is an edge (x,y)(x,y) on the outer face of UGμU_{G_{\mu}} that is the sole outgoing edge of xx and the sole incoming edge of yy. Note that the choice of slope for (x,y)(x,y) does not influence the spirality of UGμU_{G_{\mu}}, since the angles formed at xx and yy always add up to the same value; see Figure 15. Lastly, compute the upward 22-slope spirality of UGμU_{G_{\mu}} in 𝒪(n)\mathcal{O}(n) time to obtain a feasible tuple for μ{\mathcal{F}}_{\mu}. By backtracking and trying the remaining feasible tuples of the μi\mu_{i}, we complete the computation of μ{\mathcal{F}}_{\mu}.

Refer to caption
Figure 15: In an R-node μ\mu, the slope choice for an edge (x,y)(x,y) that is the sole outgoing edge at xx and sole incoming edge at yy along the outer face does not effect the upward spirality UGμU_{G_{\mu}}.

Note that dd is an upper bound on the upward 22-slope spirality of a split component and thus each μi\mu_{i} has 𝒪(d)\mathcal{O}(d) feasible tuples. Therefore the algorithm tries at most 𝒪(dk)\mathcal{O}(d^{k}) combinations of feasible tuples of the kk children of μ\mu. Hence the feasible set of an R-node μ\mu can be computed in 𝒪(dkn2)\mathcal{O}(d^{k}n^{2}) time, where the factor 𝒪(n2)\mathcal{O}(n^{2}) comes from the flow based upward planarity test.

Let dd denote the maximum diameter of a split component of GG and let tt denote the number of nontrivial triconnected components of GG, i.e., series components, parallel components, and rigid components. Didimo et al. [20] have shown that in Lemma 4.18 we can also bound the running time with 𝒪(dtn2)\mathcal{O}(d^{t}n^{2}) and further, in total, compute the feasible sets of all R-nodes in 𝒪(dttn2)\mathcal{O}(d^{t}tn^{2}) time. Recall that the time needed to compute the feasible set of an S-node is bounded by the square of possible spirality values and is thus in 𝒪(d2)\mathcal{O}(d^{2}). Since we use the canonical form of SPQR-trees there are 𝒪(n)\mathcal{O}(n) S-nodes. Therefore, we can compute the feasible sets of all S-nodes of TT in 𝒪(d2n)\mathcal{O}(d^{2}n) time. Similarly, the feasible sets of all P-nodes of TT can be computed in 𝒪(dt)\mathcal{O}(dt) time. Lastly, iterating over all SPQR-trees of GG for the different choices of reference edges adds another factor of 𝒪(n)\mathcal{O}(n). If a 2-slope representation of GG has been found, we apply again Theorem 3.3 to compute a drawing. Hence, we get the following theorem.

Theorem 4.20.

Let GG be a biconnected digraph with nn vertices. Suppose that GG has at most tt nontrivial triconnected components, and that each split component has diameter at most dd. Then there exists an 𝒪(dttn3+dtn+d2n2)\mathcal{O}(d^{t}tn^{3}+dtn+d^{2}n^{2})-time algorithm that tests if GG admits an upward planar 2-slope drawing and, if so, that constructs such a drawing of GG.

4.5 General digraphs

So far we have seen how to test whether a biconnected digraph admits a 2-slope representation. For a general digraph GG, even if each of its biconnected components, called a block, has a 2-slope representation we may not be able to join the blocks; see Figure 16. In fact, even if all blocks of GG being upward planar does not imply that GG is upward planar [27]. Nonetheless, following Healy and Lynch [27], our strategy is to test for each block if its admits a 2-slope representation under some special conditions and, in the affirmative, join these representations.

Refer to caption
Figure 16: GG does not admit a 2-slope representations (a), even though its blocks do (b).

When we want to merge the representations of two blocks, we have to take two things into consideration. Namely, we have to test whether their joined cut vertex cc is on the outer face for one of the two blocks and whether their 2-slope representations fit together at cc (just like poles and their pole categories). Before we get into detail on this, we recall what a block-cut tree is and explain how it gives a suitable order to process the blocks.

Block-cut tree.

The block-cut tree 𝒯{\mathcal{T}} of GG contains a vertex for each block and for each cut vertex, and an edge between a cut vertex cc and each block that contains cc. For GG to admit a 2-slope representation, we must be able to root 𝒯{\mathcal{T}} at a block (with all edges oriented towards this root block) such that an edge {B,c}\{B,c\} between a block BB and cut vertex cc is oriented towards cc only if BB admits a 2-slope representation where cc is on the outer face (see Figure 17 and compare to Lemma 3 by Chan [10]). Note that if we can root 𝒯{\mathcal{T}} at a block BB^{\prime}, then any other block BB has exactly one outgoing edge and BB^{\prime} has only incoming edges. For a block BB with outgoing edge to a cut vertex cc, we say BB is a block with respect to cc. Note that multiple blocks can be a block with respect to the same cut vertex.

Refer to caption
Figure 17: A digraph with six blocks and 2-slope representation (a) and the corresponding rooted block-cut tree (b).

Suppose we would know how to root 𝒯{\mathcal{T}}. With a post-order traversal of 𝒯{\mathcal{T}}, we could then try to find a 2-slope representation for each block BB with respect to cc of 𝒯{\mathcal{T}} that has cc on the outer face. However, a priori we do not know at which block to root 𝒯{\mathcal{T}}. Hence, our algorithm works as follows.

Algorithm.

Given GG, we can find its cut vertices and blocks and construct its block-cut tree 𝒯{\mathcal{T}} in 𝒪(n)\mathcal{O}(n) time [50]. Since we do not know what block can function as root of 𝒯{\mathcal{T}} yet, we start at the leaves of 𝒯{\mathcal{T}} and work “inwards”. Note that a leaf block BB has only one edge {B,c}\{B,c\} in 𝒯{\mathcal{T}} to a cut vertex cc (unless B=GB=G) and we can thus provisionally direct {B,c}\{B,c\} to cc. This yields a block with respect to a cut vertex – BB with respect to cc. Furthermore, during the algorithm, for at least one non-leaf block BB either all or all but one of its neighboring blocks have been handled. We then direct each edge {B,c}\{B,c^{\prime}\}, where all other blocks adjacent to cc^{\prime} have been handled, towards BB. If no undirected edge incident to BB remains, then all neighboring blocks of BB have been handled and BB is the root. Otherwise, there remains exactly one undirected edge {B,c}\{B,c\}. Therefore, during this ad hoc post-order traversal of 𝒯{\mathcal{T}}, we can ensure that we always have at least one block BB that is the root or for which we can provisionally direct the last undirected edge incident to BB towards a cut vertex cc in 𝒯{\mathcal{T}} i.e., BB becomes a block with respect to cc.

To process a block BB with respect to cc, we check whether BB has a 2-slope representation UBU_{B} with (i) cc on the outer face and (ii) additional constraints on the angles formed at all other cut vertices of BB, which we describe in detail below. If this is the case, then we can finalize the direction of the edge {B,c}\{B,c\} towards cc. Otherwise, if BB does not admit such a 2-slope representation, then BB has to be the root of 𝒯{\mathcal{T}}. We then orient all edges of 𝒯{\mathcal{T}} towards BB and continue in the remaining part of 𝒯{\mathcal{T}}. If we later find that another block also needs to be the root of 𝒯{\mathcal{T}}, then GG does not admit a 2-slope representation. Furthermore, when we arrive back at BB, we have to test whether BB admits a 2-slope representation at all.

Note that for a block BB with respect to cc, where cc has to be on the outer face of the 2-slope representation UBU_{B}, the algorithms from the previous two sections only have to consider an SPQR-tree with an edge incident to cc as reference edge.

Angles of cut vertices.

We now describe the additional constraints that have to be checked for a block BB at all of BB’s cut vertices. More precisely, let BB be a block with respect to cc (or the root) and let cc^{\prime} be any other cut vertex of BB if it has any. Depending on the degree of cc (and cc^{\prime}) in BB and in the neighboring blocks of BB, we have the following extra conditions on the angles at cc and cc^{\prime} in UBU_{B} of BB.

  • Suppose cc (or cc^{\prime}) has degree one in BB. Then BB is a single edge, cc is automatically on the outer face in any 2-slope representation of BB, and the angle at cc in UBU_{B} is insignificant.

  • Suppose cc has degree two in BB and cc has degree two in another block B1B_{1}; see Figure 18 (a). Then cc has to have a large angle on the outer face in UBU_{B}, since otherwise it would not be able to attach to UB1U_{B_{1}} such that B1B_{1} is in the outer face of BB. If the same case applies to cc^{\prime}, then cc^{\prime} has to have a large angle in UBU_{B}, but not necessarily on the outer face.

  • Suppose cc has degree two in BB and cc has degree one in two other blocks B1B_{1} and B2B_{2}. Then we first test if BB admits a 2-slope representation where cc has a large angle on the outer face; see Figure 18 (b). In this case, both B1B_{1} and B2B_{2} lie in the outer face of BB. Otherwise, if cc has indegree one and outdegree one in BB, we test whether BB admits a 2-slope representation where cc forms a flat angle on the outer face; see Figure 18 (c). We test once such that B1B_{1} lies on the outer face of BB and once for B2B_{2}. In the former case, B2B_{2} would lie in the interior of BB and thus {B2,c}\{B_{2},c\} would be directed as (B2,c)(B_{2},c); in the latter case, B1B_{1} would lie in the interior of BB and thus {B1,c}\{B_{1},c\} would be directed as (B1,c)(B_{1},c). If neither is possible, then BB has to be the root. For cc^{\prime} there are no restrictions under these conditions.

  • The case where cc (or cc^{\prime}) has degree two in BB and degree one in exactly one other block is similar to the previous case but simpler.

  • Suppose cc has degree three in BB; see Figure 18 (d). Then cc has to have a flat angle at cc on the outer face. Otherwise BB has to be the root. There are again no restrictions for cc^{\prime} under these conditions.

Refer to caption
Figure 18: Conditions on the angles at cc and cc^{\prime} in UBU_{B} for block a BB with respect to cc.

These conditions are clearly necessary and, following Healy and Lynch [27], also sufficient. Furthermore, they can easily be tested by the algorithms from the previous sections, where we (as observed above) can use an edge ee incident to cc as reference edge. More precisely, if cc has degree two in BB, then its two incident edges are merged in the root composition. Hence, at this step we only allow a merge with the desired angle at cc, that is, we check if there there is 2-slope representation of the child node of ee with suitable upward spirality. Otherwise, if cc has degree three in BB and has to form a flat angle, we take the sole outgoing or sole incoming edge of cc in BB as the reference edge for the SPQR-tree. In the root composition we then only allow a merge when there is the desired flat angle at cc on the outer face.

Result.

The total running time for our algorithm to test whether a general digraph admits a 2-slope representation and thus an upward planar 2-slope drawing is given by (i) a linear amount for the computation of 𝒯{\mathcal{T}}, (ii) the sum of the checks for each block, and (iii) a linear amount for merging. Because each cut vertex lies in at most four blocks, the running time for (ii) is at most as much as if we tested a biconnected graph of the same size as GG once. Hence, we get the following results.

Theorem 4.21.

Let GG be a series-parallel digraph with nn vertices. There exists an 𝒪(n4)\mathcal{O}(n^{4})-time algorithm that tests if GG admits an upward planar 2-slope drawing and, if so, that constructs such a drawing.

Theorem 4.22.

Let GG be a digraph with nn vertices. Let tt be the maximum number of nontrivial triconnected components of a block of GG, and dd be the maximum diameter of a split component of a block of GG. Then there exists an 𝒪(dttn3+dtn+d2n2)\mathcal{O}(d^{t}tn^{3}+dtn+d^{2}n^{2})-time algorithm that tests if GG admits an upward planar 2-slope drawing and, if so, that constructs such a drawing of GG.

5 Phylogenetic networks

Recall from Section 1 that a phylogenetic network is a single-source digraph whose sinks are all leaves and whose non-sink, non-source vertices have degree three. In this section we show how to find an upward planar 2-slope drawing of a phylogenetic network NN such that its leaves lie on a horizontal line – if NN admits such a drawing. Since we want that all leaves are on the outer face, we first merge them into a single vertex and then apply the linear-time algorithm of Bertolazzi et al. [6] to test whether the resulting digraph NN^{\prime} is upward planar. Clearly, NN^{\prime} is upward planar if and only if NN admits a desired upward planar embedding. In the affirmative case, let NN now be an upward plane phylogenetic network such that its kk leaves lie on the outer face. Further assume that NN contains no bad edge or, in this case equivalently, no transitive edge (unlike the network in Figure 20 (a)).

In Section 3, we constructed an upward planar 2-slope drawing by implementing the refinement step, which augments all faces to rectangular faces, and by applying a compaction algorithm [35]. In order to obtain a drawing where all leaves lie on the same horizontal line, we apply this algorithm to the following augmentation N¯\bar{N} of NN. Let l1,l2,,lkl_{1},l_{2},\ldots,l_{k} be the leaves of NN in clockwise order around the outer face. Add new vertices v1,v2,,vk1v_{1},v_{2},\ldots,v_{k-1} and edges ei=(li,vi)e_{i}=(l_{i},v_{i}) and ei=(li+1,vi)e^{\prime}_{i}=(l_{i+1},v_{i}), i{1,,k1}i\in\{1,\ldots,k-1\}; see Figure 19 (a). Then apply Theorem 3.3 to N¯\bar{N} to obtain an upward planar 2-slope drawing of N¯\bar{N} in 𝒪(n)\mathcal{O}(n) time.

Refer to caption
Figure 19: (a) The augmentation N¯\bar{N} of an upward planar phylogenetic network NN; (b) an upward planar 2-slope drawing where l1l_{1} and l2l_{2} have different y-coordinates; (c) the dual flows GlG_{l} (red) and GrG_{r} (blue); (d) Propagating the length difference of e1e_{1} and e1e_{1}^{\prime} through GlG_{l}.

We observe from Figure 19 (b) that two vertices lil_{i} and li+1l_{i+1} of N¯\bar{N} (neighboring leaves of NN) have different y-coordinates if and only if eie_{i} and eie_{i}^{\prime} have different lengths. This can be fixed by propagating these length differences through the drawing in the following way (Figure 19 (c–d)). Let GG be the dual graph of N¯\bar{N}. Furthermore, define GlG_{l} and GrG_{r} as the two subgraphs of GG with V(G)=V(Gl)=V(Gr)V(G)=V(G_{l})=V(G_{r}) and where E(Gl)E(G_{l}) and E(Gr)E(G_{r}) are the dual edges of primal edges with slope \nwarrow and \nearrow, respectively. In other words, GlG_{l} is the dual graph of N¯\bar{N} restricted to edges with slope \nwarrow. Direct every edge ee^{*} in E(Gl)E(G_{l}) (E(Gr)E(G_{r})) with primal edge ee from the left (resp. right) face of ee to the right (resp. left) face of ee. Assign to each dual edge flow equal to the length of its primal edge. Split the vertex corresponding to the outer face of N¯\bar{N} into a source ss and k1k-1 sinks t1,t2,,tk1t_{1},t_{2},\ldots,t_{k-1} such that tit_{i} has as incoming edges the dual edges of the primal edges eie_{i} and eie^{\prime}_{i}; see Figure 19 (c). These dual graphs can be constructed in linear time.

Next, to adjust the heights of the leaves of NN, for every pair eie_{i} and eie_{i}^{\prime}, i{1,,k1}i\in\{1,\ldots,k-1\}, if, say, eie_{i}^{\prime} is shorter than eie_{i}, propagate the difference as flow backwards towards ss through GlG_{l}; see Figure 19 (d). With one DFS on GlG_{l} and GrG_{r} each, all leaves can be handled simultaneously and in linear time. Lastly, since some edge lengths have been changed, update the coordinates of all vertices in N¯\bar{N} and remove the vertices viv_{i}, i{1,,k}i\in\{1,\ldots,k\}, to obtain an upward planar 2-slope drawing of NN. The following theorem summarises this section.

Theorem 5.1.

Let NN be a phylogenetic network with nn vertices and no transitive edge. If NN admits an upward planar drawing with all its leaves on the outer face, then NN admits and upward planar 2-slope drawing such that all its leaves lie on a horizontal line. Moreover, such a drawing can be constructed in 𝒪(n)\mathcal{O}(n)-time.

Refer to caption
Figure 20: (a) A phylogenetic network with a transitive edge (u,v)(u,v) does not admit an upward planar 2-slope drawing, (b) however, it admits an upward planar 1-bend 2-slope drawing.

Note that by Corollary 4.11 a phylogenetic network with mm transitive edges admits a upward planar 1-bend 2-slope drawing with at most mm bends; see Figure 20.

6 Concluding remarks

When considering the number of slopes in a graph drawing, one typically asks how many different slopes are necessary for a graph of certain graph class. Here we instead constrained the number of slopes to two and asked what digraphs can then be drawn upward planar. Our digraphs are thus limited to those that contain no transitive edges and have a small maximum degree. Beyond that, the difficulty of the problem depends on whether or not an upward planar embedding is given and on the complexity of the digraph.

We have shown that if the embedding is fixed then the question can be answered and, in the affirmative, a drawing constructed in linear time. In this case the problem boils down to whether there is a bad edge for the given embedding and, if not, to adapt algorithms for orthogonal drawings. However, even if there are bad edges present, allowing each of them to bend once is enough to obtain an upward planar 1-bend 2-slope drawing with the minimum number of bends. We conjecture that it is NP-hard to minimize the drawing area of an upward planar 2-slope drawing just like it is for orthogonal drawings [44]. It would be interesting to see a proof for this and how compaction algorithms for orthogonal drawings can be applied to upward planar drawings.

If a given digraph is not embedded yet, we first have to check whether the digraph is upward planar. For single-source digraph, we have seen that it suffices to find one upward planar embedding, which may then be altered to one without bad edges if it exists. For series-parallel and general digraphs we reused an approach by Didimo et al. [20] based on SPQR-trees and upward spirality to find a quartic time and a fixed-parameter tractable algorithm, respectively. An important difference is that our algorithm does not only compute upward planar embeddings for nodes of the SPQR-tree but also 2-slope representations. Through the degree restrictions the algorithm became simpler and can thus also consider other properties. It would be interesting to see whether the algorithm that computes an upward planar embedding of a single-source digraph can be modified to directly compute a 2-slope representation.

This research was motivated by drawings of phylogenetic networks. While we here assumed that a given phylogenetic network is upward planar, this is not a biologically motivated property of phylogenetic networks. One may argue that phylogenetic networks often have few reticulations (vertices with indegree two or higher), but even just two reticulations suffice to obstruct upward planarity. Hence, it would be interesting to have algorithms that can also draw non-upward planar phylogenetic network with two slopes.

The biggest challenges remain for drawings with more than two slopes. Our feeling is that while the complexity of developing algorithms to draw graphs with two slopes is manageable, three or more slopes increase the geometric interdependence dramatically. While the companion paper by Klawitter and Zink [36] started to investigate this, we would be happy to see more results on upward planar slope numbers of graphs.

Acknowledgements

We thank the reviewers for their helpful comments and suggestions.

References

  • [1] C. Bachmaier, F. J. Brandenburg, W. Brunner, A. Hofmeier, M. Matzeder, and T. Unfried. Tree drawings on the hexagonal grid. In I. G. Tollis and M. Patrignani, editors, Graph Drawing, pages 372–383. Springer, 2009. doi:10.1007/978-3-642-00219-9_36.
  • [2] C. Bachmaier, U. Brandes, and B. Schlieper. Drawing phylogenetic trees. In X. Deng and D.-Z. Du, editors, Algorithms and Computation, pages 1110–1121. Springer, 2005. doi:10.1007/11602613_110.
  • [3] C. Bachmaier and M. Matzeder. Drawing unordered trees on k-grids. Journal of Graph Algorithms and Applications, 17(2):103–128, 2013. doi:10.7155/jgaa.00287.
  • [4] M. A. Bekos, E. Di Giacomo, W. Didimo, G. Liotta, and F. Montecchiani. Universal Slope Sets for Upward Planar Drawings. In T. Biedl and A. Kerren, editors, Graph Drawing and Network Visualization, pages 77–91. Springer International Publishing, 2018. doi:10.1007/978-3-030-04414-5_6.
  • [5] P. Bertolazzi, G. Di Battista, G. Liotta, and C. Mannino. Upward drawings of triconnected digraphs. Algorithmica, 12(6):476–497, 1994. doi:10.1007/BF01188716.
  • [6] P. Bertolazzi, G. Di Battista, C. Mannino, and R. Tamassia. Optimal Upward Planarity Testing of Single-Source Digraphs. SIAM Journal on Computing, 27(1):132–169, 1998. doi:10.1137/S0097539794279626.
  • [7] A. Boc, A. B. Diallo, and V. Makarenkov. T-REX: a web server for inferring, validating and visualizing phylogenetic trees and networks. Nucleic Acids Research, 40(W1):W573–W579, 2012. doi:10.1093/nar/gks485.
  • [8] G. Brückner, N. D. Krisam, and T. Mchedlidze. Level-planar drawings with few slopes. In D. Archambault and C. D. Tóth, editors, Graph Drawing and Network Visualization, pages 559–572, 2019. doi:10.1007/978-3-030-35802-0_42.
  • [9] W. Brunner and M. Matzeder. Drawing ordered (k-1)-ary trees on k-grids. In U. Brandes and S. Cornelsen, editors, Graph Drawing, pages 105–116. Springer, 2011. doi:10.1007/978-3-642-18469-7_10.
  • [10] H. Chan. A Parameterized Algorithm for Upward Planarity Testing. In S. Albers and T. Radzik, editors, Algorithms – ESA 2004, pages 157–168. Springer, 2004. doi:10.1007/978-3-540-30140-0_16.
  • [11] P. Crescenzi, G. Di Battista, and A. Piperno. A note on optimal area algorithms for upward drawings of binary trees. Computational Geometry, 2(4):187–200, 1992. doi:10.1016/0925-7721(92)90021-J.
  • [12] J. Czyzowicz. Lattice diagrams with few slopes. Journal of Combinatorial Theory, Series A, 56(1):96–108, 1991. doi:10.1016/0097-3165(91)90025-C.
  • [13] J. Czyzowicz, A. Pelc, and I. Rival. Drawing orders with few slopes. Discrete Mathematics, 82(3):233–250, 1990. doi:10.1016/0012-365X(90)90201-R.
  • [14] G. Di Battista, P. Eades, R. Tamassia, and I. G. Tollis. Graph Drawing: Algorithms for the Visualization of Graphs. Prentice-Hall, 1999.
  • [15] G. Di Battista and R. Tamassia. Algorithms for plane representations of acyclic digraphs. Theoretical Computer Science, 61(2):175–198, 1988. doi:10.1016/0304-3975(88)90123-5.
  • [16] G. Di Battista and R. Tamassia. Incremental planarity testing. In 30th Annual Symposium on Foundations of Computer Science, pages 436–441, 1989. doi:10.1109/SFCS.1989.63515.
  • [17] G. Di Battista, R. Tamassia, and I. G. Tollis. Area Requirement and Symmetry Display of Planar Upward Drawings. Discrete & Computational Geometry, 7:381–401, 1992. doi:10.1007/BF02187850.
  • [18] E. Di Giacomo, G. Liotta, and F. Montecchiani. Drawing subcubic planar graphs with four slopes and optimal angular resolution. Theoretical Computer Science, 714:51–73, 2018. doi:10.1016/j.tcs.2017.12.004.
  • [19] E. Di Giacomo, G. Liotta, and F. Montecchiani. 1-bend upward planar slope number of SP-digraphs. Computational Geometry, 90:101628, 2020. doi:10.1016/j.comgeo.2020.101628.
  • [20] W. Didimo, F. Giordano, and G. Liotta. Upward Spirality and Upward Planarity Testing. SIAM Journal on Discrete Mathematics, 23(4):1842–1899, 2010. doi:10.1137/070696854.
  • [21] V. Dujmović, D. Eppstein, M. Suderman, and D. R. Wood. Drawings of planar graphs with few slopes and segments. Computational Geometry, 38(3):194–212, 2007. doi:10.1016/j.comgeo.2006.09.002.
  • [22] M. Dunn. Language phylogenies. In C. Bowern and B. Evans, editors, The Routledge Handbook of Historical Linguistics, chapter 7. Routledge, 2014. doi:10.4324/9781315794013.ch7.
  • [23] D. Eppstein. The Complexity of Bendless Three-Dimensional Orthogonal Graph Drawing. Journal of Graph Algorithms and Applications, 17(1):35–55, 2013. doi:10.7155/jgaa.00283.
  • [24] A. Garg and R. Tamassia. On the Computational Complexity of Upward and Rectilinear Planarity Testing. SIAM Journal on Computing, 31(2):601–625, 2001. doi:10.1137/S0097539794277123.
  • [25] C. Gutwenger and P. Mutzel. A Linear Time Implementation of SPQR-Trees. In J. Marks, editor, Graph Drawing, pages 77–90. Springer, 2001. doi:10.1007/3-540-44541-2_8.
  • [26] P. Healy and K. Lynch. Two fixed-parameter tractable algorithms for testing upward planarity. International Journal of Foundations of Computer Science, 17(05):1095–1114, 2006. doi:10.1142/S0129054106004285.
  • [27] P. Healy and K. Lynch. Building blocks of upward planar digraphs. Journal of Graph Algorithms and Applications, 11(1):3–44, 2007. doi:10.7155/jgaa.00135.
  • [28] U. Hoffmann. On the Complexity of the Planar Slope Number Problem. Journal of Graph Algorithms and Applications, 21(2):183–193, 2017. doi:10.7155/jgaa.00411.
  • [29] D. H. Huson. Drawing Rooted Phylogenetic Networks. IEEE/ACM Transactions on Computational Biology and Bioinformatics, 6(1):103–109, 2009. doi:10.1109/TCBB.2008.58.
  • [30] D. H. Huson and D. Bryant. Application of Phylogenetic Networks in Evolutionary Studies. Molecular Biology and Evolution, 23(2):254–267, 2005. doi:10.1093/molbev/msj030.
  • [31] D. H. Huson, R. Rupp, and C. Scornavacca. Phylogenetic Networks: Concepts, Algorithms and Applications. Cambridge University Press, 2010.
  • [32] D. H. Huson and C. Scornavacca. Dendroscope 3: An Interactive Tool for Rooted Phylogenetic Trees and Networks. Systematic Biology, 61(6):1061–1067, 2012. doi:10.1093/sysbio/sys062.
  • [33] V. Jelínek, E. Jelínková, J. Kratochvíl, B. Lidický, M. Tesař, and T. Vyskočil. The Planar Slope Number of Planar Partial 3-Trees of Bounded Degree. Graphs and Combinatorics, 29(4):981–1005, 2013. doi:10.1007/s00373-012-1157-z.
  • [34] P. Kindermann, F. Montecchiani, L. Schlipf, and A. Schulz. Drawing Subcubic 1-Planar Graphs with Few Bends, Few Slopes, and Large Angles. In T. Biedl and A. Kerren, editors, Graph Drawing and Network Visualization, pages 152–166. Springer, 2018. doi:10.1007/978-3-030-04414-5_11.
  • [35] G. W. Klau, K. Klein, and P. Mutzel. An experimental comparison of orthogonal compaction algorithms. In J. Marks, editor, Graph Drawing, pages 37–51. Springer, 2001. doi:10.1007/3-540-44541-2_5.
  • [36] J. Klawitter and J. Zink. Upward planar drawings with three and more slopes. In H. C. Purchase and I. Rutter, editors, Graph Drawing and Network Visualization, pages 149–165. Springer, 2021. doi:10.1007/978-3-030-92931-2_11.
  • [37] T. H. Kloepper and D. H. Huson. Drawing explicit phylogenetic networks and their integration into splitstree. BMC Evolutionary Biology, 8(1):22, 2008. doi:10.1186/1471-2148-8-22.
  • [38] K. Knauer, P. Micek, and B. Walczak. Outerplanar graph drawings with few slopes. Computational Geometry, 47(5):614–624, 2014. doi:doi.org/10.1016/j.comgeo.2014.01.003.
  • [39] W. Lenhart, G. Liotta, D. Mondal, and R. I. Nishat. Planar and Plane Slope Number of Partial 2-Trees. In S. Wismath and A. Wolff, editors, Graph Drawing, pages 412–423. Springer, 2013. doi:10.1007/978-3-319-03841-4_36.
  • [40] P. Mukkamala and D. Pálvölgyi. Drawing Cubic Graphs with the Four Basic Slopes. In M. van Kreveld and B. Speckmann, editors, Graph Drawing, pages 254–265. Springer, 2012. doi:10.1007/978-3-642-25878-7_25.
  • [41] M. Nöllenburg and A. Wolff. Drawing and labeling high-quality metro maps by mixed-integer programming. IEEE Transactions on Visualization and Computer Graphics, 17(5):626–641, 2011. doi:10.1109/TVCG.2010.81.
  • [42] J. Pach and D. Pálvölgyi. Bounded-degree graphs can have arbitrarily large slope numbers. Electronic Journal of Combinatorics, 13(1):N1, 2006. doi:10.37236/1139.
  • [43] A. Papakostas. Upward planarity testing of outerplanar dags. In R. Tamassia and I. G. Tollis, editors, Graph Drawing, pages 298–306. Springer, 1995. doi:10.1007/3-540-58950-3_385.
  • [44] M. Patrignani. On the complexity of orthogonal compaction. Computational Geometry, 19(1):47–67, 2001. doi:10.1016/S0925-7721(01)00010-4.
  • [45] M. S. Rahman, M. Naznin, and T. Nishizeki. Orthogonal Drawings of Plane Graphs Without Bends. Journal of Graph Algorithms and Applications, 7(4):335–362, 2003. doi:10.7155/jgaa.00074.
  • [46] K. Schliep, M. Vidal-García, L. Biancani, F. H. Diaz, E. Ada, and C. Solís-Lemus. tanggle: Visualization of phylogenetic networks in a ggplot2 framework, 2021. URL: https://klausvigo.github.io/tanggle/articles/tanggle_vignette.html.
  • [47] A. Schulz. Drawing graphs with few arcs. Journal of Graph Algorithms and Applications, 19(1):393–412, 2015. doi:10.7155/jgaa.00366.
  • [48] M. Steel. Phylogeny: Discrete and Random Processes in Evolution. Society for Industrial and Applied Mathematics, 2016. doi:10.1137/1.9781611974485.
  • [49] R. Tamassia. On Embedding a Graph in the Grid with the Minimum Number of Bends. SIAM Journal on Computing, 16(3):421–444, 1987. doi:10.1137/0216030.
  • [50] R. Tarjan. Depth-first search and linear graph algorithms. SIAM Journal on Computing, 1(2):146–160, 1972. doi:10.1137/0201010.
  • [51] I. G. Tollis and K. G. Kakoulis. Algorithms for Visualizing Phylogenetic Networks. In Y. Hu and M. Nöllenburg, editors, Graph Drawing and Network Visualization, pages 183–195. Springer, 2016. doi:10.1007/978-3-319-50106-2_15.
  • [52] T. G. Vaughan. IcyTree: rapid browser-based visualization for phylogenetic trees and networks. Bioinformatics, 33(15):2392–2394, 2017. doi:10.1093/bioinformatics/btx155.
  • [53] G. A. Wade and J.-H. Chu. Drawability of Complete Graphs Using a Minimal Slope Set. The Computer Journal, 37(2):139–142, 1994. doi:10.1093/comjnl/37.2.139.