Shape change for node dynamically


We are creating Organization Chart using GoJS. We have created shape for root node. In tool bar we have collection of images (see attachment). We need to change node shape based on what user selects from tool bar. Can you get us some code help.


First you’ll need a reference to the root node, presumably by knowing its key

var root = myDiagram.findNodeForKey('rootNodeKey');
Then you can change properties of this node or its children.
Suppose there is a shape in the root node's definition, and suppose you gave that shape the name: "SHAPE". You could then do:
root.findObject('SHAPE').figure = "Ellipse"; // or some other new shape
root.findObject('SHAPE').geometry = someNewGeometry;

While I am able find root node object using

var root = myDiagram.findNodeForKey(‘RShape’);

following is returning NULL


I have defined my root node as

key: “RShape”,
category: “RootNodeShape”,
color: “#ffffff”,
isGroup: false,
Shape: “Triangle”,
group: “RContainer”,
DisplayText: “Unified \n Command”,
isRootItem : true

.findObject(someName) looks for objects with the specified name in the element tree of the Node or Panel.

In order for it to work, you need to give your shape the name:

    {<b> <font color="#ff0000">name: "SHAPE",</font></b>
      figure: "RoundedRectangle",
      fill: "lime" // etc


Thanks for all this. Its working now.

However we have got another issue now…

As you can see in the image the links are being connected to the container node for case 1 and 5.
However, we need to implement it such that it touches the figure’s edges/boundary.

I am also attaching the code …

GO(go.Node, “Auto”, {
mouseDrop: fnRootDrop,

     // GO(go.Adornment, "Auto",
     //   GO(go.Shape, "Rectangle",
     //   { fill: null, stroke: "white", strokeWidth: 0 }),
     //   GO(go.Placeholder)
     // ),

        GO(go.Shape, {
            name: "rootNodeShapePart",
            width: 200,
            height: 200,
            strokeWidth: 1,
            stroke: "#000",
        new go.Binding("figure", "Shape"),
        new go.Binding("fill", "color")
                    font: "12pt helvetica, arial, sans-serif",
                    stroke: "black"
                 new go.Binding("text", "DisplayText").makeTwoWay()),
                  new go.Binding("location", "loc",
                     function (l) { return new go.Point(scaleWidth(l.x), l.y); }),
         GO("TreeExpanderButton", {
                         alignment: go.Spot.Bottom,
                         alignmentFocus: go.Spot.Bottom
                     }, {
                         visible: true


--------------------Link template --------------------------------------

{ routing: go.Link.AvoidsNodes },

                  { stroke: OrgChartConfig.RootInternalLinkColor, strokeWidth: 1, strokeDashArray: [6, 3] }),
                  { toArrow: "OpenTriangle", stroke: OrgChartConfig.RootInternalLinkColor, strokeWidth: 1 })

----------------------Link data array----------------------------

var getLinkDataArray = function () {
return [
category: “WeakLink”,
from: “F”,
text: “descriptive text”,
to: “B”
category: “RootInternal”,
from: “RData”,
to: OrgChartConfig.RootNodeShapeKey

---------------------------Layout of the group that contains the shape node , and green box node--------------------

GO(go.Group, “Auto”, {
ungroupable: false,
layout: GO(go.TreeLayout,
treeStyle: go.TreeLayout.StyleLayered,
arrangement: go.TreeLayout.ArrangementHorizontal,
// properties for most of the tree:
angle: 180,
layerSpacing: 65,
sorting: go.TreeLayout.SortingReverse
GO(go.Shape, {
width: OrgChartConfig.RootContainerWidth,
height: 300,
strokeWidth: 1,
stroke: “#fff”,
figure: “Rectangle”,

Make the shapes themselves ports by giving them a portId and the links will connect to the shapes instead of the square node itself

Examples of this here: