The SvgLayerSample demonstrates how to use MSAGL to construct a graph and render it as an SVG. You can define nodes (including specialized types like ComponentNode and LabeledNode), organize them into Subgraph structures, and connect them with edges. The Diagram class is used to process the Graph and generate the SVG output.
var drawingGraph = new Graph();
// Add various node types
drawingGraph.AddNode(new ComponentNode("Foo"));
drawingGraph.AddNode(new ComponentNode("Bar", "Bar Component", "[Azure Functions]", "This is the Bar component, really really important!"));
drawingGraph.AddNode(new LabeledNode("Component05", new System.Collections.Generic.List<string> { "Component Nr. 5" }));
// Organize nodes into subgraphs
var subGraph = new Subgraph("Section01");
subGraph.AddNode(drawingGraph.FindNode("Component02"));
drawingGraph.RootSubgraph.AddSubgraph(subGraph);
// Add custom labels and styling to nodes
var labels = new List<Svg.Label> {
new Svg.Label("Component Nr. 9") {
Font = new System.Drawing.Font("Consolas", 20f, System.Drawing.FontStyle.Bold),
Color = Color.Azure
}
};
var labeledNode = new LabeledNode("Component09", labels);
labeledNode.SvgElement.BackgroundColor = Color.Maroon;
drawingGraph.AddNode(labeledNode);
// Define edges
drawingGraph.AddEdge("Foo", "Something", "Bar");
// Render the diagram to SVG
var doc = new Diagram(drawingGraph);
doc.Run();
// Output the SVG string
System.Console.WriteLine(doc.ToString());