Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Create GraphViz DOT graph with .NET / C#

License

NotificationsYou must be signed in to change notification settings

vfrz/DotNetGraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo

CreateGraphViz DOT graph withdotnet (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


[8]ページ先頭

©2009-2025 Movatter.jp