My group template is binded to “position” as follows :
new go.Binding(“position” “loc”, go.Parse.point).makeTwoWay(go.point.stringify);
When a group is expanded i save the group current location :
group.data.origLoc = group.data.loc;
When the group is collapsed, i try to restore its original location by :
But, the group location moves to a new arbitrary position.
How can i restore its original location ?
I tried the moveTo, it behaves exactly as my code.
I noticed that when the group is collapsed, its position.x value is negative (-357) ,
although the group is located in the center of the diagram.
So i believe when when i collapse the group, and restore the negative value, the group is moved to some other location, -357 relative to its expanded position.
Beside, why is the ‘X’ value negative, if the group is positioned in the center of the diagram ?
So what are the values of Part.position and Part.location for that Group, before collapsing, after collapsing, and after expanding? Look in the debug console. If the group is selected: myDiagram.selection.first().location.toString()
The diagram starts with a collapsed group : (53,188)
After it is expanded its new location is set to (-450,1080)
After it is collapsed, its location is set to back to (53,188) but the Group moves “north”.
These are my handlers :
For the Group | GoJS API event handler, the Group is the argument, so you shouldn’t be looking at the selection. Use the selection when debugging interactively.
Maybe you want to override the CommandHandler commands for collapsing and expanding groups, to remember the Diagram.position beforehand, and to restore it afterwards in an “AnimationFinished” DiagramEvent Listener.
Actually the functions in the picture are “SubGraphCollapsed” and “SubGraphExpnded” diagram listeners respectively.
What’s wrong with implementing such listeners ? The timing of them ?
The Animation timing ?
Please read what I wrote more carefully. I said in my reply a few posts ago that you should override CommandHandler commands (CommandHandler.collapseSubGraph and expandSubGraph) so that you can remember the Diagram.position.
I did not say that you should implement a DiagramEvent listener and remember the Group.position.
I’m trying to follow your advise and save and restore group.location during the command handler.
All the other code i wrote and showed you is not relevant any more.
I understood from your suggestions that i should override the command handler and not implement diagram listeners.
I’m finding this frustrating. Please read again what I have written twice. You have overrides of CommandHandler commands – that’s good. But you are trying to save and restore the Group.location when I keep telling you to save and restore the Diagram.position. Furthermore, as I said originally, if there is any animation, you might need to restore the Diagram.position after an “AnimationFinished” DiagramEvent listener