Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

65 Commits

Repository files navigation

DotNetGraph

Logo

Create GraphViz DOT graph with dotnet (compatible with .NET Standard 2.0 and higher).

Current stable version: #

Latest version: #

Usage

Create a graph (DotGraph)

vargraph=newDotGraph().WithIdentifier("MyGraph");vardirectedGraph=newDotGraph().WithIdentifier("MyDirectedGraph").Directed();

Create and add a node (DotNode)

varmyNode=newDotNode().WithIdentifier("MyNode").WithShape(DotNodeShape.Ellipse).WithLabel("My node!").WithFillColor(DotColor.Coral).WithFontColor(DotColor.Black).WithStyle(DotNodeStyle.Dotted).WithWidth(0.5).WithHeight(0.5).WithPenWidth(1.5);// Add the node to the graphgraph.Add(myNode);

Create and add an edge (DotEdge)

// Create an edge with identifiersvarmyEdge=newDotEdge().From("Node1").To("Node2");// Or with nodes and attributesvarmyEdge=newDotEdge().From(node1).To(node2).WithArrowHead(DotEdgeArrowType.Box).WithArrowTail(DotEdgeArrowType.Diamond).WithColor(DotColor.Red).WithFontColor(DotColor.Black).WithLabel("My edge!").WithStyle(DotEdgeStyle.Dashed).WithPenWidth(1.5);// Add the edge to the graphgraph.Add(myEdge);

Create a subgraph / cluster

// Subgraph identifier need to start with "cluster" to be identified as a clustervarmySubgraph=newDotSubgraph().WithIdentifier("cluster_0");// Create a subgraph with attributes (only used for cluster)varmySubgraph2=newDotSubgraph().WithIdentifier("cluster_1").WithColor(DotColor.Red).WithStyle(DotSubGraphStyle.Dashed).WithLabel("My subgraph!");// Add node, edge, subgraphsubGraph.Add(myNode);subGraph.Add(myEdge);subGraph.Add(mySubgraph2);// Add subgraph to main graphgraph.Add(mySubgraph);

Compile to DOT format

awaitusingvarwriter=newStringWriter();varcontext=newCompilationContext(writer,newCompilationOptions());awaitgraph.CompileAsync(context);varresult=writer.GetStringBuilder().ToString();// Save it to a fileFile.WriteAllText("graph.dot",result);

Credits

Logo: https://www.flaticon.com/free-icon/flow-chart_4411911

Releases

Packages

Used by

Contributors

Languages