static void Main(string[] args) { DotGraph graph = new DotGraph("simple test"); DotGraph.Digraph digraph = graph.GetDigraph(); digraph.AddNode("Car").SetLabel("My Car 2").SetComment("This is BMW 2").SetOptions(DotStyles.STUB_NODE_OPTIONS); digraph.AddNode("Wheel").SetLabel("Its wheels").SetComment("The wheels of my car"); digraph.AddAssociation("Car", "Wheel").SetLabel("4*").SetComment("There are 4 wheels").SetOptions(DotStyles.ASSOCIATION_EDGE_STYLE); string dot = graph.Render(); // Create an image from the dot content var imageFilePath = GraphVizDot.RenderImage(dot, "png"); if (File.Exists(imageFilePath)) { Console.WriteLine($"Opening {imageFilePath}..."); System.Diagnostics.Process.Start(imageFilePath); } Console.WriteLine("Press enter to exit;"); Console.ReadLine(); }
private void Write(View view, Element clusterElement, StringWriter writer) { try { DotGraph graph = new DotGraph(view.Name); DotGraph.Digraph digraph = graph.GetDigraph(); DotGraph.Cluster cluster = null; if (clusterElement != null) { cluster = digraph.AddCluster(clusterElement.Id); cluster.SetLabel(clusterElement.Name); } foreach (ElementView elementView in view.Elements) { Element element = elementView.Element; if (clusterElement != null && element.Parent == clusterElement) { cluster.AddNode(element.Id).SetLabel(element.Name); } else { digraph.AddNode(element.Id).SetLabel(element.Name); } } foreach (RelationshipView relationshipView in view.Relationships) { Relationship relationship = relationshipView.Relationship; digraph.AddAssociation(relationship.SourceId, relationship.DestinationId).SetLabel(relationship.Description); } string output = graph.Render().Trim(); writer.Write(output); writer.Write(Environment.NewLine); writer.Write(Environment.NewLine); } catch (Exception ex) { String message = ex.Message; } }