Reputation: 518
I hope I don't appear lazy, but I am really struggling to draw a graph using QuickGraph and GraphViz, since I can't appear to find much documentation online. I am quite new to C# interfaces, so am finding them quite confusing as well. Would anybody be able to give me a simple working example, or direct me so some good examples and documentation?
Thank you.
Upvotes: 2
Views: 6544
Reputation: 824
The Quickgraph-to-Graphviz-export can not write files, so you need to implement IDotEngine which handles the file writing.
public class FileDotEngine : IDotEngine
{
public string Run(GraphvizImageType imageType, string dot, string outputFileName)
{
using (StreamWriter writer = new StreamWriter(outputFileName))
{
writer.Write(dot);
}
return System.IO.Path.GetFileName(outputFileName);
}
}
Then you can call the Graphviz Algorithm like this:
GraphvizAlgorithm<TNode, TEdge> graphviz = new GraphvizAlgorithm<TNode, TEdge>(this.Graph);
graphviz.FormatVertex += (sender, args) => args.VertexFormatter.Comment = args.Vertex.Label;
graphviz.FormatEdge += (sender, args) => { args.EdgeFormatter.Label.Value = args.Edge.Label; };
graphviz.Generate(new FileDotEngine(), filePath);
The created dotfile can be passed to graphviz. See Graphviz Dot usage here in the dotguide
Upvotes: 2