Reputation: 994
I have the following code (converted from C# using graphviz4net):
digraph g {
graph [rankdir="LR" ,compound="true" ];
subgraph cluster0 {
graph [label="Ready" ];
1 [ ];
};
subgraph cluster2 {
graph [label="Paused" ];
3 [ ];
};
1 -> 3 [ ltail="cluster0" ,lhead="cluster2" ,comment="4" ];
3 -> 1 [ ltail="cluster2" ,lhead="cluster0" ,comment="5" ];
}
I'm checking the converted image on http://www.graphviz-dev.appspot.com/.
The image is like this:
I'm programming in C#. I have 2 questions:
1 - How to fix the arrows in C#?
2 - How to make the ellipses disapear in C#?
*I know I can use node [shape = none], but I don't know how to set it in C#.
UPDATE:
Now I've got the following code:
digraph g {
graph [rankdir="LR" ,compound="true" ];
subgraph cluster0 {
graph [label="Ready\n\nPurchaser:\noperation1,operation2,Supplier:\noperation1,operation3," ];
1 [ shape="none" ,fontcolor="white" ];
};
subgraph cluster2 {
graph [label="Paused\n\nPurchaser:\noperation1,operation3,Supplier:\noperation2,operation3," ];
3 [ shape="none" ,fontcolor="white" ];
};
subgraph cluster4 {
graph [label="Completed\n\nPurchaser:\noperation4,Supplier:\noperation4," ];
5 [ shape="none" ,fontcolor="white" ];
};
1 -> 3 [ ltail="cluster0" ,lhead="cluster2" ,comment="6" ];
1 -> 5 [ ltail="cluster0" ,lhead="cluster4" ,comment="7" ];
3 -> 1 [ ltail="cluster2" ,lhead="cluster0" ,comment="8" ];
3 -> 5 [ ltail="cluster2" ,lhead="cluster4" ,comment="9" ];
}
Which gives me:
Don't worry about the label problems, I'll fix that.
The C# code is as it follows:
Graph<State> Graph = new Graph<State> { Rankdir = RankDirection.LeftToRight };
A stringBuilder generates the subgraphs
// returns new SubGraph<State>{ Label = stringBuilder.ToString()};
var stringNewBlock = ConvertBlockToSubgraph(state);
Inside ConvertBlockToSubgraph
foreach (var allowedOperation in allowedOperationList)
{
stringBuilder.Append(allowedOperation.Key +":\\n");
foreach (var operation in allowedOperation.Value)
{
stringBuilder.Append(!operation.Equals(lastAllowedOperation) ? operation + ",": operation);
}
}
Back to outside world:
var subgraphNewBlock = new SubGraph<State>{ Label = stringBuilder.ToString()};
stringNewBlock.AddVertex(state);
Graph.AddSubGraph(stringNewBlock);
Then I generate the Edges with:
public override IBlockHandling<State> GenerateLinks()
{
foreach (var state in statesDictionary.Values)
{
foreach (var nextPossibleState in state.GetNextPossibleStateList())
{
if (statesDictionary.ContainsKey(nextPossibleState))
{
var sourceSubGraph = Graph.SubGraphs.Single(x => x.Label.Contains(state.GetMainHeaderName()));
var destinationSubGraph = Graph.SubGraphs.Single(x => x.Label.Contains(nextPossibleState));
var edge = new Edge<SubGraph<State>>(sourceSubGraph, destinationSubGraph);
Graph.AddEdge(edge);
}
}
}
return this;
}
Then I convert to the DOT Format with:
public override IBlockHandling<State> ConvertDtoToDot()
{
var writer = new StringWriter();
new GraphToDotConverter().Convert(writer, Graph, new AttributesProvider());
var result = writer.GetStringBuilder().ToString().Trim();
Console.WriteLine(result);
return this;
}
The problem I still have are the arrows looking weird.
Any suggestions?
Upvotes: 0
Views: 864
Reputation: 19
If your problem is in the arrows shape, please see the below code:
var edge = new Edge<SubGraph<State>>(sourceSubGraph, destinationSubGraph ,
new Arrow(), new DiamondArrow());
For more info please check the below :
Upvotes: 0