SubGraph Binding

I have the following SubGraph.

Here, Inside nodes are also subgraph, some are with handle and some are without handle. Handle is invisible because there is not inside anything in that subgraph or not added anything in it yet.

I want to write an XML of the subgraph. I have created some bindings for this subgraph referring user guide and sample application. These bindings include, binding for document, node and link. Currently, I can write XML and read it. After reading I get only subgraph without links and ports. There is some information generated about links in XML.

In my XMLreadwrite base, have following bindings,

        GoXmlBindingTransformer bt;
      //////// Prototype element: Document///////
        GoDocument doc = new GoDocument(); // this.goView2.Document;
        bt = new GoXmlBindingTransformer("CustomSubgraphView", doc);
        bt.AddBinding("version", "Version", GoXmlBindingFlags.RethrowsExceptions);  
        bt.AddBinding("name", "Name");

        //////prototype element: subgraph//////
        CustomSubgraph sg = new CustomSubgraph("a", "b", "c");
        sg.Port = new CustomSubgraphPort();

        bt = new GoXmlBindingTransformer("CustomSubgraph", sg);
        bt.HandlesNamedPorts = true;  
        bt.HandlesChildren = true;  
        bt.HandlesChildAttributes = true;   
        bt.HandlesSubGraphCollapsedChildren = true;  
        bt.AddBinding("abel", "Label.Text");
        bt.AddBinding("xy", "Position");
        bt.AddBinding("back", "BackgroundColor");
        bt.AddBinding("opacity", "Opacity");
        bt.AddBinding("border", "BorderPen.Color");
        bt.AddBinding("borderwidth", "BorderPen.Width");
        bt.AddBinding("loc", "Location");                       

        ////prototype element : port
         CustomSubgraphPort prt = new CustomSubgraphPort();
        bt = new GoXmlBindingTransformer("port", sg.Port);
        bt.IdAttributeUsedForSharedObjects = true;
        bt.AddBinding("prtloc", "Location");
        bt.AddBinding("prtsize", "Size");

         /////prototype element : link
        GoLink lnk = new GoLink();
        lnk.Style = GoStrokeStyle.Bezier;
        lnk.ToArrow = true;
        lnk.FromArrow = false;
        t = new GoXmlBindingTransformer("link", lnk);
        t.AddBinding("from", "FromPort");
        t.AddBinding("to", "ToPort");

The above binding can create subgraph without ports properly. But if I add ports and try to write and read XML, it creates ports but locations are not as that of original diagram. Links are not at all shown.
Could you please tell me what could be the problem?

I also want to save lists generated while creating the subgraph in the subgraph class. For example there will be child list associated with each subgraph which contains subgraphs inside the subgraph… Could you please provide me sample code to do such bindings? Beacause currenlty when XML is read only graphical objects are created but behind data is not stored in each node object on the diagram. Each node on the diagram also have data associted with that node. But en I read XML only graphical diagram is created without assigning data associated with each node.
Please help me to do such binding with sample example.

Thank you.

The first thing to do is look at the XML being generated and seeing if you could regenerate the graph by hand using the data included.

In particular, is there enough data there to recreate the ports? Since that’s an extension to this class, that’s probably the tricky part.

Dear Jake,
Thank you very much for the mail and reply.
Now I can create links as well, same as that of original diagram. It creates diagram as that of original diagram but when I expand or collapse a subgraph subgraph starts moving which is not the case when I create subgraph(without reading i.e. manually adding node, ports and links). This happens only after reading diagram form XML.
And it creates extra ports. For instance there are 2 ports in original diagram and 1 link between them. It creates 4 ports. Out of these 4 ports, 2 ports are placed as per original diagram and link is there between them. Whereas other two ports are place some other position but link is not there in between them. I struggling to find why it is creating the extra ports.
In binding, I have created separate prototype element for port and removed bt.GeneratesPortsAsChildElements = true; and bt.HandlesNamedPorts = true from the prototype element node. I am not sure, this causing problem or not? If create separate prototype element for Port then , do I need to include the above properties in prototype node?
XML contains correct information i.e. node, link and port information. XML looks alright. While reading it is creating extra port. And when i expand or collapse or layout the diagram starts creating problem as that of the extra label. If you want I can send the sample project implementing same things in SubGrpahApp sample with Multiport subgraph. These extra ports are causing problem. Even if I add bt.GeneratesPortsAsChildElements = true; and bt.HandlesNamedPorts = true it creates some more extra ports.
Thank you once again for the reply.

Make sure the prototype subgraph you hand in to Xml doesn’t have any ports.

Thank you very much for the reply.
If I understand correctly, you mean while writing prototype subgraph node element, I should not include anything related to port in it as I am having separate prototype element for Port.
I tried above. Now my prototype element subgraph node contains following code:
SubGraph sg = new SubGraph("","","");

        bt = new GoXmlBindingTransformer("SubGraph", sg);

        bt.BodyConsumesChildElements = true;
        bt.IdAttributeUsedForSharedObjects = true;
        bt.HandlesChildren = true;
        bt.HandlesChildAttributes = true;            
        bt.HandlesSubGraphCollapsedChildren = true;

In addition to above it contains properties of the subgraph such as location, text, backgroundcolor, opacity etc.

And prototype element node contains following code:

       SubGraphPort p = sg.MakePort(GoObject.NoSpot);
        bt = new GoXmlBindingTransformer("SubGraphPort", p);
        // each port gets a unique id
        bt.IdAttributeUsedForSharedObjects = true;
        bt.AddBinding("side", "Side");
        bt.AddBinding("pos", "Position");

Now, with the above prototype elements it generates XML which contains only information of ports visible on the diagram and links. It draws connections properly among the ports as per XML which are same connections as that of the original diagram. But there are extra ports which are not exactly double that of original diagram. What I think here, these extra ports are due to number of subgraphs in the diagram. As number of extra ports are equal to number of subgraphs on the diagram. By default there may be port associated with every subgraph which get drawn while reading XML.
Currently, while reading XML contains following issues:

  1. There are extra ports other than on the diagram.
  2. Though connections drawn are correct, the ports are not placed properly on subgraph node.(I am attaching image for reference)

Original Diagram: (Here inside nodes c c (F2) and b b (F3) are also subgraphs. Handle is invisible)

Diagram After reading XML:

You can see here there are 3 extra ports and in the diagram there are only three subgraph i.e. outside subgraph( a a (F1)) and two inside subgraphs ( c c (F2) and b b (F3) ).
Please note here that if i move any subgraph inside the subgraph, ports associated with the subgraph(extra port associated port of the subgraph as well) also moves. It means that ports are properly associated to the subgraph except their location on it.


read through this old discussion: XML: duplicate xmlElements when using subclasses

I think that may help. If it doesn’t, then zip up a whole project that I can run and email that to “godiagram”.

I’ve sent you back code that works with the testing I did.

Thank you very much Jake for the reply.
Really sorry to trouble you again and again.
I really appreciate your help. The code works fine now.
Thank you.