Coder Social home page Coder Social logo

dotnetgraph's Introduction

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)

var graph = new DotGraph().WithIdentifier("MyGraph");

var directedGraph = new DotGraph().WithIdentifier("MyDirectedGraph").Directed();

Create and add a node (DotNode)

var myNode = new DotNode()
    .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 graph
graph.Add(myNode);

Create and add an edge (DotEdge)

// Create an edge with identifiers
var myEdge = new DotEdge().From("Node1").To("Node2");

// Or with nodes and attributes
var myEdge = new DotEdge()
    .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 graph
graph.Add(myEdge);

Create a subgraph / cluster

// Subgraph identifier need to start with "cluster" to be identified as a cluster
var mySubgraph = new DotSubgraph().WithIdentifier("cluster_0");

// Create a subgraph with attributes (only used for cluster)
var mySubgraph2 = new DotSubgraph()
    .WithIdentifier("cluster_1")
    .WithColor(DotColor.Red)
    .WithStyle(DotSubGraphStyle.Dashed)
    .WithLabel("My subgraph!");

// Add node, edge, subgraph
subGraph.Add(myNode);
subGraph.Add(myEdge);
subGraph.Add(mySubgraph2);

// Add subgraph to main graph
graph.Add(mySubgraph);

Compile to DOT format

await using var writer = new StringWriter();
var context = new CompilationContext(writer, new CompilationOptions());
await graph.CompileAsync(context);

var result = writer.GetStringBuilder().ToString();

// Save it to a file
File.WriteAllText("graph.dot", result);

Credits

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

dotnetgraph's People

Contributors

andreabodo avatar droppers avatar dzaba1 avatar expl0it3r avatar lukascorona avatar vfrz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.