在QuickGraph中,当导出到graphml时,如何指定边缘颜色?

时间:2013-07-02 21:11:58

标签: colors edge graphml quickgraph

我正在更新一个将图形从.dot导出到.graphml格式的方法。

以前,在FormatEdge和FormatVertex事件中设置了颜色和标签。我不清楚在哪里设置graphml的颜色。

.Dot Way

...
public ExportDot()
{
  IVertexAndEdgeListGraph<TVertex,TEdge> g= ...;

  var graphviz = new GraphvizAlgorithm<TVertex,CustomEdge<int>>(g);
  graphviz.FormatVertex += OnFormatVertex;
  graphviz.FormatEdge += OnFormatEdge;

  var output = graphviz.Generate(new FileDotEngine(), "graph");  
}

public virtual void OnFormatEdge(object obj, 
  FormatEdgeEventArgs<TVertex, CustomEdge<int>> e)
{ 
  e.EdgeFormatter.Label.Value = e.Edge.Id.ToString();
  e.EdgeFormatter.StrokeColor = Color.Blue;
}
...

自定义边缘类:

public CustomEdge : Edge<TVertex>
{
   public int Id {get; set;}
}

.Graphml Way

某些课程:

...
public ExportGraphml()
{
  var g = new BidirectionalGraph<int, CustomEdge<int>>();
  ...
  using(var xwriter = XmlWriter.Create(...))
    g.SerializeToGraphML<int, CustomEdge<int>>(xwriter);
}

自定义边缘类:

public CustomEdge : Edge<TVertex>
{
   [XmlAttribute("id")]
   public int Id {get; set;}

   public virtual string ToLabel()
   {
      return Id.ToString();
   }
}

0 个答案:

没有答案