From fad1660c9d71c640c8234ffd40ecad463b2c4728 Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Sat, 16 Nov 2019 04:00:16 -0500 Subject: [PATCH] Make some minor adjustments to graph arrow rendering --- documents/references.md | 1 + resources/graphs/directed_graph/graph.py | 53 +++++++++++++----------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/documents/references.md b/documents/references.md index ab959ae..c3474d4 100644 --- a/documents/references.md +++ b/documents/references.md @@ -27,6 +27,7 @@ for this project), it's being set up as a submodule project for now. This ended up being more complicated than I expected. * Main Ref was: <https://stackoverflow.com/a/51370419> * Secondary Ref: <https://math.stackexchange.com/questions/428843/draw-directional-arrows-on-a-given-line> +* Finding Midpoint: <https://math.stackexchange.com/questions/563566/how-do-i-find-the-middle1-2-1-3-1-4-etc-of-a-line> ### Trig "Cheat Sheet" to Help Determine Self-connecting Loop Coordinates * <http://tutorial.math.lamar.edu/pdf/trig_cheat_sheet.pdf> diff --git a/resources/graphs/directed_graph/graph.py b/resources/graphs/directed_graph/graph.py index f89435f..cbb28d4 100644 --- a/resources/graphs/directed_graph/graph.py +++ b/resources/graphs/directed_graph/graph.py @@ -87,9 +87,9 @@ class DirectedGraph(BasicGraph): else: # Node is linking to another node. - # Calculate midpoint. - mid_x = (tail_x + head_x) / 2 - mid_y = (tail_y + head_y) / 2 + # Calculate "midpoint". In our case, we want it slightly offset from center, closer to head node. + mid_x = ( 1/4 * tail_x ) + ( 3/4 * head_x ) + mid_y = ( 1/4 * tail_y ) + ( 3/4 * head_y ) # Get arrow "length" and "distance" values. length, distance = self._calc_distance_and_length(head_x, head_y, tail_x, tail_y) @@ -157,27 +157,32 @@ class DirectedGraph(BasicGraph): really large directional arrows. For reasons I don't understand, using the math below made it a lot more consistent and uniform. """ - # Get initial values, proportionally based off of cords of nodes. - length = math.sqrt(abs((head_x - tail_x) ** 2 + (head_y - tail_y) ** 2)) - if length >= 0: - length = 0.1 - distance = length - - # Calculate length. Lower of 0.6 and upper of 1.2. - length /= 20 - while length < 0.6: - length *= 2 - while length > 1.2: - length /= 2 - - # Calculate distance. Lower of 0.8 and upper of 1.6. - distance /= 10 - while distance < 0.8: - distance *= 2 - while distance > 1.6: - distance /= 2 - - return (length, distance) + # # Get initial values, proportionally based off of cords of nodes. + # length = math.sqrt(abs((head_x - tail_x) ** 2 + (head_y - tail_y) ** 2)) + # if length >= 0: + # length = 0.1 + # distance = length + # + # # Calculate length. Lower of 0.6 and upper of 1.2. + # length /= 20 + # while length < 0.6: + # length *= 2 + # while length > 1.2: + # length /= 2 + # + # # Calculate distance. Lower of 0.8 and upper of 1.6. + # distance /= 10 + # while distance < 0.8: + # distance *= 2 + # while distance > 1.6: + # distance /= 2 + # + # print('length: {0}'.format(length)) + # print('distance: {0}'.format(distance)) + # + # return (length, distance) + + return (0.64, 1.28) def _create_edge_pointer_text(self, edge): """ -- GitLab