Hi, there. I’m using TreeLayout. When A node is dragged from a palette, it will be dropped to the end of the tree. How can it be positioned just where it’s dropped and when it is linked to a node in the tree, it will still be re-arranged automatically?
Hi, Walter. Thanks for your reply. I use ‘LayoutNone’ and it does not put the added node to the end of the tree. But still, when a node was linked to the tree, all un-linked nodes automatically moved to then end of the tree. So, how to keep the un-linked nodes as the place they were placed? Any methods should be overridden or Events should be listen to?
OK, instead of setting layoutConditions, try setting isLayoutPositioned to false on the node template. Then when you connect the node to another node, set Node.isLayoutPositioned back to true.
One last question:
I wonder what is the event like ‘LinkRemoved’ which I can listen to and make the ‘fromNode.isLayoutPosistioned’ and ‘toNode.isLayoutPosistioned’ to ‘false’ again?
Good point about deletion. I hope you are not blindly setting isLayoutPositioned back to false, since the node might still be connected with other links.
Rather than those DiagramEvents, I think it would be better to implement two event handlers:
linkConnected: n => n.isLayoutPositioned = true,
linkDisconnected: n => n.isLayoutPositioned = n.linksConnected.count > 0
I think using linkConnected and linkDisconnected is the right way to do.
It would be more specific, more reliable & more convenient to do this task.
Thanks for pointing this out. :clap :clap
BTW, I might have been there to check if there is any event handler could be used for the job. And maybe I’ve just misled by the property and method list on the right side which says both linkConnected and linkDisconnected are properties but not methods.
That is correct – simple event handlers are properties of type function. The assumption is that unicast event handlers are sufficient for almost all uses, unlike the multicast DiagramEvent and ChangedEvent listeners.
In GoJS functional property event handlers always default to null and may be regular functions, not methods that expect to have this bound. That means you can always use arrow functions, and usually they do not need to be closures.