Add URLs to Nodes - QuickGraph/Graphviz

Topics: graph
Jun 8, 2011 at 2:22 PM


I am trying to use QuickGraph with Graphviz. I see that Graphviz supports a few formats such as imap that can be used to add a URL to the node. I've successfully produced a ".dot" file. How can I add a URL to a node from within QuickGraph, such that it will end up in the ".dot" file?

Jun 9, 2011 at 5:59 PM
Edited Jun 10, 2011 at 3:39 PM

Also fyi it seems that there is no documentation of the QuickGraph.Graphviz code. Am I missing something?


Here are my thoughts, correct if necessary.

1. GraphvizAlgorithm.Generate() controls how each vertex is written to file.

2. WriteVertices() is called from within the Generate() method.

3. For each vertex in the graph, OnFormatVertex() is called.

4. In OnFormatVertex() a new GraphvizVertex() formatter is created. (A separate formatter - one per method call - is created for each vertex)

5. The FormatVertexEventHandler is called. (Again, happens once per vertex)

6. The ToDot() method is called finally writing each vertex out to file.


To summarize, in order to write each node with a URL, one approach is the following:

1. Create a new class to be used as your "TVertex".

2. This class will contain the URL.

3. Create an event handler method for the FormatVertexEventHandler, in this method, use vertex.formatter.url to set the URL.

4. profit.


Second edit:

My thoughts above were correct, at least the ones pertaining to the delegate and event subscription model that QuickGraph.Graphviz uses in its GraphvizAlgorithm class. I'm still surprised that there is seemingly no documentation of the API, but for anyone interested, you can use .NET Reflector to look at the code, all you need to do is open the QuickGraph.Graphviz .dll in Reflector. Also see these articles about C# method delegation:

And these links show you how to skip the ".dot" file creation and just create/draw the graph in memory using C#

Dec 24, 2011 at 11:48 PM

I've tried this with svg but it seems that setting the url has no effect (the url is not saved to svg):

var svg = graph.ToSvg(algorithm =>
                algorithm.FormatVertex +=
                    (sender, e) =>
                        e.VertexFormatter.Label = e.Vertex.Label;
                        e.VertexFormatter.Url = "http://my-url";
Does anybody have succeeded to add links to the svg output?