Node in multiple groups


We are stuck at a point where we want a node to be part of multiple groups.

But go.js library doesn’t provide this feature, Is there any plan in upcoming releases for this.

Also it would be grateful if you could suggest me some workaround for this.


That’s true, it is not a feature currently offered by GoJS, and it will not be in version 1.5.

We’ll see if we can provide a sample that demonstrates one scenario for treating situations where nodes appear to belong to multiple groups.

Here you go:

Note that it does not handle any cycles in the membership relationships, nor does it handle dynamic modifications of such relationships. The latter could be implemented, but if you need it I’m leaving that up to you.

Thanks a lot for the sample, it was really helpful.

As far as dynamic modification is concerned, i have a button to “Insert” new node.

On clicking “Insert” button, node is successfully added to the JSON, but the canvas doesn’t redraw itself to show the updated diagram.

Please share your thoughts if i am missing something in the implementation.

Basically what all needs to be done manually to make the updated JSON render on canvas.

Thanks a lot.
Ankit Arora

Why would you want to modify some JSON-formatted text, when you really should be modifying the Diagram.model? Or did you mean that you modified the JSON text and then reloaded the whole model and set Diagram.model?

If you aren’t creating a new Model and setting Diagram.model, don’t forget to execute a transaction.

I am trying to insert node by calling “addNodeData” method on existing Diagram.model. This is done within a transaction.

Please find jsFiddle for the same :

function insertNode()

myDiagram.startTransaction(“Add Node”);
key: myDiagram.model.nodeDataArray.length + 1,
text: “New Element”,
supers: [-2]
myDiagram.commitTransaction(“Add Node”);

This is my insertNode method which works fine and adds node in the model, but same is not reflected on canvas.

Things work fine if i don’t use customLayout i.e. Comment the line below in code
<span =“Apple-tab-span” style=“white-space:pre”> layout: goMake(CustomLayout),

Please let me know if i am missing something in the implementation.

My aim is to insert a new node while using Custom Layout.

Thanks and Regards
Ankit Arora

Did you notice the additional code in the load() function that updated the _members and _supers properties on the data? I think you need to adapt that code so that when you add or remove a node data object those data properties are updated throughout the model data.

Thanks a lot for your support. It worked, the new node is now added to the canvas.

One thing left is that i have to specify the “loc” of the node. (initial ones as well as the new ones to be added)

Whereas if i don’t use CustomLayout the nodes are rendered onto the canvas without location coordinates (loc).

What can be done if i wish to use custom layout and yet not specify the location coordinates for any node.
Please refer to the same jsFiddle for code.

Ankit Arora

GoJS does not have a predefined Layout that would be good for the kind of graph structure where nodes can belong to multiple “groups” simultaneously.

I could imagine that a variant of ForceDirectedLayout could be made to work, treating the group memberships as if they were edges in the network.