Upward planar drawings with two slopes

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.


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].
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 st-graph with maximum degree ∆ admits an upward planar drawing where every edge has at most one bend and the edges segments use only ∆ 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 ∆ 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 G is a planar drawing of G where every edge (u, v) (i.e., an edge directed from u to v) is drawn as a monotonic upward curve from u to v. 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,20,26] 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].
-bend k-slope drawings. In an -bend drawing of a graph G each edge is drawn with at most + 1 line segments; equivalently, each edge has at most bends. An -bend k-slope drawing of G is an -bend drawing of G where every edge segment has one of at most k distinct slopes. From now on and if not further specified, we refer to bendless (or 0-bend) k-slope drawings simply as k-slope drawings.
Note that orthogonal drawings are 2-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 n vertices can be computed in 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 G, the minimum number k of slopes needed for G to admit a k-slope drawing is called the slope number of G [53]. In the planar setting, this is the planar slope number of G. 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,33,38,39], 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 2-slope drawings. We consider only the slope set {−π/4, π/4} and denote it by { , }, since an upward planar 2-slope drawing on any two slopes can be morphed into an upward planar 2-slope drawing with the slopes and -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 inand outdegree at most two. 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 k directions for k ∈ {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 n vertices admits an upward planar 2-slope drawing in 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 st-graph and series-parallel graphs but also allowed bends. In a companion paper to the current one, Klawitter and Zink [36] study upward planar k-slope drawings for k ≥ 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 [22,31,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).  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. [29,31,37]. 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 [7,30,32,46,52]. 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 G of in-and outdegree at most two, decide whether it admits an upward planar 2-slope drawing. We distinguish the fixed and variable embedding scenario, that is, whether G 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 G 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 G, checking whether an upward planar 2-slope drawing of G exists can be done starting from any single upward planar embedding of G. In the affirmative, a suitable upward planar embedding can be derived and a drawing constructed in linear time. For seriesparallel 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.

Preliminaries
Let G be an upward plane digraph with maximum in-and outdegree two. We assume, without loss of generality, that G is connected and let n denote the number of vertices of G or the graph currently under consideration. We use (u, v) to denote an edge of G that is directed from u to v. For two vertices u, v ∈ V (G), we say that u precedes v if there is a directed path from u to v.
If a vertex v of G has two incoming edges, then based on the left-to-right ordering of the edges around v, it is natural to talk about the left and the right incoming edge of v. If an edge e is the only incoming edge at v, we call e the sole incoming edge of v. The same holds for outgoing edges; see Figure 4 (a). We say that a vertex v has face f to the left (right) if f is the face left (resp. right) of v's leftmost (resp. rightmost) incoming and leftmost (resp. rightmost) outgoing edge (if they exist).
A 2-slope assignment φ is a mapping from the edges of G to the slopes and , that is, φ : E(G) → { , }. We say φ is a consistent 2-slope assignment if • every left (right) incoming edge of a vertex is assigned the slope (resp. ), and • every left (right) outgoing edge of a vertex is assigned the slope (resp. ).
An edge (u, v) that is the sole outgoing edge of u and the sole incoming edge of v may have either slope. A digraph G together with a consistent 2-slope assignment φ forms an upward planar 2-slope representation U G = (G, φ). To avoid cumbersome notation, we simply write 2-slope representation.
Suppose G contains an edge e = (u, v) that is the left outgoing edge of u and left incoming edge of v. Let f be the face to the right of e; see Figure 4 (b). We then call e a bad edge with respect to f since e obstructs a consistent 2-slope assignment. Note, however, that e is not a bad edge with respect to the face f left of e; see again Figure 4 (b). The same holds with "left" and "right" in reversed roles.
Let U G be a 2-slope representation of G. Let a = (e 1 , v, e 2 ) be a triplet such that v is a vertex of the boundary of a face f and e 1 , e 2 are incident edges of v that are consecutive on the boundary of f 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 U G . The triplet a is called an angle of f . We can categorise angles into three groups, namely, a is with respect to the slopes assigned to e 1 and e 2 . A vertex v of G is called a local source with respect to a face f if v has two outgoing edges on the boundary of f . A local sink is defined analogously. Furthermore, we call v a switch with respect to f if the slopes of e 1 and e 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 f ; see Figure 4 (c). A switch v is a large switch if e 1 and e 2 span a large angle at f and a small switch otherwise; note that there can be no "flat" switches. We call v a source-switch or sink-switch if v is a local sink or local source, respectively. Otherwise, if e 1 and e 2 have f to the right (left), then v is a left-switch (resp. right-switch). Note that an inner face f of G 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 f is rectangular if it contains exactly four small (resp. large) switches.
Assume for now that G is biconnected. The following definitions are illustrated in Figure 5. A split pair {u, v} of G is either a separation pair or a pair of adjacent vertices. A split component of G with respect to the split pair {u, v} is either an edge (u, v) (or (v, u)) or a maximal subgraph G of G such that G contains u and v and {u, v} is not a split pair of G . Let G be such a split component with respect to the split pair {u, v}. If G is equipped with an upward planar embedding, then we define the flip of G as the change of the embedding of G by reversing the edge ordering of every vertex of G .  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 G. 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 1. For this, recall that a switch is a triplet (e 1 , v, e 2 ) consisting of a vertex and its two incident edges along a face in counterclockwise order where e 1 and e 2 have different slopes.
Lemma 1 Let G be an upward plane digraph on n vertices with a 2-slope representation U G = (G, φ). Then, in O(n) time, G can be refined into a digraphḠ that contains only rectangular faces and such that G is a topological minor ofḠ respecting φ.
Proof: If every face of G is already rectangular, then we are done andḠ = G. Assume that this is not the case and let f be a non-rectangular inner face of G. We describe how to refine f into rectangular faces.
First, traverse the boundary of f 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 u be the first encountered large switch that is preceding a small switch v. Note that such u exists since f is not rectangular but contains at least four small switches. Without loss of generality, assume that u is a sink-switch. (The cases when u is a source-, left-, or right-switch work analogously.) Let w be the subsequent switch of v. If w is a large switch, then add a vertex x and the edges (u, x) and (w, x) with slopes and , respectively; see Figure 6 (a). Otherwise, if w is a small switch (and thus a right-switch), then subdivide the outgoing edge of w with a new vertex x, and add the edge (u, x) with slope . Assign the slope to the two edges resulting from the subdivision. This ensures that φ is respected by G as topological minor ofḠ; see Figure 6 (b). In either of the two cases, the result is a rectangular face f 1 and a face f 2 with one less small and one less large switch than f . Let f 2 now take the role of f and store the preceding switch of u and the subsequent switch of w as preceding and subsequent switches of x, respectively. If x is a small switch, continue the traversal with the switch preceding x instead of with x. Therefore, if a large switch precedes u in f , 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 f is thus rectangular. Note that this process runs in linear time in terms of the size of f and that it only adds as many new vertices as the number of large switches that f contains. Figure 6: How to refine non-rectangular faces of G to obtainḠ 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 u 4 precedes the large switch u 3 and is thus processed after u 3 .
Repeat this procedure for every non-rectangular inner face of G. If the outer face f 0 of G is non-rectangular, apply the analogous procedure with the difference that the goal is to remove all small switches such that f 0 only contains four large switches. Further note that here a large switch u preceding a small switch v exists since f 0 being non-rectangular implies that there is at least one small switch.
LetḠ be the resulting digraph where all faces are rectangular. By construction,Ḡ has G as topological minor and size in O(n). Furthermore, since the boundary of every face of G was traversed only twice, this refinement algorithm runs in O(n) time.
We can now prove the main theorem of this section. Proof: 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 G contains a bad edge can easily be checked in O(n) time. Suppose it does not and thus satisfies (F3). Construct a consistent 2-slope assignment for G as follows. Go through all edges of G (in any order). For an edge e, if it is a left (right) incoming edge, assign to it slope (resp. ). Otherwise, if it is a left (right) outgoing edge, assign to it slope (resp. ). We claim that since e is not a bad edge, there is no conflict. Assume otherwise, namely, that e = (u, v) gets, say, slope from u and slope from v. However, then u must be the left outgoing edge at u and the left incoming edge at v, which makes e a bad edge thus contradiction our assumption. If e is both a sole incoming and a sole outgoing edge, assign it an arbitrary slope, say . Together with the already given upward planar embedding of G, this slope assignment yields a 2-slope representation U G of G.
Next, we construct an upward planar 2-slope drawing of G. Use Lemma 1 to obtain a 2-slope representation UḠ of an upward planar digraphḠ in which every face is rectangular in O(n) time.
Note that rotatingḠ clockwise by 45 • , makes the slope vertical and the slope 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 UḠ, the edges with slopes and are handled independently and keep their slopes. (Note that a, say, vertical edge (u, v) with length c in the orthogonal drawing corresponds to v being c units above and to the left of u in an upward planar 2-slope drawing.) As a result, we get an upward planar 2-slope drawing ofḠ, which we can reduce to a drawing of G. Since the three steps run in O(n) time each, the claim on the running time follows.
Suppose we have an upward plane digraph G with k bad edges. Since G admits no upward planar 2-slope drawing, it is natural to ask whether G admits an upward planar 1-bend 2-slope drawing. In particular, if such a drawing exist, is it enough to bend only the k bad edges? Using Theorem 1 we can answer this question affirmatively.
Corollary 2 Let G be an upward plane digraph with n vertices, maximum in-and outdegree at most two, and with k bad edges. Then G admits an upward planar 1-bend 2-slope drawing with k bends. Moreover, without changing the embedding, this is the minimum number of bends that can be achieved.
Proof: Subdivide every bad edge once to obtain a graph G . Then apply Theorem 1 to obtain an upward planar 2-slope drawing of G . Since a bad edge e of G is neither a sole incoming nor a sole outgoing edge, the two edges obtained from e in G have different slopes. Hence, by turning every subdivision vertex into a bend we get an upward planar 1-bend 2-slope drawing of G.
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 k bends are also necessary.
Note that G may admit an upward planar 1-bend 2-slope drawing with less or no bends if the embedding is changed.

Variable embedding
In this section we consider the problem of whether a given upward planar digraph G of a particular graph class admits an upward planar 2-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 G be an upward planar digraph with maximum in-and outdegree at most two. Suppose G contains a leaf . Note that removing from G does not change whether G admits an upward planar 2-slope drawing. Moreover, we may reduce G to a digraph without leaves, obtain a drawing of the reduced digraph (if possible), and then add the leaves to obtain a 2-slope drawing of G. 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 3 A transitive edge of an upward planar digraph G is a bad edge in any upward planar embedding of G.
Proof: Let e = (u, v) be a transitive edge of G. By definition, there is a directed path P from u to v different from e. Since P may not cross e, it enters v from the same side (left or right) as it leaves u in any upward planar embedding of G and hence e is always a bad edge.

Single-source digraphs
For a single-source digraph G, our idea is to first compute an arbitrary upward planar embedding of G 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 2 An upward planar single-source digraph G contains no bad edge with respect to the outer face.
Proof: Consider an upward planar embedding of G and suppose e = (u, v) is a bad edge with respect to the outer face f 0 ; see Figure 7 (a). Let e be the second incoming edge of v. Then v is a local sink of f 0 such that if e and e would be drawn with slopes and accordingly, then f 0 would have a small angle at v. However, this implies that there are two local sources (w 1 and w 2 in Figure 7 (a)) of f 0 that are also sources of G. This is a contradiction to G being a single-source digraph.
Lemma 3 Let G be an upward planar single-source digraph with maximum in-and outdegree at most two. Then in any upward planar embedding of G, there are at most two bad edges with respect to the same face.
Proof: Let G be an upward plane single-source digraph and let f be a face of G. Note that a bad edge e with respect to f is incident to a local sink v of a face f where v lies between its two incoming edges in a counterclockwise traverse of the boundary of f . In other words, in an upward planar drawing of G, f would have a (small) angle of less than 180 • at v. If there are three or more bad edges with respect to f , then f contains at least two such local sinks (like v 1 and v 2 in Figure 7 (b)). There is then at least one local source u for f that would span a large angle in f , i.e., more than 180 • . However, u is also a source of G and since it is not the source for the outer face, it is not the only source of G. This is a contradiction to G being a single-source digraph. Figure 7 (c) gives an example of a face with two bad edges. (c) a face f with two bad edges (u 1 , v 1 ) and (u 2 , v 1 ) that can be a face of a single source digraph.
Lemma 4 Let G be an upward plane single-source digraph with maximum in-and outdegree at most two and with bad edges {e 1 , e 2 , . . . , e k }. Let e 1 be a bad edge with respect to face f . Deciding whether G admits an upward planar embedding with bad edges {e 2 , . . . , e k } can be done in O(|f |) time.
Proof: Let e 1 = e = (u, v), let e u be the second outgoing edge of u, and let e v be the second incoming edge of v. Note that e v and e u are also on the boundary of f and that by Lemma 2, f is not the outer face. We claim that e cannot be a bridge. Assume otherwise and let G u and G v be the components of G \ {e} that contain u and v, respectively. Note that both G u and G v have a source each and v cannot be the source of G v . This implies that G has two sources, which is a contradiction to G being a single-source digraph. Let f be the second face with e on its boundary, which exists since e is not a bridge. Without loss of generality, assume that f is to the left and f to the right of e.
For G to admit an upward planar embedding where e is not a bad edge, it must be possible to change, without loss of generality, the order of e u and e at u, that is, e u and e need to become the left and right outgoing edges of u, respectively. If e u is a bridge (and thus has f as left and right face), then we can swap e and e u at u and flip the component that does not contain u of G \ {e u }; see Figure 8 (a). We can find out whether e u is a bridge with a single traverse of f . Furthermore, clearly, this flip does not introduce a new bad edge. Otherwise, if e u is not a bridge, observe that we need to flip a subgraph G of G that contains e u and that is enclosed by f and f ; see Figure 8 (b). For such G to exist, there must be a vertex w that forms a split pair with u, and that has f to the right and f to the left. It can be seen as a split pair {u, w } without this property does not yield a flippable digraph G (as in Figure 9 (a)) and if no such a split pair exists at all, then the triconnectedness implies that e v , e, and e u always lie on the boundary of the same face (as in Figure 9 (b)). Assuming now that such w exists, we can define G as the digraph consisting of all split components of G with respect to {w, u} that do not contain v. To repair e, we flip G as shown in Figure 8 (b), that is, we reverse the order of incoming and outgoing edges for each vertex in G except for w, where we only reverse the order of the outgoing edges. Note that the flip cannot introduce a new bad edge since w is not a local sink or local source of f or f . Furthermore, note that such w precedes u, since otherwise both G and G \ G would contain a source (that is not w) each, which contradicts G being a single-source digraph; see Figure 9 (c). Hence, we may find w with a traverse of f .
Lastly, we show that changing the order of e and e v at v is possible only when the case above applies where the order of e and e u at u can be changed. To begin with, note that e v cannot be a bridge, since G is a single-source digraph. Hence, we would need to flip again a digraph G that contains e v and that is enclosed by f and f . Such G would imply a split pair {w , v}, where, however, w would also serve as split pair {w , u} as in Figure 8 (b).
Since we can check whether e u is a bridge or find a suitable w with a single traverse of f , the claim on the running time holds.
From Lemma 4, 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 Let G be an upward planar single-source digraph with n vertices. An upward planar 2-slope drawing of G can be computed in O(n) time, if one exists.
Proof: As noted above, we may assume that G does not contain a leaf. A linear-time algorithm to compute an upward planar 2-slope drawing of G then works as follows. First, compute an upward planar embedding of G with the algorithm of Bertolazzi et al. [6] in O(n) time. Second, to identify all bad edges in 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) with respect to a face f , check whether it can be repaired with Lemma 4. 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 x indicates that the outgoing edges of x should be swapped and that both incoming and outgoing edges of the vertices "above" x should be reversed. We thus mark u green if e can be repaired because the respective edge e u is a bridge and we mark w green if e can be repaired because of a respective split pair {w, u}. Furthermore, we mark e red to tells us to stop reversing edge orders. Both the check and the marking can be done in O(|f |) time. Since by Lemma 3 any face contains at most two bad edges, this step takes overall also only O(n) time.
Suppose every bad edge can be fixed. Then run a BFS on G 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 v, 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 G that admits a 2-slope representation U G . Finally, apply the algorithm from Theorem 1 on U G to compute an upward planar 2-slope drawing of G.
Note that in Lemma 4, whether a bad edge is bad in any upward planar embedding of G is independent from whether another edge is bad in any upward planar embedding of G. Hence, we can also use Theorem 4 and Corollary 2 to minimise the number of bends in a 1-bend 2-slope drawing of G.
Corollary 5 Let G be an upward planar single-source digraph with n vertices and maximum inand outdegree two. An upward planar 1-bend 2-slope drawing of G with the minimum number of bends can be computed in O(n) time.

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 SPQRtrees (for undirected graphs and then derived for digraphs), though recall the main concepts in this section.
Let G be a biconnected digraph and let e = (s, t) be any edge of G called reference edge. An SPRQ-tree T of G with respect to e represents a decomposition of G with respect to its triconnected components [16,25]. As such, it also represents all planar embeddings of G with e on the outer face. Starting with the split pair {s, t}, the decomposition is constructed recursively on the split pairs of G. More precisely, T 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 µ in T has associated a biconnected multigraph skel (µ), called the skeleton of µ, in which the children of µ and its reference edge are represented by a virtual edge. The root of T is a Q-node representing (s, t). The child of µ is now defined recursively as follows: Trivial case. If G consists of exactly two parallel edges between s and t, then µ is a Q-node representing the edge (s, t) parallel to the reference edge and the skeleton skel (µ) is G.
Parallel case. If the split pair {s, t} has three or four split components G 1 , G 2 , . . . , G k (more are not possible with our degree restrictions), then µ is a P-node. The skeleton skel (µ) consists of k parallel edges between s and t that represent the reference edge G 1 and the components G i , 2 ≤ i ≤ k.

