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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Diagram Color Children nodes

Thread ID:

Created:

Updated:

Platform:

Replies:

132634 Sep 13,2017 11:22 AM UTC Sep 20,2017 04:06 AM UTC ASP.NET MVC 6
loading
Tags: Diagram
Karthick
Asked On September 13, 2017 11:22 AM UTC

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

Shyam G [Syncfusion]
Replied On 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 


Shyam G [Syncfusion]
Replied On 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 


Karthick
Replied On 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.



Shyam G [Syncfusion]
Replied On 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 


Karthick
Replied On September 19, 2017 11:06 AM UTC

Thank you Shyam. This solution works for me.


Shyam G [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;