グラフを .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();
}
}