TreeLayout.comparer works tricky with animations

Im using a following comparer function:

sorting: go.TreeLayout.SortingDescending,
            comparer: function(va: go.TreeVertex, vb: go.TreeVertex) {
              if(va.node === null || vb.node === null)
                return 0;
              var da =;
              var db =;
              if (da.order < db.order) return 1;
              if (da.order > db.order) return -1;
              return 0;

Children of a given node are assigned a certain order on creation (number of children + 1) and there is an option of reordering nodes.

Reordering works but when adding a new child node, the reordered node somehow animates from the previous order to the current one. It’s only during the animation. Why is it happening? It seems like the animation takes the initial position from the default comparer.

Unless you have done some unusual custom animations, layout animations just change the locations of nodes. So the question is where the node is before the layout. Since it’s a new node that you are talking about, that might be at the document origin.

I suggest that you explicitly locate the new node when you create it, before the layout happens. Many of the samples do that. For example, consider the addNodeAndLink function called by the button in the node’s selection adornment:

Thanks. It fixed it