Get connected nodes information on click of a node in a Tree

Hi Walter,

I am creating a diagram using tree mapper sample where I have two trees. First tree is connected with another tree on the basis of some relationship. Please see the screen shot.

Now, the requirement is that as I click on the node suppose here “10.1 Capability 61” then it opens a popup and show the relationship in the opened popup. Means as I click on 10.1 Capability 61, it opens the pop up and show the tree on the left as the selected node (10.1 Capability 61) and on other side tree have the values which are connected with this means (Auto dialler/ Auto SMS…, Product Draft 1) with the connector lines. So, to achieve this, I have called the pop-up on the click event of a node and find out the nodes which are connected with it. Its giving me both the nodes which are on the right but it is also giving me the node which are directly connected to the node in the same tree means when I clicked on the 10.Capability 61, it gives me following connected node:-
a) 10 Capability 5
b) 10.1.1 Case Set up
c) Auto Dialler / Auto SMS…
d) Product Draft 1

Here, I want only © and (d) but don’t want (a) and (b).

This is my code where I called showNodeInfo on the click event of the node:-

function showNodeInfo(e, obj){
var part = obj.part;
var key = part.data.key; // This gives the ID

	part.findNodesConnected().each(function(n){
		var part1 = n.part;
		var key1 = part1.data.key;
		alert(" nodes connected === " + key1);
	});

}

Can you please suggest how I can achieve the desired result or let me know if I am wrong anywhere?

Thank you.

One way to do it is by looking at the group that the connected node is in.

function showNodeInfo(e, obj) {
    var node = obj.part;
    node.findNodesConnected().each(function(n) {
        if (n.containingGroup !== node.containingGroup) { console.log(n.data.key); }
    });
}

Thanks Walter. It solved my problem and I got the desired result.

Hi Walter,

One more thing, how I can get the name of the group in which a node is clicked? Please check the screen for more clarity.

Thank you.

The normal thing is to look at the Group.data object’s properties. For example:

function showNodeInfo(e, obj) {
    var node = obj.part;
    node.findNodesConnected().each(function(n) {
        var g = n.containingGroup;
        if (g !== null && g.data.name !== "Capabilities") { console.log(n.data.key); }
    });
}

Alternatively, you can find the TextBlock within the Group. That is easiest if you have given that TextBlock a GraphObject.name, so that you can call Panel.findObject.

Thanks Walter.