Coder Social home page Coder Social logo

dotnetgraph's Introduction

DotNetGraph

Create GraphViz DOT graph with .NET

Available on NuGet: #

Compatible with .NET Standard 2.0 and higher

Documentation

Create a graph (DotGraph)

var graph = new DotGraph("MyGraph");

var directedGraph = new DotGraph("MyDirectedGraph", true);

Create and add a node (DotNode)

var myNode = new DotNode("MyNode")
{
    Shape = DotNodeShape.Ellipse,
    Label = "My node!",
    FillColor = Color.Coral,
    FontColor = Color.Black,
    Style = DotNodeStyle.Dotted,
    Width = 0.5f,
    Height = 0.5f,
    PenWidth = 1.5f
};

// Add the node to the graph
graph.Elements.Add(myNode);

Create and add an edge (DotEdge)

// Create an edge with identifiers
var myEdge = new DotEdge("myNode1", "myNode2");

// Create an edge with nodes and attributes
var myEdge = new DotEdge(myNode1, myNode2)
{
    ArrowHead = DotEdgeArrowType.Box,
    ArrowTail = DotEdgeArrowType.Diamond,
    Color = Color.Red,
    FontColor = Color.Black,
    Label = "My edge!",
    Style = DotEdgeStyle.Dashed,
    PenWidth = 1.5f
};

// Add the edge to the graph
graph.Elements.Add(myEdge);

Create a subgraph / cluster

// Subgraph identifier need to start with "cluster" to be identified as a cluster
var mySubGraph = new DotSubGraph("cluster_0");

// Create a subgraph with attributes (only used for cluster)
var mySubGraph = new DotSubGraph("cluster_0")
{
    Color = Color.Red,
    Style = DotSubGraphStyle.Dashed,
    Label = "My subgraph!"
};

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

// Add subgraph to main graph
graph.Elements.Add(mySubGraph);

Compile to DOT format

// Non indented version
var dot = graph.Compile();
// Indented version
var dot = graph.Compile(true);

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

dotnetgraph's People

Contributors

vfrz avatar droppers avatar expl0it3r avatar andreabodo avatar lukascorona 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.