Computing NodeTrix Representations of Clustered Graphs

NodeTrix representations are a popular way to visualize clustered graphs; they represent clusters as adjacency matrices and inter-cluster edges as curves connecting the matrix boundaries. We study the complexity of constructing NodeTrix representations focusing on planarity testing problems, and we show several NP-completeness results and some polynomial-time algorithms. Building on such algorithms we develop a JavaScript library for NodeTrix representations aimed at reducing the crossings between edges incident to the same matrix.

In this paper we study the problem of automatically constructing an NT representation of a given flat clustered graph. This problem combines traditional graph drawing issues, like the placement of a set of geometric objects in the plane (here the squares Q 1 , . . . , Q k ) and the routing of the graph edges (here the inter-cluster edges), with a novel algorithmic challenge: To handle the degrees of freedom given by the choice of the order for the rows and the columns of the matrices and by the choice of the side of the matrices to which the inter-cluster edges attach to. Indeed, the order of the rows and columns of a matrix M i is arbitrary, as long as M i is symmetric; further, an inter-cluster edge incident to M i can arbitrarily exit M i from four sides: left or right if it exits M i from its associated row, or top or bottom if it exits M i from its associated column.
When working on a new model for graph representations, the very first step is usually to study the complexity of testing if a graph admits a planar representation within that model. Hence, in Section 2 we deal with the problem of testing if a flat clustered graph admits a planar NT representation. An NT representation is planar if no inter-cluster edge e intersects any matrix M i , except possibly at an end-point of e on Q i , and no two inter-cluster edges e and e cross each other, except possibly at a common end-point. The Nodetrix Planarity (NT Planarity for short) problem asks if a flat clustered graph admits a planar NT representation.
Our findings show how tough the problem is (see Table 1). Namely, we show that NT Planarity is NP-complete and remains so even if the order of the rows and of the columns of the matrices is fixed (i.e., it is part of the input), or if the exit sides of the inter-cluster edges on the matrix boundaries are fixed. It is easy to show that NT Planarity becomes linear-time solvable if both the row-column order and the exit sides of the inter-cluster edges are fixed. But this is probably too restrictive for practical applications since all the degrees of freedom that are representation-specific are lost.
Motivated by such complexity results, in Section 3 we study a more constrained model that is still useful for practical applications. A monotone NT representation is an NT representation in which the matrices have prescribed positions and the inter-cluster edges are represented by xy-monotone curves inside the convex hull of their incident matrices. We require that this convex hull, which might contain many edges, does not intersect any other matrix. We study this model for two reasons. First, in most of (although not in all) the available examples of NT representations the inter-cluster edges are represented by xy-monotone curves (see, e.g., the NodeTrix clips and prototype available online [2]). Second, we are interested in supporting a visualization system where the position of the matrices is decided by the user and the inter-cluster edges are automatically drawn with "few" crossings. Therefore, the crossings between inter-cluster edges not incident to a common matrix are somehow unavoidable, as they depend on the matrix positions selected by the users, and we are only interested in reducing the number of local crossings, that are the crossings between pairs of edges incident to the same matrix.
We say that an NT representation is locally planar if no two inter-cluster edges incident to the same matrix cross. While testing if a flat clustered graph admits a monotone NT locally planar representation is NP-complete even if the sides are fixed (see Table 1), the problem becomes polynomial-time solvable in the reasonable scenario in which the number of matrices is constant, the order of the rows and columns is fixed, and the sides of the matrices to which the inter-cluster edges attach is variable.
Building on the insights for the last result, we developed a library (Section 3.1) for NT representations (a demo is available online [3]). The adopted techniques allow the user to move the matrices around while the layout of the inter-cluster edges is automatically recomputed; this happens without any slowdown of the interaction.
Conclusions and open problems are discussed in Section 4 where NT Planarity is related to graph drawing problems of theoretical interest.
Before proceeding to prove our results, we establish formal definitions and notation. An NT representation consists of: 1. A row-column order σ i for each cluster V i , that is, a bijection σ i : V i ↔ {1, . . . , |V i |}. 2. A side assignment s i for each inter-cluster edge incident to V i , that is, an injective mapping s i : j =i E i,j → {t, b, l, r}, where E i,j is the set of intercluster edges between the clusters V i and V j (V i and V j are adjacent if E i,j = ∅). 3. A matrix M i for each cluster V i , that is, a representation of V i as a symmetric adjacency matrix such that: (a) the boundary of M i is a square Q i with sides parallel to the coordinate axes; let min x (Q i ) be the minimum x-coordinate of a point on Q i ; min y (Q i ), max x (Q i ), and max y (Q i ) are defined analogously; (b) the left-to-right order of the columns and the top-to-bottom order of the rows in M i is σ i ; and (c) any two distinct matrices are disjoint; if V i has only one vertex, we often talk about the matrix representing that vertex, rather than the matrix representing V i . 4. An edge drawing for each inter-cluster edge e = (u, v) with u ∈ V i and v ∈ V j , that is, a representation of e as a Jordan curve between two points p u and p v defined as follows. Let m u t be the mid-point of the line segment that is the intersection of the top side of Q i with the column associated to u in M i ; points m u b , m u l , and m u r are defined analogously. Then p u coincides with m u t , m u b , m u l , or m u r if s i (e) = t, s i (e) = b, s i (e) = l, or s i (e) = r, respectively. Point p v is defined analogously.

Testing NodeTrix Planarity
In this section we study the time complexity of testing NodeTrix Planarity for a flat clustered graph. We start with the following. Theorem 1. NodeTrix Planarity is NP-complete even if at most three clusters contain more than one vertex.
Proof: The membership in NP of NT Planarity is proved in Lemma 3. For the NP-hardness we give a reduction from an NP-complete problem called Partitioned 3-Page Book Embedding [7], whose input is a graph (V, E) with E partitioned into three sets E 1 , E 2 , and E 3 . The problem asks whether a total ordering O of V exists such that the end-vertices of any two edges e and e in the same set E i do not alternate in O; e and e alternate if an end-vertex of e is between the two end-vertices of e in O and vice versa.
Embedding and (b) the corresponding instance (V , E , C ) of NT Planarity. The gray regions are R 1,2 and R 2,3 .
We show how to construct in polynomial time an instance (V , E , C ) of NT Planarity starting from an instance (V, Fig. 1. We define C (and hence implicitly V ) as follows.
sets V i are in bijection with V (and hence with each other); we denote by v i the vertex in V i that is in bijection with a vertex v ∈ V ; for every edge e ∈ E, set C contains a cluster {u e }; and The set E contains an arbitrary set of intra-cluster edges and the following inter-cluster edges.
equivalence edges: edges (u e , r i ) and (u e , s i ), for every edge e = (r, s) ∈ E i ; bounding edges: the edges of cycle D = (u l , t 1 1 , . . . , t 1 side-filling edges: edges between u l and every vertex in V 1 , edges between u r and every vertex in V 3 , and edges between u i b and every vertex in V i for i = 1, 2, 3; and corner edges: The described construction can easily be performed in polynomial time. We now prove the equivalence between the instance (V, E) of Partitioned 3-Page Book Embedding and the instance (V , E , C ) of NT Planarity.
The direction (=⇒) is easy to prove. Suppose that (V, E) is a positive instance of Partitioned 3-Page Book Embedding and let O be a total ordering of V such that the end-vertices of any two edges e and e in the same set E i do not alternate in O. For i = 1, 2, 3, let σ i be the total order of the vertices in V i such that x i , y i , w i , and z i are the first, second, last but one, and last vertex in σ i , respectively, and the vertices in V i (which all follow x i and y i and precede w i and z i in σ i ) are ordered so that, for every r i , s i ∈ V i , vertex r i precedes vertex s i in σ i if and only if r precedes s in O. For i = 1, 2, 3, we represent V i as a symmetric adjacency matrix M i whose left-to-right order of the columns is σ i ; every other cluster in C consists of a single vertex and we arbitrarily define a matrix for it. We embed these matrices in the plane (except for the matrices representing vertices u e with e ∈ E, which will be embedded later) so that no two of them overlap. The side assignment for the inter-cluster edges is as follows.
First, we assign: to the right (left) side of the matrix representing the first (resp. second) vertex in the pair; edges (b 1 1 , u l ), (u l , t 1 1 ), (b 3 7 , u r ), and (u r , t 3 7 ) to the top (bottom) side of the matrix representing the first (resp. second) vertex in the pair; every other edge incident to t i j to the bottom side of the matrix representing t i j ; every other edge incident to b i j to the top side of the matrix representing b i j ; every other edge incident to u i b to the top side of the matrix representing u i b ; every other edge incident to u l to the right side of the matrix representing u l ; and every other edge incident to u r to the left side of the matrix representing u r .
By suitably routing the bounding edges, we get that M 1 , M 2 , and M 3 we ensure that the cycle D bounds the outer face of the representation, with M 1 , M 2 , and M 3 inside it.
Second, we assign the side-filling and order-preserving edges so that none of them is assigned to the top side of a matrix M i . To achieve this, we assign: the side-filling edges incident to u l and to u r to the left side of M 1 and to the right side of M 3 , respectively; the side-filling edges incident to u i b to the bottom side of M i ; and the order-preserving edges between vertices in V i and vertices in V i+1 to the right side of M i and to the left side of M i+1 . Route all these edges inside D. In particular, the order-preserving edges can be routed without crossings since the top-to-bottom order of the vertices in V i along the Third, we assign the corner edges (t The corner edges can routed inside D without crossing the side-filling and order-preserving edges since by construction their end-vertices in V i are the first, second, last but one, and last vertex in σ i . Fourth, embed the matrices representing u e with e ∈ E i in the region R i delimited by edges (t 3 i , t 4 i ), (t 3 i , y i ), and (t 4 i , w i ), and by the top side of M i . Assign the equivalence edges (u e , r i ) and (u e , s i ) to the top side of M i and to any sides of the matrix representing u e ; route these edges in R i . This can be done without introducing crossings, since the left-to-right order σ i − {x i , y i , w i , z i } of the vertices in V i along the top side of M i is the same as the order O of the vertices in V (according to the bijection between V i and V ), hence no two pairs of edges ((p i , u e ), (u e , q i )) and ((r i , u f ), (u f , s i )) have alternating end-points along the top side of M i given that edges (p, q) and (r, s) do not have alternating end-vertices in O.
The proof of the direction (⇐=) is more involved. Given a solution Γ for the instance (V , E , C ) of NT Planarity, we need to define an ordering O for the vertex set V in the instance (V, E) of Partitioned 3-Page Book Embedding. In order to do that, we prove some claims and lemmata about the structure of Γ . For i = 1, 2, 3, let M i be the matrix representing V i in Γ , let Q i be its boundary, and let σ i be the left-to-right order of the vertices in V i along the top side of Q i . We have the following. Proof: The statement follows from the fact that the clusters V i for i = 1, 2, 3 and {u e } for e ∈ E are connected by inter-cluster edges that are not bounding edges. Indeed, the clusters V 1 , V 2 , and V 3 are connected by order-preserving edges and each cluster {u e } is connected to a cluster V i by two equivalence edges. Thus, if the matrices representing two of these clusters were on opposite sides of D in Γ , there would exist: (i) an order-preserving or an equivalence edge crossing a matrix representing a vertex in D or crossing a bounding edge, or (ii) a matrix among M 1 , M 2 , and M 3 or a matrix representing a vertex u e with e ∈ E overlapping a matrix representing a vertex in D or crossing a bounding edge. However, this would contradict the planarity of Γ .
We henceforth assume that M 1 , M 2 , and M 3 , as well as the matrices representing the vertices u e for all e ∈ E, are inside D in Γ . Indeed, by Claim 1, these matrices are on the same side of D in Γ . If they are outside D, then the matrices representing vertices in D are all incident to an internal face f of Γ . Hence, changing the outer face of Γ to f ensures that M 1 , M 2 , and M 3 and the matrices representing the vertices u e for all e ∈ E are inside D in Γ . This change of the outer face can be accomplished by rerouting the inter-cluster edges that are dual to a simple path in the dual of Γ from f to the outer face.
In the following we also assume that t 1 1 , t 1 2 , and t 1 3 are encountered in this order when traversing D in clockwise direction. This is not a loss of generality, up to a reflection of Γ .
Let Γ be the restriction of Γ to M 1 , M 2 , and M 3 , to the matrices representing the vertices t i j , b i j , u i b , u l , and u r , and to the bounding and corner edges of (V , E , C ). For i = 1, 2, let R i,i+1 be the region of the plane delimited by the , by the boundaries of M i and M i+1 , and by the boundaries of the matrices representing vertices t i 7 , b i 7 , t i+1 1 , and b i+1 1 . We have the following.
Claim 2 Every order-preserving edge connecting a vertex in V i with a vertex in V i+1 lies inside R i,i+1 .
Proof: Assume that i = 1; the discussion with i = 2 is analogous. We define three regions that partition the interior of Γ . Region R 1 is the minimal simple (i.e., without holes) region of the plane containing M 1 and containing the matrices and edges representing path 1 , u l , t 1 1 , . . . , t 1 7 , y 1 ). Region R 2 is the minimal simple region of the plane containing M 2 , M 3 , and containing the matrices and edges representing path D 2 = (y 2 , t 2 1 , . . . , t 2 7 , t 3 1 , . . . , t 3 7 , u r , b 3 7 Since D 1 and M 1 do not share vertices with D 2 , M 2 , and M 3 , since D 1 and D 2 are both incident to the outer face of Γ , and since R 1 and R 2 are simple, we have that R 1 and R 2 are disjoint. Further, the only faces of Γ regions R 1 and R 2 are both incident to (and which the order-preserving edges lie because of the planarity of Γ ) are the outer face of Γ and R i,i+1 ; however, neither M i nor M i+1 is incident to the outer face of Γ , since M i and M i+1 lie inside D. It follows that every order-preserving edge connecting a vertex in V i with a vertex in V i+1 lies inside R i,i+1 .
We now present the following claim, which argues about the incidences between the corner edges and the square Q i .   Proof: We prove that, if y i precedes w i in σ i , then statement (1) holds true. A similar proof shows that, if w i precedes y i in σ i , then statement (2) holds true.
First, each of the four corner edges (t i 1 , y i ), (t i 3 , y i ), (t i 7 , y i ), and (b i 4 , y i ) incident to y i is assigned to a distinct side of Q i in Γ . Indeed assume, for a contradiction, that two of these corner edges, say (t i 1 , y i ) and (t i 3 , y i ), are assigned to the same side of Q i , as in Fig. 3a; this implies that the end-points of (t i 1 , y i ) and (t i 3 , y i ) on Q i coincide. Let p * be the end-point of these edges on Q i ; thus, p * is on the boundary of a row or column of M i associated to y i . Let R * be the region delimited by the corner edges (t i 1 , y i ) and (t i 3 , y i ), by the bounding edges (t i 1 , t i 2 ) and (t i 2 , t i 3 ), and by the boundaries of the matrices representing t i 1 , t i 2 , and t i 3 . Suppose that Q i is not contained in R * . If edge (t i 2 , x i ) leaves the matrix representing t i 2 outside D, then it crosses D since M i is inside D, a contradiction. Otherwise, (t i 2 , x i ) leaves the matrix representing t i 2 inside R * . Since p * is the only point on Q i incident to R * and since p * is not on the boundary of a row or column of M i associated to x i , we have that (t i 2 , x i ) crosses the boundary of R * , a contradiction. If Q i is contained in R * , a contradiction can be derived analogously by considering the routing of edge (t i 6 , x i ) rather than (t i 2 , x i ). A similar argument proves that each of the four corner edges (t i We now prove that (t i 1 , y i ) is assigned to the left side of Q i . Assume the contrary, for a contradiction; refer to Fig. 3b, where (t i 1 , y i ) is assigned to the top side of Q i . Consider the line segment Q + traversed when walking along Q i in clockwise direction from the end-point of (t i 1 , y i ) to the end-point of (t i 3 , y i ). If (t i 1 , y i ) is assigned to the top, right, or bottom side of Q i , we have that Q + entirely contains the top side of the column of M i associated to w i , the right side of the row of M i associated to w i , or the left side of the row of M i associated to w i , respectively. Since one of the four corner edges incident to w i has its end-point on this segment and since none of t i 1 , t i 2 , and t i 3 is adjacent to w i , it follows that: (i) one of the corner edges (t i 1 , y i ) and (t i 3 , y i ), or one of the corner edges incident to w i crosses a matrix representing a vertex in D or crosses one of the bounding edges; or (ii) two among the corner edges (t i 1 , y i ) and (t i 3 , y i ), and among the corner edges incident to w i cross each other. In both cases we get a contradiction to the planarity of Γ .
Since (t i 1 , y i ) is assigned to the left side of Q i , since each of the four corner edges incident to y 1 is assigned to a distinct side of Q i , and since t i 1 , t i 3 , t i 7 , and b i 4 appear in this clockwise order along D, we have that (t i 3 , y i ), (t i 7 , y i ), and (b i 4 , y i ) are assigned to the top, right, and bottom side of Q i , respectively.
An analogous proof shows that (t i 4 , w i ), (b i 7 , w i ), (b i 5 , w i ), and (b i 1 , w i ) are assigned to the top, right, bottom, and left side of Q i , respectively.
Further, (t i 2 , x i ) is assigned to the left or top side of Q i , since (t i 1 , y i ) and (t i 3 , y i ) are assigned to the left and top side of Q i , respectively, and since t i 1 , t i 2 , and t i 3 appear in this clockwise order along D. In both cases, x i precedes y i in σ i . An analogous argument proves that z i follows w i in σ i . Hence, x i , y i , w i , and z i appear in this order in σ i .
It remains to argue that x i , y i , w i , and z i are the first, second, last but one, and last vertex in σ i , respectively; refer to are both assigned to the bottom side of Q i , it follows that all the side-filling edges incident to u i b have their other end-point on the bottom side of Q i , between the end-point of (b i 4 , y i ) and the end-point of (b i 5 , w i ). Thus, all the vertices in V i come after y i and before w i in σ i ; this concludes the proof of statement (1).
We are now ready to state and prove the following two lemmata.
3 , y 1 ) and (t i 4 , w 1 ) are assigned to, except possibly for the edges (u e , r i ) and (u e , s i ) such that r i and s i are consecutive in σ i . The statement clearly implies Lemma 1. Note that (t i 3 , y i ) and (t i 4 , w i ) are assigned either both to the top or both to the bottom side of Q i , by Claim 3.
We first prove that, for any edge e = (r, s) ∈ E i , the edges (u e , r i ) and (u e , s i ) are assigned to the same side of Q i . Indeed suppose, for a contradiction, that the edge (u e , r i ) is assigned to, say, the top side of Q i and the edge (u e , s i ) is assigned to a different side of Q i . By Claim 3, there exist two corner edges that are assigned to the top side of Q i and that are incident to the second and to the last but one vertex in σ i , respectively; these corner edges are (t i 3 , y i ) and (t i 4 , w i ), or (b i 5 , w i ) and (b i 4 , y i ). Assume that they are (t i 3 , y i ) and (t i 4 , w i ), as the other case is analogous. Consider the region R t delimited by (t i 3 , y i ) and (t i 4 , w i ), by the bounding edge (t i 3 , t i 4 ), by the boundaries of the matrices representing t i 3 and t i 4 , and by the top side of Q i . By Claim 3, the incidence point of edge (u e , r i ) on the top side of Q i is between the incidence points of (t i 3 , y i ) and (t i 4 , w i ) on the top side of Q i , given that r i ∈ V i . Since edge (u e , r i ) does not cross M i , it leaves M i inside R t . Since (u e , s i ) is assigned to a side of Q i different from the top side, then edge (u e , r i ), or edge (u e , s i ), or the matrix representing u e crosses the boundary of R t , a contradiction to the planarity of Γ . It follows that the edges (u e , r i ) and (u e , s i ) are assigned to the same side of Q i . Now suppose that, for some e = (r, s) ∈ E i , the edges (u e , r i ) and (u e , s i ) are both assigned to a side different from the one the edges (t i 3 , y i ) and (t i 4 , w i ) are assigned to, and suppose that r i and s i are not consecutive in σ i . By Claim 3, the edges (u e , r i ) and (u e , s i ) are both assigned to the side (b i 4 , y i ) and (b i 5 , w i ) are assigned to, or to the side (t i 1 , y i ) and (b i 1 , w i ) are assigned to, or to the side (t i 7 , y i ) and (b i 7 , w i ) are assigned to.
Assume first that (u e , r i ) and (u e , s i ) are both assigned to the side (b i 4 , y i ) and (b i 5 , w i ) are assigned to. As in the proof of Claim 3, we can define R b as the region delimited by the edges , and by the boundaries of the matrices representing b i 4 , u i b , b i 5 , and V i ; then every side-filling edge incident to u i b leaves the matrix representing u i b inside R b , as otherwise it would cross D. It follows that all the side-filling edges incident to u i b have their other end-point on the same side of Q i edges (b i 4 , y i ) and (b i 5 , w i ) are assigned to. Let p i ∈ V i be any vertex between r i and s i in σ i . This vertex exists by hypothesis. Since p i is between r i and s i in σ i , the incidence point of the side-filling edge (u i b , p i ) on Q i is between the incidence points of (u e , r i ) and (u e , s i ) on Q i . It follows that (u i b , p i ) crosses M i , or the matrix representing u e , or (u e , r i ), or (u e , s i ).
The cases in which (u e , r i ) and (u e , s i ) are both assigned to the side (t i 1 , y i ) and (b i 1 , w i ) are assigned to (with i = 1), or to the side (t i 7 , y i ) and (b i 7 , w i ) are assigned to (with i = 3) are analogous to the previous one, with u l or u r playing the role of u i b , respectively. Assume next that (u e , r i ) and (u e , s i ) are both assigned to the side (t i 7 , y i ) and (b i 7 , w i ) are assigned to and i ≤ 2. By Claim 3 and by the planarity of Γ , the matrix representing u e and the edges (u e , r i ) and (u e , s i ) lie inside region R i,i+1 . By Claim 2, every order-preserving edge between a vertex in V i and a vertex in V i+1 also lies inside R i,i+1 , hence it is assigned to the same side of Q i as (t i 7 , y i ) and (b i 7 , w i ). Again by Claim 3, every order-preserving edge between a vertex in V i and a vertex in V i+1 has its end-point between the end-points of (t i 7 , y i ) and (b i 7 , w i ) along the side of Q i these edges are all assigned to. Let p i ∈ V i be any vertex between r i and s i in σ i . This vertex exists by hypothesis. Since p i is between r i and s i in σ i , then the incidence point of the order-preserving edge (p i , p i+1 ) on Q i is between the incidence points of (u e , r i ) and (u e , s i ) on Q i . It follows that (p i , p i+1 ) crosses M i , or the matrix representing u e , or (u e , r i ), or (u e , s i ).
The case in which (u e , r i ) and (u e , s i ) are both assigned to the side (t i 1 , y i ) and (b i 1 , w i ) are assigned to and i ≥ 2 is analogous to the previous one. This concludes the proof of Lemma 1.
either are the same ordering or are the reverse of each other (according to the bijection between V i and V j ).
Proof: By Claim 3, (t i 7 , y i ) and (b i 7 , w i ) are both assigned to the right or to the left side of Q i , and (t i+1 1 , y i+1 ) and (b i+1 1 , w i+1 ) are both assigned to the right or to the left side of Q i+1 . We distinguish four cases, based on these two assignments.
If (t i 7 , y i ) and (b i 7 , w i ) are both assigned to the right side of Q i , and (t i+1 1 , y i+1 ) and (b i+1 1 , w i+1 ) are both assigned to the left side of Q i+1 , then the orderings are the same ordering (according to the bijection between V i and V i+1 ). In fact, traversing the right side of Q i from the incidence point with (t i 7 , y i ) to the incidence point with (b i 7 , w i ), the segments delimiting the rows associated to the vertices in V i are encountered in the order σ i −{x i , y i , w i , z i }; this is because by Claim 3 the vertex y i precedes the vertex w i in σ i . Analogously, traversing the left side of Q i+1 from the incidence point with (t i+1 1 , y i+1 ) to the incidence point with (b i+1 1 , w i+1 ), the segments delimiting the rows associated to the vertices in V i+1 are encountered in the order σ i+1 − {x i+1 , y i+1 , w i+1 , z i+1 }. Now if there were a pair of vertices p i and q i such that p i and q i are in this order in σ i and such that q i+1 and p i+1 are in this order in σ i+1 , then the order-preserving edges (p i , p i+1 ) and (q i , q i+1 ) would cross each other, contradicting the planarity of Γ .
If (t i 7 , y i ) and (b i 7 , w i ) are both assigned to the left side of Q i , and (t i+1 1 , y i+1 ) and (b i+1 1 , w i+1 ) are both assigned to the right side of Q i+1 , the proof is analogous.
If (t i 7 , y i ) and (b i 7 , w i ) are both assigned to the right side of Q i , and (t i+1 1 , y i+1 ) and (b i+1 1 , w i+1 ) are both assigned to the right side of Q i+1 , then the orderings are the reverse of each other (according to the bijection between V i and V i+1 ). In fact, traversing the right side of Q i from the incidence point with (t i 7 , y i ) to the incidence point with (b i 7 , w i ), the segments delimiting the rows associated to the vertices in V i are encountered in the order σ i − {x i , y i , w i , z i }. However, traversing the right side of Q i+1 from the incidence point with (t i+1 1 , y i+1 ) to the incidence point with (b i+1 1 , w i+1 ), the segments delimiting the rows associated to the vertices in V i+1 are encountered in the reverse order of σ i+1 − {x i+1 , y i+1 , w i+1 , z i+1 }; this is because by Claim 3 the vertex y i follows the vertex w i in σ i . Now if there is a pair of vertices p i and q i such that p i and q i are in this order in σ i and such that p i+1 and q i+1 are in this order in σ i+1 , then the order-preserving edges (p i , p i+1 ) and (q i , q i+1 ) cross each other, contradicting the planarity of Γ .
1 , w i+1 ) are both assigned to the left side of Q i+1 the proof is analogous.
Lemmata 1 and 2 imply that (V, E) is a positive instance of Partitioned 3-Page Book Embedding. In fact, consider the ordering O of V corresponding to σ 1 − {x 1 , y 1 , w 1 , z 1 } according to the bijection between V and V 1 . By Lemma 2, for i = 2, 3, either σ i − {x i , y i , w i , z i } is the same or is the reverse of σ 1 − {x 1 , y 1 , w 1 , z 1 } (according to the bijection between V i and V 1 ). Then, for i = 1, 2, 3, no two edges e = (p, q) and f = (r, s) in E i have alternating end-vertices in O. Indeed, e and f cannot have alternating end-vertices if p i and q i are consecutive in σ i , or if r i and s i are consecutive in σ i , as in this case p and q, or r and s would be consecutive in O, respectively. If p i and q i are not consecutive in σ i and r i and s i are not consecutive in σ i , then by Lemma 1 the edges (u e , p i ), (u e , q i ), (u f , r i ), and (u f , s i ) are all assigned to the same side of Q i , hence if e and f had alternating end-vertices then: would cross the matrix representing u e or M i , or (iv) two among M i and the matrices representing u e and u f would cross each other. In each case we would get a contradiction to the planarity of Γ . This completes the proof of the theorem.
Let G = (V, E, C) be a flat clustered graph with a given side assignment s i , for each V i ∈ C. We say that G is NT planar with fixed side if G admits an NT planar representation Γ such that, for every edge e = (u, v) ∈ E with u ∈ V i and v ∈ V j , the incidence points of e with the matrices M i and M j representing Theorem 2. NodeTrix Planarity with Fixed Side is NP-complete even for instances with two clusters.
Proof: Lemma 3 will prove that NT Planarity with Fixed Side is in NP.
We give a reduction from the NP-complete problem Betweenness [18], where an instance is a collection of ordered triplets of items and the target is to find a total order of the items in which, for each of the given triplets, the middle item in the triplet appears somewhere between the other two items.
The set E contains an arbitrary set of intra-cluster edges and the following inter-cluster edges. (=⇒) Suppose that the items of T admit a total order a π1 , a π2 , . . . , a π h in which for each of the given triplets, the middle item in the triplet appears somewhere between the other two items. We show how to construct a NodeTrix planar representation of (V, E, C).
Use for the matrix M 1 representing V 1 a row-column order σ 1 such that . It can be easily seen that the inter-cluster edges can be drawn attached to the sides imposed by s 1 and s 2 without crossings, as in Fig. 4.
(⇐=) Suppose that (V, E, C) admits a NodeTrix planar representation where, for i ∈ {1, 2}, each inter-cluster edge attaches according to the edge assignment s i to the matrix M i representing the cluster V i . We show that T admits a total order in which for each triplet, the middle item in the triplet appears somewhere between the other two items.
First observe that, whatever the row-column orders σ 1 and σ 2 chosen for matrices M 1 and M 2 are, respectively, the matrices M 1 and M 2 form, together with the edges e α and e β , a cycle that separates the top sides of the two matrices from their bottom sides. It follows that all inter-cluster edges that attach to the top side (to the bottom side) of M 1 or M 2 are drawn inside the same region delimited by the boundaries of M 1 and M 2 , by e α , and by e β ; we denote by R t (by R b ) the one of these regions comprising the top side (resp. the bottom side) of M 1 and M 2 . Refer again to Fig. 4 for an illustration.
Consider the inter-cluster edges e b [i,1] , for i = 1, . . . , h. Since they all attach to u β and since s 1 (e b [i,1] ) = b, they are all drawn inside R b . Denote by π = π 1 , . . . , π h the permutation of the indices 1, . . . , h such that 1] ) (recall that these are the end-vertices of the edges e b [i,1] ). We claim that  1] and v [i,2] ). For j = 2, . . . , t − 1, the same argument can be repeated alternately for all the inter-cluster edges e t [i,j] and then for all the inter-cluster edges e b [i,j] ; then for any j ∈ {1, . . . t}, it holds true j] ). Also, it is easy to see that, in order for the drawing to be crossing-free, This concludes the proof of the claim. Now, for each j = 1, . . . , t, consider the inter-cluster edges of the path v [a b j ,j] , u j , v [ac j ,j] , u j , and v [a d j ,j] . In any NT planar representation of (V, E, C) such a path forces v [ac j ,j] to be in the middle of v [a b j ,j] and v [a d j ,j] , that is, it forces a cj to be in the middle of a bj and a dj in π. It follows that π is an ordering of the items a π1 , a π2 , . . . , a π h in which, for each triplet, the middle item in the triplet appears between the other two items.
Let G = (V, E, C) be a flat clustered graph with a given row-column order σ i , for each V i ∈ C. We say that G is NT planar with fixed order if it admits an NT planar representation Γ where, for each cluster V i ∈ C, each vertex v ∈ V i is associated with the σ i (v)-th row and column of the matrix M i representing V i in Γ .
Theorem 3. NodeTrix Planarity with Fixed Order is NP-complete even if at most one cluster contains more than one vertex.
Proof: The membership in NP of NT Planarity with Fixed Order will be proved in Lemma 3.
For the NP-hardness, we give a reduction from the NP-complete problem that asks to determine whether a proper 4-coloring exists for a circle graph [20], which is an intersection graph of chords of a circle. Let G = (N, A) be a circle graph. First, by means of the algorithm in [19], we construct in polynomial time an intersection representation P, O of G, where P is a linear sequence of distinct points on a circle and O is a set of chords between pairs of points in P such that:  The set E contains an arbitrary set of intra-cluster edges and the following inter-cluster edges.
Finally, we fix the row-column order σ * of the only non-unitary cluster V * to be v α • P • v ω (where with a slight abuse of notation we denote by P not only the order of the points on the circle in the given intersection representation of G, but also the corresponding order of the vertices in V * − {v α , v ω }). We now prove the equivalence between the problem of properly 4-coloring P, O and the constructed instance of NodeTrix Planarity with Fixed Order.
(=⇒) Suppose that the chords of P, O can be assigned colors 1, 2, 3, 4 so that no two chords with the same color intersect. We show how to construct a NodeTrix planar representation with fixed order of (V, E, C). We refer to these regions as to the top, right, bottom, and left region, respectively. Depending on whether a chord c = (p i , p j ) has color 1, 2, 3, or 4, we draw the chord edges (v i , v c ) and (v c , v j ), as well as the matrix M c representing cluster {v c }, inside the top, right, bottom, and left region, respectively. We claim that the obtained NT representation of (V, E, C) is planar. Suppose, for a contradiction, there is a crossing between two paths (v i , v c , v j ) and (v k , v c , v h ) corresponding to two chords c = (p i , p j ) and c = (p k , p h ). Then these two paths are in the interior of the same (top, right, bottom, or left) region, hence they attach to the same side of M * ; it follows that the two chords c and c have the same color. By the definition of σ * , since the end-vertices of the two paths alternate along the side of M * , the end-points of c and c alternate in P. Hence, c and c cross, thus contradicting the fact that c and c have the same color.
(⇐=) Suppose that (V, E, C) admits a NodeTrix-planar representation Γ with a row-column order σ * for the unique non-unitary cluster V * . Denote by M * the matrix representing V * in Γ . We show that the chords of P, O are 4-colorable so that no two chords of the same color intersect.
Similarly to the proof of Theorem 1, it can be proved that the corner edges subdivide the side of D that contains M * into five regions, defined as in the previous direction, so that all the vertices on the top, right, bottom, and left side of M * are incident to the top, right, bottom, and left region, respectively; while in the proof of Theorem 1 this was ensured by Claim 3, it is here a trivial consequence of the fact that v α and v ω are the first and the last vertex in σ * . By the planarity of Γ , both the incidence points of a path (v i , v c , v j ) with the boundary of M * are on the same side of M * . Then color all the chords c = (p i , p j ) in O such that path (v i , v c , v j ) is in the top, right, bottom, or left region with color 1, 2, 3, or 4, respectively.
We claim that the obtained 4-coloring of the chords of P, O is proper. Suppose, for a contradiction, there is a crossing in P, O between two chords c = (p i , p j ) and c = (p k , p h ) both with color 1 -the discussion for the other colors is analogous. Then c and c have alternating end-points in P, O . Since the order of the points in P coincides with the order of the corresponding vertices in σ * , it follows that paths (v i , v c , v j ) and (v k , v c , v h ) have alternating endpoints on the top side of M * , hence they cross, a contradiction to the planarity of Γ . This concludes the proof.
Let G = (V, E, C) be a flat clustered graph with a given row-column order σ i and side assignment s i , for each V i ∈ C. Then G is NT planar with fixed order and fixed side if it is simultaneously planar with fixed order and with fixed side. Proof: Consider the graph G obtained from an instance G = (V, E, C) of Node-Trix Planarity with Fixed Order and Fixed Side by collapsing each cluster V i ∈ C into a vertex v i . Intuitively, instance G is NT planar with fixed order and fixed side if and only if G is planar with the additional constraint that the clockwise order of the edges incident to each vertex v i is "compatible" with the row-column order σ i and the side assignment s i for the cluster V i . More formally, denote by E i the set of the inter-cluster edges incident to V i and denote by v i (e) the vertex of V i incident to an edge e ∈ E i . The edges in E i can be decomposed into a circular sequence of sets S = E t,1 , E t,2 , . . . , E t,|Vi| , E r,1 , E r,2 , . . . , E r,|Vi| , E b,|Vi| , E b,|Vi−1| , . . . , E b,1 , E l,|Vi| , E l,|Vi−1| , . . . , E l,1 , where each E x,j , with x ∈ {t, b, l, r} and j ∈ {1, . . . , |V i |}, contains the edges e ∈ E i such that s i (e) = x and σ i (v i (e)) = j. Let Γ be a planar embedding of G and let λ i denote the clockwise order of the edges incident to vertex v i of G in Γ . The embedding Γ of G is compatible with functions σ i and s i if: (i) all the edges belonging to the same set E x,j appear consecutively in λ i , and (ii) for any three edges e ∈ E x ,j , e ∈ E x ,j , and e ∈ E x ,j , where E x ,j , E x ,j , and E x ,j are all distinct, appear in this clockwise order in λ i if and only if E x ,j , E x ,j , and E x ,j appear in this circular order in S.
It can be easily seen that an instance of NodeTrix Planarity with Fixed Order and Fixed Side has a solution if and only if G admits an embedding Γ that is compatible with σ i and s i , for all vertices v i of G . We obtain an instance of constrained planarity for G that can be tested in linear time with known techniques [15].
We conclude the section with the following lemma. Proof: We prove the statement for NT Planarity; the other proofs are analogous. Consider an instance (V, E, C) of NT Planarity. For each V i ∈ C, guess a row-column order σ i and a side assignment s i ; then use the algorithm described in the proof of Theorem 4 to test in linear time whether (V, E, C) is NT planar with fixed order and fixed side. Since the number of distinct row-column orders and side assignments is a function of |V | + |E|, we get the NP membership.

Monotone NodeTrix Representations
Let G = (V, E, C) be a flat clustered graph and γ be a square assignment for G that maps each cluster in C to an axis-aligned square in the plane. A curve is xmonotone (resp. y-monotone) if no two of its points have the same projection on the x-axis (resp. on the y-axis) and is xy-monotone if it is either a horizontal or a vertical segment or it is both xand y-monotone. A monotone NT representation Γ of G, γ is an NT representation such that: 1. all the inter-cluster edges are represented by xy-monotone curves; 2. for each cluster V i ∈ C, the boundary of the matrix M i representing V i is Q i = γ(V i ); 3. for each pair of adjacent clusters V i and V j , with i = j, the convex hull of Q i and Q j does not intersect any other square Q k , with k = i, j -we call this convex hull the pipe of Q i and Q j ; and 4. all the inter-cluster edges between vertices in V i and vertices in V j lie inside the pipe of Q i and Q j .
In a monotone NT representation Γ of G let χ i (Γ ) denote the number of edge crossings between pairs of inter-cluster edges incident to V i . Let χ(Γ ) = i χ i (Γ ), where the sum is over all the clusters V i ∈ C; we say that Γ is locally planar if χ(Γ ) = 0 and no inter-cluster edge intersects any matrix except at Fig. 6: Illustration for the proof of Theorem 5, with m = 3.
its incidence points. The notions of fixed order and fixed side easily extend to monotone NT representations.
We study the complexity of testing if a flat clustered graph with fixed square assignment admits a monotone locally-planar NT representation, a problem which we call Monotone NT Local Planarity (MNTLP). The next two theorems show the NP-hardness of MNTLP and of its variant with fixed side.
Proof: The proof that the problem is in NP is similar to the proof of Theorem 4: one can guess a row-column order and a side assignment for each cluster; then the monotone NT local planarity of the given clustered graph with the given square assignment and the guessed row-column order and side assignment can be tested in polynomial time by Theorem 7, to be presented later.
For the NP-hardness we give a reduction from the NP-complete problem Betweenness [18], defined in the proof of Theorem 2. Consider an instance T of Betweenness consisting of a set of h items {a 1 , . . . a h } and m ordered triplets τ i = a bi , a ci , a di , with i = 1, . . . , m. We construct an instance G = (V, E, C), γ of MNTLP as follows (refer to Fig. 6). Let C consist of: The set E contains an arbitrary set of intra-cluster edges and the following inter-cluster edges.
order-preserving edges connecting v i j with v i+1 j , for 1 ≤ i ≤ m − 1 and 1 ≤ j ≤ h; side-filling edges connecting u with v 1 j , for 1 ≤ j ≤ h; protecting edges connecting x i with x i+1 , for 0 ≤ i ≤ m − 1; corner edges connecting x i with α i and β i , for 1 ≤ i ≤ m; and betweenness edges connecting, for each triplet τ i = a bi , a ci , a di with i ∈ {1, . . . , m}, the vertex v i bi with α i , the vertex v i di with β i , and the vertex v i ci with both α i and β i .
Finally, square assignment γ is defined as follows: for i = 1, . . . , m, the cluster V i is assigned to a square Q i so that, for every Notice that the above definition of γ is such that, for each pair of adjacent clusters V i and V j , with i = j, the convex hull of Q i and Q j does not intersect any other square Q k , with k = i, j.
We now prove the equivalence between the given instance of Betweenness and the constructed instance of MNTLP.
(=⇒) If T admits an order σ = (a π1 , . . . , a π h ) in which a ci appears between a bi and a di in σ, for each triplet τ i = a bi , a ci , a di , we construct a monotone locally-planar NT representation Γ with fixed square assignment of G as follows. For i = 1, . . . , m, represent V i as a matrix M i with boundary Q i and with row- i and with row-column order α i , β i or β i , α i depending on whether v i bi follows or precedes v i di in σ, respectively; the representation of the unitary clusters {x 0 } and {u} in Γ is trivially defined. Assign every inter-cluster edge incident to x 0 (or u) to the right side of Q 0 (or Q u ) and to the left side of Q 1 , every orderpreserving or protecting edge between a vertex in V i and a vertex in V i+1 to the right side of Q i and to the left side of Q i+1 , every corner edge incident to x i to the top side of Q i and to the bottom side of Q α i , and every betweenness edge incident to a vertex in V i to the top side of Q i and to the right side of Q α i . Finally, draw all the inter-cluster edges as straight-line segments in Γ . Observe that such segments are xy-monotone curves inside the corresponding pipe.
Representation Γ has no crossing between any inter-cluster edge and any matrix, as a consequence of the square and side assignments and independently of the row-column order of the matrices. Further, the order-preserving, sidefilling, and protecting edges do not cross the corner and betweenness edges since they are separated by the horizontal line y = max y {Q 1 }, and do not cross each other since the row-column orders of any two matrices M i and M i+1 both correspond to σ with x i and x i+1 as the first element, respectively. The corner edges incident to x i do not cross the betweenness edges incident to vertices in V i , because of the side assignment of these edges to Q α i and since x i precedes v i π1 , . . . , v i π h in the row-column order of M i . Finally, the betweenness edges do not cross each other because of the row-column order defined for M α i and since the top side of the column representing v i ci in M i is between the top sides of the columns representing v i bi and v i di in M i . (⇐=) Suppose that G admits a monotone locally-planar NT representation Γ with fixed square assignment γ. Let M 1 , . . . , M m be the matrices representing the clusters V 1 , . . . , V m in Γ , respectively. First, the monotonicity of Γ and the placement of squares Q 0 , Q 1 , and Q u imply that the side-filling edges, as well as the edge (x 0 , x 1 ), lie to the right of Q 0 and Q u , to the left of Q 1 , above the line y = min y {Q 1 }, and below the line y = max y {Q 1 }. Since max y {Q u } < min y {Q 0 }, we have that all the side-filling edges lie below edge (x 0 , x 1 ), hence the planarity of Γ implies that x 1 is the first vertex in the row-column order of M 1 ; let x 1 , v 1 π1 , . . . , v 1 π h be such an order, for some permutation π 1 , . . . , π h of {1, . . . , h}. We claim that the total ordering σ = (a π1 , . . . , a π h ) is a solution to instance T of betweenness.
We first prove that the order x 1 , v 1 π1 , . . . , v 1 π h is "preserved" in M 2 , . . . , M m . The monotonicity of Γ and the placement of squares Q i imply that, for 1 ≤ i ≤ m − 1, the order-preserving and protecting edges between vertices in V i and vertices in V i+1 are to the right of Q i , to the left of Q i+1 , above the line y = min y {Q i }, and below the line y = max y {Q i }. Then the planarity of Γ implies that, if the row-column order of π1 , . . . , v i+1 π h . Now consider any triplet τ i = a bi , a ci , a di in T . The monotonicity of Γ and the placement of the squares Q i and Q α i imply that every corner or betweenness edge is assigned to the top or left side of Q i and to the bottom or right side of Q α i . Further, since x i is the first element in the row-column order of M i and since max y {Q i } < min y {Q α i }, no betweenness edge is assigned to the left side of Q i , as otherwise it would cross edge (x i−1 , x i ). Hence, all the betweenness edges are assigned to the top side of Q i . Since x i is the first vertex in the row-column order of M i and by the planarity of Γ , we have that, when traversing Q α i in clockwise direction starting from its top-right corner, the incidence points between Q α i and the betweenness edges are encountered before the incidence points between Q α i and the corner edges; in particular, no betweenness edge incident to the first vertex -say α i as other case is analogous -in the row-column order of M α i is assigned to the bottom side of M α i , as otherwise this edge would cross the corner edge incident to β i . The planarity of Γ also implies that, when traversing the top side of Q i from left to right, the end-points of the betweenness edges incident to β i are encountered all before the end-points of the betweenness edges incident to α i . Since v i ci is the only vertex among v i bi , v i ci , and v i di that is neighbor of both α i and β i , then its associated column is between the columns associated to v i bi and v i di , hence a ci is between a bi and a di in σ. This concludes the proof.
Theorem 6. MNTLP with Fixed Side is NP-complete.
Proof: The reduction presented in the proof of Theorem 5, equipped with the side assignment for the inter-cluster edges described in the direction (=⇒) implies the statement.
Since the instances of MNTLP used in the proof of Theorem 5 are planar whenever they are locally planar, testing the existence of a monotone planar NT representation with fixed square assignment is also NP-complete. Further, the instances of NT Planarity used in the proof of Theorem 1 can be drawn planarly with straight-line (hence monotone) edges, whenever they are planar. Hence, testing whether a flat clustered graph admits a monotone planar NT representation -without square assignment -is also NP-complete.
Consider now a flat clustered graph G = (V, E, C) and a monotone NT representation Γ of G with fixed square assignment γ. Consider two clusters V a , V b ∈ C and let Q a = γ(V a ) and Q b = γ(V b ). Since Q a and Q b are disjoint, there exists either a vertical or a horizontal line separating them. Suppose that the former holds, the other case being analogous. Also suppose that max x (Q a ) < min x (Q b ) and max y (Q a ) ≥ max y (Q b ), the other cases being analogous up to reflections of the Cartesian axes (refer to Fig. 7). Also, consider an inter-cluster edge e = (u, v) ∈ E a,b . Depending on the relative positions of Q a and Q b in Γ , not all the possible combinations of side assignments for e might be allowed, as described in the following property. Notice that, by the assumptions on the relative positions of Q a and Q b in Γ and by the monotonicity and the local planarity of Γ , we have that s a (e) = l, t and s a (e) = r.   Note that if an edge e can be drawn as an xy-monotone curve not crossing any matrix, then it can also be drawn as a straight-line segment not crossing any matrix, since the pipe of Q a and Q b does not intersect any matrix other than M a and M b . The next lemma extends this observation by arguing that the xy-monotonicity constraint can be replaced by a straight-line requirement also for what concerns crossings between inter-cluster edges incident to the same matrix. Proof: Since a straight-line segment is an xy-monotone curve, one direction of the proof is trivial. Consider an NT representation Γ of G = (V, E, C), γ with a fixed row-column order, a fixed side assignment, and a fixed square assignment, in which all the inter-cluster edges are straight-line segments. Suppose that Γ is not locally planar and consider two crossing inter-cluster edges e = (v a,1 , v b ) and f = (v a,2 , v c ) such that v a,1 and v a,2 belong to the same cluster V a ∈ C. We show that e and f cross in any monotone NT representation Γ with the same row-column order, side assignment, and square assignment as Γ . Two are the cases: either v b and v c belong to the same cluster V b as in Fig. 8a (Case 1), or they belong to different clusters V b and V c , respectively, as in Fig. 8b (Case 2).
In Case 1, consider the region R ab of the plane inside the pipe of Q a and Q b and outside each of Q a and Q b . Edge e splits R ab into two regions R 1 and R 2 . Since e and f cross in Γ , the end-points of f are one incident to R 1 and one incident to R 2 in Γ . Since the representation of f has to lie inside R ab , it follows that e and f cross in Γ .
In Case 2, consider the region R ab defined as in Case 1 and consider the region R ac of the plane inside the pipe of Q a and Q c and outside each of Q a and Q c . Since e lies in R ab and f in R ac , and since e and f cross in Γ , it follows that the intersection of R ab and R ac is a non-empty region R ∩ . The part of e inside R ∩ partitions R ∩ into two regions R 1 and R 2 . Since e and f cross in Γ , the end-point of f on the boundary of Q a is incident to the one between R 1 and R 2 that does not share the boundary with region R ac −R ∩ . Since the representation of f has to lie inside R ac , it follows that e and f cross in Γ .
The previous lemma, in contrast to the negative results of Theorems 5 and 6, allows us to show that MNTLP with Fixed Order and Fixed Side is a polynomial-time solvable problem. Suppose that an inter-cluster edge e * is required to have a drawing Γ e as in Case 1. By the definition of an S-drawn edge, if Q a and Q b are arranged as in Arrangement 3 of Property 1, then the required NT representation does not exist, thus the statement trivially holds. Hence, we can assume that Q a and Q b are arranged as in Arrangement 1 or 2 of Property 1. Let e = e * ∈ E be any inter-cluster edge not adjacent to e. Denote by σ a and σ b the row-column orders associated to V a and V b in σ, respectively.
Consider Arrangement 1 and suppose s a (e * ) = r and s b (e * ) = l. The endvertices of e and e * in V a (in V b ) have two possible relative positions in σ a (resp. in σ b ). This leads to four possible combinations for these relative positions.
If σ a (e * ) < σ a (e) and σ b (e) < σ b (e * ), then any xy-monotone curve representing e crosses e * , independently of the side assignment for e, and the statement trivially holds. See Fig. 9a. For each of the three remaining combinations, exactly two side assignments for e create no crossing with e * . Indeed: -If σ a (e) < σ a (e * ) and σ b (e) < σ b (e * ), then it holds true that either s a (e) = r and s b (e) = t, or that s a (e) = r and s b (e) = l. See Fig. 9b. The discussion for the case in which Q a and Q b are arranged as in Arrangement 1, s a (e * ) = b, and s b (e * ) = t is analogous to the previous one.
Consider now Arrangement 2. According to the definition of S-drawing it holds true for e * = (u, v) that (a) s a (e * ) = r and s b (e * ) = l, (b) the y-coordinate of p u is greater than max y (Q b ), and (c) the y-coordinate of p v is smaller than min y (Q a ).
Similarly to Arrangement 1, there are four possible combinations for the relative positions of the end-vertices of e and e * in σ a and σ b . If σ a (e * ) < σ a (e) and σ b (e) < σ b (e * ), then any xy-monotone curve representing e crosses Hence, for each inter-cluster edge e = e * ∈ E not adjacent to e * , there exist two side assignments for e that allow it to be represented as an xy-monotone curve not intersecting e * .
We are now ready to show, for Case 1 of the lemma, that a monotone locally planar NT representation of G = (V, E, C = {V a , V b }), γ in which e * is represented by Γ e exists if and only if a suitable 2-SAT formula φ(a, b, Γ e ) is satisfiable.
For each inter-cluster edge e = e * ∈ E not adjacent to e * , we define a Boolean variable x e . The above discussion shows that, if we did not conclude that a trivially false formula exists, then there are exactly two distinct side assignments for e. We select one arbitrarily, which we call canonical side assignment, and associate x e = true to it and x e = false to the other.
For each pair of non-adjacent inter-cluster edges e 1 , e 2 = e * ∈ E, consider the four possible side assignments for them. We add to φ(a, b, Γ e ) at most four clauses defined as follows.
-If the canonical side assignment for e 1 and the canonical side assignment for e 2 generate a crossing between e 1 and e 2 , then we add clause {x e1 ∨ x e2 } to φ(a, b, Γ e ). -If the canonical side assignment for e 1 and the non-canonical side assignment for e 2 generate a crossing between e 1 and e 2 , then we add clause {x e1 ∨ x e2 } to φ(a, b, Γ e ). -If the non-canonical side assignment for e 1 and the canonical side assignment for e 2 generate a crossing between e 1 and e 2 , then we add clause {x e1 ∨ x e2 } to φ(a, b, Γ e ). -If the non-canonical side assignment for e 1 and the non-canonical side assignment for e 2 generate a crossing between e 1 and e 2 , then we add clause As a consequence of the above discussion G = (V, E, C = {V a , V b }), γ admits a monotone locally planar NT representation in which e * is represented by Γ e if and only if φ(a, b, Γ e ) is satisfiable. Further, since the number of clauses in φ(a, b, Γ e ) is upper-bounded by O(|E| 2 ) and since it can be determined in constant time whether a side assignment for any two edges produces a crossing, then formula φ(a, b, Γ e ) can be constructed in O(|E| 2 ) time and has O(|E| 2 ) size. Since 2-SAT formulae can be tested for satisfiability in linear time [8], the statement of Case 1 follows.
Suppose now that Case 2 of the statement holds. According to Property 1, squares Q a and Q b can be arranged as in Arrangement 1, 2, or 3.
Consider Arrangement 1. By the hypothesis of the case, no edge is allowed to be S-drawn. Hence, for each inter-cluster edge e, we have either s a (e) = r and s b (e) = t or s a (e) = b and s b (e) = l.
Consider Arrangement 2. Let e = (u, v) be an inter-cluster edge. We distinguish four cases depending on the y-coordinate y u of m u r with respect to max y (Q b ) and on the y-coordinate y v of m v l with respect to min y (Q a ). In each of the four cases, at most two side assignments for e are possible so that e is not S-drawn.
-If y u > max y (Q b ) and y v ≥ min y (Q a ), then it holds true that either s a (e) = r and s b (e) = t, or that s a (e) = r and s b (e) = l. See Fig. 11a. -If y u > max y (Q b ) and y v < min y (Q a ), then it holds true that either s a (e) = r and s b (e) = t, or that s a (e) = b and s b (e) = l. See Fig. 11b; notice that the side assignment s a (e) = r and s b (e) = l would imply that e is S-drawn, which is not possible by hypothesis. -If y u ≤ max y (Q b ) and y v ≥ min y (Q a ), then it holds true that s a (e) = r and s b (e) = l. See Fig. 11c. -If y u ≤ max y (Q b ) and y v < min y (Q a ), then it holds true that either s a (e) = r and s b (e) = l, or that s a (e) = b and s b (e) = l. See Fig. 11d.
Consider Arrangement 3. Let e = (u, v) be an inter-cluster edge. By definition e cannot be S-drawn. We distinguish three cases depending on the y-coordinate y u of m u r with respect to min y (Q b ) and max y (Q b ). In each of the three cases, at most two side assignments for e are possible. -If y u > max y (Q b ), then it holds true that either s a (e) = r and s b (e) = t, or that s a (e) = r and s b (e) = l. See Fig. 12a. Hence, regardless of whether Q a and Q b are arranged as in Arrangement 1, 2, or 3, and regardless of the y-coordinate of m u r and m v l , there exist at most two side assignments for e that allow it to be represented as an xy-monotone curve.
The construction of the 2-SAT formula and the bound on its size can be derived analogously to Case 1; the only difference is that, when only one side assignment is possible, a clause with a single literal is generated. This concludes the proof of the lemma.
We now turn to the study of flat clustered graphs with three clusters. Lemma 6. Let G = (V, E, C = {V a , V b , V c }), γ, σ be an instance of MNTLP with Fixed Order. Consider the four cases that are generated by assuming that an edge e * ∈ E a,b has a prescribed S-drawing or not and that an edge f * ∈ E a,c has a prescribed S-drawing or not. In each case, we can construct in O(|E| 2 ) time a 2-SAT formula φ(a, b, c) with length O(|E| 2 ) that is satisfiable if and only if G, γ, σ admits a monotone NT representation with fixed order that satisfies the constraints of the corresponding case, such that no inter-cluster edge intersects any matrix except at its incidence points, and such that there are no two edges, one in E a,b and one in E a,c , that cross each other.
Proof: In each of the four cases, the hypotheses lead us in either Case 1 or Case 2 of Lemma 5 for the edges in E a,b and the same holds for the edges in E a,c . Hence, by Lemma 5, each of these edges admits at most two side assignments in each case. Moreover, each of these side assignments corresponds to a directed or negated literal. For each pair of edges e ∈ E a,b and f ∈ E a,c and for each of the at most four side assignments for them, we exploit Lemma 4 to test whether a side assignment for e and f leads to a crossing and in the case of a crossing we introduce suitable clauses to rule out that side assignment.
We finally get the following. Proof: For each pair V a , V b of adjacent clusters in C, we guess whether V a , V b belongs to a set P s or to a set P n . The set P s contains all the pairs V a , V b of clusters that have an inter-cluster edge that is S-drawn. The set P n contains all the pairs V a , V b of clusters that do not have an inter-cluster edge that is S-drawn. For each pair V a , V b of clusters in P s we guess an inter-cluster edge e ∈ E a,b that can be S-drawn and one of its possible S-drawings Γ e for e; we remark that the guess of Γ e consists of a guess of the side assignement for e, hence there are a constant number of possible guesses for each edge e.
By means of Lemma 5 we compute the following formula: Further, let P triplet be the set of triplets V a , V b , V c of clusters in C such that V b and V c are adjacent to V a . We write one of the formulae φ(a, b, c) of the four cases of Lemma 6 according to the presence in P s of an inter-cluster edge between V a and V b or of an inter-cluster edge between V a and V c . By means of Lemma 6, we compute the following: Finally, we define φ = φ pairs ∧ φ triplets .
We have that instance G = (V, E, C), γ, σ is a positive instance if and only if there exists a guess such that the corresponding formula φ is satisfiable.
About the time complexity, for each guess O(|E| 2 ) time is needed to compute the corresponding formula φ and to check it for satisfiability, due to Lemmata 5 and 6. The number of guesses can be bounded as follows. For each pair of adjacent clusters V a , V b we have to guess among 2|E a,b | + 1 possibilities, corresponding to the choice of |E a,b | edges to be S-drawn, each in two possible ways, plus the possibility of not having any S-drawn edge. This leads to O((2|E|+1) |C| 2 ), which is in |E| O(|C| 2 ) , guesses.
Observe that the computational complexity of the algorithm described in the proof of Theorem 8 is polynomial if the number of clusters is constant.

A JavaScript Library for Monotone NodeTrix Representations
In this section we consider the following scenario. A user moves (e.g. via a dragand-drop primitive) the matrices representing the clusters of a flat clustered graph, choosing also her preferred row-column order. A system automatically selects sides for the inter-cluster edges so to produce a monotone NT representation Γ with a "small" χ(Γ ).
The algorithm in the proof of Theorem 8 suggests the following strategy: 1. Compute the 2-SAT formula associated to each possible guess of S-drawings of edges between adjacent matrices. In each formula the value of a variable represents the two possible side assignments for an edge; further, each unsatisfied clause corresponds to a crossing in the monotone NT representation. 2. If one of such formulae admits a solution, draw the edges according to the values of the associated variables, obtaining an MNTLP representation. 3. Otherwise, for each formula, heuristically search for a solution of the corresponding MAX-2-SAT problem and keep the solution with the smallest number of false clauses, corresponding to a drawing with few local crossings.
Such a strategy requires polynomial time if the number of clusters is constant (Theorem 8) and the selected MAX-2-SAT heuristic is polynomial. However, solving a MAX-2-SAT instance for each of the guesses of the proof of Theorem 8 is unfeasible even in a static setting. Therefore, we modify the above strategy as follows. We restrict to monotone NT representations without S-drawn edges. A locally-planar flat clustered graph may become non-planar with this restriction, hence this choice corresponds to trading accuracy for efficiency. However, the proof of Theorem 8 shows that in this setting there is a unique formula associated to an instance, hence we need to solve one MAX-2-SAT instance. Fig. 13: A NodeTrix Representation created by the demo editor [3].
A JavaScript library implementing the above heuristic has been designed and used in a proof-of-concept editor available at [3] (see Fig. 13). In the editor the internal part of the matrices is not shown and inter-cluster edges are polylines or splines; this is not intended to be the best choice and many alternatives for the actual geometry of the edges are possible whose visual appeal should be considered according to the specific application domain. In order to check if the strategy is usable on medium size instances, we experimented our simple editor on clustered graphs with at most twenty clusters and 200 inter-cluster edges, without experiencing delays in the interaction. We did not compare the number of crossings produced by our heuristic with other approaches because, as far as we know, this is the first attempt to reduce local crossings in NT representations. Also, it would be pointless to compare our approach with the original NT software, since in that case the edges just attach to the nearest sides. The JavaScript software of our library is freely available and can be integrated in any NodeTrix-style interface. As an example, it can be coupled with an algorithm that automatically places matrices based on a force-directed approach or with one that computes row-column order for the matrices with the purpose of clarifying the internal structure of the clusters [13].

Conclusions and Open problems
We have shown that clustered graphs for Nodetrix planarity is NP-complete even if the order of the rows and columns is fixed or if the matrix sides to which the inter-cluster edges attach is fixed. We have also studied the setting where matrices have fixed positions and inter-cluster edges are xy-monotone curves. In this case we established negative and positive results; leveraging on the latter, we developed a library that computes a layout of the inter-cluster edges with few crossings. A demo [3] shows that the computation allows the user to move matrices without any slowdown of the interaction.
Several theoretical problems are related to the planarity of Nodetrix representations. First, the NP-completeness of Nodetrix planarity can be interpreted as a proof of the NP-completeness of clustered planarity (see, for example, [4,6,11,14]) when a specific type of representation is required. Observe, though, that a flat clustered graph may be Nodetrix planar even if its underlying graph is not planar. Second, planarity of hybrid representations have been recently studied [5] in the setting in which clusters are represented as the intersections of geometric objects. Our results can be viewed as a further progress in this area. Third, given a flat clustered graph with two clusters, computing a locally planar Nodetrix representation in which the clusters are represented as matrices aligned along their principal diagonal is equivalent to solve the 2-page bipartite book embedding with spine crossings problem [5]. Interestingly, if the two matrices are aligned along their secondary diagonal this equivalence is not evident anymore.
Among the future research directions, we mention the one of automatically embedding the matrices in order to minimize the number of crossings in monotone Nodetrix representations.