Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Nodes on right side of graph aren't centered #2

Open
sambonfire opened this issue Sep 10, 2019 · 1 comment
Open

Nodes on right side of graph aren't centered #2

sambonfire opened this issue Sep 10, 2019 · 1 comment

Comments

@sambonfire
Copy link

sambonfire commented Sep 10, 2019

It looks like the code to center the nodes on the right side of the graph isn't working correctly. For me these nodes were often offset at odd angles. I changed this method to fix it:

        private void CenterTreeToRoot(Node.NodeInputSide side)
        {
            var children = _refTargetNode.GetChildren(side);

            if (children.Count > 1)
            {
                float refTargetY = _refTargetNode.Position.y;
                float size = _refTargetNode.GetLastChild(side).Position.y -
                             _refTargetNode.GetFirstChild(side).Position.y;
                float actualY = _refTargetNode.GetFirstChild(side).Position.y;
                float desiredY = refTargetY - size/2.0f;
                float shiftY = desiredY - actualY;

                for (int i = 0; i < children.Count; ++i)
                {
                    children[i].ForeachChildrenRecursively(side, (node) => node.SetPositionY(node.Position.y + shiftY));
                }
            }
        }
@Begounet
Copy link
Owner

Hello!

I will completely trust you and add it into the plugin.
I won't tell that I had no idea of what I was doing but I tried to implement an algorithm that I did not fully understood...

So, thanks you for your contribution!
It is now available on master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants