Removing edge-node intersections in drawings of graphs

6
Information Processing Letters 81 (2002) 105–110 Removing edge-node intersections in drawings of graphs Wei Lai a , Peter Eades b,a School of Information Technology, Swinburne University of Technology, P.O. Box 218, Hawthorn, Vic 3126, Australia b Basser Department of Computer Science, The University of Sydney, NSW 2006, Australia Received 1 June 2000; received in revised form 1 February 2001 Communicated by R.G. Dromey Keywords: Algorithms; Graph layout; Overlapping nodes; Node-edge intersections; Layout adjustment 1. Introduction A graph is a set of nodes and edges. Graphs are commonly used to model relations in computer sys- tems. Nodes are used to represent objects in an appli- cation, and edges represent relationships between ob- jects. Examples are data flow diagrams, state transi- tion diagrams, flow charts, PERT charts, organization charts, Petri nets and entity-relationship diagrams. A number of graph drawing algorithms have been developed (see [1]). These produce aesthetically pleas- ing abstract graph drawings, where nodes are just points in the plane. In practice, nodes have many at- tributes; for example, in a class diagram in Object Modeling Technique (OMT) [13], a node has several textual labels in several fields (see Fig. 1(c)). These attributes need to be represented graphically, for in- stance, as shapes, sizes, and colors. We call this kind of graph where nodes vary in shape and size a practi- cal graph. Classical algorithms can be applied to draw graphs arising in practice as long as nodes take very little space. However, in applications, the node images are This work is partially supported by a grant from Australian Research Council. * Corresponding author. E-mail address: [email protected] (P. Eades). circles, boxes, diamonds and similar shapes, and may contain a considerable amount of text and graphics; thus they take a nontrivial amount of screen space. In some systems [3,7,14] nodes are used to represent subgraphs, and may be quite unpredictable in size and shape. Applying the classical algorithms to practical graphs may result in overlapping nodes and/or edge- node intersections. Algorithms which exemplify this problem can be found in [1] — they produce graph layouts which are nicely symmetric and well spread out, and have great potential for use in visualization of network structures. However nodes of nontrivial size in a practical graph produced by these algorithms tend to overlap. An example is illustrated in Fig. 1; an algorithm from [1] produces a structure as in Fig. 1(a), and replacing the nodes with rectangles gives the overlapping nodes in Fig. 1(b). But the layout we need should be Fig. 1(c). We propose an approach here for practical graph drawings. It has two steps, as follows. (1) Apply an abstract graph layout function to the graph. (2) Use a post-process to avoid overlaps of node images and edge-node intersections by rearrang- ing the graph layout generated by step (1). The rearrangement should also preserve the original “structure” of the graph. In the other words, the 0020-0190/02/$ – see front matter 2002 Elsevier Science B.V. All rights reserved. PII:S0020-0190(01)00194-6

Transcript of Removing edge-node intersections in drawings of graphs

Page 1: Removing edge-node intersections in drawings of graphs

Information Processing Letters 81 (2002) 105–110

Removing edge-node intersections in drawings of graphs✩

Wei Laia, Peter Eadesb,∗a School of Information Technology, Swinburne University of Technology, P.O. Box 218, Hawthorn, Vic 3126, Australia

b Basser Department of Computer Science, The University of Sydney, NSW 2006, Australia

Received 1 June 2000; received in revised form 1 February 2001Communicated by R.G. Dromey

Keywords: Algorithms; Graph layout; Overlapping nodes; Node-edge intersections; Layout adjustment

1. Introduction

A graph is a set of nodes and edges. Graphs arecommonly used to model relations in computer sys-tems. Nodes are used to represent objects in an appli-cation, and edges represent relationships between ob-jects. Examples are data flow diagrams, state transi-tion diagrams, flow charts, PERT charts, organizationcharts, Petri nets and entity-relationship diagrams.

A number of graph drawing algorithms have beendeveloped (see [1]). These produce aesthetically pleas-ing abstract graph drawings, where nodes are justpoints in the plane. In practice, nodes have many at-tributes; for example, in a class diagram in ObjectModeling Technique (OMT) [13], a node has severaltextual labels in several fields (see Fig. 1(c)). Theseattributes need to be represented graphically, for in-stance, as shapes, sizes, and colors. We call this kindof graph where nodes vary in shape and size apracti-cal graph.

