The latest version of Matthew Sackman's Haskell bindings to Graphviz [1] are now available on Hackage [2]. The reason there's a new release only two weeks after the previous one is that I've made some extensions to it (hence why I'm writing the announcement) that Matthew has kindly included.
Since Matthew doesn't recall writing an announcement for graphviz before, here is a brief synopsis of what it does. The Graphviz program is probably _the_ way of drawing graphs (note: this is graph-theory graphs, not function plotting). As it stands, there are currently at least four different Haskell bindings available for Graphviz that I've managed: * The inbuilt Graphviz module in FGL [3] * graphviz (which this announcement is for) * dotgen [4] * A really simple generator by Duncan Coutts [5] In addition to this, the following utilities on Hackage output graphs in Graphviz's .dot format (either using one of the above libraries or their own parser): * prof2dot : converts profiling information to .dot [custom, I think] [6] * flow2Dot : convert textual descriptions to .dot [also custom, I think] [7] * graphmod : draw the dependencies between Haskell modules [uses dotgen] [8] As it can be seen, there's a plethora of possible ways of creating .dot graphs in Haskell. What seperates the graphviz package from the others is: * It uses FGL graphs, rather than passing through lists of nodes and edges manually (of course, if you're not doing any other graph-related activity you might not want to use an FGL graph), whilst providing more control than the default FGL module. * A large list of attributes that can be used are available: http://hackage.haskell.org/packages/archive/graphviz/2008.9.20/doc/html/Data-GraphViz-Attributes.html * A "sane" interface that provides a large degree of customizability (don't specify the attributes manually for each node/edge/etc., just pass through a function that will create the attribute you want). * Limited parsing of .dot format (note that as yet it can't convert a parsed DotGraph into an FGL graph). * The graphToGraph function allows you to pass a graph through Graphviz and then extract out positional information and combine it with the original graph. There are some things things that graphviz can't do, such as drawing undirected graphs and clusters (which dotgen can)... at least until now. The changes that I have made provide the additional functionality to graphviz: * Differentiate between undirected and directed graphs. Whilst FGL represents undirected graphs with a directed graph by duplicating all edges (an undirected edge {1,2} is represented by the two edges (1,2) and (2,1)), you don't really want to draw a graph this way. Furthermore, many reports say that graphviz's "neato" command is better at drawing undirected graphs than the normal "dot" command is. Thus, graphviz will now draw only one edge out of every directed pair. To do so, however, requires that the edge labels are an instance of Ord: if this is a problem for you, please contact either Matthew or myself and we'll see what else we can do (this is required because it's assumed that if two edges (1,2) and (2,1) are meant to represent the undirected edge {1,2}, then their labels must be the same). * Add clustering support. Graphs can be drawn (but as yet not parsed) to provide nested clustering support to arbitrary depth. To do so, you need to provide a function (LNode a -> NodeCluster c a), where NodeCluster is the following recursive data type that indicates in which subcluster a node in the graph belongs: data NodeCluster c a = N (LNode a) | C c (NodeCluster c a) The c type represents the cluster label, and is the parameter by which cluster attributes are assigned. Note that c has to be an instance of Ord. Clusters are not parseable, because there's no clear way of how to convert a cluster to an FGL graph. The interface for graphviz remains unchanged, so you can safely upgrade to this version. Here is an example function of how the library can be used to draw an FGL graph to a (very plain) Graphviz graph (well, it will convert it to the DotGraph datatype, which when shown produces the .dot graph code): graphviz :: (Graph g, Show a, Ord b, Show b) => String -> g a b -> DotGraph graphviz title g = graphToDot g attrs nattrs eattrs where attrs = [Label title] nattrs (_,a) = [Label (show a)] eattrs (_,_,b) = [Label (show b)] Enjoy! [1] http://graphviz.org/ [2] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/graphviz [3] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/fgl [4] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/dotgen [5] http://haskell.org/~duncan/WriteDotGraph.hs [6] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/prof2dot [7] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/flow2dot [8] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/graphmod -- Ivan Lazar Miljenovic [EMAIL PROTECTED] IvanMiljenovic.wordpress.com _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell