We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Diagram Color Children nodes

Hi,

I am trying to color the children nodes if i double click a parent node. I added a double click event while creating the diagram and also able to get into the javascript method. Is there any way that I can identify the children nodes based on the element which i clicked before the diagram.updateNode and color those nodes? I think node.fillcolor can color the nodes but the challenge is to identify the children nodes.

function doubleclick(args) {            
            var diagram = $("#Diagram1").ejDiagram("instance");
            if (args && args.element) {
                diagram.updateNode(args.element.name, { } )
            }
        }

Thanks,
Karthick

6 Replies

SG Shyam G Syncfusion Team September 14, 2017 08:41 AM UTC

Hi Karthick, 
 
  • In a group node, when you double click on the empty space in-between the group, the double click event raises in which you will get a group node in args.element and you can find an group’s children in the group’s children property. so you can iterate an children and set an fillColor for it. Please refer to the code example and playground link below
Code example: 
 
$("#diagram").ejDiagram({ 
             //define doubleClick event 
       doubleClick: doubleClick, 
}); 
 
              function doubleClick(args) { 
                   var diagram = $("#diagram").ejDiagram("instance"); 
                   var node = args.element; 
                   if (args.elementType === "group") { 
                           for (var i = 0; i < node.children.length; i++) { 
                                   var child = diagram.getNode(node.children[i]); 
                                  diagram.updateNode(child.name, { fillColor: "red" }); 
                           } 
                       } 
   } 
  • In a group node, when you double click on the group’s children, you will get a selected children in args.element and you can set a fillColor for that children. If you need to find a parent for that children, we have parent property in node to retrieve the parent node.
Code example: 
        function doubleClick(args) { 
            var diagram = $("#diagram").ejDiagram("instance"); 
            var node = args.element; 
            if (args.elementType === "node") { 
                diagram.updateNode(node.name, { fillColor: "red" }); 
                //to get a parent node 
                var parent=diagram.getNode(node.parent) 
            } 
              
    } 
 
Please refer to the below help documentation which shows how to define doubleClick event. 
 
 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Shyam G 



SG Shyam G Syncfusion Team September 14, 2017 10:24 AM UTC

Hi Karthick, 
 
Additional to our previous update, we have explained the double click event behavior for the group node with the screenshot below. 
 
  • In a group node, when you double click on the empty space in-between the group(as shown in the below screenshot with red arrow), the double click event raises in which you will get a group node in args.element and you can find an group’s children in the group’s children property. so you can iterate an children and set an fillColor for it.
  • In a group node, when you double click on the group’s children(as shown in the below screenshot with green arrow), you will get a clicked node in args.element and you can set a fillColor for that node. If you need to find a parent for that children, we have parent property in node to retrieve the parent node. please refer to the video below.
 
 
Screenshot: 
 
 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Shyam G 



KA Karthick September 18, 2017 05:30 PM UTC

Thanks Shyam for the details and code. Is there any way that the children amd parent nodes can be identified without having a group node? I have a diagram with connectors and basic shapes. Clicking on the parent should highlight the children. There is no group node in my case.

I draw the digram using diagram builder and save the file as JSON in a server path  and load the diagram from there using controller.

Right now, i did a workaround by parsing through the JSON and identify the children based on InEdges and OutEdges. I am trying to check if there is a better way to identify the children.




SG Shyam G Syncfusion Team September 19, 2017 09:37 AM UTC

Hi Karthick, 
 
  • In the previous update, you mentioned about setting fillColor to the node’s children, so we have assumed that you are using a group node and provided the solution related to an group node. Now, please ignore our previous update.
  • please use node’s inEdges and outEdges property which is used to read collection of the incoming and outgoing connectors of the node and it is an better way to find the parent/child relationship.
  • Also if you need to highlight(fillColor) the children while doubleClick on the parent node, then please use node outEdges property which contains connector name and use findNode method to get the connector object. In that connector, you can get an targetNode name and use findNode method to get an targetNode object by its name.
  • Please refer to the below screenshot, code example and playground link below.
 
Screenshot: 
 
Code example: 
 
  function doubleClick(args) { 
            var diagram = $("#diagram").ejDiagram("instance"); 
            var node = args.element; 
            if (args.elementType === "node") { 
                if (node.outEdges && node.outEdges.length > 0) { 
                    for (i = 0; i < node.outEdges.length; i++) { 
                        //to get the connector 
                        var connector = diagram.findNode(node.outEdges[i]); 
                        //to get the targetNode 
                        var targetNode = diagram.findNode(connector.targetNode); 
                         //to update the targetNode fillColor 
                        diagram.updateNode(targetNode.name, { fillColor: "red" }) 
                    } 
                } 
            } 
        } 
 
 
Regards, 
Shyam G 



KA Karthick September 19, 2017 11:06 AM UTC

Thank you Shyam. This solution works for me.



SG Shyam G Syncfusion Team September 20, 2017 04:06 AM UTC

Hi Karthick, 
We are happy to hear that your problem is resolved. 
Please let us know if you need further assistance on this. 
Regards, 
Shyam G 


Loader.
Up arrow icon