Articles in this section
Category / Section

How to get the bounds for the path node

1 min read

How to get the bounds for the path Node

You can use getBounds method in the Application level in which you can pass the pathData to get the bounds. You can set these bounds to the node’s width, height, offsetX and offsetY.

JS

    function Getpath(userdata) {
        //pass your path data as a parameter
        var newdata = userdata;
        //you can directly give the pathData
        var data = "M13.501763,0L18.301814,0 18.301814,7.4989894 23.200896,7.4989894 15.901789,13.598993 8.6017047,7.4989894 13.501763,7.4989894z";
        var xmlns = "http://www.w3.org/2000/svg"; 
        var svg = document.createElementNS(xmlns, "svg");
        svg.setAttribute("width", "1000px");
        svg.setAttribute("height", "1000px");
        var path = document.createElementNS(xmlns, "path");
        if (newdata)
            path.setAttribute("d", newdata);
        else
            path.setAttribute("d", data);
        document.body.appendChild(svg);
        svg.appendChild(path);
        var bounds = path.getBBox();
        document.body.removeChild(svg);
        //get the bounds
        return bounds; 
    }

 

If you have a multiple pathData, you can create as a group node. Please refer to the code example and JSPlayground link below.

Code example:

JS

var nodes =
            [
                {
                    name: "group", type:"group", 
                    children: [{ name: "node1", width: 32, height: 12, offsetX: 100, offsetY: 100, shape: "path", pathData: "M7.1026927,8.3989833L8.9016973,9.8989823C4.6026598,10.699 2.0026196,12.199 2.0026196,13.299005 2.0026196,14.898979 7.5016848,17.299004 15.901789,17.299004 24.300916,17.299004 29.800988,14.898979 29.800988,13.299005 29.800988,12.199 27.200948,10.699 22.900874,9.8989823L24.800923,8.3989833C29.100967,9.6990007 32.001001,11.799006 32.001001,14.299005 32.001001,18.198996 24.800923,21.398001 16.001796,21.398001 7.2026693,21.398001 0.0025934007,18.198996 0.0025932575,14.299005 -0.097414011,11.799006 2.7026104,9.6990007 7.1026927,8.3989833z" },
                      { name: "node2", width: 13, height: 14, offsetX: 100, offsetY: 90, shape: "path", pathData: "M13.501763,0L18.301814,0 18.301814,7.4989894 23.200896,7.4989894 15.901789,13.598993 8.6017047,7.4989894 13.501763,7.4989894z" },
                    ]
                },
            ];
$("#diagram").ejDiagram({
            nodes: nodes,
        });
 

 

JSPlayground link: https://jsplayground.syncfusion.com/1euy2s1a

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied