A GRAPH LIBRARY EXTENSION OF SVG Kurt Nørmark Department of Computer Science, Aalborg University Fredrik Bajers Vej 7, Aalborg, Denmark. [email protected] ABSTRACT This paper describes an extension of SVG that supports the drawing of graphs in terms of nodes and edges in between nodes. The graph drawing primitives support a variety of different node shapes, edge connection points, and edges. Both nodes and edges can be labeled. Two or more nodes can be aggregated as a single node, and an entire graph can be embedded into a single node. In addition, a number of different graph animations are described. The starting point of the SVG extension is a library that provides an exact of mirror of SVG 1.1 in the functional programming language Scheme. Each element of SVG 1.1 is represented as a specific function in Scheme. The graph drawing primitives are implemented as functional abstractions on top of the SVG 1.1 mirror functions. It is argued that the SVG extension approach, as exemplified by the graph drawing facilities, is useful whenever an author wish to control the complexity of a non-trivial SVG document. KEYWORDS Graph drawing, Graph animation, SVG extensions, SVG and functional programming. 1. INTRODUCTION A graph is a set of nodes and a set of edges between the nodes. Drawing of graphs is needed in a variety of contexts. In our own work we encountered a concrete need in a system that generates web-based lecture notes. The lecture note materials are both authored and delivered in XML languages. The use of SVG instead of bitmapped images allows for scalable contents. In addition, the use of SVG makes it possible to stay entirely within the framework of XML, both in the source language and the target language of the materials. There is a gap between the drawing primitives of SVG and the desired graph drawing primitives. In this paper we will illustrate one particular way to fill this gap. We define a graph drawing language that acts as an smooth and gentle extension of SVG. Via use of a functional programming language, the high-level graph concepts are translated to their lower-level SVG counterparts. In Section 2 we introduce the SVG extension approach. Based on this, we describe the SVG graph drawing facilities in Section 3. In Section 4 we describe a facility for graph animation on top of the basic graph drawing primitives. The conclusions are drawn in Section 5. There are three different contributions of this work: 1. A collection of graph drawing primitives that in part are intertwined with SVG. 2. A collection of graph animations on top of the graph drawing primitives, and implemented in terms of the SVG animation facilities. 3. An SVG extension mechanism, which can be used for controlling the complexity SVG documents in general. It is worth pointing out that our work is not about XML representation of graphs; we are focused on graph drawing. In addition, our work is not about automatic layout of graphs. The current version of the software requires explicit positioning of each node. We will briefly mention related work on XML graph representation, and graph drawing that is related to the use of SVG. GraphML [Brandes et al. 2002] and GXL [Winter et al. 2002] are XML formats for graphs. SVG has been used for graph drawing on top of both GraphML and GXL. GDL is a graph format of the commercial system aiSee (http://www.aisee.com/gdl/), which is able to generate SVG drawings of graphs. Similarly, GraphViz [Gansner 2000] is a graph visualization tool that is able to generate SVG output. Several different kinds of graph animation are represented in the literature. A main branch is covered by algorithm animation [Stasko 90]. In the “Graph Animation” project, Diehl et al. [Görk 2004] can visualize a sequence of graphs, to which nodes and edges are added or deleted. SVG is used in the Graph Animation project to visualize the graph evolutions. The aiSee system mentioned above is able, in SVG, to animate the transitions between different layouts of a given graph. The work described in this paper deals with step-by- step presentation of nodes and edges in a single graph, as well as visualization of different kinds of “graph walk through”. All graphs that are used as illustrations in this paper are available, both as complete Scheme source files and as SVG files, via the URL http://www.cs.aau.dk/~normark/svg-graphs.html. 2. THE SVG EXTENSION MECHANISM The SVG extension mechanism is based on a general mechanism for extending an XML language. The basic idea is to author an SVG document as an expression in a functional programming language, which returns an SVG value. In our work we use the Scheme programming language [Kelsey et al. 1998]. The SVG fragment <svg width="800" height="800"> <g> <circle cx="100" cy="100" r="50" stroke="black" stroke-width="3px" fill="none" /> <polygon points="256.7,125, 300,50, 343.3,125" stroke="black" stroke-width="3px" fill="none" /> <polygon points="50,300, 100,250, 150,300, 100,350" stroke="black" stroke-width="3px" fill="none" /> <rect x="250" y="250" width="100" height="100" stroke="black" stroke-width="3px" fill="none" /> <line x1="100" y1="100" x2="300" y2="100" stroke="black" stroke-width="3px" /> <line x1="300" y1="100" x2="300" y2="300" stroke="black" stroke-width="3px" /> <line x1="300" y1="300" x2="100" y2="300" stroke="black" stroke-width="3px" /> <line x1="100" y1="300" x2="100" y2="100" stroke="black" stroke-width="3px" /> </g> </svg> corresponds to the following expression in Scheme (svg 'width "800" 'height "800" (g (circle 'cx 100 'cy 100 'r 50 'stroke "black" 'stroke-width "3px" 'fill "none") (polygon 'points "256.7,125, 300,50, 343.3,125" 'stroke "black" 'stroke-width "3px" 'fill "none") (polygon 'points "50,300, 100,250, 150,300, 100,350" 'stroke "black" 'stroke-width "3px" 'fill "none") (rect 'x 250 'y 250 'width 100 'height 100 'stroke "black" 'stroke-width "3px" 'fill "none") (line 'x1 100 'y1 100 'x2 300 'y2 100 'stroke "black" 'stroke-width "3px") (line 'x1 300 'y1 100 'x2 300 'y2 300 'stroke "black" 'stroke-width "3px") (line 'x1 300 'y1 300 'x2 100 'y2 300 'stroke "black" 'stroke-width "3px") (line 'x1 100 'y1 300 'x2 100 'y2 100 'stroke "black" 'stroke-width "3px"))) Both of these create the geometric forms shown in Figure 1. Figure 1. Four geometric forms connected by straight lines. For each element in SVG there is a so-called corresponding mirror function in Scheme. The name of the mirror function is the same as the name of the SVG element. When a Scheme mirror function is called it generates an intermediate tree structure (akin to an abstract syntax tree), which in a straightforward way can be transformed to SVG. Moreover, the Scheme function encapsulates detailed knowledge of the SVG element in terms of the attributes and the possible immediate document constituents. This knowledge is used to guarantee that the resulting SVG value of the expression is valid relative to the SVG DTD. The set of Scheme mirror functions corresponding to SVG 1.1 is generated automatically from an SVG 1.1 DTD by use of tools from the LAML tool suite [Nørmark 2005]. There are only lexical differences between an SVG fragment and the similar expression in Scheme (as illustrated above). In the Scheme expression, SVG element instances are represented by function calls. Attribute names are represented as Scheme symbols, and attribute values can be either strings or numbers. The advantages of the Scheme expressions over the SVG fragments are substantial: 1. First and foremost, it is possible to introduce functional abstractions (corresponding to custom tags) in SVG documents. 2. In natural continuation of the first item, it is possible to bind local names to given values in let forms. The systematic use of local name bindings makes it possible to refactor selected aspects of the SVG document (such as positioning matters). 3. Lists of attribute name/value pairs can be dealt with as "first class values". 4. Arbitrary computations can be embedded in the SVG document. 5. When the Scheme expression is evaluated, validation is performed against the SVG DTD, and possible problems are reported immediately. For a concrete illustration of these advantages, the Scheme source of the SVG fragment shown above can be rewritten as (svg 'width "800" 'height "800" (let ((x1 100) (y1 100) (x2 300) (y2 300) (r 50) (line-props (list 'stroke "black" 'stroke-width "3px")) ) (g (circle 'cx x1 'cy y1 'r r line-props 'fill "none") (equilateral-triangle 'cx x2 'cy y1 'r r line-props) (diamond 'cx x1 'cy y2 'r r line-props) (rect 'x (- x2 r) 'y (- y2 r) 'width (* 2 r) 'height (* 2 r) line-props 'fill "none") (line 'x1 x1 'y1 y1 'x2 x2 'y2 y1 line-props) (line 'x1 x2 'y1 y1 'x2 x2 'y2 y2 line-props) (line 'x1 x2 'y1 y2 'x2 x1 'y2 y2 line-props) (line 'x1 x1 'y1 y2 'x2 x1 'y2 y1 line-props) ))) This expression still produces the drawing shown in Figure 1. The functions equilateral- triangle and diamond have been implemented for demonstration purposes. (Their implementations are given in Appendix A). The use of these abstractions raises the level of abstraction of the SVG document. The new abstractions enjoy the same status as the existing, pre-defined elements of SVG (such as circle and rect). As another aspect that improves the document, the local name bindings of the coordinates x1, y1, x2, y2, as well as the radius r makes the SVG document fragment much easier to maintain.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages11 Page
-
File Size-