2013-10-15 65 views
0

我有以下代碼(使用graphviz4net C#轉換):的Graphviz(4net)至DOT轉換

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/轉換後的圖像。

的形象是這樣的:

Image converted with Graphviz

我在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" ]; 
} 

這給了我:

Graphviz4net

不要擔心標籤的問題,我會解決這個問題。

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; 
    } 

這個問題我還是期待奇怪的箭頭。

有什麼建議嗎?

+0

你能提供圖形的C#代碼你輸入Graphviz4Net,以便它產生這個輸出? – Steves

+0

@Steves,我無法解決這個問題。我用我目前的狀態編輯了這個問題。請看看,並告訴我,如果你知道如何解決它。我擁有的代碼充滿了系統細節 – Th3B0Y

回答

0

如果你的問題是在箭頭形狀,請參閱下面的代碼:

var edge = new Edge<SubGraph<State>>(sourceSubGraph, destinationSubGraph , 
    new Arrow(), new DiamondArrow()); 

欲瞭解更多信息,請檢查下面:

Graphviz4Net