Level-Planar Drawings with Few Slopes

We introduce and study level-planar straight-line drawings with a fixed number $\lambda$ of slopes. For proper level graphs, we give an $O(n \log^2 n / \log \log n)$-time algorithm that either finds such a drawing or determines that no such drawing exists. Moreover, we consider the partial drawing extension problem, where we seek to extend an immutable drawing of a subgraph to a drawing of the whole graph, and the simultaneous drawing problem, which asks about the existence of drawings of two graphs whose restrictions to their shared subgraph coincide. We present $O(n^{4/3} \log n)$-time and $O({\lambda} n^{10/3} \log n)$-time algorithms for these respective problems on proper level-planar graphs. We complement these positive results by showing that testing whether non-proper level graphs admit level-planar drawings with $\lambda$ slopes is $\textsf{NP}$-hard even in restricted cases.


Introduction
Directed graphs explaining hierarchy naturally appear in multiple industrial and academic applications. Some examples include PERT diagrams, UML component diagrams, text edition networks [1], text variant graphs [20], philogenetic and neural networks. In these, and many other applications, it is essential to visualize the implied directed graph so that the viewer can perceive the hierarchical structure it contains. By far the most popular way to achieve this is to apply the Sugyiama framework -a generic network visualization algorithm that results in a drawing where each vertex lies on a horizontal line, called layer, and each edge is directed from a lower layer to a higher layer [15].
The Sugyiama framework consists of several steps: elimination of directed cycles in the initial graph, assignement of vertices to layers, vertex ordering and coordinate assignement. During each of these steps several criteria are optimized, by leading to more readable visualizations, see e.g. [15]. In this paper we concentrate on the last step of the framework, namely coordinate assignment. Thus, the subject of our study are level graphs defined as follows. Let G = (V, E) be a directed graph. A k-level assignment of G is a function : V → {1, 2, . . . , k} that assigns each vertex of G to one of k levels. We refer to G together with as to a (k-)level graph. The length of an edge (u, v) is defined as (v) − (u). We say that G is proper if all edges have length one. The level graph shown in Fig. 1  A level drawing Γ of a level graph G maps each vertex v ∈ V to a point on the horizontal line with y-coordinate (v) and a real x-coordinate Γ (v), and each edge to a y-monotone curve between its endpoints. A level drawing is called level-planar if no two edges intersect except in common endpoints. It is straightline if the edges are straight lines. A level drawing of a proper (subdivision of a) level graph G induces a total left-to-right order on the vertices of a level. We say that two drawings are equivalent if they induce the same order on every level. An equivalence class of this equivalence relation is an embedding of G. We refer to G together with an embedding to as embedded level graph G. The third step of Sugyiama framework, vertex ordering, results in an embedded level graph.
The general goal of the coordinate assignment step is to produce a final visualization while further improving its readability. The criteria of readability that have been considered in the literature for this step include straightness and verticality of the edges [15]. Here we study the problem of coordinate assignment step with bounded number of slopes. The slope of an edge (u, v) in Γ is defined as (Γ (v) − Γ (u))/( (v) − (u)). For proper level graphs this simplifies to Γ (v) − Γ (u). We restrict our study to drawings in which all slopes are nonnegative; such drawings can be transformed into drawings with negative slopes by shearing; see Fig. 1. A level drawing Γ is a λ-slope drawing if all slopes in Γ appear in the set {0, 1, . . . , λ − 1}. We study embedding-preserving straight-line level-planar λ-slope drawings, or λ-drawings for short and refer to the problem of finding these drawings as λ-Drawability . Since the possible edge slopes in a λ-drawing are integers all vertices lie on the integer grid.
Related Work. The number of slopes used for the edges in a graph drawing can be seen as an indication of the simplicity of the drawing. For instance, the measure edge orthogonality, which specifies how close a drawing is to an orthogonal drawing, where edges are polylines consisting of horizontal and vertical segments only, has been proposed as a measure of aesthetic quality of a graph drawing [33]. In a similar spirit, Kindermann et al. studied the effect reducing the segment complexity on the aesthetics preference of graph drawings and observed that in some cases people prefer drawings using lower segment complexity [23]. More generally, the use of few slopes for a graph drawing may contribute to the formation of "Prägnanz" ("good figure" in German) of the visualization, that accordingly to the Gestalt law of Prägnanz, or law of simplicity, contributes to the perceived quality of the visualizations. This is design principle often guides the visualization of metro maps. See [30] for a survey of the existing approaches, most of which generate octilinear layouts of metro maps, and [29] for a recent model for drawing more general k-linear metro maps.
Level-planar drawing with few slopes have not been considered in the literature but drawings of undirected graphs with few slopes have been extensively studied. The (planar ) slope number of a (planar) graph G is the smallest number s so that G has a (planar) straight-line drawing with edges of at most s distinct slopes. Special attention has been given to proving bounds on the (planar) slope number of undirected graph classes [4, 9-11, 13, 22, 21, 24, 25, 31]. Determining the planar slope number is hard in the existential theory of reals [17].
Several graph visualization problems have been considered in the partial and simultaneous settings. In the partial drawing extension problem, one is presented with a graph and an immutable drawing of some subgraph thereof. The task is to determine whether the given drawing of the subgraph can be completed to a drawing of the entire graph. The problem has been studied for the planar setting [26,32] and also the level-planar setting [7]. In the simultaneous drawing problem, one is presented with two graphs that may share some subgraph. The task is to draw both graphs so that the restrictions of both drawings to the shared subgraph are identical. We refer the reader to [5] for an older literature overview. The problem has been considered for orthogonal drawings [2] and level-planar drawings [3]. Up to our knowledge, neither partial nor simultaneous drawings have been considered in the restricted slope setting.
Contribution. We introduce and study the λ-Drawability problem. To solve this problem for proper level graphs, we introduce two models. In Section 3 we describe the first model, which uses a classic integer-circulation-based approach. This model allows us to solve the λ-Drawability in O(n log 3 n) time and obtain a λ-drawing within the same running time if one exists. In Section 4, we describe the second distance-based model. It uses the duality between flows in the primal graph and distances in the dual graph and allows us to solve the λ-Drawability in O(n log 2 n/ log log n) time. We also address the partial and simultaneous settings. The classic integer-circulation-based approach can be used to extend connected partial λ-drawings in O(n log 3 n) time. In Section 5, we build on the distance-based model to extend not-necessarily-connected partial λ-drawings in O(n 4/3 log n) time, and to obtain simultaneous λ-drawings in O(λn 10/3 log n) time if they exist. We finish with some concluding remarks in Section 6 and refer to Appendix A for a proof that 2-Drawability is NP-hard even for biconnected graphs where all edges have length one or two.
it is Γ (v) =x for all v ∈ V , Γ (v 1 ) <x and Γ (v 2 ) >x for some v 1 , v 2 ∈ V , and Γ (u) <x < Γ (v) for no edge (u, v) ∈ E. A drawing Γ is compact if it has no gap. Note that a λ-drawing of a connected level-planar graph is inherently compact. While in a λ-drawing of a non-connected level-planar graph every gap can be eliminated by a shift. The fact that we only need to consider compact λdrawings helps us to limit their width. Thus, any compact λ-drawing has a width of at most (λ − 1)(n − 1).
Let u and v be two vertices on the same level i. With A flow network F = (N, A) consists of a set of nodes N connected by a set of directed arcs A. Each arc has a demand specified by a function d : A → N 0 and a capacity specified by a function c : A → N ∪ {∞} where ∞ encodes unlimited capacity. A circulation in F is a function ϕ : A → N 0 that assigns an integral flow to each arc of F and satisifies the two following conditions. First, the circulation has to respect the demands and capacities of the arcs, i.e., for each arc a ∈ A it is d(a) ≤ ϕ(a) ≤ c(a). Second, the circulation has to respect flow conservation, i.e., for each node v ∈ N it is (u,v)∈A ϕ(u, v) = (v,u)∈A ϕ(v, u). Depending on the flow network no circulation may exist.

Flow Model
In this section, we model the λ-Drawability as a problem of finding a circulation in a flow network. Let G be an embedded proper k-level graph together with a level-planar drawing Γ . As a first step, we add two directed paths p left and p right that consist of one vertex on each level from 1 to k to G. Insert p left and p right into Γ to the left and right of all other vertices as the left and right boundary, respectively. See Fig. 2 (a) and (c). From now on, we assume that G and Γ contain the left and right boundary.
The flow network F λ G consists of nodes and arcs and is similar to a directed dual of G with the difference that it takes the levels of G into account. In particular, for every edge e of G, F λ G contains two nodes e left and e right , in the left and the right faces incident to e, and a dual slope arc e = (e right , e left ) with demand 0 and capacity λ − 1; see the blue arcs in Fig. 2 (b) and (c). The flow across e determines the slope of e. Additionally, for every pair of consecutive vertices u, v we add two nodes [u, v] low and [u, v] high to F λ G and connect them by a space arc [u, v] ; see the red arcs in Fig. 2 (b) and (c). The flow across [u, v] determines the space between u and v. The space between u and v needs to be at least one to prevent u and v from colliding and can be at most (λ − 1)(n − 1) due to the restriction to compact drawings. So, assign to [u, v] a demand of one and a capacity of (λ − 1)(n − 1). To obtain the final flow network we merge certain nodes. Let e = (u, w) and e = (v, x) be consecutive edges. Merge the  nodes e right , e left , the nodes {{u , v } high : ∀u , v consecutive in [u, v]} and the nodes {{w , x } low : ∀w , x consecutive in [w, x]} into a single node. Next, merge all remaining source and sink nodes into one source node s and one sink node t, respectively. See Fig. 2 (c), where the gray areas touch nodes that are merged into a single node. Finally, insert an arc from t to s with unlimited capacity.
The network F λ G is designed in such a way that the circulations in F λ G correspond bijectively to the λ-drawings of G. Let Γ be a drawing of G and let x be the function that assigns to each vertex of G its x-coordinate in Γ . We define a dual circulation x as follows. Recall that every arc a of F λ G is either dual to an edge of G or to two consecutive vertices in G. Hence, the left and right incident faces f left and f right of a in F λ G contain vertices of G. Define the circulation x by setting x (a) := x(f right ) − x(f left ). We remark the following, although we defer the proof to the next section. Lemma 1. Let G be an embedded proper level-planar graph together with a λdrawing Γ . The dual x of the function x that assigns to each vertex of G its xcoordinate in Γ is a circulation in F λ G .
In the reverse direction, given a circulation ϕ in F λ G we define a dual function ϕ that, when interpeted as assigning an x-coordinate to the vertices of G, defines a λ-drawing of G. Refer to the level-1-vertex p right as v right . Start by setting ϕ (v right ) = 0, i.e., the x-coordinate of v right is 0. Process the remaining vertices of the right boundary in ascending order with respect to their levels. Let (u, v) be an edge of the right boundary so that u has already been processed and v has not been processed yet. Then set ϕ (v) = ϕ (u) + ϕ((u, v) ), where (u, v) is the slope arc dual to (u, v). Let w, x be a pair of consecutive vertices so that x has already been processed and w has not yet been processed yet. Then set ϕ x] is a space arc. It turns out that ϕ defines a λ-drawing of G.
Lemma 2. Let G be an embedded proper level-planar graph, let λ ∈ N and let ϕ be a circulation in F λ G . Then the dual ϕ , when interpeted as assigning an xcoordinate to the vertices of G, defines a λ-drawing of G.
While both Lemma 1 and Lemma 2 can be proven directly, we defer their proofs to Section 4 where we introduce the distance model and prove Lemma 3 and Lemma 4, the stronger versions of Lemma 1 and Lemma 2, respectively. Combining Lemma 1 and Lemma 2 we obtain the following. Theorem 1. Let G be an embedded proper level-planar graph and let λ ∈ N. The circulations in F λ G correspond bijectively to the λ-drawings of G.
Theorem 1 implies that a λ-drawing can be found by applying existing flow algorithms to F λ G . For that, we transform our flow network with arc demands to the standard maximum flow setting without demands by introducing new sources and sinks. We can then use the O(n log 3 n)-time multiple-source multiple-sink maximum flow algorithm due to Borradaile et al. [6] to find a circulation in F λ G or to determine that no circulation exists.
Corollary 1. Let G be an embedded proper level-planar graph and let λ ∈ N. It can be tested in O(n log 3 n) time whether a λ-drawing of G exists, and if so, such a drawing can be found within the same running time.

