From 39aa628a3285ad2ad145c77a35bd4b7c781e56ca Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Wed, 4 Dec 2019 04:15:47 -0500
Subject: [PATCH] Add minimal logic for manually setting node coords

Previously, certain node setups would override manual coord setting
---
 resources/graphs/basic_graph/components.py | 18 ++++++++++++++++++
 resources/graphs/basic_graph/graph.py      | 14 ++++++++++----
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/resources/graphs/basic_graph/components.py b/resources/graphs/basic_graph/components.py
index 3264677..b553116 100644
--- a/resources/graphs/basic_graph/components.py
+++ b/resources/graphs/basic_graph/components.py
@@ -241,6 +241,8 @@ class BasicNode():
         self._graph = None
         self.x_coord = None
         self.y_coord = None
+        self._manually_set_x_coord = False
+        self._manually_set_y_coord = False
 
         # Define expected class types (should all be of "Basic" type).
         # This is necessary for inheritance, or else child classes will only have access to parent functions.
@@ -434,6 +436,22 @@ class BasicNode():
 
     #region Upkeep Functions
 
+    def set_x_coord(self, x_coord):
+        """
+        Manually sets node x_coord.
+        :param x_coord: Coordinate to set for node.
+        """
+        self.x_coord = x_coord
+        self._manually_set_x_coord = True
+
+    def set_y_coord(self, y_coord):
+        """
+        Manually sets node y_coord.
+        :param y_coord: Coordinate to set for node.
+        """
+        self.y_coord = y_coord
+        self._manually_set_y_coord = True
+
     def connect_node(self, neighbor_node, edge_name=None):
         """
         Connects current node to passed node.
diff --git a/resources/graphs/basic_graph/graph.py b/resources/graphs/basic_graph/graph.py
index f3e10d1..4899f4f 100644
--- a/resources/graphs/basic_graph/graph.py
+++ b/resources/graphs/basic_graph/graph.py
@@ -301,8 +301,11 @@ class BasicGraphDisplay():
                                 # Coord was already taken by another node. Try again.
                                 pass
 
-                        connected_node.x_coord = x_coord
-                        connected_node.y_coord = y_coord
+                        # Set coordinates if not manually set.
+                        if not connected_node._manually_set_x_coord:
+                            connected_node.x_coord = x_coord
+                        if not connected_node._manually_set_y_coord:
+                            connected_node.y_coord = y_coord
 
                         # Record extreme positions.
                         if x_coord > farthest_x[0]:
@@ -370,8 +373,11 @@ class BasicGraphDisplay():
                                 # Coord was already taken by another node. Try again.
                                 pass
 
-                        connected_node.x_coord = x_coord
-                        connected_node.y_coord = y_coord
+                        # Set coordinates if not manually set.
+                        if not connected_node._manually_set_x_coord:
+                            connected_node.x_coord = x_coord
+                        if not connected_node._manually_set_y_coord:
+                            connected_node.y_coord = y_coord
 
                         # Record extreme positions.
                         if x_coord > farthest_x[0]:
-- 
GitLab