Loop through all elements in a node

Hi ,

I have a requirement, where all the nodes contains a invisible icon. We have a context menu with option “Set As Primary” and when user click on this context menu item, the icon within that node should be made visible.

So is there a sample code to iterate through all the shapes, panel, text block and picture elements that constitutes the node for a selected node, So that while iterating we can dynamically set the visible property of the picture as per our requirement.


The normal thing to do, if you just have a single Picture whose GraphObject.visible property you want to toggle, is to give that Picture a unique GraphObject.name within in the Node. Then you can just call Panel.findObject with that name in order to find that element, no matter where it is in the visual tree.

Depending on how you want to handle panel layout, you can either toggle GraphObject.visible or switch GraphObject.opacity between 1 and 0. The former will cause a panel layout; the latter simply makes it transparent.

If you really want to walk the visual tree, that’s easy enough to do recursively. There are also some not-yet-documented methods for walking the visual tree.

Oh, I assume you have already read http://gojs.net/latest/intro/contextMenus.html.