Connected Partial Drawings
Recall that a partial λ-drawing is a tuple (G, H, Π), where G is an embedded level-planar graph, H is an embedded subgraph of G and Π is a λ-drawing of H. We say that (G, H, Π) is λ-extendable if G admits a λ-drawing Γ whose restriction to H is Π. Here Γ is referred to as a λ-extension of (G, H, Π).
In this section we show that in case H is connected, we can use the flow model to decide whether (G, H, Π) is λ-extendable. Observe that when H is connected Π is completely defined by the slopes of the edges in H up to horizontal translation. Let F λ G be the flow network corresponding to G. In order to fix the slopes of an edge e of H to a value , we fix the flow across the dual slope arc e in H to . Checking whether a circulation in the resulting flow network exists can be reduced to a multiple-source multiple-sink maximum flow problem, which once again can be solved by the algorithm due to Borradaile et al. [6].
and if so, a corresponding λ-extension can be constructed within the same running time.

Dual Distance Model
A minimum cut (and, equivalently, the value of the maximum flow) of an stplanar graph G can be determined by computing a shortest (s , t )-path in a dual of G [18,19]. Hassin showed that to construct a flow, it is sufficient to compute the distances from s to all other vertices in the dual graph [14]. To the best of our knowledge, this duality has been exploited only for flow networks with arc capacities, but not with arc demands. In this section, we extend this duality to arcs with demands. The resulting dual distance model improves the running time for the λ-Drawability, lets us test the existence of λ-extensions of partial λ-drawings for non-connected subgraphs, and allows us to develop an efficient algorithm for testing the existence of simultaneous λ-drawings.
We Observe that to obtain F λ G from G (with left and right paths p left and p right ) we added dual arcs to edges of G and dual arcs to the space between two consecutive vertices on one level. Consider for a moment the graph G obtained from G by adding edges (u, v) for all consecutive vertices u v, where u is to the right of v. Graph G and D λ G are identical and therefore D λ G has the vertex set V of G and contains a subset of its edges. Recall that the dual slope arcs in F λ G have demand 0 and capacity λ − 1, therefore the edges of D λ G that connect vertices on different layers have non-negative length. While the edges of D λ G between consecutive vertices on the same level have length −1.
A distance labeling is a function x : V → Z that for every edge (u, v) of D λ G with length l satisfies x(v) ≤ x(u)+l. We also say that (u, v) imposes the distance constraint x(v) ≤ x(u) + l. A distance labeling for D λ G is the x-coordinate assignment for a λ-drawing: For an edge (u, v) of D λ G where u, v are consecutive vertices in G, the distance labeling guarantees x(v) ≤ x(u) − 1, i.e., the consecutive vertices are in the correct order and do not overlap. If an edge (u, v) between layers has length λ−1, then the distance labeling ensures x(v) ≤ x(u)+λ−1, i.e., (u, v) has a slope in {0, . . . , λ − 1}. Computing the shortest distances from v right in D λ G to every vertex (if they are well-defined) gives a distance labeling that we refer to as the shortest distance labeling. A distance labeling of D λ G does not necessarily exist. This is the case when D λ G contains a negative cycle, e.g., when the in-or out-degree of a vertex in G is strictly larger than λ. For a distance labeling Fig. 2 (c). The x-coordinate of every vertex is its distance from v right in D 2 G . All red arcs have length −1, all blue arcs pointing up have length 1 and all blue arcs pointing down have length 0. For every red arc there exists an arc in the reverse direction with length ∞. We omit these arcs because they do not impose any constraints on the shortest distance labeling. Lemma 3. Let G be an embedded level-planar graph and Γ be a λ-drawing of G.
The function x that assigns to each vertex of G its x-coordinate in Γ is a distance labeling of D λ G and its dual x is a circulation in F λ G .
Proof. Since Γ preserves the embedding of G, for each consecutive vertices v, u, with v preceeding u in G it holds that Γ (v) < Γ (u). Since Γ is a grid drawing Γ (v) ≤ Γ (u) − 1, which implies x(v) ≤ x(u) + , where = −1 is the length of (u, v). Since Γ is a λ-drawing, i.e. every edge (u, v) between the two levels has a slope in {0, . . , f t , f t+1 = f 1 be the faces incident to some node v of F λ G in counter-clockwise order. Let a be the arc incident to v and dual to the edge between f i and f i+1 with 1 ≤ i ≤ t. If a is an incoming arc, it adds a flow of . This sum cancels to zero, i.e., the flow is preserved at v. Recall that the edge d(a). Hence, all demands are fulfilled and x is indeed a circulation in F λ G .
Recall from Section 3 that for a circulation ϕ in F λ G we define a dual drawing ϕ by setting the x-coordinates of the vertices of G as follows. For the lowest vertex of the right boundary set ϕ (v right ) = 0. Process the remaining vertices of the right boundary in ascending order with respect to their levels. Let (u, v) be an edge of the right boundary so that u has already been processed and v has not been processed yet. Then set ϕ (v) = ϕ (u) + ϕ((u, v) ), where (u, v) is the slope arc dual to (u, v). Let w, x be a pair of consecutive vertices so that x has already been processed and w has not yet been processed yet. Then set ϕ (w) = ϕ (x) + ϕ([w, x] ), where [w, x] is a space arc. It turns out that ϕ is a distance labeling of D λ G and a λ-drawing of G.
Lemma 4. Let G be an embedded level-planar graph, let λ ∈ N, and let ϕ be a circulation in F λ G . The dual ϕ is a distance labeling of D λ G and the drawing induced by interpreting the distance label of a vertex as its x-coordinate is a λdrawing of G.
Proof. We show that ϕ is a distance labeling in D λ G . The algorithm described above assings a value to every vertex of D λ G . We now show that ϕ is indeed a distance labeling by showing that every edge satisfies a distance constraint.
Observe that the distance constraints imposed by edges dual to the space arcs are satisfied by construction. To show that the distance constraints imposed by edges dual to the slope arcs are also satisfied, we prove that for every edge (u, v), it holds that ϕ (v) = ϕ (u) + ϕ((u, v) ). We refer to this as condition C for short. Since ϕ((u, v) ) ≤ λ − 1 and the length of (u, v) is λ − 1 we obtain ϕ (v) = ϕ (u) + , which implied that φ is a distance labeling of D λ G . The proof is by induction based on the bottom to top and right to left order among the edges of D λ G . We say that (a, b) precedes (c, d) if either (a) < (c), or (a) = (c) and a is to the right of c, or (a) = (c) and b is to the right of d (in case a = c). For the base case observe that the edges with both end-vertices on the first level and the edges of p right satisfy condition C by the definition of ϕ . Now let (u, v) be an edge not addressed in the base case and assume that for every edge (u , v ) preceding edge (u, v) condition C holds. For the inductive step we show that condition C also holds for (u, v). Let (u , v ) denote the edge to the right of (u, v) so that (u, v) and (u , v ) are consecutive; see Fig. 5. Because v is not the rightmost vertex on its level this edge exists. Let A denote the set of space It is ϕ (v) = ϕ (v ) + a∈A ϕ(a) by definition of ϕ . Further, by induction hypothesis and since (u , v ) precedes (u, v) it holds that ϕ (v ) = ϕ (u ) + ϕ((u , v ) ). Inserting the latter into the former equation, we obtain ϕ (v) = ϕ (u ) + ϕ((u , v ) ) + a∈A ϕ(a). Again, by definition of ϕ , it is ϕ (u) = ϕ (u ) + b∈B ϕ(b). By subtracting ϕ (u) from ϕ (v) we obtain Flow conservation on the vertex of F λ G to which edges of A and B are incident gives ϕ((u, v) )− a∈A ϕ(a)−ϕ((u , v ) )+ b∈B ϕ(b) = 0. Solving this equation for ϕ(u, v) and inserting it into (1) yields ϕ (v) = ϕ (u) + ϕ ((u, v) ), i.e. the condition C holds for (u, v). Therefore ϕ is a distance labeling, which we have shown to define a λ-drawing of G.
Because D λ G is planar we can use the O(n log 2 n/ log log n)-time shortest path algorithm due to Mozes and Wulff-Nilsen [28] to compute the shortest distance labeling. This improves our O(n log 3 n)-time algorithm from Section 3.
Theorem 2. Let G be an embedded proper level-planar graph. The distance labelings of D k G correspond bijectively to the λ-drawings of G. If such a drawing exists, it can be found in O(n log 2 n/ log log n) time.

Partial and Simultaneous Drawings
In this section we use the distance model from Section 4 to construct partial and simultaneous λ-drawings. We start with introducing a useful kind of drawing. Let Γ be a λ-drawing of G. We call Γ a λ-rightmost drawing when there exists no λ-drawing Γ with Γ (v) < Γ (v) for some v ∈ V . In this definition, we assume x(Γ (v right )) = x(Γ (v right )) = 0 to exclude trivial horizontal translations. Hence, a drawing is rightmost when every vertex is at its rightmost position across all level-planar λ-slope grid drawings of G. It is not trivial that a λrightmost drawing exists, but it follows directly from the definition that if such a drawing exists, it is unique. The following lemma establishes the relationship between λ-rightmost drawings and shortest distance labelings of D λ G . Lemma 5. Let G be an embedded proper level-planar graph. If D λ G has a shortest distance labeling it describes the λ-rightmost drawing of G.
Proof. The shortest distance labeling of D λ G is maximal in the sense that for any vertex v there exists a vertex u and an edge (u, v) with length l so that it is x(v) = x(u) + l. Recall that the definition of distance labelings only requires x(v) ≤ x(u) + l. The claim then follows by induction over V in ascending order with respect to the shortest distance labeling.

Partial Drawings
Let (G, H, Π) be a partial λ-drawing. In Section 3.1 we have shown that the flow model can be adapted to check whether (G, H, Π) has a λ-extension, in case H is connected. In this section, we show how to adapt the distance model to extend partial λ-drawings, including the case H is disconnected. Recall that the distance label of a vertex v is its x-coordinate. A partial λ-drawing fixes the xcoordinates of the vertices of H. The idea is to express this with additional constraints in D λ G . Let v ref be a vertex of H. In a λ-extension of (G, H, Π), the relative distance along the x-axis between a vertex v of H and vertex v ref . This can be achieved by adding an edge : ∀v ∈ H} with lengths as described above.
To decide existence of λ-extension and in affirmative construct the corresponding drawing we compute the shortest distance labeling in D λ G,Π . Observe that this network can contain negative cycles and therefore no shortest distance labeling. Unfortunately, D λ G,Π is not planar, and thus we cannot use the embedding-based algorithm of Mozes and Wulff-Nilsen. However, since all newly introduced edges have v ref as one endpoint, v ref is an apex of D λ G , i.e., removing v ref from D λ G,Π makes it planar. Therefore D λ G,Π can be recursively separated by separators of size O( √ n). We can therefore use the shortest-path algorithm due to Henzinger et al. to compute the shortest distance labeling of D λ G,Π in O(n 4/3 log n) time [16].

