/csdot

A c# based DOT (graphviz) framework

Primary LanguageC#MIT LicenseMIT

csdot

Nuget

GitHub release (latest by date)

GitHub Workflow Status GitHub issues GitHub stars GitHub license GitHub contributors Nuget

A c# library to process the Dot language used by Graphviz.

Why csdot?

  • Easy and in tune.
  • Maximum number of attributes are supported as defined by the DOT grammar.
  • Support of custom attribute: the user can sync code and add custom attribute to the json to generate specific class or can use the inbuilt custom attribute present.
  • Attribute code is generated by python from json data making it scalable.
  • Simple API's for dot Elements and Attributes with Load and Save Support.
  • Continuous development and intergration with new feature updates.
  • Tracking of known bugs and quick support for user based issue.
  • Listed on Graphviz - Resources [https://graphviz.org/resources/]

Development occurs at GitHub, where you can report issues and request enhancement. Requires python(2-3) to build.

Usage:

Just import the library for your respective framework and start working!

csdot library

In csdot: graph, node, edge, subgraph, clusters are represented as Elements (implements IDot interface for grouping).

As they are grouped, they can be added to the root element using a single function: public void AddElement(IDot i_dot)

To add multiple attribute to root element, you can use: public void AddElements(params IDot [] i_dot)

Each element generated a unique ID UID which refers to that particular element. One can access it by calling:

var unique_id = graph.uid

(Considering graph is object of class Graph)

Elements of Dot

Graph:

To create a graph

Graph graph = new Graph("id");          // where id is the graph-ID string.

To set type 'strict'

graph.strict = true;

To set the type 'graph' or 'diagraph'

graph.type = "graph";

Node:

To create a node:

Node node = new Node("id");		// where id is the node-id

To set the compass point:

node.compassPoint = DataTypes.CompassPoint.North;

(Will explain the DataTypes later in this thread)

Edge:

To create an edge, we need to add a transition. A Transition is an element of edge.

Node a = new Node("a");
Node b = new Node("b");
Node c = new Node("c");
Edge edge = new Edge();
List<Transition> transition = new List<Transition>()
{
	new Transition(a, EdgeOp.directed),
	new Transition(b, EdgeOp.undirected),
	new Transition(c, EdgeOp.unspecified)
};
edge.Transition = transition;

Transition also supports ID:

List<Transition> transition = new List<Transition>()
{
	new Transition("a", EdgeOp.directed),
	new Transition("b", EdgeOp.unspecified)
};
Edge edge = new Edge(transition);

Here no node is created, and the edge is created using the ID. Edge also supports adding of Elements.

Add elements to a root(like Graph, Subgraph):

graph.AddElement(node)
graph.AddElement(edge)

or you can directly call:

graph.AddElements(node, edge)

Attributes

Each element of Dot can have its respective attribute as defined in the dot guidelines. In csdot, we have covered many attributes respective to the type specified.

Set the value of attribute

The attributes are present in Attribute property of every element. Therefore to set a specific attribute, you need to call the property, which contains all the attribute objects and set its value as mentioned here:

graph.Attribute.center.Value = true;

This will set the center attribute of graph. The generated graph will have this attribute.

Removing attribute from Element using Set property

Natrually the attributes are just defined but not added to the element. Once the value is set for a particular attribute, it is added to the element.

You can remove the attribute by setting the Set property of that attribute to false

graph.Attribute.center.Set = false;

To set Node attribute "color"

node.Attribute.color.Value = Color.X11.darkviolet;

Default and Minimum:

Also we can get the default and minimum as well as set the default and minimum.

graph.Attribute.center.SetDefault();

To Set Minimum

graph.Attribute.voro_margin.SetMinimum();

Simiarly to Get default and minimum, one can invoke GetDefault() GetMinimum()

DataTypes

A few inbuilt classes are defined where the developer can check the available list of properties and set accordingly. Like Color in namespace namespace csdot.Attributes.DataTypes can be used. Most of these are static classes where the const data is present. Others are created for attributes supporting derived datatypes:

public class point

is one such example.

Attributes currently not added:

  • esep
  • headport
  • layer
  • layers
  • layerselect
  • normalize
  • orientation
  • pad
  • page
  • pagedir
  • quadtree
  • ratio
  • sep
  • size
  • start
  • style
  • tailport
  • vertices
  • viewport

These will be added in the upcoming versions.

The attributes having List as their secondary datatype and string as their first datatype, like color, fillcolor takes string Value. There is no list defined for such attributes. However for ranksep, a secondary holder, ValueList is added to support double datatype.

There are multiple known issues in the Attribute segment like handling of multi-types (string/double) as well as multi-default and multi-minimum. Please refer doc: csdot\Docs\Attribute Status.docs for more info

DotDocument

To load and save a file, you need to create a DotDocument object.

To save, you can call the API mentioned below:

public void SaveToFile(Graph i_graph, string i_fileLocation)

To load a graph you can call:

public Graph LoadDigraph(string i_fileLocation)

This will load the dot from the given file location and return a graph object.

License:

Distributed under MIT license.

Contacts:

Harsh (harshsikhwal7@gmail.com) Vibaswan (vroychowdhury@gmail.com)