I’m interested in using the {"draggingTool.dragsTree": true}
setting, but only if the tree is collapsed. Is this possible?
Whenever I expand one of my groups, the top-left corner always stays stationary. Is there a way to make it so that the center of the group is stationary? I can’t use any of the layouts as they screw up the rest of my graph, so this would have to be specifically coded in the SubGraphExpanderButton click function.
What do you mean by “only if the tree is collapsed”? What if the user has selected one expanded node, one collapsed node and one node that has some but not all tree children visible? What then should happen when the user starts to drag these three nodes?
Three cases:
Expanded node - the node should be dragged without the tree children
Collapsed node - the node should be dragged with the tree children
Partially collapsed node - if any direct children are collapsed, they should be dragged along with the parent node. Any child that is not hidden’s trees will not be moved regardless of whether portions of their own tree are hidden.
I understand that this is difficult to explain so I attached a quick diagram for reference. Please let me know if you have any more questions.
I don’t think there’s any trivial way to get what you want. When you set DraggingTool.dragsTree to true, the subtree of every dragged node will be dragged as well – whether individual nodes within the subtree(s) are visible or not.
I suggest that you override DraggingTool.computeEffectiveCollection to create a Set with the nodes and links that you want to include, and then return the result of calling the super method with that collection. (The standard behavior of that method looks at the value of dragsTree in order to decide whether to include the nodes and links of the subtree, but presumably you don’t care about that.)
I set Group.locationSpot to go.Spot.Center, and the expansion is now centered. The only issue now is the initial location of the object.
If I collapse the groups before they render on the canvas, I get this, which is perfect:
But when I expand the groups, they jump down and expand from the center to become this:
You don’t have any Diagram.layout, do you? I’ll assume not.
You should make sure that the member nodes, when the containing group is expanded, are at the desired locations. But that can be hard to do in general. After all, what arrangement would you want if one of those groups had a thousand member nodes? That’s why it would be easier to depend on a Layout.
I’m making something similar to a double tree in the samples, so I use the doLayout command on this right portion, but it doesn’t line the groups up correctly
Does your Group have a Group.layout? Is it a GridLayout?
Make sure that your member nodes all have the locations that you want when the group is expanded. Then you can start with the group collapsed and expect the expanded group to be where you want it to be.
$(go.Group, “Auto”,
{
// make it so that groups expand neatly
locationSpot: go.Spot.Left,
// define the group’s internal layout
layout: $(go.GridLayout,
{ wrappingColumn: 1, alignment: go.GridLayout.Location })
},
etc.
If you really only want to do an initial layout, as you said you do, then you need to make sure that at that time all of the nodes, including ones that are members of your groups, have real locations. Then collapsing or expanding groups will “stay in place”.