Classical algorithms can be applied to draw graphsarising in practice as long as nodes take very littlespace. However, in applications, the node images are

✩ This work is partially supported by a grant from AustralianResearch Council.

* Corresponding author.E-mail address: [email protected] (P. Eades).

circles, boxes, diamonds and similar shapes, and maycontain a considerable amount of text and graphics;thus they take a nontrivial amount of screen space.In some systems [3,7,14] nodes are used to representsubgraphs, and may be quite unpredictable in size andshape. Applying the classical algorithms to practicalgraphs may result in overlapping nodes and/or edge-node intersections. Algorithms which exemplify thisproblem can be found in [1] — they produce graphlayouts which are nicely symmetric and well spreadout, and have great potential for use in visualizationof network structures. However nodes of nontrivialsize in a practical graph produced by these algorithmstend to overlap. An example is illustrated in Fig. 1; analgorithm from [1] produces a structure as in Fig. 1(a),and replacing the nodes with rectangles gives theoverlapping nodes in Fig. 1(b). But the layout we needshould be Fig. 1(c).

We propose an approach here for practical graphdrawings. It has two steps, as follows.(1) Apply an abstract graph layout function to the

graph.(2) Use a post-process to avoid overlaps of node

images and edge-node intersections by rearrang-ing the graph layout generated by step (1). Therearrangement should also preserve the original“structure” of the graph. In the other words, the

0020-0190/02/$ – see front matter 2002 Elsevier Science B.V. All rights reserved.PII: S0020-0190(01)00194-6

Page 2: Removing edge-node intersections in drawings of graphs

106 W. Lai, P. Eades / Information Processing Letters 81 (2002) 105–110

Fig. 1. Layout of a class diagram in OMT.

user’s mental map of the graph [5] should be pre-served.

Step (2) needs to address the problems of over-lapping nodes and edge-node intersections. Currentlythere are several solutions to the problem of overlap-ping nodes [6,5,9,8], but there is less work on remov-ing edge-node intersections in a graph layout.

The aim of this paper is to present methods forremoving edge-node intersections. Firstly, however,we review theforce scan method for removing nodeoverlaps [6].

2. Force-scan algorithm

This uses a “force”fuv between two pairsu, v ofnodes so that ifu and v overlap thenfuv pushesvaway fromu. The algorithm uses the projectionsf x

uv

andfyuv in horizontal(x) and vertical(y) directions.

The algorithm proceeds by scanning the nodes,and applies forces in both horizontal and verticaldirections. The horizontal scan is illustrated below.Here thex coordinates on the nodes arex1, x2, . . . , xn,and we assume thatx1 � x2 � · · ·� xn.

Horizontal Scani← 1;

while i < |V | doSuppose thatk is the largest integer

such thatxi = xi+1= · · · = xk;δ←maxi�m�k<j�|V | f x

mj ;for j← k + 1 to |V | do

xj := xj + δ;i← k + 1;

A vertical scan is similar.The purpose of using projection forces in two

directions is not only make nodes disjoint but alsomake them as compact as possible. The output ofthe force-scan algorithm applied to Fig. 1(b) is inFig. 1(c). It has been proved that the force-scanalgorithm ensures that its output has disjoint nodeimages and it preserves the mental map under theorthogonal ordering model [4,5], as described below.

Informally, the orthogonal ordering is, in SesameStreet terms, preserving up, down, left and right ofrelations between nodes. More precisely, it is definedas:S ≡OO T if for each pairp, q of points inS,• xp < xq if and only if xt(p) < xt(q), and• yp < yq if and only if yt(p) < yt(q), and• xp = xq if and only if xt(p) = xt(q), and• yp = yq if and only if yt(p) = yt(g),wherep = (xp, yp), q = (xq, yq), t (p)= (xt(p), yt (p))

andt (q)= (xt(q), yt (q)).If S ≡OO T then we say thatS andT have the same

orthogonal ordering.Other approaches for removing node overlap in-

clude a modified force-scan approach [9] and a con-strained optimization approach [8].

3. Removing edge-node intersections

Applying classical graph drawing algorithms tosuch graphs with nodes varying in shape and size

Page 3: Removing edge-node intersections in drawings of graphs

W. Lai, P. Eades / Information Processing Letters 81 (2002) 105–110 107

Fig. 2. A classical graph drawing.

Fig. 3. An example of edge-node intersections.

may also suffer from the problem of intersectionsbetween edges and nodes. An example is illustratedin Fig. 3: the spring algorithm from [2] gives Fig. 2,and replacing the nodes with rectangles gives not onlythe overlapping nodes but edge-node intersections.

For a graph drawing with no overlapping nodes (thiscan be ensured by the force-scan algorithm), thereare many routing algorithms which may be applied tosolve the problem of edge-node intersections. Thesealgorithms [10–12] originate in robot motion plan-ning. They are designed for finding a shortest path (inthe applicable metric) between two specified points(source and destination) while avoiding intersectionswith a set of “obstacles”. Robot motion planning al-gorithms generally assume that the obstacles are fixedin space. Such algorithms are not suitable for graphdrawing, because the “obstacles” in our case are nodesin a graph, and they not fixed in space (although theymay be constrained in some way). In a graph layout,the positions of nodes may change, especially for aninteractive layout system in which the user may insertor delete a node. For edge routing, sometimes severaledges may go though the gap between two nodes. Todraw these edges clearly, it may be required to makethat gap bigger by moving those two nodes apart. Also,the best edge route in a specific application may notthe shortest path between two nodes.

3.1. Requirements for edge drawings

For edge routes in a graph layout, several readabilitycriteria are relevant, such as:• Minimizing the number of edge crossings.• Minimizing the number of edge bends.• Minimizing the total length of edges.

Fig. 4. An example of different routings.

Page 4: Removing edge-node intersections in drawings of graphs

108 W. Lai, P. Eades / Information Processing Letters 81 (2002) 105–110

However, these criteria are often in conflict. Fig. 4shows two examples of drawing a edge from the nodea to the nodeb. Fig. 4(a) shows a shortest path withone crossing, Fig. 4(b) shows a longer path with fewerbends and no crossings. Different applications mayfocus on different criteria, so the selection of therouting should depend on the requirement of the user.

3.2. Method for removing edge-node intersections

We propose a method for removing edge-nodeintersections in graph layout based on our force-scanalgorithm. The steps of this method are described asfollows:(1) Ensure that a diagramG has no overlapping

nodes by applying a variation of the force-scanalgorithm.

(2) Apply a routing algorithm according to the se-lected criteria (for example, focus on the shortestpath, to obtain a polyline for each edge).

(3) Each bend of the edge decided by step (2) isreplaced by a dummy node with small size, so anew graphG′ is formed.

(4) Apply a variation of the force-scan algorithm tothe graphG′.

A variation of the force-scan algorithm means a slightchange based on applications. For example, we canadd a gap between nodes, that is, we increase the forcea bit between nodes in the algorithm. Another exampleis to increase nodes — that is, to choose bending pointsof edges as dummy nodes.

Note that the selection of the routing algorithm instep (2) is up to the user based on the user’s appli-cation, as different applications have different criteriafor the routing algorithm. Our method is to ensure thatthere are no edge-node intersections in a diagram.

3.3. Empirical evaluation

We have chosen several cases to test our methodfor removing edge-node intersections. Fig. 5 shows anexample of node overlaps and edge-node intersections

Fig. 5. An example of edge-node intersections.

Fig. 6. Two examples of our routing drawings.

Page 5: Removing edge-node intersections in drawings of graphs

W. Lai, P. Eades / Information Processing Letters 81 (2002) 105–110 109

Fig. 7. Output of our routing method.

in a diagram. If a routing algorithm for satisfying thecriteria of shortest path is chosen in step (2) in ourmethod, the output of our method is shown in Fig. 4(a).If an algorithm for orthogonal routing drawings ischosen in step (2) in the method, the output is shownin Fig. 4(b).

