0
我有以下代码(使用graphviz4net C#转换):怪异箭头
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" ];
}
我检查上http://www.graphviz-dev.appspot.com/转换后的图像。
的形象是这样的:
我在C#编程。我有2个问题:
1 - 如何修复C#中的箭头?
2 - 如何使椭圆在C#中消失?
*我知道我可以使用node [shape = none],但我不知道如何在C#中设置它。
UPDATE:
现在我已经得到了下面的代码:
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" ];
}
这给了我:
不要担心标签的问题,我会解决这个问题。
C#代码是因为它遵循:
Graph<State> Graph = new Graph<State> { Rankdir = RankDirection.LeftToRight };
一个StringBuilder生成子图
// returns new SubGraph<State>{ Label = stringBuilder.ToString()};
var stringNewBlock = ConvertBlockToSubgraph(state);
内部ConvertBlockToSubgraph
foreach (var allowedOperation in allowedOperationList)
{
stringBuilder.Append(allowedOperation.Key +":\\n");
foreach (var operation in allowedOperation.Value)
{
stringBuilder.Append(!operation.Equals(lastAllowedOperation) ? operation + ",": operation);
}
}
回到外界:
var subgraphNewBlock = new SubGraph<State>{ Label = stringBuilder.ToString()};
stringNewBlock.AddVertex(state);
Graph.AddSubGraph(stringNewBlock);
然后我生成的边缘:
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;
}
然后我转换为DOT格式:
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;
}
这个问题我还是期待奇怪的箭头。
有什么建议吗?
这听起来不像是一个真正的C#问题 - 它只是一个graphviz问题。我怀疑,当你计算出需要生成的文本时,生成它的C#代码将变得微不足道。 –
@JonSkeet他已经为此打开了一个问题:http://stackoverflow.com/questions/19384408/graphviz-4net-to-dot-conversion – Potherca