Simultaneous Drawings
In the simultaneous λ-drawing problem, we are given a tuple (G 1 , G 2 ) of two embedded level-planar graphs that share a common subgraph G 1∩2 = G 1 ∩ G 2 . We assume w.l.o.g. that G 1 and G 2 share the same right boundary and that the embeddings of G 1 and G 2 coincide on G 1∩2 . The task is to determine whether there exist λ-drawings Γ 1 , Γ 2 of G 1 , G 2 , respectively, so that Γ 1 and Γ 2 coincide on the shared graph G 1∩2 . The approach is the following. Start by computing the rightmost drawings of G 1 and G 2 . Then, as long as these drawings do not coincide on G 1∩2 add necessary constraints to D λ G1 and D λ G2 . This process terminates after a polynomial number of iterations, either by finding a simultaneous λ-drawing, or by determining that no such drawing exist.
Finding the necessary constraints works as follows. Suppose that Γ 1 , Γ 2 are the rightmost drawings of G 1 , G 2 , respectively. Because both G 1 and G 2 have the same right boundary they both contain vertex v right . We define the coordinates in the distance labelings of D λ G1 and D λ G2 in terms of this reference vertex. Now suppose that for some vertex v of G 1∩2 the x-coordinates in Γ 1 and Γ 2 differ, i.e., it is Γ 1 (v) = Γ 2 (v). Assume Γ 1 (v) < Γ 2 (v) without loss of generality. Because Γ 1 is a rightmost drawing, there exists no drawing of G 1 where v has an x-coordinate greater than Γ 1 (v). In particular, there exist no simultaneous drawings where v has an x-coordinate greater than Γ 1 (v). Therefore, we must search for a simultaneous drawing where Γ 2 (v) ≤ Γ 1 (v). We can enforce this constraint by adding an edge (v right , v) with length Γ 1 (v) into D λ G2 . We then attempt to compute the drawing Γ 2 of G 2 defined by the shortest distance labeling in D λ G2 . This attempt produces one of two possible outcomes. The first possibility is that there now exists a negative cycle in D λ G2 . This means that there exists no drawing Γ 2 of G 2 with Γ 2 (v) ≤ Γ (v). Because Γ 1 is a rightmost drawing, this means that no simultaneous drawings of G 1 and G 2 exist. The algorithm then terminates and rejects this instance. The second possiblity is that we obtain a new drawing Γ 2 . This drawing is rightmost among all drawings that satisfy the added constraint Γ 2 (v) ≤ Γ 1 (v). In this case there are again two possibilities. Either we have Γ 1 (v) = Γ 2 (v) for each vertex v in G 1∩2 . In this case Γ 1 and Γ 2 are simultaneous drawings and the algorithm terminates. Otherwise there exists at least one vertex w in G 1∩2 with Γ 1 (w) = Γ 2 (w). We then repeat the procedure just described for adding a new constraint.
We repeat this procedure of adding other constraints. To bound the number of iterations, recall that we only consider compact drawings, i.e., drawings whose width is at most (λ − 1)(n − 1). In each iteration the x-coordinate of at least one vertex is decreased by at least one. Therefore, each vertex is responsible for at most (λ − 1)(n − 1) iterations. The total number of iterations is therefore bounded by n(λ − 1)(n − 1) ∈ O(λn 2 ).
Note that due to the added constraints D λ G1 and D λ G2 are generally not planar. We therefore apply the O(n 4/3 log n)-time shortest-path algorithm due to Henzinger et al. that relies not on planarity but on O( √ n)-sized separators to compute the shortest distance labellings. This gives the following. Theorem 4. Let G 1 , G 2 be embedded level-planar graphs that share a common subgraph G 1∩2 . In O(λn 10/3 log n) time it can be determined whether G 1 , G 2 admit simultaneous λ-drawings and if so, such drawings can be computed within the same running time.

