Sorting and Snapping nodes on same level in a Tree layout

Hi all,

I’m using GoJs to build conditional questions in a form. I wanted to sort the question based on the node position (every node is a questions/answer).

  1. How would I get the position of a node on the same level? (let to right to top to bottom)
  2. How to stop overlapping on nodes, when changing node position (sorting manually)?

Thanks in advanced.

Chat.

I’m not sure I understand the situation. Do you know about TreeLayout.sorting and TreeLayout.comparer?

Would you want to perform a layout at the end of each move? If so, implement a “SelectionMoved” DiagramEvent listener that calls myDiagram.layoutDiagram(true).

Hi Walter,

Thanks for the quick reply. Do you know on top of your head, any samples i can refer to regarding TreeLayout.sorting and TreeLayout.comparer?

I think re-layout on move will work like a treat. thanks for the tip.

Chat.

Hi Walter,

I manage to come up with a solution using your solution Functionality in Org Chart to shift a node to left - #6 by walter

Is there a way to achieve the same functionality based on location, the user drops the node in?

Thanks,
Chat.

Yes, instead of having the comparer function depend on some property of each vertex’s node’s data (.node.data.sequence in that forum topic), have it depend on the TreeVertex.node.location.x.