Hi,
I'm writing a crude Visual Studio project dependency analyzer tool (I know - I can use nDepend, etc.) and need to export my graph into GraphML. I am not using the yFiles libs to construct the graph; I have to use QuickGraph (sorry).
QuickGraph has the ability to serialize its graph to GraphML.
try {
var settings = new XmlWriterSettings();
settings.Indent = true;
var writer = XmlWriter.Create(outpath + Path.DirectorySeparatorChar + name + ".graphml", settings);
graph.SerializeToGraphML(writer, graph.GetVertexIdentity(), graph.GetEdgeIdentity());
writer.Close();
}
catch (Exception) {
throw;
}
By default, this produces the graph structure, which, when read into yEd, produces a nice graph, but none of the nodes (or edges) have labels, and there is no <data> element for any of the graphml elements.
A workaround is to create my own Node class and give it a serializable name attribute:
[Serializable]
public class Node {
public Node(string name) {
Name = name;
}
[XmlAttribute("Name")]
public string Name { get; set; }
}
The graphml created in this case has the serialized names embedded in the <data> element within the graphml node:
<?xml version="1.0" encoding="utf-8"?>
<key id="Name" for="node" attr.name="Name" attr.type="string" />
<graph id="G" edgedefault="directed" parse.nodes="100" parse.edges="2" parse.order="nodesfirst" parse.nodeids="free" parse.edgeids="free">
<node id="0">
<data key="Name">Foo.Common.Remoting</data>
</node>
...
Still, when imported into yEd, I see no node labels. My questions are as follows:
-
Is yEd capable of extracting the node labels, somehow, using the above node definitions?
-
If the answer to #1 above is no, is there some .Net snippet yWorks has developed to allow serializing a .Net class into a graphml node structure which conforms to the yFiles <y:ShapeNode>?
I'm only interested in serializing the node name into the y:NodeLabel. None of the positional/formatting attributes are necessary.
Thanks very much.
E.