Skip to content
Snippets Groups Projects
Commit fad1660c authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Make some minor adjustments to graph arrow rendering

parent 059f51f7
Branches
No related merge requests found
...@@ -27,6 +27,7 @@ for this project), it's being set up as a submodule project for now. ...@@ -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. This ended up being more complicated than I expected.
* Main Ref was: <https://stackoverflow.com/a/51370419> * Main Ref was: <https://stackoverflow.com/a/51370419>
* Secondary Ref: <https://math.stackexchange.com/questions/428843/draw-directional-arrows-on-a-given-line> * 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 ### Trig "Cheat Sheet" to Help Determine Self-connecting Loop Coordinates
* <http://tutorial.math.lamar.edu/pdf/trig_cheat_sheet.pdf> * <http://tutorial.math.lamar.edu/pdf/trig_cheat_sheet.pdf>
......
...@@ -87,9 +87,9 @@ class DirectedGraph(BasicGraph): ...@@ -87,9 +87,9 @@ class DirectedGraph(BasicGraph):
else: else:
# Node is linking to another node. # Node is linking to another node.
# Calculate midpoint. # Calculate "midpoint". In our case, we want it slightly offset from center, closer to head node.
mid_x = (tail_x + head_x) / 2 mid_x = ( 1/4 * tail_x ) + ( 3/4 * head_x )
mid_y = (tail_y + head_y) / 2 mid_y = ( 1/4 * tail_y ) + ( 3/4 * head_y )
# Get arrow "length" and "distance" values. # Get arrow "length" and "distance" values.
length, distance = self._calc_distance_and_length(head_x, head_y, tail_x, tail_y) length, distance = self._calc_distance_and_length(head_x, head_y, tail_x, tail_y)
...@@ -157,27 +157,32 @@ class DirectedGraph(BasicGraph): ...@@ -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 really large directional arrows. For reasons I don't understand, using the math below made it a lot more
consistent and uniform. consistent and uniform.
""" """
# Get initial values, proportionally based off of cords of nodes. # # Get initial values, proportionally based off of cords of nodes.
length = math.sqrt(abs((head_x - tail_x) ** 2 + (head_y - tail_y) ** 2)) # length = math.sqrt(abs((head_x - tail_x) ** 2 + (head_y - tail_y) ** 2))
if length >= 0: # if length >= 0:
length = 0.1 # length = 0.1
distance = length # distance = length
#
# Calculate length. Lower of 0.6 and upper of 1.2. # # Calculate length. Lower of 0.6 and upper of 1.2.
length /= 20 # length /= 20
while length < 0.6: # while length < 0.6:
length *= 2 # length *= 2
while length > 1.2: # while length > 1.2:
length /= 2 # length /= 2
#
# Calculate distance. Lower of 0.8 and upper of 1.6. # # Calculate distance. Lower of 0.8 and upper of 1.6.
distance /= 10 # distance /= 10
while distance < 0.8: # while distance < 0.8:
distance *= 2 # distance *= 2
while distance > 1.6: # while distance > 1.6:
distance /= 2 # distance /= 2
#
return (length, distance) # 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): def _create_edge_pointer_text(self, edge):
""" """
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment