我正在更新一个将图形从.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;}
}
某些课程:
...
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();
}
}