Skip to content

Visualization Using MSAGL

Alexandre Rabérin edited this page Jun 14, 2020 · 1 revision

Visualization Using MSAGL

QuikGraph supports MSAGL to render the graphs. The QuikGraph.MSAGL module contains specialized "populators" that converts a QuikGraph graph into an MSAGL graph. This is possible through convenient extensions methods:

// Verbose way
IEdgeListGraph<string, Edge<string>> graph = ...;

var populator = graph.CreateMsaglPopulator<string, Edge<string>>(graph);
populator.Compute();
Graph msaglGraph = populator.MsaglGraph;

// Easy way
IEdgeListGraph<string, Edge<string>> graph = ...;

Graph msaglGraph = graph.ToMsaglGraph(); // We have the graph :)

Once you have the MSAGL graph, you can use the MSAGL rendering support or built-in visualizer control to view it.

Customizing the vertices look

Hook to the NodeAdded and EdgeAdded events to get a hold on the MSAGL nodes and edges when they are created.

// Verbose way
IEdgeListGraph<string, Edge<string>> graph = ...;

var populator = graph.CreateMsaglPopulator<string, Edge<string>>(graph);
populator.NodeAdded += (sender, args) => args.Node.Attr.Shape = Shape.Circle;
populator.Compute();
Graph msaglGraph = populator.MsaglGraph;

// Easy way
IEdgeListGraph<string, Edge<string>> graph = ...;

Graph msaglGraph = graph.ToMsaglGraph((sender, args) => args.Node.Attr.Shape = Shape.Circle);

Side note

If you need a support of Graphviz conversion like available in MSAGL, you can also consider using the QuikGraph.Graphviz module.

Clone this wiki locally