Rigid case.
Otherwise µ is an R-node. Let {s 1 , t 1 }, . . . , {s k , t k } be the maximal split pairs of G with respect to {s, t}. Let G i be the union of split components of {s i , t i } except the one containing e. Then skel (µ) is obtained from G by replacing each subgraph G i with e i .
The skeleton of the root consists of two parallel edges, e and a virtual edge representing the rest of the graph. Each node µ of T that is not a Q-node has children µ 1 , . . . , µ k , in this order such that µ i is a child of µ based on G i ∪ e i with respect to e i . The pertinent graph G µ for a node µ of T represents the full subgraph of G in the SPQR-tree rooted at µ. The end vertices of e i = (s i , t i ) are called the poles of µ, of skel (µ), and of G µ . Refer to Figure 10 for an example and note that every edge is represented by a Q-node. We assume that T is in its canonical form, that is, every S-node of T has exactly two children. The canonical form can be derived from a non-canonical form in linear time [20]. Assume that G is equipped with an st-numbering (based on its underlying undirected graph and with respect to the reference edge {s, t}). Let µ be a node of T with poles u and v such that u precedes v in the st-numbering. Then u is the first pole and v is the second pole of µ.
Assume that a pertinent graph G µ of a node µ of T admits an upward planar 2-slope drawing and let U Gµ be a 2-slope representation of G µ . Let u and v be the poles of µ and let w ∈ {u, v}. The pole category t w of the pole w is the way the edges that lie in the outer face of G µ are incident to w and which slopes they got assigned under U Gµ . Note that edges incident to w that lie in the interior of G µ do not affect the pole category of w. The sixteen possible pole categories of split components are shown in Figure 11. Two poles w and w with pole category t w and t w , respectively, are compatible if t w and t w can be combined into a pole category of higher degree. For example, combining iR and iL gives iRiL.
Next we define upward spirality, which measures how much a split component is "rolled up". The pertinent graph G µ of a node µ of T may have 2-slope representations with different spirality. Let U Gµ be a 2-slope representation of G µ with first pole u and second pole v. Let P be an undirected path in U Gµ . Two subsequent edges {x, y} and {y, z} of P define a right (left) turn if P makes a 90 • clockwise (resp. counterclockwise) turn at y according to U Gµ . Define the turn number n(P ) of P as the number of right turns minus the number of left turns of P . Let P l and P r be the clockwise and counterclockwise paths from u to v along the outer face, respectively. We define the upward 2-slope spirality σ of U Gµ as σ(U Gµ ) = n(P l )+n(Pr) 2 . 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 2-slope spirality of U Gµ is in O(n) (and in O(d) where d is the diameter of U Gµ ). 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(P l ) and n(P r ).
Let µ be a node of T with first pole u and second pole v. A feasible tuple of µ is a tuple τ µ = U Gµ , σ, t u , t v where U Gµ is an upward 2-slope representation of G µ with pole categories t u and t v and upward 2-slope spirality σ. Two feasible tuples of µ are spirality equivalent if they have the same upward 2-slope spirality and pole categories. A feasible set F µ of µ is a set of all feasible tuples of µ such that there is exactly one representative tuple for each class of spirality equivalent tuples of µ.

Series-parallel digraphs
Let G be a biconnected series-parallel digraph, that is, an SPQR-tree (or rather SPQ-tree) of G 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 G. The idea of the algorithm is as follows. Pick a reference edge e and construct the respective SPQR-tree T of G.
In a post-order traversal of T , compute the feasible set of each node. This is straightforward for v u u v P l P l P r P r (a) (b) Figure 12: Two different 2-slope representations of the same digraph for different upward planar embeddings: (a) The paths P l and P r have turn number 1 and 0, and so the upward 2-slope spirality is 0.5; (b) the paths P l and P r have turn number −3 and −4, and so the upward 2-slope spirality is −3.5 Q-nodes. For an S-or P-node µ, try to combine feasible tuples of the children of µ to feasible tuples of µ. The pole categories and upward 2-slope spirality values make it easier to check whether a composition admits an upward planar 2-slope representation. If this leads to a non-empty feasible set for the root of T , we can construct a drawing. Otherwise, we try again with another reference edge.
Let µ be a Q-node of T with first pole u and second pole v and suppose G µ is the edge (u, v); the case where G µ is (v, u) is handled analogously. Then there are only two upward 2-slope representation of G µ , namely when (u, v) is assigned the slope or the slope . Therefore, F µ has size two. The following two lemmata show how to compute the feasible set of an S-node and a P-node of T .
Lemma 5 Let G be a biconnected digraph with n vertices and T be an SPQR-tree of G. Let µ be an S-node of T with children µ 1 and µ 2 . Given the feasible sets F µ1 and F µ2 , the feasible set F µ can be computed in O(n 2 ) time.
Proof: To compute a feasible tuple τ of F µ we check for all pairs τ 1 ∈ F µ1 and τ 2 ∈ F µ2 whether they can be combined. More precisely, let u be the first and v the second pole of µ; refer to Figure 13. Let u i be the first and v i be the second pole of µ i , i ∈ {1, 2}. Without loss of generality, assume that u = u 1 , v 1 = u 2 , and v 2 = v. For each pair of feasible tuples τ 1 = U Gµ 1 , σ 1 , t u1 , t v1 ∈ F µ1 and τ 2 = U Gµ 2 , σ 2 , t u2 , t v2 ∈ F µ2 check whether t v1 and t u2 are compatible. In other words, check whether G µ1 and G µ2 can be plugged together at v 1 = u 2 under the slope assignments of U Gµ 1 and U Gµ 2 and with the reference edge on the outer face.
If the pole categories are compatible, the feasible tuple τ = U Gµ , σ, t u , t v is given by t u = t u1 , t v = t v2 , U Gµ as the series composition of U Gµ 1 and U Gµ 2 at the common vertex u 2 = v 1 , and where σ can be computed as follows. For i ∈ {1, 2}, let e i l and e i r be the edges of U Gµ i that are incident to u 2 = v 1 and lie on the clockwise and counterclockwise path from u to v along the outer face, respectively; see Figure 13 (b). Note that e i l may coincide with e i r . For j ∈ {l, r}, let α j be −1, 1, or 0 depending on whether e 1 j and e 2 j make a left, right, or no turn, respectively. The upward 2-slope spirality of U Gµ is σ = σ 1 + σ 2 + α l +αr 2 (compare to Lemma 6.4 by Didimo et al. [20]). Store τ in F µ if F µ contains no feasible tuple with spirality equivalent to τ . Since F µ1 and F µ2 have O(n) tuples, F µ can be computed in O(n 2 ) time.
Lemma 6 Let G be a biconnected digraph with n vertices and T be an SPQR-tree of G. Let µ be a P-node of T with children µ 1 , . . . , µ k with k ≤ 4. Given the feasible sets F µ1 , . . . , F µ k , the feasible set F µ can be computed in O(n) time.
Proof: Let u be the first and v the second pole of µ (and its children). Since u and v have at most degree four in G, µ has at most four children (but at least two). We first consider the case where µ has three children. The cases where µ has two or four children are discussed at the end of this proof.
For i ∈ {1, 2, 3}, let G i be the pertinent digraph of µ i . Note that u and v have degree one in G i . We can thus define e i and e i as the edges of G i incident to u and v, respectively. (If µ i is a Q-node, then e i = e i .) Let e u and e v be the edges of G incident to u and v, respectively, that lie outside of G µ . (Note that e u = e v is only possible in the final composition, where e u is then also the reference edge.) We want to construct a 2-slope representation of G µ such that the order of e 1 , e 2 , e 3 , e u at u is the reverse order of e 1 , e 2 , e 3 , e v at v; see Figure 14 (a). Furthermore, the half edges representing e u and e v have to be on the outer face.
Suppose we pick a feasible tuple τ 1 = U G1 , σ 1 , t u1 , t v1 ∈ F µ1 . Then t u1 and t u2 restrict the choices of pole categories of compatible upward 2-slope representations of G 2 and G 3 . Likewise, σ 1 restricts these choices further; see Figure 14 (b) and (c). More precisely, we observe that the upward 2-slope spirality σ 2 and σ 3 of compatible U G2 and U G3 differ from σ 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 G 1 , G 2 , and G 3 , we only have to consider O(1) feasible tuples in F µ2 and F µ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 and τ 3 in constant time. Similar to the series-composition, we can compute the upward 2-slope spirality of the resulting upward 2-slope representation U Gµ based on its categories and σ i , i ∈ {1, 2, 3}. More precisely, for this purpose we not only stored each σ i but also the respective values n(P l ) and n(P r ) to compute them. Therefore, we can take the appropriate values from the two 2-slope representations of U Gi , i ∈ {1, 2, 3}, that are on the outer face. Overall, we get that by iterating once over F µ1 we can construct all feasible tuples of F µ in O(n) time.
The case where µ has four children is only possible in the final composition with the reference edge e. Here the algorithms works along the same line with the difference that the half edges e u and e v are replaced with e. The case where µ has two children, works analogously with the difference that for some feasible tuples of U G1 there can now be more compatible upward spirality values for U G2 than above. However, these are still O(1) many and the running time is thus not affected. Figure 14: Illustration of a parallel compositions with three children and how picking an upward 2-slope representation of G 1 enforces the spirality of representation of G 2 and G 3 .
Lastly, for the root composition we check in O(n) time whether the root of T , which is a Q-node representing e, can be combined with a feasible tuple of its child. In the affirmative case, we obtain an upward 2-slope representation of G. With all compositions described, we can now prove the main theorem of this section.
Theorem 6 Let G be a biconnected series-parallel digraph with n vertices. There exists an O(n 4 )time algorithm that tests if G admits an upward planar 2-slope drawing and, if so, that constructs such a drawing.
Proof: Let e be an edge of G. Compute the (canonical) SPQR-tree T with respect to e of G, which can be done in O(n) time [20,25]. In a post-order traversal of T , the algorithm computes the feasible set for every node of T . If the algorithm arrives at a node with an empty feasible set, its starts with another reference of G. Otherwise, the algorithm stops when it has constructed a feasible tuple for G. We can then use Theorem 1 to construct an upward planar 2-slope drawing. For one reference edge, this takes at most O(n 2 ) time per node by Lemmas 5 and 6. and since the size of T is linear in n, at most O(n 3 ) time in total. The total running time is thus in O(n 4 ).
In Section 4.5 we explain how to handle non-biconnected series-parallel digraphs.

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 G be a biconnected digraph. Let T be the SPQR-tree of G with respect to a reference edge e. The algorithm computes again the feasible sets of the nodes of T 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 skel (µ) to construct U Gµ . If substitutions are successful, we have to check upward planarity and the existence of bad edges.
Lemma 7 Let G be a biconnected digraph with n vertices and T be an SPQR-tree of G. Let µ be an R-node of T with children µ 1 , . . . , µ k . Let d be the diameter of G µ . Given the feasible sets F µ1 , . . . , F µ k , the feasible set F µ can be computed in O(d k n 2 ) time.
Proof: Note that since skel (µ) is triconnected, it has a unique planar embedding (up to mirroring), which we can compute in O(n) time. Note that, by Theorem 1, if skel (µ) contains a bad edge with respect to three non-virtual edges, then F µ is empty. Moreover, then G 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 µ by substituting virtual edges with the respective 2-slope representations. More precisely, for all i ∈ {1, . . . , k}, substitute e i with the 2-slope representation U Gµ i of a feasible tuple in F µi . Let U Gµ denote the partial upward 2-slope representation of G µ during this process, that is, U Gµ consists of an embedding of G µ and the 2-slope assignment for all edges of the U Gµ i , for i ∈ {1, . . . , k}. At each pole of a child µ i in U Gµ check whether the 2-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 . Then test the upward planarity of U Gµ 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 U Gµ ). This flow-based algorithm runs in O(n 2 ) time.
If U Gµ is upward planar, check whether U Gµ contains any bad edge and, if not, extend U Gµ to a 2-slope representation U Gµ of G µ (compare to Lemma 8.2 by Didimo et al. [20]). Suppose there is an edge (x, y) on the outer face of U Gµ that is the sole outgoing edge of x and the sole incoming edge of y. Note that the choice of slope for (x, y) does not influence the spirality of U Gµ , since the angles formed at x and y always add up to the same value; see Figure 15. Lastly, compute the upward 2-slope spirality of U Gµ in O(n) time to obtain a feasible tuple for F µ . By backtracking and trying the remaining feasible tuples of the µ i , we complete the computation of F µ . If a 2-slope representation of G has been found, we apply again Theorem 1 to compute a drawing. Hence, we get the following theorem.
Theorem 7 Let G be a biconnected digraph with n vertices. Suppose that G has at most t nontrivial triconnected components, and that each split component has diameter at most d. Then there exists an O(d t tn 3 + dtn + d 2 n 2 )-time algorithm that tests if G admits an upward planar 2-slope drawing and, if so, that constructs such a drawing of G.

