2

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

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

.点方式

...
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方式

一些类:

...
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();
   }
}
4

0 回答 0