Added a check to keep the nodes in the graph area.