General digraphs
So far we have seen how to test whether a biconnected digraph admits a 2-slope representation. For a general digraph G, 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 G being upward planar does not imply that G 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.
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 c is on the outer face for one of the two blocks and whether their 2-slope representations fit together at c (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 T of G contains a vertex for each block and for each cut vertex, and an edge between a cut vertex c and each block that contains c. For G to admit a 2-slope representation, we must be able to root T at a block (with all edges oriented towards this root block) such that an edge {B, c} between a block B and cut vertex c is oriented towards c only if B admits a 2-slope representation where c is on the outer face (see Figure 17 and compare to Lemma 3 by Chan [10]). Note that if we can root T at a block B , then any other block B has exactly one outgoing edge and B has only incoming edges. For a block B with outgoing edge to a cut vertex c, we say B is a block with respect to c. Note that multiple blocks can be a block with respect to the same cut vertex. Suppose we would know how to root T . With a post-order traversal of T , we could then try to find a 2-slope representation for each block B with respect to c of T that has c on the outer face. However, a priori we do not know at which block to root T . Hence, our algorithm works as follows.
Algorithm. Given G, we can find its cut vertices and blocks and construct its block-cut tree T in O(n) time [50]. Since we do not know what block can function as root of T yet, we start at the leaves of T and work "inwards". Note that a leaf block B has only one edge {B, c} in T to a cut vertex c (unless B = G) and we can thus provisionally direct {B, c} to c. This yields a block with respect to a cut vertex -B with respect to c. Furthermore, during the algorithm, for at least one non-leaf block B either all or all but one of its neighboring blocks have been handled. We then direct each edge {B, c }, where all other blocks adjacent to c have been handled, towards B. If no undirected edge incident to B remains, then all neighboring blocks of B have been handled and B is the root. Otherwise, there remains exactly one undirected edge {B, c}. Therefore, during this ad hoc post-order traversal of T , we can ensure that we always have at least one block B that is the root or for which we can provisionally direct the last undirected edge incident to B towards a cut vertex c in T i.e., B becomes a block with respect to c.
To process a block B with respect to c, we check whether B has a 2-slope representation U B with (i) c on the outer face and (ii) additional constraints on the angles formed at all other cut vertices of B, which we describe in detail below. If this is the case, then we can finalize the direction of the edge {B, c} towards c. Otherwise, if B does not admit such a 2-slope representation, then B has to be the root of T . We then orient all edges of T towards B and continue in the remaining part of T . If we later find that another block also needs to be the root of T , then G does not admit a 2-slope representation. Furthermore, when we arrive back at B, we have to test whether B admits a 2-slope representation at all.
Note that for a block B with respect to c, where c has to be on the outer face of the 2slope representation U B , the algorithms from the previous two sections only have to consider an SPQR-tree with an edge incident to c as reference edge.
Angles of cut vertices. We now describe the additional constraints that have to be checked for a block B at all of B's cut vertices. More precisely, let B be a block with respect to c (or the root) and let c be any other cut vertex of B if it has any. Depending on the degree of c (and c ) in B and in the neighboring blocks of B, we have the following extra conditions on the angles at c and c in U B of B.
• Suppose c (or c ) has degree one in B. Then B is a single edge, c is automatically on the outer face in any 2-slope representation of B, and the angle at c in U B is insignificant.
• Suppose c has degree two in B and c has degree two in another block B 1 ; see Figure 18 (a). Then c has to have a large angle on the outer face in U B , since otherwise it would not be able to attach to U B1 such that B 1 is in the outer face of B. If the same case applies to c , then c has to have a large angle in U B , but not necessarily on the outer face.
• Suppose c has degree two in B and c has degree one in two other blocks B 1 and B 2 . Then we first test if B admits a 2-slope representation where c has a large angle on the outer face; see Figure 18 (b). In this case, both B 1 and B 2 lie in the outer face of B. Otherwise, if c has indegree one and outdegree one in B, we test whether B admits a 2-slope representation where c forms a flat angle on the outer face; see Figure 18 (c). We test once such that B 1 lies on the outer face of B and once for B 2 . In the former case, B 2 would lie in the interior of B and thus {B 2 , c} would be directed as (B 2 , c); in the latter case, B 1 would lie in the interior of B and thus {B 1 , c} would be directed as (B 1 , c). If neither is possible, then B has to be the root. For c there are no restrictions under these conditions.
• The case where c (or c ) has degree two in B and degree one in exactly one other block is similar to the previous case but simpler.
• Suppose c has degree three in B; see Figure 18 (d). Then c has to have a flat angle at c on the outer face. Otherwise B has to be the root. There are again no restrictions for c under these conditions. Figure 18: Conditions on the angles at c and c in U B for block a B with respect to c.
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 e incident to c as reference edge. More precisely, if c has degree two in B, 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 c, that is, we check if there there is 2-slope representation of the child node of e with suitable upward spirality. Otherwise, if c has degree three in B and has to form a flat angle, we take the sole outgoing or sole incoming edge of c in B 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 c 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 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 G once. Hence, we get the following results.
Theorem 8 Let G be a series-parallel digraph with n vertices. There exists an O(n 4 )-time algorithm that tests if G admits an upward planar 2-slope drawing and, if so, that constructs such a drawing.
Theorem 9 Let G be a digraph with n vertices. Let t be the maximum number of nontrivial triconnected components of a block of G, and d be the maximum diameter of a split component of a block of G. Then there exists an O(d t tn 3 + dtn + d 2 n 2 )-time algorithm that tests if G admits an upward planar 2-slope drawing and, if so, that constructs such a drawing of G.

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 N such that its leaves lie on a horizontal line -if N 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 N is upward planar. Clearly, N is upward planar if and only if N admits a desired upward planar embedding. In the affirmative case, let N now be an upward plane phylogenetic network such that its k leaves lie on the outer face. Further assume that N 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 augmentationN of N . Let l 1 , l 2 , . . . , l k be the leaves of N in clockwise order around the outer face. Add new vertices v 1 , v 2 , . . . , v k−1 and edges e i = (l i , v i ) and e i = (l i+1 , v i ), i ∈ {1, . . . , k − 1}; see Figure 19 (a). Then apply Theorem 1 toN to obtain an upward planar 2-slope drawing ofN in O(n) time. We observe from Figure 19 (b) that two vertices l i and l i+1 ofN (neighboring leaves of N ) have different y-coordinates if and only if e i and e i have different lengths. This can be fixed by propagating these length differences through the drawing in the following way ( Figure 19 (cd)). Let G be the dual graph ofN . Furthermore, define G l and G r as the two subgraphs of G with V (G) = V (G l ) = V (G r ) and where E(G l ) and E(G r ) are the dual edges of primal edges with slope and , respectively. In other words, G l is the dual graph ofN restricted to edges with slope . Direct every edge e * in E(G l ) (E(G r )) with primal edge e from the left (resp. right) face of e to the right (resp. left) face of e. Assign to each dual edge flow equal to the length of its primal edge. Split the vertex corresponding to the outer face ofN into a source s and k − 1 sinks t 1 , t 2 , . . . , t k−1 such that t i has as incoming edges the dual edges of the primal edges e i and e i ; see Figure 19 (c). These dual graphs can be constructed in linear time.
Next, to adjust the heights of the leaves of N , for every pair e i and e i , i ∈ {1, . . . , k − 1}, if, say, e i is shorter than e i , propagate the difference as flow backwards towards s through G l ; see Figure 19 (d). With one DFS on G l and G 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 inN and remove the vertices v i , i ∈ {1, . . . , k}, to obtain an upward planar 2-slope drawing of N . The following theorem summarises this section.
Theorem 10 Let N be a phylogenetic network with n vertices and no transitive edge. If N admits an upward planar drawing with all its leaves on the outer face, then N 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 O(n)-time.

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.