Welcome to yEd Q&A!
Here you can ask questions and receive answers from other members of the community and yEd developers. And you can tell us your most wanted feature requests.

Categories

Serialize .Net Class into GraphML and read into yEd

+1 vote

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:
 
  1. Is yEd capable of extracting the node labels, somehow, using the above node definitions?
  2. 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.
 
 

 

in Help by
edited

1 Answer

0 votes

Yes, yEd is capable of extracting the node labels from your node definitions.

Your data element will result in  a custom "Name" property when you open your GraphML in yEd. (Select a node, press F6 to open the properties dialog. Its "Data" tab will have a text area labeled "Name" that holds the corresponding value.) To use your Name data as node label, open yEd's property mapper ("Edit -> Properties Mapper"), create a new node configuration, add a new entry in the "Mappings" table by clicking the green "+" icon. If "Name" is the only custom property in your graph, simply click "Ok". If you have several custom properties, choose "Name" as "Data Source", "Label Text" as "Map To", and "Automatic" as "Conversion", then click "Ok".

 

by [yWorks] (161k points)
Legal Disclosure | Privacy Policy
...