Conclusion
In this paper we studied λ-drawings, i.e., level-planar drawings with λ slopes. We model λ-drawings of proper level-planar graphs as integer flow networks. This lets us find λ-drawings and extend connected partial λ-drawings in O(n log 3 n) time. We extend the duality between integer flows in a primal graph and shortest distances in its dual to obtain a more powerful distance model. This distance model allows us to find λ-drawings in O(n log 2 n/ log log n) time, extend notnecessarily-connected partial λ-drawings in O(n 4/3 log n) time and find simultaneous λ-drawings in O(λn 10/3 log n) time.
In the non proper case, testing the existence of a 2-drawing becomes NP-hard, even for biconnected graphs with maximum edge length two; see Appendix A.

A Complexity of the General Case
So far, we have considered proper level graphs, i.e., level graphs where all edges have length one. In this section, we consider the general case, where edges may have arbitrary lengths. We say that an edge with length two or more is long. One approach would be to try to adapt the flow model from Section 3 to this more general case. By subdividing long edges, any level graph G can be transformed into a proper level graph G . Observe that two edges in G created by subdividing the same long edge must have the same slope in order to yield a fixed-slope drawing of G. In the context of our flow model, this means that the amount of flow across the corresponding slope arcs must be the same. Our problem then becomes an instance of the integer equal flow problem. In this problem, we are given a flow network along with disjoint sets R 1 , R 2 , . . . , R t of arcs. The task is to find the maximum flow from s to t such that the amount of flow across arcs in the same set R i is the same. This problem was introduced and shown to be NP-hard by Sahni [34]. The problem remains NP-hard in special cases [12,35] and the integrality gap of the fractional LP can be arbitrarily large [27].
In this section we show that the level-planar grid drawing problem is NPcomplete even for two slopes and biconnected graphs where all edges have length one or two. To this end, we present a reduction from rectilinear planar monotone 3-Sat [8]. An instance of this problem consists of a set of variables X and a set of clauses C. A clause is positive (negative) when it consists of only positive (negative) literals. We say that the instance is monotone when each clause is either positive or negative. Further, the instance can be planarly drawn as a graph with vertices X ∪ C; see Fig. 6. In this drawing, the variables are aligned along a virtual horizontal line X . Positive clauses are drawn as vertices above X and connected by an edge to a variable if the clause contains the corresponding postive literal. Symmetrically, negative clauses are drawn as vertices below X and connected by an edge to a variable if the clause contains the corresponding negative literal.
Our reduction works by first replacing every vertex that corresponds to a variable by a variable gadget and every vertex that corresponds to a positive (negative) clause by a positive (negative) clause gadget. All three gadgets consist of fixed and movable parts. The fixed parts only admit one level-planar two-slope  grid drawing, whereas the movable parts admit two or more drawings depending on the choice of slope for some edges. Second, the gadgets are connected by a common fixed frame. All fixed parts of the gadgets are connected to the common frame in order to provide a common point of reference. The movable parts of the gadgets then interact in such a way that any level-planar two-slope grid drawing induces a solution to the underlying planar monotone 3-Sat instance. The variable gadget consists of a number of connectors arranged around a fixed horizontal line that connects all variable gadgets along the virtual line of variables X . See Fig. 7, where the fixed structure is shaded in gray. Vertices drawn as squares are fixed, i.e., they cannot change their position relative to other vertices drawn as squares. Vertices drawn as circles are movable, i.e., they can change their position relative to vertices drawn as squares. The line of variables X extends from the the square vertices on the left and right boundaries of the drawing. Every connector consists of two pins: the movable assignment pin and the fixed reference pin. The variable gadget in Fig. 7 features four connectors: two above the horizontal line and two below the horizontal line. Assignment pins are shaded in yellow and reference pins are shaded in gray. The relative position of the assignment pin and the reference pin of one connector encodes the truth assignment of the underlying variable. Moreover, the reference pin allows the fixed parts of the clause gadgets to be connected to the variable gadgets and thereby to the common frame. Comparing Fig. 7 (a) and (b), observe how the relative position of the two pins of each connector changes depending on the truth assignment of the underlying variable. The key structure of the variable gadget is that the position of the assignment pins of one variable gadget are coordinated by long edges. In Fig. 7, long edges are drawn as thick lines. Changing the slope of these long edges moves all assignment pins above the horizontal line in one direction and all assignment pins below the horizontal line in the reverse direction. In this way, all connectors encode the same truth assignment of the underlying variable. Note that we can introduce as many connectors as needed for any one variable.
The positive clause gadget consists of a fixed boundary, a movable wiggle and three assignment pin endings. See Fig. 8, where the fixed boundary is shaded in gray, the wiggle is highlighted in blue and the assignment pin endings are highlighted in yellow. The fixed boundary is connected to the reference pin of the variable gadget that is rightmost amongst the connected variable gadgets. Because the variable gadgets are fixed to the common frame, the boundary of the positive clause gadget is also connected to the common frame. The assignment pin endings are connected to assigment pins of connectors of the corresponding variable gadgets. The idea of the positive clause gadget is that the wiggle has to wiggle through the space bounded by the assignment pin endings on the left and the fixed boundary on the right. Recall that the assignment pins change their horizontal position depending on the truth assignment of their underlying variables. The positive clause gadget is designed so that the wiggle can always be drawn, except for the case when all variables are assigned to false. See Fig. 8 (a)-(c), which shows the three possible situations when exactly one variable is assigned to true. In any case where at least one variable is assigned to true the wiggle can be drawn in one of the three ways shown. However, as shown in Fig. 8 (d), the wiggle cannot be drawn in the case where all variables are assigned to false. The reason for this is that the the assignment pin endings get so close to the fixed boundary that they leave too little space for the wiggle to be drawn. This means that some vertices must intersect, for example those shown in red in Fig. 8 (d).
The negative clause gadgets works very similarly. It is drawn below the horizontal line of variables and it forces at least one of the incident variable gadgets to be configured as false. See Fig. 9, where subfigures (a)-(c) show the admissible drawings and subfigure (d) shows that the case when all incident variables are configured as true cannot occur. Note that this uses the design of the vari-  Fig. 9. The negative clause gadget. Subfigures (a)-(c) show the drawing when at least one variable is assigned to false. Subfigure (d) shows that no drawing exists when all variables are assigned to true, because this leads to intersections, e.g., at the vertices marked in red. Note the symmetry to the positive clause gadget in Fig. 8. able gadget that the assignment and reference pins below the horizontal line are closer when the variable is assigned to true (i.e., the inverse situtation compared to the situation above the horizontal line). It is evident that any level-planar two-slope grid drawing of the resulting graph induces a solution of the underlying planar monotone 3-Sat problem and vice versa. Note that the variable gadgets become biconnected when embedded into the common frame and that the clause gadgets are biconnected by design. Furthermore, all long edges have length two. We therefore conclude the following.
Theorem 5. The level-planar grid drawing problem is NP-complete even for two slopes and biconnected graphs where all edges have length one or two.