Dragging Hidden Nodes Only, Keeping Groups Centered During Expansion

Hi, I’ve got two questions.

  1. I’m interested in using the
    {"draggingTool.dragsTree": true}
    setting, but only if the tree is collapsed. Is this possible?
  2. 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.
  1. 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?

  2. Set Group.locationSpot to go.Spot.Center.

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.

And thanks for the help with Q2!

Forgot to mention that reddish hue means that the part is hidden

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’ll look into it, thanks.

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:
53%20AM
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

So you are performing a layout after each expand or collapse of a group? In general you should.

I only want to apply the layout initially. Even when the group is initially expanded it still appears as you see in the second picture above.

Although the initial layout is right, and the groups generally expand from the center, there’s a problem with the first expansion.

The first time I click the SubGraphExpanderButton, the group jumps down and expands from the center, resulting in this:
05%20PM

Minimizing again results in this:
15%20PM
So the group clearly jumps down the first time I expand it.

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.

Yes, the group has a GridLayout.

$(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.

I tried changing it to

layout: $(go.TreeLayout,
{
arrangement: go.TreeLayout.ArrangementVertical
})
and I still have the same problem

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”.