Twin adding to a node that is in between

I have adopted some code from the twin supported Genogram to be able to represent twins in my pedigree editor app. The representation looks fantastic.

However, I also realised it will only work fine when I add twins to the last node on the right. If I tried to pick a node in between, it will always draw its twin at the last on the right. e.g:

Is there a way to prevent this?

As far as I know, if I add a spouse to a particular node, it will automatically move the new node to the selected node. Is it possible to do the same for adding twins? Does it do anything with the vertexes?

I wonder if the order of the children is causing that. That is, in your scenario, the user selected “Male Child 2” and added a “Twin” which got put at the end of the list of parent links.

[EDIT: replaced by new code using a different method, referenced below]

Hi Walter,

Thank you very much for your effort taking the time to put up a code.

Actually, I discovered a way which bring one step forward towards the outcome I’m hoping for, by adding this into prototype.commitNodes (isTwin is a custom property):

                // Handling twin
                this.network.vertexes.each(function(vertex) {
                    var node = vertex.node;
                    
                    if (node === null) { return; } 

                    if (node.data.isTwin) {
                        var orgNode = node.diagram.findNodeForKey(node.data.birth);
                        if(node.data.birth !== node.data.pedigreeMemberId) {
                            //node.move(new go.Point(orgNode.actualBounds.x + orgNode.actualBounds.width + layout.spouseSpacing, vertex.y));
                            vertex.x = orgNode.actualBounds.x;
                            node.move(new go.Point(orgNode.actualBounds.x, vertex.y));
                            orgNode.move(new go.Point(node.actualBounds.x + orgNode.actualBounds.width, vertex.y));
                        }
                    }
                });

This will actually move the node next to the selected node’s position.

However, one problem left is that, although the node is moved correctly, but it doesn’t push away the other nodes, which makes the two nodes overlap with each other. And the other new siblings created after the twin formulated will leave a big gap - e.g.,:

So, talking about marriages, when creating a new spouse will be able to move the node likewise my example, but at the same time, layout all the remaining nodes properly, so no nodes overlapped. How was this done? Is there a grouping done to the married couples? And how can I applied the same to the twins that I’m trying to achieve?

Sorry, but commitNodes is called at the end of the layout procedures, when it is time to assign the locations of the Nodes from the calculated locations stored in the LayoutVertexes. That time is much too late to affect the behavior of the layout.

Hi Walter,

Ok, I’ve took your code and modified the way I want it to work. I haven’t touch the sort, instead, I have manipulate the adding of kvp in “mv.destinationEdges”, which finally takes even closer to the result I want.

I met an issue, I cannot add a spouse to the twin nodes. It will either freeze the app or move the couple to the end - e.g.:

I have identify that the causes of freezing is because when a marriage is detected, the node is not added into the edgelist, which fail to identify its position for grouping.

I couldn’t identify the reason why the married twin would be moved to the end of the list.

Any ideas?

I’m not sure I have a good answer for you. The GenogramLayout is treating married couples specially – as if they were single nodes in a graph. So they aren’t really “children” of the parents’ marriage, because there might be two of them. Anyway, they are treated at a different time, so changing the order in which the “destinationEdges” are presented will have no effect.

We plan to create a completely new GenogramLayout that addresses these desired features and others, but we’ve been so busy we haven’t had time to finish the work.

Hi Walter,

So can you please advise which place I should change the ordering of the nodes to support twins? Currently I just need to know the part of the code that handles the married couple insertion. Once the married couples are process, then I can reshuffle the twin-related nodes.

I thought that was the code I gave you earlier in this topic.

Was just asking in the code that you sent, which part of it actually places the married couple into the diagram. While I know the “mv.destinationEdges” inserts and nodes in row order, and the top part of the code assign vertexs and combines the married couple. The code that actually places the married couple down into the diagram, I am still yet to identify it.

But that’s ok, I’ll figure this out eventually.

The married couples are treated as a single LayoutVertex within the LayoutNetwork that is operated upon by the LayeredDigraphLayout, and they are re-ordered to reduce logical link crossings. Actually, all vertexes are subject to re-ordering, but for unmarried individuals, that would not be necessary.

I think this is improved in the new Genogram Twins sample:
Genogram: Twins