Convert a node to a group?

I have a routine that runs when the user right-clicks a containing node (that part works fine) that iterates through all of the outbound nodes and attempts to add them to the group that is the parent node. As part of this, I need to convert the parent node (the one the user launched the context menu from) to a group. I tried using the following code:

//Get the node from the diagram using the key from the part
var n = myDiagram.findNodeForKey(part.data.key);

//Get the iterator (this appears to work just fine)
var itr = n.findNodesOutOf(null);

//THIS LINE THROWS THE EXCEPTION BELOW
myDiagram.model.setDataProperty(n.data, “isGroup”, true);

//Iterate over the nodes
while (itr.next()) {
//get the next node
var j = itr.value;
j.data.group = n.data[“key”];
//myDiagram.model.setDataProperty(j.data, “Group”, n.data[“key”]);
}

The exception is: GraphLinksModel.setDataProperty:property name must not be the nodelsGroupProperty: isGroup.

There are no examples of how to do this but I imagine that grouping based on connected nodes is something that would have to be easily do-able. Any ideas?

Thanks!

Jeff

You cannot dynamically change a Node to a Group or vice-versa.

Could you explain why you need that functionality?


If your nodes need the appearance of dynamically changing between nodes and groups, then you may need to have all of your node data always have isGroup: true, and only use Diagram.groupTemplateMap, instead of nodeTemplateMap.

So in this case it’s a fairly simple - sometimes users want to see things radially, but other times they want to view it as a containment group so that they can collapse it. It’s like being able to group regions on the fly but instead of doing it by selecting and grouping with the command, the grouping is done based on the values of the node.
I wasn’t able to find an example of switching back and forth between the nodeTemplateMap and the groupTemplateMap.
This may work but I suspect it will group everything on the map. Also some of this use will be for a Directed Acyclic Graph which means that nodes can be members of multiple groups and it doesn’t look like this functionality is easily supported so that might cause problems.

Thanks!

Jeff

In this case you won’t want to be switching between nodeTemplateMap and groupTemplateMap, just switching some of your Nodes (All of which are really Groups) between different group templates within the groupTemplateMap. (There’s an example of changing template categories here)

Yes, there is no ability to have a Node or Group within more than one Group.<span =“Apple-tab-span” style=“white-space:pre”>