For the example shown in Fig. 3, another routing al-gorithm is used in step (2) of our method. This routingalgorithm is derived from robot motion planning [10–12], but it is slightly different from those algorithmsfocusing on the shortest path. This routing approachattempts to preserve the topology of the graph, thatis, an edge route is kept in the same sides of origi-nal nodes. In Fig. 6, two original graphs are shown onthe left, our routing drawings for them are shown onthe right, respectively. Fig. 7 shows the output of us-ing our method on Fig. 3.

More examples are shown on Figs. 8 and 9, in whichFigs. 8(b) and 9(b) are outputs of using this method onFigs. 8(a) and 9(a), respectively.

One feature of our method is that by using steps (3)and (4), we can prevent edge overlaps and controlthe density of edges in specific areas. For instance,Figs. 8(b) and 9(b) show disjoint edges in a “channel”between nodes 2 and 3. If there are more edgesthrough a “channel”, then our method rearrangesnodes (including the dummy nodes for bends) tomake this “channel” wide enough. For example, the“channel” between nodes 2 and 3 in Fig. 9(b) is widerthan that in Fig. 8(b).

Fig. 8. An example of ensuring disjoint edges.

4. Conclusion

The literature on abstract graph layout is quitelarge compared to that for graphs with nontrivial nodesizes. This note presents an approach for drawingthe latter kind of graph. Our method may use avariety of aesthetic criteria for edge routing. Thismethod integrates the force-scan algorithm and applies

Page 6: Removing edge-node intersections in drawings of graphs

110 W. Lai, P. Eades / Information Processing Letters 81 (2002) 105–110

Fig. 9. A further example of ensuring disjoint edges.

it successfully to preventing edge-node intersectionsand overlapping edges.

References

[1] G. Di Battista, P. Eades, R. Tamassia, I. Tollis, Algorithmsfor drawing graphs: An annotated bibliography, Comput.Geometry: Theory Appl. 4 (5) (1994) 235–282.

[2] P. Eades, A heuristic for graph drawing, Congressus Numer. 42(1984) 149–160.

[3] P. Eades, W. Lai, Visual interface design for relational systems,in: Proc. 5th Australian Software Engineering Conference,Sydney, May 1990, pp. 259–263.

[4] P. Eades, W. Lai, K. Misue, K. Sugiyama, Preserving themental map of a diagram, in: Proc. COMPUGRAPHICS’91,Sesimbra, Portugal, September 1991, pp. 34–43.

[5] P. Eades, W. Lai, K. Misue, K. Sugiyama, Layout adjustmentand the mental map, J. Visual Languages Comput. 6 (1995)183–210.

[6] P. Eades, W. Lai, Algorithms for disjoint node images, in:Proc. 15th Australian Computer Science Conference, Hobart,January 1992, pp. 253–265.

[7] D. Harel, On visual formalisms, Comm. ACM 31 (5) (1988)514–530.

[8] W. He, K. Marriott, Removing node overlapping using con-strained optimization, in: Proc. 21st Australian Computer Sci-ence Conference, Perth, February 1998, pp. 169–180.

[9] T. Masuzawa, K. Hayashi, M. Inoue, H. Fujiwara, A layout ad-justment problem for disjoint rectangles preserving orthogonalorder, in: Graph Drawing (GD’98), Lecture Notes in Comput.Sci., Vol. 1547, Springer, Berlin, 1998, pp. 183–197.

[10] R.C. Larson, V.O.K. Li, Finding minimum rectilinear distancepaths in the paths in the presence of barriers, Networks 11(1981) 285–304.

[11] D.T. Lee, F.P. Preparata, Euclidean shortest paths in thepresence of rectilinear barriers, Networks 14 (1984) 393–410.

[12] T. Lozano-Perez, M.A. Wesley, An algorithm for plan-ning collision-free paths among polyhedral obstacles, Comm.ACM 22 (1979) 560–570.

[13] J. Rumbaugh, OMT: The development process, J. Object-Oriented Programm. 5 (1995) 8–16.

[14] K. Sugiyama, K. Misue, Visualization of structural informa-tion: Automatic drawing of compound digraphs, IEEE Trans.Systems, Man Cybernetics 21 (4) (1991) 876–892.